| 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> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DCHECK(view); | 53 DCHECK(view); |
| 54 g_view_id_map.Get().erase(view); | 54 g_view_id_map.Get().erase(view); |
| 55 } | 55 } |
| 56 | 56 |
| 57 NSView* GetView(NSWindow* window, ViewID viewID) { | 57 NSView* GetView(NSWindow* window, ViewID viewID) { |
| 58 DCHECK(viewID != VIEW_ID_NONE); | 58 DCHECK(viewID != VIEW_ID_NONE); |
| 59 DCHECK(window); | 59 DCHECK(window); |
| 60 | 60 |
| 61 // As tabs can be created, destroyed or rearranged dynamically, we handle them | 61 // As tabs can be created, destroyed or rearranged dynamically, we handle them |
| 62 // here specially. | 62 // here specially. |
| 63 #if 0 |
| 63 if (viewID >= VIEW_ID_TAB_0 && viewID <= VIEW_ID_TAB_LAST) { | 64 if (viewID >= VIEW_ID_TAB_0 && viewID <= VIEW_ID_TAB_LAST) { |
| 64 BrowserWindowController* windowController = [window windowController]; | 65 BrowserWindowController* windowController = [window windowController]; |
| 65 DCHECK([windowController isKindOfClass:[BrowserWindowController class]]); | 66 DCHECK([windowController isKindOfClass:[BrowserWindowController class]]); |
| 66 TabStripController* tabStripController = | 67 TabStripController* tabStripController = |
| 67 [windowController tabStripController]; | 68 [windowController tabStripController]; |
| 68 DCHECK(tabStripController); | 69 DCHECK(tabStripController); |
| 69 NSUInteger count = [tabStripController viewsCount]; | 70 NSUInteger count = [tabStripController viewsCount]; |
| 70 DCHECK(count); | 71 DCHECK(count); |
| 71 NSUInteger index = | 72 NSUInteger index = |
| 72 (viewID == VIEW_ID_TAB_LAST ? count - 1 : viewID - VIEW_ID_TAB_0); | 73 (viewID == VIEW_ID_TAB_LAST ? count - 1 : viewID - VIEW_ID_TAB_0); |
| 73 return index < count ? [tabStripController viewAtIndex:index] : nil; | 74 return index < count ? [tabStripController viewAtIndex:index] : nil; |
| 74 } | 75 } |
| 76 #endif |
| 75 | 77 |
| 76 return FindViewWithID([[window contentView] superview], viewID); | 78 return FindViewWithID([[window contentView] superview], viewID); |
| 77 } | 79 } |
| 78 | 80 |
| 79 } // namespace view_id_util | 81 } // namespace view_id_util |
| 80 | 82 |
| 81 @implementation NSView (ViewID) | 83 @implementation NSView (ViewID) |
| 82 | 84 |
| 83 - (ViewID)viewID { | 85 - (ViewID)viewID { |
| 84 ViewIDMap* map = g_view_id_map.Pointer(); | 86 ViewIDMap* map = g_view_id_map.Pointer(); |
| 85 ViewIDMap::const_iterator iter = map->find(self); | 87 ViewIDMap::const_iterator iter = map->find(self); |
| 86 return iter != map->end() ? iter->second : VIEW_ID_NONE; | 88 return iter != map->end() ? iter->second : VIEW_ID_NONE; |
| 87 } | 89 } |
| 88 | 90 |
| 89 - (NSView*)ancestorWithViewID:(ViewID)viewID { | 91 - (NSView*)ancestorWithViewID:(ViewID)viewID { |
| 90 NSView* ancestor = self; | 92 NSView* ancestor = self; |
| 91 while (ancestor && [ancestor viewID] != viewID) | 93 while (ancestor && [ancestor viewID] != viewID) |
| 92 ancestor = [ancestor superview]; | 94 ancestor = [ancestor superview]; |
| 93 return ancestor; | 95 return ancestor; |
| 94 } | 96 } |
| 95 | 97 |
| 96 @end | 98 @end |
| OLD | NEW |