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

Side by Side Diff: sky/viewer/converters/input_event_types.cc

Issue 847873003: Add support for touch events to sky_viewer (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « sky/examples/touch-demo.sky ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "sky/viewer/converters/input_event_types.h" 5 #include "sky/viewer/converters/input_event_types.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "mojo/services/input_events/public/interfaces/input_event_constants.moj om.h" 9 #include "mojo/services/input_events/public/interfaces/input_event_constants.moj om.h"
10 #include "sky/engine/public/web/WebInputEvent.h" 10 #include "sky/engine/public/web/WebInputEvent.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 int GetClickCount(int flags) { 51 int GetClickCount(int flags) {
52 if (flags & mojo::MOUSE_EVENT_FLAGS_IS_TRIPLE_CLICK) 52 if (flags & mojo::MOUSE_EVENT_FLAGS_IS_TRIPLE_CLICK)
53 return 3; 53 return 3;
54 else if (flags & mojo::MOUSE_EVENT_FLAGS_IS_DOUBLE_CLICK) 54 else if (flags & mojo::MOUSE_EVENT_FLAGS_IS_DOUBLE_CLICK)
55 return 2; 55 return 2;
56 56
57 return 1; 57 return 1;
58 } 58 }
59 59
60 scoped_ptr<blink::WebInputEvent> BuildWebTouchEvent(const EventPtr& event) {
61 scoped_ptr<blink::WebTouchEvent> web_event(new blink::WebTouchEvent);
62
63 web_event->timeStampSeconds =
64 base::TimeDelta::FromInternalValue(event->time_stamp).InSecondsF();
65
66 web_event->touchesLength = 1;
67 web_event->changedTouchesLength = 1;
68 web_event->targetTouchesLength = 1;
69
70 blink::WebTouchPoint touch;
71
72 switch (event->action) {
73 case EVENT_TYPE_TOUCH_RELEASED:
74 web_event->type = blink::WebInputEvent::TouchEnd;
75 touch.state = blink::WebTouchPoint::StateReleased;
76 break;
77 case EVENT_TYPE_TOUCH_PRESSED:
78 web_event->type = blink::WebInputEvent::TouchStart;
79 touch.state = blink::WebTouchPoint::StatePressed;
80 break;
81 case EVENT_TYPE_TOUCH_MOVED:
82 web_event->type = blink::WebInputEvent::TouchMove;
83 touch.state = blink::WebTouchPoint::StateMoved;
84 break;
85 case EVENT_TYPE_TOUCH_CANCELLED:
86 web_event->type = blink::WebInputEvent::TouchCancel;
87 touch.state = blink::WebTouchPoint::StateCancelled;
88 break;
89 default:
90 NOTIMPLEMENTED() << "Received unexpected event: " << event->action;
91 break;
92 }
93
94 touch.id = event->touch_data->pointer_id;
95
96 touch.position.x = event->location_data->in_view_location->x;
97 touch.position.y = event->location_data->in_view_location->y;
98
99 if (event->location_data->screen_location) {
100 touch.screenPosition.x = event->location_data->screen_location->x;
101 touch.screenPosition.y = event->location_data->screen_location->y;
102 }
103
104 if (web_event->touchesLength)
105 web_event->touches[0] = touch;
106 if (web_event->changedTouchesLength)
107 web_event->changedTouches[0] = touch;
108 if (web_event->targetTouchesLength)
109 web_event->targetTouches[0] = touch;
110
111 web_event->cancelable = true;
112
113 return web_event.Pass();
114 }
115
60 scoped_ptr<blink::WebInputEvent> BuildWebMouseEventFrom(const EventPtr& event) { 116 scoped_ptr<blink::WebInputEvent> BuildWebMouseEventFrom(const EventPtr& event) {
61 scoped_ptr<blink::WebMouseEvent> web_event(new blink::WebMouseEvent); 117 scoped_ptr<blink::WebMouseEvent> web_event(new blink::WebMouseEvent);
62 web_event->x = event->location_data->in_view_location->x; 118 web_event->x = event->location_data->in_view_location->x;
63 web_event->y = event->location_data->in_view_location->y; 119 web_event->y = event->location_data->in_view_location->y;
64 120
65 // TODO(erg): Remove this if check once we can rely on screen_location 121 // TODO(erg): Remove this if check once we can rely on screen_location
66 // actually being passed to us. As written today, getting the screen 122 // actually being passed to us. As written today, getting the screen
67 // location from ui::Event objects can only be done by querying the 123 // location from ui::Event objects can only be done by querying the
68 // underlying native events, so all synthesized events don't have screen 124 // underlying native events, so all synthesized events don't have screen
69 // locations. 125 // locations.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 231
176 return web_event.Pass(); 232 return web_event.Pass();
177 } 233 }
178 234
179 } // namespace 235 } // namespace
180 236
181 // static 237 // static
182 scoped_ptr<blink::WebInputEvent> 238 scoped_ptr<blink::WebInputEvent>
183 TypeConverter<scoped_ptr<blink::WebInputEvent>, EventPtr>::Convert( 239 TypeConverter<scoped_ptr<blink::WebInputEvent>, EventPtr>::Convert(
184 const EventPtr& event) { 240 const EventPtr& event) {
185 if (event->action == EVENT_TYPE_MOUSE_PRESSED || 241 if (event->action == EVENT_TYPE_TOUCH_RELEASED ||
242 event->action == EVENT_TYPE_TOUCH_PRESSED ||
243 event->action == EVENT_TYPE_TOUCH_MOVED ||
244 event->action == EVENT_TYPE_TOUCH_CANCELLED) {
245 return BuildWebTouchEvent(event);
246 } else if (event->action == EVENT_TYPE_MOUSE_PRESSED ||
186 event->action == EVENT_TYPE_MOUSE_RELEASED || 247 event->action == EVENT_TYPE_MOUSE_RELEASED ||
187 event->action == EVENT_TYPE_MOUSE_ENTERED || 248 event->action == EVENT_TYPE_MOUSE_ENTERED ||
188 event->action == EVENT_TYPE_MOUSE_EXITED || 249 event->action == EVENT_TYPE_MOUSE_EXITED ||
189 event->action == EVENT_TYPE_MOUSE_MOVED || 250 event->action == EVENT_TYPE_MOUSE_MOVED ||
190 event->action == EVENT_TYPE_MOUSE_DRAGGED) { 251 event->action == EVENT_TYPE_MOUSE_DRAGGED) {
191 return BuildWebMouseEventFrom(event); 252 return BuildWebMouseEventFrom(event);
192 } else if ((event->action == EVENT_TYPE_KEY_PRESSED || 253 } else if ((event->action == EVENT_TYPE_KEY_PRESSED ||
193 event->action == EVENT_TYPE_KEY_RELEASED) && 254 event->action == EVENT_TYPE_KEY_RELEASED) &&
194 event->key_data) { 255 event->key_data) {
195 return BuildWebKeyboardEvent(event); 256 return BuildWebKeyboardEvent(event);
196 } else if (event->action == EVENT_TYPE_MOUSEWHEEL) { 257 } else if (event->action == EVENT_TYPE_MOUSEWHEEL) {
197 return BuildWebMouseWheelEventFrom(event); 258 return BuildWebMouseWheelEventFrom(event);
198 } 259 }
199 260
200 return scoped_ptr<blink::WebInputEvent>(); 261 return scoped_ptr<blink::WebInputEvent>();
201 } 262 }
202 263
203 } // namespace mojo 264 } // namespace mojo
OLDNEW
« no previous file with comments | « sky/examples/touch-demo.sky ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698