Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: ui/views/controls/button/md_text_button.cc

Issue 2315233002: views: support disabled color for CTA buttons (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 280
281 void MdTextButton::UpdateColors() { 281 void MdTextButton::UpdateColors() {
282 ui::NativeTheme::ColorId fg_color_id = 282 ui::NativeTheme::ColorId fg_color_id =
283 is_cta_ ? ui::NativeTheme::kColorId_TextOnCallToActionColor 283 is_cta_ ? ui::NativeTheme::kColorId_TextOnCallToActionColor
284 : ui::NativeTheme::kColorId_ButtonEnabledColor; 284 : ui::NativeTheme::kColorId_ButtonEnabledColor;
285 285
286 ui::NativeTheme* theme = GetNativeTheme(); 286 ui::NativeTheme* theme = GetNativeTheme();
287 if (!explicitly_set_normal_color()) 287 if (!explicitly_set_normal_color())
288 LabelButton::SetEnabledTextColors(theme->GetSystemColor(fg_color_id)); 288 LabelButton::SetEnabledTextColors(theme->GetSystemColor(fg_color_id));
289 289
290 // CTA buttons keep their enabled text color; disabled state is conveyed by
291 // shading the background instead.
292 if (is_cta_)
293 SetTextColor(STATE_DISABLED, theme->GetSystemColor(fg_color_id));
294
290 SkColor text_color = label()->enabled_color(); 295 SkColor text_color = label()->enabled_color();
291 SkColor bg_color = 296 SkColor bg_color = SK_ColorTRANSPARENT;
292 bg_color_override_ 297
293 ? *bg_color_override_ 298 if (bg_color_override_) {
294 : is_cta_ 299 bg_color = *bg_color_override_;
295 ? theme->GetSystemColor( 300 } else if (is_cta_ && state() == STATE_DISABLED) {
296 ui::NativeTheme::kColorId_CallToActionColor) 301 bg_color = theme->GetSystemColor(
297 : is_default() 302 ui::NativeTheme::kColorId_CallToActionDisabledColor);
298 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) 303 } else if (is_cta_) {
299 : SK_ColorTRANSPARENT; 304 bg_color = theme->GetSystemColor(
305 ui::NativeTheme::kColorId_CallToActionColor);
306 } else if (is_default()) {
307 bg_color = color_utils::BlendTowardOppositeLuma(text_color, 0xD8);
308 }
300 309
301 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); 310 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state());
302 311
303 const SkAlpha kStrokeOpacity = 0x1A; 312 const SkAlpha kStrokeOpacity = 0x1A;
304 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) 313 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color))
305 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) 314 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity)
306 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); 315 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity);
307 316
308 set_background(Background::CreateBackgroundPainter( 317 set_background(Background::CreateBackgroundPainter(
309 true, Painter::CreateRoundRectWith1PxBorderPainter( 318 true, Painter::CreateRoundRectWith1PxBorderPainter(
310 bg_color, stroke_color, kInkDropSmallCornerRadius))); 319 bg_color, stroke_color, kInkDropSmallCornerRadius)));
311 } 320 }
312 321
313 } // namespace views 322 } // namespace views
OLDNEW
« ui/native_theme/native_theme_dark_aura.cc ('K') | « ui/native_theme/native_theme_dark_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698