OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_COCOA_DRAGGABLE_BUTTON_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_DRAGGABLE_BUTTON_H_ |
| 7 #pragma once |
| 8 |
5 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
6 | 10 |
| 11 #import "base/memory/scoped_nsobject.h" |
| 12 #import "chrome/browser/ui/cocoa/draggable_button_mixin.h" |
| 13 |
7 // Class for buttons that can be drag sources. If the mouse is clicked and moved | 14 // Class for buttons that can be drag sources. If the mouse is clicked and moved |
8 // more than a given distance, this class will call |-beginDrag:| instead of | 15 // more than a given distance, this class will call |-beginDrag:| instead of |
9 // |-performClick:|. Subclasses should override these two methods. | 16 // |-performClick:|. Subclasses should override these two methods. |
10 @interface DraggableButton : NSButton { | 17 @interface DraggableButton : NSButton<DraggableButtonMixin> { |
11 @private | 18 @private |
12 BOOL draggable_; // Is this a draggable type of button? | 19 scoped_nsobject<DraggableButtonImpl> draggableButtonImpl_; |
13 BOOL actionHasFired_; // Has the action already fired for this click? | |
14 BOOL actsOnMouseDown_; // Does button action happen on mouse down when | |
15 // possible? | |
16 NSTimeInterval durationMouseWasDown_; | |
17 NSTimeInterval whenMouseDown_; | |
18 } | 20 } |
19 | 21 |
20 @property NSTimeInterval durationMouseWasDown; | 22 @property(readonly, nonatomic) DraggableButtonImpl* draggableButton; |
21 | 23 |
22 @property NSTimeInterval whenMouseDown; | 24 @end |
23 | 25 |
24 // Whether the action has already fired for this click. | 26 #endif // CHROME_BROWSER_UI_COCOA_DRAGGABLE_BUTTON_H_ |
25 @property(nonatomic) BOOL actionHasFired; | |
26 | |
27 // Enable or disable dragability for special buttons like "Other Bookmarks". | |
28 @property(nonatomic) BOOL draggable; | |
29 | |
30 // If it has a popup menu, for example, we want to perform the action on mouse | |
31 // down, if possible (as long as user still gets chance to drag, if | |
32 // appropriate). | |
33 @property(nonatomic) BOOL actsOnMouseDown; | |
34 | |
35 // Called when a drag should start. Subclasses must override this to do any | |
36 // pasteboard manipulation and begin the drag, usually with | |
37 // -dragImage:at:offset:event:. Subclasses must call one of the blocking | |
38 // -drag* methods of NSView when overriding this method. | |
39 - (void)beginDrag:(NSEvent*)dragEvent; | |
40 | |
41 | |
42 // Override if you want to do any extra work on mouseUp, after a mouseDown | |
43 // action has already fired. | |
44 - (void)secondaryMouseUpAction:(BOOL)wasInside; | |
45 | |
46 // This is called internally. | |
47 // Decides if we now have enough information to stop tracking the mouse. | |
48 // It's the function below, deltaIndicatesDragStartWithXDelta. however, that | |
49 // decides whether it's a drag or not. | |
50 // Override if you want to do something tricky when making the decision. | |
51 // Default impl returns YES if ABS(xDelta) or ABS(yDelta) >= their respective | |
52 // hysteresis limit. | |
53 - (BOOL)deltaIndicatesConclusionReachedWithXDelta:(float)xDelta | |
54 yDelta:(float)yDelta | |
55 xHysteresis:(float)xHysteresis | |
56 yHysteresis:(float)yHysteresis; | |
57 | |
58 // This is called internally. | |
59 // Decides whether we should treat the click as a cue to start dragging, or | |
60 // instead call the mouseDown/mouseUp handler as appropriate. | |
61 // Override if you want to do something tricky when making the decision. | |
62 // Default impl returns YES if ABS(xDelta) or ABS(yDelta) >= their respective | |
63 // hysteresis limit. | |
64 - (BOOL)deltaIndicatesDragStartWithXDelta:(float)xDelta | |
65 yDelta:(float)yDelta | |
66 xHysteresis:(float)xHysteresis | |
67 yHysteresis:(float)yHysteresis; | |
68 | |
69 | |
70 @end // @interface DraggableButton | |
71 | |
72 @interface DraggableButton (Private) | |
73 | |
74 // Resets the draggable state of the button after dragging is finished. This is | |
75 // called by DraggableButton when the beginDrag call returns, it should not be | |
76 // called by the subclass. | |
77 - (void)endDrag; | |
78 | |
79 // Called internally if the actsOnMouseDown property is set. | |
80 // Fires the button's action and tracks the click. | |
81 - (void)performMouseDownAction:(NSEvent*)theEvent; | |
82 | |
83 | |
84 @end // @interface DraggableButton(Private) | |
OLD | NEW |