Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 case SINGLE_TAP_PRESSED: | 123 case SINGLE_TAP_PRESSED: |
| 124 return InSingleTapPressed(touch_event, rewritten_event); | 124 return InSingleTapPressed(touch_event, rewritten_event); |
| 125 case SINGLE_TAP_RELEASED: | 125 case SINGLE_TAP_RELEASED: |
| 126 return InSingleTapReleased(touch_event, rewritten_event); | 126 return InSingleTapReleased(touch_event, rewritten_event); |
| 127 case DOUBLE_TAP_PRESSED: | 127 case DOUBLE_TAP_PRESSED: |
| 128 return InDoubleTapPressed(touch_event, rewritten_event); | 128 return InDoubleTapPressed(touch_event, rewritten_event); |
| 129 case TOUCH_EXPLORATION: | 129 case TOUCH_EXPLORATION: |
| 130 return InTouchExploration(touch_event, rewritten_event); | 130 return InTouchExploration(touch_event, rewritten_event); |
| 131 case PASSTHROUGH_MINUS_ONE: | 131 case PASSTHROUGH_MINUS_ONE: |
| 132 return InPassthroughMinusOne(touch_event, rewritten_event); | 132 return InPassthroughMinusOne(touch_event, rewritten_event); |
| 133 case TE_SECOND_PRESS: | |
| 134 return InTESecondPress(touch_event, rewritten_event); | |
| 133 } | 135 } |
| 134 | 136 |
| 135 NOTREACHED(); | 137 NOTREACHED(); |
| 136 return ui::EVENT_REWRITE_CONTINUE; | 138 return ui::EVENT_REWRITE_CONTINUE; |
| 137 } | 139 } |
| 138 | 140 |
| 139 ui::EventRewriteStatus TouchExplorationController::NextDispatchEvent( | 141 ui::EventRewriteStatus TouchExplorationController::NextDispatchEvent( |
| 140 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) { | 142 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) { |
| 141 NOTREACHED(); | 143 NOTREACHED(); |
| 142 return ui::EVENT_REWRITE_CONTINUE; | 144 return ui::EVENT_REWRITE_CONTINUE; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 return ui::EVENT_REWRITE_DISCARD; | 239 return ui::EVENT_REWRITE_DISCARD; |
| 238 } | 240 } |
| 239 NOTREACHED() << "Unexpected event type received."; | 241 NOTREACHED() << "Unexpected event type received."; |
| 240 return ui::EVENT_REWRITE_CONTINUE; | 242 return ui::EVENT_REWRITE_CONTINUE; |
| 241 } | 243 } |
| 242 | 244 |
| 243 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( | 245 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( |
| 244 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { | 246 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
| 245 const ui::EventType type = event.type(); | 247 const ui::EventType type = event.type(); |
| 246 if (type == ui::ET_TOUCH_PRESSED) { | 248 if (type == ui::ET_TOUCH_PRESSED) { |
| 247 | 249 // Split-tap |
| 248 // Ignore any additional fingers when we're already in touch exploration | 250 initial_press_.reset(new TouchEvent(event)); |
| 249 // mode. TODO(evy, lisayin): Support "split-tap" here instead. | 251 if (tap_timer_.IsRunning()) |
| 250 return ui::EVENT_REWRITE_DISCARD; | 252 tap_timer_.Stop(); |
| 253 ui::TouchEvent* rewritten_release_event = | |
|
dmazzoni
2014/06/13 05:52:38
this should be rewritten_touch_event
evy
2014/06/13 16:48:07
Done.
| |
| 254 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, | |
| 255 last_touch_exploration_location_, | |
| 256 event.touch_id(), | |
| 257 event.time_stamp()); | |
| 258 rewritten_release_event->set_flags(event.flags()); | |
| 259 rewritten_event->reset(rewritten_release_event); | |
| 260 state_ = TE_SECOND_PRESS; | |
| 261 VLOG_STATE(); | |
| 262 return ui::EVENT_REWRITE_REWRITTEN; | |
| 251 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 263 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
| 252 if (current_touch_ids_.size() == 0) | 264 if (current_touch_ids_.size() == 0) |
| 253 ResetToNoFingersDown(); | 265 ResetToNoFingersDown(); |
| 254 } else if (type != ui::ET_TOUCH_MOVED) { | 266 } else if (type != ui::ET_TOUCH_MOVED) { |
| 255 NOTREACHED() << "Unexpected event type received."; | 267 NOTREACHED() << "Unexpected event type received."; |
| 256 return ui::EVENT_REWRITE_CONTINUE; | 268 return ui::EVENT_REWRITE_CONTINUE; |
| 257 } | 269 } |
| 258 | 270 |
| 259 // Rewrite as a mouse-move event. | 271 // Rewrite as a mouse-move event. |
| 260 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags()); | 272 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 initial_touch_id_passthrough_mapping_, | 314 initial_touch_id_passthrough_mapping_, |
| 303 event.time_stamp()); | 315 event.time_stamp()); |
| 304 rewritten_passthrough_event->set_flags(event.flags()); | 316 rewritten_passthrough_event->set_flags(event.flags()); |
| 305 rewritten_event->reset(rewritten_passthrough_event); | 317 rewritten_event->reset(rewritten_passthrough_event); |
| 306 return ui::EVENT_REWRITE_REWRITTEN; | 318 return ui::EVENT_REWRITE_REWRITTEN; |
| 307 } | 319 } |
| 308 | 320 |
| 309 return ui::EVENT_REWRITE_CONTINUE; | 321 return ui::EVENT_REWRITE_CONTINUE; |
| 310 } | 322 } |
| 311 | 323 |
| 324 ui::EventRewriteStatus TouchExplorationController::InTESecondPress( | |
| 325 const ui::TouchEvent& event, | |
| 326 scoped_ptr<ui::Event>* rewritten_event) { | |
| 327 ui::EventType type = event.type(); | |
| 328 gfx::PointF location = event.location_f(); | |
| 329 if (tap_timer_.IsRunning()) | |
|
dmazzoni
2014/06/13 05:52:38
This shouldn't be necessary - it's already done be
evy
2014/06/13 16:48:07
Yeah - right before the state change - thanks
| |
| 330 tap_timer_.Stop(); | |
| 331 if (type == ui::ET_TOUCH_PRESSED) { | |
| 332 return ui::EVENT_REWRITE_DISCARD; | |
| 333 } else if (type == ui::ET_TOUCH_MOVED) { | |
| 334 // Currently this is a discard, but could be something like rotor | |
| 335 // in the future. | |
| 336 return ui::EVENT_REWRITE_DISCARD; | |
| 337 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | |
| 338 // If the touch exploration finger is lifted, there is no option to return | |
| 339 // to touch explore anymore. The remaining finger acts as a pending | |
| 340 // tap or long tap for the last touch explore location. | |
| 341 if (event.touch_id() == 0){ | |
|
dmazzoni
2014/06/13 05:52:38
I don't think you can assume the touch id is 0 for
evy
2014/06/13 16:48:07
Done. I changed last_touch_exploration_location to
| |
| 342 state_ = DOUBLE_TAP_PRESSED; | |
| 343 VLOG_STATE(); | |
| 344 return EVENT_REWRITE_DISCARD; | |
| 345 } | |
| 346 | |
| 347 // Continue to rlease the touch only if the touch explore finger is the | |
|
dmazzoni
2014/06/13 05:52:38
rlease -> release
evy
2014/06/13 16:48:07
Done.
| |
| 348 // only finger remaining. | |
| 349 if (current_touch_ids_.size() != 1) | |
| 350 return EVENT_REWRITE_DISCARD; | |
| 351 | |
| 352 // Rewrite at location of last touch exploration. | |
| 353 ui::TouchEvent* rewritten_release_event = new ui::TouchEvent( | |
| 354 ui::ET_TOUCH_RELEASED, | |
| 355 last_touch_exploration_location_, | |
| 356 event.touch_id(), | |
|
dmazzoni
2014/06/13 05:52:38
This touch id might not be the same as the one tha
evy
2014/06/13 16:48:07
Done. I used initial_press_ instead - which should
| |
| 357 event.time_stamp()); | |
| 358 rewritten_release_event->set_flags(event.flags()); | |
| 359 rewritten_event->reset(rewritten_release_event); | |
| 360 state_ = TOUCH_EXPLORATION; | |
| 361 VLOG_STATE(); | |
| 362 return ui::EVENT_REWRITE_REWRITTEN; | |
| 363 } | |
| 364 NOTREACHED() << "Unexpected event type received."; | |
| 365 return ui::EVENT_REWRITE_CONTINUE; | |
| 366 } | |
| 367 | |
| 312 void TouchExplorationController::OnTapTimerFired() { | 368 void TouchExplorationController::OnTapTimerFired() { |
| 313 if (state_ != SINGLE_TAP_RELEASED && state_ != SINGLE_TAP_PRESSED) | 369 if (state_ != SINGLE_TAP_RELEASED && state_ != SINGLE_TAP_PRESSED) |
| 314 return; | 370 return; |
| 315 | 371 |
| 316 if (state_ == SINGLE_TAP_RELEASED) { | 372 if (state_ == SINGLE_TAP_RELEASED) { |
| 317 ResetToNoFingersDown(); | 373 ResetToNoFingersDown(); |
| 318 } else { | 374 } else { |
| 319 EnterTouchToMouseMode(); | 375 EnterTouchToMouseMode(); |
| 320 state_ = TOUCH_EXPLORATION; | 376 state_ = TOUCH_EXPLORATION; |
| 321 VLOG_STATE(); | 377 VLOG_STATE(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 case SINGLE_TAP_PRESSED: | 455 case SINGLE_TAP_PRESSED: |
| 400 return "SINGLE_TAP_PRESSED"; | 456 return "SINGLE_TAP_PRESSED"; |
| 401 case SINGLE_TAP_RELEASED: | 457 case SINGLE_TAP_RELEASED: |
| 402 return "SINGLE_TAP_RELEASED"; | 458 return "SINGLE_TAP_RELEASED"; |
| 403 case DOUBLE_TAP_PRESSED: | 459 case DOUBLE_TAP_PRESSED: |
| 404 return "DOUBLE_TAP_PRESSED"; | 460 return "DOUBLE_TAP_PRESSED"; |
| 405 case TOUCH_EXPLORATION: | 461 case TOUCH_EXPLORATION: |
| 406 return "TOUCH_EXPLORATION"; | 462 return "TOUCH_EXPLORATION"; |
| 407 case PASSTHROUGH_MINUS_ONE: | 463 case PASSTHROUGH_MINUS_ONE: |
| 408 return "PASSTHROUGH_MINUS_ONE"; | 464 return "PASSTHROUGH_MINUS_ONE"; |
| 465 case TE_SECOND_PRESS: | |
| 466 return "TE_SECOND_PRESS"; | |
| 409 } | 467 } |
| 410 return "Not a state"; | 468 return "Not a state"; |
| 411 } | 469 } |
| 412 | 470 |
| 413 const char* TouchExplorationController::EnumEventTypeToString( | 471 const char* TouchExplorationController::EnumEventTypeToString( |
| 414 ui::EventType type) { | 472 ui::EventType type) { |
| 415 // Add more cases later. For now, these are the most frequently seen | 473 // Add more cases later. For now, these are the most frequently seen |
| 416 // event types. | 474 // event types. |
| 417 switch (type) { | 475 switch (type) { |
| 418 case ET_TOUCH_RELEASED: | 476 case ET_TOUCH_RELEASED: |
| 419 return "ET_TOUCH_RELEASED"; | 477 return "ET_TOUCH_RELEASED"; |
| 420 case ET_TOUCH_PRESSED: | 478 case ET_TOUCH_PRESSED: |
| 421 return "ET_TOUCH_PRESSED"; | 479 return "ET_TOUCH_PRESSED"; |
| 422 case ET_TOUCH_MOVED: | 480 case ET_TOUCH_MOVED: |
| 423 return "ET_TOUCH_MOVED"; | 481 return "ET_TOUCH_MOVED"; |
| 424 case ET_TOUCH_CANCELLED: | 482 case ET_TOUCH_CANCELLED: |
| 425 return "ET_TOUCH_CANCELLED"; | 483 return "ET_TOUCH_CANCELLED"; |
| 426 default: | 484 default: |
| 427 return base::IntToString(type).c_str(); | 485 return base::IntToString(type).c_str(); |
| 428 } | 486 } |
| 429 } | 487 } |
| 430 | 488 |
| 431 } // namespace ui | 489 } // namespace ui |
| OLD | NEW |