| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/cocoa/tab_strip_view.h" | 5 #import "chrome/browser/cocoa/tab_strip_view.h" |
| 6 |
| 7 #include "base/logging.h" |
| 6 | 8 |
| 7 @implementation TabStripView | 9 @implementation TabStripView |
| 8 | 10 |
| 9 - (id)initWithFrame:(NSRect)frame { | 11 - (id)initWithFrame:(NSRect)frame { |
| 10 self = [super initWithFrame:frame]; | 12 self = [super initWithFrame:frame]; |
| 11 if (self) { | 13 if (self) { |
| 12 // Nothing yet to do here... | 14 // Set lastMouseUp_ = -1000.0 so that timestamp-lastMouseUp_ is big unless |
| 15 // lastMouseUp_ has been reset. |
| 16 lastMouseUp_ = -1000.0; |
| 13 } | 17 } |
| 14 return self; | 18 return self; |
| 15 } | 19 } |
| 16 | 20 |
| 17 - (void)drawRect:(NSRect)rect { | 21 - (void)drawRect:(NSRect)rect { |
| 18 NSRect boundsRect = [self bounds]; | 22 NSRect boundsRect = [self bounds]; |
| 19 NSRect borderRect, contentRect; | 23 NSRect borderRect, contentRect; |
| 20 NSDivideRect(boundsRect, &borderRect, &contentRect, 1, NSMinYEdge); | 24 NSDivideRect(boundsRect, &borderRect, &contentRect, 1, NSMinYEdge); |
| 21 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.3] set]; | 25 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.3] set]; |
| 22 | 26 |
| 23 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 27 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
| 24 } | 28 } |
| 25 | 29 |
| 26 // Called to determine where in our view hierarchy the click should go. We | 30 // We accept first mouse so clicks onto close/zoom/miniaturize buttons and |
| 27 // want clicks to go to our children (tabs, new tab button, etc), but no click | 31 // title bar double-clicks are properly detected even when the window is in the |
| 28 // should ever go to this view. In fact, returning this view breaks things | 32 // background. |
| 29 // such as the window buttons and double-clicking the title bar since the | 33 - (BOOL)acceptsFirstMouse:(NSEvent*)event { |
| 30 // window manager believes there is a view that wants the mouse event. If the | 34 return YES; |
| 31 // superclass impl says the click should go here, just cheat and return nil. | 35 } |
| 32 - (NSView*)hitTest:(NSPoint)point { | 36 |
| 33 NSView* hit = [super hitTest:point]; | 37 // Trap double-clicks and make them miniaturize the browser window. |
| 34 if ([hit isEqual:self]) | 38 - (void)mouseUp:(NSEvent*)event { |
| 35 hit = nil; | 39 NSInteger clickCount = [event clickCount]; |
| 36 return hit; | 40 NSTimeInterval timestamp = [event timestamp]; |
| 41 |
| 42 // Double-clicks on Zoom/Close/Mininiaturize buttons shouldn't cause |
| 43 // miniaturization. For those, we miss the first click but get the second |
| 44 // (with clickCount == 2!). We thus check that we got a first click shortly |
| 45 // before (measured up-to-up) a double-click. Cocoa doesn't have a documented |
| 46 // way of getting the proper interval (= (double-click-threshold) + |
| 47 // (drag-threshold); the former is Carbon GetDblTime()/60.0 or |
| 48 // com.apple.mouse.doubleClickThreshold [undocumented]). So we hard-code |
| 49 // "short" as 0.8 seconds. (Measuring up-to-up isn't enough to properly |
| 50 // detect double-clicks, but we're actually using Cocoa for that.) |
| 51 if (clickCount == 2 && (timestamp - lastMouseUp_) < 0.8) { |
| 52 // We use an undocumented method in Cocoa; if it doesn't exist, default to |
| 53 // YES. If it ever goes away, we can do (using an undocumented pref. key): |
| 54 // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 55 // if (![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] |
| 56 // || [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"]) |
| 57 // [[self window] performMiniaturize:self]; |
| 58 DCHECK([NSWindow |
| 59 respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]); |
| 60 if (![NSWindow |
| 61 respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)] |
| 62 || [NSWindow |
| 63 performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]) |
| 64 [[self window] performMiniaturize:self]; |
| 65 } else { |
| 66 [super mouseUp:event]; |
| 67 } |
| 68 |
| 69 // If clickCount is 0, the drag threshold was passed. |
| 70 lastMouseUp_ = (clickCount == 1) ? timestamp : -1000.0; |
| 37 } | 71 } |
| 38 | 72 |
| 39 @end | 73 @end |
| OLD | NEW |