Commit 8c7c8cfb authored by spqchan's avatar spqchan Committed by Commit Bot

[Mac] Fix extension button highlight issue

Currently, the extensions can go in an incorrect
hover state when they're being reordered via drag
and drop. This bug fixes it by preventing the buttons
to enter the hover state when a button is dragged.

Bug: 793572
Change-Id: I1275882b68bbafd901f5edeab4e5c9b93286e699
Reviewed-on: https://chromium-review.googlesource.com/874523Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Sarah Chan <spqchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532948}
parent ae87b773
...@@ -62,6 +62,9 @@ extern NSString* const kBrowserActionVisibilityChangedNotification; ...@@ -62,6 +62,9 @@ extern NSString* const kBrowserActionVisibilityChangedNotification;
// Bridge for showing the toolkit-views bubble on a Cocoa browser. // Bridge for showing the toolkit-views bubble on a Cocoa browser.
std::unique_ptr<ToolbarActionsBarBubbleViewsPresenter> viewsBubblePresenter_; std::unique_ptr<ToolbarActionsBarBubbleViewsPresenter> viewsBubblePresenter_;
// True if a toolbar action button is being dragged.
BOOL isDraggingSession_;
} }
@property(nonatomic) CGFloat maxWidth; @property(nonatomic) CGFloat maxWidth;
......
...@@ -679,6 +679,15 @@ void ToolbarActionsBarBridge::ShowToolbarActionBubble( ...@@ -679,6 +679,15 @@ void ToolbarActionsBarBridge::ShowToolbarActionBubble(
// Determine what index the dragged button should lie in, alter the model and // Determine what index the dragged button should lie in, alter the model and
// reposition the buttons. // reposition the buttons.
BrowserActionButton* draggedButton = [notification object]; BrowserActionButton* draggedButton = [notification object];
if (!isDraggingSession_) {
for (BrowserActionButton* button : buttons_.get()) {
if (button != draggedButton)
[[button cell] setIsHoverDisabled:YES];
}
isDraggingSession_ = YES;
}
NSRect draggedButtonFrame = [draggedButton frame]; NSRect draggedButtonFrame = [draggedButton frame];
// Find the mid-point. We flip the y-coordinates so that y = 0 is at the // Find the mid-point. We flip the y-coordinates so that y = 0 is at the
// top of the container to make row calculation more logical. // top of the container to make row calculation more logical.
...@@ -712,6 +721,13 @@ void ToolbarActionsBarBridge::ShowToolbarActionBubble( ...@@ -712,6 +721,13 @@ void ToolbarActionsBarBridge::ShowToolbarActionBubble(
} }
- (void)actionButtonDragFinished:(NSNotification*)notification { - (void)actionButtonDragFinished:(NSNotification*)notification {
BrowserActionButton* draggedButton = [notification object];
for (BrowserActionButton* button : buttons_.get()) {
if (button != draggedButton)
[[button cell] setIsHoverDisabled:NO];
}
isDraggingSession_ = NO;
[self redraw]; [self redraw];
} }
......
...@@ -46,6 +46,9 @@ enum ButtonState { ...@@ -46,6 +46,9 @@ enum ButtonState {
base::scoped_nsobject<NSImage> image; base::scoped_nsobject<NSImage> image;
} image_[image_button_cell::kButtonStateCount]; } image_[image_button_cell::kButtonStateCount];
BOOL isMouseInside_; BOOL isMouseInside_;
// Disables the hover effect if set to true.
BOOL isHoverDisabled_;
} }
@property(assign, nonatomic) BOOL isMouseInside; @property(assign, nonatomic) BOOL isMouseInside;
...@@ -75,6 +78,10 @@ enum ButtonState { ...@@ -75,6 +78,10 @@ enum ButtonState {
// Draws the cell's image within |cellFrame|. // Draws the cell's image within |cellFrame|.
- (void)drawImageWithFrame:(NSRect)cellFrame inView:(NSView*)controlView; - (void)drawImageWithFrame:(NSRect)cellFrame inView:(NSView*)controlView;
// Setter for |isHoverDisabled|. If |disable| is true, set |isMouseInside_| to
// false.
- (void)setIsHoverDisabled:(BOOL)disable;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ #endif // CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_
...@@ -167,6 +167,13 @@ NSRect CenterImageInFrame(NSImage* image, NSRect frame) { ...@@ -167,6 +167,13 @@ NSRect CenterImageInFrame(NSImage* image, NSRect frame) {
hints:nil]; hints:nil];
} }
- (void)setIsHoverDisabled:(BOOL)disable {
if (disable)
[self setIsMouseInside:NO];
isHoverDisabled_ = disable;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
[self drawImageWithFrame:cellFrame inView:controlView]; [self drawImageWithFrame:cellFrame inView:controlView];
} }
...@@ -235,6 +242,9 @@ NSRect CenterImageInFrame(NSImage* image, NSRect frame) { ...@@ -235,6 +242,9 @@ NSRect CenterImageInFrame(NSImage* image, NSRect frame) {
} }
- (void)setIsMouseInside:(BOOL)isMouseInside { - (void)setIsMouseInside:(BOOL)isMouseInside {
if (isHoverDisabled_)
return;
if (isMouseInside_ != isMouseInside) { if (isMouseInside_ != isMouseInside) {
oldState_ = [self currentButtonState]; oldState_ = [self currentButtonState];
isMouseInside_ = isMouseInside; isMouseInside_ = isMouseInside;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment