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

Side by Side Diff: ui/chromeos/touch_exploration_controller.cc

Issue 358693004: Added touch event permutations test to touch_exploration_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_passthrough
Patch Set: 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/chromeos/touch_exploration_controller.h" 5 #include "ui/chromeos/touch_exploration_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "ui/aura/client/cursor_client.h" 9 #include "ui/aura/client/cursor_client.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 bool TouchExplorationController::IsInNoFingersDownStateForTesting() const { 47 bool TouchExplorationController::IsInNoFingersDownStateForTesting() const {
48 return state_ == NO_FINGERS_DOWN; 48 return state_ == NO_FINGERS_DOWN;
49 } 49 }
50 50
51 ui::EventRewriteStatus TouchExplorationController::RewriteEvent( 51 ui::EventRewriteStatus TouchExplorationController::RewriteEvent(
52 const ui::Event& event, 52 const ui::Event& event,
53 scoped_ptr<ui::Event>* rewritten_event) { 53 scoped_ptr<ui::Event>* rewritten_event) {
54 if (!event.IsTouchEvent()) { 54 if (!event.IsTouchEvent()) {
55 if (event.IsKeyEvent()) { 55 if (event.IsKeyEvent()) {
56 const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event); 56 const ui::KeyEvent& key_event = static_cast<const ui::KeyEvent&>(event);
57 VLOG(0) << "\nKeyboard event: " << key_event.name() << "\n" 57 VLOG(0) << "\nKeyboard event: " << key_event.name()
58 << " Key code: " << key_event.key_code() 58 << "\n Key code: " << key_event.key_code()
59 << ", Flags: " << key_event.flags() 59 << ", Flags: " << key_event.flags()
60 << ", Is char: " << key_event.is_char(); 60 << ", Is char: " << key_event.is_char();
61 } 61 }
62 if(event.IsGestureEvent()){ 62 if(event.IsGestureEvent()){
63 VLOG(0) << "\n Gesture event " << event.name(); 63 VLOG(0) << "\n Gesture event " << event.name();
64 } 64 }
65 return ui::EVENT_REWRITE_CONTINUE; 65 return ui::EVENT_REWRITE_CONTINUE;
66 } 66 }
67 const ui::TouchEvent& touch_event = static_cast<const ui::TouchEvent&>(event); 67 const ui::TouchEvent& touch_event = static_cast<const ui::TouchEvent&>(event);
68 68
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 initial_press_.reset(new TouchEvent(event)); 149 initial_press_.reset(new TouchEvent(event));
150 last_unused_finger_event_.reset(new TouchEvent(event)); 150 last_unused_finger_event_.reset(new TouchEvent(event));
151 tap_timer_.Start(FROM_HERE, 151 tap_timer_.Start(FROM_HERE,
152 gesture_detector_config_.double_tap_timeout, 152 gesture_detector_config_.double_tap_timeout,
153 this, 153 this,
154 &TouchExplorationController::OnTapTimerFired); 154 &TouchExplorationController::OnTapTimerFired);
155 state_ = SINGLE_TAP_PRESSED; 155 state_ = SINGLE_TAP_PRESSED;
156 VLOG_STATE(); 156 VLOG_STATE();
157 return ui::EVENT_REWRITE_DISCARD; 157 return ui::EVENT_REWRITE_DISCARD;
158 } 158 }
159 NOTREACHED() << "Unexpected event type received."; 159 NOTREACHED() << "Unexpected event type received: " << event.name();;
160 return ui::EVENT_REWRITE_CONTINUE; 160 return ui::EVENT_REWRITE_CONTINUE;
161 } 161 }
162 162
163 ui::EventRewriteStatus TouchExplorationController::InSingleTapPressed( 163 ui::EventRewriteStatus TouchExplorationController::InSingleTapPressed(
164 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { 164 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) {
165 const ui::EventType type = event.type(); 165 const ui::EventType type = event.type();
166 166
167 if (type == ui::ET_TOUCH_PRESSED) { 167 if (type == ui::ET_TOUCH_PRESSED) {
168 // Adding a second finger within the timeout period switches to 168 // Adding a second finger within the timeout period switches to
169 // passing through every event from the second finger and none form the 169 // passing through every event from the second finger and none form the
(...skipping 19 matching lines...) Expand all
189 // high enough, and touch exploration if the velocity is lower. 189 // high enough, and touch exploration if the velocity is lower.
190 float delta = (event.location() - initial_press_->location()).Length(); 190 float delta = (event.location() - initial_press_->location()).Length();
191 if (delta > gesture_detector_config_.touch_slop) { 191 if (delta > gesture_detector_config_.touch_slop) {
192 EnterTouchToMouseMode(); 192 EnterTouchToMouseMode();
193 state_ = TOUCH_EXPLORATION; 193 state_ = TOUCH_EXPLORATION;
194 VLOG_STATE(); 194 VLOG_STATE();
195 return InTouchExploration(event, rewritten_event); 195 return InTouchExploration(event, rewritten_event);
196 } 196 }
197 return EVENT_REWRITE_DISCARD; 197 return EVENT_REWRITE_DISCARD;
198 } 198 }
199 NOTREACHED() << "Unexpected event type received."; 199 NOTREACHED() << "Unexpected event type received: " << event.name();;
200 return ui::EVENT_REWRITE_CONTINUE; 200 return ui::EVENT_REWRITE_CONTINUE;
201 } 201 }
202 202
203 ui::EventRewriteStatus 203 ui::EventRewriteStatus
204 TouchExplorationController::InSingleTapOrTouchExploreReleased( 204 TouchExplorationController::InSingleTapOrTouchExploreReleased(
205 const ui::TouchEvent& event, 205 const ui::TouchEvent& event,
206 scoped_ptr<ui::Event>* rewritten_event) { 206 scoped_ptr<ui::Event>* rewritten_event) {
207 const ui::EventType type = event.type(); 207 const ui::EventType type = event.type();
208 if (type == ui::ET_TOUCH_PRESSED) { 208 if (type == ui::ET_TOUCH_PRESSED) {
209 // This is the second tap in a double-tap (or double tap-hold). 209 // This is the second tap in a double-tap (or double tap-hold).
(...skipping 11 matching lines...) Expand all
221 state_ = DOUBLE_TAP_PRESSED; 221 state_ = DOUBLE_TAP_PRESSED;
222 VLOG_STATE(); 222 VLOG_STATE();
223 return ui::EVENT_REWRITE_REWRITTEN; 223 return ui::EVENT_REWRITE_REWRITTEN;
224 } else if (type == ui::ET_TOUCH_RELEASED && !last_touch_exploration_) { 224 } else if (type == ui::ET_TOUCH_RELEASED && !last_touch_exploration_) {
225 // If the previous press was discarded, we need to also handle its 225 // If the previous press was discarded, we need to also handle its
226 // release. 226 // release.
227 if (current_touch_ids_.size() == 0) { 227 if (current_touch_ids_.size() == 0) {
228 ResetToNoFingersDown(); 228 ResetToNoFingersDown();
229 } 229 }
230 return ui::EVENT_REWRITE_DISCARD; 230 return ui::EVENT_REWRITE_DISCARD;
231 } else if (type == ui::ET_TOUCH_MOVED){
232 return ui::EVENT_REWRITE_DISCARD;
231 } 233 }
232 NOTREACHED() << "Unexpected event type received."; 234 NOTREACHED() << "Unexpected event type received: " << event.name();
233 return ui::EVENT_REWRITE_CONTINUE; 235 return ui::EVENT_REWRITE_CONTINUE;
234 } 236 }
235 237
236 ui::EventRewriteStatus TouchExplorationController::InDoubleTapPressed( 238 ui::EventRewriteStatus TouchExplorationController::InDoubleTapPressed(
237 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { 239 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) {
238 const ui::EventType type = event.type(); 240 const ui::EventType type = event.type();
239 if (type == ui::ET_TOUCH_PRESSED) { 241 if (type == ui::ET_TOUCH_PRESSED) {
240 return ui::EVENT_REWRITE_DISCARD; 242 return ui::EVENT_REWRITE_DISCARD;
241 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { 243 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
242 if (current_touch_ids_.size() != 0) 244 if (current_touch_ids_.size() != 0)
243 return EVENT_REWRITE_DISCARD; 245 return EVENT_REWRITE_DISCARD;
244 246
245 // Rewrite release at location of last touch exploration with the same 247 // Rewrite release at location of last touch exploration with the same
246 // id as the prevoius press. 248 // id as the prevoius press.
247 rewritten_event->reset( 249 rewritten_event->reset(
248 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, 250 new ui::TouchEvent(ui::ET_TOUCH_RELEASED,
249 last_touch_exploration_->location(), 251 last_touch_exploration_->location(),
250 initial_press_->touch_id(), 252 initial_press_->touch_id(),
251 event.time_stamp())); 253 event.time_stamp()));
252 (*rewritten_event)->set_flags(event.flags()); 254 (*rewritten_event)->set_flags(event.flags());
253 ResetToNoFingersDown(); 255 ResetToNoFingersDown();
254 return ui::EVENT_REWRITE_REWRITTEN; 256 return ui::EVENT_REWRITE_REWRITTEN;
255 } else if (type == ui::ET_TOUCH_MOVED) { 257 } else if (type == ui::ET_TOUCH_MOVED) {
256 return ui::EVENT_REWRITE_DISCARD; 258 return ui::EVENT_REWRITE_DISCARD;
257 } 259 }
258 NOTREACHED() << "Unexpected event type received."; 260 NOTREACHED() << "Unexpected event type received: " << event.name();
259 return ui::EVENT_REWRITE_CONTINUE; 261 return ui::EVENT_REWRITE_CONTINUE;
260 } 262 }
261 263
262 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( 264 ui::EventRewriteStatus TouchExplorationController::InTouchExploration(
263 const ui::TouchEvent& event, 265 const ui::TouchEvent& event,
264 scoped_ptr<ui::Event>* rewritten_event) { 266 scoped_ptr<ui::Event>* rewritten_event) {
265 const ui::EventType type = event.type(); 267 const ui::EventType type = event.type();
266 if (type == ui::ET_TOUCH_PRESSED) { 268 if (type == ui::ET_TOUCH_PRESSED) {
267 // Handle split-tap. 269 // Handle split-tap.
268 initial_press_.reset(new TouchEvent(event)); 270 initial_press_.reset(new TouchEvent(event));
(...skipping 10 matching lines...) Expand all
279 return ui::EVENT_REWRITE_REWRITTEN; 281 return ui::EVENT_REWRITE_REWRITTEN;
280 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { 282 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
281 initial_press_.reset(new TouchEvent(event)); 283 initial_press_.reset(new TouchEvent(event));
282 tap_timer_.Start(FROM_HERE, 284 tap_timer_.Start(FROM_HERE,
283 gesture_detector_config_.double_tap_timeout, 285 gesture_detector_config_.double_tap_timeout,
284 this, 286 this,
285 &TouchExplorationController::OnTapTimerFired); 287 &TouchExplorationController::OnTapTimerFired);
286 state_ = TOUCH_EXPLORE_RELEASED; 288 state_ = TOUCH_EXPLORE_RELEASED;
287 VLOG_STATE(); 289 VLOG_STATE();
288 } else if (type != ui::ET_TOUCH_MOVED) { 290 } else if (type != ui::ET_TOUCH_MOVED) {
289 NOTREACHED() << "Unexpected event type received."; 291 NOTREACHED() << "Unexpected event type received: " << event.name();
290 return ui::EVENT_REWRITE_CONTINUE; 292 return ui::EVENT_REWRITE_CONTINUE;
291 } 293 }
292 294
293 // Rewrite as a mouse-move event. 295 // Rewrite as a mouse-move event.
294 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags()); 296 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags());
295 last_touch_exploration_.reset(new TouchEvent(event)); 297 last_touch_exploration_.reset(new TouchEvent(event));
296 return ui::EVENT_REWRITE_REWRITTEN; 298 return ui::EVENT_REWRITE_REWRITTEN;
297 } 299 }
298 300
299 301
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if (event.touch_id() == last_two_to_one_->touch_id()) { 347 if (event.touch_id() == last_two_to_one_->touch_id()) {
346 last_two_to_one_.reset(new TouchEvent(event)); 348 last_two_to_one_.reset(new TouchEvent(event));
347 rewritten_event->reset(new ui::TouchEvent(ui::ET_TOUCH_MOVED, 349 rewritten_event->reset(new ui::TouchEvent(ui::ET_TOUCH_MOVED,
348 event.location(), 350 event.location(),
349 event.touch_id(), 351 event.touch_id(),
350 event.time_stamp())); 352 event.time_stamp()));
351 (*rewritten_event)->set_flags(event.flags()); 353 (*rewritten_event)->set_flags(event.flags());
352 return ui::EVENT_REWRITE_REWRITTEN; 354 return ui::EVENT_REWRITE_REWRITTEN;
353 } 355 }
354 } 356 }
355 NOTREACHED() << "Unexpected event type received"; 357 NOTREACHED() << "Unexpected event type received: " << event.name();
356 return ui::EVENT_REWRITE_CONTINUE; 358 return ui::EVENT_REWRITE_CONTINUE;
357 } 359 }
358 360
359 ui::EventRewriteStatus TouchExplorationController::InPassthrough( 361 ui::EventRewriteStatus TouchExplorationController::InPassthrough(
360 const ui::TouchEvent& event, 362 const ui::TouchEvent& event,
361 scoped_ptr<ui::Event>* rewritten_event) { 363 scoped_ptr<ui::Event>* rewritten_event) {
362 ui::EventType type = event.type(); 364 ui::EventType type = event.type();
363 365
364 if (!(type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED || 366 if (!(type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED ||
365 type == ui::ET_TOUCH_MOVED || type == ui::ET_TOUCH_PRESSED)) { 367 type == ui::ET_TOUCH_MOVED || type == ui::ET_TOUCH_PRESSED)) {
366 NOTREACHED() << "Unexpected event type received."; 368 NOTREACHED() << "Unexpected event type received: " << event.name();
367 return ui::EVENT_REWRITE_CONTINUE; 369 return ui::EVENT_REWRITE_CONTINUE;
368 } 370 }
369 371
370 rewritten_event->reset(new ui::TouchEvent( 372 rewritten_event->reset(new ui::TouchEvent(
371 type, event.location(), event.touch_id(), event.time_stamp())); 373 type, event.location(), event.touch_id(), event.time_stamp()));
372 (*rewritten_event)->set_flags(event.flags()); 374 (*rewritten_event)->set_flags(event.flags());
373 375
374 if (current_touch_ids_.size() == 0) { 376 if (current_touch_ids_.size() == 0) {
375 ResetToNoFingersDown(); 377 ResetToNoFingersDown();
376 } 378 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 rewritten_event->reset( 410 rewritten_event->reset(
409 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, 411 new ui::TouchEvent(ui::ET_TOUCH_RELEASED,
410 last_touch_exploration_->location(), 412 last_touch_exploration_->location(),
411 initial_press_->touch_id(), 413 initial_press_->touch_id(),
412 event.time_stamp())); 414 event.time_stamp()));
413 (*rewritten_event)->set_flags(event.flags()); 415 (*rewritten_event)->set_flags(event.flags());
414 state_ = TOUCH_EXPLORATION; 416 state_ = TOUCH_EXPLORATION;
415 VLOG_STATE(); 417 VLOG_STATE();
416 return ui::EVENT_REWRITE_REWRITTEN; 418 return ui::EVENT_REWRITE_REWRITTEN;
417 } 419 }
418 NOTREACHED() << "Unexpected event type received."; 420 NOTREACHED() << "Unexpected event type received: " << event.name();
419 return ui::EVENT_REWRITE_CONTINUE; 421 return ui::EVENT_REWRITE_CONTINUE;
420 } 422 }
421 423
422 ui::EventRewriteStatus TouchExplorationController::InWaitForRelease( 424 ui::EventRewriteStatus TouchExplorationController::InWaitForRelease(
423 const ui::TouchEvent& event, 425 const ui::TouchEvent& event,
424 scoped_ptr<ui::Event>* rewritten_event) { 426 scoped_ptr<ui::Event>* rewritten_event) {
425 ui::EventType type = event.type(); 427 ui::EventType type = event.type();
426 if (!(type == ui::ET_TOUCH_PRESSED || type == ui::ET_TOUCH_MOVED || 428 if (!(type == ui::ET_TOUCH_PRESSED || type == ui::ET_TOUCH_MOVED ||
427 type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED)) { 429 type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED)) {
428 NOTREACHED() << "Unexpected event type received."; 430 NOTREACHED() << "Unexpected event type received: " << event.name();
429 return ui::EVENT_REWRITE_CONTINUE; 431 return ui::EVENT_REWRITE_CONTINUE;
430 } 432 }
431 if (current_touch_ids_.size() == 0) { 433 if (current_touch_ids_.size() == 0) {
432 state_ = NO_FINGERS_DOWN; 434 state_ = NO_FINGERS_DOWN;
433 ResetToNoFingersDown(); 435 ResetToNoFingersDown();
434 } 436 }
435 return EVENT_REWRITE_DISCARD; 437 return EVENT_REWRITE_DISCARD;
436 } 438 }
437 439
438 void TouchExplorationController::OnTapTimerFired() { 440 void TouchExplorationController::OnTapTimerFired() {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 return "TWO_TO_ONE_FINGER"; 554 return "TWO_TO_ONE_FINGER";
553 case PASSTHROUGH: 555 case PASSTHROUGH:
554 return "PASSTHROUGH"; 556 return "PASSTHROUGH";
555 case WAIT_FOR_RELEASE: 557 case WAIT_FOR_RELEASE:
556 return "WAIT_FOR_RELEASE"; 558 return "WAIT_FOR_RELEASE";
557 } 559 }
558 return "Not a state"; 560 return "Not a state";
559 } 561 }
560 562
561 } // namespace ui 563 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698