diff options
author | feldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 01:31:08 +0000 |
---|---|---|
committer | feldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 01:31:08 +0000 |
commit | 60a50255ede2001cef2c52bee8377ede6fcd1473 (patch) | |
tree | f0254591e595b8742ac39199162ca3b513fa1f15 /chrome/browser/cocoa/hover_close_button.mm | |
parent | ba89742ced6463b6d555b8caf3806ad45d48e39b (diff) | |
download | chromium_src-60a50255ede2001cef2c52bee8377ede6fcd1473.zip chromium_src-60a50255ede2001cef2c52bee8377ede6fcd1473.tar.gz chromium_src-60a50255ede2001cef2c52bee8377ede6fcd1473.tar.bz2 |
Fix stuck hover states on tab close buttons
Use the |bounds| property instead of the |frame| property when updating tracking rectangles and deciding whether the button has the mouse over it. We used to do this from the parent views context, but moved the code into the button itself and this broke.
Check the image state when the mouseDown event loop finishes. We can get into a weird state when the tabs resize and the close button is placed under the cursor. We update the image to highlight it, but if we click/hold the mouse button without moving the mouse, there are no mouseMove events and thus no mouseEntered, and thus no mouseExited (just assuming that's what is happening).
BUG=31279
TEST=Open a bunch of tabs, Click/hold on the last close button, then let go. Wit
hout moving the mouse at all, click/hold on the next button that moves under the
mouse. Drag mouse away from tab strip area and let go. It should unhighlight it
self.
Review URL: http://codereview.chromium.org/524016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/hover_close_button.mm')
-rw-r--r-- | chrome/browser/cocoa/hover_close_button.mm | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/hover_close_button.mm b/chrome/browser/cocoa/hover_close_button.mm index 8348401..9eeafe9 100644 --- a/chrome/browser/cocoa/hover_close_button.mm +++ b/chrome/browser/cocoa/hover_close_button.mm @@ -52,6 +52,16 @@ const NSString* kHoverImageString = @"close_bar_h.pdf"; [self setImage:nsimage_cache::ImageNamed(kNormalImageString)]; } +- (void)mouseDown:(NSEvent*)theEvent { + [super mouseDown:theEvent]; + // We need to check the image state after the mouseDown event loop finishes. + // It's possible that we won't get a mouseExited event if the button was + // moved under the mouse during tab resize, instead of the mouse moving over + // the button. + // http://crbug.com/31279 + [self checkImageState]; +} + - (void)setTrackingEnabled:(BOOL)enabled { if (enabled) { closeTrackingArea_.reset( @@ -61,6 +71,12 @@ const NSString* kHoverImageString = @"close_bar_h.pdf"; owner:self userInfo:nil]); [self addTrackingArea:closeTrackingArea_.get()]; + + // If you have a separate window that overlaps the close button, and you + // move the mouse directly over the close button without entering another + // part of the tab strip, we don't get any mouseEntered event since the + // tracking area was disabled when we entered. + [self checkImageState]; } else { if (closeTrackingArea_.get()) { [self removeTrackingArea:closeTrackingArea_.get()]; @@ -71,11 +87,15 @@ const NSString* kHoverImageString = @"close_bar_h.pdf"; - (void)updateTrackingAreas { [super updateTrackingAreas]; + [self checkImageState]; +} + +- (void)checkImageState { if (closeTrackingArea_.get()) { // Update the close buttons if the tab has moved. NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream]; mouseLoc = [self convertPointFromBase:mouseLoc]; - NSString* name = NSPointInRect(mouseLoc, [self frame]) ? + NSString* name = NSPointInRect(mouseLoc, [self bounds]) ? kHoverImageString : kNormalImageString; NSImage* newImage = nsimage_cache::ImageNamed(name); NSImage* buttonImage = [self image]; @@ -84,4 +104,5 @@ const NSString* kHoverImageString = @"close_bar_h.pdf"; } } } + @end |