| 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/extensions/browser_actions_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 14 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
| 14 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 15 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
| 16 #import "chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h" |
| 15 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 17 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/extensions/extension_toolbar_icon_surfacing_bub
ble_mac.h" | 18 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" |
| 17 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 19 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 18 #import "chrome/browser/ui/cocoa/menu_button.h" | 20 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 21 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 22 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 24 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 25 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 26 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 24 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
| 25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 28 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 26 | 29 |
| 27 NSString* const kBrowserActionVisibilityChangedNotification = | 30 NSString* const kBrowserActionVisibilityChangedNotification = |
| 28 @"BrowserActionVisibilityChangedNotification"; | 31 @"BrowserActionVisibilityChangedNotification"; |
| 29 | 32 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 137 |
| 135 // Handles when a menu item within the chevron overflow menu is selected. | 138 // Handles when a menu item within the chevron overflow menu is selected. |
| 136 - (void)chevronItemSelected:(id)menuItem; | 139 - (void)chevronItemSelected:(id)menuItem; |
| 137 | 140 |
| 138 // Updates the container's grippy cursor based on the number of hidden buttons. | 141 // Updates the container's grippy cursor based on the number of hidden buttons. |
| 139 - (void)updateGrippyCursors; | 142 - (void)updateGrippyCursors; |
| 140 | 143 |
| 141 // Returns the associated ToolbarController. | 144 // Returns the associated ToolbarController. |
| 142 - (ToolbarController*)toolbarController; | 145 - (ToolbarController*)toolbarController; |
| 143 | 146 |
| 147 // Creates a message bubble anchored to the first action in the toolbar (or the |
| 148 // overflow menu, if no actions are present). |
| 149 - (ToolbarActionsBarBubbleMac*)createMessageBubble: |
| 150 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate; |
| 151 |
| 144 @end | 152 @end |
| 145 | 153 |
| 146 namespace { | 154 namespace { |
| 147 | 155 |
| 148 // A bridge between the ToolbarActionsBar and the BrowserActionsController. | 156 // A bridge between the ToolbarActionsBar and the BrowserActionsController. |
| 149 class ToolbarActionsBarBridge : public ToolbarActionsBarDelegate { | 157 class ToolbarActionsBarBridge : public ToolbarActionsBarDelegate { |
| 150 public: | 158 public: |
| 151 explicit ToolbarActionsBarBridge(BrowserActionsController* controller); | 159 explicit ToolbarActionsBarBridge(BrowserActionsController* controller); |
| 152 ~ToolbarActionsBarBridge() override; | 160 ~ToolbarActionsBarBridge() override; |
| 153 | 161 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 254 } |
| 247 | 255 |
| 248 void ToolbarActionsBarBridge::OnOverflowedActionWantsToRunChanged( | 256 void ToolbarActionsBarBridge::OnOverflowedActionWantsToRunChanged( |
| 249 bool overflowed_action_wants_to_run) { | 257 bool overflowed_action_wants_to_run) { |
| 250 [[controller_ toolbarController] | 258 [[controller_ toolbarController] |
| 251 setOverflowedToolbarActionWantsToRun:overflowed_action_wants_to_run]; | 259 setOverflowedToolbarActionWantsToRun:overflowed_action_wants_to_run]; |
| 252 } | 260 } |
| 253 | 261 |
| 254 void ToolbarActionsBarBridge::ShowExtensionMessageBubble( | 262 void ToolbarActionsBarBridge::ShowExtensionMessageBubble( |
| 255 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 263 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 256 NOTREACHED(); // Not yet implemented on Mac. | 264 // This goop is a by-product of needing to wire together abstract classes, |
| 265 // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange |
| 266 // Show() interface. It's ugly, but it's pretty confined, so it's probably |
| 267 // okay (but if we ever need to expand, it might need to be reconsidered). |
| 268 scoped_ptr<ExtensionMessageBubbleBridge> bridge( |
| 269 new ExtensionMessageBubbleBridge(controller.Pass())); |
| 270 ExtensionMessageBubbleBridge* weak_bridge = bridge.get(); |
| 271 ToolbarActionsBarBubbleMac* bubble = |
| 272 [controller_ createMessageBubble:bridge.Pass()]; |
| 273 weak_bridge->SetBubble(bubble); |
| 274 weak_bridge->controller()->Show(weak_bridge); |
| 257 } | 275 } |
| 258 | 276 |
| 259 } // namespace | 277 } // namespace |
| 260 | 278 |
| 261 @implementation BrowserActionsController | 279 @implementation BrowserActionsController |
| 262 | 280 |
| 263 @synthesize containerView = containerView_; | 281 @synthesize containerView = containerView_; |
| 264 @synthesize browser = browser_; | 282 @synthesize browser = browser_; |
| 265 @synthesize isOverflow = isOverflow_; | 283 @synthesize isOverflow = isOverflow_; |
| 266 | 284 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 336 } |
| 319 | 337 |
| 320 if (isOverflow_) | 338 if (isOverflow_) |
| 321 toolbarActionsBar_->SetOverflowRowWidth(NSWidth([containerView_ frame])); | 339 toolbarActionsBar_->SetOverflowRowWidth(NSWidth([containerView_ frame])); |
| 322 | 340 |
| 323 buttons_.reset([[NSMutableArray alloc] init]); | 341 buttons_.reset([[NSMutableArray alloc] init]); |
| 324 toolbarActionsBar_->CreateActions(); | 342 toolbarActionsBar_->CreateActions(); |
| 325 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; | 343 [self showChevronIfNecessaryInFrame:[containerView_ frame]]; |
| 326 [self updateGrippyCursors]; | 344 [self updateGrippyCursors]; |
| 327 [container setResizable:!isOverflow_]; | 345 [container setResizable:!isOverflow_]; |
| 328 if (toolbarActionsBar_->ShouldShowInfoBubble()) { | 346 if (ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( |
| 347 browser_->profile())) { |
| 329 [containerView_ setTrackingEnabled:YES]; | 348 [containerView_ setTrackingEnabled:YES]; |
| 330 [[NSNotificationCenter defaultCenter] | 349 [[NSNotificationCenter defaultCenter] |
| 331 addObserver:self | 350 addObserver:self |
| 332 selector:@selector(containerMouseEntered:) | 351 selector:@selector(containerMouseEntered:) |
| 333 name:kBrowserActionsContainerMouseEntered | 352 name:kBrowserActionsContainerMouseEntered |
| 334 object:containerView_]; | 353 object:containerView_]; |
| 335 } | 354 } |
| 336 } | 355 } |
| 337 | 356 |
| 338 return self; | 357 return self; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 name:kBrowserActionButtonDraggingNotification | 500 name:kBrowserActionButtonDraggingNotification |
| 482 object:newButton]; | 501 object:newButton]; |
| 483 | 502 |
| 484 [containerView_ setMaxDesiredWidth:toolbarActionsBar_->GetMaximumWidth()]; | 503 [containerView_ setMaxDesiredWidth:toolbarActionsBar_->GetMaximumWidth()]; |
| 485 } | 504 } |
| 486 | 505 |
| 487 - (void)redraw { | 506 - (void)redraw { |
| 488 if (![self updateContainerVisibility]) | 507 if (![self updateContainerVisibility]) |
| 489 return; // Container is hidden; no need to update. | 508 return; // Container is hidden; no need to update. |
| 490 | 509 |
| 510 [containerView_ setIsHighlighting:toolbarActionsBar_->is_highlighting()]; |
| 511 |
| 491 std::vector<ToolbarActionViewController*> toolbar_actions = | 512 std::vector<ToolbarActionViewController*> toolbar_actions = |
| 492 toolbarActionsBar_->toolbar_actions(); | 513 toolbarActionsBar_->toolbar_actions(); |
| 493 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { | 514 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { |
| 494 if ([[buttons_ objectAtIndex:i] viewController] != toolbar_actions[i]) { | 515 if ([[buttons_ objectAtIndex:i] viewController] != toolbar_actions[i]) { |
| 495 size_t j = i + 1; | 516 size_t j = i + 1; |
| 496 while (toolbar_actions[i] != [[buttons_ objectAtIndex:j] viewController]) | 517 while (toolbar_actions[i] != [[buttons_ objectAtIndex:j] viewController]) |
| 497 ++j; | 518 ++j; |
| 498 [buttons_ exchangeObjectAtIndex:i withObjectAtIndex: j]; | 519 [buttons_ exchangeObjectAtIndex:i withObjectAtIndex: j]; |
| 499 } | 520 } |
| 500 } | 521 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 } | 684 } |
| 664 | 685 |
| 665 toolbarActionsBar_->OnResizeComplete( | 686 toolbarActionsBar_->OnResizeComplete( |
| 666 toolbarActionsBar_->IconCountToWidth([self visibleButtonCount])); | 687 toolbarActionsBar_->IconCountToWidth([self visibleButtonCount])); |
| 667 | 688 |
| 668 [self updateGrippyCursors]; | 689 [self updateGrippyCursors]; |
| 669 [self resizeContainerToWidth:toolbarActionsBar_->GetPreferredSize().width()]; | 690 [self resizeContainerToWidth:toolbarActionsBar_->GetPreferredSize().width()]; |
| 670 } | 691 } |
| 671 | 692 |
| 672 - (void)containerMouseEntered:(NSNotification*)notification { | 693 - (void)containerMouseEntered:(NSNotification*)notification { |
| 673 if (toolbarActionsBar_->ShouldShowInfoBubble()) { | 694 if (ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( |
| 674 NSPoint anchor = [self popupPointForId:[[buttons_ objectAtIndex:0] | 695 browser_->profile())) { |
| 675 viewController]->GetId()]; | 696 ToolbarActionsBarBubbleMac* bubble = |
| 676 anchor = [[containerView_ window] convertBaseToScreen:anchor]; | 697 [self createMessageBubble:scoped_ptr<ToolbarActionsBarBubbleDelegate>( |
| 677 ExtensionToolbarIconSurfacingBubbleMac* bubble = | 698 new ExtensionToolbarIconSurfacingBubbleDelegate( |
| 678 [[ExtensionToolbarIconSurfacingBubbleMac alloc] | 699 browser_->profile()))]; |
| 679 initWithParentWindow:[containerView_ window] | |
| 680 anchorPoint:anchor | |
| 681 delegate:toolbarActionsBar_.get()]; | |
| 682 [bubble showWindow:nil]; | 700 [bubble showWindow:nil]; |
| 683 } | 701 } |
| 684 [containerView_ setTrackingEnabled:NO]; | 702 [containerView_ setTrackingEnabled:NO]; |
| 685 [[NSNotificationCenter defaultCenter] | 703 [[NSNotificationCenter defaultCenter] |
| 686 removeObserver:self | 704 removeObserver:self |
| 687 name:kBrowserActionsContainerMouseEntered | 705 name:kBrowserActionsContainerMouseEntered |
| 688 object:containerView_]; | 706 object:containerView_]; |
| 689 } | 707 } |
| 690 | 708 |
| 691 - (void)actionButtonDragging:(NSNotification*)notification { | 709 - (void)actionButtonDragging:(NSNotification*)notification { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]]; | 879 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]]; |
| 862 [containerView_ setCanDragRight:[self visibleButtonCount] > 0]; | 880 [containerView_ setCanDragRight:[self visibleButtonCount] > 0]; |
| 863 [[containerView_ window] invalidateCursorRectsForView:containerView_]; | 881 [[containerView_ window] invalidateCursorRectsForView:containerView_]; |
| 864 } | 882 } |
| 865 | 883 |
| 866 - (ToolbarController*)toolbarController { | 884 - (ToolbarController*)toolbarController { |
| 867 return [[BrowserWindowController browserWindowControllerForWindow: | 885 return [[BrowserWindowController browserWindowControllerForWindow: |
| 868 browser_->window()->GetNativeWindow()] toolbarController]; | 886 browser_->window()->GetNativeWindow()] toolbarController]; |
| 869 } | 887 } |
| 870 | 888 |
| 889 - (ToolbarActionsBarBubbleMac*)createMessageBubble: |
| 890 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate { |
| 891 DCHECK_GE([buttons_ count], 0u); |
| 892 NSPoint anchor = [self popupPointForId:[[buttons_ objectAtIndex:0] |
| 893 viewController]->GetId()]; |
| 894 anchor = [[containerView_ window] convertBaseToScreen:anchor]; |
| 895 return [[ToolbarActionsBarBubbleMac alloc] |
| 896 initWithParentWindow:[containerView_ window] |
| 897 anchorPoint:anchor |
| 898 delegate:delegate.Pass()]; |
| 899 } |
| 900 |
| 871 | 901 |
| 872 #pragma mark - | 902 #pragma mark - |
| 873 #pragma mark Testing Methods | 903 #pragma mark Testing Methods |
| 874 | 904 |
| 875 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 905 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
| 876 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 906 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
| 877 } | 907 } |
| 878 | 908 |
| 879 - (ToolbarActionsBar*)toolbarActionsBar { | 909 - (ToolbarActionsBar*)toolbarActionsBar { |
| 880 return toolbarActionsBar_.get(); | 910 return toolbarActionsBar_.get(); |
| 881 } | 911 } |
| 882 | 912 |
| 883 + (BrowserActionsController*)fromToolbarActionsBarDelegate: | 913 + (BrowserActionsController*)fromToolbarActionsBarDelegate: |
| 884 (ToolbarActionsBarDelegate*)delegate { | 914 (ToolbarActionsBarDelegate*)delegate { |
| 885 return static_cast<ToolbarActionsBarBridge*>(delegate)->controller_for_test(); | 915 return static_cast<ToolbarActionsBarBridge*>(delegate)->controller_for_test(); |
| 886 } | 916 } |
| 887 | 917 |
| 888 @end | 918 @end |
| OLD | NEW |