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

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

Issue 2406323002: CustomButton: restrict animation repaints to buttons that actually animate (Closed)
Patch Set: don't use bool(T*) 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
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/examples/button_example.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a29530c6346759ebdfb1c752249d87382b2abb32..6b914ac5dbaa6f56bc2b0a869b85f1e53fb10548 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_animate_on_state_change(true);
+
// Paint to a layer so that the canvas is snapped to pixel boundaries (useful
// for fractional DSF).
SetPaintToLayer(true);
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/examples/button_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698