1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_MD_TEXT_BUTTON_H_ 6 #define UI_VIEWS_CONTROLS_BUTTON_MD_TEXT_BUTTON_H_ 7 8 #include <memory> 9 10 #include "base/optional.h" 11 #include "ui/views/controls/button/label_button.h" 12 #include "ui/views/controls/focus_ring.h" 13 #include "ui/views/style/typography.h" 14 15 namespace views { 16 17 // A button class that implements the Material Design text button spec. 18 class VIEWS_EXPORT MdTextButton : public LabelButton { 19 public: 20 METADATA_HEADER(MdTextButton); 21 22 explicit MdTextButton(PressedCallback callback = PressedCallback(), 23 const base::string16& text = base::string16(), 24 int button_context = style::CONTEXT_BUTTON_MD); 25 ~MdTextButton() override; 26 27 // See |is_prominent_|. 28 void SetProminent(bool is_prominent); 29 bool GetProminent() const; 30 31 // See |bg_color_override_|. 32 void SetBgColorOverride(const base::Optional<SkColor>& color); 33 base::Optional<SkColor> GetBgColorOverride() const; 34 35 // Override the default corner radius of the round rect used for the 36 // background and ink drop effects. 37 void SetCornerRadius(float radius); 38 float GetCornerRadius() const; 39 40 // See |custom_padding_|. 41 void SetCustomPadding(const base::Optional<gfx::Insets>& padding); 42 base::Optional<gfx::Insets> GetCustomPadding() const; 43 44 // LabelButton: 45 void OnThemeChanged() override; 46 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() 47 const override; 48 SkColor GetInkDropBaseColor() const override; 49 void SetEnabledTextColors(base::Optional<SkColor> color) override; 50 void SetText(const base::string16& text) override; 51 PropertyEffects UpdateStyleToIndicateDefaultStatus() override; 52 void StateChanged(ButtonState old_state) override; 53 54 protected: 55 // View: 56 void OnFocus() override; 57 void OnBlur() override; 58 59 private: 60 void UpdatePadding(); 61 gfx::Insets CalculateDefaultPadding() const; 62 63 void UpdateTextColor(); 64 void UpdateBackgroundColor() override; 65 void UpdateColors(); 66 67 // True if this button uses prominent styling (blue fill, etc.). 68 bool is_prominent_ = false; 69 70 // When set, this provides the background color. 71 base::Optional<SkColor> bg_color_override_; 72 73 float corner_radius_ = 0.0f; 74 75 // Used to override default padding. 76 base::Optional<gfx::Insets> custom_padding_; 77 78 DISALLOW_COPY_AND_ASSIGN(MdTextButton); 79 }; 80 81 BEGIN_VIEW_BUILDER(VIEWS_EXPORT, MdTextButton, LabelButton) 82 VIEW_BUILDER_PROPERTY(bool, Prominent) 83 VIEW_BUILDER_PROPERTY(base::Optional<SkColor>, BgColorOverride) 84 VIEW_BUILDER_PROPERTY(float, CornerRadius) 85 VIEW_BUILDER_PROPERTY(base::Optional<gfx::Insets>, CustomPadding) 86 END_VIEW_BUILDER 87 88 } // namespace views 89 90 DEFINE_VIEW_BUILDER(VIEWS_EXPORT, MdTextButton) 91 92 #endif // UI_VIEWS_CONTROLS_BUTTON_MD_TEXT_BUTTON_H_ 93