| 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" |
| 11 #include "ui/gfx/color_utils.h" | 11 #include "ui/gfx/color_utils.h" |
| 12 #include "ui/native_theme/native_theme.h" | 12 #include "ui/native_theme/native_theme.h" |
| 13 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 13 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 14 #include "ui/views/animation/ink_drop_highlight.h" | 14 #include "ui/views/animation/ink_drop_highlight.h" |
| 15 #include "ui/views/animation/ink_drop_impl.h" |
| 15 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" | 16 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
| 16 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
| 17 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 18 #include "ui/views/controls/button/blue_button.h" | 19 #include "ui/views/controls/button/blue_button.h" |
| 19 #include "ui/views/controls/focus_ring.h" | 20 #include "ui/views/controls/focus_ring.h" |
| 20 #include "ui/views/painter.h" | 21 #include "ui/views/painter.h" |
| 21 #include "ui/views/style/platform_style.h" | 22 #include "ui/views/style/platform_style.h" |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 | 25 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 115 |
| 115 void MdTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 116 void MdTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 116 LabelButton::OnNativeThemeChanged(theme); | 117 LabelButton::OnNativeThemeChanged(theme); |
| 117 UpdateColors(); | 118 UpdateColors(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 SkColor MdTextButton::GetInkDropBaseColor() const { | 121 SkColor MdTextButton::GetInkDropBaseColor() const { |
| 121 return color_utils::DeriveDefaultIconColor(label()->enabled_color()); | 122 return color_utils::DeriveDefaultIconColor(label()->enabled_color()); |
| 122 } | 123 } |
| 123 | 124 |
| 125 std::unique_ptr<InkDrop> MdTextButton::CreateInkDrop() { |
| 126 return CreateDefaultFloodFillInkDropImpl(); |
| 127 } |
| 128 |
| 124 std::unique_ptr<views::InkDropRipple> MdTextButton::CreateInkDropRipple() | 129 std::unique_ptr<views::InkDropRipple> MdTextButton::CreateInkDropRipple() |
| 125 const { | 130 const { |
| 126 return std::unique_ptr<views::InkDropRipple>( | 131 return std::unique_ptr<views::InkDropRipple>( |
| 127 new views::FloodFillInkDropRipple( | 132 new views::FloodFillInkDropRipple( |
| 128 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), | 133 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(), |
| 129 GetInkDropBaseColor(), ink_drop_visible_opacity())); | 134 GetInkDropBaseColor(), ink_drop_visible_opacity())); |
| 130 } | 135 } |
| 131 | 136 |
| 132 void MdTextButton::StateChanged() { | 137 void MdTextButton::StateChanged() { |
| 133 LabelButton::StateChanged(); | 138 LabelButton::StateChanged(); |
| 134 UpdateColors(); | 139 UpdateColors(); |
| 135 } | 140 } |
| 136 | 141 |
| 137 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() | 142 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() |
| 138 const { | 143 const { |
| 139 if (!ShouldShowInkDropHighlight()) | |
| 140 return nullptr; | |
| 141 | |
| 142 // The prominent button hover effect is a shadow. | 144 // The prominent button hover effect is a shadow. |
| 143 const int kYOffset = 1; | 145 const int kYOffset = 1; |
| 144 const int kSkiaBlurRadius = 2; | 146 const int kSkiaBlurRadius = 2; |
| 145 const int shadow_alpha = is_prominent_ ? 0x3D : 0x1A; | 147 const int shadow_alpha = is_prominent_ ? 0x3D : 0x1A; |
| 146 std::vector<gfx::ShadowValue> shadows; | 148 std::vector<gfx::ShadowValue> shadows; |
| 147 // The notion of blur that gfx::ShadowValue uses is twice the Skia/CSS value. | 149 // The notion of blur that gfx::ShadowValue uses is twice the Skia/CSS value. |
| 148 // Skia counts the number of pixels outside the mask area whereas | 150 // Skia counts the number of pixels outside the mask area whereas |
| 149 // gfx::ShadowValue counts together the number of pixels inside and outside | 151 // gfx::ShadowValue counts together the number of pixels inside and outside |
| 150 // the mask bounds. | 152 // the mask bounds. |
| 151 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(0, kYOffset), | 153 shadows.push_back(gfx::ShadowValue(gfx::Vector2d(0, kYOffset), |
| 152 2 * kSkiaBlurRadius, | 154 2 * kSkiaBlurRadius, |
| 153 SkColorSetA(SK_ColorBLACK, shadow_alpha))); | 155 SkColorSetA(SK_ColorBLACK, shadow_alpha))); |
| 154 const SkColor fill_color = | 156 const SkColor fill_color = |
| 155 SkColorSetA(SK_ColorWHITE, is_prominent_ ? 0x0D : 0x05); | 157 SkColorSetA(SK_ColorWHITE, is_prominent_ ? 0x0D : 0x05); |
| 156 return base::MakeUnique<InkDropHighlight>( | 158 return base::MakeUnique<InkDropHighlight>( |
| 157 gfx::RectF(GetLocalBounds()).CenterPoint(), | 159 gfx::RectF(GetLocalBounds()).CenterPoint(), |
| 158 base::WrapUnique(new BorderShadowLayerDelegate( | 160 base::WrapUnique(new BorderShadowLayerDelegate( |
| 159 shadows, GetLocalBounds(), fill_color, kInkDropSmallCornerRadius))); | 161 shadows, GetLocalBounds(), fill_color, kInkDropSmallCornerRadius))); |
| 160 } | 162 } |
| 161 | 163 |
| 162 bool MdTextButton::ShouldShowInkDropForFocus() const { | |
| 163 // These types of button use FocusRing. | |
| 164 return false; | |
| 165 } | |
| 166 | |
| 167 void MdTextButton::SetEnabledTextColors(SkColor color) { | 164 void MdTextButton::SetEnabledTextColors(SkColor color) { |
| 168 LabelButton::SetEnabledTextColors(color); | 165 LabelButton::SetEnabledTextColors(color); |
| 169 UpdateColors(); | 166 UpdateColors(); |
| 170 } | 167 } |
| 171 | 168 |
| 172 void MdTextButton::SetText(const base::string16& text) { | 169 void MdTextButton::SetText(const base::string16& text) { |
| 173 LabelButton::SetText(text); | 170 LabelButton::SetText(text); |
| 174 UpdatePadding(); | 171 UpdatePadding(); |
| 175 } | 172 } |
| 176 | 173 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 stroke_color, gfx::kDisabledControlAlpha); | 293 stroke_color, gfx::kDisabledControlAlpha); |
| 297 } | 294 } |
| 298 | 295 |
| 299 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 296 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
| 300 set_background(Background::CreateBackgroundPainter( | 297 set_background(Background::CreateBackgroundPainter( |
| 301 true, Painter::CreateRoundRectWith1PxBorderPainter( | 298 true, Painter::CreateRoundRectWith1PxBorderPainter( |
| 302 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 299 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
| 303 } | 300 } |
| 304 | 301 |
| 305 } // namespace views | 302 } // namespace views |
| OLD | NEW |