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" |
11 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
13 #include "ui/views/animation/ink_drop_highlight.h" | 13 #include "ui/views/animation/ink_drop_highlight.h" |
14 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" | 14 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
15 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
16 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
17 #include "ui/views/controls/button/blue_button.h" | 17 #include "ui/views/controls/button/blue_button.h" |
18 #include "ui/views/painter.h" | 18 #include "ui/views/painter.h" |
19 #include "ui/views/style/platform_style.h" | |
19 | 20 |
20 namespace views { | 21 namespace views { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Minimum size to reserve for the button contents. | 25 // Minimum size to reserve for the button contents. |
25 const int kMinWidth = 48; | 26 const int kMinWidth = 48; |
26 | 27 |
27 // The stroke width of the focus border in normal and call to action mode. | 28 // The stroke width of the focus border in normal and call to action mode. |
28 const int kFocusBorderThickness = 1; | 29 const int kFocusBorderThickness = 1; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 } | 172 } |
172 | 173 |
173 std::unique_ptr<views::InkDropRipple> MdTextButton::CreateInkDropRipple() | 174 std::unique_ptr<views::InkDropRipple> MdTextButton::CreateInkDropRipple() |
174 const { | 175 const { |
175 return std::unique_ptr<views::InkDropRipple>( | 176 return std::unique_ptr<views::InkDropRipple>( |
176 new views::FloodFillInkDropRipple( | 177 new views::FloodFillInkDropRipple( |
177 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), | 178 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), |
178 GetInkDropBaseColor(), ink_drop_visible_opacity())); | 179 GetInkDropBaseColor(), ink_drop_visible_opacity())); |
179 } | 180 } |
180 | 181 |
182 void MdTextButton::StateChanged() { | |
183 UpdateColors(); | |
sky
2016/08/25 23:44:50
Are you sure you don't need to call LabelButton::S
Elly Fong-Jones
2016/08/26 15:46:44
Nope, I totally do. Good catch.
| |
184 } | |
185 | |
181 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() | 186 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() |
182 const { | 187 const { |
183 if (!ShouldShowInkDropHighlight()) | 188 if (!ShouldShowInkDropHighlight()) |
184 return nullptr; | 189 return nullptr; |
185 if (!is_cta_) | 190 if (!is_cta_) |
186 return LabelButton::CreateInkDropHighlight(); | 191 return LabelButton::CreateInkDropHighlight(); |
187 | 192 |
188 // The call to action hover effect is a shadow. | 193 // The call to action hover effect is a shadow. |
189 const int kYOffset = 1; | 194 const int kYOffset = 1; |
190 const int kSkiaBlurRadius = 1; | 195 const int kSkiaBlurRadius = 1; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 | 233 |
229 void MdTextButton::SetFontList(const gfx::FontList& font_list) { | 234 void MdTextButton::SetFontList(const gfx::FontList& font_list) { |
230 NOTREACHED() | 235 NOTREACHED() |
231 << "Don't call MdTextButton::SetFontList (it will soon be protected)"; | 236 << "Don't call MdTextButton::SetFontList (it will soon be protected)"; |
232 } | 237 } |
233 | 238 |
234 MdTextButton::MdTextButton(ButtonListener* listener) | 239 MdTextButton::MdTextButton(ButtonListener* listener) |
235 : LabelButton(listener, base::string16()), | 240 : LabelButton(listener, base::string16()), |
236 focus_ring_(new internal::MdFocusRing()), | 241 focus_ring_(new internal::MdFocusRing()), |
237 is_cta_(false) { | 242 is_cta_(false) { |
238 SetInkDropMode(InkDropMode::ON); | 243 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON |
244 : InkDropMode::OFF); | |
239 set_has_ink_drop_action_on_click(true); | 245 set_has_ink_drop_action_on_click(true); |
240 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 246 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
241 SetFocusForPlatform(); | 247 SetFocusForPlatform(); |
242 SetMinSize(gfx::Size(kMinWidth, 0)); | 248 SetMinSize(gfx::Size(kMinWidth, 0)); |
243 SetFocusPainter(nullptr); | 249 SetFocusPainter(nullptr); |
244 label()->SetAutoColorReadabilityEnabled(false); | 250 label()->SetAutoColorReadabilityEnabled(false); |
245 AddChildView(focus_ring_); | 251 AddChildView(focus_ring_); |
246 focus_ring_->SetVisible(false); | 252 focus_ring_->SetVisible(false); |
247 set_request_focus_on_press(false); | 253 set_request_focus_on_press(false); |
248 LabelButton::SetFontList(GetMdFontList()); | 254 LabelButton::SetFontList(GetMdFontList()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 SkColor bg_color = | 305 SkColor bg_color = |
300 bg_color_override_ | 306 bg_color_override_ |
301 ? *bg_color_override_ | 307 ? *bg_color_override_ |
302 : is_cta_ | 308 : is_cta_ |
303 ? theme->GetSystemColor( | 309 ? theme->GetSystemColor( |
304 ui::NativeTheme::kColorId_CallToActionColor) | 310 ui::NativeTheme::kColorId_CallToActionColor) |
305 : is_default() | 311 : is_default() |
306 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) | 312 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) |
307 : SK_ColorTRANSPARENT; | 313 : SK_ColorTRANSPARENT; |
308 | 314 |
315 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); | |
316 | |
309 const SkAlpha kStrokeOpacity = 0x1A; | 317 const SkAlpha kStrokeOpacity = 0x1A; |
310 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) | 318 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) |
311 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) | 319 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) |
312 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); | 320 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); |
313 | 321 |
314 set_background(Background::CreateBackgroundPainter( | 322 set_background(Background::CreateBackgroundPainter( |
315 true, Painter::CreateRoundRectWith1PxBorderPainter( | 323 true, Painter::CreateRoundRectWith1PxBorderPainter( |
316 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 324 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
317 } | 325 } |
318 | 326 |
319 } // namespace views | 327 } // namespace views |
OLD | NEW |