Index: content/browser/renderer_host/input/content_motion_event_impl_android.cc |
diff --git a/content/browser/renderer_host/input/content_motion_event_impl_android.cc b/content/browser/renderer_host/input/content_motion_event_impl_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c66c3df7480d4c18ef94dc14e8837bf35de4801e |
--- /dev/null |
+++ b/content/browser/renderer_host/input/content_motion_event_impl_android.cc |
@@ -0,0 +1,141 @@ |
+// 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/content_motion_event_impl.h" |
+ |
+#include "base/logging.h" |
+#include "content/browser/renderer_host/input/web_input_event_builders_android.h" |
+ |
+using blink::WebInputEvent; |
+using blink::WebPoint; |
+using blink::WebTouchEvent; |
+using blink::WebTouchPoint; |
+ |
+namespace content { |
+namespace { |
+ |
+ui::MotionEvent::Action ToUIAction(const MotionEventAndroid::Action action) { |
+ switch (action) { |
+ case MotionEventAndroid::ACTION_DOWN: |
+ return ui::MotionEvent::ACTION_DOWN; |
+ case MotionEventAndroid::ACTION_UP: |
+ return ui::MotionEvent::ACTION_UP; |
+ case MotionEventAndroid::ACTION_MOVE: |
+ return ui::MotionEvent::ACTION_MOVE; |
+ case MotionEventAndroid::ACTION_CANCEL: |
+ return ui::MotionEvent::ACTION_CANCEL; |
+ case MotionEventAndroid::ACTION_POINTER_DOWN: |
+ return ui::MotionEvent::ACTION_POINTER_DOWN; |
+ case MotionEventAndroid::ACTION_POINTER_UP: |
+ return ui::MotionEvent::ACTION_POINTER_UP; |
+ }; |
+ NOTREACHED() << "Invalid MotionEventAndroid action."; |
+ return ui::MotionEvent::ACTION_CANCEL; |
+} |
+ |
+} // namespace |
+ |
+ContentMotionEventImpl::ContentMotionEventImpl(jobject android_motion_event, |
+ bool should_recycle, |
+ float device_scale_factor) |
+ : event_(android_motion_event, should_recycle, device_scale_factor), |
+ cached_action_(ToUIAction(event_.android_event.GetActionMasked())), |
+ cached_action_index_(event_.android_event.GetActionIndex()) {} |
+ |
+ContentMotionEventImpl::ContentMotionEventImpl(const NativeWebTouchEvent& event) |
+ : event_(event), |
+ cached_action_(ToUIAction(event_.android_event.GetActionMasked())), |
+ cached_action_index_(event_.android_event.GetActionIndex()) { |
+ DCHECK_GT(GetPointerCount(), 0U); |
+} |
+ |
+ContentMotionEventImpl::~ContentMotionEventImpl() {} |
+ |
+ContentMotionEventImpl::Action ContentMotionEventImpl::GetAction() const { |
+ return cached_action_; |
+} |
+ |
+int ContentMotionEventImpl::GetActionIndex() const { |
+ return cached_action_index_; |
+} |
+ |
+size_t ContentMotionEventImpl::GetPointerCount() const { |
+ return event_.android_event.GetPointerCount(); |
+} |
+ |
+int ContentMotionEventImpl::GetPointerId(size_t pointer_index) const { |
+ DCHECK_LT(pointer_index, GetPointerCount()); |
+ // TODO(jdduke): Determine the relative speed of the two queries. |
+ return event_.android_event.GetPointerId(pointer_index); |
+ // return event_.touches[pointer_index].id; |
+} |
+ |
+float ContentMotionEventImpl::GetX(size_t pointer_index) const { |
+ DCHECK_LT(pointer_index, GetPointerCount()); |
+ // TODO(jdduke): Determine the relative speed of the two queries. |
+ return event_.android_event.GetX(pointer_index); |
+ // return event_.touches[pointer_index].position.x * device_scale_factor_; |
+} |
+ |
+float ContentMotionEventImpl::GetY(size_t pointer_index) const { |
+ DCHECK_LT(pointer_index, GetPointerCount()); |
+ // TODO(jdduke): Determine the relative speed of the two queries. |
+ return event_.android_event.GetY(pointer_index); |
+ // return event_.touches[pointer_index].position.y * device_scale_factor_; |
+} |
+ |
+float ContentMotionEventImpl::GetTouchMajor(size_t pointer_index) const { |
+ DCHECK_LT(pointer_index, GetPointerCount()); |
+ return event_.android_event.GetTouchMajor(pointer_index); |
+} |
+ |
+base::TimeTicks ContentMotionEventImpl::GetEventTime() const { |
+ return event_.android_event.GetEventTime(); |
+} |
+ |
+size_t ContentMotionEventImpl::GetHistorySize() const { |
+ return event_.android_event.GetHistorySize(); |
+} |
+ |
+base::TimeTicks ContentMotionEventImpl::GetHistoricalEventTime( |
+ size_t historical_index) const { |
+ return event_.android_event.GetHistoricalEventTime(historical_index); |
+} |
+ |
+float ContentMotionEventImpl::GetHistoricalTouchMajor(size_t pointer_index, |
+ size_t historical_index) |
+ const { |
+ return event_.android_event.GetHistoricalTouchMajor(pointer_index, |
+ historical_index); |
+} |
+ |
+float ContentMotionEventImpl::GetHistoricalX(size_t pointer_index, |
+ size_t historical_index) const { |
+ return event_.android_event.GetHistoricalX(pointer_index, historical_index); |
+} |
+ |
+float ContentMotionEventImpl::GetHistoricalY(size_t pointer_index, |
+ size_t historical_index) const { |
+ return event_.android_event.GetHistoricalY(pointer_index, historical_index); |
+} |
+ |
+scoped_ptr<ui::MotionEvent> ContentMotionEventImpl::Clone() const { |
+ return scoped_ptr<MotionEvent>(new ContentMotionEventImpl( |
+ MotionEventAndroid::Obtain(event_.android_event).obj(), |
+ true, |
+ event_.device_scale_factor)); |
+} |
+ |
+scoped_ptr<ui::MotionEvent> ContentMotionEventImpl::Cancel() const { |
+ return scoped_ptr<MotionEvent>(new ContentMotionEventImpl( |
+ MotionEventAndroid::Obtain(GetEventTime(), |
+ GetEventTime(), |
+ MotionEventAndroid::ACTION_CANCEL, |
+ GetX(0), |
+ GetY(0)).obj(), |
+ true, |
+ event_.device_scale_factor)); |
+} |
+ |
+} // namespace content |