summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorandybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 22:36:52 +0000
committerandybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 22:36:52 +0000
commitbdf4206fe44fe56f1430d5c7d4d64abf3377b964 (patch)
treee9ce485cffa2fa64bf3cfaa0290b0fdefd655651 /chrome/browser
parent02fd1ecdadfd2c0ffe0426188bafff7f1a942919 (diff)
downloadchromium_src-bdf4206fe44fe56f1430d5c7d4d64abf3377b964.zip
chromium_src-bdf4206fe44fe56f1430d5c7d4d64abf3377b964.tar.gz
chromium_src-bdf4206fe44fe56f1430d5c7d4d64abf3377b964.tar.bz2
[Mac] Constrain the user (for now) to only be able to reorder the visible buttons and sync the order of buttons across windows when a drag has completed.
Also fixes an issue where drag events were being intercepted by other buttons when they were not supposed to be and so stuff got shuffled around as a result. TEST=none BUG=39199 Review URL: http://codereview.chromium.org/1569002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43007 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/extensions/browser_action_button.h5
-rw-r--r--chrome/browser/cocoa/extensions/browser_action_button.mm8
-rw-r--r--chrome/browser/cocoa/extensions/browser_actions_controller.mm20
3 files changed, 22 insertions, 11 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_action_button.h b/chrome/browser/cocoa/extensions/browser_action_button.h
index bc2128d..c8eaa66 100644
--- a/chrome/browser/cocoa/extensions/browser_action_button.h
+++ b/chrome/browser/cocoa/extensions/browser_action_button.h
@@ -50,6 +50,11 @@ extern const CGFloat kBrowserActionWidth;
// Whether the button is currently being dragged.
BOOL isBeingDragged_;
+
+ // Drag events could be intercepted by other buttons, so to make sure that
+ // this is the only button moving if it ends up being dragged. This is set to
+ // YES upon |mouseDown:|.
+ BOOL dragCouldStart_;
}
- (id)initWithExtension:(Extension*)extension
diff --git a/chrome/browser/cocoa/extensions/browser_action_button.mm b/chrome/browser/cocoa/extensions/browser_action_button.mm
index 0794b25..a6b8da5 100644
--- a/chrome/browser/cocoa/extensions/browser_action_button.mm
+++ b/chrome/browser/cocoa/extensions/browser_action_button.mm
@@ -66,8 +66,7 @@ class ExtensionImageTrackerBridge : public NotificationObserver,
Source<ExtensionAction>(extension->browser_action()));
}
- ~ExtensionImageTrackerBridge() {
- }
+ ~ExtensionImageTrackerBridge() {}
// ImageLoadingTracker::Observer implementation.
void OnImageLoaded(SkBitmap* image, ExtensionResource resource, int index) {
@@ -164,9 +163,13 @@ class ExtensionImageTrackerBridge : public NotificationObserver,
- (void)mouseDown:(NSEvent*)theEvent {
[[self cell] setHighlighted:YES];
+ dragCouldStart_ = YES;
}
- (void)mouseDragged:(NSEvent*)theEvent {
+ if (!dragCouldStart_)
+ return;
+
if (!isBeingDragged_) {
// The start of a drag. Position the button above all others.
[[self superview] addSubview:self positioned:NSWindowAbove relativeTo:nil];
@@ -186,6 +189,7 @@ class ExtensionImageTrackerBridge : public NotificationObserver,
}
- (void)mouseUp:(NSEvent*)theEvent {
+ dragCouldStart_ = NO;
// There are non-drag cases where a mouseUp: may happen
// (e.g. mouse-down, cmd-tab to another application, move mouse,
// mouse-up).
diff --git a/chrome/browser/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/cocoa/extensions/browser_actions_controller.mm
index f9e796a..0555c0f 100644
--- a/chrome/browser/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/cocoa/extensions/browser_actions_controller.mm
@@ -108,8 +108,9 @@ const CGFloat kGrippyXOffset = 8.0;
// button is within the container.
- (void)actionButtonDragging:(NSNotification*)notification;
-// Updates the underlying toolbar model and "snaps" the button into its proper
-// place within the button grid.
+// Updates the position of the Browser Actions within the container. This fires
+// when _any_ Browser Action button is done dragging to keep all open windows in
+// sync visually.
- (void)actionButtonDragFinished:(NSNotification*)notification;
// Moves the given button both visually and within the toolbar model to the
@@ -251,6 +252,13 @@ class ExtensionsServiceObserverBridge : public NotificationObserver,
selector:@selector(containerDragFinished:)
name:kBrowserActionGrippyDragFinishedNotification
object:containerView_];
+ // Listen for a finished drag from any button to make sure each open window
+ // stays in sync.
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(actionButtonDragFinished:)
+ name:kBrowserActionButtonDragEndNotification
+ object:nil];
chevronAnimation_.reset([[NSViewAnimation alloc] init]);
[chevronAnimation_ gtm_setDuration:kAnimationDuration
@@ -462,11 +470,6 @@ class ExtensionsServiceObserverBridge : public NotificationObserver,
selector:@selector(actionButtonDragging:)
name:kBrowserActionButtonDraggingNotification
object:newButton];
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(actionButtonDragFinished:)
- name:kBrowserActionButtonDragEndNotification
- object:newButton];
[self repositionActionButtonsAndAnimate:NO];
[containerView_ setMaxWidth:
@@ -645,7 +648,7 @@ class ExtensionsServiceObserverBridge : public NotificationObserver,
NSWidth(NSIntersectionRect(draggedButtonFrame, [button frame]));
if (intersectionWidth > dragThreshold && button != draggedButton &&
- ![button isAnimating]) {
+ ![button isAnimating] && index < [self visibleButtonCount]) {
toolbarModel_->MoveBrowserAction([draggedButton extension], index);
[self repositionActionButtonsAndAnimate:YES];
return;
@@ -656,7 +659,6 @@ class ExtensionsServiceObserverBridge : public NotificationObserver,
- (void)actionButtonDragFinished:(NSNotification*)notification {
[self showChevronIfNecessaryInFrame:[containerView_ frame] animate:YES];
- DCHECK(![[notification object] isBeingDragged]);
[self repositionActionButtonsAndAnimate:YES];
}