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

Side by Side Diff: ui/views/animation/button_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 (more comments in ui/views/, test) Created 5 years 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/button_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/scoped_target_handler.h"
13 #include "ui/views/view.h"
14
15 namespace views {
16
17 ButtonInkDropDelegate::ButtonInkDropDelegate(InkDropHost* ink_drop_host,
18 View* view)
19 : target_handler_(new views::ScopedTargetHandler(view, this)),
20 ink_drop_host_(ink_drop_host),
21 ink_drop_animation_controller_(
22 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
23 ink_drop_host_)) {}
24
25 ButtonInkDropDelegate::~ButtonInkDropDelegate() {
26 }
27
28 void ButtonInkDropDelegate::SetInkDropSize(int large_size,
29 int large_corner_radius,
30 int small_size,
31 int small_corner_radius) {
32 ink_drop_animation_controller_->SetInkDropSize(
33 gfx::Size(large_size, large_size), large_corner_radius,
34 gfx::Size(small_size, small_size), small_corner_radius);
35 }
36
37 void ButtonInkDropDelegate::OnLayout() {
38 ink_drop_animation_controller_->SetInkDropCenter(
39 ink_drop_host_->CalculateInkDropCenter());
40 }
41
42 void ButtonInkDropDelegate::OnAction(InkDropState state) {
43 ink_drop_animation_controller_->AnimateToState(state);
44 }
45
46 ////////////////////////////////////////////////////////////////////////////////
47 // ui::ScopedTargetHandler:
sadrul 2015/11/27 05:59:35 ui::EventHandler, right?
varkha 2015/11/27 15:17:02 Done.
48
49 void ButtonInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) {
50 InkDropState ink_drop_state = InkDropState::HIDDEN;
51 switch (event->type()) {
52 case ui::ET_GESTURE_TAP_DOWN:
53 ink_drop_state = InkDropState::ACTION_PENDING;
54 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that
55 // subsequent events for the gesture are sent to |this|.
56 event->SetHandled();
57 break;
58 case ui::ET_GESTURE_LONG_PRESS:
59 ink_drop_state = InkDropState::SLOW_ACTION_PENDING;
60 break;
61 case ui::ET_GESTURE_LONG_TAP:
62 ink_drop_state = InkDropState::SLOW_ACTION;
63 break;
64 case ui::ET_GESTURE_SCROLL_BEGIN:
65 case ui::ET_GESTURE_END:
66 ink_drop_state = InkDropState::HIDDEN;
67 break;
68 default:
69 return;
70 }
71
72 InkDropState current_ink_drop_state =
73 ink_drop_animation_controller_->GetInkDropState();
74
75 if (ink_drop_state == InkDropState::HIDDEN &&
76 (current_ink_drop_state == InkDropState::QUICK_ACTION ||
77 current_ink_drop_state == InkDropState::SLOW_ACTION ||
78 current_ink_drop_state == InkDropState::DEACTIVATED)) {
79 // These InkDropStates automatically transition to the HIDDEN state so we
80 // don't make an explicit call. Explicitly animating to HIDDEN in this case
81 // would prematurely pre-empt these animations.
82 return;
83 }
84 ink_drop_animation_controller_->AnimateToState(ink_drop_state);
85 }
86
87 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698