| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/i18n/char_iterator.h" | 8 #include "base/i18n/char_iterator.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 using blink::WebTouchPoint; | 33 using blink::WebTouchPoint; |
| 34 using blink::WebUChar; | 34 using blink::WebUChar; |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Verify the modifier flags WebKit uses match the Pepper ones. If these start | 40 // Verify the modifier flags WebKit uses match the Pepper ones. If these start |
| 41 // not matching, we'll need to write conversion code to preserve the Pepper | 41 // not matching, we'll need to write conversion code to preserve the Pepper |
| 42 // values (since plugins will be depending on them). | 42 // values (since plugins will be depending on them). |
| 43 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_SHIFTKEY) == | 43 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_SHIFTKEY) == |
| 44 static_cast<int>(WebInputEvent::ShiftKey), | 44 static_cast<int>(WebInputEvent::ShiftKey), |
| 45 ShiftKeyMatches); | 45 "ShiftKey should match"); |
| 46 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_CONTROLKEY) == | 46 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_CONTROLKEY) == |
| 47 static_cast<int>(WebInputEvent::ControlKey), | 47 static_cast<int>(WebInputEvent::ControlKey), |
| 48 ControlKeyMatches); | 48 "ControlKey should match"); |
| 49 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ALTKEY) == | 49 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ALTKEY) == |
| 50 static_cast<int>(WebInputEvent::AltKey), | 50 static_cast<int>(WebInputEvent::AltKey), |
| 51 AltKeyMatches); | 51 "AltKey should match"); |
| 52 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_METAKEY) == | 52 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_METAKEY) == |
| 53 static_cast<int>(WebInputEvent::MetaKey), | 53 static_cast<int>(WebInputEvent::MetaKey), |
| 54 MetaKeyMatches); | 54 "MetaKey should match"); |
| 55 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISKEYPAD) == | 55 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISKEYPAD) == |
| 56 static_cast<int>(WebInputEvent::IsKeyPad), | 56 static_cast<int>(WebInputEvent::IsKeyPad), |
| 57 KeyPadMatches); | 57 "KeyPad should match"); |
| 58 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT) == | 58 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT) == |
| 59 static_cast<int>(WebInputEvent::IsAutoRepeat), | 59 static_cast<int>(WebInputEvent::IsAutoRepeat), |
| 60 AutoRepeatMatches); | 60 "AutoRepeat should match"); |
| 61 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) == | 61 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) == |
| 62 static_cast<int>(WebInputEvent::LeftButtonDown), | 62 static_cast<int>(WebInputEvent::LeftButtonDown), |
| 63 LeftButtonMatches); | 63 "LeftButton should match"); |
| 64 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN) == | 64 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN) == |
| 65 static_cast<int>(WebInputEvent::MiddleButtonDown), | 65 static_cast<int>(WebInputEvent::MiddleButtonDown), |
| 66 MiddleButtonMatches); | 66 "MiddleButton should match"); |
| 67 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN) == | 67 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN) == |
| 68 static_cast<int>(WebInputEvent::RightButtonDown), | 68 static_cast<int>(WebInputEvent::RightButtonDown), |
| 69 RightButtonMatches); | 69 "RightButton should match"); |
| 70 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) == | 70 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_CAPSLOCKKEY) == |
| 71 static_cast<int>(WebInputEvent::CapsLockOn), | 71 static_cast<int>(WebInputEvent::CapsLockOn), |
| 72 CapsLockMatches); | 72 "CapsLock should match"); |
| 73 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) == | 73 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_NUMLOCKKEY) == |
| 74 static_cast<int>(WebInputEvent::NumLockOn), | 74 static_cast<int>(WebInputEvent::NumLockOn), |
| 75 NumLockMatches); | 75 "NumLock should match"); |
| 76 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISLEFT) == | 76 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISLEFT) == |
| 77 static_cast<int>(WebInputEvent::IsLeft), | 77 static_cast<int>(WebInputEvent::IsLeft), |
| 78 LeftMatches); | 78 "IsLeft should match"); |
| 79 COMPILE_ASSERT(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISRIGHT) == | 79 static_assert(static_cast<int>(PP_INPUTEVENT_MODIFIER_ISRIGHT) == |
| 80 static_cast<int>(WebInputEvent::IsRight), | 80 static_cast<int>(WebInputEvent::IsRight), |
| 81 RightMatches); | 81 "IsRight should match"); |
| 82 | 82 |
| 83 PP_InputEvent_Type ConvertEventTypes(WebInputEvent::Type wetype) { | 83 PP_InputEvent_Type ConvertEventTypes(WebInputEvent::Type wetype) { |
| 84 switch (wetype) { | 84 switch (wetype) { |
| 85 case WebInputEvent::MouseDown: | 85 case WebInputEvent::MouseDown: |
| 86 return PP_INPUTEVENT_TYPE_MOUSEDOWN; | 86 return PP_INPUTEVENT_TYPE_MOUSEDOWN; |
| 87 case WebInputEvent::MouseUp: | 87 case WebInputEvent::MouseUp: |
| 88 return PP_INPUTEVENT_TYPE_MOUSEUP; | 88 return PP_INPUTEVENT_TYPE_MOUSEUP; |
| 89 case WebInputEvent::MouseMove: | 89 case WebInputEvent::MouseMove: |
| 90 return PP_INPUTEVENT_TYPE_MOUSEMOVE; | 90 return PP_INPUTEVENT_TYPE_MOUSEMOVE; |
| 91 case WebInputEvent::MouseEnter: | 91 case WebInputEvent::MouseEnter: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 result.event_modifiers = key_event.modifiers; | 162 result.event_modifiers = key_event.modifiers; |
| 163 base::WriteUnicodeCharacter(iter.get(), &result.character_text); | 163 base::WriteUnicodeCharacter(iter.get(), &result.character_text); |
| 164 | 164 |
| 165 result_events->push_back(result); | 165 result_events->push_back(result); |
| 166 iter.Advance(); | 166 iter.Advance(); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 void AppendMouseEvent(const WebInputEvent& event, | 170 void AppendMouseEvent(const WebInputEvent& event, |
| 171 std::vector<InputEventData>* result_events) { | 171 std::vector<InputEventData>* result_events) { |
| 172 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonNone) == | 172 static_assert(static_cast<int>(WebMouseEvent::ButtonNone) == |
| 173 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), | 173 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_NONE), |
| 174 MouseNone); | 174 "MouseNone should match"); |
| 175 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonLeft) == | 175 static_assert(static_cast<int>(WebMouseEvent::ButtonLeft) == |
| 176 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), | 176 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_LEFT), |
| 177 MouseLeft); | 177 "MouseLeft should match"); |
| 178 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonRight) == | 178 static_assert(static_cast<int>(WebMouseEvent::ButtonRight) == |
| 179 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), | 179 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_RIGHT), |
| 180 MouseRight); | 180 "MouseRight should match"); |
| 181 COMPILE_ASSERT(static_cast<int>(WebMouseEvent::ButtonMiddle) == | 181 static_assert(static_cast<int>(WebMouseEvent::ButtonMiddle) == |
| 182 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), | 182 static_cast<int>(PP_INPUTEVENT_MOUSEBUTTON_MIDDLE), |
| 183 MouseMiddle); | 183 "MouseMiddle should match"); |
| 184 | 184 |
| 185 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | 185 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
| 186 InputEventData result = GetEventWithCommonFieldsAndType(event); | 186 InputEventData result = GetEventWithCommonFieldsAndType(event); |
| 187 result.event_modifiers = mouse_event.modifiers; | 187 result.event_modifiers = mouse_event.modifiers; |
| 188 if (mouse_event.type == WebInputEvent::MouseDown || | 188 if (mouse_event.type == WebInputEvent::MouseDown || |
| 189 mouse_event.type == WebInputEvent::MouseMove || | 189 mouse_event.type == WebInputEvent::MouseMove || |
| 190 mouse_event.type == WebInputEvent::MouseUp) { | 190 mouse_event.type == WebInputEvent::MouseUp) { |
| 191 result.mouse_button = | 191 result.mouse_button = |
| 192 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); | 192 static_cast<PP_InputEvent_MouseButton>(mouse_event.button); |
| 193 } | 193 } |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 case WebInputEvent::TouchStart: | 742 case WebInputEvent::TouchStart: |
| 743 return PP_INPUTEVENT_CLASS_TOUCH; | 743 return PP_INPUTEVENT_CLASS_TOUCH; |
| 744 case WebInputEvent::Undefined: | 744 case WebInputEvent::Undefined: |
| 745 default: | 745 default: |
| 746 CHECK(WebInputEvent::isGestureEventType(type)); | 746 CHECK(WebInputEvent::isGestureEventType(type)); |
| 747 return PP_InputEvent_Class(0); | 747 return PP_InputEvent_Class(0); |
| 748 } | 748 } |
| 749 } | 749 } |
| 750 | 750 |
| 751 } // namespace content | 751 } // namespace content |
| OLD | NEW |