| 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 LabelButton::StateChanged(); |
| 184 UpdateColors(); |
| 185 } |
| 186 |
| 181 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() | 187 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() |
| 182 const { | 188 const { |
| 183 if (!ShouldShowInkDropHighlight()) | 189 if (!ShouldShowInkDropHighlight()) |
| 184 return nullptr; | 190 return nullptr; |
| 185 if (!is_cta_) | 191 if (!is_cta_) |
| 186 return LabelButton::CreateInkDropHighlight(); | 192 return LabelButton::CreateInkDropHighlight(); |
| 187 | 193 |
| 188 // The call to action hover effect is a shadow. | 194 // The call to action hover effect is a shadow. |
| 189 const int kYOffset = 1; | 195 const int kYOffset = 1; |
| 190 const int kSkiaBlurRadius = 1; | 196 const int kSkiaBlurRadius = 1; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 234 |
| 229 void MdTextButton::SetFontList(const gfx::FontList& font_list) { | 235 void MdTextButton::SetFontList(const gfx::FontList& font_list) { |
| 230 NOTREACHED() | 236 NOTREACHED() |
| 231 << "Don't call MdTextButton::SetFontList (it will soon be protected)"; | 237 << "Don't call MdTextButton::SetFontList (it will soon be protected)"; |
| 232 } | 238 } |
| 233 | 239 |
| 234 MdTextButton::MdTextButton(ButtonListener* listener) | 240 MdTextButton::MdTextButton(ButtonListener* listener) |
| 235 : LabelButton(listener, base::string16()), | 241 : LabelButton(listener, base::string16()), |
| 236 focus_ring_(new internal::MdFocusRing()), | 242 focus_ring_(new internal::MdFocusRing()), |
| 237 is_cta_(false) { | 243 is_cta_(false) { |
| 238 SetInkDropMode(InkDropMode::ON); | 244 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON |
| 245 : InkDropMode::OFF); |
| 239 set_has_ink_drop_action_on_click(true); | 246 set_has_ink_drop_action_on_click(true); |
| 240 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 247 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 241 SetFocusForPlatform(); | 248 SetFocusForPlatform(); |
| 242 SetMinSize(gfx::Size(kMinWidth, 0)); | 249 SetMinSize(gfx::Size(kMinWidth, 0)); |
| 243 SetFocusPainter(nullptr); | 250 SetFocusPainter(nullptr); |
| 244 label()->SetAutoColorReadabilityEnabled(false); | 251 label()->SetAutoColorReadabilityEnabled(false); |
| 245 AddChildView(focus_ring_); | 252 AddChildView(focus_ring_); |
| 246 focus_ring_->SetVisible(false); | 253 focus_ring_->SetVisible(false); |
| 247 set_request_focus_on_press(false); | 254 set_request_focus_on_press(false); |
| 248 LabelButton::SetFontList(GetMdFontList()); | 255 LabelButton::SetFontList(GetMdFontList()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 SkColor bg_color = | 306 SkColor bg_color = |
| 300 bg_color_override_ | 307 bg_color_override_ |
| 301 ? *bg_color_override_ | 308 ? *bg_color_override_ |
| 302 : is_cta_ | 309 : is_cta_ |
| 303 ? theme->GetSystemColor( | 310 ? theme->GetSystemColor( |
| 304 ui::NativeTheme::kColorId_CallToActionColor) | 311 ui::NativeTheme::kColorId_CallToActionColor) |
| 305 : is_default() | 312 : is_default() |
| 306 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) | 313 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) |
| 307 : SK_ColorTRANSPARENT; | 314 : SK_ColorTRANSPARENT; |
| 308 | 315 |
| 316 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); |
| 317 |
| 309 const SkAlpha kStrokeOpacity = 0x1A; | 318 const SkAlpha kStrokeOpacity = 0x1A; |
| 310 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) | 319 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) |
| 311 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) | 320 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) |
| 312 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); | 321 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); |
| 313 | 322 |
| 314 set_background(Background::CreateBackgroundPainter( | 323 set_background(Background::CreateBackgroundPainter( |
| 315 true, Painter::CreateRoundRectWith1PxBorderPainter( | 324 true, Painter::CreateRoundRectWith1PxBorderPainter( |
| 316 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 325 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
| 317 } | 326 } |
| 318 | 327 |
| 319 } // namespace views | 328 } // namespace views |
| OLD | NEW |