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

Side by Side Diff: content/browser/renderer_host/ui_events_helper.cc

Issue 510793003: Remove ui::TouchEvent -> blink::WebTouchEvent conversion methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix broken test. Created 5 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/ui_events_helper.h" 5 #include "content/browser/renderer_host/ui_events_helper.h"
6 6
7 #include "content/browser/renderer_host/input/web_input_event_util.h" 7 #include "content/browser/renderer_host/input/web_input_event_util.h"
8 #include "content/common/input/web_touch_event_traits.h" 8 #include "content/common/input/web_touch_event_traits.h"
9 #include "third_party/WebKit/public/web/WebInputEvent.h" 9 #include "third_party/WebKit/public/web/WebInputEvent.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
(...skipping 14 matching lines...) Expand all
25 return ui::ET_TOUCH_MOVED; 25 return ui::ET_TOUCH_MOVED;
26 26
27 case blink::WebTouchPoint::StateCancelled: 27 case blink::WebTouchPoint::StateCancelled:
28 return ui::ET_TOUCH_CANCELLED; 28 return ui::ET_TOUCH_CANCELLED;
29 29
30 default: 30 default:
31 return ui::ET_UNKNOWN; 31 return ui::ET_UNKNOWN;
32 } 32 }
33 } 33 }
34 34
35 blink::WebTouchPoint::State TouchPointStateFromEvent(
36 const ui::TouchEvent& event) {
37 switch (event.type()) {
38 case ui::ET_TOUCH_PRESSED:
39 return blink::WebTouchPoint::StatePressed;
40 case ui::ET_TOUCH_RELEASED:
41 return blink::WebTouchPoint::StateReleased;
42 case ui::ET_TOUCH_MOVED:
43 return blink::WebTouchPoint::StateMoved;
44 case ui::ET_TOUCH_CANCELLED:
45 return blink::WebTouchPoint::StateCancelled;
46 default:
47 return blink::WebTouchPoint::StateUndefined;
48 }
49 }
50
51 blink::WebInputEvent::Type TouchEventTypeFromEvent(
52 const ui::TouchEvent& event) {
53 switch (event.type()) {
54 case ui::ET_TOUCH_PRESSED:
55 return blink::WebInputEvent::TouchStart;
56 case ui::ET_TOUCH_RELEASED:
57 return blink::WebInputEvent::TouchEnd;
58 case ui::ET_TOUCH_MOVED:
59 return blink::WebInputEvent::TouchMove;
60 case ui::ET_TOUCH_CANCELLED:
61 return blink::WebInputEvent::TouchCancel;
62 default:
63 return blink::WebInputEvent::Undefined;
64 }
65 }
66
67 } // namespace 35 } // namespace
68 36
69 namespace content { 37 namespace content {
70 38
71 bool MakeUITouchEventsFromWebTouchEvents( 39 bool MakeUITouchEventsFromWebTouchEvents(
72 const TouchEventWithLatencyInfo& touch_with_latency, 40 const TouchEventWithLatencyInfo& touch_with_latency,
73 ScopedVector<ui::TouchEvent>* list, 41 ScopedVector<ui::TouchEvent>* list,
74 TouchEventCoordinateSystem coordinate_system) { 42 TouchEventCoordinateSystem coordinate_system) {
75 const blink::WebTouchEvent& touch = touch_with_latency.event; 43 const blink::WebTouchEvent& touch = touch_with_latency.event;
76 ui::EventType type = ui::ET_UNKNOWN; 44 ui::EventType type = ui::ET_UNKNOWN;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 90
123 blink::WebGestureEvent MakeWebGestureEventFromUIEvent( 91 blink::WebGestureEvent MakeWebGestureEventFromUIEvent(
124 const ui::GestureEvent& event) { 92 const ui::GestureEvent& event) {
125 return CreateWebGestureEvent(event.details(), 93 return CreateWebGestureEvent(event.details(),
126 event.time_stamp(), 94 event.time_stamp(),
127 event.location_f(), 95 event.location_f(),
128 event.root_location_f(), 96 event.root_location_f(),
129 event.flags()); 97 event.flags());
130 } 98 }
131 99
132 blink::WebTouchPoint* UpdateWebTouchEventFromUIEvent(
133 const ui::TouchEvent& event,
134 blink::WebTouchEvent* web_event) {
135 blink::WebTouchPoint* point = NULL;
136 switch (event.type()) {
137 case ui::ET_TOUCH_PRESSED:
138 // Add a new touch point.
139 if (web_event->touchesLength < blink::WebTouchEvent::touchesLengthCap) {
140 point = &web_event->touches[web_event->touchesLength++];
141 point->id = event.touch_id();
142 }
143 break;
144 case ui::ET_TOUCH_RELEASED:
145 case ui::ET_TOUCH_CANCELLED:
146 case ui::ET_TOUCH_MOVED: {
147 // The touch point should have been added to the event from an earlier
148 // _PRESSED event. So find that.
149 // At the moment, only a maximum of 4 touch-points are allowed. So a
150 // simple loop should be sufficient.
151 for (unsigned i = 0; i < web_event->touchesLength; ++i) {
152 point = web_event->touches + i;
153 if (point->id == event.touch_id())
154 break;
155 point = NULL;
156 }
157 break;
158 }
159 default:
160 DLOG(WARNING) << "Unknown touch event " << event.type();
161 break;
162 }
163
164 if (!point)
165 return NULL;
166
167 // The spec requires the radii values to be positive (and 1 when unknown).
168 point->radiusX = std::max(1.f, event.radius_x());
169 point->radiusY = std::max(1.f, event.radius_y());
170 point->rotationAngle = event.rotation_angle();
171 point->force = event.force();
172
173 // Update the location and state of the point.
174 point->state = TouchPointStateFromEvent(event);
175 point->position.x = event.x();
176 point->position.y = event.y();
177
178 const gfx::PointF& root_point = event.root_location_f();
179 point->screenPosition.x = root_point.x();
180 point->screenPosition.y = root_point.y();
181
182 // Mark the rest of the points as stationary.
183 for (unsigned i = 0; i < web_event->touchesLength; ++i) {
184 blink::WebTouchPoint* iter = web_event->touches + i;
185 if (iter != point)
186 iter->state = blink::WebTouchPoint::StateStationary;
187 }
188
189 // Update the type of the touch event.
190 WebTouchEventTraits::ResetType(TouchEventTypeFromEvent(event),
191 event.time_stamp().InSecondsF(),
192 web_event);
193 web_event->causesScrollingIfUncanceled = event.may_cause_scrolling();
194 web_event->modifiers = EventFlagsToWebEventModifiers(event.flags());
195
196 return point;
197 }
198
199 } // namespace content 100 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/ui_events_helper.h ('k') | content/browser/web_contents/web_contents_view_aura_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698