Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/ui/cocoa/tab_controller.mm

Issue 5703007: Mac: Correctly clip tab title... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 "app/l10n_util_mac.h" 5 #include "app/l10n_util_mac.h"
6 #include "base/mac_util.h" 6 #include "base/mac_util.h"
7 #import "chrome/browser/themes/browser_theme_provider.h" 7 #import "chrome/browser/themes/browser_theme_provider.h"
8 #import "chrome/browser/ui/cocoa/menu_controller.h" 8 #import "chrome/browser/ui/cocoa/menu_controller.h"
9 #import "chrome/browser/ui/cocoa/tab_controller.h" 9 #import "chrome/browser/ui/cocoa/tab_controller.h"
10 #import "chrome/browser/ui/cocoa/tab_controller_target.h" 10 #import "chrome/browser/ui/cocoa/tab_controller_target.h"
11 #import "chrome/browser/ui/cocoa/tab_view.h" 11 #import "chrome/browser/ui/cocoa/tab_view.h"
12 #import "chrome/browser/ui/cocoa/themed_window.h" 12 #import "chrome/browser/ui/cocoa/themed_window.h"
13 #import "chrome/common/extensions/extension.h" 13 #import "chrome/common/extensions/extension.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 15
16 @implementation TabController 16 @implementation TabController
17 17
18 @synthesize action = action_; 18 @synthesize action = action_;
19 @synthesize app = app_; 19 @synthesize app = app_;
20 @synthesize loadingState = loadingState_; 20 @synthesize loadingState = loadingState_;
21 @synthesize mini = mini_; 21 @synthesize mini = mini_;
22 @synthesize pinned = pinned_; 22 @synthesize pinned = pinned_;
23 @synthesize target = target_; 23 @synthesize target = target_;
24 @synthesize iconView = iconView_;
25 @synthesize titleView = titleView_;
26 @synthesize closeButton = closeButton_;
24 27
25 namespace TabControllerInternal { 28 namespace TabControllerInternal {
26 29
27 // A C++ delegate that handles enabling/disabling menu items and handling when 30 // A C++ delegate that handles enabling/disabling menu items and handling when
28 // a menu command is chosen. Also fixes up the menu item label for "pin/unpin 31 // a menu command is chosen. Also fixes up the menu item label for "pin/unpin
29 // tab". 32 // tab".
30 class MenuDelegate : public menus::SimpleMenuModel::Delegate { 33 class MenuDelegate : public menus::SimpleMenuModel::Delegate {
31 public: 34 public:
32 explicit MenuDelegate(id<TabControllerTarget> target, TabController* owner) 35 explicit MenuDelegate(id<TabControllerTarget> target, TabController* owner)
33 : target_(target), 36 : target_(target),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 110
108 // Called when the tab's nib is done loading and all outlets are hooked up. 111 // Called when the tab's nib is done loading and all outlets are hooked up.
109 - (void)awakeFromNib { 112 - (void)awakeFromNib {
110 // Remember the icon's frame, so that if the icon is ever removed, a new 113 // Remember the icon's frame, so that if the icon is ever removed, a new
111 // one can later replace it in the proper location. 114 // one can later replace it in the proper location.
112 originalIconFrame_ = [iconView_ frame]; 115 originalIconFrame_ = [iconView_ frame];
113 116
114 // When the icon is removed, the title expands to the left to fill the space 117 // When the icon is removed, the title expands to the left to fill the space
115 // left by the icon. When the close button is removed, the title expands to 118 // left by the icon. When the close button is removed, the title expands to
116 // the right to fill its space. These are the amounts to expand and contract 119 // the right to fill its space. These are the amounts to expand and contract
117 // titleView_ under those conditions. 120 // titleView_ under those conditions. We don't have to explicilty save the
121 // offset between the title and the close button since we can just get that
122 // value for the close button's frame.
118 NSRect titleFrame = [titleView_ frame]; 123 NSRect titleFrame = [titleView_ frame];
119 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); 124 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_);
120 titleCloseWidthOffset_ = NSMaxX([closeButton_ frame]) - NSMaxX(titleFrame);
121 125
122 [self internalSetSelected:selected_]; 126 [self internalSetSelected:selected_];
123 } 127 }
124 128
125 // Called when Cocoa wants to display the context menu. Lazily instantiate 129 // Called when Cocoa wants to display the context menu. Lazily instantiate
126 // the menu based off of the cross-platform model. Re-create the menu and 130 // the menu based off of the cross-platform model. Re-create the menu and
127 // model every time to get the correct labels and enabling. 131 // model every time to get the correct labels and enabling.
128 - (NSMenu*)menu { 132 - (NSMenu*)menu {
129 contextMenuDelegate_.reset( 133 contextMenuDelegate_.reset(
130 new TabControllerInternal::MenuDelegate(target_, self)); 134 new TabControllerInternal::MenuDelegate(target_, self));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 [iconView_ setFrame:originalIconFrame_]; 180 [iconView_ setFrame:originalIconFrame_];
177 } 181 }
178 // Ensure that the icon is suppressed if no icon is set or if the tab is too 182 // Ensure that the icon is suppressed if no icon is set or if the tab is too
179 // narrow to display one. 183 // narrow to display one.
180 [self updateVisibility]; 184 [self updateVisibility];
181 185
182 if (iconView_) 186 if (iconView_)
183 [[self view] addSubview:iconView_]; 187 [[self view] addSubview:iconView_];
184 } 188 }
185 189
186 - (NSView*)iconView {
187 return iconView_;
188 }
189
190 - (NSString*)toolTip { 190 - (NSString*)toolTip {
191 return [[self view] toolTip]; 191 return [[self view] toolTip];
192 } 192 }
193 193
194 // Return a rough approximation of the number of icons we could fit in the 194 // Return a rough approximation of the number of icons we could fit in the
195 // tab. We never actually do this, but it's a helpful guide for determining 195 // tab. We never actually do this, but it's a helpful guide for determining
196 // how much space we have available. 196 // how much space we have available.
197 - (int)iconCapacity { 197 - (int)iconCapacity {
198 CGFloat width = NSMaxX([closeButton_ frame]) - NSMinX(originalIconFrame_); 198 CGFloat width = NSMaxX([closeButton_ frame]) - NSMinX(originalIconFrame_);
199 CGFloat iconWidth = NSWidth(originalIconFrame_); 199 CGFloat iconWidth = NSWidth(originalIconFrame_);
(...skipping 23 matching lines...) Expand all
223 - (BOOL)shouldShowCloseButton { 223 - (BOOL)shouldShowCloseButton {
224 if ([self mini]) 224 if ([self mini])
225 return NO; 225 return NO;
226 return ([self selected] || [self iconCapacity] >= 3); 226 return ([self selected] || [self iconCapacity] >= 3);
227 } 227 }
228 228
229 - (void)updateVisibility { 229 - (void)updateVisibility {
230 // iconView_ may have been replaced or it may be nil, so [iconView_ isHidden] 230 // iconView_ may have been replaced or it may be nil, so [iconView_ isHidden]
231 // won't work. Instead, the state of the icon is tracked separately in 231 // won't work. Instead, the state of the icon is tracked separately in
232 // isIconShowing_. 232 // isIconShowing_.
233 BOOL oldShowIcon = isIconShowing_ ? YES : NO; 233 BOOL newShowIcon = [self shouldShowIcon];
234 BOOL newShowIcon = [self shouldShowIcon] ? YES : NO;
235 234
236 [iconView_ setHidden:newShowIcon ? NO : YES]; 235 [iconView_ setHidden:!newShowIcon];
237 isIconShowing_ = newShowIcon; 236 isIconShowing_ = newShowIcon;
238 237
239 // If the tab is a mini-tab, hide the title. 238 // If the tab is a mini-tab, hide the title.
240 [titleView_ setHidden:[self mini]]; 239 [titleView_ setHidden:[self mini]];
241 240
242 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES; 241 BOOL newShowCloseButton = [self shouldShowCloseButton];
243 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO;
244 242
245 [closeButton_ setHidden:newShowCloseButton ? NO : YES]; 243 [closeButton_ setHidden:!newShowCloseButton];
246 244
247 // Adjust the title view based on changes to the icon's and close button's 245 // Adjust the title view based on changes to the icon's and close button's
248 // visibility. 246 // visibility.
249 NSRect titleFrame = [titleView_ frame]; 247 NSRect oldTitleFrame = [titleView_ frame];
248 NSRect newTitleFrame;
249 newTitleFrame.size.height = oldTitleFrame.size.height;
250 newTitleFrame.origin.y = oldTitleFrame.origin.y;
250 251
251 if (oldShowIcon != newShowIcon) { 252 if (newShowIcon) {
252 // Adjust the left edge of the title view according to the presence or 253 newTitleFrame.origin.x = originalIconFrame_.origin.x + iconTitleXOffset_;
253 // absence of the icon view. 254 } else {
254 255 newTitleFrame.origin.x = originalIconFrame_.origin.x;
255 if (newShowIcon) {
256 titleFrame.origin.x += iconTitleXOffset_;
257 titleFrame.size.width -= iconTitleXOffset_;
258 } else {
259 titleFrame.origin.x -= iconTitleXOffset_;
260 titleFrame.size.width += iconTitleXOffset_;
261 }
262 } 256 }
263 257
264 if (oldShowCloseButton != newShowCloseButton) { 258 if (newShowCloseButton) {
265 // Adjust the right edge of the title view according to the presence or 259 newTitleFrame.size.width = NSMinX([closeButton_ frame]) -
266 // absence of the close button. 260 newTitleFrame.origin.x;
267 if (newShowCloseButton) 261 } else {
268 titleFrame.size.width -= titleCloseWidthOffset_; 262 newTitleFrame.size.width = NSMaxX([closeButton_ frame]) -
269 else 263 newTitleFrame.origin.x;
270 titleFrame.size.width += titleCloseWidthOffset_;
271 } 264 }
272 265
273 [titleView_ setFrame:titleFrame]; 266 [titleView_ setFrame:newTitleFrame];
274 } 267 }
275 268
276 - (void)updateTitleColor { 269 - (void)updateTitleColor {
277 NSColor* titleColor = nil; 270 NSColor* titleColor = nil;
278 ThemeProvider* theme = [[[self view] window] themeProvider]; 271 ThemeProvider* theme = [[[self view] window] themeProvider];
279 if (theme && ![self selected]) { 272 if (theme && ![self selected]) {
280 titleColor = 273 titleColor =
281 theme->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT, 274 theme->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT,
282 true); 275 true);
283 } 276 }
(...skipping 20 matching lines...) Expand all
304 // Called by the tabs to determine whether we are in rapid (tab) closure mode. 297 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
305 - (BOOL)inRapidClosureMode { 298 - (BOOL)inRapidClosureMode {
306 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { 299 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) {
307 return [[self target] performSelector:@selector(inRapidClosureMode)] ? 300 return [[self target] performSelector:@selector(inRapidClosureMode)] ?
308 YES : NO; 301 YES : NO;
309 } 302 }
310 return NO; 303 return NO;
311 } 304 }
312 305
313 @end 306 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tab_controller.h ('k') | chrome/browser/ui/cocoa/tab_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698