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/extensions/browser_actions_container_view.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #import "chrome/browser/ui/cocoa/view_id_util.h" | 10 #import "chrome/browser/ui/cocoa/view_id_util.h" |
11 | 11 |
12 NSString* const kBrowserActionGrippyDragStartedNotification = | 12 NSString* const kBrowserActionGrippyDragStartedNotification = |
13 @"BrowserActionGrippyDragStartedNotification"; | 13 @"BrowserActionGrippyDragStartedNotification"; |
14 NSString* const kBrowserActionGrippyDraggingNotification = | 14 NSString* const kBrowserActionGrippyDraggingNotification = |
15 @"BrowserActionGrippyDraggingNotification"; | 15 @"BrowserActionGrippyDraggingNotification"; |
16 NSString* const kBrowserActionGrippyDragFinishedNotification = | 16 NSString* const kBrowserActionGrippyDragFinishedNotification = |
17 @"BrowserActionGrippyDragFinishedNotification"; | 17 @"BrowserActionGrippyDragFinishedNotification"; |
18 NSString* const kBrowserActionContainerWillTranslateOnXNotification = | |
Yoyo Zhou
2014/10/29 21:17:10
Should this name be more consistent with the other
Robert Sesek
2014/10/29 21:21:33
Yes, I'd recommend that.
Malcolm
2014/10/30 10:08:05
I will change the naming.
On 2014/10/29 21:21:33,
| |
19 @"BrowseActionContainerWillTranslateOnXNotification"; | |
20 NSString* const kTranslationWithDelta = | |
21 @"TranslationWithDelta"; | |
18 | 22 |
19 namespace { | 23 namespace { |
20 const CGFloat kAnimationDuration = 0.2; | 24 const CGFloat kAnimationDuration = 0.2; |
21 const CGFloat kGrippyWidth = 4.0; | 25 const CGFloat kGrippyWidth = 4.0; |
22 const CGFloat kMinimumContainerWidth = 10.0; | 26 const CGFloat kMinimumContainerWidth = 10.0; |
23 } // namespace | 27 } // namespace |
24 | 28 |
25 @interface BrowserActionsContainerView(Private) | 29 @interface BrowserActionsContainerView(Private) |
26 // Returns the cursor that should be shown when hovering over the grippy based | 30 // Returns the cursor that should be shown when hovering over the grippy based |
27 // on |canDragLeft_| and |canDragRight_|. | 31 // on |canDragLeft_| and |canDragRight_|. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 | 115 |
112 NSPoint location = [self convertPoint:[theEvent locationInWindow] | 116 NSPoint location = [self convertPoint:[theEvent locationInWindow] |
113 fromView:nil]; | 117 fromView:nil]; |
114 NSRect containerFrame = [self frame]; | 118 NSRect containerFrame = [self frame]; |
115 CGFloat dX = [theEvent deltaX]; | 119 CGFloat dX = [theEvent deltaX]; |
116 CGFloat withDelta = location.x - dX; | 120 CGFloat withDelta = location.x - dX; |
117 canDragRight_ = (withDelta >= initialDragPoint_.x) && | 121 canDragRight_ = (withDelta >= initialDragPoint_.x) && |
118 (NSWidth(containerFrame) > kMinimumContainerWidth); | 122 (NSWidth(containerFrame) > kMinimumContainerWidth); |
119 canDragLeft_ = (withDelta <= initialDragPoint_.x) && | 123 canDragLeft_ = (withDelta <= initialDragPoint_.x) && |
120 (NSWidth(containerFrame) < maxWidth_); | 124 (NSWidth(containerFrame) < maxWidth_); |
125 | |
126 // Notify others to see whether this dragging is allowed. | |
127 if (canDragLeft_ || canDragRight_) { | |
128 NSDictionary* userInfo = | |
129 [NSDictionary dictionaryWithObjectsAndKeys: | |
Robert Sesek
2014/10/29 21:21:34
This can be simplified to @{ kTranslationWithDelta
Malcolm
2014/10/30 10:08:05
Absolutely!
On 2014/10/29 21:21:34, Robert Sesek w
| |
130 [NSNumber numberWithFloat:dX], kTranslationWithDelta, nil]; | |
131 [[NSNotificationCenter defaultCenter] | |
132 postNotificationName:kBrowserActionContainerWillTranslateOnXNotification | |
133 object:self | |
134 userInfo:userInfo]; | |
135 } | |
136 | |
121 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) | 137 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) |
122 return; | 138 return; |
123 | 139 |
124 containerFrame.size.width = | 140 containerFrame.size.width = |
125 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth); | 141 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth); |
126 | 142 |
127 if (NSWidth(containerFrame) == kMinimumContainerWidth) | 143 if (NSWidth(containerFrame) == kMinimumContainerWidth) |
128 return; | 144 return; |
129 | 145 |
130 containerFrame.origin.x += dX; | 146 containerFrame.origin.x += dX; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 retVal = [NSCursor resizeRightCursor]; | 198 retVal = [NSCursor resizeRightCursor]; |
183 } else if (!canDragRight_) { | 199 } else if (!canDragRight_) { |
184 retVal = [NSCursor resizeLeftCursor]; | 200 retVal = [NSCursor resizeLeftCursor]; |
185 } else { | 201 } else { |
186 retVal = [NSCursor resizeLeftRightCursor]; | 202 retVal = [NSCursor resizeLeftRightCursor]; |
187 } | 203 } |
188 return retVal; | 204 return retVal; |
189 } | 205 } |
190 | 206 |
191 @end | 207 @end |
OLD | NEW |