Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: ui/views/animation/toolbar_ink_drop_delegate.cc

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attempt to refactor ink drop animations (wired up chained EventHandler) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6edc2ac3035038f9bafcd5b2bba469e463f909a8
--- /dev/null
+++ b/ui/views/animation/toolbar_ink_drop_delegate.cc
@@ -0,0 +1,139 @@
+// 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/events/event.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/animation/toolbar_ink_drop_delegate.h"
+#include "ui/views/view.h"
+
+namespace views {
+
+ToolbarInkDropDelegate::ToolbarInkDropDelegate(InkDropHost* ink_drop_host,
+ View* view)
+ : view_(view),
+ ink_drop_host_(ink_drop_host),
+ ink_drop_animation_controller_(
+ views::InkDropAnimationControllerFactory::
+ CreateInkDropAnimationController(ink_drop_host_)) {
+ original_event_handler_ = view_->target_handler();
+ view_->set_target_handler(this);
+}
+
+ToolbarInkDropDelegate::~ToolbarInkDropDelegate() {
+ view_->set_target_handler(original_event_handler_);
bruthig 2015/11/16 22:37:11 What do you think about adding a D/CHECK here to v
varkha 2015/11/18 22:56:44 Done (inside ScopedTargetHandler).
+}
+
+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::OnActionComplete() {
+ ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
+}
+
+void ToolbarInkDropDelegate::OnActionPending() {
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::ACTION_PENDING);
+}
+
+void ToolbarInkDropDelegate::OnActionQuick() {
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::QUICK_ACTION);
+}
+
+void ToolbarInkDropDelegate::OnActivated() {
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::ACTIVATED);
+}
+
+void ToolbarInkDropDelegate::OnDeactivated() {
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::DEACTIVATED);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ui::EventHandler:
+
+void ToolbarInkDropDelegate::OnEvent(ui::Event* event) {
+ EventHandler::OnEvent(event);
+ if (original_event_handler_)
+ original_event_handler_->OnEvent(event);
+}
+
+void ToolbarInkDropDelegate::OnKeyEvent(ui::KeyEvent* event) {
+ view_->OnKeyEvent(event);
+}
+
+void ToolbarInkDropDelegate::OnMouseEvent(ui::MouseEvent* event) {
+ view_->OnMouseEvent(event);
+}
+
+void ToolbarInkDropDelegate::OnScrollEvent(ui::ScrollEvent* event) {
+ view_->OnScrollEvent(event);
+}
+
+void ToolbarInkDropDelegate::OnTouchEvent(ui::TouchEvent* event) {
+ view_->OnTouchEvent(event);
+}
+
+void ToolbarInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) {
+ LOG(ERROR) << __FUNCTION__ << " event:" << event->type();
bruthig 2015/11/16 22:37:11 Don't forget to remove this log line.
varkha 2015/11/18 22:56:44 Done.
+ view_->OnGestureEvent(event);
+
+ // TODO(varkha): Check if |this| has been deleted.
+ views::InkDropState ink_drop_state = views::InkDropState::HIDDEN;
+ switch (event->type()) {
+ case ui::ET_GESTURE_TAP_DOWN:
+ ink_drop_state = views::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 = views::InkDropState::SLOW_ACTION_PENDING;
+ break;
+ case ui::ET_GESTURE_LONG_TAP:
+ ink_drop_state = views::InkDropState::SLOW_ACTION;
+ break;
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ case ui::ET_GESTURE_END:
+ ink_drop_state = views::InkDropState::HIDDEN;
+ break;
+ default:
+ return;
+ }
+
+ views::InkDropState current_ink_drop_state =
+ ink_drop_animation_controller_->GetInkDropState();
+
+ if (ink_drop_state == views::InkDropState::HIDDEN &&
+ (current_ink_drop_state == views::InkDropState::QUICK_ACTION ||
+ current_ink_drop_state == views::InkDropState::SLOW_ACTION ||
+ current_ink_drop_state == views::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) {
+ view_->OnCancelMode(event);
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698