| 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/extensions/extension_message_bubble_controller.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 - (void)containerDragStart:(NSNotification*)notification; | 92 - (void)containerDragStart:(NSNotification*)notification; |
| 93 | 93 |
| 94 // Determines which buttons need to be hidden based on the new size, hides them | 94 // Determines which buttons need to be hidden based on the new size, hides them |
| 95 // and updates the chevron overflow menu. Also fires a notification to let the | 95 // and updates the chevron overflow menu. Also fires a notification to let the |
| 96 // toolbar know that the drag has finished. | 96 // toolbar know that the drag has finished. |
| 97 - (void)containerDragFinished:(NSNotification*)notification; | 97 - (void)containerDragFinished:(NSNotification*)notification; |
| 98 | 98 |
| 99 // Shows the toolbar info bubble, if it should be displayed. | 99 // Shows the toolbar info bubble, if it should be displayed. |
| 100 - (void)containerMouseEntered:(NSNotification*)notification; | 100 - (void)containerMouseEntered:(NSNotification*)notification; |
| 101 | 101 |
| 102 - (void)containerAnimationEnded:(NSNotification*)notification; |
| 103 |
| 102 // Adjusts the position of the surrounding action buttons depending on where the | 104 // Adjusts the position of the surrounding action buttons depending on where the |
| 103 // button is within the container. | 105 // button is within the container. |
| 104 - (void)actionButtonDragging:(NSNotification*)notification; | 106 - (void)actionButtonDragging:(NSNotification*)notification; |
| 105 | 107 |
| 106 // Updates the position of the Browser Actions within the container. This fires | 108 // Updates the position of the Browser Actions within the container. This fires |
| 107 // when _any_ Browser Action button is done dragging to keep all open windows in | 109 // when _any_ Browser Action button is done dragging to keep all open windows in |
| 108 // sync visually. | 110 // sync visually. |
| 109 - (void)actionButtonDragFinished:(NSNotification*)notification; | 111 - (void)actionButtonDragFinished:(NSNotification*)notification; |
| 110 | 112 |
| 111 // Returns the frame that the button with the given |index| should have. | 113 // Returns the frame that the button with the given |index| should have. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 [[NSNotificationCenter defaultCenter] | 318 [[NSNotificationCenter defaultCenter] |
| 317 addObserver:self | 319 addObserver:self |
| 318 selector:@selector(containerDragStart:) | 320 selector:@selector(containerDragStart:) |
| 319 name:kBrowserActionGrippyDragStartedNotification | 321 name:kBrowserActionGrippyDragStartedNotification |
| 320 object:containerView_]; | 322 object:containerView_]; |
| 321 [[NSNotificationCenter defaultCenter] | 323 [[NSNotificationCenter defaultCenter] |
| 322 addObserver:self | 324 addObserver:self |
| 323 selector:@selector(containerDragFinished:) | 325 selector:@selector(containerDragFinished:) |
| 324 name:kBrowserActionGrippyDragFinishedNotification | 326 name:kBrowserActionGrippyDragFinishedNotification |
| 325 object:containerView_]; | 327 object:containerView_]; |
| 328 [[NSNotificationCenter defaultCenter] |
| 329 addObserver:self |
| 330 selector:@selector(containerAnimationEnded:) |
| 331 name:kBrowserActionsContainerAnimationEnded |
| 332 object:containerView_]; |
| 326 // Listen for a finished drag from any button to make sure each open window | 333 // Listen for a finished drag from any button to make sure each open window |
| 327 // stays in sync. | 334 // stays in sync. |
| 328 [[NSNotificationCenter defaultCenter] | 335 [[NSNotificationCenter defaultCenter] |
| 329 addObserver:self | 336 addObserver:self |
| 330 selector:@selector(actionButtonDragFinished:) | 337 selector:@selector(actionButtonDragFinished:) |
| 331 name:kBrowserActionButtonDragEndNotification | 338 name:kBrowserActionButtonDragEndNotification |
| 332 object:nil]; | 339 object:nil]; |
| 333 | 340 |
| 334 suppressChevron_ = NO; | 341 suppressChevron_ = NO; |
| 335 if (toolbarActionsBar_->platform_settings().chevron_enabled) { | 342 if (toolbarActionsBar_->platform_settings().chevron_enabled) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 - (content::WebContents*)currentWebContents { | 443 - (content::WebContents*)currentWebContents { |
| 437 return browser_->tab_strip_model()->GetActiveWebContents(); | 444 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 438 } | 445 } |
| 439 | 446 |
| 440 - (BrowserActionButton*)mainButtonForId:(const std::string&)id { | 447 - (BrowserActionButton*)mainButtonForId:(const std::string&)id { |
| 441 BrowserActionsController* mainController = isOverflow_ ? | 448 BrowserActionsController* mainController = isOverflow_ ? |
| 442 [[self toolbarController] browserActionsController] : self; | 449 [[self toolbarController] browserActionsController] : self; |
| 443 return [mainController buttonForId:id]; | 450 return [mainController buttonForId:id]; |
| 444 } | 451 } |
| 445 | 452 |
| 453 - (ToolbarActionsBar*)toolbarActionsBar { |
| 454 return toolbarActionsBar_.get(); |
| 455 } |
| 456 |
| 446 #pragma mark - | 457 #pragma mark - |
| 447 #pragma mark NSMenuDelegate | 458 #pragma mark NSMenuDelegate |
| 448 | 459 |
| 449 - (void)menuNeedsUpdate:(NSMenu*)menu { | 460 - (void)menuNeedsUpdate:(NSMenu*)menu { |
| 450 [menu removeAllItems]; | 461 [menu removeAllItems]; |
| 451 | 462 |
| 452 // See menu_button.h for documentation on why this is needed. | 463 // See menu_button.h for documentation on why this is needed. |
| 453 [menu addItemWithTitle:@"" action:nil keyEquivalent:@""]; | 464 [menu addItemWithTitle:@"" action:nil keyEquivalent:@""]; |
| 454 | 465 |
| 455 NSUInteger iconCount = toolbarActionsBar_->GetIconCount(); | 466 NSUInteger iconCount = toolbarActionsBar_->GetIconCount(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 [containerView_ setMaxDesiredWidth:toolbarActionsBar_->GetMaximumWidth()]; | 508 [containerView_ setMaxDesiredWidth:toolbarActionsBar_->GetMaximumWidth()]; |
| 498 } | 509 } |
| 499 | 510 |
| 500 - (void)redraw { | 511 - (void)redraw { |
| 501 if (![self updateContainerVisibility]) | 512 if (![self updateContainerVisibility]) |
| 502 return; // Container is hidden; no need to update. | 513 return; // Container is hidden; no need to update. |
| 503 | 514 |
| 504 [containerView_ setIsHighlighting:toolbarActionsBar_->is_highlighting()]; | 515 [containerView_ setIsHighlighting:toolbarActionsBar_->is_highlighting()]; |
| 505 | 516 |
| 506 std::vector<ToolbarActionViewController*> toolbar_actions = | 517 std::vector<ToolbarActionViewController*> toolbar_actions = |
| 507 toolbarActionsBar_->toolbar_actions(); | 518 toolbarActionsBar_->GetActions(); |
| 508 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { | 519 for (NSUInteger i = 0; i < [buttons_ count]; ++i) { |
| 509 auto controller = static_cast<ToolbarActionViewController*>( | 520 auto controller = static_cast<ToolbarActionViewController*>( |
| 510 [[buttons_ objectAtIndex:i] viewController]); | 521 [[buttons_ objectAtIndex:i] viewController]); |
| 511 if (controller != toolbar_actions[i]) { | 522 if (controller != toolbar_actions[i]) { |
| 512 size_t j = i + 1; | 523 size_t j = i + 1; |
| 513 while (true) { | 524 while (true) { |
| 514 auto other_controller = static_cast<ToolbarActionViewController*>( | 525 auto other_controller = static_cast<ToolbarActionViewController*>( |
| 515 [[buttons_ objectAtIndex:j] viewController]); | 526 [[buttons_ objectAtIndex:j] viewController]); |
| 516 if (other_controller == toolbar_actions[i]) | 527 if (other_controller == toolbar_actions[i]) |
| 517 break; | 528 break; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 } | 695 } |
| 685 } | 696 } |
| 686 | 697 |
| 687 toolbarActionsBar_->OnResizeComplete( | 698 toolbarActionsBar_->OnResizeComplete( |
| 688 toolbarActionsBar_->IconCountToWidth([self visibleButtonCount])); | 699 toolbarActionsBar_->IconCountToWidth([self visibleButtonCount])); |
| 689 | 700 |
| 690 [self updateGrippyCursors]; | 701 [self updateGrippyCursors]; |
| 691 [self resizeContainerToWidth:toolbarActionsBar_->GetPreferredSize().width()]; | 702 [self resizeContainerToWidth:toolbarActionsBar_->GetPreferredSize().width()]; |
| 692 } | 703 } |
| 693 | 704 |
| 705 - (void)containerAnimationEnded:(NSNotification*)notification { |
| 706 toolbarActionsBar_->OnAnimationEnded(); |
| 707 } |
| 708 |
| 694 - (void)containerMouseEntered:(NSNotification*)notification { | 709 - (void)containerMouseEntered:(NSNotification*)notification { |
| 695 if (!activeBubble_ && // only show one bubble at a time | 710 if (!activeBubble_ && // only show one bubble at a time |
| 696 ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( | 711 ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( |
| 697 browser_->profile())) { | 712 browser_->profile())) { |
| 698 ToolbarActionsBarBubbleMac* bubble = | 713 ToolbarActionsBarBubbleMac* bubble = |
| 699 [self createMessageBubble:scoped_ptr<ToolbarActionsBarBubbleDelegate>( | 714 [self createMessageBubble:scoped_ptr<ToolbarActionsBarBubbleDelegate>( |
| 700 new ExtensionToolbarIconSurfacingBubbleDelegate( | 715 new ExtensionToolbarIconSurfacingBubbleDelegate( |
| 701 browser_->profile()))]; | 716 browser_->profile()))]; |
| 702 [bubble showWindow:nil]; | 717 [bubble showWindow:nil]; |
| 703 } | 718 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 activeBubble_ = nil; | 949 activeBubble_ = nil; |
| 935 } | 950 } |
| 936 | 951 |
| 937 #pragma mark - | 952 #pragma mark - |
| 938 #pragma mark Testing Methods | 953 #pragma mark Testing Methods |
| 939 | 954 |
| 940 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 955 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
| 941 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 956 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
| 942 } | 957 } |
| 943 | 958 |
| 944 - (ToolbarActionsBar*)toolbarActionsBar { | |
| 945 return toolbarActionsBar_.get(); | |
| 946 } | |
| 947 | |
| 948 @end | 959 @end |
| OLD | NEW |