Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_actions_container_view.mm

Issue 636283004: To ensure that the location bar will not reach the minimum width. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make naming consistent. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kBrowserActionGrippyWillDragNotification =
19 @"BrowserActionGrippyWillDragNotification";
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
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 = @{ kTranslationWithDelta : @(dX) };
129 [[NSNotificationCenter defaultCenter]
130 postNotificationName:kBrowserActionGrippyWillDragNotification
131 object:self
132 userInfo:userInfo];
133 }
134
121 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) 135 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_))
122 return; 136 return;
123 137
124 containerFrame.size.width = 138 containerFrame.size.width =
125 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth); 139 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth);
126 140
127 if (NSWidth(containerFrame) == kMinimumContainerWidth) 141 if (NSWidth(containerFrame) == kMinimumContainerWidth)
128 return; 142 return;
129 143
130 containerFrame.origin.x += dX; 144 containerFrame.origin.x += dX;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 retVal = [NSCursor resizeRightCursor]; 196 retVal = [NSCursor resizeRightCursor];
183 } else if (!canDragRight_) { 197 } else if (!canDragRight_) {
184 retVal = [NSCursor resizeLeftCursor]; 198 retVal = [NSCursor resizeLeftCursor];
185 } else { 199 } else {
186 retVal = [NSCursor resizeLeftRightCursor]; 200 retVal = [NSCursor resizeLeftRightCursor];
187 } 201 }
188 return retVal; 202 return retVal;
189 } 203 }
190 204
191 @end 205 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698