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

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

Issue 1009613002: [Toolbar UI Mac] Fix omnibox minimum width (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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 kBrowserActionsContainerWillAnimate = 18 NSString* const kBrowserActionsContainerWillAnimate =
21 @"BrowserActionsContainerWillAnimate"; 19 @"BrowserActionsContainerWillAnimate";
22 NSString* const kBrowserActionsContainerMouseEntered = 20 NSString* const kBrowserActionsContainerMouseEntered =
23 @"BrowserActionsContainerMouseEntered"; 21 @"BrowserActionsContainerMouseEntered";
24 NSString* const kTranslationWithDelta = 22 NSString* const kTranslationWithDelta =
25 @"TranslationWithDelta"; 23 @"TranslationWithDelta";
26 24
27 namespace { 25 namespace {
28 const CGFloat kAnimationDuration = 0.2; 26 const CGFloat kAnimationDuration = 0.2;
29 const CGFloat kGrippyWidth = 3.0; 27 const CGFloat kGrippyWidth = 3.0;
30 const CGFloat kMinimumContainerWidth = 3.0; 28 const CGFloat kMinimumContainerWidth = 3.0;
31 } // namespace 29 } // namespace
32 30
33 @interface BrowserActionsContainerView(Private) 31 @interface BrowserActionsContainerView(Private)
34 // Returns the cursor that should be shown when hovering over the grippy based 32 // Returns the cursor that should be shown when hovering over the grippy based
35 // on |canDragLeft_| and |canDragRight_|. 33 // on |canDragLeft_| and |canDragRight_|.
36 - (NSCursor*)appropriateCursorForGrippy; 34 - (NSCursor*)appropriateCursorForGrippy;
35
36 // Returns the maximum allowed size for the container.
37 - (CGFloat)maxAllowedWidth;
37 @end 38 @end
38 39
39 @implementation BrowserActionsContainerView 40 @implementation BrowserActionsContainerView
40 41
41 @synthesize canDragLeft = canDragLeft_; 42 @synthesize canDragLeft = canDragLeft_;
42 @synthesize canDragRight = canDragRight_; 43 @synthesize canDragRight = canDragRight_;
43 @synthesize grippyPinned = grippyPinned_; 44 @synthesize grippyPinned = grippyPinned_;
44 @synthesize maxWidth = maxWidth_; 45 @synthesize maxDesiredWidth = maxDesiredWidth_;
45 @synthesize userIsResizing = userIsResizing_; 46 @synthesize userIsResizing = userIsResizing_;
47 @synthesize delegate = delegate_;
46 48
47 #pragma mark - 49 #pragma mark -
48 #pragma mark Overridden Class Functions 50 #pragma mark Overridden Class Functions
49 51
50 - (id)initWithFrame:(NSRect)frameRect { 52 - (id)initWithFrame:(NSRect)frameRect {
51 if ((self = [super initWithFrame:frameRect])) { 53 if ((self = [super initWithFrame:frameRect])) {
52 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); 54 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds]));
53 canDragLeft_ = YES; 55 canDragLeft_ = YES;
54 canDragRight_ = YES; 56 canDragRight_ = YES;
55 resizable_ = YES; 57 resizable_ = YES;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (!userIsResizing_) 151 if (!userIsResizing_)
150 return; 152 return;
151 153
152 NSPoint location = [self convertPoint:[theEvent locationInWindow] 154 NSPoint location = [self convertPoint:[theEvent locationInWindow]
153 fromView:nil]; 155 fromView:nil];
154 NSRect containerFrame = [self frame]; 156 NSRect containerFrame = [self frame];
155 CGFloat dX = [theEvent deltaX]; 157 CGFloat dX = [theEvent deltaX];
156 CGFloat withDelta = location.x - dX; 158 CGFloat withDelta = location.x - dX;
157 canDragRight_ = (withDelta >= initialDragPoint_.x) && 159 canDragRight_ = (withDelta >= initialDragPoint_.x) &&
158 (NSWidth(containerFrame) > kMinimumContainerWidth); 160 (NSWidth(containerFrame) > kMinimumContainerWidth);
159 canDragLeft_ = (withDelta <= initialDragPoint_.x) && 161 CGFloat maxAllowedWidth = [self maxAllowedWidth];
160 (NSWidth(containerFrame) < maxWidth_); 162 containerFrame.size.width =
161 163 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth);
162 // Notify others to see whether this dragging is allowed. 164 canDragLeft_ = withDelta <= initialDragPoint_.x &&
163 if ((dX < 0.0 && canDragLeft_) || (dX > 0.0 && canDragRight_)) { 165 NSWidth(containerFrame) < maxDesiredWidth_ &&
164 NSDictionary* userInfo = @{ kTranslationWithDelta : @(dX) }; 166 NSWidth(containerFrame) < maxAllowedWidth;
165 [[NSNotificationCenter defaultCenter]
166 postNotificationName:kBrowserActionGrippyWillDragNotification
167 object:self
168 userInfo:userInfo];
169 }
170 167
171 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) 168 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_))
172 return; 169 return;
173 170
174 containerFrame.size.width =
175 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth);
176
177 if (NSWidth(containerFrame) == kMinimumContainerWidth) 171 if (NSWidth(containerFrame) == kMinimumContainerWidth)
178 return; 172 return;
179 173
174 grippyPinned_ = NSWidth(containerFrame) == maxAllowedWidth;
180 containerFrame.origin.x += dX; 175 containerFrame.origin.x += dX;
181 176
182 [self setFrame:containerFrame]; 177 [self setFrame:containerFrame];
183 [self setNeedsDisplay:YES]; 178 [self setNeedsDisplay:YES];
184 179
185 [[NSNotificationCenter defaultCenter] 180 [[NSNotificationCenter defaultCenter]
186 postNotificationName:kBrowserActionGrippyDraggingNotification 181 postNotificationName:kBrowserActionGrippyDraggingNotification
187 object:self]; 182 object:self];
188 183
189 lastXPos_ += dX; 184 lastXPos_ += dX;
190 } 185 }
191 186
192 - (ViewID)viewID { 187 - (ViewID)viewID {
193 return VIEW_ID_BROWSER_ACTION_TOOLBAR; 188 return VIEW_ID_BROWSER_ACTION_TOOLBAR;
194 } 189 }
195 190
196 #pragma mark - 191 #pragma mark -
197 #pragma mark Public Methods 192 #pragma mark Public Methods
198 193
199 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { 194 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate {
200 width = std::max(width, kMinimumContainerWidth); 195 width = std::max(width, kMinimumContainerWidth);
201 NSRect frame = [self frame]; 196 NSRect frame = [self frame];
197
198 CGFloat maxAllowedWidth = [self maxAllowedWidth];
199 if (width > maxAllowedWidth)
200 width = maxAllowedWidth;
Avi (use Gerrit) 2015/03/13 23:26:03 std::min? (parallel to line 195)
Devlin 2015/03/14 00:03:14 Done.
201
202 lastXPos_ = frame.origin.x; 202 lastXPos_ = frame.origin.x;
203 CGFloat dX = frame.size.width - width; 203 CGFloat dX = frame.size.width - width;
204 frame.size.width = width; 204 frame.size.width = width;
205 NSRect newFrame = NSOffsetRect(frame, dX, 0); 205 NSRect newFrame = NSOffsetRect(frame, dX, 0);
206 206
207 grippyPinned_ = width == maxAllowedWidth;
208
207 [self stopAnimation]; 209 [self stopAnimation];
208 210
209 if (animate) { 211 if (animate) {
210 NSDictionary* animationDictionary = @{ 212 NSDictionary* animationDictionary = @{
211 NSViewAnimationTargetKey : self, 213 NSViewAnimationTargetKey : self,
212 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], 214 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]],
213 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] 215 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame]
214 }; 216 };
215 [resizeAnimation_ setViewAnimations:@[ animationDictionary ]]; 217 [resizeAnimation_ setViewAnimations:@[ animationDictionary ]];
216 [resizeAnimation_ startAnimation]; 218 [resizeAnimation_ startAnimation];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } else if (!canDragLeft_) { 261 } else if (!canDragLeft_) {
260 retVal = [NSCursor resizeRightCursor]; 262 retVal = [NSCursor resizeRightCursor];
261 } else if (!canDragRight_) { 263 } else if (!canDragRight_) {
262 retVal = [NSCursor resizeLeftCursor]; 264 retVal = [NSCursor resizeLeftCursor];
263 } else { 265 } else {
264 retVal = [NSCursor resizeLeftRightCursor]; 266 retVal = [NSCursor resizeLeftRightCursor];
265 } 267 }
266 return retVal; 268 return retVal;
267 } 269 }
268 270
271 - (CGFloat)maxAllowedWidth {
272 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX;
273 }
274
269 @end 275 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698