| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/aura/gestures/gesture_sequence.h" | 5 #include "ui/aura/gestures/gesture_sequence.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 302 } |
| 303 | 303 |
| 304 void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point, | 304 void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point, |
| 305 Gestures* gestures) { | 305 Gestures* gestures) { |
| 306 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 306 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 307 ui::ET_GESTURE_TAP_DOWN, | 307 ui::ET_GESTURE_TAP_DOWN, |
| 308 point.first_touch_position().x(), | 308 point.first_touch_position().x(), |
| 309 point.first_touch_position().y(), | 309 point.first_touch_position().y(), |
| 310 flags_, | 310 flags_, |
| 311 base::Time::FromDoubleT(point.last_touch_time()), | 311 base::Time::FromDoubleT(point.last_touch_time()), |
| 312 0.f, 0.f))); | 312 GestureEvent::Properties()))); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void GestureSequence::AppendClickGestureEvent(const GesturePoint& point, | 315 void GestureSequence::AppendClickGestureEvent(const GesturePoint& point, |
| 316 Gestures* gestures) { | 316 Gestures* gestures) { |
| 317 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 317 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 318 ui::ET_GESTURE_TAP, | 318 ui::ET_GESTURE_TAP, |
| 319 point.first_touch_position().x(), | 319 point.first_touch_position().x(), |
| 320 point.first_touch_position().y(), | 320 point.first_touch_position().y(), |
| 321 flags_, | 321 flags_, |
| 322 base::Time::FromDoubleT(point.last_touch_time()), | 322 base::Time::FromDoubleT(point.last_touch_time()), |
| 323 0.f, 0.f))); | 323 GestureEvent::Properties()))); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void GestureSequence::AppendDoubleClickGestureEvent(const GesturePoint& point, | 326 void GestureSequence::AppendDoubleClickGestureEvent(const GesturePoint& point, |
| 327 Gestures* gestures) { | 327 Gestures* gestures) { |
| 328 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 328 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 329 ui::ET_GESTURE_DOUBLE_TAP, | 329 ui::ET_GESTURE_DOUBLE_TAP, |
| 330 point.first_touch_position().x(), | 330 point.first_touch_position().x(), |
| 331 point.first_touch_position().y(), | 331 point.first_touch_position().y(), |
| 332 flags_, | 332 flags_, |
| 333 base::Time::FromDoubleT(point.last_touch_time()), | 333 base::Time::FromDoubleT(point.last_touch_time()), |
| 334 0.f, 0.f))); | 334 GestureEvent::Properties()))); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void GestureSequence::AppendScrollGestureBegin(const GesturePoint& point, | 337 void GestureSequence::AppendScrollGestureBegin(const GesturePoint& point, |
| 338 const gfx::Point& location, | 338 const gfx::Point& location, |
| 339 Gestures* gestures) { | 339 Gestures* gestures) { |
| 340 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 340 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 341 ui::ET_GESTURE_SCROLL_BEGIN, | 341 ui::ET_GESTURE_SCROLL_BEGIN, |
| 342 location.x(), | 342 location.x(), |
| 343 location.y(), | 343 location.y(), |
| 344 flags_, | 344 flags_, |
| 345 base::Time::FromDoubleT(point.last_touch_time()), | 345 base::Time::FromDoubleT(point.last_touch_time()), |
| 346 0.f, 0.f))); | 346 GestureEvent::Properties()))); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point, | 349 void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point, |
| 350 const gfx::Point& location, | 350 const gfx::Point& location, |
| 351 Gestures* gestures, | 351 Gestures* gestures, |
| 352 float x_velocity, | 352 float x_velocity, |
| 353 float y_velocity) { | 353 float y_velocity) { |
| 354 float railed_x_velocity = x_velocity; | 354 float railed_x_velocity = x_velocity; |
| 355 float railed_y_velocity = y_velocity; | 355 float railed_y_velocity = y_velocity; |
| 356 | 356 |
| 357 if (scroll_type_ == ST_HORIZONTAL) | 357 if (scroll_type_ == ST_HORIZONTAL) |
| 358 railed_y_velocity = 0; | 358 railed_y_velocity = 0; |
| 359 else if (scroll_type_ == ST_VERTICAL) | 359 else if (scroll_type_ == ST_VERTICAL) |
| 360 railed_x_velocity = 0; | 360 railed_x_velocity = 0; |
| 361 | 361 |
| 362 GestureEvent::Properties props; |
| 363 props.delta_x = railed_x_velocity; |
| 364 props.delta_y = railed_y_velocity; |
| 365 |
| 362 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 366 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 363 ui::ET_GESTURE_SCROLL_END, | 367 ui::ET_GESTURE_SCROLL_END, |
| 364 location.x(), | 368 location.x(), |
| 365 location.y(), | 369 location.y(), |
| 366 flags_, | 370 flags_, |
| 367 base::Time::FromDoubleT(point.last_touch_time()), | 371 base::Time::FromDoubleT(point.last_touch_time()), |
| 368 railed_x_velocity, railed_y_velocity))); | 372 props))); |
| 369 } | 373 } |
| 370 | 374 |
| 371 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, | 375 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, |
| 372 const gfx::Point& location, | 376 const gfx::Point& location, |
| 373 Gestures* gestures) { | 377 Gestures* gestures) { |
| 374 int dx = point.x_delta(); | 378 int dx = point.x_delta(); |
| 375 int dy = point.y_delta(); | 379 int dy = point.y_delta(); |
| 376 | 380 |
| 377 if (scroll_type_ == ST_HORIZONTAL) | 381 if (scroll_type_ == ST_HORIZONTAL) |
| 378 dy = 0; | 382 dy = 0; |
| 379 else if (scroll_type_ == ST_VERTICAL) | 383 else if (scroll_type_ == ST_VERTICAL) |
| 380 dx = 0; | 384 dx = 0; |
| 381 | 385 |
| 386 GestureEvent::Properties props; |
| 387 props.delta_x = dx; |
| 388 props.delta_y = dy; |
| 389 |
| 382 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 390 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 383 ui::ET_GESTURE_SCROLL_UPDATE, | 391 ui::ET_GESTURE_SCROLL_UPDATE, |
| 384 location.x(), | 392 location.x(), |
| 385 location.y(), | 393 location.y(), |
| 386 flags_, | 394 flags_, |
| 387 base::Time::FromDoubleT(point.last_touch_time()), | 395 base::Time::FromDoubleT(point.last_touch_time()), |
| 388 dx, dy))); | 396 props))); |
| 389 } | 397 } |
| 390 | 398 |
| 391 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1, | 399 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1, |
| 392 const GesturePoint& p2, | 400 const GesturePoint& p2, |
| 393 Gestures* gestures) { | 401 Gestures* gestures) { |
| 394 gfx::Point center = p1.last_touch_position().Middle(p2.last_touch_position()); | 402 gfx::Point center = p1.last_touch_position().Middle(p2.last_touch_position()); |
| 395 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 403 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 396 ui::ET_GESTURE_PINCH_BEGIN, | 404 ui::ET_GESTURE_PINCH_BEGIN, |
| 397 center.x(), | 405 center.x(), |
| 398 center.y(), | 406 center.y(), |
| 399 flags_, | 407 flags_, |
| 400 base::Time::FromDoubleT(p1.last_touch_time()), | 408 base::Time::FromDoubleT(p1.last_touch_time()), |
| 401 0.f, 0.f))); | 409 GestureEvent::Properties()))); |
| 402 } | 410 } |
| 403 | 411 |
| 404 void GestureSequence::AppendPinchGestureEnd(const GesturePoint& p1, | 412 void GestureSequence::AppendPinchGestureEnd(const GesturePoint& p1, |
| 405 const GesturePoint& p2, | 413 const GesturePoint& p2, |
| 406 float scale, | 414 float scale, |
| 407 Gestures* gestures) { | 415 Gestures* gestures) { |
| 408 gfx::Point center = p1.last_touch_position().Middle(p2.last_touch_position()); | 416 gfx::Point center = p1.last_touch_position().Middle(p2.last_touch_position()); |
| 417 GestureEvent::Properties props; |
| 418 props.delta_x = scale; |
| 419 props.scale_x = scale; |
| 420 |
| 409 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 421 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 410 ui::ET_GESTURE_PINCH_END, | 422 ui::ET_GESTURE_PINCH_END, |
| 411 center.x(), | 423 center.x(), |
| 412 center.y(), | 424 center.y(), |
| 413 flags_, | 425 flags_, |
| 414 base::Time::FromDoubleT(p1.last_touch_time()), | 426 base::Time::FromDoubleT(p1.last_touch_time()), |
| 415 scale, 0.f))); | 427 props))); |
| 416 } | 428 } |
| 417 | 429 |
| 418 void GestureSequence::AppendPinchGestureUpdate(const GesturePoint& p1, | 430 void GestureSequence::AppendPinchGestureUpdate(const GesturePoint& p1, |
| 419 const GesturePoint& p2, | 431 const GesturePoint& p2, |
| 420 float scale, | 432 float scale, |
| 421 Gestures* gestures) { | 433 Gestures* gestures) { |
| 422 // TODO(sad): Compute rotation and include it in delta_y. | 434 // TODO(sad): Compute rotation and include it in delta_y. |
| 423 // http://crbug.com/113145 | 435 // http://crbug.com/113145 |
| 424 gfx::Point center = p1.last_touch_position().Middle(p2.last_touch_position()); | 436 gfx::Point center = p1.last_touch_position().Middle(p2.last_touch_position()); |
| 437 |
| 438 GestureEvent::Properties props; |
| 439 props.delta_x = scale; |
| 440 props.scale_x = scale; |
| 441 |
| 425 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( | 442 gestures->push_back(linked_ptr<GestureEvent>(new GestureEvent( |
| 426 ui::ET_GESTURE_PINCH_UPDATE, | 443 ui::ET_GESTURE_PINCH_UPDATE, |
| 427 center.x(), | 444 center.x(), |
| 428 center.y(), | 445 center.y(), |
| 429 flags_, | 446 flags_, |
| 430 base::Time::FromDoubleT(p1.last_touch_time()), | 447 base::Time::FromDoubleT(p1.last_touch_time()), |
| 431 scale, 0.f))); | 448 props))); |
| 432 } | 449 } |
| 433 | 450 |
| 434 bool GestureSequence::Click(const TouchEvent& event, | 451 bool GestureSequence::Click(const TouchEvent& event, |
| 435 const GesturePoint& point, Gestures* gestures) { | 452 const GesturePoint& point, Gestures* gestures) { |
| 436 DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK); | 453 DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK); |
| 437 if (point.IsInClickWindow(event)) { | 454 if (point.IsInClickWindow(event)) { |
| 438 AppendClickGestureEvent(point, gestures); | 455 AppendClickGestureEvent(point, gestures); |
| 439 if (point.IsInDoubleClickWindow(event)) | 456 if (point.IsInDoubleClickWindow(event)) |
| 440 AppendDoubleClickGestureEvent(point, gestures); | 457 AppendDoubleClickGestureEvent(point, gestures); |
| 441 return true; | 458 return true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 long_press_timer_->Start( | 510 long_press_timer_->Start( |
| 494 FROM_HERE, | 511 FROM_HERE, |
| 495 base::TimeDelta::FromMilliseconds(kLongPressTimeInMilliseconds), | 512 base::TimeDelta::FromMilliseconds(kLongPressTimeInMilliseconds), |
| 496 this, | 513 this, |
| 497 &GestureSequence::AppendLongPressGestureEvent); | 514 &GestureSequence::AppendLongPressGestureEvent); |
| 498 return true; | 515 return true; |
| 499 } | 516 } |
| 500 | 517 |
| 501 void GestureSequence::AppendLongPressGestureEvent() { | 518 void GestureSequence::AppendLongPressGestureEvent() { |
| 502 const GesturePoint* point = GetPointByPointId(0); | 519 const GesturePoint* point = GetPointByPointId(0); |
| 520 GestureEvent::Properties props; |
| 521 props.point_id = point->point_id(); |
| 522 |
| 503 GestureEvent gesture( | 523 GestureEvent gesture( |
| 504 ui::ET_GESTURE_LONG_PRESS, | 524 ui::ET_GESTURE_LONG_PRESS, |
| 505 point->first_touch_position().x(), | 525 point->first_touch_position().x(), |
| 506 point->first_touch_position().y(), | 526 point->first_touch_position().y(), |
| 507 flags_, | 527 flags_, |
| 508 base::Time::FromDoubleT(point->last_touch_time()), | 528 base::Time::FromDoubleT(point->last_touch_time()), |
| 509 point->point_id(), 0.f); | 529 props); |
| 510 root_window_->DispatchGestureEvent(&gesture); | 530 root_window_->DispatchGestureEvent(&gesture); |
| 511 } | 531 } |
| 512 | 532 |
| 513 bool GestureSequence::ScrollEnd(const TouchEvent& event, | 533 bool GestureSequence::ScrollEnd(const TouchEvent& event, |
| 514 GesturePoint& point, Gestures* gestures) { | 534 GesturePoint& point, Gestures* gestures) { |
| 515 DCHECK(state_ == GS_SCROLL); | 535 DCHECK(state_ == GS_SCROLL); |
| 516 if (point.IsInFlickWindow(event)) { | 536 if (point.IsInFlickWindow(event)) { |
| 517 AppendScrollGestureEnd(point, point.last_touch_position(), gestures, | 537 AppendScrollGestureEnd(point, point.last_touch_position(), gestures, |
| 518 point.XVelocity(), point.YVelocity()); | 538 point.XVelocity(), point.YVelocity()); |
| 519 } else { | 539 } else { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 float distance = point1->Distance(*point2); | 605 float distance = point1->Distance(*point2); |
| 586 AppendPinchGestureEnd(*point1, *point2, | 606 AppendPinchGestureEnd(*point1, *point2, |
| 587 distance / pinch_distance_start_, gestures); | 607 distance / pinch_distance_start_, gestures); |
| 588 | 608 |
| 589 pinch_distance_start_ = 0; | 609 pinch_distance_start_ = 0; |
| 590 pinch_distance_current_ = 0; | 610 pinch_distance_current_ = 0; |
| 591 return true; | 611 return true; |
| 592 } | 612 } |
| 593 | 613 |
| 594 } // namespace aura | 614 } // namespace aura |
| OLD | NEW |