Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / view_id_util.h
blobe104ad843a546338dc09056beaf7d1c1e470bbef
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.
5 #ifndef CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_
6 #define CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_
8 #import <Cocoa/Cocoa.h>
10 #include "chrome/browser/ui/view_ids.h"
11 #include "ui/gfx/native_widget_types.h"
13 // ViewIDs are a system that indexes important views in the browser window by a
14 // ViewID identifier (integer). This is a useful compatibility for finding a
15 // view object in cross-platform tests. See BrowserFocusTest.* for an example
16 // of how ViewIDs are used.
18 // For views with fixed ViewIDs, we add a -viewID method to them to return their
19 // ViewIDs directly. But for views with changeable ViewIDs, as NSView itself
20 // doesn't provide a facility to store its ViewID, to avoid modifying each
21 // individual classes for adding ViewID support, we use an internal map to store
22 // ViewIDs of each view and provide some utility functions for NSView to
23 // set/unset the ViewID and lookup a view with a specified ViewID.
25 namespace view_id_util {
27 // Associates the given ViewID with the view. It shall be called upon the view's
28 // initialization.
29 void SetID(NSView* view, ViewID viewID);
31 // Removes the association between the view and its ViewID. It shall be called
32 // just before the view's destruction.
33 void UnsetID(NSView* view);
35 // Returns the view with a specific ViewID in a window, or nil if no view in the
36 // window has that ViewID.
37 NSView* GetView(NSWindow* window, ViewID viewID);
39 } // namespace view_id_util
42 @interface NSView (ViewID)
44 // Returns the ViewID associated to the receiver. The default implementation
45 // looks up the view's ViewID in the internal view to ViewID map. A subclass may
46 // override this method to return its fixed ViewID.
47 - (ViewID)viewID;
49 // Returns the ancestor view with a specific ViewID, or nil if no ancestor
50 // view has that ViewID.
51 - (NSView*)ancestorWithViewID:(ViewID)viewID;
53 @end
55 #endif // CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_