OLD | NEW |
1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/draggable_button.h" | 5 #import "chrome/browser/ui/cocoa/draggable_button.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/memory/scoped_nsobject.h" | 10 #import "base/memory/scoped_nsobject.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 button_ = button; | 57 button_ = button; |
58 draggable_ = YES; | 58 draggable_ = YES; |
59 actsOnMouseDown_ = NO; | 59 actsOnMouseDown_ = NO; |
60 actionHasFired_ = NO; | 60 actionHasFired_ = NO; |
61 } | 61 } |
62 return self; | 62 return self; |
63 } | 63 } |
64 | 64 |
65 // NSButton/NSResponder Implementations //////////////////////////////////////// | 65 // NSButton/NSResponder Implementations //////////////////////////////////////// |
66 | 66 |
67 - (DraggableButtonResult)mouseUp:(NSEvent*)theEvent { | 67 - (DraggableButtonResult)mouseUpImpl:(NSEvent*)theEvent { |
68 durationMouseWasDown_ = [theEvent timestamp] - whenMouseDown_; | 68 durationMouseWasDown_ = [theEvent timestamp] - whenMouseDown_; |
69 | 69 |
70 if (actionHasFired_) | 70 if (actionHasFired_) |
71 return kDraggableButtonImplDidWork; | 71 return kDraggableButtonImplDidWork; |
72 | 72 |
73 if (!draggable_) | 73 if (!draggable_) |
74 return kDraggableButtonMixinCallSuper; | 74 return kDraggableButtonMixinCallSuper; |
75 | 75 |
76 // There are non-drag cases where a |-mouseUp:| may happen (e.g. mouse-down, | 76 // There are non-drag cases where a |-mouseUp:| may happen (e.g. mouse-down, |
77 // cmd-tab to another application, move mouse, mouse-up), so check. | 77 // cmd-tab to another application, move mouse, mouse-up), so check. |
78 NSPoint viewLocal = [button_ convertPoint:[theEvent locationInWindow] | 78 NSPoint viewLocal = [button_ convertPoint:[theEvent locationInWindow] |
79 fromView:[[button_ window] contentView]]; | 79 fromView:[[button_ window] contentView]]; |
80 if (NSPointInRect(viewLocal, [button_ bounds])) | 80 if (NSPointInRect(viewLocal, [button_ bounds])) |
81 [button_ performClick:self]; | 81 [button_ performClick:self]; |
82 | 82 |
83 return kDraggableButtonImplDidWork; | 83 return kDraggableButtonImplDidWork; |
84 } | 84 } |
85 | 85 |
86 // Mimic "begin a click" operation visually. Do NOT follow through with normal | 86 // Mimic "begin a click" operation visually. Do NOT follow through with normal |
87 // button event handling. | 87 // button event handling. |
88 - (DraggableButtonResult)mouseDown:(NSEvent*)theEvent { | 88 - (DraggableButtonResult)mouseDownImpl:(NSEvent*)theEvent { |
89 [[NSCursor arrowCursor] set]; | 89 [[NSCursor arrowCursor] set]; |
90 | 90 |
91 whenMouseDown_ = [theEvent timestamp]; | 91 whenMouseDown_ = [theEvent timestamp]; |
92 actionHasFired_ = NO; | 92 actionHasFired_ = NO; |
93 | 93 |
94 if (draggable_) { | 94 if (draggable_) { |
95 NSDate* date = [NSDate dateWithTimeIntervalSinceNow:kDragExpirationTimeout]; | 95 NSDate* date = [NSDate dateWithTimeIntervalSinceNow:kDragExpirationTimeout]; |
96 if ([self dragShouldBeginFromMouseDown:theEvent | 96 if ([self dragShouldBeginFromMouseDown:theEvent |
97 withExpiration:date]) { | 97 withExpiration:date]) { |
98 [button_ beginDrag:theEvent]; | 98 [button_ beginDrag:theEvent]; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 280 |
281 - (void)endDrag { | 281 - (void)endDrag { |
282 if ([button_ respondsToSelector:_cmd] && | 282 if ([button_ respondsToSelector:_cmd] && |
283 [button_ endDrag] != kDraggableButtonImplUseBase) { | 283 [button_ endDrag] != kDraggableButtonImplUseBase) { |
284 return; | 284 return; |
285 } | 285 } |
286 [button_ highlight:NO]; | 286 [button_ highlight:NO]; |
287 } | 287 } |
288 | 288 |
289 @end | 289 @end |
OLD | NEW |