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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm

Issue 1770573002: Update extension buttons to Material Design (Mac). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_toolbar
Patch Set: Code clean-up. Created 4 years, 9 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
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/toolbar/toolbar_controller.h" 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 using content::OpenURLParams; 72 using content::OpenURLParams;
73 using content::Referrer; 73 using content::Referrer;
74 using content::WebContents; 74 using content::WebContents;
75 75
76 namespace { 76 namespace {
77 77
78 // Duration of the toolbar animation. 78 // Duration of the toolbar animation.
79 const NSTimeInterval kToolBarAnimationDuration = 0.12; 79 const NSTimeInterval kToolBarAnimationDuration = 0.12;
80 80
81 // The size of toolbar buttons in Material Design.
82 const NSSize kMaterialDesignToolbarButtonSize = NSMakeSize(28, 28);
83
84 // The height of the location bar in Material Design. 81 // The height of the location bar in Material Design.
85 const CGFloat kMaterialDesignLocationBarHeight = 28; 82 const CGFloat kMaterialDesignLocationBarHeight = 28;
86 83
87 // The padding between Material Design elements (when they don't abut). 84 // The padding between Material Design elements (when they don't abut).
88 const CGFloat kMaterialDesignElementPadding = 4; 85 const CGFloat kMaterialDesignElementPadding = 4;
89 86
90 // The minimum width of the location bar in pixels. 87 // The minimum width of the location bar in pixels.
91 const CGFloat kMinimumLocationBarWidth = 100.0; 88 const CGFloat kMinimumLocationBarWidth = 100.0;
92 89
93 class BrowserActionsContainerDelegate : 90 class BrowserActionsContainerDelegate :
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // be called, don't initialize twice. 282 // be called, don't initialize twice.
286 if (locationBarView_) { 283 if (locationBarView_) {
287 DCHECK(base::mac::IsOSYosemiteOrLater()); 284 DCHECK(base::mac::IsOSYosemiteOrLater());
288 return; 285 return;
289 } 286 }
290 287
291 // Make Material Design layout adjustments to the NIB items. 288 // Make Material Design layout adjustments to the NIB items.
292 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); 289 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial();
293 if (isModeMaterial) { 290 if (isModeMaterial) {
294 ToolbarView* toolbarView = [self toolbarView]; 291 ToolbarView* toolbarView = [self toolbarView];
292 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize];
295 293
296 // Set the toolbar height. 294 // Set the toolbar height.
297 NSRect frame = [toolbarView frame]; 295 NSRect frame = [toolbarView frame];
298 frame.size.height = [self baseToolbarHeight]; 296 frame.size.height = [self baseToolbarHeight];
299 [toolbarView setFrame:frame]; 297 [toolbarView setFrame:frame];
300 298
301 NSRect backButtonFrame = [backButton_ frame]; 299 NSRect backButtonFrame = [backButton_ frame];
302 backButtonFrame.origin.x = kMaterialDesignElementPadding; 300 backButtonFrame.origin.x = kMaterialDesignElementPadding;
303 backButtonFrame.origin.y -= 1; 301 backButtonFrame.origin.y -= 1;
304 backButtonFrame.size = kMaterialDesignToolbarButtonSize; 302 backButtonFrame.size = toolbarButtonSize;
305 [backButton_ setFrame:backButtonFrame]; 303 [backButton_ setFrame:backButtonFrame];
306 304
307 NSRect forwardButtonFrame = [forwardButton_ frame]; 305 NSRect forwardButtonFrame = [forwardButton_ frame];
308 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame); 306 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame);
309 forwardButtonFrame.origin.y = backButtonFrame.origin.y; 307 forwardButtonFrame.origin.y = backButtonFrame.origin.y;
310 forwardButtonFrame.size = kMaterialDesignToolbarButtonSize; 308 forwardButtonFrame.size = toolbarButtonSize;
311 [forwardButton_ setFrame:forwardButtonFrame]; 309 [forwardButton_ setFrame:forwardButtonFrame];
312 310
313 NSRect reloadButtonFrame = [reloadButton_ frame]; 311 NSRect reloadButtonFrame = [reloadButton_ frame];
314 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame); 312 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame);
315 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; 313 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y;
316 reloadButtonFrame.size = kMaterialDesignToolbarButtonSize; 314 reloadButtonFrame.size = toolbarButtonSize;
317 [reloadButton_ setFrame:reloadButtonFrame]; 315 [reloadButton_ setFrame:reloadButtonFrame];
318 316
319 NSRect homeButtonFrame = [homeButton_ frame]; 317 NSRect homeButtonFrame = [homeButton_ frame];
320 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame); 318 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame);
321 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; 319 homeButtonFrame.origin.y = reloadButtonFrame.origin.y;
322 homeButtonFrame.size = kMaterialDesignToolbarButtonSize; 320 homeButtonFrame.size = toolbarButtonSize;
323 [homeButton_ setFrame:homeButtonFrame]; 321 [homeButton_ setFrame:homeButtonFrame];
324 322
325 // Replace the app button from the nib with an AppToolbarButton instance for 323 // Replace the app button from the nib with an AppToolbarButton instance for
326 // Material Design. 324 // Material Design.
327 AppToolbarButton* newMenuButton = 325 AppToolbarButton* newMenuButton =
328 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] 326 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]]
329 autorelease]; 327 autorelease];
330 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; 328 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]];
331 [[appMenuButton_ superview] addSubview:newMenuButton]; 329 [[appMenuButton_ superview] addSubview:newMenuButton];
332 [appMenuButton_ removeFromSuperview]; 330 [appMenuButton_ removeFromSuperview];
333 appMenuButton_ = newMenuButton; 331 appMenuButton_ = newMenuButton;
334 332
335 // Adjust the menu button's position. 333 // Adjust the menu button's position.
336 NSRect toolbarBounds = [toolbarView bounds]; 334 NSRect toolbarBounds = [toolbarView bounds];
337 NSRect menuButtonFrame = [appMenuButton_ frame]; 335 NSRect menuButtonFrame = [appMenuButton_ frame];
338 menuButtonFrame.origin.x = NSMaxX(toolbarBounds) - 336 menuButtonFrame.origin.x = NSMaxX(toolbarBounds) -
339 [ToolbarController appMenuLeftPadding] - 337 [ToolbarController appMenuLeftPadding] - toolbarButtonSize.width;
340 kMaterialDesignToolbarButtonSize.width;
341 menuButtonFrame.origin.y = homeButtonFrame.origin.y; 338 menuButtonFrame.origin.y = homeButtonFrame.origin.y;
342 menuButtonFrame.size = kMaterialDesignToolbarButtonSize; 339 menuButtonFrame.size = toolbarButtonSize;
343 [appMenuButton_ setFrame:menuButtonFrame]; 340 [appMenuButton_ setFrame:menuButtonFrame];
344 341
345 // Adjust the size and location on the location bar to take up the 342 // Adjust the size and location on the location bar to take up the
346 // space between the reload and menu buttons. 343 // space between the reload and menu buttons.
347 NSRect locationBarFrame = [locationBar_ frame]; 344 NSRect locationBarFrame = [locationBar_ frame];
348 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + 345 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) +
349 kMaterialDesignElementPadding; 346 kMaterialDesignElementPadding;
350 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - 347 locationBarFrame.origin.y = NSMaxY(toolbarBounds) -
351 kMaterialDesignElementPadding - [ToolbarController locationBarHeight]; 348 kMaterialDesignElementPadding - [ToolbarController locationBarHeight];
352 locationBarFrame.size.width = 349 locationBarFrame.size.width =
353 (menuButtonFrame.origin.x - kMaterialDesignElementPadding) - 350 (menuButtonFrame.origin.x - kMaterialDesignElementPadding) -
354 locationBarFrame.origin.x; 351 locationBarFrame.origin.x;
355 locationBarFrame.size.height = kMaterialDesignToolbarButtonSize.height; 352 locationBarFrame.size.height = toolbarButtonSize.height;
356 [locationBar_ setFrame:locationBarFrame]; 353 [locationBar_ setFrame:locationBarFrame];
354
355 // Correctly position the extension buttons' container view.
356 NSRect containerFrame = [browserActionsContainerView_ frame];
357 containerFrame.origin.y = locationBarFrame.origin.y;
358 containerFrame.size.height = toolbarButtonSize.height;
359 [browserActionsContainerView_ setFrame:containerFrame];
357 } else { 360 } else {
358 [[backButton_ cell] setImageID:IDR_BACK 361 [[backButton_ cell] setImageID:IDR_BACK
359 forButtonState:image_button_cell::kDefaultState]; 362 forButtonState:image_button_cell::kDefaultState];
360 [[backButton_ cell] setImageID:IDR_BACK_H 363 [[backButton_ cell] setImageID:IDR_BACK_H
361 forButtonState:image_button_cell::kHoverState]; 364 forButtonState:image_button_cell::kHoverState];
362 [[backButton_ cell] setImageID:IDR_BACK_P 365 [[backButton_ cell] setImageID:IDR_BACK_P
363 forButtonState:image_button_cell::kPressedState]; 366 forButtonState:image_button_cell::kPressedState];
364 [[backButton_ cell] setImageID:IDR_BACK_D 367 [[backButton_ cell] setImageID:IDR_BACK_D
365 forButtonState:image_button_cell::kDisabledState]; 368 forButtonState:image_button_cell::kDisabledState];
366 369
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); 872 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]);
870 CGFloat leftDistance = 0.0; 873 CGFloat leftDistance = 0.0;
871 874
872 if ([browserActionsContainerView_ isHidden]) { 875 if ([browserActionsContainerView_ isHidden]) {
873 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; 876 CGFloat edgeXPos = [appMenuButton_ frame].origin.x;
874 leftDistance = edgeXPos - locationBarXPos - 877 leftDistance = edgeXPos - locationBarXPos -
875 [ToolbarController appMenuLeftPadding]; 878 [ToolbarController appMenuLeftPadding];
876 } else { 879 } else {
877 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - 880 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) -
878 locationBarXPos; 881 locationBarXPos;
882 // Equalize the distance between the location bar and the first extension
883 // button, and the distance between the location bar and home/reload button.
884 if (ui::MaterialDesignController::IsModeMaterial()) {
885 leftDistance -= 4;
886 }
879 } 887 }
880 if (leftDistance != 0.0) 888 if (leftDistance != 0.0)
881 [self adjustLocationSizeBy:leftDistance animate:animate]; 889 [self adjustLocationSizeBy:leftDistance animate:animate];
882 else 890 else
883 [locationBar_ stopAnimation]; 891 [locationBar_ stopAnimation];
884 } 892 }
885 893
886 - (void)maintainMinimumLocationBarWidth { 894 - (void)maintainMinimumLocationBarWidth {
887 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); 895 CGFloat locationBarWidth = NSWidth([locationBar_ frame]);
888 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; 896 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 - (void)hideDropURLsIndicatorInView:(NSView*)view { 1124 - (void)hideDropURLsIndicatorInView:(NSView*)view {
1117 // Do nothing. 1125 // Do nothing.
1118 } 1126 }
1119 1127
1120 // (URLDropTargetController protocol) 1128 // (URLDropTargetController protocol)
1121 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { 1129 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info {
1122 return drag_util::IsUnsupportedDropData(profile_, info); 1130 return drag_util::IsUnsupportedDropData(profile_, info);
1123 } 1131 }
1124 1132
1125 @end 1133 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm ('k') | chrome/browser/ui/layout_constants.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698