| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const CGFloat kLocationBarHeight = 29.0; | 81 const CGFloat kLocationBarHeight = 29.0; |
| 82 | 82 |
| 83 // The padding above the toolbar elements. This is calculated from the values | 83 // The padding above the toolbar elements. This is calculated from the values |
| 84 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child | 84 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child |
| 85 // elements (29) minus the y-origin of the elements (4). | 85 // elements (29) minus the y-origin of the elements (4). |
| 86 const CGFloat kToolbarElementTopPadding = 2.0; | 86 const CGFloat kToolbarElementTopPadding = 2.0; |
| 87 | 87 |
| 88 // The minimum width of the location bar in pixels. | 88 // The minimum width of the location bar in pixels. |
| 89 const CGFloat kMinimumLocationBarWidth = 100.0; | 89 const CGFloat kMinimumLocationBarWidth = 100.0; |
| 90 | 90 |
| 91 // The amount of left padding that the wrench menu should have. | 91 // The amount of left padding that the app menu should have. |
| 92 const CGFloat kWrenchMenuLeftPadding = 3.0; | 92 const CGFloat kAppMenuLeftPadding = 3.0; |
| 93 | 93 |
| 94 class BrowserActionsContainerDelegate : | 94 class BrowserActionsContainerDelegate : |
| 95 public BrowserActionsContainerViewSizeDelegate { | 95 public BrowserActionsContainerViewSizeDelegate { |
| 96 public: | 96 public: |
| 97 BrowserActionsContainerDelegate( | 97 BrowserActionsContainerDelegate( |
| 98 AutocompleteTextField* location_bar, | 98 AutocompleteTextField* location_bar, |
| 99 BrowserActionsContainerView* browser_actions_container_view); | 99 BrowserActionsContainerView* browser_actions_container_view); |
| 100 ~BrowserActionsContainerDelegate() override; | 100 ~BrowserActionsContainerDelegate() override; |
| 101 | 101 |
| 102 private: | 102 private: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 - (ToolbarView*)toolbarView; | 138 - (ToolbarView*)toolbarView; |
| 139 - (void)toolbarFrameChanged; | 139 - (void)toolbarFrameChanged; |
| 140 - (void)showLocationBarOnly; | 140 - (void)showLocationBarOnly; |
| 141 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 141 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
| 142 - (void)maintainMinimumLocationBarWidth; | 142 - (void)maintainMinimumLocationBarWidth; |
| 143 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 143 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
| 144 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 144 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
| 145 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 145 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
| 146 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; | 146 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; |
| 147 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 147 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
| 148 - (void)updateWrenchButtonSeverity:(AppMenuIconPainter::Severity)severity | 148 - (void)updateAppMenuButtonSeverity:(AppMenuIconPainter::Severity)severity |
| 149 animate:(BOOL)animate; | 149 animate:(BOOL)animate; |
| 150 @end | 150 @end |
| 151 | 151 |
| 152 namespace ToolbarControllerInternal { | 152 namespace ToolbarControllerInternal { |
| 153 | 153 |
| 154 // A C++ bridge class that handles listening for updates to commands and | 154 // A C++ bridge class that handles listening for updates to commands and |
| 155 // passing them back to ToolbarController. ToolbarController will create one of | 155 // passing them back to ToolbarController. ToolbarController will create one of |
| 156 // these bridges, pass them to CommandUpdater::AddCommandObserver, and then wait | 156 // these bridges, pass them to CommandUpdater::AddCommandObserver, and then wait |
| 157 // for update notifications, delivered via | 157 // for update notifications, delivered via |
| 158 // -enabledStateChangedForCommand:enabled:. | 158 // -enabledStateChangedForCommand:enabled:. |
| 159 class CommandObserverBridge : public CommandObserver { | 159 class CommandObserverBridge : public CommandObserver { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 186 } | 186 } |
| 187 ~NotificationBridge() override {} | 187 ~NotificationBridge() override {} |
| 188 | 188 |
| 189 void UpdateBadgeSeverity() { | 189 void UpdateBadgeSeverity() { |
| 190 badge_controller_.UpdateDelegate(); | 190 badge_controller_.UpdateDelegate(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void UpdateBadgeSeverity(AppMenuBadgeController::BadgeType type, | 193 void UpdateBadgeSeverity(AppMenuBadgeController::BadgeType type, |
| 194 AppMenuIconPainter::Severity severity, | 194 AppMenuIconPainter::Severity severity, |
| 195 bool animate) override { | 195 bool animate) override { |
| 196 [controller_ updateWrenchButtonSeverity:severity animate:animate]; | 196 [controller_ updateAppMenuButtonSeverity:severity animate:animate]; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void OnPreferenceChanged(const std::string& pref_name) { | 199 void OnPreferenceChanged(const std::string& pref_name) { |
| 200 [controller_ prefChanged:pref_name]; | 200 [controller_ prefChanged:pref_name]; |
| 201 } | 201 } |
| 202 | 202 |
| 203 private: | 203 private: |
| 204 ToolbarController* controller_; // weak, owns us | 204 ToolbarController* controller_; // weak, owns us |
| 205 | 205 |
| 206 AppMenuBadgeController badge_controller_; | 206 AppMenuBadgeController badge_controller_; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 [[reloadButton_ cell] setImageID:IDR_RELOAD_P | 291 [[reloadButton_ cell] setImageID:IDR_RELOAD_P |
| 292 forButtonState:image_button_cell::kPressedState]; | 292 forButtonState:image_button_cell::kPressedState]; |
| 293 | 293 |
| 294 [[homeButton_ cell] setImageID:IDR_HOME | 294 [[homeButton_ cell] setImageID:IDR_HOME |
| 295 forButtonState:image_button_cell::kDefaultState]; | 295 forButtonState:image_button_cell::kDefaultState]; |
| 296 [[homeButton_ cell] setImageID:IDR_HOME_H | 296 [[homeButton_ cell] setImageID:IDR_HOME_H |
| 297 forButtonState:image_button_cell::kHoverState]; | 297 forButtonState:image_button_cell::kHoverState]; |
| 298 [[homeButton_ cell] setImageID:IDR_HOME_P | 298 [[homeButton_ cell] setImageID:IDR_HOME_P |
| 299 forButtonState:image_button_cell::kPressedState]; | 299 forButtonState:image_button_cell::kPressedState]; |
| 300 | 300 |
| 301 [[wrenchButton_ cell] setImageID:IDR_TOOLS | 301 [[appMenuButton_ cell] setImageID:IDR_TOOLS |
| 302 forButtonState:image_button_cell::kDefaultState]; | 302 forButtonState:image_button_cell::kDefaultState]; |
| 303 [[wrenchButton_ cell] setImageID:IDR_TOOLS_H | 303 [[appMenuButton_ cell] setImageID:IDR_TOOLS_H |
| 304 forButtonState:image_button_cell::kHoverState]; | 304 forButtonState:image_button_cell::kHoverState]; |
| 305 [[wrenchButton_ cell] setImageID:IDR_TOOLS_P | 305 [[appMenuButton_ cell] setImageID:IDR_TOOLS_P |
| 306 forButtonState:image_button_cell::kPressedState]; | 306 forButtonState:image_button_cell::kPressedState]; |
| 307 | 307 |
| 308 notificationBridge_.reset( | 308 notificationBridge_.reset( |
| 309 new ToolbarControllerInternal::NotificationBridge(self)); | 309 new ToolbarControllerInternal::NotificationBridge(self)); |
| 310 notificationBridge_->UpdateBadgeSeverity(); | 310 notificationBridge_->UpdateBadgeSeverity(); |
| 311 | 311 |
| 312 [wrenchButton_ setOpenMenuOnClick:YES]; | 312 [appMenuButton_ setOpenMenuOnClick:YES]; |
| 313 | 313 |
| 314 [backButton_ setOpenMenuOnRightClick:YES]; | 314 [backButton_ setOpenMenuOnRightClick:YES]; |
| 315 [forwardButton_ setOpenMenuOnRightClick:YES]; | 315 [forwardButton_ setOpenMenuOnRightClick:YES]; |
| 316 | 316 |
| 317 [backButton_ setHandleMiddleClick:YES]; | 317 [backButton_ setHandleMiddleClick:YES]; |
| 318 [forwardButton_ setHandleMiddleClick:YES]; | 318 [forwardButton_ setHandleMiddleClick:YES]; |
| 319 [reloadButton_ setHandleMiddleClick:YES]; | 319 [reloadButton_ setHandleMiddleClick:YES]; |
| 320 [homeButton_ setHandleMiddleClick:YES]; | 320 [homeButton_ setHandleMiddleClick:YES]; |
| 321 | 321 |
| 322 [self initCommandStatus:commands_]; | 322 [self initCommandStatus:commands_]; |
| 323 [reloadButton_ setCommandUpdater:commands_]; | 323 [reloadButton_ setCommandUpdater:commands_]; |
| 324 | 324 |
| 325 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, | 325 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, |
| 326 profile_, browser_)); | 326 profile_, browser_)); |
| 327 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 327 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 328 | 328 |
| 329 // Register pref observers for the optional home and page/options buttons | 329 // Register pref observers for the optional home and page/options buttons |
| 330 // and then add them to the toolbar based on those prefs. | 330 // and then add them to the toolbar based on those prefs. |
| 331 PrefService* prefs = profile_->GetPrefs(); | 331 PrefService* prefs = profile_->GetPrefs(); |
| 332 showHomeButton_.Init( | 332 showHomeButton_.Init( |
| 333 prefs::kShowHomeButton, prefs, | 333 prefs::kShowHomeButton, prefs, |
| 334 base::Bind( | 334 base::Bind( |
| 335 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, | 335 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, |
| 336 base::Unretained(notificationBridge_.get()))); | 336 base::Unretained(notificationBridge_.get()))); |
| 337 [self showOptionalHomeButton]; | 337 [self showOptionalHomeButton]; |
| 338 [self installWrenchMenu]; | 338 [self installAppMenu]; |
| 339 | 339 |
| 340 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 340 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| 341 | 341 |
| 342 // Create the controllers for the back/forward menus. | 342 // Create the controllers for the back/forward menus. |
| 343 backMenuController_.reset([[BackForwardMenuController alloc] | 343 backMenuController_.reset([[BackForwardMenuController alloc] |
| 344 initWithBrowser:browser_ | 344 initWithBrowser:browser_ |
| 345 modelType:BACK_FORWARD_MENU_TYPE_BACK | 345 modelType:BACK_FORWARD_MENU_TYPE_BACK |
| 346 button:backButton_]); | 346 button:backButton_]); |
| 347 forwardMenuController_.reset([[BackForwardMenuController alloc] | 347 forwardMenuController_.reset([[BackForwardMenuController alloc] |
| 348 initWithBrowser:browser_ | 348 initWithBrowser:browser_ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 368 selector:@selector(toolbarFrameChanged) | 368 selector:@selector(toolbarFrameChanged) |
| 369 name:NSViewFrameDidChangeNotification | 369 name:NSViewFrameDidChangeNotification |
| 370 object:toolbarView]; | 370 object:toolbarView]; |
| 371 | 371 |
| 372 // Set ViewIDs for toolbar elements which don't have their dedicated class. | 372 // Set ViewIDs for toolbar elements which don't have their dedicated class. |
| 373 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | 373 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
| 374 // |browserActionsContainerView_| are handled by themselves. | 374 // |browserActionsContainerView_| are handled by themselves. |
| 375 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); | 375 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); |
| 376 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); | 376 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); |
| 377 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); | 377 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); |
| 378 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU); | 378 view_id_util::SetID(appMenuButton_, VIEW_ID_APP_MENU); |
| 379 | 379 |
| 380 [self addAccessibilityDescriptions]; | 380 [self addAccessibilityDescriptions]; |
| 381 } | 381 } |
| 382 | 382 |
| 383 - (void)dealloc { | 383 - (void)dealloc { |
| 384 [self cleanUp]; | 384 [self cleanUp]; |
| 385 [super dealloc]; | 385 [super dealloc]; |
| 386 } | 386 } |
| 387 | 387 |
| 388 - (void)browserWillBeDestroyed { | 388 - (void)browserWillBeDestroyed { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 400 [self cleanUp]; | 400 [self cleanUp]; |
| 401 } | 401 } |
| 402 | 402 |
| 403 - (void)cleanUp { | 403 - (void)cleanUp { |
| 404 // Unset ViewIDs of toolbar elements. | 404 // Unset ViewIDs of toolbar elements. |
| 405 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | 405 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
| 406 // |browserActionsContainerView_| are handled by themselves. | 406 // |browserActionsContainerView_| are handled by themselves. |
| 407 view_id_util::UnsetID(backButton_); | 407 view_id_util::UnsetID(backButton_); |
| 408 view_id_util::UnsetID(forwardButton_); | 408 view_id_util::UnsetID(forwardButton_); |
| 409 view_id_util::UnsetID(homeButton_); | 409 view_id_util::UnsetID(homeButton_); |
| 410 view_id_util::UnsetID(wrenchButton_); | 410 view_id_util::UnsetID(appMenuButton_); |
| 411 | 411 |
| 412 // Make sure any code in the base class which assumes [self view] is | 412 // Make sure any code in the base class which assumes [self view] is |
| 413 // the "parent" view continues to work. | 413 // the "parent" view continues to work. |
| 414 hasToolbar_ = YES; | 414 hasToolbar_ = YES; |
| 415 hasLocationBar_ = YES; | 415 hasLocationBar_ = YES; |
| 416 | 416 |
| 417 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 417 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 418 | 418 |
| 419 if (trackingArea_.get()) { | 419 if (trackingArea_.get()) { |
| 420 [[self view] removeTrackingArea:trackingArea_.get()]; | 420 [[self view] removeTrackingArea:trackingArea_.get()]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 forAttribute:NSAccessibilityDescriptionAttribute]; | 454 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 455 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_HOME); | 455 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_HOME); |
| 456 [[homeButton_ cell] | 456 [[homeButton_ cell] |
| 457 accessibilitySetOverrideValue:description | 457 accessibilitySetOverrideValue:description |
| 458 forAttribute:NSAccessibilityDescriptionAttribute]; | 458 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 459 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_LOCATION); | 459 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_LOCATION); |
| 460 [[locationBar_ cell] | 460 [[locationBar_ cell] |
| 461 accessibilitySetOverrideValue:description | 461 accessibilitySetOverrideValue:description |
| 462 forAttribute:NSAccessibilityDescriptionAttribute]; | 462 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 463 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_APP); | 463 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_APP); |
| 464 [[wrenchButton_ cell] | 464 [[appMenuButton_ cell] |
| 465 accessibilitySetOverrideValue:description | 465 accessibilitySetOverrideValue:description |
| 466 forAttribute:NSAccessibilityDescriptionAttribute]; | 466 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 467 } | 467 } |
| 468 | 468 |
| 469 - (void)mouseExited:(NSEvent*)theEvent { | 469 - (void)mouseExited:(NSEvent*)theEvent { |
| 470 [[hoveredButton_ cell] setIsMouseInside:NO]; | 470 [[hoveredButton_ cell] setIsMouseInside:NO]; |
| 471 [hoveredButton_ release]; | 471 [hoveredButton_ release]; |
| 472 hoveredButton_ = nil; | 472 hoveredButton_ = nil; |
| 473 } | 473 } |
| 474 | 474 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 setBackgroundColor:[locationBar_ backgroundColor]]; | 619 setBackgroundColor:[locationBar_ backgroundColor]]; |
| 620 } | 620 } |
| 621 return autocompleteTextFieldEditor_.get(); | 621 return autocompleteTextFieldEditor_.get(); |
| 622 } | 622 } |
| 623 return nil; | 623 return nil; |
| 624 } | 624 } |
| 625 | 625 |
| 626 // Returns an array of views in the order of the outlets above. | 626 // Returns an array of views in the order of the outlets above. |
| 627 - (NSArray*)toolbarViews { | 627 - (NSArray*)toolbarViews { |
| 628 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, | 628 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, |
| 629 homeButton_, wrenchButton_, locationBar_, | 629 homeButton_, appMenuButton_, locationBar_, |
| 630 browserActionsContainerView_, nil]; | 630 browserActionsContainerView_, nil]; |
| 631 } | 631 } |
| 632 | 632 |
| 633 // Moves |rect| to the right by |delta|, keeping the right side fixed by | 633 // Moves |rect| to the right by |delta|, keeping the right side fixed by |
| 634 // shrinking the width to compensate. Passing a negative value for |deltaX| | 634 // shrinking the width to compensate. Passing a negative value for |deltaX| |
| 635 // moves to the left and increases the width. | 635 // moves to the left and increases the width. |
| 636 - (NSRect)adjustRect:(NSRect)rect byAmount:(CGFloat)deltaX { | 636 - (NSRect)adjustRect:(NSRect)rect byAmount:(CGFloat)deltaX { |
| 637 NSRect frame = NSOffsetRect(rect, deltaX, 0); | 637 NSRect frame = NSOffsetRect(rect, deltaX, 0); |
| 638 frame.size.width -= deltaX; | 638 frame.size.width -= deltaX; |
| 639 return frame; | 639 return frame; |
| 640 } | 640 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 653 // hiding the button, reverse the direction of the movement (to the left). | 653 // hiding the button, reverse the direction of the movement (to the left). |
| 654 CGFloat moveX = [homeButton_ frame].size.width - 1.0; | 654 CGFloat moveX = [homeButton_ frame].size.width - 1.0; |
| 655 if (hide) | 655 if (hide) |
| 656 moveX *= -1; // Reverse the direction of the move. | 656 moveX *= -1; // Reverse the direction of the move. |
| 657 | 657 |
| 658 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 658 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
| 659 byAmount:moveX]]; | 659 byAmount:moveX]]; |
| 660 [homeButton_ setHidden:hide]; | 660 [homeButton_ setHidden:hide]; |
| 661 } | 661 } |
| 662 | 662 |
| 663 // Install the menu wrench buttons. Calling this repeatedly is inexpensive so it | 663 // Install the app menu buttons. Calling this repeatedly is inexpensive so it |
| 664 // can be done every time the buttons are shown. | 664 // can be done every time the buttons are shown. |
| 665 - (void)installWrenchMenu { | 665 - (void)installAppMenu { |
| 666 if (appMenuController_.get()) | 666 if (appMenuController_.get()) |
| 667 return; | 667 return; |
| 668 | 668 |
| 669 appMenuController_.reset( | 669 appMenuController_.reset( |
| 670 [[AppMenuController alloc] initWithBrowser:browser_]); | 670 [[AppMenuController alloc] initWithBrowser:browser_]); |
| 671 [appMenuController_ setUseWithPopUpButtonCell:YES]; | 671 [appMenuController_ setUseWithPopUpButtonCell:YES]; |
| 672 [wrenchButton_ setAttachedMenu:[appMenuController_ menu]]; | 672 [appMenuButton_ setAttachedMenu:[appMenuController_ menu]]; |
| 673 } | 673 } |
| 674 | 674 |
| 675 - (void)updateWrenchButtonSeverity:(AppMenuIconPainter::Severity)severity | 675 - (void)updateAppButtonSeverity:(AppMenuIconPainter::Severity)severity |
| 676 animate:(BOOL)animate { | 676 animate:(BOOL)animate { |
| 677 AppToolbarButtonCell* cell = | 677 AppToolbarButtonCell* cell = |
| 678 base::mac::ObjCCastStrict<AppToolbarButtonCell>([wrenchButton_ cell]); | 678 base::mac::ObjCCastStrict<AppToolbarButtonCell>([appMenuButton_ cell]); |
| 679 [cell setSeverity:severity shouldAnimate:animate]; | 679 [cell setSeverity:severity shouldAnimate:animate]; |
| 680 } | 680 } |
| 681 | 681 |
| 682 - (void)prefChanged:(const std::string&)prefName { | 682 - (void)prefChanged:(const std::string&)prefName { |
| 683 if (prefName == prefs::kShowHomeButton) { | 683 if (prefName == prefs::kShowHomeButton) { |
| 684 [self showOptionalHomeButton]; | 684 [self showOptionalHomeButton]; |
| 685 } | 685 } |
| 686 } | 686 } |
| 687 | 687 |
| 688 - (void)createBrowserActionButtons { | 688 - (void)createBrowserActionButtons { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 751 |
| 752 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { | 752 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { |
| 753 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; | 753 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; |
| 754 } | 754 } |
| 755 | 755 |
| 756 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { | 756 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { |
| 757 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); | 757 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); |
| 758 CGFloat leftDistance = 0.0; | 758 CGFloat leftDistance = 0.0; |
| 759 | 759 |
| 760 if ([browserActionsContainerView_ isHidden]) { | 760 if ([browserActionsContainerView_ isHidden]) { |
| 761 CGFloat edgeXPos = [wrenchButton_ frame].origin.x; | 761 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; |
| 762 leftDistance = edgeXPos - locationBarXPos - kWrenchMenuLeftPadding; | 762 leftDistance = edgeXPos - locationBarXPos - kAppMenuLeftPadding; |
| 763 } else { | 763 } else { |
| 764 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 764 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
| 765 locationBarXPos; | 765 locationBarXPos; |
| 766 } | 766 } |
| 767 if (leftDistance != 0.0) | 767 if (leftDistance != 0.0) |
| 768 [self adjustLocationSizeBy:leftDistance animate:animate]; | 768 [self adjustLocationSizeBy:leftDistance animate:animate]; |
| 769 else | 769 else |
| 770 [locationBar_ stopAnimation]; | 770 [locationBar_ stopAnimation]; |
| 771 } | 771 } |
| 772 | 772 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 containerFrame = NSOffsetRect(containerFrame, | 828 containerFrame = NSOffsetRect(containerFrame, |
| 829 NSWidth(containerFrame) - savedContainerWidth, 0); | 829 NSWidth(containerFrame) - savedContainerWidth, 0); |
| 830 containerFrame.size.width = savedContainerWidth; | 830 containerFrame.size.width = savedContainerWidth; |
| 831 [browserActionsContainerView_ setGrippyPinned:NO]; | 831 [browserActionsContainerView_ setGrippyPinned:NO]; |
| 832 } | 832 } |
| 833 [browserActionsContainerView_ setFrame:containerFrame]; | 833 [browserActionsContainerView_ setFrame:containerFrame]; |
| 834 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 834 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| 835 } | 835 } |
| 836 } | 836 } |
| 837 | 837 |
| 838 // Hide the back, forward, reload, home, and wrench buttons of the toolbar. | 838 // Hide the back, forward, reload, home, and app menu buttons of the toolbar. |
| 839 // This allows the location bar to occupy the entire width. There is no way to | 839 // This allows the location bar to occupy the entire width. There is no way to |
| 840 // undo this operation, and once it is called, no other programmatic changes | 840 // undo this operation, and once it is called, no other programmatic changes |
| 841 // to the toolbar or location bar width should be made. This message is | 841 // to the toolbar or location bar width should be made. This message is |
| 842 // invalid if the toolbar is shown or the location bar is hidden. | 842 // invalid if the toolbar is shown or the location bar is hidden. |
| 843 - (void)showLocationBarOnly { | 843 - (void)showLocationBarOnly { |
| 844 // -showLocationBarOnly is only ever called once, shortly after | 844 // -showLocationBarOnly is only ever called once, shortly after |
| 845 // initialization, so the regular buttons should all be visible. | 845 // initialization, so the regular buttons should all be visible. |
| 846 DCHECK(!hasToolbar_ && hasLocationBar_); | 846 DCHECK(!hasToolbar_ && hasLocationBar_); |
| 847 DCHECK(![backButton_ isHidden]); | 847 DCHECK(![backButton_ isHidden]); |
| 848 | 848 |
| 849 // Ensure the location bar fills the toolbar. | 849 // Ensure the location bar fills the toolbar. |
| 850 NSRect toolbarFrame = [[self view] frame]; | 850 NSRect toolbarFrame = [[self view] frame]; |
| 851 toolbarFrame.size.height = kLocationBarHeight; | 851 toolbarFrame.size.height = kLocationBarHeight; |
| 852 [[self view] setFrame:toolbarFrame]; | 852 [[self view] setFrame:toolbarFrame]; |
| 853 | 853 |
| 854 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), | 854 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), |
| 855 kLocationBarHeight)]; | 855 kLocationBarHeight)]; |
| 856 | 856 |
| 857 [backButton_ setHidden:YES]; | 857 [backButton_ setHidden:YES]; |
| 858 [forwardButton_ setHidden:YES]; | 858 [forwardButton_ setHidden:YES]; |
| 859 [reloadButton_ setHidden:YES]; | 859 [reloadButton_ setHidden:YES]; |
| 860 [wrenchButton_ setHidden:YES]; | 860 [appMenuButton_ setHidden:YES]; |
| 861 [homeButton_ setHidden:YES]; | 861 [homeButton_ setHidden:YES]; |
| 862 } | 862 } |
| 863 | 863 |
| 864 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { | 864 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { |
| 865 // Ensure that the location bar is in its proper place. | 865 // Ensure that the location bar is in its proper place. |
| 866 NSRect locationFrame = [locationBar_ frame]; | 866 NSRect locationFrame = [locationBar_ frame]; |
| 867 locationFrame.size.width += dX; | 867 locationFrame.size.width += dX; |
| 868 | 868 |
| 869 [locationBar_ stopAnimation]; | 869 [locationBar_ stopAnimation]; |
| 870 | 870 |
| 871 if (animate) | 871 if (animate) |
| 872 [locationBar_ animateToFrame:locationFrame]; | 872 [locationBar_ animateToFrame:locationFrame]; |
| 873 else | 873 else |
| 874 [locationBar_ setFrame:locationFrame]; | 874 [locationBar_ setFrame:locationFrame]; |
| 875 } | 875 } |
| 876 | 876 |
| 877 - (NSPoint)bookmarkBubblePoint { | 877 - (NSPoint)bookmarkBubblePoint { |
| 878 if (locationBarView_->IsStarEnabled()) | 878 if (locationBarView_->IsStarEnabled()) |
| 879 return locationBarView_->GetBookmarkBubblePoint(); | 879 return locationBarView_->GetBookmarkBubblePoint(); |
| 880 | 880 |
| 881 // Grab bottom middle of hotdogs. | 881 // Grab bottom middle of hotdogs. |
| 882 NSRect frame = wrenchButton_.frame; | 882 NSRect frame = appMenuButton_.frame; |
| 883 NSPoint point = NSMakePoint(NSMidX(frame), NSMinY(frame)); | 883 NSPoint point = NSMakePoint(NSMidX(frame), NSMinY(frame)); |
| 884 // Inset to account for the whitespace around the hotdogs. | 884 // Inset to account for the whitespace around the hotdogs. |
| 885 point.y += app_menu_controller::kAppMenuBubblePointOffsetY; | 885 point.y += app_menu_controller::kAppMenuBubblePointOffsetY; |
| 886 return [self.view convertPoint:point toView:nil]; | 886 return [self.view convertPoint:point toView:nil]; |
| 887 } | 887 } |
| 888 | 888 |
| 889 - (NSPoint)managePasswordsBubblePoint { | 889 - (NSPoint)managePasswordsBubblePoint { |
| 890 return locationBarView_->GetManagePasswordsBubblePoint(); | 890 return locationBarView_->GetManagePasswordsBubblePoint(); |
| 891 } | 891 } |
| 892 | 892 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 906 ToolbarView* toolbarView = [self toolbarView]; | 906 ToolbarView* toolbarView = [self toolbarView]; |
| 907 [toolbarView setShowsDivider:(opacity > 0 ? YES : NO)]; | 907 [toolbarView setShowsDivider:(opacity > 0 ? YES : NO)]; |
| 908 [toolbarView setDividerOpacity:opacity]; | 908 [toolbarView setDividerOpacity:opacity]; |
| 909 [toolbarView setNeedsDisplay:YES]; | 909 [toolbarView setNeedsDisplay:YES]; |
| 910 } | 910 } |
| 911 | 911 |
| 912 - (BrowserActionsController*)browserActionsController { | 912 - (BrowserActionsController*)browserActionsController { |
| 913 return browserActionsController_.get(); | 913 return browserActionsController_.get(); |
| 914 } | 914 } |
| 915 | 915 |
| 916 - (NSView*)wrenchButton { | 916 - (NSView*)appMenuButton { |
| 917 return wrenchButton_; | 917 return appMenuButton_; |
| 918 } | 918 } |
| 919 | 919 |
| 920 - (AppMenuController*)appMenuController { | 920 - (AppMenuController*)appMenuController { |
| 921 return appMenuController_.get(); | 921 return appMenuController_.get(); |
| 922 } | 922 } |
| 923 | 923 |
| 924 // (URLDropTargetController protocol) | 924 // (URLDropTargetController protocol) |
| 925 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { | 925 - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { |
| 926 // TODO(viettrungluu): This code is more or less copied from the code in | 926 // TODO(viettrungluu): This code is more or less copied from the code in |
| 927 // |TabStripController|. I'll refactor this soon to make it common and expand | 927 // |TabStripController|. I'll refactor this soon to make it common and expand |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 975 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 976 // Do nothing. | 976 // Do nothing. |
| 977 } | 977 } |
| 978 | 978 |
| 979 // (URLDropTargetController protocol) | 979 // (URLDropTargetController protocol) |
| 980 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 980 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 981 return drag_util::IsUnsupportedDropData(profile_, info); | 981 return drag_util::IsUnsupportedDropData(profile_, info); |
| 982 } | 982 } |
| 983 | 983 |
| 984 @end | 984 @end |
| OLD | NEW |