Chromium Code Reviews| Index: chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm |
| index a8851d3e0b815ac94ffbbf0f206f3dbafa9bb665..32e28585cba50df16b5ff4eb1c8957a53e207730 100644 |
| --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm |
| +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm |
| @@ -230,18 +230,10 @@ @implementation ToolbarController |
| @synthesize browser = browser_; |
| + (CGFloat)locationBarHeight { |
| - if (!ui::MaterialDesignController::IsModeMaterial()) { |
| - return 29; |
| - } |
| - |
| return kMaterialDesignLocationBarHeight; |
| } |
| + (CGFloat)appMenuLeftPadding { |
| - if (!ui::MaterialDesignController::IsModeMaterial()) { |
| - return 3; |
| - } |
| - |
| return kMaterialDesignElementPadding; |
| } |
| @@ -302,141 +294,89 @@ - (void)viewDidLoad { |
| } |
| // Make Material Design layout adjustments to the NIB items. |
| - bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); |
| - if (isModeMaterial) { |
| - ToolbarView* toolbarView = [self toolbarView]; |
| - NSRect toolbarBounds = [toolbarView bounds]; |
| - NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
| - |
| - // Set the toolbar height. |
| - NSRect frame = [toolbarView frame]; |
| - frame.size.height = [self baseToolbarHeight]; |
| - [toolbarView setFrame:frame]; |
| - |
| - NSRect backButtonFrame = [backButton_ frame]; |
| - backButtonFrame.origin.x = |
| - kMaterialDesignElementPadding + kMaterialDesignButtonInset; |
| - backButtonFrame.origin.y = NSMaxY(toolbarBounds) - |
| - kMaterialDesignElementPadding - toolbarButtonSize.height; |
| - backButtonFrame.size = toolbarButtonSize; |
| - [backButton_ setFrame:backButtonFrame]; |
| - |
| - NSRect forwardButtonFrame = [forwardButton_ frame]; |
| - forwardButtonFrame.origin.x = |
| - NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; |
| - forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
| - forwardButtonFrame.size = toolbarButtonSize; |
| - [forwardButton_ setFrame:forwardButtonFrame]; |
| - |
| - NSRect reloadButtonFrame = [reloadButton_ frame]; |
| - reloadButtonFrame.origin.x = |
| - NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; |
| - reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
| - reloadButtonFrame.size = toolbarButtonSize; |
| - [reloadButton_ setFrame:reloadButtonFrame]; |
| - |
| - NSRect homeButtonFrame = [homeButton_ frame]; |
| - homeButtonFrame.origin.x = |
| - NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; |
| - homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
| - homeButtonFrame.size = toolbarButtonSize; |
| - [homeButton_ setFrame:homeButtonFrame]; |
| - |
| - // Replace the app button from the nib with an AppToolbarButton instance for |
| - // Material Design. |
| - AppToolbarButton* newMenuButton = |
| - [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
| - autorelease]; |
| - [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
| - [[appMenuButton_ superview] addSubview:newMenuButton]; |
| - [appMenuButton_ removeFromSuperview]; |
| - appMenuButton_ = newMenuButton; |
| - |
| - // Adjust the menu button's position. |
| - NSRect menuButtonFrame = [appMenuButton_ frame]; |
| - CGFloat menuButtonFrameMaxX = |
| - NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
| - menuButtonFrame.origin.x = |
| - menuButtonFrameMaxX - kMaterialDesignButtonInset - |
| - toolbarButtonSize.width; |
| - menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
| - menuButtonFrame.size = toolbarButtonSize; |
| - [appMenuButton_ setFrame:menuButtonFrame]; |
| - |
| - // Adjust the size and location on the location bar to take up the |
| - // space between the reload and menu buttons. |
| - NSRect locationBarFrame = [locationBar_ frame]; |
| - locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + |
| - kMaterialDesignButtonInset; |
| - if (![homeButton_ isHidden]) { |
| - // Ensure proper spacing between the home button and the location bar. |
| - locationBarFrame.origin.x += kMaterialDesignElementPadding; |
| - } |
| - locationBarFrame.origin.y = NSMaxY(toolbarBounds) - |
| - kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight; |
| - locationBarFrame.size.width = |
| - menuButtonFrame.origin.x - |
| - locationBarFrame.origin.x; |
| - locationBarFrame.size.height = kMaterialDesignLocationBarHeight; |
| - [locationBar_ setFrame:locationBarFrame]; |
| - |
| - // Correctly position the extension buttons' container view. |
| - NSRect containerFrame = [browserActionsContainerView_ frame]; |
| - containerFrame.size.width += kMaterialDesignButtonInset; |
| - containerFrame.origin.y = |
| - locationBarFrame.origin.y + kMaterialDesignContainerYOffset; |
| - containerFrame.size.height = toolbarButtonSize.height; |
| - [browserActionsContainerView_ setFrame:containerFrame]; |
| - } else { |
| - [[backButton_ cell] setImageID:IDR_BACK |
| - forButtonState:image_button_cell::kDefaultState]; |
| - [[backButton_ cell] setImageID:IDR_BACK_H |
| - forButtonState:image_button_cell::kHoverState]; |
| - [[backButton_ cell] setImageID:IDR_BACK_P |
| - forButtonState:image_button_cell::kPressedState]; |
| - [[backButton_ cell] setImageID:IDR_BACK_D |
| - forButtonState:image_button_cell::kDisabledState]; |
| - |
| - [[forwardButton_ cell] setImageID:IDR_FORWARD |
| - forButtonState:image_button_cell::kDefaultState]; |
| - [[forwardButton_ cell] setImageID:IDR_FORWARD_H |
| - forButtonState:image_button_cell::kHoverState]; |
| - [[forwardButton_ cell] setImageID:IDR_FORWARD_P |
| - forButtonState:image_button_cell::kPressedState]; |
| - [[forwardButton_ cell] setImageID:IDR_FORWARD_D |
| - forButtonState:image_button_cell::kDisabledState]; |
| - |
| - [[reloadButton_ cell] setImageID:IDR_RELOAD |
| - forButtonState:image_button_cell::kDefaultState]; |
| - [[reloadButton_ cell] setImageID:IDR_RELOAD_H |
| - forButtonState:image_button_cell::kHoverState]; |
| - [[reloadButton_ cell] setImageID:IDR_RELOAD_P |
| - forButtonState:image_button_cell::kPressedState]; |
| - |
| - [[homeButton_ cell] setImageID:IDR_HOME |
| - forButtonState:image_button_cell::kDefaultState]; |
| - [[homeButton_ cell] setImageID:IDR_HOME_H |
| - forButtonState:image_button_cell::kHoverState]; |
| - [[homeButton_ cell] setImageID:IDR_HOME_P |
| - forButtonState:image_button_cell::kPressedState]; |
| - |
| - [[appMenuButton_ cell] setImageID:IDR_TOOLS |
| - forButtonState:image_button_cell::kDefaultState]; |
| - [[appMenuButton_ cell] setImageID:IDR_TOOLS_H |
| - forButtonState:image_button_cell::kHoverState]; |
| - [[appMenuButton_ cell] setImageID:IDR_TOOLS_P |
| - forButtonState:image_button_cell::kPressedState]; |
| - |
| - // Adjust the toolbar height if running on Retina - see the comment in |
| - // -baseToolbarHeight. |
| - CGFloat toolbarHeight = [self baseToolbarHeight]; |
| - ToolbarView* toolbarView = [self toolbarView]; |
| - NSRect toolbarFrame = [toolbarView frame]; |
| - if (toolbarFrame.size.height != toolbarHeight) { |
| - toolbarFrame.size.height = toolbarHeight; |
| - [toolbarView setFrame:toolbarFrame]; |
| - } |
| + ToolbarView* toolbarView = [self toolbarView]; |
| + NSRect toolbarBounds = [toolbarView bounds]; |
| + NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
| + |
| + // Set the toolbar height. |
| + NSRect frame = [toolbarView frame]; |
| + frame.size.height = [self baseToolbarHeight]; |
| + [toolbarView setFrame:frame]; |
| + |
| + NSRect backButtonFrame = [backButton_ frame]; |
| + backButtonFrame.origin.x = |
| + kMaterialDesignElementPadding + kMaterialDesignButtonInset; |
| + backButtonFrame.origin.y = NSMaxY(toolbarBounds) - |
| + kMaterialDesignElementPadding - toolbarButtonSize.height; |
| + backButtonFrame.size = toolbarButtonSize; |
| + [backButton_ setFrame:backButtonFrame]; |
| + |
| + NSRect forwardButtonFrame = [forwardButton_ frame]; |
| + forwardButtonFrame.origin.x = |
| + NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; |
| + forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
| + forwardButtonFrame.size = toolbarButtonSize; |
| + [forwardButton_ setFrame:forwardButtonFrame]; |
| + |
| + NSRect reloadButtonFrame = [reloadButton_ frame]; |
| + reloadButtonFrame.origin.x = |
| + NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; |
| + reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
| + reloadButtonFrame.size = toolbarButtonSize; |
| + [reloadButton_ setFrame:reloadButtonFrame]; |
| + |
| + NSRect homeButtonFrame = [homeButton_ frame]; |
| + homeButtonFrame.origin.x = |
| + NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; |
| + homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
| + homeButtonFrame.size = toolbarButtonSize; |
| + [homeButton_ setFrame:homeButtonFrame]; |
| + |
| + // Replace the app button from the nib with an AppToolbarButton instance for |
|
Evan Stade
2016/09/27 19:34:51
can you remove AppToolbarButtonCell now too?
|
| + // Material Design. |
|
Evan Stade
2016/09/27 19:34:51
nit: remove references to material design (since i
|
| + AppToolbarButton* newMenuButton = |
| + [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
| + autorelease]; |
| + [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
| + [[appMenuButton_ superview] addSubview:newMenuButton]; |
| + [appMenuButton_ removeFromSuperview]; |
| + appMenuButton_ = newMenuButton; |
| + |
| + // Adjust the menu button's position. |
| + NSRect menuButtonFrame = [appMenuButton_ frame]; |
| + CGFloat menuButtonFrameMaxX = |
| + NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
| + menuButtonFrame.origin.x = |
| + menuButtonFrameMaxX - kMaterialDesignButtonInset - |
| + toolbarButtonSize.width; |
| + menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
| + menuButtonFrame.size = toolbarButtonSize; |
| + [appMenuButton_ setFrame:menuButtonFrame]; |
| + |
| + // Adjust the size and location on the location bar to take up the |
| + // space between the reload and menu buttons. |
| + NSRect locationBarFrame = [locationBar_ frame]; |
| + locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + |
| + kMaterialDesignButtonInset; |
| + if (![homeButton_ isHidden]) { |
| + // Ensure proper spacing between the home button and the location bar. |
| + locationBarFrame.origin.x += kMaterialDesignElementPadding; |
| } |
| + locationBarFrame.origin.y = NSMaxY(toolbarBounds) - |
| + kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight; |
| + locationBarFrame.size.width = |
| + menuButtonFrame.origin.x - |
| + locationBarFrame.origin.x; |
| + locationBarFrame.size.height = kMaterialDesignLocationBarHeight; |
| + [locationBar_ setFrame:locationBarFrame]; |
| + |
| + // Correctly position the extension buttons' container view. |
| + NSRect containerFrame = [browserActionsContainerView_ frame]; |
| + containerFrame.size.width += kMaterialDesignButtonInset; |
| + containerFrame.origin.y = |
| + locationBarFrame.origin.y + kMaterialDesignContainerYOffset; |
| + containerFrame.size.height = toolbarButtonSize.height; |
| + [browserActionsContainerView_ setFrame:containerFrame]; |
| notificationBridge_.reset( |
| new ToolbarControllerInternal::NotificationBridge(self)); |
| @@ -472,10 +412,6 @@ - (void)viewDidLoad { |
| relativeTo:locationBar_]; |
| } |
| - if (!isModeMaterial) { |
| - [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| - } |
| - |
| // Register pref observers for the optional home and page/options buttons |
| // and then add them to the toolbar based on those prefs. |
| PrefService* prefs = profile_->GetPrefs(); |
| @@ -507,17 +443,17 @@ - (void)viewDidLoad { |
| NSTrackingActiveAlways |
| owner:self |
| userInfo:nil]); |
| - NSView* toolbarView = [self view]; |
| - [toolbarView addTrackingArea:trackingArea_.get()]; |
| + NSView* parentView = [self view]; |
| + [parentView addTrackingArea:trackingArea_.get()]; |
| // If the user has any Browser Actions installed, the container view for them |
| // may have to be resized depending on the width of the toolbar frame. |
| - [toolbarView setPostsFrameChangedNotifications:YES]; |
| + [parentView setPostsFrameChangedNotifications:YES]; |
| [[NSNotificationCenter defaultCenter] |
| addObserver:self |
| selector:@selector(toolbarFrameChanged) |
| name:NSViewFrameDidChangeNotification |
| - object:toolbarView]; |
| + object:parentView]; |
| // Set ViewIDs for toolbar elements which don't have their dedicated class. |
| // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
| @@ -800,12 +736,8 @@ - (void)showOptionalHomeButton { |
| // since the frame edges of each button are right on top of each other. When |
| // hiding the button, reverse the direction of the movement (to the left). |
| CGFloat moveX = [homeButton_ frame].size.width; |
| - if (!ui::MaterialDesignController::IsModeMaterial()) { |
| - moveX -= 1.0; |
| - } else { |
| - // Ensure proper spacing between the home button and the location bar. |
| - moveX += kMaterialDesignElementPadding; |
| - } |
| + // Ensure proper spacing between the home button and the location bar. |
| + moveX += kMaterialDesignElementPadding; |
| if (hide) |
| moveX *= -1; // Reverse the direction of the move. |
| @@ -829,12 +761,6 @@ - (void)installAppMenu { |
| - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity |
| iconType:(AppMenuIconController::IconType)iconType |
| animate:(BOOL)animate { |
| - if (!ui::MaterialDesignController::IsModeMaterial()) { |
| - AppToolbarButtonCell* cell = |
| - base::mac::ObjCCastStrict<AppToolbarButtonCell>([appMenuButton_ cell]); |
| - [cell setSeverity:severity shouldAnimate:animate]; |
| - return; |
| - } |
| AppToolbarButton* appMenuButton = |
| base::mac::ObjCCastStrict<AppToolbarButton>(appMenuButton_); |
| [appMenuButton setSeverity:severity iconType:iconType shouldAnimate:animate]; |
| @@ -927,9 +853,7 @@ - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { |
| locationBarXPos; |
| // Equalize the distance between the location bar and the first extension |
| // button, and the distance between the location bar and home/reload button. |
| - if (ui::MaterialDesignController::IsModeMaterial()) { |
| - leftDistance -= kMaterialDesignButtonInset; |
| - } |
| + leftDistance -= kMaterialDesignButtonInset; |
| } |
| if (leftDistance != 0.0) |
| [self adjustLocationSizeBy:leftDistance animate:animate]; |
| @@ -960,20 +884,8 @@ - (void)toolbarFrameChanged { |
| // it afterwards. |
| [browserActionsContainerView_ stopAnimation]; |
| NSRect containerFrame = [browserActionsContainerView_ frame]; |
| - if (!ui::MaterialDesignController::IsModeMaterial()) { |
| - CGFloat elementTopPadding = |
| - kMaterialDesignElementPadding + kMaterialDesignButtonInset; |
| - // Pre-Material Design, this value is calculated from the values in |
| - // Toolbar.xib: the height of the toolbar (35) minus the height of the |
| - // child elements (29) minus the y-origin of the elements (4). |
| - elementTopPadding = 2; |
| - containerFrame.origin.y = |
| - NSHeight([[self view] frame]) - NSHeight(containerFrame) - |
| - elementTopPadding; |
| - } else { |
| - containerFrame.origin.y = |
| - [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; |
| - } |
| + containerFrame.origin.y = |
| + [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; |
| [browserActionsContainerView_ setFrame:containerFrame]; |
| [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| } |
| @@ -1078,26 +990,8 @@ - (NSPoint)translateBubblePoint { |
| - (CGFloat)baseToolbarHeight { |
| // Height of the toolbar in pixels when the bookmark bar is closed. |
| - const bool kIsModeMaterial = ui::MaterialDesignController::IsModeMaterial(); |
| - const CGFloat kBaseToolbarHeightNormal = kIsModeMaterial ? 37 : 35; |
| - |
| - // Not all lines are drawn at 2x normal height when running on Retina, which |
| - // causes the toolbar controls to be visually 1pt too high within the toolbar |
| - // area. It's not possible to adjust the control y-positions by 0.5pt and have |
| - // them appear 0.5pt lower (they are still drawn at their original locations), |
| - // so instead shave off 1pt from the bottom of the toolbar. Note that there's |
| - // an offsetting change in -[BookmarkBarController preferredHeight] to |
| - // maintain the proper spacing between bookmark icons and toolbar items. See |
| - // https://crbug.com/326245 . |
| - const CGFloat kLineWidth = [[self view] cr_lineWidth]; |
| - const BOOL kIsRetina = (kLineWidth < 1); |
| - BOOL reduceHeight = NO; |
| - |
| - // Only adjust the height if Retina and not Material Design. |
| - reduceHeight = kIsRetina && !kIsModeMaterial; |
| - |
| - return reduceHeight ? kBaseToolbarHeightNormal - 1 |
| - : kBaseToolbarHeightNormal; |
| + const CGFloat kBaseToolbarHeightNormal = 37; |
| + return kBaseToolbarHeightNormal; |
| } |
| - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { |