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

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

Issue 1680773006: Implement Material Design for Mac toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_master
Patch Set: Change button hover and pressed styles. 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
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 #import "chrome/browser/ui/cocoa/background_gradient_view.h" 31 #import "chrome/browser/ui/cocoa/background_gradient_view.h"
32 #include "chrome/browser/ui/cocoa/drag_util.h" 32 #include "chrome/browser/ui/cocoa/drag_util.h"
33 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" 33 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
34 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" 34 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
35 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 35 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
36 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" 36 #import "chrome/browser/ui/cocoa/gradient_button_cell.h"
37 #import "chrome/browser/ui/cocoa/image_button_cell.h" 37 #import "chrome/browser/ui/cocoa/image_button_cell.h"
38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 38 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
39 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 39 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
40 #import "chrome/browser/ui/cocoa/menu_button.h" 40 #import "chrome/browser/ui/cocoa/menu_button.h"
41 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h"
41 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h" 42 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h"
42 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" 43 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h"
43 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h" 44 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h"
44 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" 45 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h"
45 #import "chrome/browser/ui/cocoa/toolbar/toolbar_view_cocoa.h" 46 #import "chrome/browser/ui/cocoa/toolbar/toolbar_view_cocoa.h"
46 #import "chrome/browser/ui/cocoa/view_id_util.h" 47 #import "chrome/browser/ui/cocoa/view_id_util.h"
47 #include "chrome/browser/ui/tabs/tab_strip_model.h" 48 #include "chrome/browser/ui/tabs/tab_strip_model.h"
48 #include "chrome/browser/ui/toolbar/app_menu_badge_controller.h" 49 #include "chrome/browser/ui/toolbar/app_menu_badge_controller.h"
49 #include "chrome/browser/ui/toolbar/app_menu_model.h" 50 #include "chrome/browser/ui/toolbar/app_menu_model.h"
50 #include "chrome/common/pref_names.h" 51 #include "chrome/common/pref_names.h"
51 #include "chrome/grit/chromium_strings.h" 52 #include "chrome/grit/chromium_strings.h"
52 #include "chrome/grit/generated_resources.h" 53 #include "chrome/grit/generated_resources.h"
53 #include "components/metrics/proto/omnibox_event.pb.h" 54 #include "components/metrics/proto/omnibox_event.pb.h"
54 #include "components/omnibox/browser/autocomplete_classifier.h" 55 #include "components/omnibox/browser/autocomplete_classifier.h"
55 #include "components/omnibox/browser/autocomplete_match.h" 56 #include "components/omnibox/browser/autocomplete_match.h"
56 #include "components/omnibox/browser/omnibox_view.h" 57 #include "components/omnibox/browser/omnibox_view.h"
57 #include "components/prefs/pref_service.h" 58 #include "components/prefs/pref_service.h"
58 #include "components/search_engines/template_url_service.h" 59 #include "components/search_engines/template_url_service.h"
59 #include "components/url_formatter/url_fixer.h" 60 #include "components/url_formatter/url_fixer.h"
60 #include "content/public/browser/web_contents.h" 61 #include "content/public/browser/web_contents.h"
61 #include "grit/components_strings.h" 62 #include "grit/components_strings.h"
62 #include "grit/theme_resources.h" 63 #include "grit/theme_resources.h"
63 #import "ui/base/cocoa/menu_controller.h" 64 #import "ui/base/cocoa/menu_controller.h"
64 #import "ui/base/cocoa/nsview_additions.h" 65 #import "ui/base/cocoa/nsview_additions.h"
65 #include "ui/base/l10n/l10n_util.h" 66 #include "ui/base/l10n/l10n_util.h"
66 #include "ui/base/l10n/l10n_util_mac.h" 67 #include "ui/base/l10n/l10n_util_mac.h"
68 #include "ui/base/material_design/material_design_controller.h"
67 #include "ui/gfx/geometry/rect.h" 69 #include "ui/gfx/geometry/rect.h"
68 #include "ui/gfx/image/image.h" 70 #include "ui/gfx/image/image.h"
69 71
70 using content::OpenURLParams; 72 using content::OpenURLParams;
71 using content::Referrer; 73 using content::Referrer;
72 using content::WebContents; 74 using content::WebContents;
73 75
74 namespace { 76 namespace {
75 77
76 // Duration of the toolbar animation. 78 // Duration of the toolbar animation.
77 const NSTimeInterval kToolBarAnimationDuration = 0.12; 79 const NSTimeInterval kToolBarAnimationDuration = 0.12;
78 80
79 // Height of the location bar. Used for animating the toolbar in and out when 81 // The size of toolbar buttons in Material Design.
80 // the location bar is displayed stand-alone for bookmark apps. 82 const NSSize kMaterialDesignToolbarButtonSize = NSMakeSize(28, 28);
81 const CGFloat kLocationBarHeight = 29.0;
82 83
83 // The padding above the toolbar elements. This is calculated from the values 84 // The height of the location bar in Material Design.
84 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child 85 const CGFloat kMaterialDesignLocationBarHeight = 28;
85 // elements (29) minus the y-origin of the elements (4). 86
86 const CGFloat kToolbarElementTopPadding = 2.0; 87 // The padding between Material Design elements (when they don't abut).
88 const CGFloat kMaterialDesignElementPadding = 4;
87 89
88 // The minimum width of the location bar in pixels. 90 // The minimum width of the location bar in pixels.
89 const CGFloat kMinimumLocationBarWidth = 100.0; 91 const CGFloat kMinimumLocationBarWidth = 100.0;
90 92
91 // The amount of left padding that the app menu should have.
92 const CGFloat kAppMenuLeftPadding = 3.0;
93
94 class BrowserActionsContainerDelegate : 93 class BrowserActionsContainerDelegate :
95 public BrowserActionsContainerViewSizeDelegate { 94 public BrowserActionsContainerViewSizeDelegate {
96 public: 95 public:
97 BrowserActionsContainerDelegate( 96 BrowserActionsContainerDelegate(
98 AutocompleteTextField* location_bar, 97 AutocompleteTextField* location_bar,
99 BrowserActionsContainerView* browser_actions_container_view); 98 BrowserActionsContainerView* browser_actions_container_view);
100 ~BrowserActionsContainerDelegate() override; 99 ~BrowserActionsContainerDelegate() override;
101 100
102 private: 101 private:
103 // BrowserActionsContainerSizeDelegate: 102 // BrowserActionsContainerSizeDelegate:
(...skipping 20 matching lines...) Expand all
124 CGFloat BrowserActionsContainerDelegate::GetMaxAllowedWidth() { 123 CGFloat BrowserActionsContainerDelegate::GetMaxAllowedWidth() {
125 CGFloat location_bar_flex = 124 CGFloat location_bar_flex =
126 NSWidth([location_bar_ frame]) - kMinimumLocationBarWidth; 125 NSWidth([location_bar_ frame]) - kMinimumLocationBarWidth;
127 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; 126 return NSWidth([browser_actions_container_ frame]) + location_bar_flex;
128 } 127 }
129 128
130 } // namespace 129 } // namespace
131 130
132 @interface ToolbarController() 131 @interface ToolbarController()
133 @property(assign, nonatomic) Browser* browser; 132 @property(assign, nonatomic) Browser* browser;
133 // Height of the location bar. Used for animating the toolbar in and out when
134 // the location bar is displayed stand-alone for bookmark apps.
135 + (CGFloat)locationBarHeight;
136 // Return the amount of left padding that the app menu should have.
137 + (CGFloat)appMenuLeftPadding;
134 - (void)cleanUp; 138 - (void)cleanUp;
135 - (void)addAccessibilityDescriptions; 139 - (void)addAccessibilityDescriptions;
136 - (void)initCommandStatus:(CommandUpdater*)commands; 140 - (void)initCommandStatus:(CommandUpdater*)commands;
137 - (void)prefChanged:(const std::string&)prefName; 141 - (void)prefChanged:(const std::string&)prefName;
138 - (ToolbarView*)toolbarView; 142 - (ToolbarView*)toolbarView;
143 // Height of the toolbar in pixels when the bookmark bar is closed.
144 - (CGFloat)baseToolbarHeight;
139 - (void)toolbarFrameChanged; 145 - (void)toolbarFrameChanged;
140 - (void)showLocationBarOnly; 146 - (void)showLocationBarOnly;
141 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; 147 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate;
142 - (void)maintainMinimumLocationBarWidth; 148 - (void)maintainMinimumLocationBarWidth;
143 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; 149 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification;
144 - (void)browserActionsContainerDragged:(NSNotification*)notification; 150 - (void)browserActionsContainerDragged:(NSNotification*)notification;
145 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; 151 - (void)browserActionsVisibilityChanged:(NSNotification*)notification;
146 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; 152 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification;
147 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; 153 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate;
148 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity 154 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 213
208 DISALLOW_COPY_AND_ASSIGN(NotificationBridge); 214 DISALLOW_COPY_AND_ASSIGN(NotificationBridge);
209 }; 215 };
210 216
211 } // namespace ToolbarControllerInternal 217 } // namespace ToolbarControllerInternal
212 218
213 @implementation ToolbarController 219 @implementation ToolbarController
214 220
215 @synthesize browser = browser_; 221 @synthesize browser = browser_;
216 222
223 + (CGFloat)locationBarHeight {
224 if (!ui::MaterialDesignController::IsModeMaterial()) {
225 return 29;
226 }
227
228 return kMaterialDesignLocationBarHeight;
229 }
230
231 + (CGFloat)appMenuLeftPadding {
232 if (!ui::MaterialDesignController::IsModeMaterial()) {
233 return 3;
234 }
235
236 return kMaterialDesignElementPadding;
237 }
238
217 - (id)initWithCommands:(CommandUpdater*)commands 239 - (id)initWithCommands:(CommandUpdater*)commands
218 profile:(Profile*)profile 240 profile:(Profile*)profile
219 browser:(Browser*)browser 241 browser:(Browser*)browser
220 resizeDelegate:(id<ViewResizer>)resizeDelegate { 242 resizeDelegate:(id<ViewResizer>)resizeDelegate {
221 DCHECK(commands && profile); 243 DCHECK(commands && profile);
222 if ((self = [super initWithNibName:@"Toolbar" 244 if ((self = [super initWithNibName:@"Toolbar"
223 bundle:base::mac::FrameworkBundle()])) { 245 bundle:base::mac::FrameworkBundle()])) {
224 commands_ = commands; 246 commands_ = commands;
225 profile_ = profile; 247 profile_ = profile;
226 browser_ = browser; 248 browser_ = browser;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 281 }
260 282
261 - (void)viewDidLoad { 283 - (void)viewDidLoad {
262 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may 284 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may
263 // be called, don't initialize twice. 285 // be called, don't initialize twice.
264 if (locationBarView_) { 286 if (locationBarView_) {
265 DCHECK(base::mac::IsOSYosemiteOrLater()); 287 DCHECK(base::mac::IsOSYosemiteOrLater());
266 return; 288 return;
267 } 289 }
268 290
269 [[backButton_ cell] setImageID:IDR_BACK 291 // Make Material Design layout adjustments to the NIB items.
270 forButtonState:image_button_cell::kDefaultState]; 292 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial();
271 [[backButton_ cell] setImageID:IDR_BACK_H 293 if (isModeMaterial) {
272 forButtonState:image_button_cell::kHoverState]; 294 ToolbarView* toolbarView = [self toolbarView];
273 [[backButton_ cell] setImageID:IDR_BACK_P
274 forButtonState:image_button_cell::kPressedState];
275 [[backButton_ cell] setImageID:IDR_BACK_D
276 forButtonState:image_button_cell::kDisabledState];
277 295
278 [[forwardButton_ cell] setImageID:IDR_FORWARD 296 // Set the toolbar height.
279 forButtonState:image_button_cell::kDefaultState]; 297 NSRect frame = [toolbarView frame];
280 [[forwardButton_ cell] setImageID:IDR_FORWARD_H 298 frame.size.height = [self baseToolbarHeight];
281 forButtonState:image_button_cell::kHoverState]; 299 [toolbarView setFrame:frame];
282 [[forwardButton_ cell] setImageID:IDR_FORWARD_P
283 forButtonState:image_button_cell::kPressedState];
284 [[forwardButton_ cell] setImageID:IDR_FORWARD_D
285 forButtonState:image_button_cell::kDisabledState];
286 300
287 [[reloadButton_ cell] setImageID:IDR_RELOAD 301 NSRect backButtonFrame = [backButton_ frame];
302 backButtonFrame.origin.x = kMaterialDesignElementPadding;
303 backButtonFrame.origin.y -= 1;
304 backButtonFrame.size = kMaterialDesignToolbarButtonSize;
305 [backButton_ setFrame:backButtonFrame];
306
307 NSRect forwardButtonFrame = [forwardButton_ frame];
308 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame);
309 forwardButtonFrame.origin.y = backButtonFrame.origin.y;
310 forwardButtonFrame.size = kMaterialDesignToolbarButtonSize;
311 [forwardButton_ setFrame:forwardButtonFrame];
312
313 NSRect reloadButtonFrame = [reloadButton_ frame];
314 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame);
315 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y;
316 reloadButtonFrame.size = kMaterialDesignToolbarButtonSize;
317 [reloadButton_ setFrame:reloadButtonFrame];
318
319 NSRect homeButtonFrame = [homeButton_ frame];
320 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame);
321 homeButtonFrame.origin.y = reloadButtonFrame.origin.y;
322 homeButtonFrame.size = kMaterialDesignToolbarButtonSize;
323 [homeButton_ setFrame:homeButtonFrame];
324
325 // Replace the app button from the nib with an AppToolbarButton instance for
326 // Material Design.
327 AppToolbarButton* newMenuButton =
328 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]]
329 autorelease];
330 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]];
331 [[appMenuButton_ superview] addSubview:newMenuButton];
332 [appMenuButton_ removeFromSuperview];
333 appMenuButton_ = newMenuButton;
334
335 // Adjust the menu button's position.
336 NSRect toolbarBounds = [toolbarView bounds];
337 NSRect menuButtonFrame = [appMenuButton_ frame];
338 menuButtonFrame.origin.x = NSMaxX(toolbarBounds) -
339 [ToolbarController appMenuLeftPadding] -
340 kMaterialDesignToolbarButtonSize.width;
341 menuButtonFrame.origin.y = homeButtonFrame.origin.y;
342 menuButtonFrame.size = kMaterialDesignToolbarButtonSize;
343 [appMenuButton_ setFrame:menuButtonFrame];
344
345 // Adjust the size and location on the location bar to take up the
346 // space between the reload and menu buttons.
347 NSRect locationBarFrame = [locationBar_ frame];
348 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) +
349 kMaterialDesignElementPadding;
350 locationBarFrame.origin.y = NSMaxY(toolbarBounds) -
351 kMaterialDesignElementPadding - [ToolbarController locationBarHeight];
352 locationBarFrame.size.width =
353 (menuButtonFrame.origin.x - kMaterialDesignElementPadding) -
354 locationBarFrame.origin.x;
355 locationBarFrame.size.height = kMaterialDesignToolbarButtonSize.height;
356 [locationBar_ setFrame:locationBarFrame];
357 } else {
358 [[backButton_ cell] setImageID:IDR_BACK
288 forButtonState:image_button_cell::kDefaultState]; 359 forButtonState:image_button_cell::kDefaultState];
289 [[reloadButton_ cell] setImageID:IDR_RELOAD_H 360 [[backButton_ cell] setImageID:IDR_BACK_H
290 forButtonState:image_button_cell::kHoverState]; 361 forButtonState:image_button_cell::kHoverState];
291 [[reloadButton_ cell] setImageID:IDR_RELOAD_P 362 [[backButton_ cell] setImageID:IDR_BACK_P
363 forButtonState:image_button_cell::kPressedState];
364 [[backButton_ cell] setImageID:IDR_BACK_D
365 forButtonState:image_button_cell::kDisabledState];
366
367 [[forwardButton_ cell] setImageID:IDR_FORWARD
368 forButtonState:image_button_cell::kDefaultState];
369 [[forwardButton_ cell] setImageID:IDR_FORWARD_H
370 forButtonState:image_button_cell::kHoverState];
371 [[forwardButton_ cell] setImageID:IDR_FORWARD_P
372 forButtonState:image_button_cell::kPressedState];
373 [[forwardButton_ cell] setImageID:IDR_FORWARD_D
374 forButtonState:image_button_cell::kDisabledState];
375
376 [[reloadButton_ cell] setImageID:IDR_RELOAD
377 forButtonState:image_button_cell::kDefaultState];
378 [[reloadButton_ cell] setImageID:IDR_RELOAD_H
379 forButtonState:image_button_cell::kHoverState];
380 [[reloadButton_ cell] setImageID:IDR_RELOAD_P
381 forButtonState:image_button_cell::kPressedState];
382
383 [[homeButton_ cell] setImageID:IDR_HOME
384 forButtonState:image_button_cell::kDefaultState];
385 [[homeButton_ cell] setImageID:IDR_HOME_H
386 forButtonState:image_button_cell::kHoverState];
387 [[homeButton_ cell] setImageID:IDR_HOME_P
292 forButtonState:image_button_cell::kPressedState]; 388 forButtonState:image_button_cell::kPressedState];
293 389
294 [[homeButton_ cell] setImageID:IDR_HOME 390 [[appMenuButton_ cell] setImageID:IDR_TOOLS
295 forButtonState:image_button_cell::kDefaultState]; 391 forButtonState:image_button_cell::kDefaultState];
296 [[homeButton_ cell] setImageID:IDR_HOME_H 392 [[appMenuButton_ cell] setImageID:IDR_TOOLS_H
297 forButtonState:image_button_cell::kHoverState]; 393 forButtonState:image_button_cell::kHoverState];
298 [[homeButton_ cell] setImageID:IDR_HOME_P 394 [[appMenuButton_ cell] setImageID:IDR_TOOLS_P
299 forButtonState:image_button_cell::kPressedState]; 395 forButtonState:image_button_cell::kPressedState];
300 396
301 [[appMenuButton_ cell] setImageID:IDR_TOOLS 397 // Adjust the toolbar height if running on Retina - see the comment in
302 forButtonState:image_button_cell::kDefaultState]; 398 // -baseToolbarHeight.
303 [[appMenuButton_ cell] setImageID:IDR_TOOLS_H 399 CGFloat toolbarHeight = [self baseToolbarHeight];
304 forButtonState:image_button_cell::kHoverState]; 400 ToolbarView* toolbarView = [self toolbarView];
305 [[appMenuButton_ cell] setImageID:IDR_TOOLS_P 401 NSRect toolbarFrame = [toolbarView frame];
306 forButtonState:image_button_cell::kPressedState]; 402 if (toolbarFrame.size.height != toolbarHeight) {
403 toolbarFrame.size.height = toolbarHeight;
404 [toolbarView setFrame:toolbarFrame];
405 }
406 }
307 407
308 notificationBridge_.reset( 408 notificationBridge_.reset(
309 new ToolbarControllerInternal::NotificationBridge(self)); 409 new ToolbarControllerInternal::NotificationBridge(self));
310 notificationBridge_->UpdateBadgeSeverity(); 410 notificationBridge_->UpdateBadgeSeverity();
311 411
312 [appMenuButton_ setOpenMenuOnClick:YES]; 412 [appMenuButton_ setOpenMenuOnClick:YES];
313 413
314 [backButton_ setOpenMenuOnRightClick:YES]; 414 [backButton_ setOpenMenuOnRightClick:YES];
315 [forwardButton_ setOpenMenuOnRightClick:YES]; 415 [forwardButton_ setOpenMenuOnRightClick:YES];
316 416
317 [backButton_ setHandleMiddleClick:YES]; 417 [backButton_ setHandleMiddleClick:YES];
318 [forwardButton_ setHandleMiddleClick:YES]; 418 [forwardButton_ setHandleMiddleClick:YES];
319 [reloadButton_ setHandleMiddleClick:YES]; 419 [reloadButton_ setHandleMiddleClick:YES];
320 [homeButton_ setHandleMiddleClick:YES]; 420 [homeButton_ setHandleMiddleClick:YES];
321 421
322 [self initCommandStatus:commands_]; 422 [self initCommandStatus:commands_];
323 [reloadButton_ setCommandUpdater:commands_]; 423 [reloadButton_ setCommandUpdater:commands_];
324 424
325 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, 425 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_,
326 profile_, browser_)); 426 profile_, browser_));
327 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 427 [locationBar_ setFont:[NSFont systemFontOfSize:14]];
328 428 if (!isModeMaterial) {
329 // Adjust the toolbar height if running on Retina - see the comment in 429 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
330 // -baseToolbarHeight.
331 CGFloat toolbarHeight = [self baseToolbarHeight];
332 NSRect toolbarFrame = [[locationBar_ superview] frame];
333 if (toolbarFrame.size.height != toolbarHeight) {
334 toolbarFrame.size.height = toolbarHeight;
335 [[locationBar_ superview] setFrame:toolbarFrame];
336 } 430 }
337 431
338 // Register pref observers for the optional home and page/options buttons 432 // Register pref observers for the optional home and page/options buttons
339 // and then add them to the toolbar based on those prefs. 433 // and then add them to the toolbar based on those prefs.
340 PrefService* prefs = profile_->GetPrefs(); 434 PrefService* prefs = profile_->GetPrefs();
341 showHomeButton_.Init( 435 showHomeButton_.Init(
342 prefs::kShowHomeButton, prefs, 436 prefs::kShowHomeButton, prefs,
343 base::Bind( 437 base::Bind(
344 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, 438 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged,
345 base::Unretained(notificationBridge_.get()))); 439 base::Unretained(notificationBridge_.get())));
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // Ignore this message if only showing the URL bar. 747 // Ignore this message if only showing the URL bar.
654 if (!hasToolbar_) 748 if (!hasToolbar_)
655 return; 749 return;
656 BOOL hide = showHomeButton_.GetValue() ? NO : YES; 750 BOOL hide = showHomeButton_.GetValue() ? NO : YES;
657 if (hide == [homeButton_ isHidden]) 751 if (hide == [homeButton_ isHidden])
658 return; // Nothing to do, view state matches pref state. 752 return; // Nothing to do, view state matches pref state.
659 753
660 // Always shift the text field by the width of the home button minus one pixel 754 // Always shift the text field by the width of the home button minus one pixel
661 // since the frame edges of each button are right on top of each other. When 755 // since the frame edges of each button are right on top of each other. When
662 // hiding the button, reverse the direction of the movement (to the left). 756 // hiding the button, reverse the direction of the movement (to the left).
663 CGFloat moveX = [homeButton_ frame].size.width - 1.0; 757 CGFloat moveX = [homeButton_ frame].size.width;
758 if (!ui::MaterialDesignController::IsModeMaterial()) {
759 moveX -= 1.0;
760 }
664 if (hide) 761 if (hide)
665 moveX *= -1; // Reverse the direction of the move. 762 moveX *= -1; // Reverse the direction of the move.
666 763
667 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] 764 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame]
668 byAmount:moveX]]; 765 byAmount:moveX]];
669 [homeButton_ setHidden:hide]; 766 [homeButton_ setHidden:hide];
670 } 767 }
671 768
672 // Install the app menu buttons. Calling this repeatedly is inexpensive so it 769 // Install the app menu buttons. Calling this repeatedly is inexpensive so it
673 // can be done every time the buttons are shown. 770 // can be done every time the buttons are shown.
674 - (void)installAppMenu { 771 - (void)installAppMenu {
675 if (appMenuController_.get()) 772 if (appMenuController_.get())
676 return; 773 return;
677 774
678 appMenuController_.reset( 775 appMenuController_.reset(
679 [[AppMenuController alloc] initWithBrowser:browser_]); 776 [[AppMenuController alloc] initWithBrowser:browser_]);
680 [appMenuController_ setUseWithPopUpButtonCell:YES]; 777 [appMenuController_ setUseWithPopUpButtonCell:YES];
681 [appMenuButton_ setAttachedMenu:[appMenuController_ menu]]; 778 [appMenuButton_ setAttachedMenu:[appMenuController_ menu]];
682 } 779 }
683 780
684 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity 781 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity
685 animate:(BOOL)animate { 782 animate:(BOOL)animate {
686 AppToolbarButtonCell* cell = 783 if (!ui::MaterialDesignController::IsModeMaterial()) {
687 base::mac::ObjCCastStrict<AppToolbarButtonCell>([appMenuButton_ cell]); 784 AppToolbarButtonCell* cell =
688 [cell setSeverity:severity shouldAnimate:animate]; 785 base::mac::ObjCCastStrict<AppToolbarButtonCell>([appMenuButton_ cell]);
786 [cell setSeverity:severity shouldAnimate:animate];
787 return;
788 }
789 AppToolbarButton* appMenuButton =
790 base::mac::ObjCCastStrict<AppToolbarButton>(appMenuButton_);
791 [appMenuButton setSeverity:severity shouldAnimate:animate];
689 } 792 }
690 793
691 - (void)prefChanged:(const std::string&)prefName { 794 - (void)prefChanged:(const std::string&)prefName {
692 if (prefName == prefs::kShowHomeButton) { 795 if (prefName == prefs::kShowHomeButton) {
693 [self showOptionalHomeButton]; 796 [self showOptionalHomeButton];
694 } 797 }
695 } 798 }
696 799
697 - (void)createBrowserActionButtons { 800 - (void)createBrowserActionButtons {
698 if (!browserActionsController_.get()) { 801 if (!browserActionsController_.get()) {
(...skipping 23 matching lines...) Expand all
722 addObserver:self 825 addObserver:self
723 selector:@selector(adjustBrowserActionsContainerForNewWindow:) 826 selector:@selector(adjustBrowserActionsContainerForNewWindow:)
724 name:NSWindowDidBecomeKeyNotification 827 name:NSWindowDidBecomeKeyNotification
725 object:[[self view] window]]; 828 object:[[self view] window]];
726 } 829 }
727 if (![browserActionsContainerView_ isHidden]) 830 if (![browserActionsContainerView_ isHidden])
728 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; 831 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO];
729 } 832 }
730 833
731 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { 834 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate {
732 CGFloat newHeight = visible ? kLocationBarHeight : 0; 835 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0;
733 836
734 // Perform the animation, which will cause the BrowserWindowController to 837 // Perform the animation, which will cause the BrowserWindowController to
735 // resize this view in the browser layout as required. 838 // resize this view in the browser layout as required.
736 if (animate) { 839 if (animate) {
737 [[self toolbarView] animateToNewHeight:newHeight 840 [[self toolbarView] animateToNewHeight:newHeight
738 duration:kToolBarAnimationDuration]; 841 duration:kToolBarAnimationDuration];
739 } else { 842 } else {
740 [[self toolbarView] setHeight:newHeight]; 843 [[self toolbarView] setHeight:newHeight];
741 } 844 }
742 } 845 }
(...skipping 18 matching lines...) Expand all
761 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { 864 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification {
762 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; 865 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES];
763 } 866 }
764 867
765 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { 868 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate {
766 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); 869 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]);
767 CGFloat leftDistance = 0.0; 870 CGFloat leftDistance = 0.0;
768 871
769 if ([browserActionsContainerView_ isHidden]) { 872 if ([browserActionsContainerView_ isHidden]) {
770 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; 873 CGFloat edgeXPos = [appMenuButton_ frame].origin.x;
771 leftDistance = edgeXPos - locationBarXPos - kAppMenuLeftPadding; 874 leftDistance = edgeXPos - locationBarXPos -
875 [ToolbarController appMenuLeftPadding];
772 } else { 876 } else {
773 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - 877 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) -
774 locationBarXPos; 878 locationBarXPos;
775 } 879 }
776 if (leftDistance != 0.0) 880 if (leftDistance != 0.0)
777 [self adjustLocationSizeBy:leftDistance animate:animate]; 881 [self adjustLocationSizeBy:leftDistance animate:animate];
778 else 882 else
779 [locationBar_ stopAnimation]; 883 [locationBar_ stopAnimation];
780 } 884 }
781 885
(...skipping 11 matching lines...) Expand all
793 // present. 897 // present.
794 if (!browserActionsController_.get()) 898 if (!browserActionsController_.get())
795 return; 899 return;
796 900
797 if ([browserActionsContainerView_ isAnimating]) { 901 if ([browserActionsContainerView_ isAnimating]) {
798 // If the browser actions container is animating, we need to stop it first, 902 // If the browser actions container is animating, we need to stop it first,
799 // because the frame it's animating for could be incorrect with the new 903 // because the frame it's animating for could be incorrect with the new
800 // bounds (if, for instance, the bookmark bar was added). 904 // bounds (if, for instance, the bookmark bar was added).
801 // This will advance to the end of the animation, so we also need to adjust 905 // This will advance to the end of the animation, so we also need to adjust
802 // it afterwards. 906 // it afterwards.
907 CGFloat elementTopPadding = kMaterialDesignElementPadding;
908 if (!ui::MaterialDesignController::IsModeMaterial()) {
909 // Pre-Material Design, this value is calculated from the values in
910 // Toolbar.xib: the height of the toolbar (35) minus the height of the
911 // child elements (29) minus the y-origin of the elements (4).
912 elementTopPadding = 2;
913 }
803 [browserActionsContainerView_ stopAnimation]; 914 [browserActionsContainerView_ stopAnimation];
804 NSRect containerFrame = [browserActionsContainerView_ frame]; 915 NSRect containerFrame = [browserActionsContainerView_ frame];
805 containerFrame.origin.y = 916 containerFrame.origin.y =
806 NSHeight([[self view] frame]) - NSHeight(containerFrame) - 917 NSHeight([[self view] frame]) - NSHeight(containerFrame) -
807 kToolbarElementTopPadding; 918 elementTopPadding;
808 [browserActionsContainerView_ setFrame:containerFrame]; 919 [browserActionsContainerView_ setFrame:containerFrame];
809 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; 920 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO];
810 } 921 }
811 922
812 [self maintainMinimumLocationBarWidth]; 923 [self maintainMinimumLocationBarWidth];
813 924
814 if (locationBarAtMinSize_) { 925 if (locationBarAtMinSize_) {
815 // Once the grippy is pinned, leave it until it is explicity un-pinned. 926 // Once the grippy is pinned, leave it until it is explicity un-pinned.
816 [browserActionsContainerView_ setGrippyPinned:YES]; 927 [browserActionsContainerView_ setGrippyPinned:YES];
817 NSRect containerFrame = [browserActionsContainerView_ frame]; 928 NSRect containerFrame = [browserActionsContainerView_ frame];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // to the toolbar or location bar width should be made. This message is 961 // to the toolbar or location bar width should be made. This message is
851 // invalid if the toolbar is shown or the location bar is hidden. 962 // invalid if the toolbar is shown or the location bar is hidden.
852 - (void)showLocationBarOnly { 963 - (void)showLocationBarOnly {
853 // -showLocationBarOnly is only ever called once, shortly after 964 // -showLocationBarOnly is only ever called once, shortly after
854 // initialization, so the regular buttons should all be visible. 965 // initialization, so the regular buttons should all be visible.
855 DCHECK(!hasToolbar_ && hasLocationBar_); 966 DCHECK(!hasToolbar_ && hasLocationBar_);
856 DCHECK(![backButton_ isHidden]); 967 DCHECK(![backButton_ isHidden]);
857 968
858 // Ensure the location bar fills the toolbar. 969 // Ensure the location bar fills the toolbar.
859 NSRect toolbarFrame = [[self view] frame]; 970 NSRect toolbarFrame = [[self view] frame];
860 toolbarFrame.size.height = kLocationBarHeight; 971 toolbarFrame.size.height = [ToolbarController locationBarHeight];
861 [[self view] setFrame:toolbarFrame]; 972 [[self view] setFrame:toolbarFrame];
862 973
863 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), 974 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]),
864 kLocationBarHeight)]; 975 [ToolbarController locationBarHeight])];
865 976
866 [backButton_ setHidden:YES]; 977 [backButton_ setHidden:YES];
867 [forwardButton_ setHidden:YES]; 978 [forwardButton_ setHidden:YES];
868 [reloadButton_ setHidden:YES]; 979 [reloadButton_ setHidden:YES];
869 [appMenuButton_ setHidden:YES]; 980 [appMenuButton_ setHidden:YES];
870 [homeButton_ setHidden:YES]; 981 [homeButton_ setHidden:YES];
871 } 982 }
872 983
873 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { 984 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate {
874 // Ensure that the location bar is in its proper place. 985 // Ensure that the location bar is in its proper place.
(...skipping 27 matching lines...) Expand all
902 - (NSPoint)saveCreditCardBubblePoint { 1013 - (NSPoint)saveCreditCardBubblePoint {
903 return locationBarView_->GetSaveCreditCardBubblePoint(); 1014 return locationBarView_->GetSaveCreditCardBubblePoint();
904 } 1015 }
905 1016
906 - (NSPoint)translateBubblePoint { 1017 - (NSPoint)translateBubblePoint {
907 return locationBarView_->GetTranslateBubblePoint(); 1018 return locationBarView_->GetTranslateBubblePoint();
908 } 1019 }
909 1020
910 - (CGFloat)baseToolbarHeight { 1021 - (CGFloat)baseToolbarHeight {
911 // Height of the toolbar in pixels when the bookmark bar is closed. 1022 // Height of the toolbar in pixels when the bookmark bar is closed.
912 const CGFloat baseToolbarHeightNormal = 35.0; 1023 const CGFloat baseToolbarHeightNormal =
1024 ui::MaterialDesignController::IsModeMaterial() ? 37 : 35;
913 1025
914 // Not all lines are drawn at 2x normal height when running on Retina, which 1026 // Not all lines are drawn at 2x normal height when running on Retina, which
915 // causes the toolbar controls to be visually 1pt too high within the toolbar 1027 // causes the toolbar controls to be visually 1pt too high within the toolbar
916 // area. It's not possible to adjust the control y-positions by 0.5pt and have 1028 // area. It's not possible to adjust the control y-positions by 0.5pt and have
917 // them appear 0.5pt lower (they are still drawn at their original locations), 1029 // them appear 0.5pt lower (they are still drawn at their original locations),
918 // so instead shave off 1pt from the bottom of the toolbar. Note that there's 1030 // so instead shave off 1pt from the bottom of the toolbar. Note that there's
919 // an offsetting change in -[BookmarkBarController preferredHeight] to 1031 // an offsetting change in -[BookmarkBarController preferredHeight] to
920 // maintain the proper spacing between bookmark icons and toolbar items. See 1032 // maintain the proper spacing between bookmark icons and toolbar items. See
921 // https://crbug.com/326245 . 1033 // https://crbug.com/326245 .
922 return [[self view] cr_lineWidth] == 0.5 ? baseToolbarHeightNormal - 1 1034 return [[self view] cr_lineWidth] == 0.5 ? baseToolbarHeightNormal - 1
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 - (void)hideDropURLsIndicatorInView:(NSView*)view { 1116 - (void)hideDropURLsIndicatorInView:(NSView*)view {
1005 // Do nothing. 1117 // Do nothing.
1006 } 1118 }
1007 1119
1008 // (URLDropTargetController protocol) 1120 // (URLDropTargetController protocol)
1009 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { 1121 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info {
1010 return drag_util::IsUnsupportedDropData(profile_, info); 1122 return drag_util::IsUnsupportedDropData(profile_, info);
1011 } 1123 }
1012 1124
1013 @end 1125 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698