| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/animation/ink_drop_host_view.h" | 5 #include "ui/views/animation/ink_drop_host_view.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/base/material_design/material_design_controller.h" |
| 8 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 9 #include "ui/events/scoped_target_handler.h" | 10 #include "ui/events/scoped_target_handler.h" |
| 10 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
| 11 #include "ui/gfx/geometry/size_conversions.h" | 12 #include "ui/gfx/geometry/size_conversions.h" |
| 13 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 12 #include "ui/views/animation/ink_drop.h" | 14 #include "ui/views/animation/ink_drop.h" |
| 13 #include "ui/views/animation/ink_drop_highlight.h" | 15 #include "ui/views/animation/ink_drop_highlight.h" |
| 14 #include "ui/views/animation/ink_drop_impl.h" | 16 #include "ui/views/animation/ink_drop_impl.h" |
| 15 #include "ui/views/animation/ink_drop_mask.h" | 17 #include "ui/views/animation/ink_drop_mask.h" |
| 16 #include "ui/views/animation/ink_drop_stub.h" | 18 #include "ui/views/animation/ink_drop_stub.h" |
| 17 #include "ui/views/animation/square_ink_drop_ripple.h" | 19 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 18 #include "ui/views/style/platform_style.h" | 20 #include "ui/views/style/platform_style.h" |
| 19 | 21 |
| 20 namespace views { | 22 namespace views { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // The scale factor to compute the large size of the default | 25 // The scale factor to compute the large size of the default |
| 24 // SquareInkDropRipple. | 26 // SquareInkDropRipple. |
| 25 const float kLargeInkDropScale = 1.333f; | 27 const float kLargeInkDropScale = 1.333f; |
| 26 | 28 |
| 27 // Default opacity of the ink drop when it is visible. | 29 // Default opacity of the ink drop when it is visible. |
| 28 const float kInkDropVisibleOpacity = 0.175f; | 30 float DefaultInkDropVisibleOpacity() { |
| 31 constexpr float kInkDropVisibleOpacity = 0.175f; |
| 32 constexpr float kInkDropVisibleOpacityMd = 0.05f; |
| 33 return ui::MaterialDesignController::IsSecondaryUiMaterial() |
| 34 ? kInkDropVisibleOpacityMd |
| 35 : kInkDropVisibleOpacity; |
| 36 } |
| 29 | 37 |
| 30 } // namespace | 38 } // namespace |
| 31 | 39 |
| 32 // static | 40 // static |
| 33 constexpr int InkDropHostView::kInkDropSmallCornerRadius; | 41 constexpr int InkDropHostView::kInkDropSmallCornerRadius; |
| 34 constexpr int InkDropHostView::kInkDropLargeCornerRadius; | 42 constexpr int InkDropHostView::kInkDropLargeCornerRadius; |
| 35 | 43 |
| 36 // An EventHandler that is guaranteed to be invoked and is not prone to | 44 // An EventHandler that is guaranteed to be invoked and is not prone to |
| 37 // InkDropHostView descendents who do not call | 45 // InkDropHostView descendents who do not call |
| 38 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist | 46 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // static | 119 // static |
| 112 | 120 |
| 113 gfx::Size InkDropHostView::CalculateLargeInkDropSize( | 121 gfx::Size InkDropHostView::CalculateLargeInkDropSize( |
| 114 const gfx::Size& small_size) { | 122 const gfx::Size& small_size) { |
| 115 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); | 123 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); |
| 116 } | 124 } |
| 117 | 125 |
| 118 InkDropHostView::InkDropHostView() | 126 InkDropHostView::InkDropHostView() |
| 119 : ink_drop_mode_(InkDropMode::OFF), | 127 : ink_drop_mode_(InkDropMode::OFF), |
| 120 ink_drop_(nullptr), | 128 ink_drop_(nullptr), |
| 121 ink_drop_visible_opacity_(kInkDropVisibleOpacity), | 129 ink_drop_visible_opacity_(DefaultInkDropVisibleOpacity()), |
| 122 old_paint_to_layer_(false), | 130 old_paint_to_layer_(false), |
| 123 destroying_(false) {} | 131 destroying_(false) {} |
| 124 | 132 |
| 125 InkDropHostView::~InkDropHostView() { | 133 InkDropHostView::~InkDropHostView() { |
| 126 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to | 134 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to |
| 127 // potentially destroyed InkDropHosts and remove |destroying_|. | 135 // potentially destroyed InkDropHosts and remove |destroying_|. |
| 128 destroying_ = true; | 136 destroying_ = true; |
| 129 } | 137 } |
| 130 | 138 |
| 131 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 139 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const { | 173 const { |
| 166 return CreateDefaultInkDropHighlight( | 174 return CreateDefaultInkDropHighlight( |
| 167 gfx::RectF(GetMirroredRect(GetContentsBounds())).CenterPoint()); | 175 gfx::RectF(GetMirroredRect(GetContentsBounds())).CenterPoint()); |
| 168 } | 176 } |
| 169 | 177 |
| 170 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( | 178 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( |
| 171 const gfx::Point& center_point, | 179 const gfx::Point& center_point, |
| 172 const gfx::Size& size) const { | 180 const gfx::Size& size) const { |
| 173 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( | 181 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( |
| 174 CalculateLargeInkDropSize(size), kInkDropLargeCornerRadius, size, | 182 CalculateLargeInkDropSize(size), kInkDropLargeCornerRadius, size, |
| 175 kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor(), | 183 kInkDropSmallCornerRadius, center_point, GetInkDropBaseColorImpl(), |
| 176 ink_drop_visible_opacity())); | 184 ink_drop_visible_opacity())); |
| 177 return ripple; | 185 return ripple; |
| 178 } | 186 } |
| 179 | 187 |
| 188 std::unique_ptr<InkDropRipple> InkDropHostView::CreateFloodFillInkDropRipple() |
| 189 const { |
| 190 return std::unique_ptr<InkDropRipple>(new FloodFillInkDropRipple( |
| 191 gfx::Size(kDefaultInkDropSize, kDefaultInkDropSize), |
| 192 GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColorImpl(), |
| 193 ink_drop_visible_opacity())); |
| 194 } |
| 195 |
| 180 std::unique_ptr<InkDropHighlight> | 196 std::unique_ptr<InkDropHighlight> |
| 181 InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point, | 197 InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point, |
| 182 const gfx::Size& size) const { | 198 const gfx::Size& size) const { |
| 183 std::unique_ptr<InkDropHighlight> highlight(new InkDropHighlight( | 199 std::unique_ptr<InkDropHighlight> highlight( |
| 184 size, kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor())); | 200 new InkDropHighlight(size, kInkDropSmallCornerRadius, center_point, |
| 201 GetInkDropBaseColorImpl())); |
| 185 highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size))); | 202 highlight->set_explode_size(gfx::SizeF(CalculateLargeInkDropSize(size))); |
| 186 return highlight; | 203 return highlight; |
| 187 } | 204 } |
| 188 | 205 |
| 189 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { | 206 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { |
| 190 ink_drop_mode_ = ink_drop_mode; | 207 ink_drop_mode_ = ink_drop_mode; |
| 191 ink_drop_ = nullptr; | 208 ink_drop_ = nullptr; |
| 192 | 209 |
| 193 if (ink_drop_mode_ != InkDropMode::ON) | 210 if (ink_drop_mode_ != InkDropMode::ON) |
| 194 gesture_handler_ = nullptr; | 211 gesture_handler_ = nullptr; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 326 |
| 310 std::unique_ptr<InkDropImpl> | 327 std::unique_ptr<InkDropImpl> |
| 311 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { | 328 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { |
| 312 std::unique_ptr<views::InkDropImpl> ink_drop = | 329 std::unique_ptr<views::InkDropImpl> ink_drop = |
| 313 InkDropHostView::CreateDefaultInkDropImpl(); | 330 InkDropHostView::CreateDefaultInkDropImpl(); |
| 314 ink_drop->SetAutoHighlightMode( | 331 ink_drop->SetAutoHighlightMode( |
| 315 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); | 332 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); |
| 316 return ink_drop; | 333 return ink_drop; |
| 317 } | 334 } |
| 318 | 335 |
| 336 SkColor InkDropHostView::GetInkDropBaseColorImpl() const { |
| 337 return ui::MaterialDesignController::IsSecondaryUiMaterial() |
| 338 ? SK_ColorBLACK |
| 339 : GetInkDropBaseColor(); |
| 340 } |
| 341 |
| 319 } // namespace views | 342 } // namespace views |
| OLD | NEW |