Index: ui/views/animation/ink_drop_host_view.cc |
diff --git a/ui/views/animation/ink_drop_host_view.cc b/ui/views/animation/ink_drop_host_view.cc |
index 4f5f953b410751f9351b0b111a533df5b2099675..9fd61190455c396dc9a7cca904a9b81a67fa8ad6 100644 |
--- a/ui/views/animation/ink_drop_host_view.cc |
+++ b/ui/views/animation/ink_drop_host_view.cc |
@@ -41,8 +41,10 @@ const int InkDropHostView::kInkDropSmallCornerRadius = 2; |
// TODO(bruthig): Consider getting rid of this class. |
class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { |
public: |
- InkDropGestureHandler(View* view, InkDrop* ink_drop) |
- : ink_drop_(ink_drop), target_handler_(view, this) {} |
+ InkDropGestureHandler(InkDropHostView* host_view, InkDrop* ink_drop) |
+ : target_handler_(new ui::ScopedTargetHandler(host_view, this)), |
+ host_view_(host_view), |
+ ink_drop_(ink_drop) {} |
~InkDropGestureHandler() override {} |
@@ -85,16 +87,19 @@ class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { |
// case would prematurely pre-empt these animations. |
return; |
} |
- ink_drop_->AnimateToState(ink_drop_state); |
+ host_view_->AnimateInkDrop(ink_drop_state, event); |
} |
private: |
+ // Allows |this| to handle all GestureEvents on |host_view_|. |
+ std::unique_ptr<ui::ScopedTargetHandler> target_handler_; |
+ |
+ // The host view to cache ui::Events to when animating the ink drop. |
+ InkDropHostView* host_view_; |
+ |
// Animation controller for the ink drop ripple effect. |
InkDrop* ink_drop_; |
- // An instance of ScopedTargetHandler allowing |this| to handle events. |
- ui::ScopedTargetHandler target_handler_; |
- |
DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); |
}; |
@@ -127,22 +132,52 @@ void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
} |
std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { |
+ return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); |
+} |
+ |
+std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() |
+ const { |
+ return CreateDefaultInkDropHighlight(GetLocalBounds().CenterPoint()); |
+} |
+ |
+// static |
+const ui::LocatedEvent* InkDropHostView::AsLocatedEvent( |
Evan Stade
2016/06/15 20:34:42
I'm not a big fan of putting this here. It's not p
bruthig
2016/06/15 21:43:19
Moved to event_utils(h|cc) as ToLocatedEventOrNull
|
+ const ui::Event* event) { |
+ return event && event->IsLocatedEvent() ? event->AsLocatedEvent() : nullptr; |
+} |
+ |
+std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( |
+ const gfx::Point& center_point) const { |
std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( |
CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, |
- ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), |
+ ink_drop_size_, kInkDropSmallCornerRadius, center_point, |
GetInkDropBaseColor())); |
return ripple; |
} |
-std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() |
- const { |
+std::unique_ptr<InkDropHighlight> |
+InkDropHostView::CreateDefaultInkDropHighlight( |
+ const gfx::Point& center_point) const { |
std::unique_ptr<InkDropHighlight> highlight( |
new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, |
- GetInkDropCenter(), GetInkDropBaseColor())); |
+ center_point, GetInkDropBaseColor())); |
highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); |
return highlight; |
} |
+gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { |
+ return last_ripple_triggering_event_ |
+ ? last_ripple_triggering_event_->location() |
+ : GetLocalBounds().CenterPoint(); |
+} |
+ |
+void InkDropHostView::AnimateInkDrop(InkDropState state, |
+ const ui::LocatedEvent* event) { |
+ last_ripple_triggering_event_.reset( |
+ event ? ui::Event::Clone(*event).release()->AsLocatedEvent() : nullptr); |
+ ink_drop_->AnimateToState(state); |
+} |
+ |
void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) { |
View::VisibilityChanged(starting_from, is_visible); |
if (GetWidget() && !is_visible) { |
@@ -177,10 +212,6 @@ void InkDropHostView::OnMouseEvent(ui::MouseEvent* event) { |
View::OnMouseEvent(event); |
} |
-gfx::Point InkDropHostView::GetInkDropCenter() const { |
- return GetLocalBounds().CenterPoint(); |
-} |
- |
SkColor InkDropHostView::GetInkDropBaseColor() const { |
NOTREACHED(); |
return gfx::kPlaceholderColor; |
@@ -200,8 +231,4 @@ void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) { |
} |
} |
-void InkDropHostView::AnimateInkDrop(InkDropState ink_drop_state) { |
- ink_drop_->AnimateToState(ink_drop_state); |
-} |
- |
} // namespace views |