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_utils.h" | 10 #include "ui/gfx/color_utils.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 void MdTextButton::UpdateColors() { | 286 void MdTextButton::UpdateColors() { |
287 ui::NativeTheme::ColorId fg_color_id = | 287 ui::NativeTheme::ColorId fg_color_id = |
288 is_cta_ ? ui::NativeTheme::kColorId_TextOnCallToActionColor | 288 is_cta_ ? ui::NativeTheme::kColorId_TextOnCallToActionColor |
289 : ui::NativeTheme::kColorId_ButtonEnabledColor; | 289 : ui::NativeTheme::kColorId_ButtonEnabledColor; |
290 | 290 |
291 ui::NativeTheme* theme = GetNativeTheme(); | 291 ui::NativeTheme* theme = GetNativeTheme(); |
292 if (!explicitly_set_normal_color()) | 292 if (!explicitly_set_normal_color()) |
293 LabelButton::SetEnabledTextColors(theme->GetSystemColor(fg_color_id)); | 293 LabelButton::SetEnabledTextColors(theme->GetSystemColor(fg_color_id)); |
294 | 294 |
| 295 // CTA buttons keep their enabled text color; disabled state is conveyed by |
| 296 // shading the background instead. |
| 297 if (is_cta_) |
| 298 SetTextColor(STATE_DISABLED, theme->GetSystemColor(fg_color_id)); |
| 299 |
295 SkColor text_color = label()->enabled_color(); | 300 SkColor text_color = label()->enabled_color(); |
296 SkColor bg_color = | 301 SkColor bg_color = |
297 bg_color_override_ | 302 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
298 ? *bg_color_override_ | |
299 : is_cta_ | |
300 ? theme->GetSystemColor( | |
301 ui::NativeTheme::kColorId_CallToActionColor) | |
302 : is_default() | |
303 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) | |
304 : theme->GetSystemColor( | |
305 ui::NativeTheme::kColorId_DialogBackground); | |
306 | 303 |
| 304 if (bg_color_override_) { |
| 305 bg_color = *bg_color_override_; |
| 306 } else if (is_cta_) { |
| 307 bg_color = theme->GetSystemColor( |
| 308 ui::NativeTheme::kColorId_CallToActionColor); |
| 309 if (state() == STATE_DISABLED) |
| 310 bg_color = color_utils::BlendTowardOppositeLuma(bg_color, 0x61); |
| 311 } else if (is_default()) { |
| 312 bg_color = color_utils::BlendTowardOppositeLuma(text_color, 0xD8); |
| 313 } |
| 314 |
| 315 // TODO(ellyjones): Excise this, in favor of a helper function wrapping |
| 316 // |color_utils::AlphaBlend| and a new NativeTheme color constant. |
307 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); | 317 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); |
308 | 318 |
309 const SkAlpha kStrokeOpacity = 0x1A; | 319 const SkAlpha kStrokeOpacity = 0x1A; |
310 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) | 320 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) |
311 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) | 321 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) |
312 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); | 322 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); |
313 | 323 |
314 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 324 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
315 set_background(Background::CreateBackgroundPainter( | 325 set_background(Background::CreateBackgroundPainter( |
316 true, Painter::CreateRoundRectWith1PxBorderPainter( | 326 true, Painter::CreateRoundRectWith1PxBorderPainter( |
317 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 327 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
318 } | 328 } |
319 | 329 |
320 } // namespace views | 330 } // namespace views |
OLD | NEW |