| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // static | 72 // static |
| 73 MdTextButton* MdTextButton::Create(ButtonListener* listener, | 73 MdTextButton* MdTextButton::Create(ButtonListener* listener, |
| 74 const base::string16& text) { | 74 const base::string16& text) { |
| 75 MdTextButton* button = new MdTextButton(listener); | 75 MdTextButton* button = new MdTextButton(listener); |
| 76 button->SetText(text); | 76 button->SetText(text); |
| 77 button->SetFocusForPlatform(); | 77 button->SetFocusForPlatform(); |
| 78 return button; | 78 return button; |
| 79 } | 79 } |
| 80 | 80 |
| 81 MdTextButton::~MdTextButton() {} |
| 82 |
| 81 void MdTextButton::SetProminent(bool is_prominent) { | 83 void MdTextButton::SetProminent(bool is_prominent) { |
| 82 if (is_prominent_ == is_prominent) | 84 if (is_prominent_ == is_prominent) |
| 83 return; | 85 return; |
| 84 | 86 |
| 85 is_prominent_ = is_prominent; | 87 is_prominent_ = is_prominent; |
| 86 UpdateColors(); | 88 UpdateColors(); |
| 87 } | 89 } |
| 88 | 90 |
| 89 void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) { | 91 void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) { |
| 90 bg_color_override_ = color; | 92 bg_color_override_ = color; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 label()->SetAutoColorReadabilityEnabled(false); | 193 label()->SetAutoColorReadabilityEnabled(false); |
| 192 set_request_focus_on_press(false); | 194 set_request_focus_on_press(false); |
| 193 LabelButton::SetFontList(GetMdFontList()); | 195 LabelButton::SetFontList(GetMdFontList()); |
| 194 | 196 |
| 195 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful | 197 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful |
| 196 // for fractional DSF). | 198 // for fractional DSF). |
| 197 SetPaintToLayer(true); | 199 SetPaintToLayer(true); |
| 198 layer()->SetFillsBoundsOpaquely(false); | 200 layer()->SetFillsBoundsOpaquely(false); |
| 199 } | 201 } |
| 200 | 202 |
| 201 MdTextButton::~MdTextButton() {} | |
| 202 | |
| 203 void MdTextButton::UpdatePadding() { | 203 void MdTextButton::UpdatePadding() { |
| 204 // Don't use font-based padding when there's no text visible. | 204 // Don't use font-based padding when there's no text visible. |
| 205 if (GetText().empty()) { | 205 if (GetText().empty()) { |
| 206 SetBorder(Border::NullBorder()); | 206 SetBorder(Border::NullBorder()); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Text buttons default to 28dp in height on all platforms when the base font | 210 // Text buttons default to 28dp in height on all platforms when the base font |
| 211 // is in use, but should grow or shrink if the font size is adjusted up or | 211 // is in use, but should grow or shrink if the font size is adjusted up or |
| 212 // down. When the system font size has been adjusted, the base font will be | 212 // down. When the system font size has been adjusted, the base font will be |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 SkColor stroke_color = | 273 SkColor stroke_color = |
| 274 is_prominent_ ? SK_ColorTRANSPARENT : SkColorSetA(text_color, 0x33); | 274 is_prominent_ ? SK_ColorTRANSPARENT : SkColorSetA(text_color, 0x33); |
| 275 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 275 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
| 276 set_background(Background::CreateBackgroundPainter( | 276 set_background(Background::CreateBackgroundPainter( |
| 277 true, Painter::CreateRoundRectWith1PxBorderPainter( | 277 true, Painter::CreateRoundRectWith1PxBorderPainter( |
| 278 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 278 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
| 279 } | 279 } |
| 280 | 280 |
| 281 } // namespace views | 281 } // namespace views |
| OLD | NEW |