diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-15 16:26:26 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-15 16:26:26 +0000 |
commit | e9a1a8ddf2167d7a052ac4736b7f5ae622d1e8b2 (patch) | |
tree | 776c0de37f69c69395686628fe6ff765a45ccad6 /chrome/browser/cocoa/tab_view.mm | |
parent | b05e0ac05876e626cc85d3a59e5b8dc2b1a6d9c0 (diff) | |
download | chromium_src-e9a1a8ddf2167d7a052ac4736b7f5ae622d1e8b2.zip chromium_src-e9a1a8ddf2167d7a052ac4736b7f5ae622d1e8b2.tar.gz chromium_src-e9a1a8ddf2167d7a052ac4736b7f5ae622d1e8b2.tar.bz2 |
Committing issue 484006 for feldstein.
Refactor close button to its own class.
BUG= 23641
TEST= see http://codereview.chromium.org/484006
Review URL: http://codereview.chromium.org/501003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34556 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_view.mm')
-rw-r--r-- | chrome/browser/cocoa/tab_view.mm | 68 |
1 files changed, 9 insertions, 59 deletions
diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm index 9330ce3..dbf9e78 100644 --- a/chrome/browser/cocoa/tab_view.mm +++ b/chrome/browser/cocoa/tab_view.mm @@ -51,7 +51,6 @@ const CGFloat kRapidCloseDist = 2.5; - (void)dealloc { // Cancel any delayed requests that may still be pending (drags or hover). [NSObject cancelPreviousPerformRequestsWithTarget:self]; - [self setTrackingEnabled:NO]; [super dealloc]; } @@ -88,14 +87,10 @@ const CGFloat kRapidCloseDist = 2.5; } - (void)mouseEntered:(NSEvent*)theEvent { - if ([theEvent trackingArea] == closeTrackingArea_) { - [closeButton_ setImage:nsimage_cache::ImageNamed(@"close_bar_h.pdf")]; - } else { - lastHoverUpdate_ = [NSDate timeIntervalSinceReferenceDate]; - isMouseInside_ = YES; - [self adjustHoverValue]; - [self setNeedsDisplay:YES]; - } + lastHoverUpdate_ = [NSDate timeIntervalSinceReferenceDate]; + isMouseInside_ = YES; + [self adjustHoverValue]; + [self setNeedsDisplay:YES]; } - (void)mouseMoved:(NSEvent*)theEvent { @@ -105,59 +100,14 @@ const CGFloat kRapidCloseDist = 2.5; } - (void)mouseExited:(NSEvent*)theEvent { - if ([theEvent trackingArea] == closeTrackingArea_) { - [closeButton_ setImage:nsimage_cache::ImageNamed(@"close_bar.pdf")]; - } else { - lastHoverUpdate_ = [NSDate timeIntervalSinceReferenceDate]; - isMouseInside_ = NO; - [self adjustHoverValue]; - [self setNeedsDisplay:YES]; - } + lastHoverUpdate_ = [NSDate timeIntervalSinceReferenceDate]; + isMouseInside_ = NO; + [self adjustHoverValue]; + [self setNeedsDisplay:YES]; } -// Enable/Disable tracking for the closeButton. - (void)setTrackingEnabled:(BOOL)enabled { - if (enabled) { - // Set up the tracking rect for the close button mouseover. Add it - // to the |closeButton_| view, but |self| will handle the messages. - // The mouseover is always enabled, because the close button works - // regardless of key/main/active status. - closeTrackingArea_.reset( - [[NSTrackingArea alloc] initWithRect:[closeButton_ bounds] - options:NSTrackingMouseEnteredAndExited | - NSTrackingActiveAlways - owner:self - userInfo:nil]); - [closeButton_ addTrackingArea:closeTrackingArea_.get()]; - } else { - if (closeTrackingArea_.get()) { - [closeButton_ removeTrackingArea:closeTrackingArea_.get()]; - closeTrackingArea_.reset(nil); - } - } -} - -// The tracking areas have been moved. Make sure that the close button is -// highlighting correctly with respect to the cursor position with the new -// tracking area locations. -- (void)updateTrackingAreas { - [super updateTrackingAreas]; - if (closeTrackingArea_.get()) { - // Update the close buttons if the tab has moved. - NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream]; - mouseLoc = [self convertPointFromBase:mouseLoc]; - NSString* name = nil; - if (NSPointInRect(mouseLoc, [closeButton_ frame])) { - name = @"close_bar_h.pdf"; - } else { - name = @"close_bar.pdf"; - } - NSImage* newImage = nsimage_cache::ImageNamed(name); - NSImage* buttonImage = [closeButton_ image]; - if (![buttonImage isEqual:newImage]) { - [closeButton_ setImage:newImage]; - } - } + [closeButton_ setTrackingEnabled:enabled]; } // Determines which view a click in our frame actually hit. It's either this |