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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 case WebInputEvent::TouchEnd: | 112 case WebInputEvent::TouchEnd: |
113 return PP_INPUTEVENT_TYPE_TOUCHEND; | 113 return PP_INPUTEVENT_TYPE_TOUCHEND; |
114 case WebInputEvent::TouchCancel: | 114 case WebInputEvent::TouchCancel: |
115 return PP_INPUTEVENT_TYPE_TOUCHCANCEL; | 115 return PP_INPUTEVENT_TYPE_TOUCHCANCEL; |
116 case WebInputEvent::Undefined: | 116 case WebInputEvent::Undefined: |
117 default: | 117 default: |
118 return PP_INPUTEVENT_TYPE_UNDEFINED; | 118 return PP_INPUTEVENT_TYPE_UNDEFINED; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
| 122 // Converts WebInputEvent::Modifiers flags to PP_InputEvent_Modifier. |
| 123 int ConvertEventModifiers(int modifiers) { |
| 124 return modifiers & (PP_INPUTEVENT_MODIFIER_CONTROLKEY | |
| 125 PP_INPUTEVENT_MODIFIER_ALTKEY | |
| 126 PP_INPUTEVENT_MODIFIER_METAKEY | |
| 127 PP_INPUTEVENT_MODIFIER_ISKEYPAD | |
| 128 PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT | |
| 129 PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN | |
| 130 PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN | |
| 131 PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN | |
| 132 PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY | |
| 133 PP_INPUTEVENT_MODIFIER_NUMLOCKKEY | |
| 134 PP_INPUTEVENT_MODIFIER_ISLEFT | |
| 135 PP_INPUTEVENT_MODIFIER_ISRIGHT); |
| 136 } |
| 137 |
122 // Generates a PP_InputEvent with the fields common to all events, as well as | 138 // Generates a PP_InputEvent with the fields common to all events, as well as |
123 // the event type from the given web event. Event-specific fields will be zero | 139 // the event type from the given web event. Event-specific fields will be zero |
124 // initialized. | 140 // initialized. |
125 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) { | 141 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) { |
126 InputEventData result; | 142 InputEventData result; |
127 result.event_type = ConvertEventTypes(web_event.type); | 143 result.event_type = ConvertEventTypes(web_event.type); |
128 result.event_time_stamp = web_event.timeStampSeconds; | 144 result.event_time_stamp = web_event.timeStampSeconds; |
129 return result; | 145 return result; |
130 } | 146 } |
131 | 147 |
132 void AppendKeyEvent(const WebInputEvent& event, | 148 void AppendKeyEvent(const WebInputEvent& event, |
133 std::vector<InputEventData>* result_events) { | 149 std::vector<InputEventData>* result_events) { |
134 const WebKeyboardEvent& key_event = | 150 const WebKeyboardEvent& key_event = |
135 static_cast<const WebKeyboardEvent&>(event); | 151 static_cast<const WebKeyboardEvent&>(event); |
136 InputEventData result = GetEventWithCommonFieldsAndType(event); | 152 InputEventData result = GetEventWithCommonFieldsAndType(event); |
137 result.event_modifiers = key_event.modifiers; | 153 result.event_modifiers = ConvertEventModifiers(key_event.modifiers); |
138 result.key_code = key_event.windowsKeyCode; | 154 result.key_code = key_event.windowsKeyCode; |
139 result.code = ui::KeycodeConverter::DomCodeToCodeString( | 155 result.code = ui::KeycodeConverter::DomCodeToCodeString( |
140 static_cast<ui::DomCode>(key_event.domCode)); | 156 static_cast<ui::DomCode>(key_event.domCode)); |
141 result_events->push_back(result); | 157 result_events->push_back(result); |
142 } | 158 } |
143 | 159 |
144 void AppendCharEvent(const WebInputEvent& event, | 160 void AppendCharEvent(const WebInputEvent& event, |
145 std::vector<InputEventData>* result_events) { | 161 std::vector<InputEventData>* result_events) { |
146 const WebKeyboardEvent& key_event = | 162 const WebKeyboardEvent& key_event = |
147 static_cast<const WebKeyboardEvent&>(event); | 163 static_cast<const WebKeyboardEvent&>(event); |
148 | 164 |
149 // This is a bit complex, the input event will normally just have one 16-bit | 165 // This is a bit complex, the input event will normally just have one 16-bit |
150 // character in it, but may be zero or more than one. The text array is | 166 // character in it, but may be zero or more than one. The text array is |
151 // just padded with 0 values for the unused ones, but is not necessarily | 167 // just padded with 0 values for the unused ones, but is not necessarily |
152 // null-terminated. | 168 // null-terminated. |
153 // | 169 // |
154 // Here we see how many UTF-16 characters we have. | 170 // Here we see how many UTF-16 characters we have. |
155 size_t utf16_char_count = 0; | 171 size_t utf16_char_count = 0; |
156 while (utf16_char_count < WebKeyboardEvent::textLengthCap && | 172 while (utf16_char_count < WebKeyboardEvent::textLengthCap && |
157 key_event.text[utf16_char_count]) | 173 key_event.text[utf16_char_count]) |
158 utf16_char_count++; | 174 utf16_char_count++; |
159 | 175 |
160 // Make a separate InputEventData for each Unicode character in the input. | 176 // Make a separate InputEventData for each Unicode character in the input. |
161 base::i18n::UTF16CharIterator iter(key_event.text, utf16_char_count); | 177 base::i18n::UTF16CharIterator iter(key_event.text, utf16_char_count); |
162 while (!iter.end()) { | 178 while (!iter.end()) { |
163 InputEventData result = GetEventWithCommonFieldsAndType(event); | 179 InputEventData result = GetEventWithCommonFieldsAndType(event); |
164 result.event_modifiers = key_event.modifiers; | 180 result.event_modifiers = ConvertEventModifiers(key_event.modifiers); |
165 base::WriteUnicodeCharacter(iter.get(), &result.character_text); | 181 base::WriteUnicodeCharacter(iter.get(), &result.character_text); |
166 | 182 |
167 result_events->push_back(result); | 183 result_events->push_back(result); |
168 iter.Advance(); | 184 iter.Advance(); |
169 } | 185 } |
170 } | 186 } |
171 | 187 |
172 void AppendMouseEvent(const WebInputEvent& event, | 188 void AppendMouseEvent(const WebInputEvent& event, |
173 std::vector<InputEventData>* result_events) { | 189 std::vector<InputEventData>* result_events) { |
174 static_assert(static_cast<int>(WebMouseEvent::Button::NoButton) == | 190 static_assert(static_cast<int>(WebMouseEvent::Button::NoButton) == |
175 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), | 191 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), |
176 "MouseNone should match"); | 192 "MouseNone should match"); |
177 static_assert(static_cast<int>(WebMouseEvent::Button::Left) == | 193 static_assert(static_cast<int>(WebMouseEvent::Button::Left) == |
178 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), | 194 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), |
179 "MouseLeft should match"); | 195 "MouseLeft should match"); |
180 static_assert(static_cast<int>(WebMouseEvent::Button::Right) == | 196 static_assert(static_cast<int>(WebMouseEvent::Button::Right) == |
181 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), | 197 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), |
182 "MouseRight should match"); | 198 "MouseRight should match"); |
183 static_assert(static_cast<int>(WebMouseEvent::Button::Middle) == | 199 static_assert(static_cast<int>(WebMouseEvent::Button::Middle) == |
184 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), | 200 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), |
185 "MouseMiddle should match"); | 201 "MouseMiddle should match"); |
186 | 202 |
187 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | 203 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
188 InputEventData result = GetEventWithCommonFieldsAndType(event); | 204 InputEventData result = GetEventWithCommonFieldsAndType(event); |
189 result.event_modifiers = mouse_event.modifiers; | 205 result.event_modifiers = ConvertEventModifiers(mouse_event.modifiers); |
| 206 if (mouse_event.pointerType == |
| 207 blink::WebPointerProperties::PointerType::Pen) { |
| 208 result.event_modifiers |= PP_INPUTEVENT_MODIFIER_ISPEN; |
| 209 } else if (mouse_event.pointerType == |
| 210 blink::WebPointerProperties::PointerType::Eraser) { |
| 211 result.event_modifiers |= PP_INPUTEVENT_MODIFIER_ISERASER; |
| 212 } |
190 if (mouse_event.type == WebInputEvent::MouseDown || | 213 if (mouse_event.type == WebInputEvent::MouseDown || |
191 mouse_event.type == WebInputEvent::MouseMove || | 214 mouse_event.type == WebInputEvent::MouseMove || |
192 mouse_event.type == WebInputEvent::MouseUp) { | 215 mouse_event.type == WebInputEvent::MouseUp) { |
193 result.mouse_button = | 216 result.mouse_button = |
194 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); | 217 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); |
195 } | 218 } |
196 result.mouse_position.x = mouse_event.x; | 219 result.mouse_position.x = mouse_event.x; |
197 result.mouse_position.y = mouse_event.y; | 220 result.mouse_position.y = mouse_event.y; |
198 result.mouse_click_count = mouse_event.clickCount; | 221 result.mouse_click_count = mouse_event.clickCount; |
199 result.mouse_movement.x = mouse_event.movementX; | 222 result.mouse_movement.x = mouse_event.movementX; |
200 result.mouse_movement.y = mouse_event.movementY; | 223 result.mouse_movement.y = mouse_event.movementY; |
201 result_events->push_back(result); | 224 result_events->push_back(result); |
202 } | 225 } |
203 | 226 |
204 void AppendMouseWheelEvent(const WebInputEvent& event, | 227 void AppendMouseWheelEvent(const WebInputEvent& event, |
205 std::vector<InputEventData>* result_events) { | 228 std::vector<InputEventData>* result_events) { |
206 const WebMouseWheelEvent& mouse_wheel_event = | 229 const WebMouseWheelEvent& mouse_wheel_event = |
207 static_cast<const WebMouseWheelEvent&>(event); | 230 static_cast<const WebMouseWheelEvent&>(event); |
208 InputEventData result = GetEventWithCommonFieldsAndType(event); | 231 InputEventData result = GetEventWithCommonFieldsAndType(event); |
209 result.event_modifiers = mouse_wheel_event.modifiers; | 232 result.event_modifiers = ConvertEventModifiers(mouse_wheel_event.modifiers); |
210 result.wheel_delta.x = mouse_wheel_event.deltaX; | 233 result.wheel_delta.x = mouse_wheel_event.deltaX; |
211 result.wheel_delta.y = mouse_wheel_event.deltaY; | 234 result.wheel_delta.y = mouse_wheel_event.deltaY; |
212 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; | 235 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; |
213 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; | 236 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; |
214 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; | 237 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; |
215 result_events->push_back(result); | 238 result_events->push_back(result); |
216 } | 239 } |
217 | 240 |
218 enum IncludedTouchPointTypes { | 241 enum IncludedTouchPointTypes { |
219 ALL, // All pointers targetting the plugin. | 242 ALL, // All pointers targetting the plugin. |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 return PP_INPUTEVENT_CLASS_TOUCH; | 763 return PP_INPUTEVENT_CLASS_TOUCH; |
741 case WebInputEvent::TouchScrollStarted: | 764 case WebInputEvent::TouchScrollStarted: |
742 return PP_InputEvent_Class(0); | 765 return PP_InputEvent_Class(0); |
743 default: | 766 default: |
744 CHECK(WebInputEvent::isGestureEventType(type)); | 767 CHECK(WebInputEvent::isGestureEventType(type)); |
745 return PP_InputEvent_Class(0); | 768 return PP_InputEvent_Class(0); |
746 } | 769 } |
747 } | 770 } |
748 | 771 |
749 } // namespace content | 772 } // namespace content |
OLD | NEW |