Commit 68c11e3d authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Fix a hang on 10.11 caused by -[MDHoverButton layout] making itself need layout.

Updating self.image (on an NSButton subclass) in -layout or -viewWillDraw both
seem to lead to an infinite loop in 10.11. I'm not sure if there's a better way
to fix this; using different triggers to update the image seems safest.

Bug: 805109
Change-Id: I468576069f44eae4a2f4b9058e078d88d157265a
Reviewed-on: https://chromium-review.googlesource.com/899586Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534137}
parent bc5e6d23
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "ui/base/cocoa/hover_button.h" #import "ui/base/cocoa/hover_button.h"
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
// MDHoverButton has a gray background with rounded corners. The background is // MDHoverButton has a gray background with rounded corners. The background is
// only visible on hover and gets darker on click. It's friendly to subviews. // only visible on hover and gets darker on click. It's friendly to subviews.
@interface MDHoverButton : HoverButton @interface MDHoverButton : HoverButton<ThemedWindowDrawing>
// An icon that's displayed in the middle of the button. // An icon that's displayed in the middle of the button.
@property(nonatomic) const gfx::VectorIcon* icon; @property(nonatomic) const gfx::VectorIcon* icon;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "ui/base/cocoa/nsview_additions.h" #import "ui/base/cocoa/nsview_additions.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
...@@ -49,12 +48,12 @@ NSColor* GetActiveColor(BOOL dark_theme) { ...@@ -49,12 +48,12 @@ NSColor* GetActiveColor(BOOL dark_theme) {
- (void)setIcon:(const gfx::VectorIcon*)icon { - (void)setIcon:(const gfx::VectorIcon*)icon {
icon_ = icon; icon_ = icon;
self.needsLayout = YES; [self updateIcon];
} }
- (void)setIconSize:(int)iconSize { - (void)setIconSize:(int)iconSize {
iconSize_ = iconSize; iconSize_ = iconSize;
self.needsLayout = YES; [self updateIcon];
} }
- (void)setHoverSuppressed:(BOOL)hoverSuppressed { - (void)setHoverSuppressed:(BOOL)hoverSuppressed {
...@@ -71,6 +70,15 @@ NSColor* GetActiveColor(BOOL dark_theme) { ...@@ -71,6 +70,15 @@ NSColor* GetActiveColor(BOOL dark_theme) {
provider->ShouldIncreaseContrast() ? 0xFF : kIconAlpha); provider->ShouldIncreaseContrast() ? 0xFF : kIconAlpha);
} }
- (void)updateIcon {
if (!icon_ || icon_->is_empty() || iconSize_ == 0) {
self.image = nil;
return;
}
self.image = NSImageFromImageSkia(
gfx::CreateVectorIcon(*icon_, iconSize_, [self iconColor]));
}
- (void)updateHoverButtonAppearanceAnimated:(BOOL)animated { - (void)updateHoverButtonAppearanceAnimated:(BOOL)animated {
const BOOL darkTheme = [[self window] hasDarkTheme]; const BOOL darkTheme = [[self window] hasDarkTheme];
const CGColorRef targetBackgroundColor = [&]() -> CGColorRef { const CGColorRef targetBackgroundColor = [&]() -> CGColorRef {
...@@ -116,16 +124,6 @@ NSColor* GetActiveColor(BOOL dark_theme) { ...@@ -116,16 +124,6 @@ NSColor* GetActiveColor(BOOL dark_theme) {
// NSView overrides. // NSView overrides.
- (void)layout {
if (!icon_ || icon_->is_empty() || iconSize_ == 0) {
self.image = nil;
return;
}
self.image = NSImageFromImageSkia(
gfx::CreateVectorIcon(*icon_, iconSize_, [self iconColor]));
[super layout];
}
- (void)drawFocusRingMask { - (void)drawFocusRingMask {
CGFloat radius = self.layer.cornerRadius; CGFloat radius = self.layer.cornerRadius;
[[NSBezierPath bezierPathWithRoundedRect:self.bounds [[NSBezierPath bezierPathWithRoundedRect:self.bounds
...@@ -133,4 +131,18 @@ NSColor* GetActiveColor(BOOL dark_theme) { ...@@ -133,4 +131,18 @@ NSColor* GetActiveColor(BOOL dark_theme) {
yRadius:radius] fill]; yRadius:radius] fill];
} }
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
[self updateIcon];
}
// ThemedWindowDrawing implementation
- (void)windowDidChangeTheme {
[self updateIcon];
}
- (void)windowDidChangeActive {
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment