| 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 #import "chrome/browser/cocoa/clickhold_button_cell.h" | 5 #import "chrome/browser/cocoa/clickhold_button_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 // Minimum and maximum click-hold timeout. | 9 // Minimum and maximum click-hold timeout. |
| 10 static const NSTimeInterval kMinTimeout = 0.01; | 10 static const NSTimeInterval kMinTimeout = 0.01; |
| 11 static const NSTimeInterval kMaxTimeout = 3600.0; | 11 static const NSTimeInterval kMaxTimeout = 3600.0; |
| 12 | 12 |
| 13 // Drag distance threshold to activate click-hold; should be >= 0. | 13 // Drag distance threshold to activate click-hold; should be >= 0. |
| 14 static const CGFloat kDragDistThreshold = 2.5; | 14 static const CGFloat kDragDistThreshold = 2.5; |
| 15 | 15 |
| 16 // See |-resetToDefaults| (and header file) for other default values. |
| 17 |
| 18 @interface ClickHoldButtonCell (Private) |
| 19 - (void)resetToDefaults; |
| 20 @end // @interface ClickHoldButtonCell (Private) |
| 21 |
| 16 @implementation ClickHoldButtonCell | 22 @implementation ClickHoldButtonCell |
| 17 | 23 |
| 18 // Overrides: | 24 // Overrides: |
| 19 | 25 |
| 20 + (BOOL)prefersTrackingUntilMouseUp { | 26 + (BOOL)prefersTrackingUntilMouseUp { |
| 21 return NO; | 27 return NO; |
| 22 } | 28 } |
| 23 | 29 |
| 30 - (id)init { |
| 31 if ((self = [super init])) |
| 32 [self resetToDefaults]; |
| 33 return self; |
| 34 } |
| 35 |
| 36 - (id)initWithCoder:(NSCoder*)decoder { |
| 37 if ((self = [super initWithCoder:decoder])) |
| 38 [self resetToDefaults]; |
| 39 return self; |
| 40 } |
| 41 |
| 42 - (id)initImageCell:(NSImage*)image { |
| 43 if ((self = [super initImageCell:image])) |
| 44 [self resetToDefaults]; |
| 45 return self; |
| 46 } |
| 47 |
| 48 - (id)initTextCell:(NSString*)string { |
| 49 if ((self = [super initTextCell:string])) |
| 50 [self resetToDefaults]; |
| 51 return self; |
| 52 } |
| 53 |
| 24 - (BOOL)startTrackingAt:(NSPoint)startPoint | 54 - (BOOL)startTrackingAt:(NSPoint)startPoint |
| 25 inView:(NSView*)controlView { | 55 inView:(NSView*)controlView { |
| 26 return enableClickHold_ ? | 56 return enableClickHold_ ? YES : |
| 27 YES : | 57 [super startTrackingAt:startPoint |
| 28 [super startTrackingAt:startPoint | 58 inView:controlView]; |
| 29 inView:controlView]; | |
| 30 } | 59 } |
| 31 | 60 |
| 32 - (BOOL)continueTracking:(NSPoint)lastPoint | 61 - (BOOL)continueTracking:(NSPoint)lastPoint |
| 33 at:(NSPoint)currentPoint | 62 at:(NSPoint)currentPoint |
| 34 inView:(NSView*)controlView { | 63 inView:(NSView*)controlView { |
| 35 return enableClickHold_ ? | 64 return enableClickHold_ ? YES : |
| 36 YES : | 65 [super continueTracking:lastPoint |
| 37 [super continueTracking:lastPoint | 66 at:currentPoint |
| 38 at:currentPoint | 67 inView:controlView]; |
| 39 inView:controlView]; | |
| 40 } | 68 } |
| 41 | 69 |
| 42 - (BOOL)trackMouse:(NSEvent*)originalEvent | 70 - (BOOL)trackMouse:(NSEvent*)originalEvent |
| 43 inRect:(NSRect)cellFrame | 71 inRect:(NSRect)cellFrame |
| 44 ofView:(NSView*)controlView | 72 ofView:(NSView*)controlView |
| 45 untilMouseUp:(BOOL)untilMouseUp { | 73 untilMouseUp:(BOOL)untilMouseUp { |
| 46 if (!enableClickHold_) { | 74 if (!enableClickHold_) { |
| 47 return [super trackMouse:originalEvent | 75 return [super trackMouse:originalEvent |
| 48 inRect:cellFrame | 76 inRect:cellFrame |
| 49 ofView:controlView | 77 ofView:controlView |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Accessors and mutators: | 166 // Accessors and mutators: |
| 139 | 167 |
| 140 @synthesize enableClickHold = enableClickHold_; | 168 @synthesize enableClickHold = enableClickHold_; |
| 141 @synthesize clickHoldTimeout = clickHoldTimeout_; | 169 @synthesize clickHoldTimeout = clickHoldTimeout_; |
| 142 @synthesize trackOnlyInRect = trackOnlyInRect_; | 170 @synthesize trackOnlyInRect = trackOnlyInRect_; |
| 143 @synthesize activateOnDrag = activateOnDrag_; | 171 @synthesize activateOnDrag = activateOnDrag_; |
| 144 @synthesize clickHoldTarget = clickHoldTarget_; | 172 @synthesize clickHoldTarget = clickHoldTarget_; |
| 145 @synthesize clickHoldAction = clickHoldAction_; | 173 @synthesize clickHoldAction = clickHoldAction_; |
| 146 | 174 |
| 147 @end // @implementation ClickHoldButtonCell | 175 @end // @implementation ClickHoldButtonCell |
| 176 |
| 177 @implementation ClickHoldButtonCell (Private) |
| 178 |
| 179 // Resets various members to defaults indicated in the header file. (Those |
| 180 // without indicated defaults are *not* touched.) Please keep the values below |
| 181 // in sync with the header file, and please be aware of side-effects on code |
| 182 // which relies on the "published" defaults. |
| 183 - (void)resetToDefaults { |
| 184 [self setEnableClickHold:NO]; |
| 185 [self setClickHoldTimeout:0.25]; |
| 186 [self setTrackOnlyInRect:NO]; |
| 187 [self setActivateOnDrag:YES]; |
| 188 } |
| 189 |
| 190 @end // @implementation ClickHoldButtonCell (Private) |
| OLD | NEW |