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

Side by Side 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 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/gestures/motion_event.h"
6
7 #include "base/logging.h"
8
9 using blink::WebInputEvent;
10 using blink::WebTouchEvent;
11 using blink::WebTouchPoint;
12
13 namespace content {
14 namespace {
15
16 bool AllTouchPointsHaveState(const WebTouchEvent& event,
17 WebTouchPoint::State state) {
18 for (size_t i = 0; i < event.touchesLength; ++i)
19 if (event.touches[i].state != state)
20 return true;
21 return false;
22 }
23
24 } // namespace
25
26 MotionEvent::MotionEvent(const WebTouchEvent& event) : event(event) {
27 DCHECK_GT(GetPointerCount(), 0U);
28 }
29
30 MotionEvent::~MotionEvent() {}
31
32 MotionEvent::Action MotionEvent::GetActionMasked() const {
33 switch (event.type) {
34 case WebInputEvent::TouchStart:
35 if (AllTouchPointsHaveState(event, WebTouchPoint::StatePressed))
36 return ACTION_DOWN;
37 else
38 return ACTION_POINTER_DOWN;
39 case WebInputEvent::TouchEnd:
40 if (AllTouchPointsHaveState(event, WebTouchPoint::StateReleased))
41 return ACTION_UP;
42 else
43 return ACTION_POINTER_UP;
44 case WebInputEvent::TouchCancel:
45 DCHECK(AllTouchPointsHaveState(event, WebTouchPoint::StateCancelled));
46 return ACTION_CANCEL;
47 case WebInputEvent::TouchMove:
48 return ACTION_MOVE;
49 default:
50 break;
51 };
52 NOTREACHED() << "Invalid masked MotionEvent action.";
53 return ACTION_CANCEL;
54 }
55
56 size_t MotionEvent::GetActionIndex() const {
57 for (size_t i = 0; i < GetPointerCount(); ++i) {
58 if (event.touches[i].state != WebTouchPoint::StateUndefined &&
59 event.touches[i].state != WebTouchPoint::StateStationary)
60 return i;
61 }
62 NOTREACHED() << "Invalid MotionEvent action index.";
63 return 0;
64 }
65
66 size_t MotionEvent::GetPointerCount() const {
67 return event.touchesLength;
68 }
69
70 int MotionEvent::GetPointerId(size_t pointer_index) const {
71 DCHECK_LT(pointer_index, GetPointerCount());
72 return event.touches[pointer_index].id;
73 }
74
75 float MotionEvent::GetX(size_t pointer_index) const {
76 DCHECK_LT(pointer_index, GetPointerCount());
77 return event.touches[pointer_index].position.x;
78 }
79
80 float MotionEvent::GetY(size_t pointer_index) const {
81 DCHECK_LT(pointer_index, GetPointerCount());
82 return event.touches[pointer_index].position.y;
83 }
84
85 float MotionEvent::GetTouchMajor(size_t pointer_index) const {
86 DCHECK_LT(pointer_index, GetPointerCount());
87 // TODO(jdduke): We should be a bit more careful about axes here.
88 return std::max(event.touches[pointer_index].radiusX,
89 event.touches[pointer_index].radiusY);
90 }
91
92 base::TimeTicks MotionEvent::GetEventTime() const {
93 return base::TimeTicks() +
94 base::TimeDelta::FromMicroseconds(event.timeStampSeconds * 1000000);
95 }
96
97 base::TimeTicks MotionEvent::GetDownTime() const {
98 return base::TimeTicks() +
99 base::TimeDelta::FromMicroseconds(event.timeStampSeconds * 1000000);
100 }
101
102 size_t MotionEvent::GetHistorySize() const {
103 return 0;
104 }
105
106 base::TimeTicks MotionEvent::GetHistoricalEventTime(
107 size_t historical_index) const {
108 NOTIMPLEMENTED();
109 return base::TimeTicks();
110 }
111
112 float MotionEvent::GetHistoricalTouchMajor(size_t pointer_index,
113 size_t historical_index) const {
114 NOTIMPLEMENTED();
115 return 0.f;
116 }
117
118 float MotionEvent::GetHistoricalX(size_t pointer_index,
119 size_t historical_index) const {
120 NOTIMPLEMENTED();
121 return 0.f;
122 }
123
124 float MotionEvent::GetHistoricalY(size_t pointer_index,
125 size_t historical_index) const {
126 NOTIMPLEMENTED();
127 return 0.f;
128 }
129
130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698