summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorEvan Stade <estade@chromium.org>2016-01-22 14:43:04 -0800
committerEvan Stade <estade@chromium.org>2016-01-22 22:45:08 +0000
commitdc29fb99b7b01e04385ac2f72c9b45ef7ad60155 (patch)
treeb792c1002680474f9b72b3a8db88e5518f42174e /ui
parentcb2a22db4740d64ee72121279c6d7f96dcd9af9e (diff)
downloadchromium_src-dc29fb99b7b01e04385ac2f72c9b45ef7ad60155.zip
chromium_src-dc29fb99b7b01e04385ac2f72c9b45ef7ad60155.tar.gz
chromium_src-dc29fb99b7b01e04385ac2f72c9b45ef7ad60155.tar.bz2
Don't change default dialog button when focus changes.
BUG=578722 Review URL: https://codereview.chromium.org/1607093003 Cr-Commit-Position: refs/heads/master@{#370823} (cherry picked from commit 8dbb3966210a157b9eadc8e8037cc9180aec31b9) Review URL: https://codereview.chromium.org/1620303005 . Cr-Commit-Position: refs/branch-heads/2623@{#89} Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907}
Diffstat (limited to 'ui')
-rw-r--r--ui/views/controls/button/label_button.cc5
-rw-r--r--ui/views/controls/button/label_button.h1
-rw-r--r--ui/views/controls/button/label_button_unittest.cc17
3 files changed, 23 insertions, 0 deletions
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc
index 06bbd26..978a5af 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -181,6 +181,11 @@ void LabelButton::SetIsDefault(bool is_default) {
if (style_ == STYLE_BUTTON) {
label_->SetFontList(
is_default ? cached_bold_font_list_ : cached_normal_font_list_);
+ // Usually this function is called before |this| is attached to a widget,
+ // but in the cases where |this| is already shown, we need to re-layout
+ // because font boldness affects the label's size.
+ if (GetWidget())
+ Layout();
}
}
diff --git a/ui/views/controls/button/label_button.h b/ui/views/controls/button/label_button.h
index fb4846f..2d69ac5 100644
--- a/ui/views/controls/button/label_button.h
+++ b/ui/views/controls/button/label_button.h
@@ -139,6 +139,7 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Image);
FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, LabelAndImage);
FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, FontList);
+ FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, ButtonStyleIsDefaultSize);
// View:
void ChildPreferredSizeChanged(View* child) override;
diff --git a/ui/views/controls/button/label_button_unittest.cc b/ui/views/controls/button/label_button_unittest.cc
index f0b03045..ef8f52d 100644
--- a/ui/views/controls/button/label_button_unittest.cc
+++ b/ui/views/controls/button/label_button_unittest.cc
@@ -284,4 +284,21 @@ TEST_F(LabelButtonTest, ChangeLabelImageSpacing) {
EXPECT_EQ(original_width, button_->GetPreferredSize().width());
}
+// Make sure the label gets the width it asks for and bolding it (via
+// SetDefault) causes the size to update. Regression test for crbug.com/578722
+TEST_F(LabelButtonTest, ButtonStyleIsDefaultSize) {
+ LabelButton* button = new LabelButton(nullptr, base::ASCIIToUTF16("Save"));
+ button->SetStyle(CustomButton::STYLE_BUTTON);
+ button_->GetWidget()->GetContentsView()->AddChildView(button);
+ button->SizeToPreferredSize();
+ button->Layout();
+ gfx::Size non_default_size = button->label_->size();
+ EXPECT_EQ(button->label_->GetPreferredSize().width(),
+ non_default_size.width());
+ button->SetIsDefault(true);
+ button->SizeToPreferredSize();
+ button->Layout();
+ EXPECT_NE(non_default_size, button->label_->size());
+}
+
} // namespace views