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

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

Issue 117533002: [Mac] Redesign of the avatar menu button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/prefs/scoped_user_pref_update.h" 12 #include "base/prefs/scoped_user_pref_update.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/fullscreen.h" 14 #include "chrome/browser/fullscreen.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_info_util.h" 16 #include "chrome/browser/profiles/profile_info_util.h"
17 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 17 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_window_state.h" 19 #include "chrome/browser/ui/browser_window_state.h"
20 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" 20 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
21 #import "chrome/browser/ui/cocoa/browser/avatar_icon_controller.h"
21 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" 22 #import "chrome/browser/ui/cocoa/dev_tools_controller.h"
22 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 23 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
23 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 24 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
24 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h" 25 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h"
25 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 26 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
26 #import "chrome/browser/ui/cocoa/fullscreen_mode_controller.h" 27 #import "chrome/browser/ui/cocoa/fullscreen_mode_controller.h"
27 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 28 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
28 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 29 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
29 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 30 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
30 #import "chrome/browser/ui/cocoa/nsview_additions.h" 31 #import "chrome/browser/ui/cocoa/nsview_additions.h"
(...skipping 18 matching lines...) Expand all
49 50
50 namespace { 51 namespace {
51 52
52 // Space between the incognito badge and the right edge of the window. 53 // Space between the incognito badge and the right edge of the window.
53 const CGFloat kAvatarRightOffset = 4; 54 const CGFloat kAvatarRightOffset = 4;
54 55
55 // The amount by which to shrink the tab strip (on the right) when the 56 // The amount by which to shrink the tab strip (on the right) when the
56 // incognito badge is present. 57 // incognito badge is present.
57 const CGFloat kAvatarTabStripShrink = 18; 58 const CGFloat kAvatarTabStripShrink = 18;
58 59
60 // Width of the full screen icon. Used to position the AvatarButton to the
61 // left of the icon.
62 const CGFloat kFullscreenIconWidth = 30;
63
59 // Insets for the location bar, used when the full toolbar is hidden. 64 // Insets for the location bar, used when the full toolbar is hidden.
60 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the 65 // TODO(viettrungluu): We can argue about the "correct" insetting; I like the
61 // following best, though arguably 0 inset is better/more correct. 66 // following best, though arguably 0 inset is better/more correct.
62 const CGFloat kLocBarLeftRightInset = 1; 67 const CGFloat kLocBarLeftRightInset = 1;
63 const CGFloat kLocBarTopInset = 0; 68 const CGFloat kLocBarTopInset = 0;
64 const CGFloat kLocBarBottomInset = 1; 69 const CGFloat kLocBarBottomInset = 1;
65 70
66 } // namespace 71 } // namespace
67 72
68 @implementation BrowserWindowController(Private) 73 @implementation BrowserWindowController(Private)
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)]; 314 [tabStripView setFrame:NSMakeRect(0, maxY, width, tabStripHeight)];
310 315
311 // Set left indentation based on fullscreen mode status. 316 // Set left indentation based on fullscreen mode status.
312 [tabStripController_ setLeftIndentForControls:(fullscreen ? 0 : 317 [tabStripController_ setLeftIndentForControls:(fullscreen ? 0 :
313 [[tabStripController_ class] defaultLeftIndentForControls])]; 318 [[tabStripController_ class] defaultLeftIndentForControls])];
314 319
315 // Lay out the icognito/avatar badge because calculating the indentation on 320 // Lay out the icognito/avatar badge because calculating the indentation on
316 // the right depends on it. 321 // the right depends on it.
317 if ([self shouldShowAvatar]) { 322 if ([self shouldShowAvatar]) {
318 NSView* avatarButton = [avatarButtonController_ view]; 323 NSView* avatarButton = [avatarButtonController_ view];
319 CGFloat buttonHeight = std::min( 324 CGFloat badgeXOffset = -kAvatarRightOffset;
325 CGFloat badgeYOffset = 0;
326
327 if ([self shouldUseNewAvatarButton]) {
328 // The fullscreen icon is displayed to the right of the avatar button.
329 if (![self isFullscreen])
330 badgeXOffset -= kFullscreenIconWidth;
331
332 // Center the button vertically on the tabstrip.
333 badgeYOffset = (tabStripHeight - [avatarButton frame].size.height) /2;
Nico 2014/01/14 03:56:02 NSHeight([avatarButton frame]) …don't you need t
noms (inactive) 2014/01/15 22:07:47 I don't know how to test this (tabstrip needs to b
334 } else {
335 CGFloat buttonHeight = std::min(
320 static_cast<CGFloat>(profiles::kAvatarIconHeight), tabStripHeight); 336 static_cast<CGFloat>(profiles::kAvatarIconHeight), tabStripHeight);
321 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), 337 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
322 buttonHeight)]; 338 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth];
323 339 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]),
324 // Actually place the badge *above* |maxY|, by +2 to miss the divider. 340 buttonHeight)];
325 CGFloat badgeXOffset = -kAvatarRightOffset; 341 }
326 CGFloat badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth];
327 NSPoint origin = 342 NSPoint origin =
328 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, 343 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset,
329 maxY + badgeYOffset); 344 maxY + badgeYOffset);
330 [avatarButton setFrameOrigin:origin]; 345 [avatarButton setFrameOrigin:origin];
331 [avatarButton setHidden:NO]; // Make sure it's shown. 346 [avatarButton setHidden:NO]; // Make sure it's shown.
332 } 347 }
333 348
334 // Calculate the right indentation. The default indentation built into the 349 // Calculate the right indentation. The default indentation built into the
335 // tabstrip leaves enough room for the fullscreen button or presentation mode 350 // tabstrip leaves enough room for the fullscreen button or presentation mode
336 // toggle button on Lion. On non-Lion systems, the right indent needs to be 351 // toggle button on Lion. On non-Lion systems, the right indent needs to be
337 // adjusted to make room for the new tab button when an avatar is present. 352 // adjusted to make room for the new tab button when an avatar is present.
338 CGFloat rightIndent = 0; 353 CGFloat rightIndent = 0;
339 if (base::mac::IsOSLionOrLater() && 354 if (base::mac::IsOSLionOrLater() &&
340 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { 355 [[self window] isKindOfClass:[FramedBrowserWindow class]]) {
341 FramedBrowserWindow* window = 356 FramedBrowserWindow* window =
342 static_cast<FramedBrowserWindow*>([self window]); 357 static_cast<FramedBrowserWindow*>([self window]);
343 rightIndent += -[window fullScreenButtonOriginAdjustment].x; 358 rightIndent += -[window fullScreenButtonOriginAdjustment].x;
344 } else if ([self shouldShowAvatar]) { 359 } else if ([self shouldShowAvatar]) {
345 rightIndent += kAvatarTabStripShrink; 360 rightIndent += kAvatarTabStripShrink;
346 NSButton* labelButton = [avatarButtonController_ labelButtonView]; 361
347 if (labelButton) 362 if ([avatarButtonController_ isKindOfClass:[AvatarIconController class]]) {
348 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset; 363 NSButton* labelButton =
364 [static_cast<AvatarIconController*>(avatarButtonController_)
365 labelButtonView];
366 if (labelButton)
367 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset;
368 }
349 } 369 }
370
371 // If the new avatar button is displayed, we need to account for its width.
372 if ([self shouldShowAvatar] && [self shouldUseNewAvatarButton]) {
373 rightIndent += NSWidth([[avatarButtonController_ view] frame])
374 + kAvatarTabStripShrink;
Nico 2014/01/14 03:56:02 Isn't this what the else-if 4 lines above does? Sh
noms (inactive) 2014/01/15 22:07:47 Oops! Yes on all counts. On 2014/01/14 03:56:02, N
375 }
376
350 [tabStripController_ setRightIndentForControls:rightIndent]; 377 [tabStripController_ setRightIndentForControls:rightIndent];
351 378
352 // Go ahead and layout the tabs. 379 // Go ahead and layout the tabs.
353 [tabStripController_ layoutTabsWithoutAnimation]; 380 [tabStripController_ layoutTabsWithoutAnimation];
354 381
355 return maxY; 382 return maxY;
356 } 383 }
357 384
358 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX 385 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX
359 maxY:(CGFloat)maxY 386 maxY:(CGFloat)maxY
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // With this call, valgrind complains that a "Conditional jump or move depends 584 // With this call, valgrind complains that a "Conditional jump or move depends
558 // on uninitialised value(s)". The error happens in -[NSThemeFrame 585 // on uninitialised value(s)". The error happens in -[NSThemeFrame
559 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is 586 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is
560 // no visual impact. I have been unable to tickle it away with other window 587 // no visual impact. I have been unable to tickle it away with other window
561 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt. 588 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt.
562 [contentView setAutoresizesSubviews:YES]; 589 [contentView setAutoresizesSubviews:YES];
563 [destWindow setContentView:contentView]; 590 [destWindow setContentView:contentView];
564 591
565 // Move the incognito badge if present. 592 // Move the incognito badge if present.
566 if ([self shouldShowAvatar]) { 593 if ([self shouldShowAvatar]) {
567 [[avatarButtonController_ view] removeFromSuperview]; 594 NSView* avatarButtonView = [avatarButtonController_ view];
Nico 2014/01/14 03:56:02 Nice change!
noms (inactive) 2014/01/15 22:07:47 To preemptively balance the oops above, obviously.
568 [[avatarButtonController_ view] setHidden:YES]; // Will be shown in layout. 595
569 [[[destWindow contentView] superview] addSubview: 596 [avatarButtonView removeFromSuperview];
570 [avatarButtonController_ view]]; 597 [avatarButtonView setHidden:YES]; // Will be shown in layout.
598 [[[destWindow contentView] superview] addSubview: avatarButtonView];
571 } 599 }
572 600
573 // Add the tab strip after setting the content view and moving the incognito 601 // Add the tab strip after setting the content view and moving the incognito
574 // badge (if any), so that the tab strip will be on top (in the z-order). 602 // badge (if any), so that the tab strip will be on top (in the z-order).
575 if ([self hasTabStrip]) 603 if ([self hasTabStrip])
576 [[[destWindow contentView] superview] addSubview:tabStripView]; 604 [[[destWindow contentView] superview] addSubview:tabStripView];
577 605
578 [sourceWindow setWindowController:nil]; 606 [sourceWindow setWindowController:nil];
579 [self setWindow:destWindow]; 607 [self setWindow:destWindow];
580 [destWindow setWindowController:self]; 608 [destWindow setWindowController:self];
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 return browser_window_controller::kCoreAnimationEnabledLazy; 1039 return browser_window_controller::kCoreAnimationEnabledLazy;
1012 } 1040 }
1013 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 1041 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
1014 switches::kUseCoreAnimation) == "disabled") { 1042 switches::kUseCoreAnimation) == "disabled") {
1015 return browser_window_controller::kCoreAnimationDisabled; 1043 return browser_window_controller::kCoreAnimationDisabled;
1016 } 1044 }
1017 return browser_window_controller::kCoreAnimationEnabledAlways; 1045 return browser_window_controller::kCoreAnimationEnabledAlways;
1018 } 1046 }
1019 1047
1020 @end // @implementation BrowserWindowController(Private) 1048 @end // @implementation BrowserWindowController(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698