diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 22:50:44 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 22:50:44 +0000 |
commit | a99f83f902ee83a35be2606e7758099fa6d11324 (patch) | |
tree | 0585cb4ef5c2dbfedb3ec2c95da157429a2766ca /chrome/browser | |
parent | 34085a3e2502925a5c9974d15dd7c32f7cb60e35 (diff) | |
download | chromium_src-a99f83f902ee83a35be2606e7758099fa6d11324.zip chromium_src-a99f83f902ee83a35be2606e7758099fa6d11324.tar.gz chromium_src-a99f83f902ee83a35be2606e7758099fa6d11324.tar.bz2 |
Adds hover and pressed states for the newtab button on the Mac.
BrowserWindow.xib change was to add newtab_p as the image for the alternate
state for the new tab button.
BUG=26205
TEST=1) mouse over the new tab button and it should highlight.
2) Click and hold on the new tab button and its state should change
3) Release, and watch new tab get created. Verify that new button state
changes appropriately
4) Create a full tab strip of tabs. Verify that button state stays
correct as you click on the new tab button and new tabs are created but
the button doesn't move.
5) Create 2 tabs, and move the mouse button into the newtab button.
See that it highlights. hit cmd-w to close a tab. As the newtab button
moves away from under the cursor make sure it loses its highlight.
Review URL: http://codereview.chromium.org/372009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31316 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 40 |
2 files changed, 38 insertions, 5 deletions
diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h index eacad13..0ee2fc4 100644 --- a/chrome/browser/cocoa/tab_strip_controller.h +++ b/chrome/browser/cocoa/tab_strip_controller.h @@ -42,6 +42,9 @@ class ToolbarModel; NSView* switchView_; // weak scoped_nsobject<NSView> dragBlockingView_; // avoid bad window server drags NSButton* newTabButton_; // weak, obtained from the nib. + + // Tracks the newTabButton_ for rollovers. + scoped_nsobject<NSTrackingArea> newTabTrackingArea_; scoped_ptr<TabStripModelObserverBridge> bridge_; Browser* browser_; // weak TabStripModel* tabModel_; // weak diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 33fd937..dcc25ea 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -230,6 +230,13 @@ static const NSTimeInterval kAnimationDuration = 0.2; [newTabButton_ setTarget:nil]; [newTabButton_ setAction:@selector(commandDispatch:)]; [newTabButton_ setTag:IDC_NEW_TAB]; + newTabTrackingArea_.reset( + [[NSTrackingArea alloc] initWithRect:[newTabButton_ bounds] + options:(NSTrackingMouseEnteredAndExited | + NSTrackingActiveAlways) + owner:self + userInfo:nil]); + [newTabButton_ addTrackingArea:newTabTrackingArea_.get()]; targetFrames_.reset([[NSMutableDictionary alloc] init]); dragBlockingView_.reset( [[TabStripControllerDragBlockingView alloc] initWithFrame:NSZeroRect @@ -267,6 +274,7 @@ static const NSTimeInterval kAnimationDuration = 0.2; - (void)dealloc { if (trackingArea_.get()) [tabView_ removeTrackingArea:trackingArea_.get()]; + [newTabButton_ removeTrackingArea:newTabTrackingArea_.get()]; // Invalidate all closing animations so they don't call back to us after // we're gone. for (TabController* controller in closingControllers_.get()) { @@ -672,6 +680,18 @@ static const NSTimeInterval kAnimationDuration = 0.2; [newTabButton_ setHidden:NO]; if (!NSEqualRects(newTabTargetFrame_, newTabNewFrame)) { + // Set the new tab button image correctly based on where the cursor is. + NSWindow* window = [tabView_ window]; + NSPoint currentMouse = [window mouseLocationOutsideOfEventStream]; + currentMouse = [tabView_ convertPoint:currentMouse fromView:nil]; + NSString* imageName = nil; + if (NSPointInRect(currentMouse, newTabNewFrame)) { + imageName = @"newtab_h"; + } else { + imageName = @"newtab"; + } + [newTabButton_ setImage:nsimage_cache::ImageNamed(imageName)]; + // Move the new tab button into place. We want to animate the new tab // button if it's moving to the left (closing a tab), but not when it's // moving to the right (inserting a new tab). If moving right, we need @@ -1156,18 +1176,28 @@ static const NSTimeInterval kAnimationDuration = 0.2; } - (void)mouseEntered:(NSEvent*)event { - [self mouseMoved:event]; + NSTrackingArea* area = [event trackingArea]; + if ([area isEqual:trackingArea_]) { + [self mouseMoved:event]; + } else if ([area isEqual:newTabTrackingArea_]) { + [newTabButton_ setImage:nsimage_cache::ImageNamed(@"newtab_h.pdf")]; + } } // Called when the tracking area is in effect which means we're tracking to // see if the user leaves the tab strip with their mouse. When they do, // reset layout to use all available width. - (void)mouseExited:(NSEvent*)event { - availableResizeWidth_ = kUseFullAvailableWidth; + NSTrackingArea* area = [event trackingArea]; + if ([area isEqual:trackingArea_]) { + availableResizeWidth_ = kUseFullAvailableWidth; - [hoveredTab_ mouseExited:event]; - hoveredTab_ = nil; - [self layoutTabs]; + [hoveredTab_ mouseExited:event]; + hoveredTab_ = nil; + [self layoutTabs]; + } else if ([area isEqual:newTabTrackingArea_]) { + [newTabButton_ setImage:nsimage_cache::ImageNamed(@"newtab.pdf")]; + } } // Adds the given subview to (the end of) the list of permanent subviews |