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

Side by Side Diff: chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm

Issue 1330423003: [Extensions Toolbar] Protect against crazy bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Peter's Created 5 years, 3 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/wrench_menu/wrench_menu_controller.h" 5 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/mac/bundle_locations.h" 8 #include "base/mac/bundle_locations.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/user_metrics.h" 31 #include "content/public/browser/user_metrics.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/models/menu_model.h" 33 #include "ui/base/models/menu_model.h"
34 #include "ui/gfx/geometry/size.h" 34 #include "ui/gfx/geometry/size.h"
35 35
36 namespace { 36 namespace {
37 // Padding amounts on the left/right of a custom menu item (like the browser 37 // Padding amounts on the left/right of a custom menu item (like the browser
38 // actions overflow container). 38 // actions overflow container).
39 const int kLeftPadding = 16; 39 const int kLeftPadding = 16;
40 const int kRightPadding = 10; 40 const int kRightPadding = 10;
41
42 // In *very* extreme cases, it's possible that there are so many overflowed
43 // actions, we won't be able to show them all. Cap the height so that the
44 // overflow won't make the menu larger than the height of the screen.
45 // Note: With this height, we can show 104 actions. Less than 0.0002% of our
46 // users will be affected.
47 const int kMaxOverflowContainerHeight = 416;
41 } 48 }
42 49
43 namespace wrench_menu_controller { 50 namespace wrench_menu_controller {
44 const CGFloat kWrenchBubblePointOffsetY = 6; 51 const CGFloat kWrenchBubblePointOffsetY = 6;
45 } 52 }
46 53
47 using base::UserMetricsAction; 54 using base::UserMetricsAction;
48 55
49 @interface WrenchMenuController (Private) 56 @interface WrenchMenuController (Private)
50 - (void)createModel; 57 - (void)createModel;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 [[self menu] setMinimumWidth:menuWidth]; 278 [[self menu] setMinimumWidth:menuWidth];
272 gfx::Size preferredContainerSize = 279 gfx::Size preferredContainerSize =
273 [browserActionsController_ sizeForOverflowWidth:maxContainerWidth]; 280 [browserActionsController_ sizeForOverflowWidth:maxContainerWidth];
274 281
275 // Set the origins and preferred size for the container. 282 // Set the origins and preferred size for the container.
276 // View hierarchy is as follows (from parent > child): 283 // View hierarchy is as follows (from parent > child):
277 // |view| > |anonymous view| > containerView. We have to set the origin 284 // |view| > |anonymous view| > containerView. We have to set the origin
278 // and size of each for it display properly. 285 // and size of each for it display properly.
279 // The parent views each have a size of the full width of the menu, so we can 286 // The parent views each have a size of the full width of the menu, so we can
280 // properly position the container. 287 // properly position the container.
281 NSSize parentSize = NSMakeSize(menuWidth, preferredContainerSize.height()); 288 NSSize parentSize = NSMakeSize(menuWidth,
289 std::min(preferredContainerSize.height(),
290 kMaxOverflowContainerHeight));
282 [view setFrameSize:parentSize]; 291 [view setFrameSize:parentSize];
283 [[containerView superview] setFrameSize:parentSize]; 292 [[containerView superview] setFrameSize:parentSize];
284 293
285 // The container view gets its preferred size. 294 // The container view gets its preferred size.
286 [containerView setFrameSize:NSMakeSize(preferredContainerSize.width(), 295 [containerView setFrameSize:NSMakeSize(preferredContainerSize.width(),
287 preferredContainerSize.height())]; 296 preferredContainerSize.height())];
288 [browserActionsController_ update]; 297 [browserActionsController_ update];
289 298
290 [view setFrameOrigin:NSZeroPoint]; 299 [view setFrameOrigin:NSZeroPoint];
291 [[containerView superview] setFrameOrigin:NSZeroPoint]; 300 [[containerView superview] setFrameOrigin:NSZeroPoint];
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // (and thus, after all our ability to adjust it normally). Throw in the 558 // (and thus, after all our ability to adjust it normally). Throw in the
550 // towel, and simply don't let the frame move from where it's supposed to be. 559 // towel, and simply don't let the frame move from where it's supposed to be.
551 // TODO(devlin): Yet another Cocoa hack. It'd be good to find a workaround, 560 // TODO(devlin): Yet another Cocoa hack. It'd be good to find a workaround,
552 // but unlikely unless we replace the Cocoa menu implementation. 561 // but unlikely unless we replace the Cocoa menu implementation.
553 NSView* containerSuperview = [overflowActionsContainerView_ superview]; 562 NSView* containerSuperview = [overflowActionsContainerView_ superview];
554 if (NSMinX([containerSuperview frame]) != 0) 563 if (NSMinX([containerSuperview frame]) != 0)
555 [containerSuperview setFrameOrigin:NSZeroPoint]; 564 [containerSuperview setFrameOrigin:NSZeroPoint];
556 } 565 }
557 566
558 @end // @implementation WrenchMenuButtonViewController 567 @end // @implementation WrenchMenuButtonViewController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698