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

Side by Side Diff: ui/views/animation/button_ink_drop_delegate.cc

Issue 2041033002: Moved ButtonInkDropDelegate logic into InkDropHostView and deleted InkDropDelegates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed merge conflict in custom_button.cc Created 4 years, 6 months 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
« no previous file with comments | « ui/views/animation/button_ink_drop_delegate.h ('k') | ui/views/animation/ink_drop.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/events/scoped_target_handler.h"
9 #include "ui/views/animation/ink_drop.h"
10 #include "ui/views/animation/ink_drop_factory.h"
11 #include "ui/views/animation/ink_drop_host.h"
12 #include "ui/views/animation/ink_drop_state.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 ui::ScopedTargetHandler(view, this)),
20 ink_drop_host_(ink_drop_host),
21 ink_drop_(InkDropFactory::CreateInkDrop(ink_drop_host_)) {}
22
23 ButtonInkDropDelegate::~ButtonInkDropDelegate() {
24 }
25
26 void ButtonInkDropDelegate::OnAction(InkDropState state) {
27 ink_drop_->AnimateToState(state);
28 }
29
30 void ButtonInkDropDelegate::SnapToActivated() {
31 ink_drop_->SnapToActivated();
32 }
33
34 void ButtonInkDropDelegate::SetHovered(bool is_hovered) {
35 ink_drop_->SetHovered(is_hovered);
36 }
37
38 InkDropState ButtonInkDropDelegate::GetTargetInkDropState() const {
39 return ink_drop_->GetTargetInkDropState();
40 }
41
42 InkDrop* ButtonInkDropDelegate::GetInkDrop() {
43 return ink_drop_.get();
44 }
45
46 ////////////////////////////////////////////////////////////////////////////////
47 // ui::EventHandler:
48
49 void ButtonInkDropDelegate::OnMouseEvent(ui::MouseEvent* event) {
50 switch (event->type()) {
51 case ui::ET_MOUSE_ENTERED:
52 SetHovered(true);
53 break;
54 case ui::ET_MOUSE_EXITED:
55 SetHovered(false);
56 break;
57 default:
58 return;
59 }
60 }
61
62 void ButtonInkDropDelegate::OnGestureEvent(ui::GestureEvent* event) {
63 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState();
64
65 InkDropState ink_drop_state = InkDropState::HIDDEN;
66 switch (event->type()) {
67 case ui::ET_GESTURE_TAP_DOWN:
68 ink_drop_state = InkDropState::ACTION_PENDING;
69 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that
70 // subsequent events for the gesture are sent to |this|.
71 event->SetHandled();
72 break;
73 case ui::ET_GESTURE_LONG_PRESS:
74 ink_drop_state = InkDropState::ALTERNATE_ACTION_PENDING;
75 break;
76 case ui::ET_GESTURE_LONG_TAP:
77 ink_drop_state = InkDropState::ALTERNATE_ACTION_TRIGGERED;
78 break;
79 case ui::ET_GESTURE_END:
80 if (current_ink_drop_state == InkDropState::ACTIVATED)
81 return;
82 // Fall through to ui::ET_GESTURE_SCROLL_BEGIN case.
83 case ui::ET_GESTURE_SCROLL_BEGIN:
84 ink_drop_state = InkDropState::HIDDEN;
85 break;
86 default:
87 return;
88 }
89
90 last_ink_drop_location_ = event->location();
91
92 if (ink_drop_state == InkDropState::HIDDEN &&
93 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED ||
94 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED ||
95 current_ink_drop_state == InkDropState::DEACTIVATED)) {
96 // These InkDropStates automatically transition to the HIDDEN state so we
97 // don't make an explicit call. Explicitly animating to HIDDEN in this case
98 // would prematurely pre-empt these animations.
99 return;
100 }
101 ink_drop_->AnimateToState(ink_drop_state);
102 }
103
104 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/button_ink_drop_delegate.h ('k') | ui/views/animation/ink_drop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698