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

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

Issue 181833003: [Android] Out with the Android GR, in with the new unified C++ GR (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/motion_event_web.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 MotionEventWeb::MotionEventWeb(const WebTouchEvent& event)
62 : event_(event),
63 cached_action_(GetActionFrom(event)),
64 cached_action_index_(GetActionIndexFrom(event)) {
65 DCHECK_GT(GetPointerCount(), 0U);
66 }
67
68 MotionEventWeb::~MotionEventWeb() {}
69
70 MotionEventWeb::Action MotionEventWeb::GetAction() const {
71 return cached_action_;
72 }
73
74 int MotionEventWeb::GetActionIndex() const { return cached_action_index_; }
75
76 size_t MotionEventWeb::GetPointerCount() const { return event_.touchesLength; }
77
78 int MotionEventWeb::GetPointerId(size_t pointer_index) const {
79 DCHECK_LT(pointer_index, GetPointerCount());
80 return event_.touches[pointer_index].id;
81 }
82
83 float MotionEventWeb::GetX(size_t pointer_index) const {
84 DCHECK_LT(pointer_index, GetPointerCount());
85 return event_.touches[pointer_index].position.x;
86 }
87
88 float MotionEventWeb::GetY(size_t pointer_index) const {
89 DCHECK_LT(pointer_index, GetPointerCount());
90 return event_.touches[pointer_index].position.y;
91 }
92
93 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const {
94 DCHECK_LT(pointer_index, GetPointerCount());
95 // TODO(jdduke): We should be a bit more careful about axes here.
96 return 2.f * std::max(event_.touches[pointer_index].radiusX,
97 event_.touches[pointer_index].radiusY);
98 }
99
100 base::TimeTicks MotionEventWeb::GetEventTime() const {
101 return base::TimeTicks() +
102 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
103 base::Time::kMicrosecondsPerSecond);
104 }
105
106 size_t MotionEventWeb::GetHistorySize() const { return 0; }
107
108 base::TimeTicks MotionEventWeb::GetHistoricalEventTime(
109 size_t historical_index) const {
110 NOTIMPLEMENTED();
111 return base::TimeTicks();
112 }
113
114 float MotionEventWeb::GetHistoricalTouchMajor(size_t pointer_index,
115 size_t historical_index) const {
116 NOTIMPLEMENTED();
117 return 0.f;
118 }
119
120 float MotionEventWeb::GetHistoricalX(size_t pointer_index,
121 size_t historical_index) const {
122 NOTIMPLEMENTED();
123 return 0.f;
124 }
125
126 float MotionEventWeb::GetHistoricalY(size_t pointer_index,
127 size_t historical_index) const {
128 NOTIMPLEMENTED();
129 return 0.f;
130 }
131
132 scoped_ptr<ui::MotionEvent> MotionEventWeb::Clone() const {
133 return scoped_ptr<MotionEvent>(new MotionEventWeb(event_));
134 }
135
136 scoped_ptr<ui::MotionEvent> MotionEventWeb::Cancel() const {
137 WebTouchEvent cancel_event(event_);
138
139 cancel_event.type = WebInputEvent::TouchCancel;
140 for (size_t i = 0; i < cancel_event.touchesLength; ++i)
141 cancel_event.touches[i].state = WebTouchPoint::StateCancelled;
142
143 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event));
144 }
145
146 // StackAllocatedMotionEventWeb
147
148 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698