diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 23:28:41 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 23:28:41 +0000 |
commit | 98940fdf0611aa314b1a1f5511676a3726c7297d (patch) | |
tree | 308cab7fcac55a6aa2ef6bc7d3957d5d7da39e8d | |
parent | e67ced4317b42834974c31672bdc1b154f569b28 (diff) | |
download | chromium_src-98940fdf0611aa314b1a1f5511676a3726c7297d.zip chromium_src-98940fdf0611aa314b1a1f5511676a3726c7297d.tar.gz chromium_src-98940fdf0611aa314b1a1f5511676a3726c7297d.tar.bz2 |
[Mac] Prep for animating the Browser Action Buttons in and out.
Also fixes bug where the go button would overlap with the page/wrench menus upon uninstalling the last extension.
BUG=40003,39200
TEST=none
Review URL: http://codereview.chromium.org/1551009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43282 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 46 insertions, 27 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_actions_container_view.mm b/chrome/browser/cocoa/extensions/browser_actions_container_view.mm index fea701a..cbe232e 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_container_view.mm +++ b/chrome/browser/cocoa/extensions/browser_actions_container_view.mm @@ -165,15 +165,14 @@ const CGFloat kUpperPadding = 9.0; lastXPos_ = frame.origin.x; CGFloat dX = frame.size.width - width; frame.size.width = width; - NSRect newFrame = NSOffsetRect(frame, dX, 0); + animationEndFrame_ = NSOffsetRect(frame, dX, 0); if (animate) { [NSAnimationContext beginGrouping]; [[NSAnimationContext currentContext] setDuration:kAnimationDuration]; - [[self animator] setFrame:newFrame]; + [[self animator] setFrame:animationEndFrame_]; [NSAnimationContext endGrouping]; - animationEndFrame_ = newFrame; } else { - [self setFrame:newFrame]; + [self setFrame:animationEndFrame_]; [self setNeedsDisplay:YES]; } } diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.h b/chrome/browser/cocoa/extensions/browser_actions_controller.h index f35fc0f..a27a3fa 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.h +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.h @@ -31,6 +31,10 @@ extern const NSString* kBrowserActionVisibilityChangedNotification; // container within the Toolbar. @interface BrowserActionsController : NSObject { @private + // Whether the container has already done initial setup and layout of the + // buttons. + BOOL isInitialized_; + // Reference to the current browser. Weak. Browser* browser_; diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm index 90600dc..e235f80 100644 --- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm +++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm @@ -63,8 +63,10 @@ const CGFloat kGrippyXOffset = 8.0; // Useful in the case of a Browser Action being added/removed from the middle of // the container, this method repositions each button according to the current -// toolbar model. -- (void)repositionActionButtonsAndAnimate:(BOOL)animate; +// toolbar model. Since during an insert or remove, the icons to the right will +// be the only ones needing a position change, a starting point is provided. +- (void)repositionActionButtonsStartingAtIndex:(NSUInteger)index + animate:(BOOL)animate; // During container resizing, buttons become more transparent as they are pushed // off the screen. This method updates each button's opacity determined by the @@ -188,12 +190,10 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, // ExtensionToolbarModel::Observer implementation. void BrowserActionAdded(Extension* extension, int index) { [owner_ createActionButtonForExtension:extension withIndex:index]; - [owner_ resizeContainerAndAnimate:NO]; } void BrowserActionRemoved(Extension* extension) { [owner_ removeActionButtonForExtension:extension]; - [owner_ resizeContainerAndAnimate:NO]; } private: @@ -273,6 +273,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, [self createButtons]; [self showChevronIfNecessaryInFrame:[containerView_ frame] animate:NO]; [self updateGrippyCursors]; + isInitialized_ = YES; } return self; @@ -317,11 +318,9 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, [self showChevronIfNecessaryInFrame:frame animate:animate]; - if (!animate) { - [[NSNotificationCenter defaultCenter] - postNotificationName:kBrowserActionVisibilityChangedNotification - object:self]; - } + [[NSNotificationCenter defaultCenter] + postNotificationName:kBrowserActionVisibilityChangedNotification + object:self]; } - (NSView*)browserActionViewForExtension:(Extension*)extension { @@ -461,6 +460,8 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, [buttons_ setObject:newButton forKey:buttonKey]; if (index < [self containerButtonCapacity]) { [containerView_ addSubview:newButton]; + if (!profile_->IsOffTheRecord() && isInitialized_) + toolbarModel_->SetVisibleIconCount([self visibleButtonCount]); } else { [hiddenButtons_ addObject:newButton]; [newButton setAlphaValue:0.0]; @@ -473,10 +474,12 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, name:kBrowserActionButtonDraggingNotification object:newButton]; - [self repositionActionButtonsAndAnimate:NO]; [containerView_ setMaxWidth: [self containerWidthWithButtonCount:[self buttonCount]]]; - [containerView_ setNeedsDisplay:YES]; + [self resizeContainerAndAnimate:isInitialized_]; + + // TODO(andybons): Use isInitialized_ to animate this. + [self repositionActionButtonsStartingAtIndex:0 animate:NO]; } - (void)removeActionButtonForExtension:(Extension*)extension { @@ -488,35 +491,45 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, return; BrowserActionButton* button = [buttons_ objectForKey:buttonKey]; + [buttons_ removeObjectForKey:buttonKey]; // This could be the case in incognito, where only a subset of extensions are // shown. if (!button) return; [button removeFromSuperview]; - // It may or may not be hidden, but it won't matter to NSMutableArray either - // way. - [hiddenButtons_ removeObject:button]; - [self updateOverflowMenu]; - [buttons_ removeObjectForKey:buttonKey]; + if ([hiddenButtons_ containsObject:button]) { + [hiddenButtons_ removeObject:button]; + [self updateOverflowMenu]; + } else { + if (!profile_->IsOffTheRecord() && isInitialized_) + toolbarModel_->SetVisibleIconCount([self visibleButtonCount]); + } + if ([self buttonCount] == 0) { // No more buttons? Hide the container. [containerView_ setHidden:YES]; } else { - [self repositionActionButtonsAndAnimate:NO]; + [self repositionActionButtonsStartingAtIndex:0 animate:NO]; } [containerView_ setMaxWidth: [self containerWidthWithButtonCount:[self buttonCount]]]; - [containerView_ setNeedsDisplay:YES]; + [self resizeContainerAndAnimate:isInitialized_]; } -- (void)repositionActionButtonsAndAnimate:(BOOL)animate { +- (void)repositionActionButtonsStartingAtIndex:(NSUInteger)index + animate:(BOOL)animate { NSUInteger i = 0; for (ExtensionList::iterator iter = toolbarModel_->begin(); iter != toolbarModel_->end(); ++iter) { if (![self shouldDisplayBrowserAction:*iter]) continue; + + if (i < index) { + ++i; + continue; + } BrowserActionButton* button = [self buttonForExtension:(*iter)]; if (!button) continue; @@ -657,7 +670,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, if (intersectionWidth > dragThreshold && button != draggedButton && ![button isAnimating] && index < [self visibleButtonCount]) { toolbarModel_->MoveBrowserAction([draggedButton extension], index); - [self repositionActionButtonsAndAnimate:YES]; + [self repositionActionButtonsStartingAtIndex:0 animate:YES]; return; } ++index; @@ -666,7 +679,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver, - (void)actionButtonDragFinished:(NSNotification*)notification { [self showChevronIfNecessaryInFrame:[containerView_ frame] animate:YES]; - [self repositionActionButtonsAndAnimate:YES]; + [self repositionActionButtonsStartingAtIndex:0 animate:YES]; } - (void)moveButton:(BrowserActionButton*)button diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 68819f1..7a75fe7 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -671,7 +671,8 @@ class PrefObserverBridge : public NotificationObserver { } - (void)browserActionsVisibilityChanged:(NSNotification*)notification { - [self pinGoButtonToLeftOfBrowserActionsContainerAndAnimate:NO]; + [self pinGoButtonToLeftOfBrowserActionsContainerAndAnimate: + [[[self view] window] isVisible]]; } - (void)pinGoButtonToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { @@ -679,7 +680,9 @@ class PrefObserverBridge : public NotificationObserver { CGFloat leftPadding; if ([browserActionsContainerView_ isHidden]) { - leftPadding = NSWidth([[goButton_ window] frame]) - goXPos; + CGFloat edgeXPos = [pageButton_ isHidden] ? + NSWidth([[goButton_ window] frame]) : [pageButton_ frame].origin.x; + leftPadding = edgeXPos - goXPos; } else { NSRect containerFrame = animate ? [browserActionsContainerView_ animationEndFrame] : |