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 #include "base/mac/mac_util.h" | 5 #include "base/mac/mac_util.h" |
6 #import "chrome/browser/themes/theme_service.h" | 6 #import "chrome/browser/themes/theme_service.h" |
7 #import "chrome/browser/ui/cocoa/menu_controller.h" | 7 #import "chrome/browser/ui/cocoa/menu_controller.h" |
8 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 8 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
9 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 9 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
10 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 10 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 return self; | 92 return self; |
93 } | 93 } |
94 | 94 |
95 - (void)dealloc { | 95 - (void)dealloc { |
96 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 96 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
97 [[self tabView] setController:nil]; | 97 [[self tabView] setController:nil]; |
98 [super dealloc]; | 98 [super dealloc]; |
99 } | 99 } |
100 | 100 |
101 // The internals of |-setSelected:| but doesn't check if we're already set | 101 // The internals of |-setSelected:| and |-setActive:| but doesn't set the |
102 // to |selected|. Pass the selection change to the subviews that need it and | 102 // backing variables. This updates the drawing state and marks self as needing |
103 // mark ourselves as needing a redraw. | 103 // a re-draw. |
104 - (void)internalSetSelected:(BOOL)selected { | 104 - (void)internalSetSelected:(BOOL)selected { |
105 selected_ = selected; | |
106 TabView* tabView = static_cast<TabView*>([self view]); | 105 TabView* tabView = static_cast<TabView*>([self view]); |
107 DCHECK([tabView isKindOfClass:[TabView class]]); | 106 DCHECK([tabView isKindOfClass:[TabView class]]); |
108 [tabView setState:selected]; | 107 [tabView setState:selected]; |
109 [tabView cancelAlert]; | 108 if ([self active]) |
| 109 [tabView cancelAlert]; |
110 [self updateVisibility]; | 110 [self updateVisibility]; |
111 [self updateTitleColor]; | 111 [self updateTitleColor]; |
112 } | 112 } |
113 | 113 |
114 // Called when the tab's nib is done loading and all outlets are hooked up. | 114 // Called when the tab's nib is done loading and all outlets are hooked up. |
115 - (void)awakeFromNib { | 115 - (void)awakeFromNib { |
116 // Remember the icon's frame, so that if the icon is ever removed, a new | 116 // Remember the icon's frame, so that if the icon is ever removed, a new |
117 // one can later replace it in the proper location. | 117 // one can later replace it in the proper location. |
118 originalIconFrame_ = [iconView_ frame]; | 118 originalIconFrame_ = [iconView_ frame]; |
119 | 119 |
120 // When the icon is removed, the title expands to the left to fill the space | 120 // When the icon is removed, the title expands to the left to fill the space |
121 // left by the icon. When the close button is removed, the title expands to | 121 // left by the icon. When the close button is removed, the title expands to |
122 // the right to fill its space. These are the amounts to expand and contract | 122 // the right to fill its space. These are the amounts to expand and contract |
123 // titleView_ under those conditions. We don't have to explicilty save the | 123 // titleView_ under those conditions. We don't have to explicilty save the |
124 // offset between the title and the close button since we can just get that | 124 // offset between the title and the close button since we can just get that |
125 // value for the close button's frame. | 125 // value for the close button's frame. |
126 NSRect titleFrame = [titleView_ frame]; | 126 NSRect titleFrame = [titleView_ frame]; |
127 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); | 127 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); |
128 | 128 |
129 [self internalSetSelected:selected_]; | 129 [self internalSetSelected:selected_]; |
130 } | 130 } |
131 | 131 |
132 // Called when Cocoa wants to display the context menu. Lazily instantiate | 132 // Called when Cocoa wants to display the context menu. Lazily instantiate |
133 // the menu based off of the cross-platform model. Re-create the menu and | 133 // the menu based off of the cross-platform model. Re-create the menu and |
134 // model every time to get the correct labels and enabling. | 134 // model every time to get the correct labels and enabling. |
135 - (NSMenu*)menu { | 135 - (NSMenu*)menu { |
136 contextMenuDelegate_.reset( | 136 contextMenuDelegate_.reset( |
137 new TabControllerInternal::MenuDelegate(target_, self)); | 137 new TabControllerInternal::MenuDelegate(target_, self)); |
138 contextMenuModel_.reset(new TabMenuModel(contextMenuDelegate_.get(), | 138 contextMenuModel_.reset( |
139 [self pinned])); | 139 [target_ contextMenuModelForController:self |
| 140 menuDelegate:contextMenuDelegate_.get()]); |
140 contextMenuController_.reset( | 141 contextMenuController_.reset( |
141 [[MenuController alloc] initWithModel:contextMenuModel_.get() | 142 [[MenuController alloc] initWithModel:contextMenuModel_.get() |
142 useWithPopUpButtonCell:NO]); | 143 useWithPopUpButtonCell:NO]); |
143 return [contextMenuController_ menu]; | 144 return [contextMenuController_ menu]; |
144 } | 145 } |
145 | 146 |
146 - (IBAction)closeTab:(id)sender { | 147 - (IBAction)closeTab:(id)sender { |
147 if ([[self target] respondsToSelector:@selector(closeTab:)]) { | 148 if ([[self target] respondsToSelector:@selector(closeTab:)]) { |
148 [[self target] performSelector:@selector(closeTab:) | 149 [[self target] performSelector:@selector(closeTab:) |
149 withObject:[self view]]; | 150 withObject:[self view]]; |
150 } | 151 } |
151 } | 152 } |
152 | 153 |
153 - (void)setTitle:(NSString*)title { | 154 - (void)setTitle:(NSString*)title { |
154 [[self view] setToolTip:title]; | 155 [[self view] setToolTip:title]; |
155 if ([self mini] && ![self selected]) { | 156 if ([self mini] && ![self selected]) { |
156 TabView* tabView = static_cast<TabView*>([self view]); | 157 TabView* tabView = static_cast<TabView*>([self view]); |
157 DCHECK([tabView isKindOfClass:[TabView class]]); | 158 DCHECK([tabView isKindOfClass:[TabView class]]); |
158 [tabView startAlert]; | 159 [tabView startAlert]; |
159 } | 160 } |
160 [super setTitle:title]; | 161 [super setTitle:title]; |
161 } | 162 } |
162 | 163 |
| 164 - (void)setActive:(BOOL)active { |
| 165 if (active != active_) { |
| 166 active_ = active; |
| 167 [self internalSetSelected:[self selected]]; |
| 168 } |
| 169 } |
| 170 |
| 171 - (BOOL)active { |
| 172 return active_; |
| 173 } |
| 174 |
163 - (void)setSelected:(BOOL)selected { | 175 - (void)setSelected:(BOOL)selected { |
164 if (selected_ != selected) | 176 if (selected_ != selected) { |
165 [self internalSetSelected:selected]; | 177 selected_ = selected; |
| 178 [self internalSetSelected:[self selected]]; |
| 179 } |
166 } | 180 } |
167 | 181 |
168 - (BOOL)selected { | 182 - (BOOL)selected { |
169 return selected_; | 183 return selected_ || active_; |
170 } | 184 } |
171 | 185 |
172 - (void)setIconView:(NSView*)iconView { | 186 - (void)setIconView:(NSView*)iconView { |
173 [iconView_ removeFromSuperview]; | 187 [iconView_ removeFromSuperview]; |
174 iconView_ = iconView; | 188 iconView_ = iconView; |
175 if ([self app]) { | 189 if ([self app]) { |
176 NSRect appIconFrame = [iconView frame]; | 190 NSRect appIconFrame = [iconView frame]; |
177 appIconFrame.origin = originalIconFrame_.origin; | 191 appIconFrame.origin = originalIconFrame_.origin; |
178 // Center the icon. | 192 // Center the icon. |
179 appIconFrame.origin.x = ([TabController appTabWidth] - | 193 appIconFrame.origin.x = ([TabController appTabWidth] - |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 DCHECK([[titleView_ cell] isKindOfClass: | 324 DCHECK([[titleView_ cell] isKindOfClass: |
311 [GTMFadeTruncatingTextFieldCell class]]); | 325 [GTMFadeTruncatingTextFieldCell class]]); |
312 GTMFadeTruncatingTextFieldCell* cell = [titleView_ cell]; | 326 GTMFadeTruncatingTextFieldCell* cell = [titleView_ cell]; |
313 [cell setDesiredCharactersToTruncateFromHead:length - | 327 [cell setDesiredCharactersToTruncateFromHead:length - |
314 TitlePrefixMatcher::kCommonCharsToShow]; | 328 TitlePrefixMatcher::kCommonCharsToShow]; |
315 [cell setTruncateMode:length > TitlePrefixMatcher::kMinElidingLength ? | 329 [cell setTruncateMode:length > TitlePrefixMatcher::kMinElidingLength ? |
316 GTMFadeTruncatingHeadAndTail : GTMFadeTruncatingTail]; | 330 GTMFadeTruncatingHeadAndTail : GTMFadeTruncatingTail]; |
317 } | 331 } |
318 | 332 |
319 @end | 333 @end |
OLD | NEW |