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

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: Refactor ink drop animations (moved ACTION_PENDING handling to toolbar_action_view for now) 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/views/animation/toolbar_ink_drop_delegate.h"
6
7 #include "ui/events/event.h"
8 #include "ui/views/animation/ink_drop_animation_controller.h"
9 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
10 #include "ui/views/animation/ink_drop_host.h"
11 #include "ui/views/animation/ink_drop_state.h"
12 #include "ui/views/view.h"
13
14 namespace views {
15
16 ToolbarInkDropDelegate::ToolbarInkDropDelegate(InkDropHost* ink_drop_host,
17 ui::EventTarget* event_target)
18 : ui::ScopedTargetHandler(event_target),
19 destroyed_flag_(NULL),
20 ink_drop_host_(ink_drop_host),
21 ink_drop_animation_controller_(
22 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
23 ink_drop_host_)) {}
24
25 ToolbarInkDropDelegate::~ToolbarInkDropDelegate() {
26 if (destroyed_flag_)
27 *destroyed_flag_ = true;
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::OnAction(InkDropState state) {
45 ink_drop_animation_controller_->AnimateToState(state);
46 }
47
48 ////////////////////////////////////////////////////////////////////////////////
49 // ui::ScopedTargetHandler:
50
51 void ToolbarInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) {
52 bool destroyed = false;
53 destroyed_flag_ = &destroyed;
54 ScopedTargetHandler::OnGestureEvent(event);
55 if (destroyed)
56 return;
57 destroyed_flag_ = NULL;
58
59 InkDropState ink_drop_state = InkDropState::HIDDEN;
60 switch (event->type()) {
61 case ui::ET_GESTURE_TAP_DOWN:
62 ink_drop_state = InkDropState::ACTION_PENDING;
63 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that
64 // subsequent events for the gesture are sent to |this|.
65 event->SetHandled();
66 break;
67 case ui::ET_GESTURE_LONG_PRESS:
68 ink_drop_state = InkDropState::SLOW_ACTION_PENDING;
69 break;
70 case ui::ET_GESTURE_LONG_TAP:
71 ink_drop_state = InkDropState::SLOW_ACTION;
72 break;
73 case ui::ET_GESTURE_SCROLL_BEGIN:
74 case ui::ET_GESTURE_END:
75 ink_drop_state = InkDropState::HIDDEN;
76 break;
77 default:
78 return;
79 }
80
81 InkDropState current_ink_drop_state =
82 ink_drop_animation_controller_->GetInkDropState();
83
84 if (ink_drop_state == InkDropState::HIDDEN &&
85 (current_ink_drop_state == InkDropState::QUICK_ACTION ||
86 current_ink_drop_state == InkDropState::SLOW_ACTION ||
87 current_ink_drop_state == InkDropState::DEACTIVATED)) {
88 // These InkDropStates automatically transition to the HIDDEN state so we
89 // don't make an explicit call. Explicitly animating to HIDDEN in this case
90 // would prematurely pre-empt these animations.
91 return;
92 }
93 ink_drop_animation_controller_->AnimateToState(ink_drop_state);
94 }
95
96 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698