| 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" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/gestures/gesture_configuration.h" | 12 #include "ui/aura/gestures/gesture_configuration.h" |
| 13 #include "ui/base/events.h" | 13 #include "ui/base/events.h" |
| 14 | 14 |
| 15 namespace { | |
| 16 | |
| 17 // TODO(girard): Make these configurable in sync with this CL | |
| 18 // http://crbug.com/100773 | |
| 19 const float kMinimumPinchUpdateDistance = 5; // in pixels | |
| 20 const float kMinimumDistanceForPinchScroll = 20; | |
| 21 const float kLongPressTimeInMilliseconds = 500; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 namespace aura { | 15 namespace aura { |
| 26 | 16 |
| 27 namespace { | 17 namespace { |
| 28 | 18 |
| 29 // ui::EventType is mapped to TouchState so it can fit into 3 bits of | 19 // ui::EventType is mapped to TouchState so it can fit into 3 bits of |
| 30 // Signature. | 20 // Signature. |
| 31 enum TouchState { | 21 enum TouchState { |
| 32 TS_RELEASED, | 22 TS_RELEASED, |
| 33 TS_PRESSED, | 23 TS_PRESSED, |
| 34 TS_MOVED, | 24 TS_MOVED, |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 Reset(); | 478 Reset(); |
| 489 return false; | 479 return false; |
| 490 } | 480 } |
| 491 | 481 |
| 492 bool GestureSequence::TouchDown(const TouchEvent& event, | 482 bool GestureSequence::TouchDown(const TouchEvent& event, |
| 493 const GesturePoint& point, Gestures* gestures) { | 483 const GesturePoint& point, Gestures* gestures) { |
| 494 DCHECK(state_ == GS_NO_GESTURE); | 484 DCHECK(state_ == GS_NO_GESTURE); |
| 495 AppendTapDownGestureEvent(point, gestures); | 485 AppendTapDownGestureEvent(point, gestures); |
| 496 long_press_timer_->Start( | 486 long_press_timer_->Start( |
| 497 FROM_HERE, | 487 FROM_HERE, |
| 498 base::TimeDelta::FromMilliseconds(kLongPressTimeInMilliseconds), | 488 base::TimeDelta::FromSeconds( |
| 489 GestureConfiguration::long_press_time_in_seconds()), |
| 499 this, | 490 this, |
| 500 &GestureSequence::AppendLongPressGestureEvent); | 491 &GestureSequence::AppendLongPressGestureEvent); |
| 501 return true; | 492 return true; |
| 502 } | 493 } |
| 503 | 494 |
| 504 void GestureSequence::AppendLongPressGestureEvent() { | 495 void GestureSequence::AppendLongPressGestureEvent() { |
| 505 const GesturePoint* point = GetPointByPointId(0); | 496 const GesturePoint* point = GetPointByPointId(0); |
| 506 GestureEvent gesture( | 497 GestureEvent gesture( |
| 507 ui::ET_GESTURE_LONG_PRESS, | 498 ui::ET_GESTURE_LONG_PRESS, |
| 508 point->first_touch_position().x(), | 499 point->first_touch_position().x(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 541 |
| 551 bool GestureSequence::PinchUpdate(const TouchEvent& event, | 542 bool GestureSequence::PinchUpdate(const TouchEvent& event, |
| 552 const GesturePoint& point, Gestures* gestures) { | 543 const GesturePoint& point, Gestures* gestures) { |
| 553 DCHECK(state_ == GS_PINCH); | 544 DCHECK(state_ == GS_PINCH); |
| 554 | 545 |
| 555 const GesturePoint* point1 = GetPointByPointId(0); | 546 const GesturePoint* point1 = GetPointByPointId(0); |
| 556 const GesturePoint* point2 = GetPointByPointId(1); | 547 const GesturePoint* point2 = GetPointByPointId(1); |
| 557 | 548 |
| 558 float distance = point1->Distance(*point2); | 549 float distance = point1->Distance(*point2); |
| 559 if (abs(distance - pinch_distance_current_) < | 550 if (abs(distance - pinch_distance_current_) < |
| 560 GestureConfiguration::minimum_pinch_update_distance_in_pixels()) { | 551 GestureConfiguration::min_pinch_update_distance_in_pixels()) { |
| 561 // The fingers didn't move towards each other, or away from each other, | 552 // The fingers didn't move towards each other, or away from each other, |
| 562 // enough to constitute a pinch. But perhaps they moved enough in the same | 553 // enough to constitute a pinch. But perhaps they moved enough in the same |
| 563 // direction to do a two-finger scroll. | 554 // direction to do a two-finger scroll. |
| 564 if (!point1->DidScroll(event, | 555 if (!point1->DidScroll(event, |
| 565 GestureConfiguration::minimum_distance_for_pinch_scroll_in_pixels()) || | 556 GestureConfiguration::min_distance_for_pinch_scroll_in_pixels()) || |
| 566 !point2->DidScroll(event, | 557 !point2->DidScroll(event, |
| 567 GestureConfiguration::minimum_distance_for_pinch_scroll_in_pixels())) | 558 GestureConfiguration::min_distance_for_pinch_scroll_in_pixels())) |
| 568 return false; | 559 return false; |
| 569 | 560 |
| 570 gfx::Point center = point1->last_touch_position().Middle( | 561 gfx::Point center = point1->last_touch_position().Middle( |
| 571 point2->last_touch_position()); | 562 point2->last_touch_position()); |
| 572 AppendScrollGestureUpdate(point, center, gestures); | 563 AppendScrollGestureUpdate(point, center, gestures); |
| 573 } else { | 564 } else { |
| 574 AppendPinchGestureUpdate(*point1, *point2, | 565 AppendPinchGestureUpdate(*point1, *point2, |
| 575 distance / pinch_distance_current_, gestures); | 566 distance / pinch_distance_current_, gestures); |
| 576 pinch_distance_current_ = distance; | 567 pinch_distance_current_ = distance; |
| 577 } | 568 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 588 float distance = point1->Distance(*point2); | 579 float distance = point1->Distance(*point2); |
| 589 AppendPinchGestureEnd(*point1, *point2, | 580 AppendPinchGestureEnd(*point1, *point2, |
| 590 distance / pinch_distance_start_, gestures); | 581 distance / pinch_distance_start_, gestures); |
| 591 | 582 |
| 592 pinch_distance_start_ = 0; | 583 pinch_distance_start_ = 0; |
| 593 pinch_distance_current_ = 0; | 584 pinch_distance_current_ = 0; |
| 594 return true; | 585 return true; |
| 595 } | 586 } |
| 596 | 587 |
| 597 } // namespace aura | 588 } // namespace aura |
| OLD | NEW |