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

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: updated NOTREACHED() logging and prevented the test from reaching the NOTREACHED() 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 state_ = NO_FINGERS_DOWN; 228 state_ = NO_FINGERS_DOWN;
229 } 229 }
230 return ui::EVENT_REWRITE_DISCARD; 230 return ui::EVENT_REWRITE_DISCARD;
231 } else if (type == ui::ET_TOUCH_MOVED){
232 LOG(WARNING) << "TOUCH_MOVED in InSingleTapOrTouchExploreReleased"
233 << " though there should not be any fingers down.";
234 return ui::EVENT_REWRITE_DISCARD;
231 } 235 }
232 NOTREACHED() << "Unexpected event type received.";; 236 NOTREACHED() << "Unexpected event type received: " << event.name();
233 return ui::EVENT_REWRITE_CONTINUE; 237 return ui::EVENT_REWRITE_CONTINUE;
234 } 238 }
235 239
236 ui::EventRewriteStatus TouchExplorationController::InDoubleTapPressed( 240 ui::EventRewriteStatus TouchExplorationController::InDoubleTapPressed(
237 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { 241 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) {
238 const ui::EventType type = event.type(); 242 const ui::EventType type = event.type();
239 if (type == ui::ET_TOUCH_PRESSED) { 243 if (type == ui::ET_TOUCH_PRESSED) {
240 return ui::EVENT_REWRITE_DISCARD; 244 return ui::EVENT_REWRITE_DISCARD;
241 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { 245 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
242 if (current_touch_ids_.size() != 0) 246 if (current_touch_ids_.size() != 0)
243 return EVENT_REWRITE_DISCARD; 247 return EVENT_REWRITE_DISCARD;
244 248
245 // Rewrite release at location of last touch exploration with the same 249 // Rewrite release at location of last touch exploration with the same
246 // id as the prevoius press. 250 // id as the prevoius press.
247 rewritten_event->reset( 251 rewritten_event->reset(
248 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, 252 new ui::TouchEvent(ui::ET_TOUCH_RELEASED,
249 last_touch_exploration_->location(), 253 last_touch_exploration_->location(),
250 initial_press_->touch_id(), 254 initial_press_->touch_id(),
251 event.time_stamp())); 255 event.time_stamp()));
252 (*rewritten_event)->set_flags(event.flags()); 256 (*rewritten_event)->set_flags(event.flags());
253 ResetToNoFingersDown(); 257 ResetToNoFingersDown();
254 return ui::EVENT_REWRITE_REWRITTEN; 258 return ui::EVENT_REWRITE_REWRITTEN;
255 } else if (type == ui::ET_TOUCH_MOVED) { 259 } else if (type == ui::ET_TOUCH_MOVED) {
256 return ui::EVENT_REWRITE_DISCARD; 260 return ui::EVENT_REWRITE_DISCARD;
257 } 261 }
258 NOTREACHED() << "Unexpected event type received."; 262 NOTREACHED() << "Unexpected event type received: " << event.name();
259 return ui::EVENT_REWRITE_CONTINUE; 263 return ui::EVENT_REWRITE_CONTINUE;
260 } 264 }
261 265
262 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( 266 ui::EventRewriteStatus TouchExplorationController::InTouchExploration(
263 const ui::TouchEvent& event, 267 const ui::TouchEvent& event,
264 scoped_ptr<ui::Event>* rewritten_event) { 268 scoped_ptr<ui::Event>* rewritten_event) {
265 const ui::EventType type = event.type(); 269 const ui::EventType type = event.type();
266 if (type == ui::ET_TOUCH_PRESSED) { 270 if (type == ui::ET_TOUCH_PRESSED) {
267 // Handle split-tap. 271 // Handle split-tap.
268 initial_press_.reset(new TouchEvent(event)); 272 initial_press_.reset(new TouchEvent(event));
(...skipping 10 matching lines...) Expand all
279 return ui::EVENT_REWRITE_REWRITTEN; 283 return ui::EVENT_REWRITE_REWRITTEN;
280 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { 284 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) {
281 initial_press_.reset(new TouchEvent(event)); 285 initial_press_.reset(new TouchEvent(event));
282 tap_timer_.Start(FROM_HERE, 286 tap_timer_.Start(FROM_HERE,
283 gesture_detector_config_.double_tap_timeout, 287 gesture_detector_config_.double_tap_timeout,
284 this, 288 this,
285 &TouchExplorationController::OnTapTimerFired); 289 &TouchExplorationController::OnTapTimerFired);
286 state_ = TOUCH_EXPLORE_RELEASED; 290 state_ = TOUCH_EXPLORE_RELEASED;
287 VLOG_STATE(); 291 VLOG_STATE();
288 } else if (type != ui::ET_TOUCH_MOVED) { 292 } else if (type != ui::ET_TOUCH_MOVED) {
289 NOTREACHED() << "Unexpected event type received."; 293 NOTREACHED() << "Unexpected event type received: " << event.name();
290 return ui::EVENT_REWRITE_CONTINUE; 294 return ui::EVENT_REWRITE_CONTINUE;
291 } 295 }
292 296
293 // Rewrite as a mouse-move event. 297 // Rewrite as a mouse-move event.
294 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags()); 298 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags());
295 last_touch_exploration_.reset(new TouchEvent(event)); 299 last_touch_exploration_.reset(new TouchEvent(event));
296 return ui::EVENT_REWRITE_REWRITTEN; 300 return ui::EVENT_REWRITE_REWRITTEN;
297 } 301 }
298 302
299 303
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if (event.touch_id() == last_two_to_one_->touch_id()) { 349 if (event.touch_id() == last_two_to_one_->touch_id()) {
346 last_two_to_one_.reset(new TouchEvent(event)); 350 last_two_to_one_.reset(new TouchEvent(event));
347 rewritten_event->reset(new ui::TouchEvent(ui::ET_TOUCH_MOVED, 351 rewritten_event->reset(new ui::TouchEvent(ui::ET_TOUCH_MOVED,
348 event.location(), 352 event.location(),
349 event.touch_id(), 353 event.touch_id(),
350 event.time_stamp())); 354 event.time_stamp()));
351 (*rewritten_event)->set_flags(event.flags()); 355 (*rewritten_event)->set_flags(event.flags());
352 return ui::EVENT_REWRITE_REWRITTEN; 356 return ui::EVENT_REWRITE_REWRITTEN;
353 } 357 }
354 } 358 }
355 NOTREACHED() << "Unexpected event type received"; 359 NOTREACHED() << "Unexpected event type received: " << event.name();
356 return ui::EVENT_REWRITE_CONTINUE; 360 return ui::EVENT_REWRITE_CONTINUE;
357 } 361 }
358 362
359 ui::EventRewriteStatus TouchExplorationController::InPassthrough( 363 ui::EventRewriteStatus TouchExplorationController::InPassthrough(
360 const ui::TouchEvent& event, 364 const ui::TouchEvent& event,
361 scoped_ptr<ui::Event>* rewritten_event) { 365 scoped_ptr<ui::Event>* rewritten_event) {
362 ui::EventType type = event.type(); 366 ui::EventType type = event.type();
363 367
364 if (!(type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED || 368 if (!(type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED ||
365 type == ui::ET_TOUCH_MOVED || type == ui::ET_TOUCH_PRESSED)) { 369 type == ui::ET_TOUCH_MOVED || type == ui::ET_TOUCH_PRESSED)) {
366 NOTREACHED() << "Unexpected event type received."; 370 NOTREACHED() << "Unexpected event type received: " << event.name();
367 return ui::EVENT_REWRITE_CONTINUE; 371 return ui::EVENT_REWRITE_CONTINUE;
368 } 372 }
369 373
370 rewritten_event->reset(new ui::TouchEvent( 374 rewritten_event->reset(new ui::TouchEvent(
371 type, event.location(), event.touch_id(), event.time_stamp())); 375 type, event.location(), event.touch_id(), event.time_stamp()));
372 (*rewritten_event)->set_flags(event.flags()); 376 (*rewritten_event)->set_flags(event.flags());
373 377
374 if (current_touch_ids_.size() == 0) { 378 if (current_touch_ids_.size() == 0) {
375 ResetToNoFingersDown(); 379 ResetToNoFingersDown();
376 } 380 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 rewritten_event->reset( 412 rewritten_event->reset(
409 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, 413 new ui::TouchEvent(ui::ET_TOUCH_RELEASED,
410 last_touch_exploration_->location(), 414 last_touch_exploration_->location(),
411 initial_press_->touch_id(), 415 initial_press_->touch_id(),
412 event.time_stamp())); 416 event.time_stamp()));
413 (*rewritten_event)->set_flags(event.flags()); 417 (*rewritten_event)->set_flags(event.flags());
414 state_ = TOUCH_EXPLORATION; 418 state_ = TOUCH_EXPLORATION;
415 VLOG_STATE(); 419 VLOG_STATE();
416 return ui::EVENT_REWRITE_REWRITTEN; 420 return ui::EVENT_REWRITE_REWRITTEN;
417 } 421 }
418 NOTREACHED() << "Unexpected event type received."; 422 NOTREACHED() << "Unexpected event type received: " << event.name();
419 return ui::EVENT_REWRITE_CONTINUE; 423 return ui::EVENT_REWRITE_CONTINUE;
420 } 424 }
421 425
422 ui::EventRewriteStatus TouchExplorationController::InWaitForRelease( 426 ui::EventRewriteStatus TouchExplorationController::InWaitForRelease(
423 const ui::TouchEvent& event, 427 const ui::TouchEvent& event,
424 scoped_ptr<ui::Event>* rewritten_event) { 428 scoped_ptr<ui::Event>* rewritten_event) {
425 ui::EventType type = event.type(); 429 ui::EventType type = event.type();
426 if (!(type == ui::ET_TOUCH_PRESSED || type == ui::ET_TOUCH_MOVED || 430 if (!(type == ui::ET_TOUCH_PRESSED || type == ui::ET_TOUCH_MOVED ||
427 type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED)) { 431 type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED)) {
428 NOTREACHED() << "Unexpected event type received."; 432 NOTREACHED() << "Unexpected event type received: " << event.name();
429 return ui::EVENT_REWRITE_CONTINUE; 433 return ui::EVENT_REWRITE_CONTINUE;
430 } 434 }
431 if (current_touch_ids_.size() == 0) { 435 if (current_touch_ids_.size() == 0) {
432 state_ = NO_FINGERS_DOWN; 436 state_ = NO_FINGERS_DOWN;
433 ResetToNoFingersDown(); 437 ResetToNoFingersDown();
434 } 438 }
435 return EVENT_REWRITE_DISCARD; 439 return EVENT_REWRITE_DISCARD;
436 } 440 }
437 441
438 void TouchExplorationController::OnTapTimerFired() { 442 void TouchExplorationController::OnTapTimerFired() {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 return "TWO_TO_ONE_FINGER"; 556 return "TWO_TO_ONE_FINGER";
553 case PASSTHROUGH: 557 case PASSTHROUGH:
554 return "PASSTHROUGH"; 558 return "PASSTHROUGH";
555 case WAIT_FOR_RELEASE: 559 case WAIT_FOR_RELEASE:
556 return "WAIT_FOR_RELEASE"; 560 return "WAIT_FOR_RELEASE";
557 } 561 }
558 return "Not a state"; 562 return "Not a state";
559 } 563 }
560 564
561 } // namespace ui 565 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698