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

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 a rebase issue. 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
oshima 2014/07/22 21:30:46 remove this
oshima 2014/07/22 21:32:03 Sorry for incomplete comments. What I meant is tha
mfomitchev 2014/07/22 22:22:01 Done.
mfomitchev 2014/07/22 22:22:01 Done.
13 // Using bezel swipes, the first touch that is registered is usually within
14 // 5-10 pixels from the edge, but sometimes as far as 29 pixels away.
15 // So setting this width fairly high for now.
16 const float BezelController::kBezelWidth = 20.0f;
17
18 const float BezelController::kScrollPositionNone = -100;
19
20 BezelController::BezelController(aura::Window* container)
21 : container_(container),
22 num_fingers_down_(0),
23 state_(NO_FINGERS_DOWN),
24 scroll_bezel_(BEZEL_NONE),
25 left_right_delegate_(NULL) {
26 }
27
28 float BezelController::GetDistance(const gfx::PointF& position,
29 BezelController::Bezel bezel) {
30 DCHECK(bezel == BEZEL_LEFT || bezel == BEZEL_RIGHT);
31 return bezel == BEZEL_LEFT
32 ? position.x()
33 : position.x() - container_->GetBoundsInScreen().width();
34 }
35
36 void BezelController::SetState(BezelController::State state,
37 const gfx::PointF& scroll_position) {
38 if (left_right_delegate_) {
39 if (state != state_) {
sadrul 2014/07/22 21:53:19 early outing here if state_ == state would make th
mfomitchev 2014/07/22 22:22:01 Done.
40 if (state == BEZEL_SCROLLING_TWO_FINGERS) {
41 float delta = GetDistance(scroll_position, scroll_bezel_);
42 left_right_delegate_->ScrollBegin(scroll_bezel_, delta);
43 } else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) {
44 left_right_delegate_->ScrollEnd();
45 }
46 }
47 }
48 state_ = state;
49 if (state_ == IGNORE || state == NO_FINGERS_DOWN)
50 scroll_bezel_ = BEZEL_NONE;
51 }
52
53 // Only implemented for LEFT and RIGHT bezels ATM.
54 BezelController::Bezel BezelController::GetBezel(const gfx::PointF& location) {
55 if (location.x() < kBezelWidth) {
56 return BEZEL_LEFT;
57 } else if (location.x() >
58 container_->GetBoundsInScreen().width() - kBezelWidth) {
59 return BEZEL_RIGHT;
60 } else {
61 return BEZEL_NONE;
62 }
63 }
64
65 bool BezelController::ShouldProcessGesture(ui::EventType event_type) {
oshima 2014/07/22 21:30:46 Move this to anonymouse namespace as it doesn't de
mfomitchev 2014/07/22 22:22:01 Done.
66 return event_type == ui::ET_GESTURE_SCROLL_UPDATE ||
67 event_type == ui::ET_GESTURE_SCROLL_BEGIN ||
68 event_type == ui::ET_GESTURE_BEGIN;
69 }
70
71 void BezelController::OnTouchEvent(ui::TouchEvent* event) {
72 if (!left_right_delegate_)
73 return;
74
75 // TODO (mfomitchev): Currently we aren't retargetting or consuming any of the
76 // touch events. This means that content can prevent the generation of gesture
77 // events and two-finger scroll won't work. Possible solution to this problem
78 // is hosting our own gesture recognizer or retargetting touch events at the
79 // bezel.
sadrul 2014/07/22 21:53:19 On chromeos/x11, we do this by using a --touch-cal
mfomitchev 2014/07/22 22:22:01 Thanks for the pointer. Discussed offline: Ideally
80
81 ui::EventType type = event->type();
82 if (type == ui::ET_TOUCH_PRESSED) {
83 num_fingers_down_++;
oshima 2014/07/22 21:30:46 shouldn't you use event->finger_count() instead?
mfomitchev 2014/07/22 22:22:01 finger_count() is defined for ScrollEvent, not for
oshima 2014/07/22 23:26:47 I see. sadrul@, does it make sense to have a finge
84 BezelController::Bezel event_bezel =
85 GetBezel(gfx::PointF(event->x(), event->y()));
oshima 2014/07/22 21:30:46 event->location()
mfomitchev 2014/07/22 22:22:01 Done.
86
87 if (num_fingers_down_ > 2 ||
88 (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT)) {
89 SetState(IGNORE, gfx::Point(kScrollPositionNone, kScrollPositionNone));
90 return;
91 }
92
93 switch (state_) {
94 case NO_FINGERS_DOWN:
95 SetState(BEZEL_GESTURE_STARTED,
96 gfx::Point(kScrollPositionNone, kScrollPositionNone));
97 scroll_bezel_ = event_bezel;
98 return;
99 case IGNORE:
100 case BEZEL_GESTURE_STARTED:
101 return;
102 case BEZEL_SCROLLING_ONE_FINGER:
103 if (event_bezel != scroll_bezel_)
104 SetState(IGNORE,
105 gfx::Point(kScrollPositionNone, kScrollPositionNone));
106 return;
107 case BEZEL_SCROLLING_TWO_FINGERS:
108 // Should've exited above
109 NOTREACHED();
110 return;
111 };
sadrul 2014/07/22 21:53:19 Remove ;
mfomitchev 2014/07/22 22:22:01 Done.
112 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
113 num_fingers_down_--;
114 DCHECK_NE(state_, NO_FINGERS_DOWN);
115 // The finger beeing lifted gets counted for touch_points.
116 if (num_fingers_down_ == 0) {
117 SetState(NO_FINGERS_DOWN,
118 gfx::Point(kScrollPositionNone, kScrollPositionNone));
119 } else {
120 // Lifting fingers means the user is doing a gesture other than 2-finger
121 // scrolling.
122 SetState(IGNORE,
123 gfx::Point(kScrollPositionNone, kScrollPositionNone));
124 }
125 }
126 }
127
128 void BezelController::OnGestureEvent(ui::GestureEvent* event) {
129 if (!left_right_delegate_)
130 return;
131
132 ui::EventType type = event->type();
133 if (!ShouldProcessGesture(type))
134 return;
135
136 gfx::PointF event_location = event->location_f();
oshima 2014/07/22 21:30:46 const gfx::PointF&
mfomitchev 2014/07/22 22:22:01 Done.
137 const ui::GestureEventDetails& event_details = event->details();
138
139 if (type == ui::ET_GESTURE_BEGIN && event_details.touch_points() == 2 &&
140 state_ == BEZEL_SCROLLING_ONE_FINGER) {
141 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location);
142 } else if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
143 DCHECK(state_ == IGNORE || state_ == BEZEL_GESTURE_STARTED);
144 if (state_ == BEZEL_GESTURE_STARTED) {
145 if (num_fingers_down_ == 1) {
146 SetState(BEZEL_SCROLLING_ONE_FINGER, event_location);
147 } else {
148 DCHECK_EQ(num_fingers_down_, 2);
149 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location);
150 if (left_right_delegate_->CanScroll()) {
151 event->SetHandled();
152 event->StopPropagation();
153 }
154 }
155 }
156 } else if (type == ui::ET_GESTURE_SCROLL_UPDATE) {
157 if (state_ == BEZEL_SCROLLING_TWO_FINGERS) {
158 float scroll_delta = GetDistance(event_location, scroll_bezel_);
159 left_right_delegate_->ScrollUpdate(scroll_delta);
160 if (left_right_delegate_->CanScroll()) {
161 event->SetHandled();
162 event->StopPropagation();
163 }
164 }
165 }
sadrul 2014/07/22 21:53:18 Prefer early-outs where possible.
mfomitchev 2014/07/22 22:22:01 Done.
166 }
167
168 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698