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

Fix a possible crash when displaying a small HarmonyButton.

Bug: 
Change-Id: Ia6e2432f3b735adc080327ee517f6050859ffbfc
Reviewed-on: https://chromium-review.googlesource.com/974084Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545550}
parent 8b97320b
...@@ -222,7 +222,9 @@ constexpr NSTimeInterval kTransitionDuration = 0.25; ...@@ -222,7 +222,9 @@ constexpr NSTimeInterval kTransitionDuration = 0.25;
CALayer* layer = self.layer; CALayer* layer = self.layer;
layer.shadowPath = layer.shadowPath =
base::ScopedCFTypeRef<CGPathRef>(CGPathCreateWithRoundedRect( base::ScopedCFTypeRef<CGPathRef>(CGPathCreateWithRoundedRect(
layer.bounds, layer.cornerRadius, layer.cornerRadius, nullptr)); layer.bounds,
MIN(layer.cornerRadius, CGRectGetWidth(layer.bounds) / 2),
MIN(layer.cornerRadius, CGRectGetHeight(layer.bounds) / 2), nullptr));
[self updateHoverButtonAppearanceAnimated:NO]; [self updateHoverButtonAppearanceAnimated:NO];
self.title = self.title; // Match the theme. self.title = self.title; // Match the theme.
[super layout]; [super layout];
......
...@@ -24,6 +24,17 @@ class HarmonyButtonTest : public ui::CocoaTest { ...@@ -24,6 +24,17 @@ class HarmonyButtonTest : public ui::CocoaTest {
TEST_VIEW(HarmonyButtonTest, button_) TEST_VIEW(HarmonyButtonTest, button_)
// Verify that displaying a button that's smaller than double the corner radius
// doesn't crash. (CGPathCreateWithRoundedRect throws an exception if you pass
// it a radius that's too big).
TEST_F(HarmonyButtonTest, TooSmall) {
CGFloat cornerRadius = button_.layer.cornerRadius;
EXPECT_LT(0, cornerRadius);
[button_ setFrameSize:NSMakeSize(cornerRadius, cornerRadius)];
[button_ layoutSubtreeIfNeeded];
[button_ displayIfNeeded];
}
TEST(HarmonyButtonTestMore, NSViewRespondsToClipsToBounds) { TEST(HarmonyButtonTestMore, NSViewRespondsToClipsToBounds) {
// HarmonyButton implements an undocumented method to avoid having its shadow // HarmonyButton implements an undocumented method to avoid having its shadow
// clipped, so verify that it hasn't disappeared. // clipped, so verify that it hasn't disappeared.
......
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