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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "ui/base/material_design/material_design_controller.h" | 9 #include "ui/base/material_design/material_design_controller.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 MdTextButton::MdTextButton(ButtonListener* listener) | 188 MdTextButton::MdTextButton(ButtonListener* listener) |
189 : LabelButton(listener, base::string16()), | 189 : LabelButton(listener, base::string16()), |
190 is_prominent_(false) { | 190 is_prominent_(false) { |
191 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON | 191 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON |
192 : InkDropMode::OFF); | 192 : InkDropMode::OFF); |
193 set_has_ink_drop_action_on_click(true); | 193 set_has_ink_drop_action_on_click(true); |
194 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 194 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
195 SetFocusForPlatform(); | 195 SetFocusForPlatform(); |
196 const int minimum_width = | 196 const int minimum_width = ViewsDelegate::GetInstance()->GetSpacingMetric( |
197 ViewsDelegate::GetInstance()->GetButtonMinimumWidth(); | 197 SpacingMetric::DIALOG_BUTTON_MINIMUM_WIDTH); |
198 SetMinSize(gfx::Size(minimum_width, 0)); | 198 SetMinSize(gfx::Size(minimum_width, 0)); |
199 SetFocusPainter(nullptr); | 199 SetFocusPainter(nullptr); |
200 label()->SetAutoColorReadabilityEnabled(false); | 200 label()->SetAutoColorReadabilityEnabled(false); |
201 set_request_focus_on_press(false); | 201 set_request_focus_on_press(false); |
202 LabelButton::SetFontList(GetMdFontList()); | 202 LabelButton::SetFontList(GetMdFontList()); |
203 | 203 |
204 set_animate_on_state_change(true); | 204 set_animate_on_state_change(true); |
205 | 205 |
206 // 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 |
207 // for fractional DSF). | 207 // for fractional DSF). |
(...skipping 25 matching lines...) Expand all Loading... |
233 int target_height = std::max(kBaseHeight + size_delta * 2, | 233 int target_height = std::max(kBaseHeight + size_delta * 2, |
234 label()->font_list().GetFontSize() * 2); | 234 label()->font_list().GetFontSize() * 2); |
235 | 235 |
236 int label_height = label()->GetPreferredSize().height(); | 236 int label_height = label()->GetPreferredSize().height(); |
237 int top_padding = (target_height - label_height) / 2; | 237 int top_padding = (target_height - label_height) / 2; |
238 int bottom_padding = (target_height - label_height + 1) / 2; | 238 int bottom_padding = (target_height - label_height + 1) / 2; |
239 DCHECK_EQ(target_height, label_height + top_padding + bottom_padding); | 239 DCHECK_EQ(target_height, label_height + top_padding + bottom_padding); |
240 | 240 |
241 // TODO(estade): can we get rid of the platform style border hoopla if | 241 // TODO(estade): can we get rid of the platform style border hoopla if |
242 // we apply the MD treatment to all buttons, even GTK buttons? | 242 // we apply the MD treatment to all buttons, even GTK buttons? |
243 const int horizontal_padding = | 243 const int horizontal_padding = ViewsDelegate::GetInstance()->GetSpacingMetric( |
244 ViewsDelegate::GetInstance()->GetButtonHorizontalPadding(); | 244 SpacingMetric::BUTTON_HORIZONTAL_PADDING); |
245 SetBorder(CreateEmptyBorder(top_padding, horizontal_padding, bottom_padding, | 245 SetBorder(CreateEmptyBorder(top_padding, horizontal_padding, bottom_padding, |
246 horizontal_padding)); | 246 horizontal_padding)); |
247 } | 247 } |
248 | 248 |
249 void MdTextButton::UpdateColors() { | 249 void MdTextButton::UpdateColors() { |
250 ui::NativeTheme::ColorId fg_color_id = | 250 ui::NativeTheme::ColorId fg_color_id = |
251 is_prominent_ ? ui::NativeTheme::kColorId_TextOnProminentButtonColor | 251 is_prominent_ ? ui::NativeTheme::kColorId_TextOnProminentButtonColor |
252 : ui::NativeTheme::kColorId_ButtonEnabledColor; | 252 : ui::NativeTheme::kColorId_ButtonEnabledColor; |
253 | 253 |
254 ui::NativeTheme* theme = GetNativeTheme(); | 254 ui::NativeTheme* theme = GetNativeTheme(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 stroke_color, gfx::kDisabledControlAlpha); | 298 stroke_color, gfx::kDisabledControlAlpha); |
299 } | 299 } |
300 | 300 |
301 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 301 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
302 set_background(Background::CreateBackgroundPainter( | 302 set_background(Background::CreateBackgroundPainter( |
303 Painter::CreateRoundRectWith1PxBorderPainter(bg_color, stroke_color, | 303 Painter::CreateRoundRectWith1PxBorderPainter(bg_color, stroke_color, |
304 kInkDropSmallCornerRadius))); | 304 kInkDropSmallCornerRadius))); |
305 } | 305 } |
306 | 306 |
307 } // namespace views | 307 } // namespace views |
OLD | NEW |