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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 14 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
18 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 18 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
19 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 19 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
20 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 20 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
21 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" | 21 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" |
22 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 22 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 23 #import "chrome/browser/ui/cocoa/l10n_util.h" |
23 #import "chrome/browser/ui/cocoa/menu_button.h" | 24 #import "chrome/browser/ui/cocoa/menu_button.h" |
24 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 25 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
25 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h" | 26 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
27 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 28 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 30 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
30 #include "chrome/grit/theme_resources.h" | 31 #include "chrome/grit/theme_resources.h" |
31 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 32 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
32 #include "ui/base/cocoa/appkit_utils.h" | 33 #include "ui/base/cocoa/appkit_utils.h" |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 - (void)updateButtonPositions { | 575 - (void)updateButtonPositions { |
575 for (NSUInteger index = 0; index < [buttons_ count]; ++index) { | 576 for (NSUInteger index = 0; index < [buttons_ count]; ++index) { |
576 BrowserActionButton* button = [buttons_ objectAtIndex:index]; | 577 BrowserActionButton* button = [buttons_ objectAtIndex:index]; |
577 NSRect buttonFrame = [self frameForIndex:index]; | 578 NSRect buttonFrame = [self frameForIndex:index]; |
578 | 579 |
579 // If the button is at the proper position (or animating to it), then we | 580 // If the button is at the proper position (or animating to it), then we |
580 // don't need to update its position. | 581 // don't need to update its position. |
581 if (NSMinX([button frameAfterAnimation]) == NSMinX(buttonFrame)) | 582 if (NSMinX([button frameAfterAnimation]) == NSMinX(buttonFrame)) |
582 continue; | 583 continue; |
583 | 584 |
584 // We set the x-origin by calculating the proper distance from the right | 585 // In LTR, We set the x-origin by calculating the proper distance from the |
585 // edge in the container so that, if the container is animating, the | 586 // right edge in the container so that, if the container is animating, the |
586 // button appears stationary. | 587 // button appears stationary. |
587 buttonFrame.origin.x = NSWidth([containerView_ frame]) - | 588 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
588 (toolbarActionsBar_->GetPreferredSize().width() - NSMinX(buttonFrame)); | 589 buttonFrame.origin.x = NSWidth([containerView_ frame]) - |
| 590 (toolbarActionsBar_->GetPreferredSize().width() - |
| 591 NSMinX(buttonFrame)); |
| 592 } |
589 [button setFrame:buttonFrame animate:NO]; | 593 [button setFrame:buttonFrame animate:NO]; |
590 } | 594 } |
591 } | 595 } |
592 | 596 |
593 - (BrowserActionButton*)buttonForId:(const std::string&)id { | 597 - (BrowserActionButton*)buttonForId:(const std::string&)id { |
594 for (BrowserActionButton* button in buttons_.get()) { | 598 for (BrowserActionButton* button in buttons_.get()) { |
595 if ([button viewController]->GetId() == id) | 599 if ([button viewController]->GetId() == id) |
596 return button; | 600 return button; |
597 } | 601 } |
598 return nil; | 602 return nil; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 [button setFrame:buttonFrame | 780 [button setFrame:buttonFrame |
777 animate:!toolbarActionsBar_->suppress_animation() && !isOverflow_]; | 781 animate:!toolbarActionsBar_->suppress_animation() && !isOverflow_]; |
778 } | 782 } |
779 } | 783 } |
780 | 784 |
781 - (BOOL)browserActionClicked:(BrowserActionButton*)button { | 785 - (BOOL)browserActionClicked:(BrowserActionButton*)button { |
782 return [button viewController]->ExecuteAction(true); | 786 return [button viewController]->ExecuteAction(true); |
783 } | 787 } |
784 | 788 |
785 - (void)updateGrippyCursors { | 789 - (void)updateGrippyCursors { |
| 790 BOOL canClose = [self visibleButtonCount] > 0; |
| 791 BOOL canOpen = toolbarActionsBar_->GetIconCount() != [buttons_ count]; |
786 [containerView_ | 792 [containerView_ |
787 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]]; | 793 setCanDragLeft:cocoa_l10n_util::ShouldDoExperimentalRTLLayout() |
788 [containerView_ setCanDragRight:[self visibleButtonCount] > 0]; | 794 ? canClose |
| 795 : canOpen]; |
| 796 [containerView_ |
| 797 setCanDragRight:cocoa_l10n_util::ShouldDoExperimentalRTLLayout() |
| 798 ? canOpen |
| 799 : canClose]; |
789 [[containerView_ window] invalidateCursorRectsForView:containerView_]; | 800 [[containerView_ window] invalidateCursorRectsForView:containerView_]; |
790 } | 801 } |
791 | 802 |
792 - (ToolbarController*)toolbarController { | 803 - (ToolbarController*)toolbarController { |
793 return [[BrowserWindowController browserWindowControllerForWindow: | 804 return [[BrowserWindowController browserWindowControllerForWindow: |
794 browser_->window()->GetNativeWindow()] toolbarController]; | 805 browser_->window()->GetNativeWindow()] toolbarController]; |
795 } | 806 } |
796 | 807 |
797 - (void)createMessageBubble: | 808 - (void)createMessageBubble: |
798 (std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate { | 809 (std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 } | 851 } |
841 | 852 |
842 #pragma mark - | 853 #pragma mark - |
843 #pragma mark Testing Methods | 854 #pragma mark Testing Methods |
844 | 855 |
845 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 856 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
846 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 857 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
847 } | 858 } |
848 | 859 |
849 @end | 860 @end |
OLD | NEW |