diff options
-rw-r--r-- | chrome/browser/cocoa/hover_close_button.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/hover_close_button.mm | 23 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 10 |
3 files changed, 40 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/hover_close_button.h b/chrome/browser/cocoa/hover_close_button.h index ac42bf8..7c34395 100644 --- a/chrome/browser/cocoa/hover_close_button.h +++ b/chrome/browser/cocoa/hover_close_button.h @@ -3,6 +3,7 @@ // found in the LICENSE file. #import <Cocoa/Cocoa.h> + #include "base/scoped_nsobject.h" // The standard close button for our Mac UI which is the "x" @@ -20,4 +21,11 @@ // Sets up the button's images, tracking areas, and accessibility info // when instantiated via initWithFrame or awakeFromNib. - (void)commonInit; + +// Checks to see whether the mouse is in the button's bounds and update +// the image in case it gets out of sync. This occurs when you close a +// tab so the tab to the left of it takes its place, and drag the button +// without moving the mouse before you press the button down. +- (void)checkImageState; + @end 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 diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 4253aa7..14eb3c7 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -343,6 +343,16 @@ private: userInfo:nil]); [tabStripView_ addTrackingArea:trackingArea_.get()]; + // Check to see if the mouse is currently in our bounds so we can + // enable the tracking areas. Otherwise we won't get hover states + // or tab gradients if we load the window up under the mouse. + NSPoint mouseLoc = [[view window] mouseLocationOutsideOfEventStream]; + mouseLoc = [view convertPointFromBase:mouseLoc]; + if (NSPointInRect(mouseLoc, [view bounds])) { + [self setTabTrackingAreasEnabled:YES]; + mouseInside_ = YES; + } + // Set accessibility descriptions. http://openradar.appspot.com/7496255 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_NEWTAB); [[newTabButton_ cell] |