| 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/events/event.h" | 8 #include "ui/events/event.h" |
| 9 #include "ui/events/scoped_target_handler.h" | 9 #include "ui/events/scoped_target_handler.h" |
| 10 #include "ui/gfx/color_palette.h" | 10 #include "ui/gfx/color_palette.h" |
| 11 #include "ui/gfx/geometry/size_conversions.h" | 11 #include "ui/gfx/geometry/size_conversions.h" |
| 12 #include "ui/views/animation/ink_drop.h" | 12 #include "ui/views/animation/ink_drop.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_impl.h" | 14 #include "ui/views/animation/ink_drop_impl.h" |
| 15 #include "ui/views/animation/ink_drop_mask.h" | 15 #include "ui/views/animation/ink_drop_mask.h" |
| 16 #include "ui/views/animation/ink_drop_stub.h" | 16 #include "ui/views/animation/ink_drop_stub.h" |
| 17 #include "ui/views/animation/square_ink_drop_ripple.h" | 17 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 18 | 18 |
| 19 namespace views { | 19 namespace views { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Size used for the default SquareInkDropRipple. | |
| 23 const int kInkDropSize = 24; | |
| 24 | |
| 25 // The scale factor to compute the large size of the default | 22 // The scale factor to compute the large size of the default |
| 26 // SquareInkDropRipple. | 23 // SquareInkDropRipple. |
| 27 const float kLargeInkDropScale = 1.333f; | 24 const float kLargeInkDropScale = 1.333f; |
| 28 | 25 |
| 29 // Default opacity of the ink drop when it is visible. | 26 // Default opacity of the ink drop when it is visible. |
| 30 const float kInkDropVisibleOpacity = 0.175f; | 27 const float kInkDropVisibleOpacity = 0.175f; |
| 31 | 28 |
| 32 } // namespace | 29 } // namespace |
| 33 | 30 |
| 34 // static | |
| 35 const int InkDropHostView::kInkDropSmallCornerRadius = 2; | |
| 36 const int InkDropHostView::kInkDropLargeCornerRadius = 4; | |
| 37 | |
| 38 // An EventHandler that is guaranteed to be invoked and is not prone to | 31 // An EventHandler that is guaranteed to be invoked and is not prone to |
| 39 // InkDropHostView descendents who do not call | 32 // InkDropHostView descendents who do not call |
| 40 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist | 33 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist |
| 41 // at any given time for each ink drop host view. | 34 // at any given time for each ink drop host view. |
| 42 // | 35 // |
| 43 // TODO(bruthig): Consider getting rid of this class. | 36 // TODO(bruthig): Consider getting rid of this class. |
| 44 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { | 37 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { |
| 45 public: | 38 public: |
| 46 explicit InkDropGestureHandler(InkDropHostView* host_view) | 39 explicit InkDropGestureHandler(InkDropHostView* host_view) |
| 47 : target_handler_(new ui::ScopedTargetHandler(host_view, this)), | 40 : target_handler_(new ui::ScopedTargetHandler(host_view, this)), |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); | 153 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); |
| 161 } | 154 } |
| 162 | 155 |
| 163 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() | 156 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() |
| 164 const { | 157 const { |
| 165 return CreateDefaultInkDropHighlight( | 158 return CreateDefaultInkDropHighlight( |
| 166 gfx::RectF(GetLocalBounds()).CenterPoint()); | 159 gfx::RectF(GetLocalBounds()).CenterPoint()); |
| 167 } | 160 } |
| 168 | 161 |
| 169 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( | 162 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( |
| 170 const gfx::Point& center_point) const { | 163 const gfx::Point& center_point, |
| 171 const gfx::Size small_size(kInkDropSize, kInkDropSize); | 164 const gfx::Size& size) const { |
| 172 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( | 165 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( |
| 173 CalculateLargeInkDropSize(small_size), kInkDropLargeCornerRadius, | 166 CalculateLargeInkDropSize(size), kInkDropLargeCornerRadius, size, |
| 174 small_size, kInkDropSmallCornerRadius, center_point, | 167 kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor(), |
| 175 GetInkDropBaseColor(), ink_drop_visible_opacity())); | 168 ink_drop_visible_opacity())); |
| 176 return ripple; | 169 return ripple; |
| 177 } | 170 } |
| 178 | 171 |
| 179 std::unique_ptr<InkDropHighlight> | 172 std::unique_ptr<InkDropHighlight> |
| 180 InkDropHostView::CreateDefaultInkDropHighlight( | 173 InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point, |
| 181 const gfx::PointF& center_point) const { | 174 const gfx::Size& size) const { |
| 182 const gfx::Size small_size(kInkDropSize, kInkDropSize); | 175 std::unique_ptr<InkDropHighlight> highlight(new InkDropHighlight( |
| 183 std::unique_ptr<InkDropHighlight> highlight( | 176 size, kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor())); |
| 184 new InkDropHighlight(small_size, kInkDropSmallCornerRadius, center_point, | 177 highlight->set_explode_size(CalculateLargeInkDropSize(size)); |
| 185 GetInkDropBaseColor())); | |
| 186 highlight->set_explode_size(CalculateLargeInkDropSize(small_size)); | |
| 187 return highlight; | 178 return highlight; |
| 188 } | 179 } |
| 189 | 180 |
| 190 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { | 181 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { |
| 191 ink_drop_mode_ = ink_drop_mode; | 182 ink_drop_mode_ = ink_drop_mode; |
| 192 ink_drop_ = nullptr; | 183 ink_drop_ = nullptr; |
| 193 | 184 |
| 194 if (ink_drop_mode_ != InkDropMode::ON) | 185 if (ink_drop_mode_ != InkDropMode::ON) |
| 195 gesture_handler_ = nullptr; | 186 gesture_handler_ = nullptr; |
| 196 else if (!gesture_handler_) | 187 else if (!gesture_handler_) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 std::unique_ptr<InkDropImpl> | 284 std::unique_ptr<InkDropImpl> |
| 294 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { | 285 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { |
| 295 std::unique_ptr<views::InkDropImpl> ink_drop = | 286 std::unique_ptr<views::InkDropImpl> ink_drop = |
| 296 InkDropHostView::CreateDefaultInkDropImpl(); | 287 InkDropHostView::CreateDefaultInkDropImpl(); |
| 297 ink_drop->SetAutoHighlightMode( | 288 ink_drop->SetAutoHighlightMode( |
| 298 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); | 289 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); |
| 299 return ink_drop; | 290 return ink_drop; |
| 300 } | 291 } |
| 301 | 292 |
| 302 } // namespace views | 293 } // namespace views |
| OLD | NEW |