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

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: now with less incorrect usage of initializers 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;
320 static_cast<CGFloat>(profiles::kAvatarIconHeight), tabStripHeight); 325 CGFloat badgeYOffset = 0;
326 CGFloat buttonHeight;
327
328 if ([self shouldUseNewAvatarButton]) {
329 // The fullscreen icon is displayed to the right of the avatar button.
330 if (![self isFullscreen])
331 badgeXOffset -= kFullscreenIconWidth;
332
333 // Center the button vertically on the tabstrip.
334 buttonHeight = NSHeight([avatarButton frame]);
335 badgeYOffset = (tabStripHeight - buttonHeight) / 2;
336 } else {
337 buttonHeight = static_cast<CGFloat>(profiles::kAvatarIconHeight);
338 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
339 badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth];
340
Nico 2014/01/23 00:51:33 The two ifs in this file seem slightly icky; I'd t
noms (inactive) 2014/01/23 18:24:27 I have another small CL to fix some avatar button
341 }
321 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]), 342 [avatarButton setFrameSize:NSMakeSize(NSWidth([avatarButton frame]),
322 buttonHeight)]; 343 std::min(buttonHeight, tabStripHeight))];
323
324 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
325 CGFloat badgeXOffset = -kAvatarRightOffset;
326 CGFloat badgeYOffset = 2 * [[avatarButton superview] cr_lineWidth];
327 NSPoint origin = 344 NSPoint origin =
328 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset, 345 NSMakePoint(width - NSWidth([avatarButton frame]) + badgeXOffset,
329 maxY + badgeYOffset); 346 maxY + badgeYOffset);
330 [avatarButton setFrameOrigin:origin]; 347 [avatarButton setFrameOrigin:origin];
331 [avatarButton setHidden:NO]; // Make sure it's shown. 348 [avatarButton setHidden:NO]; // Make sure it's shown.
332 } 349 }
333 350
334 // Calculate the right indentation. The default indentation built into the 351 // Calculate the right indentation. The default indentation built into the
335 // tabstrip leaves enough room for the fullscreen button or presentation mode 352 // 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 353 // 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. 354 // adjusted to make room for the new tab button when an avatar is present.
338 CGFloat rightIndent = 0; 355 CGFloat rightIndent = 0;
339 if (base::mac::IsOSLionOrLater() && 356 if (base::mac::IsOSLionOrLater() &&
340 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { 357 [[self window] isKindOfClass:[FramedBrowserWindow class]]) {
341 FramedBrowserWindow* window = 358 FramedBrowserWindow* window =
342 static_cast<FramedBrowserWindow*>([self window]); 359 static_cast<FramedBrowserWindow*>([self window]);
343 rightIndent += -[window fullScreenButtonOriginAdjustment].x; 360 rightIndent += -[window fullScreenButtonOriginAdjustment].x;
344 } else if ([self shouldShowAvatar]) { 361 } else if ([self shouldShowAvatar]) {
345 rightIndent += kAvatarTabStripShrink; 362 rightIndent += kAvatarTabStripShrink;
346 NSButton* labelButton = [avatarButtonController_ labelButtonView]; 363 if ([self shouldUseNewAvatarButton]) {
347 if (labelButton) 364 rightIndent += NSWidth([[avatarButtonController_ view] frame])
348 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset; 365 + kAvatarTabStripShrink;
366 } else {
367 NSButton* labelButton =
368 [static_cast<AvatarIconController*>(avatarButtonController_)
369 labelButtonView];
370 if (labelButton)
371 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset;
372 }
349 } 373 }
350 [tabStripController_ setRightIndentForControls:rightIndent]; 374 [tabStripController_ setRightIndentForControls:rightIndent];
351 375
352 // Go ahead and layout the tabs. 376 // Go ahead and layout the tabs.
353 [tabStripController_ layoutTabsWithoutAnimation]; 377 [tabStripController_ layoutTabsWithoutAnimation];
354 378
355 return maxY; 379 return maxY;
356 } 380 }
357 381
358 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX 382 - (CGFloat)layoutToolbarAtMinX:(CGFloat)minX
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // With this call, valgrind complains that a "Conditional jump or move depends 581 // With this call, valgrind complains that a "Conditional jump or move depends
558 // on uninitialised value(s)". The error happens in -[NSThemeFrame 582 // on uninitialised value(s)". The error happens in -[NSThemeFrame
559 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is 583 // 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 584 // 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. 585 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt.
562 [contentView setAutoresizesSubviews:YES]; 586 [contentView setAutoresizesSubviews:YES];
563 [destWindow setContentView:contentView]; 587 [destWindow setContentView:contentView];
564 588
565 // Move the incognito badge if present. 589 // Move the incognito badge if present.
566 if ([self shouldShowAvatar]) { 590 if ([self shouldShowAvatar]) {
567 [[avatarButtonController_ view] removeFromSuperview]; 591 NSView* avatarButtonView = [avatarButtonController_ view];
568 [[avatarButtonController_ view] setHidden:YES]; // Will be shown in layout. 592
569 [[[destWindow contentView] superview] addSubview: 593 [avatarButtonView removeFromSuperview];
570 [avatarButtonController_ view]]; 594 [avatarButtonView setHidden:YES]; // Will be shown in layout.
595 [[[destWindow contentView] superview] addSubview: avatarButtonView];
571 } 596 }
572 597
573 // Add the tab strip after setting the content view and moving the incognito 598 // 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). 599 // badge (if any), so that the tab strip will be on top (in the z-order).
575 if ([self hasTabStrip]) 600 if ([self hasTabStrip])
576 [[[destWindow contentView] superview] addSubview:tabStripView]; 601 [[[destWindow contentView] superview] addSubview:tabStripView];
577 602
578 [sourceWindow setWindowController:nil]; 603 [sourceWindow setWindowController:nil];
579 [self setWindow:destWindow]; 604 [self setWindow:destWindow];
580 [destWindow setWindowController:self]; 605 [destWindow setWindowController:self];
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 return browser_window_controller::kCoreAnimationEnabledLazy; 1036 return browser_window_controller::kCoreAnimationEnabledLazy;
1012 } 1037 }
1013 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 1038 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
1014 switches::kUseCoreAnimation) == "disabled") { 1039 switches::kUseCoreAnimation) == "disabled") {
1015 return browser_window_controller::kCoreAnimationDisabled; 1040 return browser_window_controller::kCoreAnimationDisabled;
1016 } 1041 }
1017 return browser_window_controller::kCoreAnimationEnabledAlways; 1042 return browser_window_controller::kCoreAnimationEnabledAlways;
1018 } 1043 }
1019 1044
1020 @end // @implementation BrowserWindowController(Private) 1045 @end // @implementation BrowserWindowController(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698