OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
46 #include "ui/base/ui_base_types.h" | 47 #include "ui/base/ui_base_types.h" |
47 | 48 |
48 using content::RenderWidgetHostView; | 49 using content::RenderWidgetHostView; |
49 using content::WebContents; | 50 using content::WebContents; |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 // Space between the incognito badge and the right edge of the window. | 54 // Space between the incognito badge and the right edge of the window. |
54 const CGFloat kAvatarRightOffset = 4; | 55 const CGFloat kAvatarRightOffset = 4; |
55 | 56 |
56 // The amount by which to shrink the tab strip (on the right) when the | |
57 // incognito badge is present. | |
58 const CGFloat kAvatarTabStripShrink = 18; | |
59 | |
60 // Width of the full screen icon. Used to position the AvatarButton to the | |
61 // left of the icon. | |
62 const CGFloat kFullscreenIconWidth = 32; | |
63 | |
64 // Insets for the location bar, used when the full toolbar is hidden. | 57 // Insets for the location bar, used when the full toolbar is hidden. |
65 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the | 58 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the |
66 // following best, though arguably 0 inset is better/more correct. | 59 // following best, though arguably 0 inset is better/more correct. |
67 const CGFloat kLocBarLeftRightInset = 1; | 60 const CGFloat kLocBarLeftRightInset = 1; |
68 const CGFloat kLocBarTopInset = 0; | 61 const CGFloat kLocBarTopInset = 0; |
69 const CGFloat kLocBarBottomInset = 1; | 62 const CGFloat kLocBarBottomInset = 1; |
70 | 63 |
71 } // namespace | 64 } // namespace |
72 | 65 |
73 @implementation BrowserWindowController(Private) | 66 @implementation BrowserWindowController(Private) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 CGFloat leftIndent = 0; | 335 CGFloat leftIndent = 0; |
343 if (!fullscreen || addControlsInFullscreen) | 336 if (!fullscreen || addControlsInFullscreen) |
344 leftIndent = [[tabStripController_ class] defaultLeftIndentForControls]; | 337 leftIndent = [[tabStripController_ class] defaultLeftIndentForControls]; |
345 [tabStripController_ setLeftIndentForControls:leftIndent]; | 338 [tabStripController_ setLeftIndentForControls:leftIndent]; |
346 | 339 |
347 if (addControlsInFullscreen) | 340 if (addControlsInFullscreen) |
348 [tabStripController_ addWindowControls]; | 341 [tabStripController_ addWindowControls]; |
349 else | 342 else |
350 [tabStripController_ removeWindowControls]; | 343 [tabStripController_ removeWindowControls]; |
351 | 344 |
345 // fullScreenButton is non-nil when isInAnyFullscreenMode is NO, and OS | |
346 // version is in the range 10.7 <= version <= 10.9. Starting with 10.10, the | |
347 // zoom/maximize button acts as the fullscreen button. | |
348 NSButton* fullScreenButton = | |
349 [[self window] standardWindowButton:NSWindowFullScreenButton]; | |
350 | |
352 // Lay out the icognito/avatar badge because calculating the indentation on | 351 // Lay out the icognito/avatar badge because calculating the indentation on |
353 // the right depends on it. | 352 // the right depends on it. |
354 NSView* avatarButton = [avatarButtonController_ view]; | 353 NSView* avatarButton = [avatarButtonController_ view]; |
355 if ([self shouldShowAvatar]) { | 354 if ([self shouldShowAvatar]) { |
356 CGFloat badgeXOffset = -kAvatarRightOffset; | 355 CGFloat badgeXOffset = -kAvatarRightOffset; |
357 CGFloat badgeYOffset = 0; | 356 CGFloat badgeYOffset = 0; |
358 CGFloat buttonHeight = NSHeight([avatarButton frame]); | 357 CGFloat buttonHeight = NSHeight([avatarButton frame]); |
359 | 358 |
360 if ([self shouldUseNewAvatarButton]) { | 359 if ([self shouldUseNewAvatarButton]) { |
361 // The fullscreen icon is displayed to the right of the avatar button. | 360 // The fullscreen icon is displayed to the right of the avatar button. |
362 if (![self isInAnyFullscreenMode]) | 361 if (![self isInAnyFullscreenMode] && fullScreenButton) |
363 badgeXOffset -= kFullscreenIconWidth; | 362 badgeXOffset -= width - NSMinX([fullScreenButton frame]); |
364 // Center the button vertically on the tabstrip. | 363 // Center the button vertically on the tabstrip. |
365 badgeYOffset = (tabStripHeight - buttonHeight) / 2; | 364 badgeYOffset = (tabStripHeight - buttonHeight) / 2; |
366 } else { | 365 } else { |
367 // Actually place the badge *above* |maxY|, by +2 to miss the divider. | 366 // Actually place the badge *above* |maxY|, by +2 to miss the divider. |
368 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; | 367 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth]; |
369 } | 368 } |
370 | 369 |
371 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), | 370 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), |
372 std::min(buttonHeight, tabStripHeight))]; | 371 std::min(buttonHeight, tabStripHeight))]; |
373 NSPoint origin = | 372 NSPoint origin = |
374 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, | 373 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, |
375 maxY + badgeYOffset); | 374 maxY + badgeYOffset); |
376 [avatarButton setFrameOrigin:origin]; | 375 [avatarButton setFrameOrigin:origin]; |
377 [avatarButton setHidden:NO]; // Make sure it's shown. | 376 [avatarButton setHidden:NO]; // Make sure it's shown. |
378 } | 377 } |
379 | 378 |
380 // Calculate the right indentation. The default indentation built into the | 379 // Calculate the right indentation. The default indentation built into the |
381 // tabstrip leaves enough room for the fullscreen button or presentation mode | 380 // tabstrip leaves enough room for the fullscreen button on Lion (10.7) to |
382 // toggle button on Lion. On non-Lion systems, the right indent needs to be | 381 // Mavericks (10.9). On 10.6 and >=10.10, the right indent needs to be |
383 // adjusted to make room for the new tab button when an avatar is present. | 382 // adjusted to make room for the new tab button when an avatar is present. |
384 CGFloat rightIndent = 0; | 383 CGFloat rightIndent = 0; |
385 if (base::mac::IsOSLionOrLater() && | 384 if (![self isInAnyFullscreenMode] && fullScreenButton) { |
erikchen
2014/09/11 01:20:54
The comment references OS versions, but your code
Andre
2014/09/11 02:54:25
It was intentional.
In 10.6 and 10.10, fullScreenB
| |
386 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { | 385 rightIndent = width - NSMinX([fullScreenButton frame]); |
387 FramedBrowserWindow* window = | |
388 static_cast<FramedBrowserWindow*>([self window]); | |
389 rightIndent += -[window fullScreenButtonOriginAdjustment].x; | |
390 | 386 |
391 if ([self shouldUseNewAvatarButton]) { | 387 if ([self shouldUseNewAvatarButton]) { |
392 // The new avatar is wider than the default indentation, so we need to | 388 // The new avatar button is to the left of the fullscreen button. |
393 // account for its width. | 389 // (The old avatar button is to the right). |
394 rightIndent += NSWidth([avatarButton frame]) + kAvatarTabStripShrink; | 390 rightIndent += NSWidth([avatarButton frame]) + kAvatarRightOffset; |
395 | |
396 // When the fullscreen icon is not displayed, return its width to the | |
397 // tabstrip. | |
398 if ([self isInAnyFullscreenMode]) | |
399 rightIndent -= kFullscreenIconWidth; | |
400 } | 391 } |
401 } else if ([self shouldShowAvatar]) { | 392 } else if ([self shouldShowAvatar]) { |
402 rightIndent += kAvatarTabStripShrink + | 393 rightIndent += NSWidth([avatarButton frame]) + kAvatarRightOffset; |
403 NSWidth([avatarButton frame]) + kAvatarRightOffset; | |
404 } | 394 } |
405 [tabStripController_ setRightIndentForControls:rightIndent]; | 395 [tabStripController_ setRightIndentForControls:rightIndent]; |
406 | 396 |
407 // Go ahead and layout the tabs. | 397 // Go ahead and layout the tabs. |
408 [tabStripController_ layoutTabsWithoutAnimation]; | 398 [tabStripController_ layoutTabsWithoutAnimation]; |
409 | 399 |
410 return maxY; | 400 return maxY; |
411 } | 401 } |
412 | 402 |
413 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX | 403 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 | 1169 |
1180 - (void)exitAppKitFullscreen { | 1170 - (void)exitAppKitFullscreen { |
1181 DCHECK(base::mac::IsOSLionOrLater()); | 1171 DCHECK(base::mac::IsOSLionOrLater()); |
1182 if (FramedBrowserWindow* framedBrowserWindow = | 1172 if (FramedBrowserWindow* framedBrowserWindow = |
1183 base::mac::ObjCCast<FramedBrowserWindow>([self window])) { | 1173 base::mac::ObjCCast<FramedBrowserWindow>([self window])) { |
1184 [framedBrowserWindow toggleSystemFullScreen]; | 1174 [framedBrowserWindow toggleSystemFullScreen]; |
1185 } | 1175 } |
1186 } | 1176 } |
1187 | 1177 |
1188 @end // @implementation BrowserWindowController(Private) | 1178 @end // @implementation BrowserWindowController(Private) |
OLD | NEW |