Commit 3009675f authored by spqchan's avatar spqchan Committed by Commit Bot

[Mac] Fix for incorrect bookmark bar hover state

Currently if you click on an item in the bookmark
bar, the item will lose its highlight state.

This CL makes sure it retains it by updating the
highlight on a mouse up.

Testing:
Unit test BookmarkButtonTest.MouseUpAndDownHighlight

Bug: 613208
Change-Id: I2a3063af49065d3e985f681f69b0978666455243
Reviewed-on: https://chromium-review.googlesource.com/804695Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Sarah Chan <spqchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522141}
parent 5710f8d7
...@@ -369,6 +369,15 @@ BookmarkButton* gDraggedButton = nil; // Weak ...@@ -369,6 +369,15 @@ BookmarkButton* gDraggedButton = nil; // Weak
[id(delegate_) mouseDragged:theEvent]; [id(delegate_) mouseDragged:theEvent];
} }
- (void)mouseUp:(NSEvent*)theEvent {
[super mouseUp:theEvent];
// Update the highlight on mouse up.
GradientButtonCell* cell =
base::mac::ObjCCastStrict<GradientButtonCell>([self cell]);
[cell setMouseInside:[cell isMouseReallyInside] animate:NO];
}
- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event { - (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event {
// Ensure that right-clicking on a button while a context menu is already open // Ensure that right-clicking on a button while a context menu is already open
// highlights the new button. // highlights the new button.
......
...@@ -133,6 +133,36 @@ TEST_F(BookmarkButtonTest, MouseEnterExitRedirect) { ...@@ -133,6 +133,36 @@ TEST_F(BookmarkButtonTest, MouseEnterExitRedirect) {
EXPECT_EQ(2, delegate.get()->exited_); EXPECT_EQ(2, delegate.get()->exited_);
} }
// Tests to see if the bookmark button is properly highlighted on mouse up/down
// events.
TEST_F(BookmarkButtonTest, MouseUpAndDownHighlight) {
NSEvent* moveEvent = cocoa_test_event_utils::MouseEventAtPoint(
NSMakePoint(510, 510), NSMouseMoved, 0);
base::scoped_nsobject<BookmarkButton> button;
base::scoped_nsobject<BookmarkButtonCell> cell;
base::scoped_nsobject<FakeButtonDelegate> delegate(
[[FakeButtonDelegate alloc] init]);
button.reset(
[[BookmarkButton alloc] initWithFrame:NSMakeRect(0, 0, 500, 500)]);
cell.reset([[BookmarkButtonCell alloc] initTextCell:@"nightjar"]);
[button setCell:cell];
[button setDelegate:delegate];
[cell updateTrackingAreas];
EXPECT_FALSE([cell isMouseInside]);
moveEvent = cocoa_test_event_utils::MouseEventAtPoint(NSMakePoint(10, 10),
NSMouseMoved, 0);
[cell mouseEntered:moveEvent];
EXPECT_TRUE([cell isMouseInside]);
[button mouseDown:moveEvent];
EXPECT_TRUE([cell isMouseInside]);
[button mouseUp:moveEvent];
EXPECT_EQ([cell isMouseReallyInside], [cell isMouseInside]);
}
TEST_F(BookmarkButtonTest, DragToTrash) { TEST_F(BookmarkButtonTest, DragToTrash) {
base::scoped_nsobject<BookmarkButton> button; base::scoped_nsobject<BookmarkButton> button;
base::scoped_nsobject<BookmarkButtonCell> cell; base::scoped_nsobject<BookmarkButtonCell> cell;
......
...@@ -129,6 +129,7 @@ typedef enum { ...@@ -129,6 +129,7 @@ typedef enum {
- (BOOL)pulsing; - (BOOL)pulsing;
- (gradient_button_cell::PulseState)pulseState; - (gradient_button_cell::PulseState)pulseState;
- (void)setPulseState:(gradient_button_cell::PulseState)pstate; - (void)setPulseState:(gradient_button_cell::PulseState)pstate;
- (void)updateTrackingAreas;
@end @end
#endif // CHROME_BROWSER_UI_COCOA_GRADIENT_BUTTON_CELL_H_ #endif // CHROME_BROWSER_UI_COCOA_GRADIENT_BUTTON_CELL_H_
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