OLD | NEW |
---|---|
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 using content::OpenURLParams; | 73 using content::OpenURLParams; |
74 using content::Referrer; | 74 using content::Referrer; |
75 using content::WebContents; | 75 using content::WebContents; |
76 | 76 |
77 namespace { | 77 namespace { |
78 | 78 |
79 // Duration of the toolbar animation. | 79 // Duration of the toolbar animation. |
80 const NSTimeInterval kToolBarAnimationDuration = 0.12; | 80 const NSTimeInterval kToolBarAnimationDuration = 0.12; |
81 | 81 |
82 // The height of the location bar in Material Design. | 82 // The height of the location bar in Material Design. |
83 const CGFloat kMaterialDesignLocationBarHeight = 28; | 83 const CGFloat kMaterialDesignLocationBarHeight = 28; |
Evan Stade
2016/09/27 19:34:51
nit: remove references to MD
| |
84 | 84 |
85 // The padding between the top of the toolbar and the top of the | 85 // The padding between the top of the toolbar and the top of the |
86 // location bar. | 86 // location bar. |
87 const CGFloat kMaterialDesignLocationBarPadding = 2; | 87 const CGFloat kMaterialDesignLocationBarPadding = 2; |
88 | 88 |
89 // The padding between Material Design elements and the edges of the toolbar. | 89 // The padding between Material Design elements and the edges of the toolbar. |
90 const CGFloat kMaterialDesignElementPadding = 4; | 90 const CGFloat kMaterialDesignElementPadding = 4; |
91 | 91 |
92 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- | 92 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- |
93 // wide inset. | 93 // wide inset. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 DISALLOW_COPY_AND_ASSIGN(NotificationBridge); | 223 DISALLOW_COPY_AND_ASSIGN(NotificationBridge); |
224 }; | 224 }; |
225 | 225 |
226 } // namespace ToolbarControllerInternal | 226 } // namespace ToolbarControllerInternal |
227 | 227 |
228 @implementation ToolbarController | 228 @implementation ToolbarController |
229 | 229 |
230 @synthesize browser = browser_; | 230 @synthesize browser = browser_; |
231 | 231 |
232 + (CGFloat)locationBarHeight { | 232 + (CGFloat)locationBarHeight { |
233 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
234 return 29; | |
235 } | |
236 | |
237 return kMaterialDesignLocationBarHeight; | 233 return kMaterialDesignLocationBarHeight; |
238 } | 234 } |
239 | 235 |
240 + (CGFloat)appMenuLeftPadding { | 236 + (CGFloat)appMenuLeftPadding { |
241 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
242 return 3; | |
243 } | |
244 | |
245 return kMaterialDesignElementPadding; | 237 return kMaterialDesignElementPadding; |
246 } | 238 } |
247 | 239 |
248 + (CGFloat)materialDesignButtonInset { | 240 + (CGFloat)materialDesignButtonInset { |
249 return kMaterialDesignButtonInset; | 241 return kMaterialDesignButtonInset; |
250 } | 242 } |
251 | 243 |
252 - (id)initWithCommands:(CommandUpdater*)commands | 244 - (id)initWithCommands:(CommandUpdater*)commands |
253 profile:(Profile*)profile | 245 profile:(Profile*)profile |
254 browser:(Browser*)browser | 246 browser:(Browser*)browser |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 | 287 |
296 - (void)viewDidLoad { | 288 - (void)viewDidLoad { |
297 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may | 289 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may |
298 // be called, don't initialize twice. | 290 // be called, don't initialize twice. |
299 if (locationBarView_) { | 291 if (locationBarView_) { |
300 DCHECK(base::mac::IsAtLeastOS10_10()); | 292 DCHECK(base::mac::IsAtLeastOS10_10()); |
301 return; | 293 return; |
302 } | 294 } |
303 | 295 |
304 // Make Material Design layout adjustments to the NIB items. | 296 // Make Material Design layout adjustments to the NIB items. |
305 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | 297 ToolbarView* toolbarView = [self toolbarView]; |
306 if (isModeMaterial) { | 298 NSRect toolbarBounds = [toolbarView bounds]; |
307 ToolbarView* toolbarView = [self toolbarView]; | 299 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
308 NSRect toolbarBounds = [toolbarView bounds]; | |
309 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; | |
310 | 300 |
311 // Set the toolbar height. | 301 // Set the toolbar height. |
312 NSRect frame = [toolbarView frame]; | 302 NSRect frame = [toolbarView frame]; |
313 frame.size.height = [self baseToolbarHeight]; | 303 frame.size.height = [self baseToolbarHeight]; |
314 [toolbarView setFrame:frame]; | 304 [toolbarView setFrame:frame]; |
315 | 305 |
316 NSRect backButtonFrame = [backButton_ frame]; | 306 NSRect backButtonFrame = [backButton_ frame]; |
317 backButtonFrame.origin.x = | 307 backButtonFrame.origin.x = |
318 kMaterialDesignElementPadding + kMaterialDesignButtonInset; | 308 kMaterialDesignElementPadding + kMaterialDesignButtonInset; |
319 backButtonFrame.origin.y = NSMaxY(toolbarBounds) - | 309 backButtonFrame.origin.y = NSMaxY(toolbarBounds) - |
320 kMaterialDesignElementPadding - toolbarButtonSize.height; | 310 kMaterialDesignElementPadding - toolbarButtonSize.height; |
321 backButtonFrame.size = toolbarButtonSize; | 311 backButtonFrame.size = toolbarButtonSize; |
322 [backButton_ setFrame:backButtonFrame]; | 312 [backButton_ setFrame:backButtonFrame]; |
323 | 313 |
324 NSRect forwardButtonFrame = [forwardButton_ frame]; | 314 NSRect forwardButtonFrame = [forwardButton_ frame]; |
325 forwardButtonFrame.origin.x = | 315 forwardButtonFrame.origin.x = |
326 NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; | 316 NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; |
327 forwardButtonFrame.origin.y = backButtonFrame.origin.y; | 317 forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
328 forwardButtonFrame.size = toolbarButtonSize; | 318 forwardButtonFrame.size = toolbarButtonSize; |
329 [forwardButton_ setFrame:forwardButtonFrame]; | 319 [forwardButton_ setFrame:forwardButtonFrame]; |
330 | 320 |
331 NSRect reloadButtonFrame = [reloadButton_ frame]; | 321 NSRect reloadButtonFrame = [reloadButton_ frame]; |
332 reloadButtonFrame.origin.x = | 322 reloadButtonFrame.origin.x = |
333 NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; | 323 NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; |
334 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; | 324 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
335 reloadButtonFrame.size = toolbarButtonSize; | 325 reloadButtonFrame.size = toolbarButtonSize; |
336 [reloadButton_ setFrame:reloadButtonFrame]; | 326 [reloadButton_ setFrame:reloadButtonFrame]; |
337 | 327 |
338 NSRect homeButtonFrame = [homeButton_ frame]; | 328 NSRect homeButtonFrame = [homeButton_ frame]; |
339 homeButtonFrame.origin.x = | 329 homeButtonFrame.origin.x = |
340 NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; | 330 NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; |
341 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; | 331 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
342 homeButtonFrame.size = toolbarButtonSize; | 332 homeButtonFrame.size = toolbarButtonSize; |
343 [homeButton_ setFrame:homeButtonFrame]; | 333 [homeButton_ setFrame:homeButtonFrame]; |
344 | 334 |
345 // Replace the app button from the nib with an AppToolbarButton instance for | 335 // 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?
| |
346 // Material Design. | 336 // Material Design. |
Evan Stade
2016/09/27 19:34:51
nit: remove references to material design (since i
| |
347 AppToolbarButton* newMenuButton = | 337 AppToolbarButton* newMenuButton = |
348 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] | 338 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
349 autorelease]; | 339 autorelease]; |
350 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; | 340 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
351 [[appMenuButton_ superview] addSubview:newMenuButton]; | 341 [[appMenuButton_ superview] addSubview:newMenuButton]; |
352 [appMenuButton_ removeFromSuperview]; | 342 [appMenuButton_ removeFromSuperview]; |
353 appMenuButton_ = newMenuButton; | 343 appMenuButton_ = newMenuButton; |
354 | 344 |
355 // Adjust the menu button's position. | 345 // Adjust the menu button's position. |
356 NSRect menuButtonFrame = [appMenuButton_ frame]; | 346 NSRect menuButtonFrame = [appMenuButton_ frame]; |
357 CGFloat menuButtonFrameMaxX = | 347 CGFloat menuButtonFrameMaxX = |
358 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; | 348 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
359 menuButtonFrame.origin.x = | 349 menuButtonFrame.origin.x = |
360 menuButtonFrameMaxX - kMaterialDesignButtonInset - | 350 menuButtonFrameMaxX - kMaterialDesignButtonInset - |
361 toolbarButtonSize.width; | 351 toolbarButtonSize.width; |
362 menuButtonFrame.origin.y = homeButtonFrame.origin.y; | 352 menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
363 menuButtonFrame.size = toolbarButtonSize; | 353 menuButtonFrame.size = toolbarButtonSize; |
364 [appMenuButton_ setFrame:menuButtonFrame]; | 354 [appMenuButton_ setFrame:menuButtonFrame]; |
365 | 355 |
366 // Adjust the size and location on the location bar to take up the | 356 // Adjust the size and location on the location bar to take up the |
367 // space between the reload and menu buttons. | 357 // space between the reload and menu buttons. |
368 NSRect locationBarFrame = [locationBar_ frame]; | 358 NSRect locationBarFrame = [locationBar_ frame]; |
369 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + | 359 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + |
370 kMaterialDesignButtonInset; | 360 kMaterialDesignButtonInset; |
371 if (![homeButton_ isHidden]) { | 361 if (![homeButton_ isHidden]) { |
372 // Ensure proper spacing between the home button and the location bar. | 362 // Ensure proper spacing between the home button and the location bar. |
373 locationBarFrame.origin.x += kMaterialDesignElementPadding; | 363 locationBarFrame.origin.x += kMaterialDesignElementPadding; |
374 } | 364 } |
375 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - | 365 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - |
376 kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight; | 366 kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight; |
377 locationBarFrame.size.width = | 367 locationBarFrame.size.width = |
378 menuButtonFrame.origin.x - | 368 menuButtonFrame.origin.x - |
379 locationBarFrame.origin.x; | 369 locationBarFrame.origin.x; |
380 locationBarFrame.size.height = kMaterialDesignLocationBarHeight; | 370 locationBarFrame.size.height = kMaterialDesignLocationBarHeight; |
381 [locationBar_ setFrame:locationBarFrame]; | 371 [locationBar_ setFrame:locationBarFrame]; |
382 | 372 |
383 // Correctly position the extension buttons' container view. | 373 // Correctly position the extension buttons' container view. |
384 NSRect containerFrame = [browserActionsContainerView_ frame]; | 374 NSRect containerFrame = [browserActionsContainerView_ frame]; |
385 containerFrame.size.width += kMaterialDesignButtonInset; | 375 containerFrame.size.width += kMaterialDesignButtonInset; |
386 containerFrame.origin.y = | 376 containerFrame.origin.y = |
387 locationBarFrame.origin.y + kMaterialDesignContainerYOffset; | 377 locationBarFrame.origin.y + kMaterialDesignContainerYOffset; |
388 containerFrame.size.height = toolbarButtonSize.height; | 378 containerFrame.size.height = toolbarButtonSize.height; |
389 [browserActionsContainerView_ setFrame:containerFrame]; | 379 [browserActionsContainerView_ setFrame:containerFrame]; |
390 } else { | |
391 [[backButton_ cell] setImageID:IDR_BACK | |
392 forButtonState:image_button_cell::kDefaultState]; | |
393 [[backButton_ cell] setImageID:IDR_BACK_H | |
394 forButtonState:image_button_cell::kHoverState]; | |
395 [[backButton_ cell] setImageID:IDR_BACK_P | |
396 forButtonState:image_button_cell::kPressedState]; | |
397 [[backButton_ cell] setImageID:IDR_BACK_D | |
398 forButtonState:image_button_cell::kDisabledState]; | |
399 | |
400 [[forwardButton_ cell] setImageID:IDR_FORWARD | |
401 forButtonState:image_button_cell::kDefaultState]; | |
402 [[forwardButton_ cell] setImageID:IDR_FORWARD_H | |
403 forButtonState:image_button_cell::kHoverState]; | |
404 [[forwardButton_ cell] setImageID:IDR_FORWARD_P | |
405 forButtonState:image_button_cell::kPressedState]; | |
406 [[forwardButton_ cell] setImageID:IDR_FORWARD_D | |
407 forButtonState:image_button_cell::kDisabledState]; | |
408 | |
409 [[reloadButton_ cell] setImageID:IDR_RELOAD | |
410 forButtonState:image_button_cell::kDefaultState]; | |
411 [[reloadButton_ cell] setImageID:IDR_RELOAD_H | |
412 forButtonState:image_button_cell::kHoverState]; | |
413 [[reloadButton_ cell] setImageID:IDR_RELOAD_P | |
414 forButtonState:image_button_cell::kPressedState]; | |
415 | |
416 [[homeButton_ cell] setImageID:IDR_HOME | |
417 forButtonState:image_button_cell::kDefaultState]; | |
418 [[homeButton_ cell] setImageID:IDR_HOME_H | |
419 forButtonState:image_button_cell::kHoverState]; | |
420 [[homeButton_ cell] setImageID:IDR_HOME_P | |
421 forButtonState:image_button_cell::kPressedState]; | |
422 | |
423 [[appMenuButton_ cell] setImageID:IDR_TOOLS | |
424 forButtonState:image_button_cell::kDefaultState]; | |
425 [[appMenuButton_ cell] setImageID:IDR_TOOLS_H | |
426 forButtonState:image_button_cell::kHoverState]; | |
427 [[appMenuButton_ cell] setImageID:IDR_TOOLS_P | |
428 forButtonState:image_button_cell::kPressedState]; | |
429 | |
430 // Adjust the toolbar height if running on Retina - see the comment in | |
431 // -baseToolbarHeight. | |
432 CGFloat toolbarHeight = [self baseToolbarHeight]; | |
433 ToolbarView* toolbarView = [self toolbarView]; | |
434 NSRect toolbarFrame = [toolbarView frame]; | |
435 if (toolbarFrame.size.height != toolbarHeight) { | |
436 toolbarFrame.size.height = toolbarHeight; | |
437 [toolbarView setFrame:toolbarFrame]; | |
438 } | |
439 } | |
440 | 380 |
441 notificationBridge_.reset( | 381 notificationBridge_.reset( |
442 new ToolbarControllerInternal::NotificationBridge(self)); | 382 new ToolbarControllerInternal::NotificationBridge(self)); |
443 notificationBridge_->UpdateSeverity(); | 383 notificationBridge_->UpdateSeverity(); |
444 | 384 |
445 [appMenuButton_ setOpenMenuOnClick:YES]; | 385 [appMenuButton_ setOpenMenuOnClick:YES]; |
446 | 386 |
447 [backButton_ setOpenMenuOnRightClick:YES]; | 387 [backButton_ setOpenMenuOnRightClick:YES]; |
448 [forwardButton_ setOpenMenuOnRightClick:YES]; | 388 [forwardButton_ setOpenMenuOnRightClick:YES]; |
449 | 389 |
(...skipping 15 matching lines...) Expand all Loading... | |
465 // The |locationBarView_| is responsible for positioning the accessibility | 405 // The |locationBarView_| is responsible for positioning the accessibility |
466 // views. | 406 // views. |
467 std::vector<NSView*> accessibility_views = | 407 std::vector<NSView*> accessibility_views = |
468 locationBarView_->GetDecorationAccessibilityViews(); | 408 locationBarView_->GetDecorationAccessibilityViews(); |
469 for (const auto& view : accessibility_views) { | 409 for (const auto& view : accessibility_views) { |
470 [[self toolbarView] addSubview:view | 410 [[self toolbarView] addSubview:view |
471 positioned:NSWindowAbove | 411 positioned:NSWindowAbove |
472 relativeTo:locationBar_]; | 412 relativeTo:locationBar_]; |
473 } | 413 } |
474 | 414 |
475 if (!isModeMaterial) { | |
476 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
477 } | |
478 | |
479 // Register pref observers for the optional home and page/options buttons | 415 // Register pref observers for the optional home and page/options buttons |
480 // and then add them to the toolbar based on those prefs. | 416 // and then add them to the toolbar based on those prefs. |
481 PrefService* prefs = profile_->GetPrefs(); | 417 PrefService* prefs = profile_->GetPrefs(); |
482 showHomeButton_.Init( | 418 showHomeButton_.Init( |
483 prefs::kShowHomeButton, prefs, | 419 prefs::kShowHomeButton, prefs, |
484 base::Bind( | 420 base::Bind( |
485 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, | 421 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, |
486 base::Unretained(notificationBridge_.get()))); | 422 base::Unretained(notificationBridge_.get()))); |
487 [self showOptionalHomeButton]; | 423 [self showOptionalHomeButton]; |
488 [self installAppMenu]; | 424 [self installAppMenu]; |
(...skipping 11 matching lines...) Expand all Loading... | |
500 button:forwardButton_]); | 436 button:forwardButton_]); |
501 | 437 |
502 trackingArea_.reset( | 438 trackingArea_.reset( |
503 [[CrTrackingArea alloc] initWithRect:NSZeroRect // Ignored | 439 [[CrTrackingArea alloc] initWithRect:NSZeroRect // Ignored |
504 options:NSTrackingMouseMoved | | 440 options:NSTrackingMouseMoved | |
505 NSTrackingInVisibleRect | | 441 NSTrackingInVisibleRect | |
506 NSTrackingMouseEnteredAndExited | | 442 NSTrackingMouseEnteredAndExited | |
507 NSTrackingActiveAlways | 443 NSTrackingActiveAlways |
508 owner:self | 444 owner:self |
509 userInfo:nil]); | 445 userInfo:nil]); |
510 NSView* toolbarView = [self view]; | 446 NSView* parentView = [self view]; |
511 [toolbarView addTrackingArea:trackingArea_.get()]; | 447 [parentView addTrackingArea:trackingArea_.get()]; |
512 | 448 |
513 // If the user has any Browser Actions installed, the container view for them | 449 // If the user has any Browser Actions installed, the container view for them |
514 // may have to be resized depending on the width of the toolbar frame. | 450 // may have to be resized depending on the width of the toolbar frame. |
515 [toolbarView setPostsFrameChangedNotifications:YES]; | 451 [parentView setPostsFrameChangedNotifications:YES]; |
516 [[NSNotificationCenter defaultCenter] | 452 [[NSNotificationCenter defaultCenter] |
517 addObserver:self | 453 addObserver:self |
518 selector:@selector(toolbarFrameChanged) | 454 selector:@selector(toolbarFrameChanged) |
519 name:NSViewFrameDidChangeNotification | 455 name:NSViewFrameDidChangeNotification |
520 object:toolbarView]; | 456 object:parentView]; |
521 | 457 |
522 // Set ViewIDs for toolbar elements which don't have their dedicated class. | 458 // Set ViewIDs for toolbar elements which don't have their dedicated class. |
523 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | 459 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
524 // |browserActionsContainerView_| are handled by themselves. | 460 // |browserActionsContainerView_| are handled by themselves. |
525 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); | 461 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); |
526 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); | 462 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); |
527 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); | 463 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); |
528 view_id_util::SetID(appMenuButton_, VIEW_ID_APP_MENU); | 464 view_id_util::SetID(appMenuButton_, VIEW_ID_APP_MENU); |
529 | 465 |
530 [self addAccessibilityDescriptions]; | 466 [self addAccessibilityDescriptions]; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 if (!hasToolbar_) | 729 if (!hasToolbar_) |
794 return; | 730 return; |
795 BOOL hide = showHomeButton_.GetValue() ? NO : YES; | 731 BOOL hide = showHomeButton_.GetValue() ? NO : YES; |
796 if (hide == [homeButton_ isHidden]) | 732 if (hide == [homeButton_ isHidden]) |
797 return; // Nothing to do, view state matches pref state. | 733 return; // Nothing to do, view state matches pref state. |
798 | 734 |
799 // Always shift the text field by the width of the home button minus one pixel | 735 // Always shift the text field by the width of the home button minus one pixel |
800 // since the frame edges of each button are right on top of each other. When | 736 // since the frame edges of each button are right on top of each other. When |
801 // hiding the button, reverse the direction of the movement (to the left). | 737 // hiding the button, reverse the direction of the movement (to the left). |
802 CGFloat moveX = [homeButton_ frame].size.width; | 738 CGFloat moveX = [homeButton_ frame].size.width; |
803 if (!ui::MaterialDesignController::IsModeMaterial()) { | 739 // Ensure proper spacing between the home button and the location bar. |
804 moveX -= 1.0; | 740 moveX += kMaterialDesignElementPadding; |
805 } else { | |
806 // Ensure proper spacing between the home button and the location bar. | |
807 moveX += kMaterialDesignElementPadding; | |
808 } | |
809 if (hide) | 741 if (hide) |
810 moveX *= -1; // Reverse the direction of the move. | 742 moveX *= -1; // Reverse the direction of the move. |
811 | 743 |
812 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 744 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
813 byAmount:moveX]]; | 745 byAmount:moveX]]; |
814 [homeButton_ setHidden:hide]; | 746 [homeButton_ setHidden:hide]; |
815 } | 747 } |
816 | 748 |
817 // Install the app menu buttons. Calling this repeatedly is inexpensive so it | 749 // Install the app menu buttons. Calling this repeatedly is inexpensive so it |
818 // can be done every time the buttons are shown. | 750 // can be done every time the buttons are shown. |
819 - (void)installAppMenu { | 751 - (void)installAppMenu { |
820 if (appMenuController_.get()) | 752 if (appMenuController_.get()) |
821 return; | 753 return; |
822 | 754 |
823 appMenuController_.reset( | 755 appMenuController_.reset( |
824 [[AppMenuController alloc] initWithBrowser:browser_]); | 756 [[AppMenuController alloc] initWithBrowser:browser_]); |
825 [appMenuController_ setUseWithPopUpButtonCell:YES]; | 757 [appMenuController_ setUseWithPopUpButtonCell:YES]; |
826 [appMenuButton_ setAttachedMenu:[appMenuController_ menu]]; | 758 [appMenuButton_ setAttachedMenu:[appMenuController_ menu]]; |
827 } | 759 } |
828 | 760 |
829 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity | 761 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity |
830 iconType:(AppMenuIconController::IconType)iconType | 762 iconType:(AppMenuIconController::IconType)iconType |
831 animate:(BOOL)animate { | 763 animate:(BOOL)animate { |
832 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
833 AppToolbarButtonCell* cell = | |
834 base::mac::ObjCCastStrict<AppToolbarButtonCell>([appMenuButton_ cell]); | |
835 [cell setSeverity:severity shouldAnimate:animate]; | |
836 return; | |
837 } | |
838 AppToolbarButton* appMenuButton = | 764 AppToolbarButton* appMenuButton = |
839 base::mac::ObjCCastStrict<AppToolbarButton>(appMenuButton_); | 765 base::mac::ObjCCastStrict<AppToolbarButton>(appMenuButton_); |
840 [appMenuButton setSeverity:severity iconType:iconType shouldAnimate:animate]; | 766 [appMenuButton setSeverity:severity iconType:iconType shouldAnimate:animate]; |
841 } | 767 } |
842 | 768 |
843 - (void)prefChanged:(const std::string&)prefName { | 769 - (void)prefChanged:(const std::string&)prefName { |
844 if (prefName == prefs::kShowHomeButton) { | 770 if (prefName == prefs::kShowHomeButton) { |
845 [self showOptionalHomeButton]; | 771 [self showOptionalHomeButton]; |
846 } | 772 } |
847 } | 773 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 | 846 |
921 if ([browserActionsContainerView_ isHidden]) { | 847 if ([browserActionsContainerView_ isHidden]) { |
922 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; | 848 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; |
923 leftDistance = edgeXPos - locationBarXPos - | 849 leftDistance = edgeXPos - locationBarXPos - |
924 [ToolbarController appMenuLeftPadding]; | 850 [ToolbarController appMenuLeftPadding]; |
925 } else { | 851 } else { |
926 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 852 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
927 locationBarXPos; | 853 locationBarXPos; |
928 // Equalize the distance between the location bar and the first extension | 854 // Equalize the distance between the location bar and the first extension |
929 // button, and the distance between the location bar and home/reload button. | 855 // button, and the distance between the location bar and home/reload button. |
930 if (ui::MaterialDesignController::IsModeMaterial()) { | 856 leftDistance -= kMaterialDesignButtonInset; |
931 leftDistance -= kMaterialDesignButtonInset; | |
932 } | |
933 } | 857 } |
934 if (leftDistance != 0.0) | 858 if (leftDistance != 0.0) |
935 [self adjustLocationSizeBy:leftDistance animate:animate]; | 859 [self adjustLocationSizeBy:leftDistance animate:animate]; |
936 else | 860 else |
937 [locationBar_ stopAnimation]; | 861 [locationBar_ stopAnimation]; |
938 } | 862 } |
939 | 863 |
940 - (void)maintainMinimumLocationBarWidth { | 864 - (void)maintainMinimumLocationBarWidth { |
941 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 865 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
942 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 866 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
(...skipping 10 matching lines...) Expand all Loading... | |
953 return; | 877 return; |
954 | 878 |
955 if ([browserActionsContainerView_ isAnimating]) { | 879 if ([browserActionsContainerView_ isAnimating]) { |
956 // If the browser actions container is animating, we need to stop it first, | 880 // If the browser actions container is animating, we need to stop it first, |
957 // because the frame it's animating for could be incorrect with the new | 881 // because the frame it's animating for could be incorrect with the new |
958 // bounds (if, for instance, the bookmark bar was added). | 882 // bounds (if, for instance, the bookmark bar was added). |
959 // This will advance to the end of the animation, so we also need to adjust | 883 // This will advance to the end of the animation, so we also need to adjust |
960 // it afterwards. | 884 // it afterwards. |
961 [browserActionsContainerView_ stopAnimation]; | 885 [browserActionsContainerView_ stopAnimation]; |
962 NSRect containerFrame = [browserActionsContainerView_ frame]; | 886 NSRect containerFrame = [browserActionsContainerView_ frame]; |
963 if (!ui::MaterialDesignController::IsModeMaterial()) { | 887 containerFrame.origin.y = |
964 CGFloat elementTopPadding = | 888 [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; |
965 kMaterialDesignElementPadding + kMaterialDesignButtonInset; | |
966 // Pre-Material Design, this value is calculated from the values in | |
967 // Toolbar.xib: the height of the toolbar (35) minus the height of the | |
968 // child elements (29) minus the y-origin of the elements (4). | |
969 elementTopPadding = 2; | |
970 containerFrame.origin.y = | |
971 NSHeight([[self view] frame]) - NSHeight(containerFrame) - | |
972 elementTopPadding; | |
973 } else { | |
974 containerFrame.origin.y = | |
975 [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; | |
976 } | |
977 [browserActionsContainerView_ setFrame:containerFrame]; | 889 [browserActionsContainerView_ setFrame:containerFrame]; |
978 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 890 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
979 } | 891 } |
980 | 892 |
981 [self maintainMinimumLocationBarWidth]; | 893 [self maintainMinimumLocationBarWidth]; |
982 | 894 |
983 if (locationBarAtMinSize_) { | 895 if (locationBarAtMinSize_) { |
984 // Once the grippy is pinned, leave it until it is explicity un-pinned. | 896 // Once the grippy is pinned, leave it until it is explicity un-pinned. |
985 [browserActionsContainerView_ setGrippyPinned:YES]; | 897 [browserActionsContainerView_ setGrippyPinned:YES]; |
986 NSRect containerFrame = [browserActionsContainerView_ frame]; | 898 NSRect containerFrame = [browserActionsContainerView_ frame]; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 - (NSPoint)saveCreditCardBubblePoint { | 983 - (NSPoint)saveCreditCardBubblePoint { |
1072 return locationBarView_->GetSaveCreditCardBubblePoint(); | 984 return locationBarView_->GetSaveCreditCardBubblePoint(); |
1073 } | 985 } |
1074 | 986 |
1075 - (NSPoint)translateBubblePoint { | 987 - (NSPoint)translateBubblePoint { |
1076 return locationBarView_->GetTranslateBubblePoint(); | 988 return locationBarView_->GetTranslateBubblePoint(); |
1077 } | 989 } |
1078 | 990 |
1079 - (CGFloat)baseToolbarHeight { | 991 - (CGFloat)baseToolbarHeight { |
1080 // Height of the toolbar in pixels when the bookmark bar is closed. | 992 // Height of the toolbar in pixels when the bookmark bar is closed. |
1081 const bool kIsModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | 993 const CGFloat kBaseToolbarHeightNormal = 37; |
1082 const CGFloat kBaseToolbarHeightNormal = kIsModeMaterial ? 37 : 35; | 994 return kBaseToolbarHeightNormal; |
1083 | |
1084 // Not all lines are drawn at 2x normal height when running on Retina, which | |
1085 // causes the toolbar controls to be visually 1pt too high within the toolbar | |
1086 // area. It's not possible to adjust the control y-positions by 0.5pt and have | |
1087 // them appear 0.5pt lower (they are still drawn at their original locations), | |
1088 // so instead shave off 1pt from the bottom of the toolbar. Note that there's | |
1089 // an offsetting change in -[BookmarkBarController preferredHeight] to | |
1090 // maintain the proper spacing between bookmark icons and toolbar items. See | |
1091 // https://crbug.com/326245 . | |
1092 const CGFloat kLineWidth = [[self view] cr_lineWidth]; | |
1093 const BOOL kIsRetina = (kLineWidth < 1); | |
1094 BOOL reduceHeight = NO; | |
1095 | |
1096 // Only adjust the height if Retina and not Material Design. | |
1097 reduceHeight = kIsRetina && !kIsModeMaterial; | |
1098 | |
1099 return reduceHeight ? kBaseToolbarHeightNormal - 1 | |
1100 : kBaseToolbarHeightNormal; | |
1101 } | 995 } |
1102 | 996 |
1103 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { | 997 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { |
1104 // With no toolbar, just ignore the compression. | 998 // With no toolbar, just ignore the compression. |
1105 if (!hasToolbar_) | 999 if (!hasToolbar_) |
1106 return NSHeight([locationBar_ frame]); | 1000 return NSHeight([locationBar_ frame]); |
1107 | 1001 |
1108 return [self baseToolbarHeight] - compressByHeight; | 1002 return [self baseToolbarHeight] - compressByHeight; |
1109 } | 1003 } |
1110 | 1004 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1087 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
1194 // Do nothing. | 1088 // Do nothing. |
1195 } | 1089 } |
1196 | 1090 |
1197 // (URLDropTargetController protocol) | 1091 // (URLDropTargetController protocol) |
1198 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1092 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
1199 return drag_util::IsUnsupportedDropData(profile_, info); | 1093 return drag_util::IsUnsupportedDropData(profile_, info); |
1200 } | 1094 } |
1201 | 1095 |
1202 @end | 1096 @end |
OLD | NEW |