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

Side by Side Diff: athena/wm/bezel_controller.cc

Issue 394833004: Split View Mode: Support for the 2-finger bezel scroll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing scroll update. Created 6 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2014 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 "athena/wm/bezel_controller.h"
6
7 #include "ui/aura/window.h"
8 #include "ui/events/event_handler.h"
9
10 namespace athena {
11
12 // static
13 // Using bezel swipes on Nexus 10, the first touch that is registered is
oshima 2014/07/22 17:56:11 please remove the reference to specific hw
mfomitchev 2014/07/22 19:20:22 Done.
14 // usually within 5-10 pixels from the edge, but sometimes as far as 29
15 // pixels away. So setting this width fairly high.
16 const float BezelController::kBezelWidth = 20.0f;
17
18 // static
19 const gfx::PointF& BezelController::kScrollPositionNone =
20 gfx::PointF(-100, -100);
oshima 2014/07/22 17:56:11 won't this create static initializer?
mfomitchev 2014/07/22 19:20:22 Done. Just constructing gfx::Point when I need it
21
22 BezelController::BezelController(aura::Window* container)
23 : container_(container),
24 num_fingers_down_(0),
25 state_(NO_FINGERS_DOWN),
26 scroll_bezel_(BEZEL_NONE),
27 left_right_delegate_(NULL) {
28 }
29
30 float BezelController::GetDistance(const gfx::PointF& position,
31 BezelController::Bezel bezel) {
32 DCHECK(bezel == BEZEL_LEFT || bezel == BEZEL_RIGHT);
33 return bezel == BEZEL_LEFT
34 ? position.x()
35 : position.x() - container_->GetBoundsInScreen().width();
36 }
37
38 void BezelController::SetState(BezelController::State state,
39 const gfx::PointF& scroll_position) {
40 if (left_right_delegate_) {
41 if (state != state_) {
42 if (state == BEZEL_SCROLLING_TWO_FINGERS) {
43 float delta = GetDistance(scroll_position, scroll_bezel_);
44 left_right_delegate_->ScrollBegin(scroll_bezel_, delta);
45 } else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) {
46 left_right_delegate_->ScrollEnd();
47 }
48 }
49 }
50 state_ = state;
51 if (state_ == IGNORE || state == NO_FINGERS_DOWN) {
52 scroll_bezel_ = BEZEL_NONE;
53 }
oshima 2014/07/22 17:56:12 nuke {}
mfomitchev 2014/07/22 19:20:22 Done.
54 }
55
56 // Only implemented for LEFT and RIGHT bezels ATM.
57 BezelController::Bezel BezelController::GetBezel(const gfx::PointF& location) {
58 if (location.x() < kBezelWidth) {
59 return BEZEL_LEFT;
60 } else if (location.x() >
61 container_->GetBoundsInScreen().width() - kBezelWidth) {
62 return BEZEL_RIGHT;
63 } else {
64 return BEZEL_NONE;
65 }
66 }
67
68 bool BezelController::ShouldProcessGesture(ui::EventType event_type) {
69 return event_type == ui::ET_GESTURE_SCROLL_UPDATE ||
70 event_type == ui::ET_GESTURE_SCROLL_BEGIN ||
71 event_type == ui::ET_GESTURE_BEGIN;
72 }
73
74 void BezelController::OnTouchEvent(ui::TouchEvent* event) {
75 if (!left_right_delegate_)
76 return;
77
78 // TODO (mfomitchev): Currently we aren't retargetting or consuming any of the
79 // touch events. This means that content can prevent the generation of gesture
80 // events and two-finger scroll won't work. Possible solution to this problem
81 // is hosting our own gesture recognizer or retargetting touch events at the
82 // bezel.
83
84 ui::EventType type = event->type();
85 if (type == ui::ET_TOUCH_PRESSED) {
86 num_fingers_down_++;
87 BezelController::Bezel event_bezel =
88 GetBezel(gfx::PointF(event->x(), event->y()));
89
90 if (num_fingers_down_ > 2 ||
91 (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT)) {
92 SetState(IGNORE, kScrollPositionNone);
93 return;
94 }
95
96 switch (state_) {
97 case NO_FINGERS_DOWN:
98 SetState(BEZEL_GESTURE_STARTED, kScrollPositionNone);
99 scroll_bezel_ = event_bezel;
100 return;
101 case IGNORE:
102 case BEZEL_GESTURE_STARTED:
103 return;
104 case BEZEL_SCROLLING_ONE_FINGER:
105 if (event_bezel != scroll_bezel_)
106 SetState(IGNORE, kScrollPositionNone);
107 return;
108 case BEZEL_SCROLLING_TWO_FINGERS:
109 // Should've exited above
110 NOTREACHED();
111 return;
112 };
113 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
114 num_fingers_down_--;
115 DCHECK_NE(state_, NO_FINGERS_DOWN);
116 // The finger beeing lifted gets counted for touch_points.
117 if (num_fingers_down_ == 0) {
118 SetState(NO_FINGERS_DOWN, kScrollPositionNone);
119 } else {
120 // Lifting fingers means the user is doing a gesture other than 2-finger
121 // scrolling.
122 SetState(IGNORE, kScrollPositionNone);
123 }
124 }
125 }
126
127 void BezelController::OnGestureEvent(ui::GestureEvent* event) {
128 if (!left_right_delegate_)
129 return;
130
131 ui::EventType type = event->type();
132 if (!ShouldProcessGesture(type))
133 return;
134
135 gfx::PointF event_location = event->location_f();
136 const ui::GestureEventDetails& event_details = event->details();
137
138 if (type == ui::ET_GESTURE_BEGIN && event_details.touch_points() == 2 &&
139 state_ == BEZEL_SCROLLING_ONE_FINGER) {
140 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location);
141 } else if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
142 DCHECK(state_ == IGNORE || state_ == BEZEL_GESTURE_STARTED);
143 if (state_ == BEZEL_GESTURE_STARTED) {
144 if (num_fingers_down_ == 1) {
145 SetState(BEZEL_SCROLLING_ONE_FINGER, event_location);
146 } else {
147 DCHECK_EQ(num_fingers_down_, 2);
148 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location);
149 if (left_right_delegate_->CanScroll()) {
150 event->SetHandled();
151 event->StopPropagation();
152 }
153 }
154 }
155 } else if (type == ui::ET_GESTURE_SCROLL_UPDATE) {
156 if (state_ == BEZEL_SCROLLING_TWO_FINGERS) {
157 float scroll_delta = GetDistance(event_location, scroll_bezel_);
158 left_right_delegate_->ScrollUpdate(scroll_delta);
159 if (left_right_delegate_->CanScroll()) {
160 event->SetHandled();
161 event->StopPropagation();
162 }
163 }
164 }
165 }
166
167 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698