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

Side by Side Diff: content/browser/renderer_host/input/content_motion_event_impl.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
9 using blink::WebInputEvent;
10 using blink::WebPoint;
11 using blink::WebTouchEvent;
12 using blink::WebTouchPoint;
13
14 namespace content {
15 namespace {
16
17 bool AllTouchPointsHaveState(const WebTouchEvent& event,
18 WebTouchPoint::State state) {
19 for (size_t i = 0; i < event.touchesLength; ++i) {
20 if (event.touches[i].state != state)
21 return false;
22 }
23 return true;
24 }
25
26 ui::MotionEvent::Action GetActionFrom(const WebTouchEvent& event) {
27 switch (event.type) {
28 case WebInputEvent::TouchStart:
29 if (AllTouchPointsHaveState(event, WebTouchPoint::StatePressed))
30 return ui::MotionEvent::ACTION_DOWN;
31 else
32 return ui::MotionEvent::ACTION_POINTER_DOWN;
33 case WebInputEvent::TouchEnd:
34 if (AllTouchPointsHaveState(event, WebTouchPoint::StateReleased))
35 return ui::MotionEvent::ACTION_UP;
36 else
37 return ui::MotionEvent::ACTION_POINTER_UP;
38 case WebInputEvent::TouchCancel:
39 DCHECK(AllTouchPointsHaveState(event, WebTouchPoint::StateCancelled));
40 return ui::MotionEvent::ACTION_CANCEL;
41 case WebInputEvent::TouchMove:
42 return ui::MotionEvent::ACTION_MOVE;
43 default:
44 break;
45 };
46 NOTREACHED() << "Invalid masked TouchEvent action.";
47 return ui::MotionEvent::ACTION_CANCEL;
48 }
49
50 int GetActionIndexFrom(const WebTouchEvent& event) {
51 for (size_t i = 0; i < event.touchesLength; ++i) {
52 if (event.touches[i].state != WebTouchPoint::StateUndefined &&
53 event.touches[i].state != WebTouchPoint::StateStationary)
54 return i;
55 }
56 return -1;
57 }
58
59 } // namespace
60
61 ContentMotionEventImpl::ContentMotionEventImpl(const NativeWebTouchEvent& event)
62 : event_(event),
63 cached_action_(GetActionFrom(event)),
64 cached_action_index_(GetActionIndexFrom(event)) {
65 DCHECK_GT(GetPointerCount(), 0U);
66 }
67
68 ContentMotionEventImpl::~ContentMotionEventImpl() {}
69
70 ContentMotionEventImpl::Action ContentMotionEventImpl::GetAction() const {
71 return cached_action_;
72 }
73
74 int ContentMotionEventImpl::GetActionIndex() const {
75 return cached_action_index_;
76 }
77
78 size_t ContentMotionEventImpl::GetPointerCount() const {
79 return event_.touchesLength;
80 }
81
82 int ContentMotionEventImpl::GetPointerId(size_t pointer_index) const {
83 DCHECK_LT(pointer_index, GetPointerCount());
84 return event_.touches[pointer_index].id;
85 }
86
87 float ContentMotionEventImpl::GetX(size_t pointer_index) const {
88 DCHECK_LT(pointer_index, GetPointerCount());
89 return event_.touches[pointer_index].position.x;
90 }
91
92 float ContentMotionEventImpl::GetY(size_t pointer_index) const {
93 DCHECK_LT(pointer_index, GetPointerCount());
94 return event_.touches[pointer_index].position.y;
95 }
96
97 float ContentMotionEventImpl::GetTouchMajor(size_t pointer_index) const {
98 DCHECK_LT(pointer_index, GetPointerCount());
99 // TODO(jdduke): We should be a bit more careful about axes here.
100 return 2.f * std::max(event_.touches[pointer_index].radiusX,
101 event_.touches[pointer_index].radiusY);
102 }
103
104 base::TimeTicks ContentMotionEventImpl::GetEventTime() const {
105 return base::TimeTicks() +
106 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
107 base::Time::kMicrosecondsPerSecond);
108 }
109
110 size_t ContentMotionEventImpl::GetHistorySize() const {
111 return 0;
112 }
113
114 base::TimeTicks ContentMotionEventImpl::GetHistoricalEventTime(
115 size_t historical_index) const {
116 NOTIMPLEMENTED();
117 return base::TimeTicks();
118 }
119
120 float ContentMotionEventImpl::GetHistoricalTouchMajor(
121 size_t pointer_index,
122 size_t historical_index) const {
123 NOTIMPLEMENTED();
124 return 0.f;
125 }
126
127 float ContentMotionEventImpl::GetHistoricalX(size_t pointer_index,
128 size_t historical_index) const {
129 NOTIMPLEMENTED();
130 return 0.f;
131 }
132
133 float ContentMotionEventImpl::GetHistoricalY(size_t pointer_index,
134 size_t historical_index) const {
135 NOTIMPLEMENTED();
136 return 0.f;
137 }
138
139 scoped_ptr<ui::MotionEvent> ContentMotionEventImpl::Clone() const {
140 return scoped_ptr<MotionEvent>(new ContentMotionEventImpl(event_));
141 }
142
143 scoped_ptr<ui::MotionEvent> ContentMotionEventImpl::Cancel() const {
144 NativeWebTouchEvent cancel_event(event_);
145
146 cancel_event.type = WebInputEvent::TouchCancel;
147 for (size_t i = 0; i < cancel_event.touchesLength; ++i)
148 cancel_event.touches[i].state = WebTouchPoint::StateCancelled;
149
150 return scoped_ptr<MotionEvent>(new ContentMotionEventImpl(cancel_event));
151 }
152
153 // StackAllocatedContentMotionEventImpl
154
155
156 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698