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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/events/event.h"
6 #include "ui/views/animation/ink_drop_animation_controller.h"
7 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
8 #include "ui/views/animation/ink_drop_host.h"
9 #include "ui/views/animation/ink_drop_state.h"
10 #include "ui/views/animation/toolbar_ink_drop_delegate.h"
11 #include "ui/views/view.h"
12
13 namespace views {
14
15 ToolbarInkDropDelegate::ToolbarInkDropDelegate(InkDropHost* ink_drop_host,
16 View* view)
17 : view_(view),
18 ink_drop_host_(ink_drop_host),
19 ink_drop_animation_controller_(
20 views::InkDropAnimationControllerFactory::
21 CreateInkDropAnimationController(ink_drop_host_)) {
22 original_event_handler_ = view_->target_handler();
23 view_->set_target_handler(this);
24 }
25
26 ToolbarInkDropDelegate::~ToolbarInkDropDelegate() {
27 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).
28 }
29
30 void ToolbarInkDropDelegate::SetInkDropSize(int large_size,
31 int large_corner_radius,
32 int small_size,
33 int small_corner_radius) {
34 ink_drop_animation_controller_->SetInkDropSize(
35 gfx::Size(large_size, large_size), large_corner_radius,
36 gfx::Size(small_size, small_size), small_corner_radius);
37 }
38
39 void ToolbarInkDropDelegate::OnLayout() {
40 ink_drop_animation_controller_->SetInkDropCenter(
41 ink_drop_host_->CalculateInkDropCenter());
42 }
43
44 void ToolbarInkDropDelegate::OnActionComplete() {
45 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
46 }
47
48 void ToolbarInkDropDelegate::OnActionPending() {
49 ink_drop_animation_controller_->AnimateToState(
50 views::InkDropState::ACTION_PENDING);
51 }
52
53 void ToolbarInkDropDelegate::OnActionQuick() {
54 ink_drop_animation_controller_->AnimateToState(
55 views::InkDropState::QUICK_ACTION);
56 }
57
58 void ToolbarInkDropDelegate::OnActivated() {
59 ink_drop_animation_controller_->AnimateToState(
60 views::InkDropState::ACTIVATED);
61 }
62
63 void ToolbarInkDropDelegate::OnDeactivated() {
64 ink_drop_animation_controller_->AnimateToState(
65 views::InkDropState::DEACTIVATED);
66 }
67
68 ////////////////////////////////////////////////////////////////////////////////
69 // ui::EventHandler:
70
71 void ToolbarInkDropDelegate::OnEvent(ui::Event* event) {
72 EventHandler::OnEvent(event);
73 if (original_event_handler_)
74 original_event_handler_->OnEvent(event);
75 }
76
77 void ToolbarInkDropDelegate::OnKeyEvent(ui::KeyEvent* event) {
78 view_->OnKeyEvent(event);
79 }
80
81 void ToolbarInkDropDelegate::OnMouseEvent(ui::MouseEvent* event) {
82 view_->OnMouseEvent(event);
83 }
84
85 void ToolbarInkDropDelegate::OnScrollEvent(ui::ScrollEvent* event) {
86 view_->OnScrollEvent(event);
87 }
88
89 void ToolbarInkDropDelegate::OnTouchEvent(ui::TouchEvent* event) {
90 view_->OnTouchEvent(event);
91 }
92
93 void ToolbarInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) {
94 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.
95 view_->OnGestureEvent(event);
96
97 // TODO(varkha): Check if |this| has been deleted.
98 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN;
99 switch (event->type()) {
100 case ui::ET_GESTURE_TAP_DOWN:
101 ink_drop_state = views::InkDropState::ACTION_PENDING;
102 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that
103 // subsequent events for the gesture are sent to |this|.
104 event->SetHandled();
105 break;
106 case ui::ET_GESTURE_LONG_PRESS:
107 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING;
108 break;
109 case ui::ET_GESTURE_LONG_TAP:
110 ink_drop_state = views::InkDropState::SLOW_ACTION;
111 break;
112 case ui::ET_GESTURE_SCROLL_BEGIN:
113 case ui::ET_GESTURE_END:
114 ink_drop_state = views::InkDropState::HIDDEN;
115 break;
116 default:
117 return;
118 }
119
120 views::InkDropState current_ink_drop_state =
121 ink_drop_animation_controller_->GetInkDropState();
122
123 if (ink_drop_state == views::InkDropState::HIDDEN &&
124 (current_ink_drop_state == views::InkDropState::QUICK_ACTION ||
125 current_ink_drop_state == views::InkDropState::SLOW_ACTION ||
126 current_ink_drop_state == views::InkDropState::DEACTIVATED)) {
127 // These InkDropStates automatically transition to the HIDDEN state so we
128 // don't make an explicit call. Explicitly animating to HIDDEN in this case
129 // would prematurely pre-empt these animations.
130 return;
131 }
132 ink_drop_animation_controller_->AnimateToState(ink_drop_state);
133 }
134
135 void ToolbarInkDropDelegate::OnCancelMode(ui::CancelModeEvent* event) {
136 view_->OnCancelMode(event);
137 }
138
139 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698