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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 void MdTextButton::SetProminent(bool is_prominent) { | 81 void MdTextButton::SetProminent(bool is_prominent) { |
82 if (is_prominent_ == is_prominent) | 82 if (is_prominent_ == is_prominent) |
83 return; | 83 return; |
84 | 84 |
85 is_prominent_ = is_prominent; | 85 is_prominent_ = is_prominent; |
86 UpdateColors(); | 86 UpdateColors(); |
87 } | 87 } |
88 | 88 |
| 89 void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) { |
| 90 bg_color_override_ = color; |
| 91 UpdateColors(); |
| 92 } |
| 93 |
89 void MdTextButton::OnFocus() { | 94 void MdTextButton::OnFocus() { |
90 LabelButton::OnFocus(); | 95 LabelButton::OnFocus(); |
91 FocusRing::Install(this); | 96 FocusRing::Install(this); |
92 } | 97 } |
93 | 98 |
94 void MdTextButton::OnBlur() { | 99 void MdTextButton::OnBlur() { |
95 LabelButton::OnBlur(); | 100 LabelButton::OnBlur(); |
96 FocusRing::Uninstall(this); | 101 FocusRing::Uninstall(this); |
97 } | 102 } |
98 | 103 |
(...skipping 16 matching lines...) Expand all Loading... |
115 | 120 |
116 void MdTextButton::StateChanged() { | 121 void MdTextButton::StateChanged() { |
117 LabelButton::StateChanged(); | 122 LabelButton::StateChanged(); |
118 UpdateColors(); | 123 UpdateColors(); |
119 } | 124 } |
120 | 125 |
121 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() | 126 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() |
122 const { | 127 const { |
123 if (!ShouldShowInkDropHighlight()) | 128 if (!ShouldShowInkDropHighlight()) |
124 return nullptr; | 129 return nullptr; |
125 if (!is_prominent_) | |
126 return LabelButton::CreateInkDropHighlight(); | |
127 | 130 |
128 // The prominent button hover effect is a shadow. | 131 // The prominent button hover effect is a shadow. |
129 const int kYOffset = 1; | 132 const int kYOffset = 1; |
130 const int kSkiaBlurRadius = 1; | 133 const int kSkiaBlurRadius = 2; |
| 134 const int shadow_alpha = is_prominent_ ? 0x3D : 0x1A; |
131 std::vector<gfx::ShadowValue> shadows; | 135 std::vector<gfx::ShadowValue> shadows; |
132 // The notion of blur that gfx::ShadowValue uses is twice the Skia/CSS value. | 136 // The notion of blur that gfx::ShadowValue uses is twice the Skia/CSS value. |
133 // Skia counts the number of pixels outside the mask area whereas | 137 // Skia counts the number of pixels outside the mask area whereas |
134 // gfx::ShadowValue counts together the number of pixels inside and outside | 138 // gfx::ShadowValue counts together the number of pixels inside and outside |
135 // the mask bounds. | 139 // the mask bounds. |
136 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(0, kYOffset), | 140 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(0, kYOffset), |
137 2 * kSkiaBlurRadius, | 141 2 * kSkiaBlurRadius, |
138 SkColorSetA(SK_ColorBLACK, 0x3D))); | 142 SkColorSetA(SK_ColorBLACK, shadow_alpha))); |
| 143 const SkColor fill_color = |
| 144 SkColorSetA(SK_ColorWHITE, is_prominent_ ? 0x0D : 0x05); |
139 return base::MakeUnique<InkDropHighlight>( | 145 return base::MakeUnique<InkDropHighlight>( |
140 gfx::RectF(GetLocalBounds()).CenterPoint(), | 146 gfx::RectF(GetLocalBounds()).CenterPoint(), |
141 base::WrapUnique(new BorderShadowLayerDelegate( | 147 base::WrapUnique(new BorderShadowLayerDelegate( |
142 shadows, GetLocalBounds(), kInkDropSmallCornerRadius))); | 148 shadows, GetLocalBounds(), fill_color, kInkDropSmallCornerRadius))); |
143 } | 149 } |
144 | 150 |
145 bool MdTextButton::ShouldShowInkDropForFocus() const { | 151 bool MdTextButton::ShouldShowInkDropForFocus() const { |
146 // These types of button use FocusRing. | 152 // These types of button use FocusRing. |
147 return false; | 153 return false; |
148 } | 154 } |
149 | 155 |
150 void MdTextButton::SetEnabledTextColors(SkColor color) { | 156 void MdTextButton::SetEnabledTextColors(SkColor color) { |
151 LabelButton::SetEnabledTextColors(color); | 157 LabelButton::SetEnabledTextColors(color); |
152 UpdateColors(); | 158 UpdateColors(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 bg_color = color_utils::BlendTowardOppositeLuma( | 263 bg_color = color_utils::BlendTowardOppositeLuma( |
258 bg_color, gfx::kDisabledControlAlpha); | 264 bg_color, gfx::kDisabledControlAlpha); |
259 } | 265 } |
260 | 266 |
261 if (state() == STATE_PRESSED) { | 267 if (state() == STATE_PRESSED) { |
262 SkColor shade = | 268 SkColor shade = |
263 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonPressedShade); | 269 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonPressedShade); |
264 bg_color = color_utils::GetResultingPaintColor(shade, bg_color); | 270 bg_color = color_utils::GetResultingPaintColor(shade, bg_color); |
265 } | 271 } |
266 | 272 |
267 const SkAlpha kStrokeOpacity = 0x1A; | 273 SkColor stroke_color = |
268 SkColor stroke_color = (is_prominent_ || color_utils::IsDark(text_color)) | 274 is_prominent_ ? SK_ColorTRANSPARENT : SkColorSetA(text_color, 0x33); |
269 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) | |
270 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); | |
271 | |
272 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 275 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
273 set_background(Background::CreateBackgroundPainter( | 276 set_background(Background::CreateBackgroundPainter( |
274 true, Painter::CreateRoundRectWith1PxBorderPainter( | 277 true, Painter::CreateRoundRectWith1PxBorderPainter( |
275 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 278 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
276 } | 279 } |
277 | 280 |
278 } // namespace views | 281 } // namespace views |
OLD | NEW |