OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/view_id_util.h" | 5 #import "chrome/browser/ui/cocoa/view_id_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // TODO(suzhe): After migrating to Mac OS X 10.6, we may use Objective-C's new | 18 // TODO(suzhe): After migrating to Mac OS X 10.6, we may use Objective-C's new |
19 // "Associative References" feature to attach the ViewID to the view directly | 19 // "Associative References" feature to attach the ViewID to the view directly |
20 // rather than using a separated map. | 20 // rather than using a separated map. |
21 typedef std::map<NSView*, ViewID> ViewIDMap; | 21 typedef std::map<NSView*, ViewID> ViewIDMap; |
22 | 22 |
23 ViewIDMap* GetViewIDMap() { | 23 ViewIDMap* GetViewIDMap() { |
24 static auto view_id_map = new ViewIDMap(); | 24 static auto* view_id_map = new ViewIDMap(); |
25 return view_id_map; | 25 return view_id_map; |
26 } | 26 } |
27 | 27 |
28 // Returns the view's nearest descendant (including itself) with a specific | 28 // Returns the view's nearest descendant (including itself) with a specific |
29 // ViewID, or nil if no subview has that ViewID. | 29 // ViewID, or nil if no subview has that ViewID. |
30 NSView* FindViewWithID(NSView* view, ViewID viewID) { | 30 NSView* FindViewWithID(NSView* view, ViewID viewID) { |
31 if ([view viewID] == viewID) | 31 if ([view viewID] == viewID) |
32 return view; | 32 return view; |
33 | 33 |
34 for (NSView* subview in [view subviews]) { | 34 for (NSView* subview in [view subviews]) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 89 } |
90 | 90 |
91 - (NSView*)ancestorWithViewID:(ViewID)viewID { | 91 - (NSView*)ancestorWithViewID:(ViewID)viewID { |
92 NSView* ancestor = self; | 92 NSView* ancestor = self; |
93 while (ancestor && [ancestor viewID] != viewID) | 93 while (ancestor && [ancestor viewID] != viewID) |
94 ancestor = [ancestor superview]; | 94 ancestor = [ancestor superview]; |
95 return ancestor; | 95 return ancestor; |
96 } | 96 } |
97 | 97 |
98 @end | 98 @end |
OLD | NEW |