Commit f1104e55 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Remove views::Button::BUTTON_STYLE

All supporting code now assumes STYLE_TEXTBUTTON, so we no longer need
this enum or supporting code.

BUG=642920

Change-Id: I4817a8383f9e6470f2950767ea5a2f5805a5755c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636481
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664849}
parent 43a7e9dc
......@@ -574,8 +574,7 @@ std::unique_ptr<views::Border> GtkUi::CreateNativeBorder(
if (owning_button->GetNativeTheme() != native_theme_)
return std::move(border);
std::unique_ptr<views::LabelButtonAssetBorder> gtk_border(
new views::LabelButtonAssetBorder(owning_button->style()));
auto gtk_border = std::make_unique<views::LabelButtonAssetBorder>();
gtk_border->set_insets(border->GetInsets());
......
......@@ -58,14 +58,6 @@ class VIEWS_EXPORT Button : public InkDropHostView,
STATE_COUNT,
};
// Button styles with associated images and border painters.
// TODO(msw): Add Menu, ComboBox, etc.
enum ButtonStyle {
STYLE_BUTTON = 0,
STYLE_TEXTBUTTON,
STYLE_COUNT,
};
// An enum describing the events on which a button should notify its listener.
enum NotifyAction {
NOTIFY_ON_PRESS,
......
......@@ -157,26 +157,6 @@ void LabelButton::SetIsDefault(bool is_default) {
OnPropertyChanged(&is_default_, UpdateStyleToIndicateDefaultStatus());
}
void LabelButton::SetStyleDeprecated(ButtonStyle style) {
// All callers currently pass STYLE_BUTTON, and should only call this once, to
// change from the default style.
DCHECK_EQ(style, STYLE_BUTTON);
DCHECK_EQ(style_, STYLE_TEXTBUTTON);
DCHECK(!GetWidget()) << "Can't change button style after adding to a Widget.";
style_ = style;
SetFocusPainter(nullptr);
SetHorizontalAlignment(gfx::ALIGN_CENTER);
SetFocusForPlatform();
set_request_focus_on_press(true);
SetMinSize(gfx::Size(PlatformStyle::kMinLabelButtonWidth,
PlatformStyle::kMinLabelButtonHeight));
// Themed borders will be set once the button is added to a Widget, since that
// provides the value of GetNativeTheme().
}
int LabelButton::GetImageLabelSpacing() const {
return image_label_spacing_;
}
......@@ -190,11 +170,8 @@ void LabelButton::SetImageLabelSpacing(int spacing) {
}
std::unique_ptr<LabelButtonBorder> LabelButton::CreateDefaultBorder() const {
if (style_ != Button::STYLE_TEXTBUTTON)
return std::make_unique<LabelButtonAssetBorder>(style_);
auto border = std::make_unique<LabelButtonBorder>();
border->set_insets(
views::LabelButtonAssetBorder::GetDefaultInsetsForStyle(style_));
border->set_insets(views::LabelButtonAssetBorder::GetDefaultInsets());
return border;
}
......@@ -212,15 +189,6 @@ gfx::Size LabelButton::CalculatePreferredSize() const {
label.SetLineHeight(label_->line_height());
label.SetShadows(label_->shadows());
if (style_ == STYLE_BUTTON) {
// Some text appears wider when rendered normally than when rendered bold.
// Accommodate the widest, as buttons may show bold and shouldn't resize.
const int current_width = label.GetPreferredSize().width();
label.SetFontList(cached_default_button_font_list_);
if (label.GetPreferredSize().width() < current_width)
label.SetFontList(label_->font_list());
}
// Calculate the required size.
const gfx::Size preferred_label_size = label.GetPreferredSize();
gfx::Size size = GetUnclampedSizeWithoutLabel();
......@@ -432,27 +400,15 @@ void LabelButton::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
void LabelButton::ResetColorsFromNativeTheme() {
const ui::NativeTheme* theme = GetNativeTheme();
bool button_style = style() == STYLE_BUTTON;
// Button colors are used only for STYLE_BUTTON, otherwise we use label
// colors. As it turns out, these are almost always the same color anyway in
// pre-MD, although in the MD world labels and buttons get different colors.
// TODO(estade): simplify this by removing STYLE_BUTTON.
// Since this is a LabelButton, use the label colors.
SkColor colors[STATE_COUNT] = {
theme->GetSystemColor(button_style
? ui::NativeTheme::kColorId_ButtonEnabledColor
: ui::NativeTheme::kColorId_LabelEnabledColor),
theme->GetSystemColor(button_style
? ui::NativeTheme::kColorId_ButtonHoverColor
: ui::NativeTheme::kColorId_LabelEnabledColor),
theme->GetSystemColor(button_style
? ui::NativeTheme::kColorId_ButtonHoverColor
: ui::NativeTheme::kColorId_LabelEnabledColor),
theme->GetSystemColor(button_style
? ui::NativeTheme::kColorId_ButtonDisabledColor
: ui::NativeTheme::kColorId_LabelDisabledColor),
theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor),
theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor),
theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor),
theme->GetSystemColor(ui::NativeTheme::kColorId_LabelDisabledColor),
};
// Use hardcoded colors for inverted color scheme support and STYLE_BUTTON.
// Use hardcoded colors for inverted color scheme support.
if (color_utils::IsInvertedColorScheme()) {
colors[STATE_NORMAL] = colors[STATE_HOVERED] = colors[STATE_PRESSED] =
SK_ColorWHITE;
......@@ -461,8 +417,6 @@ void LabelButton::ResetColorsFromNativeTheme() {
label_->SetAutoColorReadabilityEnabled(true);
label_->SetShadows(gfx::ShadowValues());
} else {
if (style() == STYLE_BUTTON)
PlatformStyle::ApplyLabelButtonTextStyle(label_, &colors);
label_->SetBackground(nullptr);
label_->SetAutoColorReadabilityEnabled(false);
}
......
......@@ -80,12 +80,6 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
bool GetIsDefault() const;
void SetIsDefault(bool is_default);
// Gets or sets the button's overall style; the default is |STYLE_TEXTBUTTON|.
// DEPRECATED: ButtonStyle is deprecated. Use MdTextButton in place of
// |STYLE_BUTTON|.
ButtonStyle style() const { return style_; }
void SetStyleDeprecated(ButtonStyle style);
// Sets the spacing between the image and the text.
int GetImageLabelSpacing() const;
void SetImageLabelSpacing(int spacing);
......@@ -216,9 +210,6 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
// current context;
bool is_default_ = false;
// The button's overall style.
ButtonStyle style_ = STYLE_TEXTBUTTON;
// True if current border was set by UpdateThemedBorder.
bool border_is_themed_border_ = true;
......
......@@ -6,7 +6,6 @@
#include "base/logging.h"
#include "cc/paint/paint_flags.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
......@@ -23,10 +22,6 @@ namespace views {
namespace {
// Insets for the unified button images. This assumes that the images
// are of a 9 grid, of 5x5 size each.
constexpr int kButtonInsets = 5;
// The text-button hot and pushed image IDs; normal is unadorned by default.
constexpr int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER);
constexpr int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED);
......@@ -67,59 +62,21 @@ gfx::Size LabelButtonBorder::GetMinimumSize() const {
return gfx::Size();
}
LabelButtonAssetBorder::LabelButtonAssetBorder(Button::ButtonStyle style) {
set_insets(GetDefaultInsetsForStyle(style));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::Insets insets(kButtonInsets);
if (style == Button::STYLE_BUTTON) {
SetPainter(false, Button::STATE_NORMAL,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_NORMAL), insets));
SetPainter(false, Button::STATE_HOVERED,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_HOVER), insets));
SetPainter(false, Button::STATE_PRESSED,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_PRESSED), insets));
SetPainter(false, Button::STATE_DISABLED,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_DISABLED), insets));
SetPainter(true, Button::STATE_NORMAL,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_FOCUSED_NORMAL), insets));
SetPainter(true, Button::STATE_HOVERED,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_FOCUSED_HOVER), insets));
SetPainter(true, Button::STATE_PRESSED,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_FOCUSED_PRESSED), insets));
SetPainter(true, Button::STATE_DISABLED,
Painter::CreateImagePainter(
*rb.GetImageSkiaNamed(IDR_BUTTON_DISABLED), insets));
} else if (style == Button::STYLE_TEXTBUTTON) {
SetPainter(false, Button::STATE_HOVERED,
Painter::CreateImageGridPainter(kTextHoveredImages));
SetPainter(false, Button::STATE_PRESSED,
Painter::CreateImageGridPainter(kTextPressedImages));
}
LabelButtonAssetBorder::LabelButtonAssetBorder() {
set_insets(GetDefaultInsets());
SetPainter(false, Button::STATE_HOVERED,
Painter::CreateImageGridPainter(kTextHoveredImages));
SetPainter(false, Button::STATE_PRESSED,
Painter::CreateImageGridPainter(kTextPressedImages));
}
LabelButtonAssetBorder::~LabelButtonAssetBorder() = default;
// static
gfx::Insets LabelButtonAssetBorder::GetDefaultInsetsForStyle(
Button::ButtonStyle style) {
gfx::Insets insets;
if (style == Button::STYLE_BUTTON) {
insets = gfx::Insets(8, 13);
} else if (style == Button::STYLE_TEXTBUTTON) {
insets = LayoutProvider::Get()->GetInsetsMetric(
InsetsMetric::INSETS_LABEL_BUTTON);
} else {
NOTREACHED();
}
return insets;
gfx::Insets LabelButtonAssetBorder::GetDefaultInsets() {
return LayoutProvider::Get()->GetInsetsMetric(
InsetsMetric::INSETS_LABEL_BUTTON);
}
bool LabelButtonAssetBorder::PaintsButtonState(bool focused,
......
......@@ -42,11 +42,11 @@ class VIEWS_EXPORT LabelButtonBorder : public Border {
// A Border that paints a LabelButton's background frame using image assets.
class VIEWS_EXPORT LabelButtonAssetBorder : public LabelButtonBorder {
public:
explicit LabelButtonAssetBorder(Button::ButtonStyle style);
LabelButtonAssetBorder();
~LabelButtonAssetBorder() override;
// Returns the default insets for a given |style|.
static gfx::Insets GetDefaultInsetsForStyle(Button::ButtonStyle style);
// Returns the default insets.
static gfx::Insets GetDefaultInsets();
// Overridden from LabelButtonBorder:
bool PaintsButtonState(bool focused, Button::ButtonState state) override;
......
......@@ -91,9 +91,8 @@ TEST_F(LabelButtonLabelTest, Colors) {
ui::NativeTheme::kColorId_LabelEnabledColor);
EXPECT_EQ(default_theme_enabled_color, last_color_);
// Note these are not kColorId_Button{Enabled,Disabled}Color because "Button
// colors are used only for STYLE_BUTTON, otherwise we use label colors." See
// LabelButton::ResetColorsFromNativeTheme().
// Note these are not kColorId_Button{Enabled,Disabled}Color because label
// buttons use label colors. See LabelButton::ResetColorsFromNativeTheme().
theme1_.Set(ui::NativeTheme::kColorId_LabelEnabledColor, SK_ColorGREEN);
theme1_.Set(ui::NativeTheme::kColorId_LabelDisabledColor, SK_ColorYELLOW);
label_->SetNativeTheme(&theme1_);
......
......@@ -65,19 +65,6 @@ class LabelButtonTest : public test::WidgetTest {
public:
LabelButtonTest() = default;
// Adds a LabelButton to the test Widget with the STYLE_BUTTON platform style.
TestLabelButton* AddStyledButton(const char* label, bool is_default) {
TestLabelButton* button = new TestLabelButton;
button->SetText(ASCIIToUTF16(label));
button->SetStyleDeprecated(Button::STYLE_BUTTON);
if (is_default)
button->SetIsDefault(true);
button_->GetWidget()->GetContentsView()->AddChildView(button);
button->SizeToPreferredSize();
button->Layout();
return button;
}
// testing::Test:
void SetUp() override {
WidgetTest::SetUp();
......@@ -143,7 +130,6 @@ TEST_F(LabelButtonTest, Init) {
ax::mojom::StringAttribute::kName));
EXPECT_FALSE(button.GetIsDefault());
EXPECT_EQ(button.style(), Button::STYLE_TEXTBUTTON);
EXPECT_EQ(Button::STATE_NORMAL, button.state());
EXPECT_EQ(button.image()->parent(), &button);
......@@ -491,62 +477,13 @@ TEST_F(LabelButtonTest, ChangeLabelImageSpacing) {
EXPECT_EQ(original_width, button_->GetPreferredSize().width());
}
// Ensure the label gets the correct style for default buttons (e.g. bolding)
// and button size updates correctly. Regression test for crbug.com/578722.
// Disabled on Mac. The system bold font on 10.10 doesn't get wide enough to
// change the size, but we don't use styled buttons on Mac, just MdTextButton.
#if defined(OS_MACOSX)
#define MAYBE_ButtonStyleIsDefaultStyle DISABLED_ButtonStyleIsDefaultStyle
#else
#define MAYBE_ButtonStyleIsDefaultStyle ButtonStyleIsDefaultStyle
#endif
TEST_F(LabelButtonTest, MAYBE_ButtonStyleIsDefaultStyle) {
TestLabelButton* button = AddStyledButton("Save", false);
gfx::Size non_default_size = button->label()->size();
EXPECT_EQ(button->label()->GetPreferredSize().width(),
non_default_size.width());
EXPECT_EQ(button->label()->font_list().GetFontWeight(),
gfx::Font::Weight::NORMAL);
EXPECT_EQ(styled_normal_text_color_, button->label()->enabled_color());
button->SetIsDefault(true);
button->SizeToPreferredSize();
button->Layout();
EXPECT_EQ(styled_highlight_text_color_, button->label()->enabled_color());
EXPECT_NE(non_default_size, button->label()->size());
EXPECT_EQ(button->label()->font_list().GetFontWeight(),
gfx::Font::Weight::BOLD);
}
// Ensure the label gets the correct style when pressed or becoming default.
TEST_F(LabelButtonTest, HighlightedButtonStyle) {
// For STYLE_TEXTBUTTON, the NativeTheme might not provide SK_ColorBLACK, but
// it should be the same for normal and pressed states.
// The NativeTheme might not provide SK_ColorBLACK, but it should be the same
// for normal and pressed states.
EXPECT_EQ(themed_normal_text_color_, button_->label()->enabled_color());
button_->SetState(Button::STATE_PRESSED);
EXPECT_EQ(themed_normal_text_color_, button_->label()->enabled_color());
// Add a non-default button.
TestLabelButton* styled_button = AddStyledButton("OK", false);
EXPECT_EQ(styled_normal_text_color_, styled_button->label()->enabled_color());
styled_button->SetState(Button::STATE_PRESSED);
EXPECT_EQ(styled_highlight_text_color_,
styled_button->label()->enabled_color());
// If there's an explicit color set for STATE_PRESSED, that should be used.
styled_button->SetEnabledTextColors(SK_ColorRED);
EXPECT_EQ(SK_ColorRED, styled_button->label()->enabled_color());
// Test becoming default after adding to the Widget.
TestLabelButton* default_after = AddStyledButton("OK", false);
EXPECT_EQ(styled_normal_text_color_, default_after->label()->enabled_color());
default_after->SetIsDefault(true);
EXPECT_EQ(styled_highlight_text_color_,
default_after->label()->enabled_color());
// Test becoming default before adding to the Widget.
TestLabelButton* default_before = AddStyledButton("OK", true);
EXPECT_EQ(styled_highlight_text_color_,
default_before->label()->enabled_color());
}
// Ensure the label gets the correct enabled color after
......
......@@ -32,7 +32,7 @@ class VIEWS_EXPORT PlatformStyle {
// typical Cancel/OK button group.
static const bool kIsOkButtonLeading;
// Minimum size for platform-styled buttons (Button::STYLE_BUTTON).
// Minimum size for platform-styled buttons.
static const int kMinLabelButtonWidth;
static const int kMinLabelButtonHeight;
......@@ -91,8 +91,7 @@ class VIEWS_EXPORT PlatformStyle {
static std::unique_ptr<ScrollBar> CreateScrollBar(bool is_horizontal);
// Applies platform styles to |label| and fills |color_by_state| with the text
// colors for normal, pressed, hovered, and disabled states, if the colors for
// Button::STYLE_BUTTON buttons differ from those provided by ui::NativeTheme.
// colors for normal, pressed, hovered, and disabled states.
static void ApplyLabelButtonTextStyle(Label* label,
ButtonColorByState* color_by_state);
......
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