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

Unified Diff: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm

Issue 1330423003: [Extensions Toolbar] Protect against crazy bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final nits 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index d0e834cadb8be52782e02a01e67d40a16cfaea88..80f66d87d01c993fd67b9d036ce6173f4a599970 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -583,10 +583,8 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
}
[self showChevronIfNecessaryInFrame:[containerView_ frame]];
- NSUInteger minIndex = isOverflow_ ?
- [buttons_ count] - toolbarActionsBar_->GetIconCount() : 0;
- NSUInteger maxIndex = isOverflow_ ?
- [buttons_ count] : toolbarActionsBar_->GetIconCount();
+ NSUInteger startIndex = toolbarActionsBar_->GetStartIndexInBounds();
+ NSUInteger endIndex = toolbarActionsBar_->GetEndIndexInBounds();
for (NSUInteger i = 0; i < [buttons_ count]; ++i) {
BrowserActionButton* button = [buttons_ objectAtIndex:i];
if ([button isBeingDragged])
@@ -594,7 +592,7 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
[self moveButton:[buttons_ objectAtIndex:i] toIndex:i];
- if (i >= minIndex && i < maxIndex) {
+ if (i >= startIndex && i < endIndex) {
// Make sure the button is within the visible container.
if ([button superview] != containerView_) {
// We add the subview under the sibling views so that when it
@@ -669,16 +667,23 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
- (void)updateButtonOpacity {
for (BrowserActionButton* button in buttons_.get()) {
NSRect buttonFrame = [button frameAfterAnimation];
+ // The button is fully in the container view, and should get full opacity.
if (NSContainsRect([containerView_ bounds], buttonFrame)) {
if ([button alphaValue] != 1.0)
[button setAlphaValue:1.0];
continue;
}
- CGFloat intersectionWidth =
- NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame));
- CGFloat alpha = std::max(static_cast<CGFloat>(0.0),
- intersectionWidth / NSWidth(buttonFrame));
+ // The button is only partially in the container view. If the user is
+ // resizing the container, we have partial alpha so the icon fades in as
+ // space is made. Otherwise, hide the icon fully.
+ CGFloat alpha = 0.0;
+ if ([containerView_ userIsResizing]) {
+ CGFloat intersectionWidth =
+ NSWidth(NSIntersectionRect([containerView_ bounds], buttonFrame));
+ alpha = std::max(static_cast<CGFloat>(0.0),
+ intersectionWidth / NSWidth(buttonFrame));
+ }
[button setAlphaValue:alpha];
[button setNeedsDisplay:YES];
}

Powered by Google App Engine
This is Rietveld 408576698