Chromium Code Reviews| Index: ui/views/animation/toolbar_ink_drop_delegate.cc |
| diff --git a/ui/views/animation/toolbar_ink_drop_delegate.cc b/ui/views/animation/toolbar_ink_drop_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f884d4fbeb859b19cefa868b77120be16eb7b6e |
| --- /dev/null |
| +++ b/ui/views/animation/toolbar_ink_drop_delegate.cc |
| @@ -0,0 +1,118 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/views/animation/toolbar_ink_drop_delegate.h" |
| + |
| +#include "ui/events/event.h" |
| +#include "ui/events/scoped_target_handler.h" |
| +#include "ui/views/animation/ink_drop_animation_controller.h" |
| +#include "ui/views/animation/ink_drop_animation_controller_factory.h" |
| +#include "ui/views/animation/ink_drop_host.h" |
| +#include "ui/views/animation/ink_drop_state.h" |
| +#include "ui/views/view.h" |
| + |
| +namespace views { |
| + |
| +ToolbarInkDropDelegate::ToolbarInkDropDelegate(InkDropHost* ink_drop_host, |
| + ui::EventTarget* event_target) |
| + : event_handler_(event_target), |
|
bruthig
2015/11/19 16:49:53
|event_handler_| should not be needed. See commen
varkha
2015/11/19 23:34:35
Done.
|
| + target_handler_(new ui::ScopedTargetHandler(event_target, this)), |
| + ink_drop_host_(ink_drop_host), |
| + ink_drop_animation_controller_( |
| + InkDropAnimationControllerFactory:: |
| + CreateInkDropAnimationController(ink_drop_host_)) {} |
| + |
| +ToolbarInkDropDelegate::~ToolbarInkDropDelegate() { |
| +} |
| + |
| +void ToolbarInkDropDelegate::SetInkDropSize(int large_size, |
| + int large_corner_radius, |
| + int small_size, |
| + int small_corner_radius) { |
| + ink_drop_animation_controller_->SetInkDropSize( |
| + gfx::Size(large_size, large_size), large_corner_radius, |
| + gfx::Size(small_size, small_size), small_corner_radius); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnLayout() { |
| + ink_drop_animation_controller_->SetInkDropCenter( |
| + ink_drop_host_->CalculateInkDropCenter()); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnAction(InkDropState state) { |
| + ink_drop_animation_controller_->AnimateToState(state); |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// ui::EventHandler: |
| + |
| +void ToolbarInkDropDelegate::OnEvent(ui::Event* event) { |
| + // Dispatch to |event_handler_| first and then to |target_handler_|. |
| + EventHandler::OnEvent(event); |
| + if (target_handler_->original_target_handler()) |
| + target_handler_->original_target_handler()->OnEvent(event); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnKeyEvent(ui::KeyEvent* event) { |
| + event_handler_->OnKeyEvent(event); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnMouseEvent(ui::MouseEvent* event) { |
| + event_handler_->OnMouseEvent(event); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnScrollEvent(ui::ScrollEvent* event) { |
| + event_handler_->OnScrollEvent(event); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnTouchEvent(ui::TouchEvent* event) { |
| + event_handler_->OnTouchEvent(event); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) { |
| + event_handler_->OnGestureEvent(event); |
| + |
| + // TODO(varkha): Check if |this| has been deleted. |
| + InkDropState ink_drop_state = InkDropState::HIDDEN; |
| + switch (event->type()) { |
| + case ui::ET_GESTURE_TAP_DOWN: |
| + ink_drop_state = InkDropState::ACTION_PENDING; |
| + // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that |
| + // subsequent events for the gesture are sent to |this|. |
| + event->SetHandled(); |
| + break; |
| + case ui::ET_GESTURE_LONG_PRESS: |
| + ink_drop_state = InkDropState::SLOW_ACTION_PENDING; |
| + break; |
| + case ui::ET_GESTURE_LONG_TAP: |
| + ink_drop_state = InkDropState::SLOW_ACTION; |
| + break; |
| + case ui::ET_GESTURE_SCROLL_BEGIN: |
| + case ui::ET_GESTURE_END: |
| + ink_drop_state = InkDropState::HIDDEN; |
| + break; |
| + default: |
| + return; |
| + } |
| + |
| + InkDropState current_ink_drop_state = |
| + ink_drop_animation_controller_->GetInkDropState(); |
| + |
| + if (ink_drop_state == InkDropState::HIDDEN && |
| + (current_ink_drop_state == InkDropState::QUICK_ACTION || |
| + current_ink_drop_state == InkDropState::SLOW_ACTION || |
| + current_ink_drop_state == InkDropState::DEACTIVATED)) { |
| + // These InkDropStates automatically transition to the HIDDEN state so we |
| + // don't make an explicit call. Explicitly animating to HIDDEN in this case |
| + // would prematurely pre-empt these animations. |
| + return; |
| + } |
| + ink_drop_animation_controller_->AnimateToState(ink_drop_state); |
| +} |
| + |
| +void ToolbarInkDropDelegate::OnCancelMode(ui::CancelModeEvent* event) { |
| + event_handler_->OnCancelMode(event); |
| +} |
| + |
| +} // namespace views |