| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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_animate_on_state_change(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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 stroke_color, gfx::kDisabledControlAlpha); | 296 stroke_color, gfx::kDisabledControlAlpha); |
| 286 } | 297 } |
| 287 | 298 |
| 288 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 299 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
| 289 set_background(Background::CreateBackgroundPainter( | 300 set_background(Background::CreateBackgroundPainter( |
| 290 true, Painter::CreateRoundRectWith1PxBorderPainter( | 301 true, Painter::CreateRoundRectWith1PxBorderPainter( |
| 291 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 302 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
| 292 } | 303 } |
| 293 | 304 |
| 294 } // namespace views | 305 } // namespace views |
| OLD | NEW |