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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 LabelButton::SetFontList(GetMdFontList()); | 204 LabelButton::SetFontList(GetMdFontList()); |
203 | 205 |
204 set_animate_on_state_change(true); | 206 set_animate_on_state_change(true); |
205 | 207 |
206 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful | 208 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful |
207 // for fractional DSF). | 209 // for fractional DSF). |
208 SetPaintToLayer(true); | 210 SetPaintToLayer(true); |
209 layer()->SetFillsBoundsOpaquely(false); | 211 layer()->SetFillsBoundsOpaquely(false); |
210 } | 212 } |
211 | 213 |
212 MdTextButton::~MdTextButton() {} | |
213 | |
214 void MdTextButton::UpdatePadding() { | 214 void MdTextButton::UpdatePadding() { |
215 // 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. |
216 if (GetText().empty()) { | 216 if (GetText().empty()) { |
217 SetBorder(Border::NullBorder()); | 217 SetBorder(Border::NullBorder()); |
218 return; | 218 return; |
219 } | 219 } |
220 | 220 |
221 // Text buttons default to 28dp in height on all platforms when the base font | 221 // Text buttons default to 28dp in height on all platforms when the base font |
222 // is in use, but should grow or shrink if the font size is adjusted up or | 222 // is in use, but should grow or shrink if the font size is adjusted up or |
223 // down. When the system font size has been adjusted, the base font will be | 223 // down. When the system font size has been adjusted, the base font will be |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 stroke_color, gfx::kDisabledControlAlpha); | 296 stroke_color, gfx::kDisabledControlAlpha); |
297 } | 297 } |
298 | 298 |
299 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 299 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
300 set_background(Background::CreateBackgroundPainter( | 300 set_background(Background::CreateBackgroundPainter( |
301 true, Painter::CreateRoundRectWith1PxBorderPainter( | 301 true, Painter::CreateRoundRectWith1PxBorderPainter( |
302 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 302 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
303 } | 303 } |
304 | 304 |
305 } // namespace views | 305 } // namespace views |
OLD | NEW |