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

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

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Created 4 years 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
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 PP_InputEvent_Type ConvertEventTypes(const WebInputEvent& event) { 84 PP_InputEvent_Type ConvertEventTypes(const WebInputEvent& event) {
85 switch (event.type) { 85 switch (event.type()) {
86 case WebInputEvent::MouseDown: 86 case WebInputEvent::MouseDown:
87 return PP_INPUTEVENT_TYPE_MOUSEDOWN; 87 return PP_INPUTEVENT_TYPE_MOUSEDOWN;
88 case WebInputEvent::MouseUp: 88 case WebInputEvent::MouseUp:
89 return PP_INPUTEVENT_TYPE_MOUSEUP; 89 return PP_INPUTEVENT_TYPE_MOUSEUP;
90 case WebInputEvent::MouseMove: 90 case WebInputEvent::MouseMove:
91 return PP_INPUTEVENT_TYPE_MOUSEMOVE; 91 return PP_INPUTEVENT_TYPE_MOUSEMOVE;
92 case WebInputEvent::MouseEnter: 92 case WebInputEvent::MouseEnter:
93 return PP_INPUTEVENT_TYPE_MOUSEENTER; 93 return PP_INPUTEVENT_TYPE_MOUSEENTER;
94 case WebInputEvent::MouseLeave: 94 case WebInputEvent::MouseLeave:
95 return PP_INPUTEVENT_TYPE_MOUSELEAVE; 95 return PP_INPUTEVENT_TYPE_MOUSELEAVE;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 PP_INPUTEVENT_MODIFIER_ISLEFT | 135 PP_INPUTEVENT_MODIFIER_ISLEFT |
136 PP_INPUTEVENT_MODIFIER_ISRIGHT); 136 PP_INPUTEVENT_MODIFIER_ISRIGHT);
137 } 137 }
138 138
139 // 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
140 // 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
141 // initialized. 141 // initialized.
142 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) { 142 InputEventData GetEventWithCommonFieldsAndType(const WebInputEvent& web_event) {
143 InputEventData result; 143 InputEventData result;
144 result.event_type = ConvertEventTypes(web_event); 144 result.event_type = ConvertEventTypes(web_event);
145 result.event_time_stamp = web_event.timeStampSeconds; 145 result.event_time_stamp = web_event.timeStampSeconds();
146 return result; 146 return result;
147 } 147 }
148 148
149 void AppendKeyEvent(const WebInputEvent& event, 149 void AppendKeyEvent(const WebInputEvent& event,
150 std::vector<InputEventData>* result_events) { 150 std::vector<InputEventData>* result_events) {
151 const WebKeyboardEvent& key_event = 151 const WebKeyboardEvent& key_event =
152 static_cast<const WebKeyboardEvent&>(event); 152 static_cast<const WebKeyboardEvent&>(event);
153 InputEventData result = GetEventWithCommonFieldsAndType(event); 153 InputEventData result = GetEventWithCommonFieldsAndType(event);
154 result.event_modifiers = ConvertEventModifiers(key_event.modifiers); 154 result.event_modifiers = ConvertEventModifiers(key_event.modifiers());
155 result.key_code = key_event.windowsKeyCode; 155 result.key_code = key_event.windowsKeyCode;
156 result.code = ui::KeycodeConverter::DomCodeToCodeString( 156 result.code = ui::KeycodeConverter::DomCodeToCodeString(
157 static_cast<ui::DomCode>(key_event.domCode)); 157 static_cast<ui::DomCode>(key_event.domCode));
158 result_events->push_back(result); 158 result_events->push_back(result);
159 } 159 }
160 160
161 void AppendCharEvent(const WebInputEvent& event, 161 void AppendCharEvent(const WebInputEvent& event,
162 std::vector<InputEventData>* result_events) { 162 std::vector<InputEventData>* result_events) {
163 const WebKeyboardEvent& key_event = 163 const WebKeyboardEvent& key_event =
164 static_cast<const WebKeyboardEvent&>(event); 164 static_cast<const WebKeyboardEvent&>(event);
165 165
166 // 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
167 // 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
168 // 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
169 // null-terminated. 169 // null-terminated.
170 // 170 //
171 // Here we see how many UTF-16 characters we have. 171 // Here we see how many UTF-16 characters we have.
172 size_t utf16_char_count = 0; 172 size_t utf16_char_count = 0;
173 while (utf16_char_count < WebKeyboardEvent::textLengthCap && 173 while (utf16_char_count < WebKeyboardEvent::textLengthCap &&
174 key_event.text[utf16_char_count]) 174 key_event.text[utf16_char_count])
175 utf16_char_count++; 175 utf16_char_count++;
176 176
177 // Make a separate InputEventData for each Unicode character in the input. 177 // Make a separate InputEventData for each Unicode character in the input.
178 base::i18n::UTF16CharIterator iter(key_event.text, utf16_char_count); 178 base::i18n::UTF16CharIterator iter(key_event.text, utf16_char_count);
179 while (!iter.end()) { 179 while (!iter.end()) {
180 InputEventData result = GetEventWithCommonFieldsAndType(event); 180 InputEventData result = GetEventWithCommonFieldsAndType(event);
181 result.event_modifiers = ConvertEventModifiers(key_event.modifiers); 181 result.event_modifiers = ConvertEventModifiers(key_event.modifiers());
182 base::WriteUnicodeCharacter(iter.get(), &result.character_text); 182 base::WriteUnicodeCharacter(iter.get(), &result.character_text);
183 183
184 result_events->push_back(result); 184 result_events->push_back(result);
185 iter.Advance(); 185 iter.Advance();
186 } 186 }
187 } 187 }
188 188
189 void AppendMouseEvent(const WebInputEvent& event, 189 void AppendMouseEvent(const WebInputEvent& event,
190 std::vector<InputEventData>* result_events) { 190 std::vector<InputEventData>* result_events) {
191 static_assert(static_cast<int>(WebMouseEvent::Button::NoButton) == 191 static_assert(static_cast<int>(WebMouseEvent::Button::NoButton) ==
192 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), 192 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE),
193 "MouseNone should match"); 193 "MouseNone should match");
194 static_assert(static_cast<int>(WebMouseEvent::Button::Left) == 194 static_assert(static_cast<int>(WebMouseEvent::Button::Left) ==
195 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), 195 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT),
196 "MouseLeft should match"); 196 "MouseLeft should match");
197 static_assert(static_cast<int>(WebMouseEvent::Button::Right) == 197 static_assert(static_cast<int>(WebMouseEvent::Button::Right) ==
198 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), 198 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT),
199 "MouseRight should match"); 199 "MouseRight should match");
200 static_assert(static_cast<int>(WebMouseEvent::Button::Middle) == 200 static_assert(static_cast<int>(WebMouseEvent::Button::Middle) ==
201 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), 201 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE),
202 "MouseMiddle should match"); 202 "MouseMiddle should match");
203 203
204 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); 204 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
205 InputEventData result = GetEventWithCommonFieldsAndType(event); 205 InputEventData result = GetEventWithCommonFieldsAndType(event);
206 result.event_modifiers = ConvertEventModifiers(mouse_event.modifiers); 206 result.event_modifiers = ConvertEventModifiers(mouse_event.modifiers());
207 if (mouse_event.type == WebInputEvent::MouseDown || 207 if (mouse_event.type() == WebInputEvent::MouseDown ||
208 mouse_event.type == WebInputEvent::MouseMove || 208 mouse_event.type() == WebInputEvent::MouseMove ||
209 mouse_event.type == WebInputEvent::MouseUp) { 209 mouse_event.type() == WebInputEvent::MouseUp) {
210 result.mouse_button = 210 result.mouse_button =
211 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); 211 static_cast<PP_InputEvent_MouseButton>(mouse_event.button);
212 } 212 }
213 result.mouse_position.x = mouse_event.x; 213 result.mouse_position.x = mouse_event.x;
214 result.mouse_position.y = mouse_event.y; 214 result.mouse_position.y = mouse_event.y;
215 result.mouse_click_count = mouse_event.clickCount; 215 result.mouse_click_count = mouse_event.clickCount;
216 result.mouse_movement.x = mouse_event.movementX; 216 result.mouse_movement.x = mouse_event.movementX;
217 result.mouse_movement.y = mouse_event.movementY; 217 result.mouse_movement.y = mouse_event.movementY;
218 result_events->push_back(result); 218 result_events->push_back(result);
219 } 219 }
220 220
221 void AppendMouseWheelEvent(const WebInputEvent& event, 221 void AppendMouseWheelEvent(const WebInputEvent& event,
222 std::vector<InputEventData>* result_events) { 222 std::vector<InputEventData>* result_events) {
223 const WebMouseWheelEvent& mouse_wheel_event = 223 const WebMouseWheelEvent& mouse_wheel_event =
224 static_cast<const WebMouseWheelEvent&>(event); 224 static_cast<const WebMouseWheelEvent&>(event);
225 InputEventData result = GetEventWithCommonFieldsAndType(event); 225 InputEventData result = GetEventWithCommonFieldsAndType(event);
226 result.event_modifiers = ConvertEventModifiers(mouse_wheel_event.modifiers); 226 result.event_modifiers = ConvertEventModifiers(mouse_wheel_event.modifiers());
227 result.wheel_delta.x = mouse_wheel_event.deltaX; 227 result.wheel_delta.x = mouse_wheel_event.deltaX;
228 result.wheel_delta.y = mouse_wheel_event.deltaY; 228 result.wheel_delta.y = mouse_wheel_event.deltaY;
229 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; 229 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX;
230 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; 230 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY;
231 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; 231 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage;
232 result_events->push_back(result); 232 result_events->push_back(result);
233 } 233 }
234 234
235 enum IncludedTouchPointTypes { 235 enum IncludedTouchPointTypes {
236 ALL, // All pointers targetting the plugin. 236 ALL, // All pointers targetting the plugin.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 case PP_INPUTEVENT_TYPE_CONTEXTMENU: 448 case PP_INPUTEVENT_TYPE_CONTEXTMENU:
449 type = WebInputEvent::ContextMenu; 449 type = WebInputEvent::ContextMenu;
450 break; 450 break;
451 default: 451 default:
452 NOTREACHED(); 452 NOTREACHED();
453 } 453 }
454 WebMouseEvent* mouse_event = 454 WebMouseEvent* mouse_event =
455 new WebMouseEvent(type, event.event_modifiers, event.event_time_stamp); 455 new WebMouseEvent(type, event.event_modifiers, event.event_time_stamp);
456 mouse_event->pointerType = blink::WebPointerProperties::PointerType::Mouse; 456 mouse_event->pointerType = blink::WebPointerProperties::PointerType::Mouse;
457 mouse_event->button = static_cast<WebMouseEvent::Button>(event.mouse_button); 457 mouse_event->button = static_cast<WebMouseEvent::Button>(event.mouse_button);
458 if (mouse_event->type == WebInputEvent::MouseMove) { 458 if (mouse_event->type() == WebInputEvent::MouseMove) {
459 if (mouse_event->modifiers & WebInputEvent::LeftButtonDown) 459 if (mouse_event->modifiers() & WebInputEvent::LeftButtonDown)
460 mouse_event->button = WebMouseEvent::Button::Left; 460 mouse_event->button = WebMouseEvent::Button::Left;
461 else if (mouse_event->modifiers & WebInputEvent::MiddleButtonDown) 461 else if (mouse_event->modifiers() & WebInputEvent::MiddleButtonDown)
462 mouse_event->button = WebMouseEvent::Button::Middle; 462 mouse_event->button = WebMouseEvent::Button::Middle;
463 else if (mouse_event->modifiers & WebInputEvent::RightButtonDown) 463 else if (mouse_event->modifiers() & WebInputEvent::RightButtonDown)
464 mouse_event->button = WebMouseEvent::Button::Right; 464 mouse_event->button = WebMouseEvent::Button::Right;
465 } 465 }
466 mouse_event->x = event.mouse_position.x; 466 mouse_event->x = event.mouse_position.x;
467 mouse_event->y = event.mouse_position.y; 467 mouse_event->y = event.mouse_position.y;
468 mouse_event->clickCount = event.mouse_click_count; 468 mouse_event->clickCount = event.mouse_click_count;
469 mouse_event->movementX = event.mouse_movement.x; 469 mouse_event->movementX = event.mouse_movement.x;
470 mouse_event->movementY = event.mouse_movement.y; 470 mouse_event->movementY = event.mouse_movement.y;
471 return mouse_event; 471 return mouse_event;
472 } 472 }
473 473
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 *code = vk_code; 565 *code = vk_code;
566 *text = vk_text; 566 *text = vk_text;
567 } 567 }
568 568
569 } // namespace 569 } // namespace
570 570
571 void CreateInputEventData(const WebInputEvent& event, 571 void CreateInputEventData(const WebInputEvent& event,
572 std::vector<InputEventData>* result) { 572 std::vector<InputEventData>* result) {
573 result->clear(); 573 result->clear();
574 574
575 switch (event.type) { 575 switch (event.type()) {
576 case WebInputEvent::MouseDown: 576 case WebInputEvent::MouseDown:
577 case WebInputEvent::MouseUp: 577 case WebInputEvent::MouseUp:
578 case WebInputEvent::MouseMove: 578 case WebInputEvent::MouseMove:
579 case WebInputEvent::MouseEnter: 579 case WebInputEvent::MouseEnter:
580 case WebInputEvent::MouseLeave: 580 case WebInputEvent::MouseLeave:
581 case WebInputEvent::ContextMenu: 581 case WebInputEvent::ContextMenu:
582 AppendMouseEvent(event, result); 582 AppendMouseEvent(event, result);
583 break; 583 break;
584 case WebInputEvent::MouseWheel: 584 case WebInputEvent::MouseWheel:
585 AppendMouseWheelEvent(event, result); 585 AppendMouseWheelEvent(event, result);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 &code, 702 &code,
703 &text, 703 &text,
704 &needs_shift_modifier, 704 &needs_shift_modifier,
705 &generate_char); 705 &generate_char);
706 706
707 // Synthesize key down and key up events in all cases. 707 // Synthesize key down and key up events in all cases.
708 std::unique_ptr<WebKeyboardEvent> key_down_event(new WebKeyboardEvent( 708 std::unique_ptr<WebKeyboardEvent> key_down_event(new WebKeyboardEvent(
709 WebInputEvent::RawKeyDown, 709 WebInputEvent::RawKeyDown,
710 needs_shift_modifier ? WebInputEvent::ShiftKey 710 needs_shift_modifier ? WebInputEvent::ShiftKey
711 : WebInputEvent::NoModifiers, 711 : WebInputEvent::NoModifiers,
712 web_char_event->timeStampSeconds)); 712 web_char_event->timeStampSeconds()));
713 std::unique_ptr<WebKeyboardEvent> key_up_event(new WebKeyboardEvent()); 713 std::unique_ptr<WebKeyboardEvent> key_up_event(new WebKeyboardEvent());
714 714
715 key_down_event->windowsKeyCode = code; 715 key_down_event->windowsKeyCode = code;
716 key_down_event->nativeKeyCode = code; 716 key_down_event->nativeKeyCode = code;
717 717
718 // If a char event is needed, set the text fields. 718 // If a char event is needed, set the text fields.
719 if (generate_char) { 719 if (generate_char) {
720 key_down_event->text[0] = text; 720 key_down_event->text[0] = text;
721 key_down_event->unmodifiedText[0] = text; 721 key_down_event->unmodifiedText[0] = text;
722 } 722 }
(...skipping 12 matching lines...) Expand all
735 break; 735 break;
736 } 736 }
737 737
738 default: 738 default:
739 break; 739 break;
740 } 740 }
741 return events; 741 return events;
742 } 742 }
743 743
744 PP_InputEvent_Class ClassifyInputEvent(const WebInputEvent& event) { 744 PP_InputEvent_Class ClassifyInputEvent(const WebInputEvent& event) {
745 switch (event.type) { 745 switch (event.type()) {
746 case WebInputEvent::MouseDown: 746 case WebInputEvent::MouseDown:
747 case WebInputEvent::MouseUp: 747 case WebInputEvent::MouseUp:
748 case WebInputEvent::MouseMove: 748 case WebInputEvent::MouseMove:
749 case WebInputEvent::MouseEnter: 749 case WebInputEvent::MouseEnter:
750 case WebInputEvent::MouseLeave: 750 case WebInputEvent::MouseLeave:
751 case WebInputEvent::ContextMenu: 751 case WebInputEvent::ContextMenu:
752 return PP_INPUTEVENT_CLASS_MOUSE; 752 return PP_INPUTEVENT_CLASS_MOUSE;
753 case WebInputEvent::MouseWheel: 753 case WebInputEvent::MouseWheel:
754 return PP_INPUTEVENT_CLASS_WHEEL; 754 return PP_INPUTEVENT_CLASS_WHEEL;
755 case WebInputEvent::RawKeyDown: 755 case WebInputEvent::RawKeyDown:
756 case WebInputEvent::KeyDown: 756 case WebInputEvent::KeyDown:
757 case WebInputEvent::KeyUp: 757 case WebInputEvent::KeyUp:
758 case WebInputEvent::Char: 758 case WebInputEvent::Char:
759 return PP_INPUTEVENT_CLASS_KEYBOARD; 759 return PP_INPUTEVENT_CLASS_KEYBOARD;
760 case WebInputEvent::TouchCancel: 760 case WebInputEvent::TouchCancel:
761 case WebInputEvent::TouchEnd: 761 case WebInputEvent::TouchEnd:
762 case WebInputEvent::TouchMove: 762 case WebInputEvent::TouchMove:
763 case WebInputEvent::TouchStart: 763 case WebInputEvent::TouchStart:
764 return PP_INPUTEVENT_CLASS_TOUCH; 764 return PP_INPUTEVENT_CLASS_TOUCH;
765 case WebInputEvent::TouchScrollStarted: 765 case WebInputEvent::TouchScrollStarted:
766 return PP_InputEvent_Class(0); 766 return PP_InputEvent_Class(0);
767 default: 767 default:
768 CHECK(WebInputEvent::isGestureEventType(event.type)); 768 CHECK(WebInputEvent::isGestureEventType(event.type()));
769 return PP_InputEvent_Class(0); 769 return PP_InputEvent_Class(0);
770 } 770 }
771 } 771 }
772 772
773 } // namespace content 773 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698