diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 00:46:49 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 00:46:49 +0000 |
commit | 110a4e7b14519e6b3771dd9c0501618ed45fc837 (patch) | |
tree | 75eeaa9ef1c7569a7aed2282895155f7234b2d15 /chrome/browser/cocoa/tab_strip_controller.mm | |
parent | df5a4ffbb5531ca94bcf9b6a9825a99a3413c47b (diff) | |
download | chromium_src-110a4e7b14519e6b3771dd9c0501618ed45fc837.zip chromium_src-110a4e7b14519e6b3771dd9c0501618ed45fc837.tar.gz chromium_src-110a4e7b14519e6b3771dd9c0501618ed45fc837.tar.bz2 |
Reverting 24700.
Review URL: http://codereview.chromium.org/181002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24708 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_strip_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index b4b41cf..466ec30 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -47,6 +47,7 @@ static const float kUseFullAvailableWidth = -1.0; @end @interface TabStripController(Private) +- (void)installTrackingArea; - (BOOL)useFullWidthForLayout; - (void)addSubviewToPermanentList:(NSView*)aView; - (void)regenerateSubviewList; @@ -82,6 +83,7 @@ static const float kUseFullAvailableWidth = -1.0; [newTabButton_ setAction:@selector(commandDispatch:)]; [newTabButton_ setTag:IDC_NEW_TAB]; targetFrames_.reset([[NSMutableDictionary alloc] init]); + [tabView_ setWantsLayer:YES]; dragBlockingView_.reset([[TabStripControllerDragBlockingView alloc] initWithFrame:NSZeroRect]); [self addSubviewToPermanentList:dragBlockingView_]; @@ -98,23 +100,13 @@ static const float kUseFullAvailableWidth = -1.0; selector:@selector(tabViewFrameChanged:) name:NSViewFrameDidChangeNotification object:tabView_]; - - trackingArea_.reset([[NSTrackingArea alloc] - initWithRect:NSZeroRect // Ignored by NSTrackingInVisibleRect - options:NSTrackingMouseEnteredAndExited | - NSTrackingMouseMoved | - NSTrackingActiveAlways | - NSTrackingInVisibleRect - owner:self - userInfo:nil]); - [tabView_ addTrackingArea:trackingArea_.get()]; } return self; } - (void)dealloc { - if (trackingArea_.get()) - [tabView_ removeTrackingArea:trackingArea_.get()]; + if (closeTabTrackingArea_.get()) + [tabView_ removeTrackingArea:closeTabTrackingArea_.get()]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @@ -237,9 +229,6 @@ static const float kUseFullAvailableWidth = -1.0; // is the TabView that is potentially going away. - (void)closeTab:(id)sender { DCHECK([sender isKindOfClass:[NSView class]]); - if ([hoveredTab_ isEqual:sender]) { - hoveredTab_ = nil; - } int index = [self indexForTabView:sender]; if (tabModel_->ContainsIndex(index)) { TabContents* contents = tabModel_->GetTabContentsAt(index); @@ -251,6 +240,7 @@ static const float kUseFullAvailableWidth = -1.0; // TODO(pinkerton): re-visit when handling tab overflow. NSView* penultimateTab = [self viewAtIndex:[tabArray_ count] - 2]; availableResizeWidth_ = NSMaxX([penultimateTab frame]); + [self installTrackingArea]; tabModel_->CloseTabContentsAt(index); } else { // Use the standard window close if this is the last tab @@ -345,7 +335,7 @@ static const float kUseFullAvailableWidth = -1.0; for (TabController* tab in tabArray_.get()) { BOOL isPlaceholder = [[tab view] isEqual:placeholderTab_]; NSRect tabFrame = [[tab view] frame]; - tabFrame.size.height = [[self class] defaultTabHeight] + 1; + tabFrame.size.height = [[self class] defaultTabHeight]; tabFrame.origin.y = 0; tabFrame.origin.x = offset; @@ -573,10 +563,6 @@ static const float kUseFullAvailableWidth = -1.0; NSView* tab = [self viewAtIndex:index]; [tab removeFromSuperview]; - if ([hoveredTab_ isEqual:tab]) { - hoveredTab_ = nil; - } - NSValue *identifier = [NSValue valueWithPointer:tab]; [targetFrames_ removeObjectForKey:identifier]; @@ -761,9 +747,9 @@ static const float kUseFullAvailableWidth = -1.0; tabModel_->InsertTabContentsAt(index, contents, true, false); } -- (void)applyTheme { +- (void)userChangedTheme { for (TabController* tab in tabArray_.get()) { - [tab applyTheme]; + [[tab view] setNeedsDisplay:YES]; } } @@ -780,38 +766,34 @@ static const float kUseFullAvailableWidth = -1.0; return availableResizeWidth_ == kUseFullAvailableWidth; } -- (void)mouseMoved:(NSEvent *)event { - // Use hit test to figure out what view we are hovering over. - TabView* targetView = (TabView*)[tabView_ hitTest:[event locationInWindow]]; - if (![targetView isKindOfClass:[TabView class]]) { - if ([[targetView superview] isKindOfClass:[TabView class]]) { - targetView = (TabView*)[targetView superview]; - } else { - targetView = nil; - } - } - - if (hoveredTab_ != targetView) { - [hoveredTab_ mouseExited:nil]; // We don't pass event because moved events - [targetView mouseEntered:nil]; // don't have valid tracking areas - hoveredTab_ = targetView; - } else { - [hoveredTab_ mouseMoved:event]; - } +// Call to install a tracking area that reports mouseEnter/Exit messages so +// we can track when the mouse leaves the tab view after closing a tab with +// the mouse. Don't install another tracking rect if one is already there. +- (void)installTrackingArea { + if (closeTabTrackingArea_.get()) + return; + // Note that we pass |NSTrackingInVisibleRect| so the rect is actually + // ignored. + closeTabTrackingArea_.reset([[NSTrackingArea alloc] + initWithRect:[tabView_ bounds] + options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | + NSTrackingInVisibleRect + owner:self + userInfo:nil]); + [tabView_ addTrackingArea:closeTabTrackingArea_.get()]; } - (void)mouseEntered:(NSEvent*)event { - [self mouseMoved:event]; + // Do nothing. } // 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 { + [tabView_ removeTrackingArea:closeTabTrackingArea_.get()]; + closeTabTrackingArea_.reset(nil); availableResizeWidth_ = kUseFullAvailableWidth; - - [hoveredTab_ mouseExited:event]; - hoveredTab_ = nil; [self layoutTabs]; } |