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

Side by Side Diff: content/renderer/pepper/event_conversion.cc

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

Powered by Google App Engine
This is Rietveld 408576698