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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/button/md_text_button.h" 5 #include "ui/views/controls/button/md_text_button.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "ui/base/material_design/material_design_controller.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 is_prominent_ = is_prominent; 85 is_prominent_ = is_prominent;
86 UpdateColors(); 86 UpdateColors();
87 } 87 }
88 88
89 void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) { 89 void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) {
90 bg_color_override_ = color; 90 bg_color_override_ = color;
91 UpdateColors(); 91 UpdateColors();
92 } 92 }
93 93
94 void MdTextButton::OnPaintBackground(gfx::Canvas* canvas) {
95 LabelButton::OnPaintBackground(canvas);
96 if (hover_animation().is_animating() || state() == STATE_HOVERED) {
97 const int kHoverAlpha = is_prominent_ ? 0x0c : 0x05;
98 SkScalar alpha = hover_animation().CurrentValueBetween(0, kHoverAlpha);
99 canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorBLACK, alpha));
100 }
101 }
102
94 void MdTextButton::OnFocus() { 103 void MdTextButton::OnFocus() {
95 LabelButton::OnFocus(); 104 LabelButton::OnFocus();
96 FocusRing::Install(this); 105 FocusRing::Install(this);
97 } 106 }
98 107
99 void MdTextButton::OnBlur() { 108 void MdTextButton::OnBlur() {
100 LabelButton::OnBlur(); 109 LabelButton::OnBlur();
101 FocusRing::Uninstall(this); 110 FocusRing::Uninstall(this);
102 } 111 }
103 112
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 : InkDropMode::OFF); 194 : InkDropMode::OFF);
186 set_has_ink_drop_action_on_click(true); 195 set_has_ink_drop_action_on_click(true);
187 SetHorizontalAlignment(gfx::ALIGN_CENTER); 196 SetHorizontalAlignment(gfx::ALIGN_CENTER);
188 SetFocusForPlatform(); 197 SetFocusForPlatform();
189 SetMinSize(gfx::Size(kMinWidth, 0)); 198 SetMinSize(gfx::Size(kMinWidth, 0));
190 SetFocusPainter(nullptr); 199 SetFocusPainter(nullptr);
191 label()->SetAutoColorReadabilityEnabled(false); 200 label()->SetAutoColorReadabilityEnabled(false);
192 set_request_focus_on_press(false); 201 set_request_focus_on_press(false);
193 LabelButton::SetFontList(GetMdFontList()); 202 LabelButton::SetFontList(GetMdFontList());
194 203
204 set_animates_hover(true);
205
195 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful 206 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful
196 // for fractional DSF). 207 // for fractional DSF).
197 SetPaintToLayer(true); 208 SetPaintToLayer(true);
198 layer()->SetFillsBoundsOpaquely(false); 209 layer()->SetFillsBoundsOpaquely(false);
199 } 210 }
200 211
201 MdTextButton::~MdTextButton() {} 212 MdTextButton::~MdTextButton() {}
202 213
203 void MdTextButton::UpdatePadding() { 214 void MdTextButton::UpdatePadding() {
204 // Don't use font-based padding when there's no text visible. 215 // Don't use font-based padding when there's no text visible.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 283
273 SkColor stroke_color = 284 SkColor stroke_color =
274 is_prominent_ ? SK_ColorTRANSPARENT : SkColorSetA(text_color, 0x33); 285 is_prominent_ ? SK_ColorTRANSPARENT : SkColorSetA(text_color, 0x33);
275 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); 286 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color)));
276 set_background(Background::CreateBackgroundPainter( 287 set_background(Background::CreateBackgroundPainter(
277 true, Painter::CreateRoundRectWith1PxBorderPainter( 288 true, Painter::CreateRoundRectWith1PxBorderPainter(
278 bg_color, stroke_color, kInkDropSmallCornerRadius))); 289 bg_color, stroke_color, kInkDropSmallCornerRadius)));
279 } 290 }
280 291
281 } // namespace views 292 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698