| 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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 Reset(); | 475 Reset(); |
| 486 return false; | 476 return false; |
| 487 } | 477 } |
| 488 | 478 |
| 489 bool GestureSequence::TouchDown(const TouchEvent& event, | 479 bool GestureSequence::TouchDown(const TouchEvent& event, |
| 490 const GesturePoint& point, Gestures* gestures) { | 480 const GesturePoint& point, Gestures* gestures) { |
| 491 DCHECK(state_ == GS_NO_GESTURE); | 481 DCHECK(state_ == GS_NO_GESTURE); |
| 492 AppendTapDownGestureEvent(point, gestures); | 482 AppendTapDownGestureEvent(point, gestures); |
| 493 long_press_timer_->Start( | 483 long_press_timer_->Start( |
| 494 FROM_HERE, | 484 FROM_HERE, |
| 495 base::TimeDelta::FromMilliseconds(kLongPressTimeInMilliseconds), | 485 base::TimeDelta::FromMilliseconds( |
| 486 GestureConfiguration::long_press_time_in_ms()), |
| 496 this, | 487 this, |
| 497 &GestureSequence::AppendLongPressGestureEvent); | 488 &GestureSequence::AppendLongPressGestureEvent); |
| 498 return true; | 489 return true; |
| 499 } | 490 } |
| 500 | 491 |
| 501 void GestureSequence::AppendLongPressGestureEvent() { | 492 void GestureSequence::AppendLongPressGestureEvent() { |
| 502 const GesturePoint* point = GetPointByPointId(0); | 493 const GesturePoint* point = GetPointByPointId(0); |
| 503 GestureEvent gesture( | 494 GestureEvent gesture( |
| 504 ui::ET_GESTURE_LONG_PRESS, | 495 ui::ET_GESTURE_LONG_PRESS, |
| 505 point->first_touch_position().x(), | 496 point->first_touch_position().x(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 538 |
| 548 bool GestureSequence::PinchUpdate(const TouchEvent& event, | 539 bool GestureSequence::PinchUpdate(const TouchEvent& event, |
| 549 const GesturePoint& point, Gestures* gestures) { | 540 const GesturePoint& point, Gestures* gestures) { |
| 550 DCHECK(state_ == GS_PINCH); | 541 DCHECK(state_ == GS_PINCH); |
| 551 | 542 |
| 552 const GesturePoint* point1 = GetPointByPointId(0); | 543 const GesturePoint* point1 = GetPointByPointId(0); |
| 553 const GesturePoint* point2 = GetPointByPointId(1); | 544 const GesturePoint* point2 = GetPointByPointId(1); |
| 554 | 545 |
| 555 float distance = point1->Distance(*point2); | 546 float distance = point1->Distance(*point2); |
| 556 if (abs(distance - pinch_distance_current_) < | 547 if (abs(distance - pinch_distance_current_) < |
| 557 GestureConfiguration::minimum_pinch_update_distance_in_pixels()) { | 548 GestureConfiguration::min_pinch_update_distance_in_pixels()) { |
| 558 // The fingers didn't move towards each other, or away from each other, | 549 // The fingers didn't move towards each other, or away from each other, |
| 559 // enough to constitute a pinch. But perhaps they moved enough in the same | 550 // enough to constitute a pinch. But perhaps they moved enough in the same |
| 560 // direction to do a two-finger scroll. | 551 // direction to do a two-finger scroll. |
| 561 if (!point1->DidScroll(event, | 552 if (!point1->DidScroll(event, |
| 562 GestureConfiguration::minimum_distance_for_pinch_scroll_in_pixels()) || | 553 GestureConfiguration::min_distance_for_pinch_scroll_in_pixels()) || |
| 563 !point2->DidScroll(event, | 554 !point2->DidScroll(event, |
| 564 GestureConfiguration::minimum_distance_for_pinch_scroll_in_pixels())) | 555 GestureConfiguration::min_distance_for_pinch_scroll_in_pixels())) |
| 565 return false; | 556 return false; |
| 566 | 557 |
| 567 gfx::Point center = point1->last_touch_position().Middle( | 558 gfx::Point center = point1->last_touch_position().Middle( |
| 568 point2->last_touch_position()); | 559 point2->last_touch_position()); |
| 569 AppendScrollGestureUpdate(point, center, gestures); | 560 AppendScrollGestureUpdate(point, center, gestures); |
| 570 } else { | 561 } else { |
| 571 AppendPinchGestureUpdate(*point1, *point2, | 562 AppendPinchGestureUpdate(*point1, *point2, |
| 572 distance / pinch_distance_current_, gestures); | 563 distance / pinch_distance_current_, gestures); |
| 573 pinch_distance_current_ = distance; | 564 pinch_distance_current_ = distance; |
| 574 } | 565 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 585 float distance = point1->Distance(*point2); | 576 float distance = point1->Distance(*point2); |
| 586 AppendPinchGestureEnd(*point1, *point2, | 577 AppendPinchGestureEnd(*point1, *point2, |
| 587 distance / pinch_distance_start_, gestures); | 578 distance / pinch_distance_start_, gestures); |
| 588 | 579 |
| 589 pinch_distance_start_ = 0; | 580 pinch_distance_start_ = 0; |
| 590 pinch_distance_current_ = 0; | 581 pinch_distance_current_ = 0; |
| 591 return true; | 582 return true; |
| 592 } | 583 } |
| 593 | 584 |
| 594 } // namespace aura | 585 } // namespace aura |
| OLD | NEW |