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

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

Issue 2629723005: [Mac] Fix bugs in resizing the browser actions area next to the omnibox. (Closed)
Patch Set: Clarity tweaks. Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility> 8 #include <utility>
9 9
10 #import "chrome/browser/ui/cocoa/l10n_util.h" 10 #import "chrome/browser/ui/cocoa/l10n_util.h"
11 #import "chrome/browser/ui/cocoa/view_id_util.h" 11 #import "chrome/browser/ui/cocoa/view_id_util.h"
12 #include "chrome/browser/ui/layout_constants.h"
Robert Sesek 2017/01/13 22:53:59 I can't find any other uses of layout_constants.h
Sidney San Martín 2017/01/13 23:03:29 I may have a better option, hang tight.
12 #include "ui/base/cocoa/appkit_utils.h" 13 #include "ui/base/cocoa/appkit_utils.h"
13 #include "ui/events/keycodes/keyboard_code_conversion_mac.h" 14 #include "ui/events/keycodes/keyboard_code_conversion_mac.h"
14 15
15 NSString* const kBrowserActionGrippyDragStartedNotification = 16 NSString* const kBrowserActionGrippyDragStartedNotification =
16 @"BrowserActionGrippyDragStartedNotification"; 17 @"BrowserActionGrippyDragStartedNotification";
17 NSString* const kBrowserActionGrippyDraggingNotification = 18 NSString* const kBrowserActionGrippyDraggingNotification =
18 @"BrowserActionGrippyDraggingNotification"; 19 @"BrowserActionGrippyDraggingNotification";
19 NSString* const kBrowserActionGrippyDragFinishedNotification = 20 NSString* const kBrowserActionGrippyDragFinishedNotification =
20 @"BrowserActionGrippyDragFinishedNotification"; 21 @"BrowserActionGrippyDragFinishedNotification";
21 NSString* const kBrowserActionsContainerWillAnimate = 22 NSString* const kBrowserActionsContainerWillAnimate =
22 @"BrowserActionsContainerWillAnimate"; 23 @"BrowserActionsContainerWillAnimate";
23 NSString* const kBrowserActionsContainerAnimationEnded = 24 NSString* const kBrowserActionsContainerAnimationEnded =
24 @"BrowserActionsContainerAnimationEnded"; 25 @"BrowserActionsContainerAnimationEnded";
25 NSString* const kTranslationWithDelta = 26 NSString* const kTranslationWithDelta =
26 @"TranslationWithDelta"; 27 @"TranslationWithDelta";
27 NSString* const kBrowserActionsContainerReceivedKeyEvent = 28 NSString* const kBrowserActionsContainerReceivedKeyEvent =
28 @"BrowserActionsContainerReceivedKeyEvent"; 29 @"BrowserActionsContainerReceivedKeyEvent";
29 NSString* const kBrowserActionsContainerKeyEventKey = 30 NSString* const kBrowserActionsContainerKeyEventKey =
30 @"BrowserActionsContainerKeyEventKey"; 31 @"BrowserActionsContainerKeyEventKey";
31 32
32 namespace { 33 namespace {
33 const CGFloat kAnimationDuration = 0.2; 34 const CGFloat kAnimationDuration = 0.2;
34 const CGFloat kGrippyWidth = 3.0; 35 const CGFloat kGrippyWidth = 3.0;
35 const CGFloat kMinimumContainerWidth = 3.0;
36 } // namespace 36 } // namespace
37 37
38 @interface BrowserActionsContainerView(Private) 38 @interface BrowserActionsContainerView(Private)
39 // Returns the cursor that should be shown when hovering over the grippy based 39 // Returns the cursor that should be shown when hovering over the grippy based
40 // on |canDragLeft_| and |canDragRight_|. 40 // on |canDragLeft_| and |canDragRight_|.
41 - (NSCursor*)appropriateCursorForGrippy; 41 - (NSCursor*)appropriateCursorForGrippy;
42 42
43 // Returns the maximum allowed size for the container. 43 // Returns the maximum allowed size for the container.
44 - (CGFloat)maxAllowedWidth; 44 - (CGFloat)maxAllowedWidth;
45 @end 45 @end
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 postNotificationName:kBrowserActionGrippyDragFinishedNotification 210 postNotificationName:kBrowserActionGrippyDragFinishedNotification
211 object:self]; 211 object:self];
212 } 212 }
213 213
214 - (void)mouseDragged:(NSEvent*)theEvent { 214 - (void)mouseDragged:(NSEvent*)theEvent {
215 if (!userIsResizing_) 215 if (!userIsResizing_)
216 return; 216 return;
217 217
218 NSPoint location = [self convertPoint:[theEvent locationInWindow] 218 NSPoint location = [self convertPoint:[theEvent locationInWindow]
219 fromView:nil]; 219 fromView:nil];
220 NSRect containerFrame = [self frame];
221 CGFloat dX = [theEvent deltaX];
222 CGFloat withDelta = location.x - dX;
223 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); 220 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
224 221
225 CGFloat maxAllowedWidth = [self maxAllowedWidth]; 222 const CGFloat minWidth = GetLayoutConstant(TOOLBAR_STANDARD_SPACING);
223 const CGFloat maxWidth = std::min([self maxAllowedWidth], maxDesiredWidth_);
226 224
227 const CGFloat maxWidth = std::min(maxAllowedWidth, maxDesiredWidth_); 225 const CGFloat oldWidth = NSWidth(self.frame);
228 CGFloat newWidth = NSWidth(containerFrame) + (isRTL ? dX : -dX); 226 const CGFloat newWidth =
229 newWidth = std::min(std::max(newWidth, kMinimumContainerWidth), maxWidth); 227 std::min(std::max((isRTL ? location.x : oldWidth - location.x), minWidth),
228 maxWidth);
230 229
231 BOOL canGrow = NSWidth(containerFrame) < maxWidth; 230 (isRTL ? canDragLeft_ : canDragRight_) = newWidth < maxWidth;
232 BOOL canShrink = NSWidth(containerFrame) > kMinimumContainerWidth; 231 (isRTL ? canDragRight_ : canDragLeft_) = newWidth > minWidth;
233 232
234 canDragLeft_ = 233 grippyPinned_ = newWidth == maxWidth;
235 withDelta <= initialDragPoint_.x && (isRTL ? canShrink : canGrow);
236 canDragRight_ =
237 (withDelta >= initialDragPoint_.x) && (isRTL ? canGrow : canShrink);
238 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_) ||
239 fabs(dX) < FLT_EPSILON)
240 return;
241 234
242 grippyPinned_ = newWidth >= maxAllowedWidth; 235 NSRect newFrame = self.frame;
243 if (!isRTL) 236 if (!isRTL)
244 containerFrame.origin.x += dX; 237 newFrame.origin.x += oldWidth - newWidth;
245 containerFrame.size.width = newWidth; 238 newFrame.size.width = newWidth;
246 239
247 [self setFrame:containerFrame]; 240 [self setFrame:newFrame];
248 [self setNeedsDisplay:YES]; 241 [self setNeedsDisplay:YES];
249 242
250 [[NSNotificationCenter defaultCenter] 243 [[NSNotificationCenter defaultCenter]
251 postNotificationName:kBrowserActionGrippyDraggingNotification 244 postNotificationName:kBrowserActionGrippyDraggingNotification
252 object:self]; 245 object:self];
253 } 246 }
254 247
255 - (void)animationDidEnd:(NSAnimation*)animation { 248 - (void)animationDidEnd:(NSAnimation*)animation {
256 // We notify asynchronously so that the animation fully finishes before any 249 // We notify asynchronously so that the animation fully finishes before any
257 // listeners do work. 250 // listeners do work.
(...skipping 17 matching lines...) Expand all
275 } 268 }
276 269
277 - (ViewID)viewID { 270 - (ViewID)viewID {
278 return VIEW_ID_BROWSER_ACTION_TOOLBAR; 271 return VIEW_ID_BROWSER_ACTION_TOOLBAR;
279 } 272 }
280 273
281 #pragma mark - 274 #pragma mark -
282 #pragma mark Public Methods 275 #pragma mark Public Methods
283 276
284 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { 277 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate {
285 width = std::max(width, kMinimumContainerWidth); 278 width = std::max(width, CGFloat(GetLayoutConstant(TOOLBAR_STANDARD_SPACING)));
286 NSRect newFrame = [self frame]; 279 NSRect newFrame = [self frame];
287 280
288 CGFloat maxAllowedWidth = [self maxAllowedWidth]; 281 CGFloat maxAllowedWidth = [self maxAllowedWidth];
289 width = std::min(maxAllowedWidth, width); 282 width = std::min(maxAllowedWidth, width);
290 283
291 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { 284 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) {
292 newFrame.size.width = width; 285 newFrame.size.width = width;
293 } else { 286 } else {
294 CGFloat dX = NSWidth(newFrame) - width; 287 CGFloat dX = NSWidth(newFrame) - width;
295 newFrame.size.width = width; 288 newFrame.size.width = width;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 retVal = [NSCursor resizeLeftRightCursor]; 347 retVal = [NSCursor resizeLeftRightCursor];
355 } 348 }
356 return retVal; 349 return retVal;
357 } 350 }
358 351
359 - (CGFloat)maxAllowedWidth { 352 - (CGFloat)maxAllowedWidth {
360 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; 353 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX;
361 } 354 }
362 355
363 @end 356 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698