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

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

Issue 2315233002: views: support disabled color for CTA buttons (Closed)
Patch Set: get rid of CallToActionDisabled 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_) {
296 ui::NativeTheme::kColorId_CallToActionColor) 301 bg_color = theme->GetSystemColor(
297 : is_default() 302 ui::NativeTheme::kColorId_CallToActionColor);
298 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) 303 if (state() == STATE_DISABLED)
299 : SK_ColorTRANSPARENT; 304 bg_color = SkColorSetA(bg_color, 0x61);
Evan Stade 2016/09/07 17:14:33 I know it's expressed as an alpha value in the spe
Elly Fong-Jones 2016/09/07 18:01:45 Done.
305 } else if (is_default()) {
306 bg_color = color_utils::BlendTowardOppositeLuma(text_color, 0xD8);
307 }
300 308
301 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); 309 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state());
Evan Stade 2016/09/07 17:14:33 can we make it a todo to get rid of this? Color lo
Elly Fong-Jones 2016/09/07 17:43:50 Hm - I like this idea, but what would color_utils:
Elly Fong-Jones 2016/09/07 18:01:45 I ended up adding a TODO for this.
302 310
303 const SkAlpha kStrokeOpacity = 0x1A; 311 const SkAlpha kStrokeOpacity = 0x1A;
304 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) 312 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color))
305 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) 313 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity)
306 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); 314 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity);
307 315
308 set_background(Background::CreateBackgroundPainter( 316 set_background(Background::CreateBackgroundPainter(
309 true, Painter::CreateRoundRectWith1PxBorderPainter( 317 true, Painter::CreateRoundRectWith1PxBorderPainter(
310 bg_color, stroke_color, kInkDropSmallCornerRadius))); 318 bg_color, stroke_color, kInkDropSmallCornerRadius)));
311 } 319 }
312 320
313 } // namespace views 321 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698