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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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:| but doesn't check if we're already set |
102 // to |selected|. Pass the selection change to the subviews that need it and | 102 // to |selected|. Pass the selection change to the subviews that need it and |
103 // mark ourselves as needing a redraw. | 103 // mark ourselves as needing a redraw. |
104 - (void)internalSetSelected:(BOOL)selected { | 104 - (void)internalSetSelected:(BOOL)selected { |
Avi (use Gerrit)
2011/04/08 15:22:20
I'm a little fuzzy on what this function is suppos
Robert Sesek
2011/04/09 14:23:07
The only thing that may not be appropriate is canc
| |
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 [tabView cancelAlert]; |
110 [self updateVisibility]; | 109 [self updateVisibility]; |
111 [self updateTitleColor]; | 110 [self updateTitleColor]; |
112 } | 111 } |
113 | 112 |
114 // Called when the tab's nib is done loading and all outlets are hooked up. | 113 // Called when the tab's nib is done loading and all outlets are hooked up. |
115 - (void)awakeFromNib { | 114 - (void)awakeFromNib { |
(...skipping 12 matching lines...) Expand all Loading... | |
128 | 127 |
129 [self internalSetSelected:selected_]; | 128 [self internalSetSelected:selected_]; |
130 } | 129 } |
131 | 130 |
132 // Called when Cocoa wants to display the context menu. Lazily instantiate | 131 // 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 | 132 // 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. | 133 // model every time to get the correct labels and enabling. |
135 - (NSMenu*)menu { | 134 - (NSMenu*)menu { |
136 contextMenuDelegate_.reset( | 135 contextMenuDelegate_.reset( |
137 new TabControllerInternal::MenuDelegate(target_, self)); | 136 new TabControllerInternal::MenuDelegate(target_, self)); |
138 contextMenuModel_.reset(new TabMenuModel(contextMenuDelegate_.get(), | 137 contextMenuModel_.reset( |
139 [self pinned])); | 138 [target_ contextMenuModelForController:self |
139 menuDelegate:contextMenuDelegate_.get()]); | |
140 contextMenuController_.reset( | 140 contextMenuController_.reset( |
141 [[MenuController alloc] initWithModel:contextMenuModel_.get() | 141 [[MenuController alloc] initWithModel:contextMenuModel_.get() |
142 useWithPopUpButtonCell:NO]); | 142 useWithPopUpButtonCell:NO]); |
143 return [contextMenuController_ menu]; | 143 return [contextMenuController_ menu]; |
144 } | 144 } |
145 | 145 |
146 - (IBAction)closeTab:(id)sender { | 146 - (IBAction)closeTab:(id)sender { |
147 if ([[self target] respondsToSelector:@selector(closeTab:)]) { | 147 if ([[self target] respondsToSelector:@selector(closeTab:)]) { |
148 [[self target] performSelector:@selector(closeTab:) | 148 [[self target] performSelector:@selector(closeTab:) |
149 withObject:[self view]]; | 149 withObject:[self view]]; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 - (void)setTitle:(NSString*)title { | 153 - (void)setTitle:(NSString*)title { |
154 [[self view] setToolTip:title]; | 154 [[self view] setToolTip:title]; |
155 if ([self mini] && ![self selected]) { | 155 if ([self mini] && ![self selected]) { |
156 TabView* tabView = static_cast<TabView*>([self view]); | 156 TabView* tabView = static_cast<TabView*>([self view]); |
157 DCHECK([tabView isKindOfClass:[TabView class]]); | 157 DCHECK([tabView isKindOfClass:[TabView class]]); |
158 [tabView startAlert]; | 158 [tabView startAlert]; |
159 } | 159 } |
160 [super setTitle:title]; | 160 [super setTitle:title]; |
161 } | 161 } |
162 | 162 |
163 - (void)setActive:(BOOL)active { | |
164 if (active != active_) { | |
165 active_ = active; | |
166 [self internalSetSelected:[self selected]]; | |
167 } | |
168 } | |
169 | |
170 - (BOOL)active { | |
171 return active_; | |
172 } | |
173 | |
163 - (void)setSelected:(BOOL)selected { | 174 - (void)setSelected:(BOOL)selected { |
164 if (selected_ != selected) | 175 if (selected_ != selected) { |
165 [self internalSetSelected:selected]; | 176 selected_ = selected; |
177 [self internalSetSelected:[self selected]]; | |
178 } | |
166 } | 179 } |
167 | 180 |
168 - (BOOL)selected { | 181 - (BOOL)selected { |
169 return selected_; | 182 return selected_ || active_; |
170 } | 183 } |
171 | 184 |
172 - (void)setIconView:(NSView*)iconView { | 185 - (void)setIconView:(NSView*)iconView { |
173 [iconView_ removeFromSuperview]; | 186 [iconView_ removeFromSuperview]; |
174 iconView_ = iconView; | 187 iconView_ = iconView; |
175 if ([self app]) { | 188 if ([self app]) { |
176 NSRect appIconFrame = [iconView frame]; | 189 NSRect appIconFrame = [iconView frame]; |
177 appIconFrame.origin = originalIconFrame_.origin; | 190 appIconFrame.origin = originalIconFrame_.origin; |
178 // Center the icon. | 191 // Center the icon. |
179 appIconFrame.origin.x = ([TabController appTabWidth] - | 192 appIconFrame.origin.x = ([TabController appTabWidth] - |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 DCHECK([[titleView_ cell] isKindOfClass: | 323 DCHECK([[titleView_ cell] isKindOfClass: |
311 [GTMFadeTruncatingTextFieldCell class]]); | 324 [GTMFadeTruncatingTextFieldCell class]]); |
312 GTMFadeTruncatingTextFieldCell* cell = [titleView_ cell]; | 325 GTMFadeTruncatingTextFieldCell* cell = [titleView_ cell]; |
313 [cell setDesiredCharactersToTruncateFromHead:length - | 326 [cell setDesiredCharactersToTruncateFromHead:length - |
314 TitlePrefixMatcher::kCommonCharsToShow]; | 327 TitlePrefixMatcher::kCommonCharsToShow]; |
315 [cell setTruncateMode:length > TitlePrefixMatcher::kMinElidingLength ? | 328 [cell setTruncateMode:length > TitlePrefixMatcher::kMinElidingLength ? |
316 GTMFadeTruncatingHeadAndTail : GTMFadeTruncatingTail]; | 329 GTMFadeTruncatingHeadAndTail : GTMFadeTruncatingTail]; |
317 } | 330 } |
318 | 331 |
319 @end | 332 @end |
OLD | NEW |