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

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

Issue 476313003: Mac: Improve tab strip layout in case of overflow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #import "base/mac/sdk_forward_declarations.h"
12 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
13 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/fullscreen.h" 16 #include "chrome/browser/fullscreen.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 18 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
18 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 19 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_window_state.h" 21 #include "chrome/browser/ui/browser_window_state.h"
21 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" 22 #import "chrome/browser/ui/cocoa/dev_tools_controller.h"
(...skipping 25 matching lines...) Expand all
47 #include "ui/base/ui_base_types.h" 48 #include "ui/base/ui_base_types.h"
48 49
49 using content::RenderWidgetHostView; 50 using content::RenderWidgetHostView;
50 using content::WebContents; 51 using content::WebContents;
51 52
52 namespace { 53 namespace {
53 54
54 // Space between the incognito badge and the right edge of the window. 55 // Space between the incognito badge and the right edge of the window.
55 const CGFloat kAvatarRightOffset = 4; 56 const CGFloat kAvatarRightOffset = 4;
56 57
57 // The amount by which to shrink the tab strip (on the right) when the
58 // incognito badge is present.
59 const CGFloat kAvatarTabStripShrink = 18;
Andre 2014/08/28 16:34:28 This seems to be originally used as the width of t
60
61 // Width of the full screen icon. Used to position the AvatarButton to the
62 // left of the icon.
63 const CGFloat kFullscreenIconWidth = 32;
Andre 2014/08/28 16:34:28 The fullscreen icon is actually 16pt wide. We were
64
65 // Insets for the location bar, used when the full toolbar is hidden. 58 // Insets for the location bar, used when the full toolbar is hidden.
66 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the 59 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the
67 // following best, though arguably 0 inset is better/more correct. 60 // following best, though arguably 0 inset is better/more correct.
68 const CGFloat kLocBarLeftRightInset = 1; 61 const CGFloat kLocBarLeftRightInset = 1;
69 const CGFloat kLocBarTopInset = 0; 62 const CGFloat kLocBarTopInset = 0;
70 const CGFloat kLocBarBottomInset = 1; 63 const CGFloat kLocBarBottomInset = 1;
71 64
72 } // namespace 65 } // namespace
73 66
74 @implementation BrowserWindowController(Private) 67 @implementation BrowserWindowController(Private)
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 maxY -= tabStripHeight; 307 maxY -= tabStripHeight;
315 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)]; 308 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)];
316 309
317 // Set left indentation based on fullscreen mode status. 310 // Set left indentation based on fullscreen mode status.
318 [tabStripController_ setLeftIndentForControls:(fullscreen ? 0 : 311 [tabStripController_ setLeftIndentForControls:(fullscreen ? 0 :
319 [[tabStripController_ class] defaultLeftIndentForControls])]; 312 [[tabStripController_ class] defaultLeftIndentForControls])];
320 313
321 // Lay out the icognito/avatar badge because calculating the indentation on 314 // Lay out the icognito/avatar badge because calculating the indentation on
322 // the right depends on it. 315 // the right depends on it.
323 NSView* avatarButton = [avatarButtonController_ view]; 316 NSView* avatarButton = [avatarButtonController_ view];
317 NSButton* fullScreenButton =
318 [[self window] standardWindowButton:NSWindowFullScreenButton];
Robert Sesek 2014/09/02 18:17:49 This returns nil on 10.6, yes? (Rather than say, t
Andre 2014/09/02 23:09:05 Yes it does. And turns out, it returns nil on Yose
319
324 if ([self shouldShowAvatar]) { 320 if ([self shouldShowAvatar]) {
325 CGFloat badgeXOffset = -kAvatarRightOffset; 321 CGFloat badgeXOffset = -kAvatarRightOffset;
326 CGFloat badgeYOffset = 0; 322 CGFloat badgeYOffset = 0;
327 CGFloat buttonHeight = NSHeight([avatarButton frame]); 323 CGFloat buttonHeight = NSHeight([avatarButton frame]);
328 324
329 if ([self shouldUseNewAvatarButton]) { 325 if ([self shouldUseNewAvatarButton]) {
330 // The fullscreen icon is displayed to the right of the avatar button. 326 // The fullscreen icon is displayed to the right of the avatar button.
331 if (![self isFullscreen]) 327 if (![self isFullscreen] && fullScreenButton)
332 badgeXOffset -= kFullscreenIconWidth; 328 badgeXOffset -= width - NSMinX([fullScreenButton frame]);
Andre 2014/08/28 16:34:28 Width is not enough, we also need to offset for it
333 // Center the button vertically on the tabstrip. 329 // Center the button vertically on the tabstrip.
334 badgeYOffset = (tabStripHeight - buttonHeight) / 2; 330 badgeYOffset = (tabStripHeight - buttonHeight) / 2;
335 } else { 331 } else {
336 // Actually place the badge *above* |maxY|, by +2 to miss the divider. 332 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
337 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; 333 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth];
338 } 334 }
339 335
340 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), 336 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]),
341 std::min(buttonHeight, tabStripHeight))]; 337 std::min(buttonHeight, tabStripHeight))];
342 NSPoint origin = 338 NSPoint origin =
343 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, 339 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset,
344 maxY + badgeYOffset); 340 maxY + badgeYOffset);
345 [avatarButton setFrameOrigin:origin]; 341 [avatarButton setFrameOrigin:origin];
346 [avatarButton setHidden:NO]; // Make sure it's shown. 342 [avatarButton setHidden:NO]; // Make sure it's shown.
347 } 343 }
348 344
349 // Calculate the right indentation. The default indentation built into the 345 // Calculate the right indentation. The default indentation built into the
350 // tabstrip leaves enough room for the fullscreen button or presentation mode 346 // tabstrip leaves enough room for the fullscreen button or presentation mode
351 // toggle button on Lion. On non-Lion systems, the right indent needs to be 347 // toggle button on Lion. On non-Lion systems, the right indent needs to be
352 // adjusted to make room for the new tab button when an avatar is present. 348 // adjusted to make room for the new tab button when an avatar is present.
353 CGFloat rightIndent = 0; 349 CGFloat rightIndent = 0;
354 if (base::mac::IsOSLionOrLater() && 350 if (![self isFullscreen] && fullScreenButton) {
355 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { 351 rightIndent = width - NSMinX([fullScreenButton frame]);
356 FramedBrowserWindow* window =
357 static_cast<FramedBrowserWindow*>([self window]);
358 rightIndent += -[window fullScreenButtonOriginAdjustment].x;
Andre 2014/08/28 16:34:28 fullScreenButtonOriginAdjustment is not the amount
359 352
360 if ([self shouldUseNewAvatarButton]) { 353 if ([self shouldUseNewAvatarButton]) {
361 // The new avatar is wider than the default indentation, so we need to 354 // The new avatar button is to the left of the fullscreen button.
362 // account for its width. 355 // (The old avatar button is to the right).
363 rightIndent += NSWidth([avatarButton frame]) + kAvatarTabStripShrink; 356 rightIndent += NSWidth([avatarButton frame]) + kAvatarRightOffset;
364
365 // When the fullscreen icon is not displayed, return its width to the
366 // tabstrip.
367 if ([self isFullscreen])
368 rightIndent -= kFullscreenIconWidth;
369 } 357 }
370 } else if ([self shouldShowAvatar]) { 358 } else if ([self shouldShowAvatar]) {
371 rightIndent += kAvatarTabStripShrink + 359 rightIndent += NSWidth([avatarButton frame]) + kAvatarRightOffset;
372 NSWidth([avatarButton frame]) + kAvatarRightOffset;
373 } 360 }
374 [tabStripController_ setRightIndentForControls:rightIndent]; 361 [tabStripController_ setRightIndentForControls:rightIndent];
375 362
376 // Go ahead and layout the tabs. 363 // Go ahead and layout the tabs.
377 [tabStripController_ layoutTabsWithoutAnimation]; 364 [tabStripController_ layoutTabsWithoutAnimation];
378 365
379 return maxY; 366 return maxY;
380 } 367 }
381 368
382 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX 369 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 } 1039 }
1053 } 1040 }
1054 1041
1055 - (void)updateInfoBarTipVisibility { 1042 - (void)updateInfoBarTipVisibility {
1056 // If there's no toolbar then hide the infobar tip. 1043 // If there's no toolbar then hide the infobar tip.
1057 [infoBarContainerController_ 1044 [infoBarContainerController_
1058 setShouldSuppressTopInfoBarTip:![self hasToolbar]]; 1045 setShouldSuppressTopInfoBarTip:![self hasToolbar]];
1059 } 1046 }
1060 1047
1061 @end // @implementation BrowserWindowController(Private) 1048 @end // @implementation BrowserWindowController(Private)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/tabs/tab_controller.h » ('j') | chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698