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

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

Issue 509012: P4b.
Patch Set: Created 11 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
« no previous file with comments | « chrome/app/nibs/TabView.xib ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/menu_controller.h" 7 #import "chrome/browser/cocoa/menu_controller.h"
8 #import "chrome/browser/cocoa/tab_controller.h" 8 #import "chrome/browser/cocoa/tab_controller.h"
9 #import "chrome/browser/cocoa/tab_controller_target.h" 9 #import "chrome/browser/cocoa/tab_controller_target.h"
10 #import "chrome/browser/cocoa/tab_view.h" 10 #import "chrome/browser/cocoa/tab_view.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Remember the icon's frame, so that if the icon is ever removed, a new 117 // Remember the icon's frame, so that if the icon is ever removed, a new
118 // one can later replace it in the proper location. 118 // one can later replace it in the proper location.
119 originalIconFrame_ = [iconView_ frame]; 119 originalIconFrame_ = [iconView_ frame];
120 120
121 // When the icon is removed, the title expands to the left to fill the space 121 // When the icon is removed, the title expands to the left to fill the space
122 // left by the icon. When the close button is removed, the title expands to 122 // left by the icon. When the close button is removed, the title expands to
123 // the right to fill its space. These are the amounts to expand and contract 123 // the right to fill its space. These are the amounts to expand and contract
124 // titleView_ under those conditions. 124 // titleView_ under those conditions.
125 NSRect titleFrame = [titleView_ frame]; 125 NSRect titleFrame = [titleView_ frame];
126 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_); 126 iconTitleXOffset_ = NSMinX(titleFrame) - NSMinX(originalIconFrame_);
127 titleCloseWidthOffset_ = NSMaxX([closeButton_ frame]) - NSMaxX(titleFrame); 127 titleCloseWidthOffset_ = NSMinX(originalIconFrame_) - NSMinX([closeButton_ fra me]);
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));
(...skipping 26 matching lines...) Expand all
164 [self internalSetSelected:selected]; 164 [self internalSetSelected:selected];
165 } 165 }
166 166
167 - (BOOL)selected { 167 - (BOOL)selected {
168 return selected_; 168 return selected_;
169 } 169 }
170 170
171 - (void)setIconView:(NSView*)iconView { 171 - (void)setIconView:(NSView*)iconView {
172 [iconView_ removeFromSuperview]; 172 [iconView_ removeFromSuperview];
173 iconView_ = iconView; 173 iconView_ = iconView;
174
175
176 NSLog(@"original frame: %@", NSStringFromRect(originalIconFrame_));
174 [iconView_ setFrame:originalIconFrame_]; 177 [iconView_ setFrame:originalIconFrame_];
175 178
176 // Ensure that the icon is suppressed if no icon is set or if the tab is too 179 // Ensure that the icon is suppressed if no icon is set or if the tab is too
177 // narrow to display one. 180 // narrow to display one.
178 [self updateVisibility]; 181 [self updateVisibility];
179 182
180 if (iconView_) 183 if (iconView_)
181 [[self view] addSubview:iconView_]; 184 [[self view] addSubview:iconView_];
182 } 185 }
183 186
184 - (NSView*)iconView { 187 - (NSView*)iconView {
185 return iconView_; 188 return iconView_;
186 } 189 }
187 190
188 - (NSString*)toolTip { 191 - (NSString*)toolTip {
189 return [[self view] toolTip]; 192 return [[self view] toolTip];
190 } 193 }
191 194
192 // Return a rough approximation of the number of icons we could fit in the 195 // Return a rough approximation of the number of icons we could fit in the
193 // tab. We never actually do this, but it's a helpful guide for determining 196 // tab. We never actually do this, but it's a helpful guide for determining
194 // how much space we have available. 197 // how much space we have available.
195 - (int)iconCapacity { 198 - (int)iconCapacity {
196 CGFloat width = NSMaxX([closeButton_ frame]) - NSMinX(originalIconFrame_); 199 CGFloat width = NSMaxX([titleView_ frame]) - NSMinX([closeButton_ frame]);
197 CGFloat iconWidth = NSWidth(originalIconFrame_); 200 CGFloat iconWidth = NSWidth(originalIconFrame_);
198 201
199 return width / iconWidth; 202 return width / iconWidth;
200 } 203 }
201 204
202 // Returns YES if we should show the icon. When tabs get too small, we clip 205 // Returns YES if we should show the icon. When tabs get too small, we clip
203 // the favicon before the close button for selected tabs, and prefer the 206 // the favicon before the close button for selected tabs, and prefer the
204 // favicon for unselected tabs. The icon can also be suppressed more directly 207 // favicon for unselected tabs. The icon can also be suppressed more directly
205 // by clearing iconView_. 208 // by clearing iconView_.
206 - (BOOL)shouldShowIcon { 209 - (BOOL)shouldShowIcon {
(...skipping 28 matching lines...) Expand all
235 isIconShowing_ = newShowIcon; 238 isIconShowing_ = newShowIcon;
236 239
237 // If the tab is pinned, hide the title. 240 // If the tab is pinned, hide the title.
238 [titleView_ setHidden:[self pinned]]; 241 [titleView_ setHidden:[self pinned]];
239 242
240 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES; 243 BOOL oldShowCloseButton = [closeButton_ isHidden] ? NO : YES;
241 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO; 244 BOOL newShowCloseButton = [self shouldShowCloseButton] ? YES : NO;
242 245
243 [closeButton_ setHidden:newShowCloseButton ? NO : YES]; 246 [closeButton_ setHidden:newShowCloseButton ? NO : YES];
244 247
245 // Adjust the title view based on changes to the icon's and close button's 248 CGFloat overlap = NSMinX([closeButton_ frame]);
246 // visibility. 249 CGFloat availWidth = NSWidth([[self view] frame]) - 2*overlap;
247 NSRect titleFrame = [titleView_ frame]; 250
251 if (oldShowCloseButton != newShowCloseButton) {
252 // Adjust the left edge of the title view according to the presence or
253 // absence of the close button.
254 if (newShowCloseButton) {
255 //availWidth -= titleCloseWidthOffset_;
256
257 // titleFrame.origin.x += titleCloseWidthOffset_;
258 // titleFrame.size.width -= titleCloseWidthOffset_;
259 } else {
260 // titleFrame.origin.x -= titleCloseWidthOffset_;
261 // titleFrame.size.width += titleCloseWidthOffset_;
262 }
263
264 // if (newShowCloseButton) {
265 // originalIconFrame_.origin.x += titleCloseWidthOffset_;
266 // } else {
267 // originalIconFrame_.origin.x -= titleCloseWidthOffset_;
268 // }
269 // [iconView_ setFrame:originalIconFrame_];
270 }
248 271
249 if (oldShowIcon != newShowIcon) { 272 if (oldShowIcon != newShowIcon) {
250 // Adjust the left edge of the title view according to the presence or 273 // Adjust the left edge of the title view according to the presence or
251 // absence of the icon view. 274 // absence of the icon view.
252 275
253 if (newShowIcon) { 276 if (newShowIcon) {
254 titleFrame.origin.x += iconTitleXOffset_; 277 //availWidth -= iconTitleXOffset_;
255 titleFrame.size.width -= iconTitleXOffset_; 278 // titleFrame.origin.x += iconTitleXOffset_;
279 // titleFrame.size.width -= iconTitleXOffset_;
256 } else { 280 } else {
257 titleFrame.origin.x -= iconTitleXOffset_; 281 // titleFrame.origin.x -= iconTitleXOffset_;
258 titleFrame.size.width += iconTitleXOffset_; 282 // titleFrame.size.width += iconTitleXOffset_;
259 } 283 }
260 } 284 }
261 285
262 if (oldShowCloseButton != newShowCloseButton) { 286
263 // Adjust the right edge of the title view according to the presence or 287 // Adjust the title view based on changes to the icon's and close button's
264 // absence of the close button. 288 // visibility.
265 if (newShowCloseButton) 289 [titleView_ sizeToFit];
266 titleFrame.size.width -= titleCloseWidthOffset_; 290 NSRect titleFrame = [titleView_ frame];
267 else 291
268 titleFrame.size.width += titleCloseWidthOffset_; 292 NSLog(@"r: %@", NSStringFromRect(titleFrame));
293
294
295 if (NSWidth(titleFrame) + titleCloseWidthOffset_ + iconTitleXOffset_ < availWi dth) { // assume close and icon are always visible for now
296 // center favicon and title
297 CGFloat delta = ((availWidth) - (iconTitleXOffset_ + NSWidth(titleFrame)))/2 ;
298 originalIconFrame_.origin.x = (overlap) + delta;
299 titleFrame.origin.x = originalIconFrame_.origin.x + iconTitleXOffset_;
300 } else {
301 // left-align favicon and title
302 originalIconFrame_.origin.x = (newShowCloseButton ? NSMinX([closeButton_ fra me]) : overlap) + titleCloseWidthOffset_;
303 titleFrame.origin.x = originalIconFrame_.origin.x + iconTitleXOffset_;
304 titleFrame.size.width = availWidth - titleCloseWidthOffset_ - iconTitleXOffs et_;
269 } 305 }
270 306
307
308
309 NSLog(@"r: %@", NSStringFromRect(titleFrame));
310
311 [iconView_ setFrame:originalIconFrame_];
271 [titleView_ setFrame:titleFrame]; 312 [titleView_ setFrame:titleFrame];
272 } 313 }
273 314
274 - (void)updateTitleColor { 315 - (void)updateTitleColor {
275 NSColor* titleColor = nil; 316 NSColor* titleColor = nil;
276 GTMTheme* theme = [[self view] gtm_theme]; 317 GTMTheme* theme = [[self view] gtm_theme];
277 if (![self selected]) { 318 if (![self selected]) {
278 titleColor = [theme textColorForStyle:GTMThemeStyleTabBarDeselected 319 titleColor = [theme textColorForStyle:GTMThemeStyleTabBarDeselected
279 state:GTMThemeStateActiveWindow]; 320 state:GTMThemeStateActiveWindow];
280 } 321 }
(...skipping 24 matching lines...) Expand all
305 // Called by the tabs to determine whether we are in rapid (tab) closure mode. 346 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
306 - (BOOL)inRapidClosureMode { 347 - (BOOL)inRapidClosureMode {
307 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { 348 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) {
308 return [[self target] performSelector:@selector(inRapidClosureMode)] ? 349 return [[self target] performSelector:@selector(inRapidClosureMode)] ?
309 YES : NO; 350 YES : NO;
310 } 351 }
311 return NO; 352 return NO;
312 } 353 }
313 354
314 @end 355 @end
OLDNEW
« no previous file with comments | « chrome/app/nibs/TabView.xib ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698