Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1050)

Unified Diff: content/browser/renderer_host/input/gestures/motion_event.cc

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/gestures/motion_event.cc
diff --git a/content/browser/renderer_host/input/gestures/motion_event.cc b/content/browser/renderer_host/input/gestures/motion_event.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cbd0dd3019a7aa6e981a17381e3713e100550563
--- /dev/null
+++ b/content/browser/renderer_host/input/gestures/motion_event.cc
@@ -0,0 +1,130 @@
+// Copyright 2014 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 "content/browser/renderer_host/input/gestures/motion_event.h"
+
+#include "base/logging.h"
+
+using blink::WebInputEvent;
+using blink::WebTouchEvent;
+using blink::WebTouchPoint;
+
+namespace content {
+namespace {
+
+ bool AllTouchPointsHaveState(const WebTouchEvent& event,
+ WebTouchPoint::State state) {
+ for (size_t i = 0; i < event.touchesLength; ++i)
+ if (event.touches[i].state != state)
+ return true;
+ return false;
+}
+
+} // namespace
+
+MotionEvent::MotionEvent(const WebTouchEvent& event) : event(event) {
+ DCHECK_GT(GetPointerCount(), 0U);
+}
+
+MotionEvent::~MotionEvent() {}
+
+MotionEvent::Action MotionEvent::GetActionMasked() const {
+ switch (event.type) {
+ case WebInputEvent::TouchStart:
+ if (AllTouchPointsHaveState(event, WebTouchPoint::StatePressed))
+ return ACTION_DOWN;
+ else
+ return ACTION_POINTER_DOWN;
+ case WebInputEvent::TouchEnd:
+ if (AllTouchPointsHaveState(event, WebTouchPoint::StateReleased))
+ return ACTION_UP;
+ else
+ return ACTION_POINTER_UP;
+ case WebInputEvent::TouchCancel:
+ DCHECK(AllTouchPointsHaveState(event, WebTouchPoint::StateCancelled));
+ return ACTION_CANCEL;
+ case WebInputEvent::TouchMove:
+ return ACTION_MOVE;
+ default:
+ break;
+ };
+ NOTREACHED() << "Invalid masked MotionEvent action.";
+ return ACTION_CANCEL;
+}
+
+size_t MotionEvent::GetActionIndex() const {
+ for (size_t i = 0; i < GetPointerCount(); ++i) {
+ if (event.touches[i].state != WebTouchPoint::StateUndefined &&
+ event.touches[i].state != WebTouchPoint::StateStationary)
+ return i;
+ }
+ NOTREACHED() << "Invalid MotionEvent action index.";
+ return 0;
+}
+
+size_t MotionEvent::GetPointerCount() const {
+ return event.touchesLength;
+}
+
+int MotionEvent::GetPointerId(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return event.touches[pointer_index].id;
+}
+
+float MotionEvent::GetX(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return event.touches[pointer_index].position.x;
+}
+
+float MotionEvent::GetY(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return event.touches[pointer_index].position.y;
+}
+
+float MotionEvent::GetTouchMajor(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ // TODO(jdduke): We should be a bit more careful about axes here.
+ return std::max(event.touches[pointer_index].radiusX,
+ event.touches[pointer_index].radiusY);
+}
+
+base::TimeTicks MotionEvent::GetEventTime() const {
+ return base::TimeTicks() +
+ base::TimeDelta::FromMicroseconds(event.timeStampSeconds * 1000000);
+}
+
+base::TimeTicks MotionEvent::GetDownTime() const {
+ return base::TimeTicks() +
+ base::TimeDelta::FromMicroseconds(event.timeStampSeconds * 1000000);
+}
+
+size_t MotionEvent::GetHistorySize() const {
+ return 0;
+}
+
+base::TimeTicks MotionEvent::GetHistoricalEventTime(
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return base::TimeTicks();
+}
+
+float MotionEvent::GetHistoricalTouchMajor(size_t pointer_index,
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return 0.f;
+}
+
+float MotionEvent::GetHistoricalX(size_t pointer_index,
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return 0.f;
+}
+
+float MotionEvent::GetHistoricalY(size_t pointer_index,
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return 0.f;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698