Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1171)

Unified Diff: ui/views/controls/button/md_text_button.cc

Issue 2406323002: CustomButton: restrict animation repaints to buttons that actually animate (Closed)
Patch Set: CustomButton: restrict animation repaints to buttons that actually animate Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/md_text_button.cc
diff --git a/ui/views/controls/button/md_text_button.cc b/ui/views/controls/button/md_text_button.cc
index 9b3d05986a6469e9d7ec436c6575f13065149d8d..d1b6f9559a8533de11c403020a4885eb88131a85 100644
--- a/ui/views/controls/button/md_text_button.cc
+++ b/ui/views/controls/button/md_text_button.cc
@@ -91,6 +91,15 @@ void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) {
UpdateColors();
}
+void MdTextButton::OnPaintBackground(gfx::Canvas* canvas) {
+ LabelButton::OnPaintBackground(canvas);
+ if (hover_animation().is_animating() || state() == STATE_HOVERED) {
+ const int kHoverAlpha = is_prominent_ ? 0x0c : 0x05;
+ SkScalar alpha = hover_animation().CurrentValueBetween(0, kHoverAlpha);
+ canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorBLACK, alpha));
+ }
+}
+
void MdTextButton::OnFocus() {
LabelButton::OnFocus();
FocusRing::Install(this);
@@ -192,6 +201,8 @@ MdTextButton::MdTextButton(ButtonListener* listener)
set_request_focus_on_press(false);
LabelButton::SetFontList(GetMdFontList());
+ set_animates_hover(true);
+
// Paint to a layer so that the canvas is snapped to pixel boundaries (useful
// for fractional DSF).
SetPaintToLayer(true);

Powered by Google App Engine
This is Rietveld 408576698