diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-22 19:42:17 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-22 19:42:17 +0000 |
commit | fd08a47b86aa3d07fd72eb34d6c913f21fc0c8bc (patch) | |
tree | 8c863002839fa5843b72b2d75468a0a26a6b83cb /chrome/browser/cocoa/tab_strip_view.mm | |
parent | 41cf8020fe10d9949772f58af8504d768edd33a4 (diff) | |
download | chromium_src-fd08a47b86aa3d07fd72eb34d6c913f21fc0c8bc.zip chromium_src-fd08a47b86aa3d07fd72eb34d6c913f21fc0c8bc.tar.gz chromium_src-fd08a47b86aa3d07fd72eb34d6c913f21fc0c8bc.tar.bz2 |
Make double-clicking on the tab strip minimize (i.e., "miniaturize") the
window. Patch from viettrungluu@gmail.com (Viet-Trung Luu).
BUG=12286
TEST=double-clicking tab strip and anything that may have regressed in bug 12505
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_strip_view.mm')
-rw-r--r-- | chrome/browser/cocoa/tab_strip_view.mm | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/chrome/browser/cocoa/tab_strip_view.mm b/chrome/browser/cocoa/tab_strip_view.mm index 00f74cd..59b48e0 100644 --- a/chrome/browser/cocoa/tab_strip_view.mm +++ b/chrome/browser/cocoa/tab_strip_view.mm @@ -2,14 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/cocoa/tab_strip_view.h" +#import "chrome/browser/cocoa/tab_strip_view.h" + +#include "base/logging.h" @implementation TabStripView - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { - // Nothing yet to do here... + // Set lastMouseUp_ = -1000.0 so that timestamp-lastMouseUp_ is big unless + // lastMouseUp_ has been reset. + lastMouseUp_ = -1000.0; } return self; } @@ -23,17 +27,47 @@ NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); } -// Called to determine where in our view hierarchy the click should go. We -// want clicks to go to our children (tabs, new tab button, etc), but no click -// should ever go to this view. In fact, returning this view breaks things -// such as the window buttons and double-clicking the title bar since the -// window manager believes there is a view that wants the mouse event. If the -// superclass impl says the click should go here, just cheat and return nil. -- (NSView*)hitTest:(NSPoint)point { - NSView* hit = [super hitTest:point]; - if ([hit isEqual:self]) - hit = nil; - return hit; +// We accept first mouse so clicks onto close/zoom/miniaturize buttons and +// title bar double-clicks are properly detected even when the window is in the +// background. +- (BOOL)acceptsFirstMouse:(NSEvent*)event { + return YES; +} + +// Trap double-clicks and make them miniaturize the browser window. +- (void)mouseUp:(NSEvent*)event { + NSInteger clickCount = [event clickCount]; + NSTimeInterval timestamp = [event timestamp]; + + // Double-clicks on Zoom/Close/Mininiaturize buttons shouldn't cause + // miniaturization. For those, we miss the first click but get the second + // (with clickCount == 2!). We thus check that we got a first click shortly + // before (measured up-to-up) a double-click. Cocoa doesn't have a documented + // way of getting the proper interval (= (double-click-threshold) + + // (drag-threshold); the former is Carbon GetDblTime()/60.0 or + // com.apple.mouse.doubleClickThreshold [undocumented]). So we hard-code + // "short" as 0.8 seconds. (Measuring up-to-up isn't enough to properly + // detect double-clicks, but we're actually using Cocoa for that.) + if (clickCount == 2 && (timestamp - lastMouseUp_) < 0.8) { + // We use an undocumented method in Cocoa; if it doesn't exist, default to + // YES. If it ever goes away, we can do (using an undocumented pref. key): + // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + // if (![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] + // || [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"]) + // [[self window] performMiniaturize:self]; + DCHECK([NSWindow + respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]); + if (![NSWindow + respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)] + || [NSWindow + performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]) + [[self window] performMiniaturize:self]; + } else { + [super mouseUp:event]; + } + + // If clickCount is 0, the drag threshold was passed. + lastMouseUp_ = (clickCount == 1) ? timestamp : -1000.0; } @end |