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

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: Removing accidental edit. 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
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);
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(
31 const gfx::PointF& position, 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
Jun Mukai 2014/07/21 17:18:52 nit: remove this blank line
mfomitchev 2014/07/21 17:31:47 Done.
37 }
38
39 void BezelController::SetState(BezelController::State state,
40 const gfx::PointF& scroll_position) {
41 if (left_right_delegate_) {
42 if (state != state_) {
43 if (state == BEZEL_SCROLLING_TWO_FINGERS) {
44 float delta = GetDistance(scroll_position, scroll_bezel_);
45 left_right_delegate_->ScrollBegin(scroll_bezel_, delta);
46 } else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) {
47 left_right_delegate_->ScrollEnd();
48 }
49 }
50 }
51 state_ = state;
52 if (state_ == IGNORE || state == NO_FINGERS_DOWN) {
53 scroll_bezel_ = BEZEL_NONE;
54 }
55 }
56
57 // Only implemented for LEFT and RIGHT bezels ATM.
58 BezelController::Bezel BezelController::GetBezel(const gfx::PointF& location) {
59 if (location.x() < kBezelWidth) {
60 return BEZEL_LEFT;
61 } else if (
62 location.x() > container_->GetBoundsInScreen().width() - kBezelWidth) {
63 return BEZEL_RIGHT;
64 } else {
65 return BEZEL_NONE;
66 }
67 }
68
69 bool BezelController::ShouldProcessGesture(ui::EventType event_type) {
70 return event_type == ui::ET_GESTURE_SCROLL_UPDATE ||
71 event_type == ui::ET_GESTURE_SCROLL_BEGIN ||
72 event_type == ui::ET_GESTURE_BEGIN;
73 }
74
Jun Mukai 2014/07/21 17:18:52 nit: remove this blank line
mfomitchev 2014/07/21 17:31:47 Done.
75
76 void BezelController::OnTouchEvent(ui::TouchEvent* event) {
77 if (!left_right_delegate_)
78 return;
79
80 // TODO: Currently we aren't retargetting or consuming any of the touch
Jun Mukai 2014/07/21 17:18:52 TODO should have the owner name. TODO(mfomitchev):
mfomitchev 2014/07/21 17:31:47 Done.
81 // events. This means that content can prevent the generation of gesture
82 // events and two-finger scroll won't work. Possible solution to this problem
83 // is hosting our own gesture recognizer or retargetting touch events at the
84 // bezel.
85
86 ui::EventType type = event->type();
87 if (type == ui::ET_TOUCH_PRESSED) {
88 num_fingers_down_++;
89 BezelController::Bezel event_bezel =
90 GetBezel(gfx::PointF(event->x(), event->y()));
91
92 if (num_fingers_down_ > 2 ||
93 (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT)) {
94 SetState(IGNORE, kScrollPositionNone);
95 return;
96 }
97
98 switch (state_) {
99 case NO_FINGERS_DOWN:
100 SetState(BEZEL_GESTURE_STARTED, kScrollPositionNone);
101 scroll_bezel_ = event_bezel;
102 return;
103 case IGNORE:
104 case BEZEL_GESTURE_STARTED:
105 return;
106 case BEZEL_SCROLLING_ONE_FINGER:
107 if (event_bezel != scroll_bezel_)
108 SetState(IGNORE, kScrollPositionNone);
109 return;
110 case BEZEL_SCROLLING_TWO_FINGERS:
111 // Should've exited above
112 CHECK(false);
113 //NOTREACHED();
Jun Mukai 2014/07/21 17:18:52 I think it's okay to be NOTREACHED(). Anyways, ple
mfomitchev 2014/07/21 17:31:47 Done. Also replaced all CHECKs with DCHECKs - mean
114 return;
115 };
116 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
117 num_fingers_down_--;
118 CHECK_NE(state_, NO_FINGERS_DOWN);
119 // The finger beeing lifted gets counted for touch_points.
120 if (num_fingers_down_ == 0) {
121 SetState(NO_FINGERS_DOWN, kScrollPositionNone);
122 } else {
123 // Lifting fingers means the user is doing a gesture other than 2-finger
124 // scrolling.
125 SetState(IGNORE, kScrollPositionNone);
126 }
127 return;
Jun Mukai 2014/07/21 17:18:52 unnecessary to return; Anyways no further code exi
mfomitchev 2014/07/21 17:31:47 Done.
128 }
129 }
130
Jun Mukai 2014/07/21 17:18:52 nit: remove this blank line
mfomitchev 2014/07/21 17:31:47 Done.
131
132 void BezelController::OnGestureEvent(ui::GestureEvent* event) {
133 if (!left_right_delegate_)
134 return;
135
136 ui::EventType type = event->type();
137 if (!ShouldProcessGesture(type))
138 return;
139
140 gfx::PointF event_location = event->location_f();
141 const ui::GestureEventDetails& event_details = event->details();
142
143 if (type == ui::ET_GESTURE_BEGIN &&
144 event_details.touch_points() == 2 &&
145 state_== BEZEL_SCROLLING_ONE_FINGER) {
Jun Mukai 2014/07/21 17:18:52 space between _ and ==
mfomitchev 2014/07/21 17:31:47 Done.
146 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location);
147 } else if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
148 CHECK(state_ == IGNORE || state_ == BEZEL_GESTURE_STARTED);
149 if (state_ == BEZEL_GESTURE_STARTED) {
150 if (num_fingers_down_ == 1) {
151 SetState(BEZEL_SCROLLING_ONE_FINGER, event_location);
152 } else {
153 CHECK_EQ(num_fingers_down_, 2);
154 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location);
155 if (left_right_delegate_->CanScroll()) {
156 event->SetHandled();
157 event->StopPropagation();
158 }
159 }
160 }
161 return;
Jun Mukai 2014/07/21 17:18:52 you don't have to return here
mfomitchev 2014/07/21 17:31:47 Done.
162 } else if (type == ui::ET_GESTURE_SCROLL_UPDATE) {
163 float scroll_delta = GetDistance(event_location, scroll_bezel_);
164 left_right_delegate_->ScrollUpdate(scroll_delta);
165 }
166 }
167
168 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698