Index: ui/events/gestures/touch_point_state.cc |
diff --git a/ui/events/gestures/touch_point_state.cc b/ui/events/gestures/touch_point_state.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..075ae91ff5c12ce3aec26176204f3d732e64c7cb |
--- /dev/null |
+++ b/ui/events/gestures/touch_point_state.cc |
@@ -0,0 +1,156 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/events/gestures/touch_point_state.h" |
+ |
+#include "ui/events/event.h" |
+#include "ui/events/event_constants.h" |
+ |
+namespace ui { |
+ |
+TouchPointState::TouchPointState(int touch_id) |
+ : touch_id_(touch_id), |
+ has_press_(false), |
+ has_release_(false), |
+ move_count_(0), |
+ timer_count_(0) { |
+} |
+ |
+TouchPointState::TouchPointState(int touch_id, |
+ bool has_press, |
+ bool has_release, |
+ int move_count, |
+ int timer_count) |
+ : touch_id_(touch_id), |
+ has_press_(has_press), |
+ has_release_(has_release), |
+ move_count_(move_count), |
+ timer_count_(timer_count) { |
+} |
+ |
+TouchPointState::~TouchPointState() {} |
+ |
+void TouchPointState::Update(const TouchEvent& event) { |
+ DCHECK(touch_id_ == event.touch_id()); |
+ switch(event.type()) { |
+ case ET_TOUCH_PRESSED: |
+ has_press_ = true; |
+ break; |
+ case ET_TOUCH_MOVED: |
+ case ET_TOUCH_STATIONARY: |
+ ++move_count_; |
+ break; |
+ case ET_TOUCH_RELEASED: |
+ case ET_TOUCH_CANCELLED: |
+ has_release_ = true; |
+ break; |
+ default: |
+ // Should only be passed touch events. |
+ NOTREACHED(); |
+ } |
+} |
+ |
+void TouchPointState::TimerFired() { |
+ timer_count_++; |
+} |
+ |
+TouchPointState* TouchPointState::CopyForGestureType( |
+ EventType type, RequiresAck requires_ack) const { |
+ bool new_has_press = has_press_; |
+ bool new_has_release = has_release_; |
+ int new_move_count = move_count_; |
+ int new_timer_count = 0; |
+ |
+ switch(type) { |
+ case ET_GESTURE_SHOW_PRESS: |
+ // Only wait for show press timer. |
+ new_timer_count = 1; |
+ break; |
+ case ET_GESTURE_LONG_PRESS: |
+ // Wait for both long press and show press timers. |
+ new_timer_count = 2; |
+ break; |
+ default: |
+ break; |
+ } |
+ |
+ switch(type) { |
+ case ET_GESTURE_SCROLL_BEGIN: |
+ case ET_GESTURE_PINCH_BEGIN: |
+ case ET_GESTURE_SCROLL_UPDATE: |
+ case ET_GESTURE_PINCH_UPDATE: |
+ case ET_GESTURE_SCROLL_END: |
+ case ET_GESTURE_PINCH_END: |
+ case ET_GESTURE_MULTIFINGER_SWIPE: |
+ case ET_SCROLL_FLING_START: |
+ case ET_SCROLL_FLING_CANCEL: |
+ new_has_release = false; |
+ break; |
+ case ET_GESTURE_TAP: |
+ case ET_GESTURE_LONG_TAP: |
+ case ET_GESTURE_TWO_FINGER_TAP: |
+ break; |
+ case ET_GESTURE_BEGIN: |
+ case ET_GESTURE_END: |
+ case ET_GESTURE_SHOW_PRESS: |
+ case ET_GESTURE_LONG_PRESS: |
+ case ET_GESTURE_TAP_DOWN: |
+ case ET_GESTURE_TAP_CANCEL: |
+ new_has_release = false; |
+ new_move_count = 0; |
+ break; |
+ default: |
+ NOTREACHED() << "TouchPointState doesn't know about gesture type " |
+ << type; |
+ } |
+ |
+ if (requires_ack == NO_ACK) { |
+ new_has_press = false; |
+ new_has_release = false; |
+ new_move_count = false; |
+ } |
+ |
+ return new TouchPointState(touch_id_, |
+ new_has_press, |
+ new_has_release, |
+ new_move_count, |
+ new_timer_count); |
+} |
+ |
+bool TouchPointState::HasEmptyIntersection(const TouchPointState& tps) const { |
+ DCHECK(touch_id_ == tps.touch_id()); |
+ return Intersect(tps) == TouchPointState(touch_id_, 0, false, false, false); |
+} |
+ |
+bool TouchPointState::Contains(const TouchPointState& tps) const { |
+ DCHECK(touch_id_ == tps.touch_id()); |
+ return Intersect(tps) == tps; |
+} |
+ |
+void TouchPointState::Reset() { |
+ has_press_ = false; |
+ has_release_ = false; |
+ move_count_ = 0; |
+ timer_count_ = 0; |
+} |
+ |
+TouchPointState::TouchPointState(const TouchPointState& tps) |
+ : touch_id_(tps.touch_id()), |
+ has_press_(tps.has_press()), |
+ has_release_(tps.has_release()), |
+ move_count_(tps.move_count()), |
+ timer_count_(tps.timer_count()) { |
+} |
+ |
+TouchPointState TouchPointState::Intersect(const TouchPointState& tps) const { |
+ DCHECK(touch_id_ == tps.touch_id()); |
+ return TouchPointState( |
+ touch_id_, |
+ has_press() && tps.has_press(), |
+ has_release() && tps.has_release(), |
+ std::min(move_count(), tps.move_count()), |
+ std::min(timer_count(), tps.timer_count())); |
+} |
+ |
+} // namespace ui |