Home | History | Annotate | Download | only in cocoa
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_
      6 #define CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_
      7 #pragma once
      8 
      9 #import <Cocoa/Cocoa.h>
     10 
     11 #include "chrome/browser/ui/view_ids.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 
     14 // ViewIDs are a system that indexes important views in the browser window by a
     15 // ViewID identifier (integer). This is a useful compatibility for finding a
     16 // view object in cross-platform tests. See BrowserFocusTest.* for an example
     17 // of how ViewIDs are used.
     18 
     19 // For views with fixed ViewIDs, we add a -viewID method to them to return their
     20 // ViewIDs directly. But for views with changeable ViewIDs, as NSView itself
     21 // doesn't provide a facility to store its ViewID, to avoid modifying each
     22 // individual classes for adding ViewID support, we use an internal map to store
     23 // ViewIDs of each view and provide some utility functions for NSView to
     24 // set/unset the ViewID and lookup a view with a specified ViewID.
     25 
     26 namespace view_id_util {
     27 
     28 // Associates the given ViewID with the view. It shall be called upon the view's
     29 // initialization.
     30 void SetID(NSView* view, ViewID viewID);
     31 
     32 // Removes the association between the view and its ViewID. It shall be called
     33 // just before the view's destruction.
     34 void UnsetID(NSView* view);
     35 
     36 // Returns the view with a specific ViewID in a window, or nil if no view in the
     37 // window has that ViewID.
     38 NSView* GetView(NSWindow* window, ViewID viewID);
     39 
     40 }  // namespace view_id_util
     41 
     42 
     43 @interface NSView (ViewID)
     44 
     45 // Returns the ViewID associated to the receiver. The default implementation
     46 // looks up the view's ViewID in the internal view to ViewID map. A subclass may
     47 // override this method to return its fixed ViewID.
     48 - (ViewID)viewID;
     49 
     50 @end
     51 
     52 #endif  // CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_
     53