OLD | NEW |
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/renderer/pepper/event_conversion.h" | 5 #include "content/renderer/pepper/event_conversion.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) == | 74 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) == |
75 static_cast<int>(WebInputEvent::NumLockOn), | 75 static_cast<int>(WebInputEvent::NumLockOn), |
76 "NumLock should match"); | 76 "NumLock should match"); |
77 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISLEFT) == | 77 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISLEFT) == |
78 static_cast<int>(WebInputEvent::IsLeft), | 78 static_cast<int>(WebInputEvent::IsLeft), |
79 "IsLeft should match"); | 79 "IsLeft should match"); |
80 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISRIGHT) == | 80 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISRIGHT) == |
81 static_cast<int>(WebInputEvent::IsRight), | 81 static_cast<int>(WebInputEvent::IsRight), |
82 "IsRight should match"); | 82 "IsRight should match"); |
83 | 83 |
84 bool IsStylusEvent(const WebInputEvent& event) { | |
85 switch (event.type) { | |
86 case WebInputEvent::MouseDown: | |
87 case WebInputEvent::MouseUp: | |
88 case WebInputEvent::MouseMove: { | |
89 const WebMouseEvent& mouse_event = | |
90 static_cast<const WebMouseEvent&>(event); | |
91 using PointerType = blink::WebPointerProperties::PointerType; | |
92 return mouse_event.pointerType == PointerType::Pen || | |
93 mouse_event.pointerType == PointerType::Eraser; | |
94 } | |
95 default: | |
96 return false; | |
97 } | |
98 } | |
99 | |
100 PP_InputEvent_Type ConvertEventTypes(const WebInputEvent& event) { | 84 PP_InputEvent_Type ConvertEventTypes(const WebInputEvent& event) { |
101 if (IsStylusEvent(event)) { | |
102 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | |
103 if (mouse_event.button != blink::WebMouseEvent::Button::Left && | |
104 !(mouse_event.modifiers & blink::WebInputEvent::LeftButtonDown)) | |
105 return PP_INPUTEVENT_TYPE_UNDEFINED; | |
106 | |
107 switch (event.type) { | |
108 case WebInputEvent::MouseDown: | |
109 return PP_INPUTEVENT_TYPE_TOUCHSTART; | |
110 case WebInputEvent::MouseUp: | |
111 return PP_INPUTEVENT_TYPE_TOUCHEND; | |
112 case WebInputEvent::MouseMove: | |
113 return PP_INPUTEVENT_TYPE_TOUCHMOVE; | |
114 default: | |
115 return PP_INPUTEVENT_TYPE_UNDEFINED; | |
116 } | |
117 } | |
118 switch (event.type) { | 85 switch (event.type) { |
119 case WebInputEvent::MouseDown: | 86 case WebInputEvent::MouseDown: |
120 return PP_INPUTEVENT_TYPE_MOUSEDOWN; | 87 return PP_INPUTEVENT_TYPE_MOUSEDOWN; |
121 case WebInputEvent::MouseUp: | 88 case WebInputEvent::MouseUp: |
122 return PP_INPUTEVENT_TYPE_MOUSEUP; | 89 return PP_INPUTEVENT_TYPE_MOUSEUP; |
123 case WebInputEvent::MouseMove: | 90 case WebInputEvent::MouseMove: |
124 return PP_INPUTEVENT_TYPE_MOUSEMOVE; | 91 return PP_INPUTEVENT_TYPE_MOUSEMOVE; |
125 case WebInputEvent::MouseEnter: | 92 case WebInputEvent::MouseEnter: |
126 return PP_INPUTEVENT_TYPE_MOUSEENTER; | 93 return PP_INPUTEVENT_TYPE_MOUSEENTER; |
127 case WebInputEvent::MouseLeave: | 94 case WebInputEvent::MouseLeave: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 while (!iter.end()) { | 179 while (!iter.end()) { |
213 InputEventData result = GetEventWithCommonFieldsAndType(event); | 180 InputEventData result = GetEventWithCommonFieldsAndType(event); |
214 result.event_modifiers = ConvertEventModifiers(key_event.modifiers); | 181 result.event_modifiers = ConvertEventModifiers(key_event.modifiers); |
215 base::WriteUnicodeCharacter(iter.get(), &result.character_text); | 182 base::WriteUnicodeCharacter(iter.get(), &result.character_text); |
216 | 183 |
217 result_events->push_back(result); | 184 result_events->push_back(result); |
218 iter.Advance(); | 185 iter.Advance(); |
219 } | 186 } |
220 } | 187 } |
221 | 188 |
222 void AppendStylusTouchEvent(const WebInputEvent& event, | |
223 std::vector<InputEventData>* result_events) { | |
224 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | |
225 | |
226 InputEventData result = GetEventWithCommonFieldsAndType(event); | |
227 result.event_modifiers = ConvertEventModifiers(event.modifiers); | |
228 if (result.event_type == PP_INPUTEVENT_TYPE_UNDEFINED) | |
229 return; | |
230 | |
231 PP_TouchPoint touch_point; | |
232 touch_point.id = 0; | |
233 touch_point.position.x = mouse_event.x; | |
234 touch_point.position.y = mouse_event.y; | |
235 touch_point.pressure = mouse_event.force; | |
236 | |
237 result.changed_touches.push_back(touch_point); | |
238 result.target_touches.push_back(touch_point); | |
239 if (result.event_type != PP_INPUTEVENT_TYPE_TOUCHEND) | |
240 result.touches.push_back(touch_point); | |
241 | |
242 result_events->push_back(result); | |
243 } | |
244 | |
245 void AppendMouseEvent(const WebInputEvent& event, | 189 void AppendMouseEvent(const WebInputEvent& event, |
246 std::vector<InputEventData>* result_events) { | 190 std::vector<InputEventData>* result_events) { |
247 static_assert(static_cast<int>(WebMouseEvent::Button::NoButton) == | 191 static_assert(static_cast<int>(WebMouseEvent::Button::NoButton) == |
248 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), | 192 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), |
249 "MouseNone should match"); | 193 "MouseNone should match"); |
250 static_assert(static_cast<int>(WebMouseEvent::Button::Left) == | 194 static_assert(static_cast<int>(WebMouseEvent::Button::Left) == |
251 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), | 195 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), |
252 "MouseLeft should match"); | 196 "MouseLeft should match"); |
253 static_assert(static_cast<int>(WebMouseEvent::Button::Right) == | 197 static_assert(static_cast<int>(WebMouseEvent::Button::Right) == |
254 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), | 198 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), |
255 "MouseRight should match"); | 199 "MouseRight should match"); |
256 static_assert(static_cast<int>(WebMouseEvent::Button::Middle) == | 200 static_assert(static_cast<int>(WebMouseEvent::Button::Middle) == |
257 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), | 201 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), |
258 "MouseMiddle should match"); | 202 "MouseMiddle should match"); |
259 | 203 |
260 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | 204 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
261 InputEventData result = GetEventWithCommonFieldsAndType(event); | 205 InputEventData result = GetEventWithCommonFieldsAndType(event); |
262 result.event_modifiers = ConvertEventModifiers(mouse_event.modifiers); | 206 result.event_modifiers = ConvertEventModifiers(mouse_event.modifiers); |
263 if (mouse_event.pointerType == | |
264 blink::WebPointerProperties::PointerType::Pen) { | |
265 result.event_modifiers |= PP_INPUTEVENT_MODIFIER_ISPEN; | |
266 } else if (mouse_event.pointerType == | |
267 blink::WebPointerProperties::PointerType::Eraser) { | |
268 result.event_modifiers |= PP_INPUTEVENT_MODIFIER_ISERASER; | |
269 } | |
270 if (mouse_event.type == WebInputEvent::MouseDown || | 207 if (mouse_event.type == WebInputEvent::MouseDown || |
271 mouse_event.type == WebInputEvent::MouseMove || | 208 mouse_event.type == WebInputEvent::MouseMove || |
272 mouse_event.type == WebInputEvent::MouseUp) { | 209 mouse_event.type == WebInputEvent::MouseUp) { |
273 result.mouse_button = | 210 result.mouse_button = |
274 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); | 211 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); |
275 } | 212 } |
276 result.mouse_position.x = mouse_event.x; | 213 result.mouse_position.x = mouse_event.x; |
277 result.mouse_position.y = mouse_event.y; | 214 result.mouse_position.y = mouse_event.y; |
278 result.mouse_click_count = mouse_event.clickCount; | 215 result.mouse_click_count = mouse_event.clickCount; |
279 result.mouse_movement.x = mouse_event.movementX; | 216 result.mouse_movement.x = mouse_event.movementX; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 result->push_back(pp_pt); | 264 result->push_back(pp_pt); |
328 } | 265 } |
329 } | 266 } |
330 | 267 |
331 void AppendTouchEvent(const WebInputEvent& event, | 268 void AppendTouchEvent(const WebInputEvent& event, |
332 std::vector<InputEventData>* result_events) { | 269 std::vector<InputEventData>* result_events) { |
333 const WebTouchEvent& touch_event = | 270 const WebTouchEvent& touch_event = |
334 reinterpret_cast<const WebTouchEvent&>(event); | 271 reinterpret_cast<const WebTouchEvent&>(event); |
335 | 272 |
336 InputEventData result = GetEventWithCommonFieldsAndType(event); | 273 InputEventData result = GetEventWithCommonFieldsAndType(event); |
| 274 |
| 275 if (touch_event.touchesLength == 1) { |
| 276 if (touch_event.touches[0].pointerType == |
| 277 blink::WebPointerProperties::PointerType::Pen) { |
| 278 result.event_modifiers |= PP_INPUTEVENT_MODIFIER_ISPEN; |
| 279 } else if (touch_event.touches[0].pointerType == |
| 280 blink::WebPointerProperties::PointerType::Eraser) { |
| 281 result.event_modifiers |= PP_INPUTEVENT_MODIFIER_ISERASER; |
| 282 } |
| 283 } |
| 284 |
337 SetPPTouchPoints( | 285 SetPPTouchPoints( |
338 touch_event.touches, touch_event.touchesLength, ACTIVE, &result.touches); | 286 touch_event.touches, touch_event.touchesLength, ACTIVE, &result.touches); |
339 SetPPTouchPoints(touch_event.touches, | 287 SetPPTouchPoints(touch_event.touches, |
340 touch_event.touchesLength, | 288 touch_event.touchesLength, |
341 CHANGED, | 289 CHANGED, |
342 &result.changed_touches); | 290 &result.changed_touches); |
343 SetPPTouchPoints(touch_event.touches, | 291 SetPPTouchPoints(touch_event.touches, |
344 touch_event.touchesLength, | 292 touch_event.touchesLength, |
345 ALL, | 293 ALL, |
346 &result.target_touches); | 294 &result.target_touches); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 std::vector<InputEventData>* result) { | 577 std::vector<InputEventData>* result) { |
630 result->clear(); | 578 result->clear(); |
631 | 579 |
632 switch (event.type) { | 580 switch (event.type) { |
633 case WebInputEvent::MouseDown: | 581 case WebInputEvent::MouseDown: |
634 case WebInputEvent::MouseUp: | 582 case WebInputEvent::MouseUp: |
635 case WebInputEvent::MouseMove: | 583 case WebInputEvent::MouseMove: |
636 case WebInputEvent::MouseEnter: | 584 case WebInputEvent::MouseEnter: |
637 case WebInputEvent::MouseLeave: | 585 case WebInputEvent::MouseLeave: |
638 case WebInputEvent::ContextMenu: | 586 case WebInputEvent::ContextMenu: |
639 if (IsStylusEvent(event)) { | 587 AppendMouseEvent(event, result); |
640 AppendStylusTouchEvent(event, result); | |
641 } else { | |
642 AppendMouseEvent(event, result); | |
643 } | |
644 break; | 588 break; |
645 case WebInputEvent::MouseWheel: | 589 case WebInputEvent::MouseWheel: |
646 AppendMouseWheelEvent(event, result); | 590 AppendMouseWheelEvent(event, result); |
647 break; | 591 break; |
648 case WebInputEvent::RawKeyDown: | 592 case WebInputEvent::RawKeyDown: |
649 case WebInputEvent::KeyDown: | 593 case WebInputEvent::KeyDown: |
650 case WebInputEvent::KeyUp: | 594 case WebInputEvent::KeyUp: |
651 AppendKeyEvent(event, result); | 595 AppendKeyEvent(event, result); |
652 break; | 596 break; |
653 case WebInputEvent::Char: | 597 case WebInputEvent::Char: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } | 746 } |
803 | 747 |
804 PP_InputEvent_Class ClassifyInputEvent(const WebInputEvent& event) { | 748 PP_InputEvent_Class ClassifyInputEvent(const WebInputEvent& event) { |
805 switch (event.type) { | 749 switch (event.type) { |
806 case WebInputEvent::MouseDown: | 750 case WebInputEvent::MouseDown: |
807 case WebInputEvent::MouseUp: | 751 case WebInputEvent::MouseUp: |
808 case WebInputEvent::MouseMove: | 752 case WebInputEvent::MouseMove: |
809 case WebInputEvent::MouseEnter: | 753 case WebInputEvent::MouseEnter: |
810 case WebInputEvent::MouseLeave: | 754 case WebInputEvent::MouseLeave: |
811 case WebInputEvent::ContextMenu: | 755 case WebInputEvent::ContextMenu: |
812 if (IsStylusEvent(event)) { | 756 return PP_INPUTEVENT_CLASS_MOUSE; |
813 return PP_INPUTEVENT_CLASS_TOUCH; | |
814 } else { | |
815 return PP_INPUTEVENT_CLASS_MOUSE; | |
816 } | |
817 case WebInputEvent::MouseWheel: | 757 case WebInputEvent::MouseWheel: |
818 return PP_INPUTEVENT_CLASS_WHEEL; | 758 return PP_INPUTEVENT_CLASS_WHEEL; |
819 case WebInputEvent::RawKeyDown: | 759 case WebInputEvent::RawKeyDown: |
820 case WebInputEvent::KeyDown: | 760 case WebInputEvent::KeyDown: |
821 case WebInputEvent::KeyUp: | 761 case WebInputEvent::KeyUp: |
822 case WebInputEvent::Char: | 762 case WebInputEvent::Char: |
823 return PP_INPUTEVENT_CLASS_KEYBOARD; | 763 return PP_INPUTEVENT_CLASS_KEYBOARD; |
824 case WebInputEvent::TouchCancel: | 764 case WebInputEvent::TouchCancel: |
825 case WebInputEvent::TouchEnd: | 765 case WebInputEvent::TouchEnd: |
826 case WebInputEvent::TouchMove: | 766 case WebInputEvent::TouchMove: |
827 case WebInputEvent::TouchStart: | 767 case WebInputEvent::TouchStart: |
828 return PP_INPUTEVENT_CLASS_TOUCH; | 768 return PP_INPUTEVENT_CLASS_TOUCH; |
829 case WebInputEvent::TouchScrollStarted: | 769 case WebInputEvent::TouchScrollStarted: |
830 return PP_InputEvent_Class(0); | 770 return PP_InputEvent_Class(0); |
831 default: | 771 default: |
832 CHECK(WebInputEvent::isGestureEventType(event.type)); | 772 CHECK(WebInputEvent::isGestureEventType(event.type)); |
833 return PP_InputEvent_Class(0); | 773 return PP_InputEvent_Class(0); |
834 } | 774 } |
835 } | 775 } |
836 | 776 |
837 } // namespace content | 777 } // namespace content |
OLD | NEW |