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

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"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 // Called when the tab's nib is done loading and all outlets are hooked up. 108 // Called when the tab's nib is done loading and all outlets are hooked up.
109 - (void)awakeFromNib { 109 - (void)awakeFromNib {
110 // Remember the icon's frame, so that if the icon is ever removed, a new 110 // 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. 111 // one can later replace it in the proper location.
112 originalIconFrame_ = [iconView_ frame]; 112 originalIconFrame_ = [iconView_ frame];
113 113
114 // When the icon is removed, the title expands to the left to fill the space 114 // 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 115 // 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 116 // the right to fill its space. These are the amounts to expand and contract
117 // titleView_ under those conditions. 117 // titleView_ under those conditions. We don't have to explicilty save the
118 // offset between the title and the close button since we can just get that
119 // value for the close button's frame.
118 NSRect titleFrame = [titleView_ frame]; 120 NSRect titleFrame = [titleView_ frame];
119 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); 121 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_);
120 titleCloseWidthOffset_ = NSMaxX([closeButton_ frame]) - NSMaxX(titleFrame);
121 122
122 [self internalSetSelected:selected_]; 123 [self internalSetSelected:selected_];
123 } 124 }
124 125
125 // Called when Cocoa wants to display the context menu. Lazily instantiate 126 // 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 127 // 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. 128 // model every time to get the correct labels and enabling.
128 - (NSMenu*)menu { 129 - (NSMenu*)menu {
129 contextMenuDelegate_.reset( 130 contextMenuDelegate_.reset(
130 new TabControllerInternal::MenuDelegate(target_, self)); 131 new TabControllerInternal::MenuDelegate(target_, self));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 220 }
220 221
221 // Returns YES if we should be showing the close button. The selected tab 222 // Returns YES if we should be showing the close button. The selected tab
222 // always shows the close button. 223 // always shows the close button.
223 - (BOOL)shouldShowCloseButton { 224 - (BOOL)shouldShowCloseButton {
224 if ([self mini]) 225 if ([self mini])
225 return NO; 226 return NO;
226 return ([self selected] || [self iconCapacity] >= 3); 227 return ([self selected] || [self iconCapacity] >= 3);
227 } 228 }
228 229
230 - (NSTextField*)titleView {
231 return titleView_;
232 }
233
234 - (HoverCloseButton*)closeButton {
235 return closeButton_;
236 }
237
229 - (void)updateVisibility { 238 - (void)updateVisibility {
230 // iconView_ may have been replaced or it may be nil, so [iconView_ isHidden] 239 // 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 240 // won't work. Instead, the state of the icon is tracked separately in
232 // isIconShowing_. 241 // isIconShowing_.
233 BOOL oldShowIcon = isIconShowing_ ? YES : NO;
234 BOOL newShowIcon = [self shouldShowIcon] ? YES : NO; 242 BOOL newShowIcon = [self shouldShowIcon] ? YES : NO;
viettrungluu 2010/12/14 00:19:50 The |? YES : NO| here is just strange. Could you g
sail 2010/12/14 01:59:53 Done.
235 243
236 [iconView_ setHidden:newShowIcon ? NO : YES]; 244 [iconView_ setHidden:newShowIcon ? NO : YES];
viettrungluu 2010/12/14 00:19:50 Ditto. Should just be |!newShowIcon|.
sail 2010/12/14 01:59:53 Done.
237 isIconShowing_ = newShowIcon; 245 isIconShowing_ = newShowIcon;
238 246
239 // If the tab is a mini-tab, hide the title. 247 // If the tab is a mini-tab, hide the title.
240 [titleView_ setHidden:[self mini]]; 248 [titleView_ setHidden:[self mini]];
241 249
242 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES;
243 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO; 250 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO;
viettrungluu 2010/12/14 00:19:50 Etc.
sail 2010/12/14 01:59:53 Done.
244 251
245 [closeButton_ setHidden:newShowCloseButton ? NO : YES]; 252 [closeButton_ setHidden:newShowCloseButton ? NO : YES];
246 253
247 // Adjust the title view based on changes to the icon's and close button's 254 // Adjust the title view based on changes to the icon's and close button's
248 // visibility. 255 // visibility.
249 NSRect titleFrame = [titleView_ frame]; 256 NSRect oldTitleFrame = [titleView_ frame];
257 NSRect newTitleFrame;
258 newTitleFrame.size.height = oldTitleFrame.size.height;
viettrungluu 2010/12/14 00:19:50 NSMakeRect and a couple of uses of ?: would be mor
sail 2010/12/14 01:59:53 Unfortunately I need a temporary variable here sin
259 newTitleFrame.origin.y = oldTitleFrame.origin.y;
250 260
251 if (oldShowIcon != newShowIcon) { 261 if (newShowIcon) {
252 // Adjust the left edge of the title view according to the presence or 262 newTitleFrame.origin.x = originalIconFrame_.origin.x + iconTitleXOffset_;
253 // absence of the icon view. 263 } else {
254 264 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 } 265 }
263 266
264 if (oldShowCloseButton != newShowCloseButton) { 267 if (newShowCloseButton) {
265 // Adjust the right edge of the title view according to the presence or 268 newTitleFrame.size.width = NSMinX([closeButton_ frame]) -
266 // absence of the close button. 269 NSMinX(newTitleFrame);
viettrungluu 2010/12/14 00:19:50 Presumably you may want to calculate the x-coordin
sail 2010/12/14 01:59:53 Done.
267 if (newShowCloseButton) 270 } else {
268 titleFrame.size.width -= titleCloseWidthOffset_; 271 newTitleFrame.size.width = NSMaxX([closeButton_ frame]) -
269 else 272 NSMinX(newTitleFrame);
viettrungluu 2010/12/14 00:19:50 "
sail 2010/12/14 01:59:53 Done.
270 titleFrame.size.width += titleCloseWidthOffset_;
271 } 273 }
272 274
273 [titleView_ setFrame:titleFrame]; 275 [titleView_ setFrame:newTitleFrame];
274 } 276 }
275 277
276 - (void)updateTitleColor { 278 - (void)updateTitleColor {
277 NSColor* titleColor = nil; 279 NSColor* titleColor = nil;
278 ThemeProvider* theme = [[[self view] window] themeProvider]; 280 ThemeProvider* theme = [[[self view] window] themeProvider];
279 if (theme && ![self selected]) { 281 if (theme && ![self selected]) {
280 titleColor = 282 titleColor =
281 theme->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT, 283 theme->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT,
282 true); 284 true);
283 } 285 }
(...skipping 20 matching lines...) Expand all
304 // Called by the tabs to determine whether we are in rapid (tab) closure mode. 306 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
305 - (BOOL)inRapidClosureMode { 307 - (BOOL)inRapidClosureMode {
306 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { 308 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) {
307 return [[self target] performSelector:@selector(inRapidClosureMode)] ? 309 return [[self target] performSelector:@selector(inRapidClosureMode)] ?
308 YES : NO; 310 YES : NO;
309 } 311 }
310 return NO; 312 return NO;
311 } 313 }
312 314
313 @end 315 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698