• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #import <Cocoa/Cocoa.h>
9 
10 #include "chrome/browser/ui/view_ids.h"
11 #include "ui/gfx/native_widget_types.h"
12 
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.
17 
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.
24 
25 namespace view_id_util {
26 
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);
30 
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);
34 
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);
38 
39 }  // namespace view_id_util
40 
41 
42 @interface NSView (ViewID)
43 
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;
48 
49 // Returns the ancestor view with a specific ViewID, or nil if no ancestor
50 // view has that ViewID.
51 - (NSView*)ancestorWithViewID:(ViewID)viewID;
52 
53 @end
54 
55 #endif  // CHROME_BROWSER_UI_COCOA_VIEW_ID_UTIL_H_
56