| Index: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
|
| diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
|
| index 4284709111f32c7b1958108483d7c38e9a2a3473..a71d2ce62b687254bb3079dac6f67d66ee50df48 100644
|
| --- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
|
| +++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
|
| @@ -4,11 +4,9 @@
|
|
|
| #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
|
|
|
| -#include <cmath>
|
| #include <string>
|
|
|
| #include "base/strings/sys_string_conversions.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
|
| #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
|
| @@ -58,9 +56,9 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
|
| // the order in the ToolbarActionsBar.
|
| - (void)redraw;
|
|
|
| -// Resizes the container to the specified |width|, optionally animating.
|
| -- (void)resizeContainerToWidth:(CGFloat)width
|
| - shouldAnimate:(BOOL)animate;
|
| +// Resizes the container to the specified |width|, and animates according to
|
| +// the ToolbarActionsBar.
|
| +- (void)resizeContainerToWidth:(CGFloat)width;
|
|
|
| // Sets the container to be either hidden or visible based on whether there are
|
| // any actions to show.
|
| @@ -102,8 +100,7 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
|
| // Moves the given button both visually and within the toolbar model to the
|
| // specified index.
|
| - (void)moveButton:(BrowserActionButton*)button
|
| - toIndex:(NSUInteger)index
|
| - animate:(BOOL)animate;
|
| + toIndex:(NSUInteger)index;
|
|
|
| // Handles clicks for BrowserActionButtons.
|
| - (BOOL)browserActionClicked:(BrowserActionButton*)button;
|
| @@ -115,15 +112,14 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
|
|
|
| // Shows the overflow chevron button depending on whether there are any hidden
|
| // extensions within the frame given.
|
| -- (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate;
|
| +- (void)showChevronIfNecessaryInFrame:(NSRect)frame;
|
|
|
| // Moves the chevron to its correct position within |frame|.
|
| - (void)updateChevronPositionInFrame:(NSRect)frame;
|
|
|
| -// Shows or hides the chevron, animating as specified by |animate|.
|
| +// Shows or hides the chevron in the given |frame|.
|
| - (void)setChevronHidden:(BOOL)hidden
|
| - inFrame:(NSRect)frame
|
| - animate:(BOOL)animate;
|
| + inFrame:(NSRect)frame;
|
|
|
| // Handles when a menu item within the chevron overflow menu is selected.
|
| - (void)chevronItemSelected:(id)menuItem;
|
| @@ -131,8 +127,6 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
|
| // Updates the container's grippy cursor based on the number of hidden buttons.
|
| - (void)updateGrippyCursors;
|
|
|
| -- (ToolbarActionsBar*)toolbarActionsBar;
|
| -
|
| @end
|
|
|
| namespace {
|
| @@ -197,15 +191,12 @@ void ToolbarActionsBarBridge::Redraw(bool order_changed) {
|
| void ToolbarActionsBarBridge::ResizeAndAnimate(gfx::Tween::Type tween_type,
|
| int target_width,
|
| bool suppress_chevron) {
|
| - [controller_ resizeContainerToWidth:target_width
|
| - shouldAnimate:![controller_ toolbarActionsBar]->
|
| - suppress_animation()];
|
| + [controller_ resizeContainerToWidth:target_width];
|
| }
|
|
|
| void ToolbarActionsBarBridge::SetChevronVisibility(bool chevron_visible) {
|
| [controller_ setChevronHidden:!chevron_visible
|
| - inFrame:[[controller_ containerView] frame]
|
| - animate:YES];
|
| + inFrame:[[controller_ containerView] frame]];
|
| }
|
|
|
| int ToolbarActionsBarBridge::GetWidth() const {
|
| @@ -242,7 +233,6 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
|
|
| if ((self = [super init])) {
|
| browser_ = browser;
|
| - profile_ = browser->profile();
|
|
|
| toolbarActionsBarBridge_.reset(new ToolbarActionsBarBridge(self));
|
| toolbarActionsBar_.reset(
|
| @@ -281,9 +271,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
|
|
| buttons_.reset([[NSMutableArray alloc] init]);
|
| toolbarActionsBar_->CreateActions();
|
| - if ([buttons_ count] != 0)
|
| - [self resizeContainerAndAnimate:NO];
|
| - [self showChevronIfNecessaryInFrame:[containerView_ frame] animate:NO];
|
| + [self showChevronIfNecessaryInFrame:[containerView_ frame]];
|
| [self updateGrippyCursors];
|
| [container setResizable:YES];
|
| }
|
| @@ -318,11 +306,6 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| return visibleCount;
|
| }
|
|
|
| -- (void)resizeContainerAndAnimate:(BOOL)animate {
|
| - [self resizeContainerToWidth:toolbarActionsBar_->GetPreferredSize().width()
|
| - shouldAnimate:animate];
|
| -}
|
| -
|
| - (CGFloat)savedWidth {
|
| return toolbarActionsBar_->GetPreferredSize().width();
|
| }
|
| @@ -443,13 +426,10 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| }
|
| }
|
|
|
| - BOOL animate = !toolbarActionsBar_->suppress_animation();
|
| - [self showChevronIfNecessaryInFrame:[containerView_ frame] animate:animate];
|
| + [self showChevronIfNecessaryInFrame:[containerView_ frame]];
|
| for (NSUInteger i = 0; i < [buttons_ count]; ++i) {
|
| if (![[buttons_ objectAtIndex:i] isBeingDragged])
|
| - [self moveButton:[buttons_ objectAtIndex:i]
|
| - toIndex:i
|
| - animate:animate];
|
| + [self moveButton:[buttons_ objectAtIndex:i] toIndex:i];
|
| }
|
| }
|
|
|
| @@ -469,8 +449,8 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| [buttons_ removeAllObjects];
|
| }
|
|
|
| -- (void)resizeContainerToWidth:(CGFloat)width
|
| - shouldAnimate:(BOOL)animate {
|
| +- (void)resizeContainerToWidth:(CGFloat)width {
|
| + BOOL animate = !toolbarActionsBar_->suppress_animation();
|
| [self updateContainerVisibility];
|
| [containerView_ setMaxWidth:
|
| toolbarActionsBar_->IconCountToWidth([self buttonCount])];
|
| @@ -479,7 +459,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| NSRect frame = animate ? [containerView_ animationEndFrame] :
|
| [containerView_ frame];
|
|
|
| - [self showChevronIfNecessaryInFrame:frame animate:animate];
|
| + [self showChevronIfNecessaryInFrame:frame];
|
|
|
| [containerView_ setNeedsDisplay:YES];
|
|
|
| @@ -531,7 +511,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| }
|
|
|
| - (void)containerDragStart:(NSNotification*)notification {
|
| - [self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES];
|
| + [self setChevronHidden:YES inFrame:[containerView_ frame]];
|
| for (BrowserActionButton* button in buttons_.get()) {
|
| if ([button superview] != containerView_) {
|
| [button setAlphaValue:1.0];
|
| @@ -561,16 +541,13 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| toolbarActionsBar_->IconCountToWidth([self visibleButtonCount]));
|
|
|
| [self updateGrippyCursors];
|
| -
|
| - [[NSNotificationCenter defaultCenter]
|
| - postNotificationName:kBrowserActionGrippyDragFinishedNotification
|
| - object:self];
|
| + [self resizeContainerToWidth:toolbarActionsBar_->GetPreferredSize().width()];
|
| }
|
|
|
| - (void)actionButtonDragging:(NSNotification*)notification {
|
| suppressChevron_ = YES;
|
| if (![self chevronIsHidden])
|
| - [self setChevronHidden:YES inFrame:[containerView_ frame] animate:YES];
|
| + [self setChevronHidden:YES inFrame:[containerView_ frame]];
|
|
|
| // Determine what index the dragged button should lie in, alter the model and
|
| // reposition the buttons.
|
| @@ -579,10 +556,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| NSRect draggedButtonFrame = [draggedButton frame];
|
|
|
| NSUInteger index = 0;
|
| - std::vector<ToolbarActionViewController*> toolbar_actions =
|
| - toolbarActionsBar_->toolbar_actions();
|
| - for (ToolbarActionViewController* action : toolbar_actions) {
|
| - BrowserActionButton* button = [self buttonForId:(action->GetId())];
|
| + for (BrowserActionButton* button in buttons_.get()) {
|
| CGFloat intersectionWidth =
|
| NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame]));
|
|
|
| @@ -604,15 +578,15 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| }
|
|
|
| - (void)moveButton:(BrowserActionButton*)button
|
| - toIndex:(NSUInteger)index
|
| - animate:(BOOL)animate {
|
| + toIndex:(NSUInteger)index {
|
| const ToolbarActionsBar::PlatformSettings& platformSettings =
|
| toolbarActionsBar_->platform_settings();
|
| CGFloat xOffset = platformSettings.left_padding +
|
| (index * ToolbarActionsBar::IconWidth(true));
|
| NSRect buttonFrame = [button frame];
|
| buttonFrame.origin.x = xOffset;
|
| - [button setFrame:buttonFrame animate:animate];
|
| + [button setFrame:buttonFrame
|
| + animate:!toolbarActionsBar_->suppress_animation()];
|
|
|
| if (index < toolbarActionsBar_->GetIconCount()) {
|
| // Make sure the button is within the visible container.
|
| @@ -631,22 +605,14 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| }
|
| }
|
|
|
| -- (BOOL)browserActionClicked:(BrowserActionButton*)button
|
| - shouldGrant:(BOOL)shouldGrant {
|
| - return [button viewController]->ExecuteAction(shouldGrant);
|
| -}
|
| -
|
| - (BOOL)browserActionClicked:(BrowserActionButton*)button {
|
| - return [self browserActionClicked:button
|
| - shouldGrant:YES];
|
| + return [button viewController]->ExecuteAction(true);
|
| }
|
|
|
| -- (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate {
|
| +- (void)showChevronIfNecessaryInFrame:(NSRect)frame {
|
| bool hidden = suppressChevron_ ||
|
| toolbarActionsBar_->GetIconCount() == [self buttonCount];
|
| - [self setChevronHidden:hidden
|
| - inFrame:frame
|
| - animate:animate];
|
| + [self setChevronHidden:hidden inFrame:frame];
|
| }
|
|
|
| - (void)updateChevronPositionInFrame:(NSRect)frame {
|
| @@ -660,8 +626,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| }
|
|
|
| - (void)setChevronHidden:(BOOL)hidden
|
| - inFrame:(NSRect)frame
|
| - animate:(BOOL)animate {
|
| + inFrame:(NSRect)frame {
|
| if (hidden == [self chevronIsHidden])
|
| return;
|
|
|
| @@ -691,7 +656,7 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| // Stop any running animation.
|
| [chevronAnimation_ stopAnimation];
|
|
|
| - if (!animate) {
|
| + if (toolbarActionsBar_->suppress_animation()) {
|
| [chevronMenuButton_ setHidden:hidden];
|
| return;
|
| }
|
| @@ -723,19 +688,11 @@ bool ToolbarActionsBarBridge::IsPopupRunning() const {
|
| [[containerView_ window] invalidateCursorRectsForView:containerView_];
|
| }
|
|
|
| -- (ToolbarActionsBar*)toolbarActionsBar {
|
| - return toolbarActionsBar_.get();
|
| -}
|
| -
|
| #pragma mark -
|
| #pragma mark Testing Methods
|
|
|
| - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index {
|
| - const std::vector<ToolbarActionViewController*>& toolbar_actions =
|
| - toolbarActionsBar_->toolbar_actions();
|
| - if (index < toolbar_actions.size())
|
| - return [self buttonForId:toolbar_actions[index]->GetId()];
|
| - return nil;
|
| + return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil;
|
| }
|
|
|
| @end
|
|
|