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

Side by Side Diff: content/browser/renderer_host/input/content_motion_event_impl_android.cc

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/input/content_motion_event_impl.h"
6
7 #include "base/logging.h"
8 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
9
10 using blink::WebInputEvent;
11 using blink::WebPoint;
12 using blink::WebTouchEvent;
13 using blink::WebTouchPoint;
14
15 namespace content {
16 namespace {
17
18 ui::MotionEvent::Action ToUIAction(const MotionEventAndroid::Action action) {
19 switch (action) {
20 case MotionEventAndroid::ACTION_DOWN:
21 return ui::MotionEvent::ACTION_DOWN;
22 case MotionEventAndroid::ACTION_UP:
23 return ui::MotionEvent::ACTION_UP;
24 case MotionEventAndroid::ACTION_MOVE:
25 return ui::MotionEvent::ACTION_MOVE;
26 case MotionEventAndroid::ACTION_CANCEL:
27 return ui::MotionEvent::ACTION_CANCEL;
28 case MotionEventAndroid::ACTION_POINTER_DOWN:
29 return ui::MotionEvent::ACTION_POINTER_DOWN;
30 case MotionEventAndroid::ACTION_POINTER_UP:
31 return ui::MotionEvent::ACTION_POINTER_UP;
32 };
33 NOTREACHED() << "Invalid MotionEventAndroid action.";
34 return ui::MotionEvent::ACTION_CANCEL;
35 }
36
37 } // namespace
38
39 ContentMotionEventImpl::ContentMotionEventImpl(jobject android_motion_event,
40 bool should_recycle,
41 float device_scale_factor)
42 : event_(android_motion_event, should_recycle, device_scale_factor),
43 cached_action_(ToUIAction(event_.android_event.GetActionMasked())),
44 cached_action_index_(event_.android_event.GetActionIndex()) {}
45
46 ContentMotionEventImpl::ContentMotionEventImpl(const NativeWebTouchEvent& event)
47 : event_(event),
48 cached_action_(ToUIAction(event_.android_event.GetActionMasked())),
49 cached_action_index_(event_.android_event.GetActionIndex()) {
50 DCHECK_GT(GetPointerCount(), 0U);
51 }
52
53 ContentMotionEventImpl::~ContentMotionEventImpl() {}
54
55 ContentMotionEventImpl::Action ContentMotionEventImpl::GetAction() const {
56 return cached_action_;
57 }
58
59 int ContentMotionEventImpl::GetActionIndex() const {
60 return cached_action_index_;
61 }
62
63 size_t ContentMotionEventImpl::GetPointerCount() const {
64 return event_.android_event.GetPointerCount();
65 }
66
67 int ContentMotionEventImpl::GetPointerId(size_t pointer_index) const {
68 DCHECK_LT(pointer_index, GetPointerCount());
69 // TODO(jdduke): Determine the relative speed of the two queries.
70 return event_.android_event.GetPointerId(pointer_index);
71 // return event_.touches[pointer_index].id;
72 }
73
74 float ContentMotionEventImpl::GetX(size_t pointer_index) const {
75 DCHECK_LT(pointer_index, GetPointerCount());
76 // TODO(jdduke): Determine the relative speed of the two queries.
77 return event_.android_event.GetX(pointer_index);
78 // return event_.touches[pointer_index].position.x * device_scale_factor_;
79 }
80
81 float ContentMotionEventImpl::GetY(size_t pointer_index) const {
82 DCHECK_LT(pointer_index, GetPointerCount());
83 // TODO(jdduke): Determine the relative speed of the two queries.
84 return event_.android_event.GetY(pointer_index);
85 // return event_.touches[pointer_index].position.y * device_scale_factor_;
86 }
87
88 float ContentMotionEventImpl::GetTouchMajor(size_t pointer_index) const {
89 DCHECK_LT(pointer_index, GetPointerCount());
90 return event_.android_event.GetTouchMajor(pointer_index);
91 }
92
93 base::TimeTicks ContentMotionEventImpl::GetEventTime() const {
94 return event_.android_event.GetEventTime();
95 }
96
97 size_t ContentMotionEventImpl::GetHistorySize() const {
98 return event_.android_event.GetHistorySize();
99 }
100
101 base::TimeTicks ContentMotionEventImpl::GetHistoricalEventTime(
102 size_t historical_index) const {
103 return event_.android_event.GetHistoricalEventTime(historical_index);
104 }
105
106 float ContentMotionEventImpl::GetHistoricalTouchMajor(size_t pointer_index,
107 size_t historical_index)
108 const {
109 return event_.android_event.GetHistoricalTouchMajor(pointer_index,
110 historical_index);
111 }
112
113 float ContentMotionEventImpl::GetHistoricalX(size_t pointer_index,
114 size_t historical_index) const {
115 return event_.android_event.GetHistoricalX(pointer_index, historical_index);
116 }
117
118 float ContentMotionEventImpl::GetHistoricalY(size_t pointer_index,
119 size_t historical_index) const {
120 return event_.android_event.GetHistoricalY(pointer_index, historical_index);
121 }
122
123 scoped_ptr<ui::MotionEvent> ContentMotionEventImpl::Clone() const {
124 return scoped_ptr<MotionEvent>(new ContentMotionEventImpl(
125 MotionEventAndroid::Obtain(event_.android_event).obj(),
126 true,
127 event_.device_scale_factor));
128 }
129
130 scoped_ptr<ui::MotionEvent> ContentMotionEventImpl::Cancel() const {
131 return scoped_ptr<MotionEvent>(new ContentMotionEventImpl(
132 MotionEventAndroid::Obtain(GetEventTime(),
133 GetEventTime(),
134 MotionEventAndroid::ACTION_CANCEL,
135 GetX(0),
136 GetY(0)).obj(),
137 true,
138 event_.device_scale_factor));
139 }
140
141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698