Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3242)

Unified Diff: chrome/browser/cocoa/extensions/browser_actions_controller.mm

Issue 1551009: [Mac] Prep for animating the Browser Action Buttons in and out.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/extensions/browser_actions_controller.mm
===================================================================
--- chrome/browser/cocoa/extensions/browser_actions_controller.mm (revision 43254)
+++ chrome/browser/cocoa/extensions/browser_actions_controller.mm (working copy)
@@ -63,8 +63,10 @@
// 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 @@
// 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 @@
[self createButtons];
[self showChevronIfNecessaryInFrame:[containerView_ frame] animate:NO];
[self updateGrippyCursors];
+ isInitialized_ = YES;
}
return self;
@@ -317,11 +318,9 @@
[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 @@
[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 @@
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 @@
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 @@
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 @@
- (void)actionButtonDragFinished:(NSNotification*)notification {
[self showChevronIfNecessaryInFrame:[containerView_ frame] animate:YES];
- [self repositionActionButtonsAndAnimate:YES];
+ [self repositionActionButtonsStartingAtIndex:0 animate:YES];
}
- (void)moveButton:(BrowserActionButton*)button
« no previous file with comments | « chrome/browser/cocoa/extensions/browser_actions_controller.h ('k') | chrome/browser/cocoa/toolbar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698