OLD | NEW |
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 "components/html_viewer/blink_input_events_type_converters.h" | 5 #include "components/html_viewer/blink_input_events_type_converters.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 "third_party/WebKit/public/web/WebInputEvent.h" | 9 #include "third_party/WebKit/public/web/WebInputEvent.h" |
10 #include "ui/mojo/events/input_event_constants.mojom.h" | 10 #include "ui/mojo/events/input_event_constants.mojom.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 int GetClickCount(int flags) { | 55 int GetClickCount(int flags) { |
56 if (flags & mojo::MOUSE_EVENT_FLAGS_IS_TRIPLE_CLICK) | 56 if (flags & mojo::MOUSE_EVENT_FLAGS_IS_TRIPLE_CLICK) |
57 return 3; | 57 return 3; |
58 else if (flags & mojo::MOUSE_EVENT_FLAGS_IS_DOUBLE_CLICK) | 58 else if (flags & mojo::MOUSE_EVENT_FLAGS_IS_DOUBLE_CLICK) |
59 return 2; | 59 return 2; |
60 | 60 |
61 return 1; | 61 return 1; |
62 } | 62 } |
63 | 63 |
64 void SetWebMouseEventLocation(const mojo::LocationData& location_data, | 64 void SetWebMouseEventLocation(const mojo::PointerData& pointer_data, |
65 blink::WebMouseEvent* web_event) { | 65 blink::WebMouseEvent* web_event) { |
66 web_event->x = static_cast<int>(location_data.x); | 66 web_event->x = static_cast<int>(pointer_data.x); |
67 web_event->y = static_cast<int>(location_data.y); | 67 web_event->y = static_cast<int>(pointer_data.y); |
68 web_event->globalX = static_cast<int>(location_data.screen_x); | 68 web_event->globalX = static_cast<int>(pointer_data.screen_x); |
69 web_event->globalY = static_cast<int>(location_data.screen_y); | 69 web_event->globalY = static_cast<int>(pointer_data.screen_y); |
70 } | 70 } |
71 | 71 |
72 scoped_ptr<blink::WebInputEvent> BuildWebMouseEventFrom(const EventPtr& event) { | 72 scoped_ptr<blink::WebInputEvent> BuildWebMouseEventFrom(const EventPtr& event) { |
73 scoped_ptr<blink::WebMouseEvent> web_event(new blink::WebMouseEvent); | 73 scoped_ptr<blink::WebMouseEvent> web_event(new blink::WebMouseEvent); |
74 | 74 |
75 SetWebMouseEventLocation(*(event->pointer_data->location), web_event.get()); | 75 SetWebMouseEventLocation(*(event->pointer_data), web_event.get()); |
76 | 76 |
77 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags); | 77 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags); |
78 web_event->timeStampSeconds = EventTimeToWebEventTime(event); | 78 web_event->timeStampSeconds = EventTimeToWebEventTime(event); |
79 | 79 |
80 web_event->button = blink::WebMouseEvent::ButtonNone; | 80 web_event->button = blink::WebMouseEvent::ButtonNone; |
81 if (event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) | 81 if (event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) |
82 web_event->button = blink::WebMouseEvent::ButtonLeft; | 82 web_event->button = blink::WebMouseEvent::ButtonLeft; |
83 if (event->flags & mojo::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON) | 83 if (event->flags & mojo::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON) |
84 web_event->button = blink::WebMouseEvent::ButtonMiddle; | 84 web_event->button = blink::WebMouseEvent::ButtonMiddle; |
85 if (event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON) | 85 if (event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 scoped_ptr<blink::WebInputEvent> BuildWebMouseWheelEventFrom( | 139 scoped_ptr<blink::WebInputEvent> BuildWebMouseWheelEventFrom( |
140 const EventPtr& event) { | 140 const EventPtr& event) { |
141 scoped_ptr<blink::WebMouseWheelEvent> web_event( | 141 scoped_ptr<blink::WebMouseWheelEvent> web_event( |
142 new blink::WebMouseWheelEvent); | 142 new blink::WebMouseWheelEvent); |
143 web_event->type = blink::WebInputEvent::MouseWheel; | 143 web_event->type = blink::WebInputEvent::MouseWheel; |
144 web_event->button = blink::WebMouseEvent::ButtonNone; | 144 web_event->button = blink::WebMouseEvent::ButtonNone; |
145 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags); | 145 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags); |
146 web_event->timeStampSeconds = EventTimeToWebEventTime(event); | 146 web_event->timeStampSeconds = EventTimeToWebEventTime(event); |
147 | 147 |
148 SetWebMouseEventLocation(*(event->wheel_data->location), web_event.get()); | 148 SetWebMouseEventLocation(*(event->pointer_data), web_event.get()); |
149 | 149 |
150 // TODO(rjkroege): Update the following code once Blink supports | 150 if ((event->flags & mojo::EVENT_FLAGS_SHIFT_DOWN) != 0 && |
151 // DOM Level 3 wheel events | 151 event->pointer_data->horizontal_wheel == 0) { |
152 // (http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents) | 152 web_event->deltaX = event->pointer_data->horizontal_wheel; |
153 web_event->deltaX = event->wheel_data->delta_x; | 153 web_event->deltaY = 0; |
154 web_event->deltaY = event->wheel_data->delta_y; | 154 } else { |
| 155 web_event->deltaX = event->pointer_data->horizontal_wheel; |
| 156 web_event->deltaY = event->pointer_data->vertical_wheel; |
| 157 } |
155 | 158 |
| 159 // TODO(sky): resole this, doesn't work for desktop. |
156 web_event->wheelTicksX = web_event->deltaX / kPixelsPerTick; | 160 web_event->wheelTicksX = web_event->deltaX / kPixelsPerTick; |
157 web_event->wheelTicksY = web_event->deltaY / kPixelsPerTick; | 161 web_event->wheelTicksY = web_event->deltaY / kPixelsPerTick; |
158 | 162 |
159 // TODO(rjkroege): Mandoline currently only generates WHEEL_MODE_LINE | |
160 // wheel events so the other modes are not yet tested. Verify that | |
161 // the implementation is correct. | |
162 switch (event->wheel_data->mode) { | |
163 case mojo::WHEEL_MODE_PIXEL: | |
164 web_event->hasPreciseScrollingDeltas = true; | |
165 web_event->scrollByPage = false; | |
166 web_event->canScroll = true; | |
167 break; | |
168 case mojo::WHEEL_MODE_LINE: | |
169 web_event->hasPreciseScrollingDeltas = false; | |
170 web_event->scrollByPage = false; | |
171 web_event->canScroll = true; | |
172 break; | |
173 case mojo::WHEEL_MODE_PAGE: | |
174 web_event->hasPreciseScrollingDeltas = false; | |
175 web_event->scrollByPage = true; | |
176 web_event->canScroll = true; | |
177 break; | |
178 case mojo::WHEEL_MODE_SCALING: | |
179 web_event->hasPreciseScrollingDeltas = false; | |
180 web_event->scrollByPage = false; | |
181 web_event->canScroll = false; | |
182 break; | |
183 } | |
184 | |
185 return web_event.Pass(); | 163 return web_event.Pass(); |
186 } | 164 } |
187 | 165 |
188 } // namespace | 166 } // namespace |
189 | 167 |
190 // static | 168 // static |
191 scoped_ptr<blink::WebInputEvent> | 169 scoped_ptr<blink::WebInputEvent> |
192 TypeConverter<scoped_ptr<blink::WebInputEvent>, EventPtr>::Convert( | 170 TypeConverter<scoped_ptr<blink::WebInputEvent>, EventPtr>::Convert( |
193 const EventPtr& event) { | 171 const EventPtr& event) { |
194 switch (event->action) { | 172 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || |
195 case mojo::EVENT_TYPE_POINTER_DOWN: | 173 event->action == mojo::EVENT_TYPE_POINTER_UP || |
196 case mojo::EVENT_TYPE_POINTER_UP: | 174 event->action == mojo::EVENT_TYPE_POINTER_CANCEL || |
197 case mojo::EVENT_TYPE_POINTER_CANCEL: | 175 event->action == mojo::EVENT_TYPE_POINTER_MOVE) { |
198 case mojo::EVENT_TYPE_POINTER_MOVE: | 176 if (event->pointer_data->horizontal_wheel != 0 || |
199 if (event->pointer_data->kind == mojo::POINTER_KIND_MOUSE) | 177 event->pointer_data->vertical_wheel != 0) { |
200 return BuildWebMouseEventFrom(event); | |
201 case mojo::EVENT_TYPE_WHEEL: | |
202 return BuildWebMouseWheelEventFrom(event); | 178 return BuildWebMouseWheelEventFrom(event); |
203 case mojo::EVENT_TYPE_KEY_PRESSED: | 179 } |
204 case mojo::EVENT_TYPE_KEY_RELEASED: | 180 if (event->pointer_data->kind == mojo::POINTER_KIND_MOUSE) |
205 return BuildWebKeyboardEvent(event); | 181 return BuildWebMouseEventFrom(event); |
206 case mojo::EVENT_TYPE_UNKNOWN: | 182 } else if ((event->action == mojo::EVENT_TYPE_KEY_PRESSED || |
207 return nullptr; | 183 event->action == mojo::EVENT_TYPE_KEY_RELEASED) && |
| 184 event->key_data) { |
| 185 return BuildWebKeyboardEvent(event); |
208 } | 186 } |
209 return nullptr; | 187 return nullptr; |
210 } | 188 } |
211 | 189 |
212 } // namespace mojo | 190 } // namespace mojo |
OLD | NEW |