| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "content/browser/renderer_host/input/web_input_event_util.h" | 8 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 | 11 |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "content/common/input/web_touch_event_traits.h" | 13 #include "content/common/input/web_touch_event_traits.h" |
| 14 #include "ui/events/blink/blink_event_util.h" | 14 #include "ui/events/blink/blink_event_util.h" |
| 15 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 16 #include "ui/events/gesture_detection/gesture_event_data.h" | 16 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 17 #include "ui/events/gesture_detection/motion_event.h" | 17 #include "ui/events/gesture_detection/motion_event.h" |
| 18 #include "ui/events/keycodes/dom/keycode_converter.h" | 18 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 19 #include "ui/gfx/geometry/safe_integer_conversions.h" | 19 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 20 | 20 |
| 21 using blink::WebGestureEvent; | 21 using blink::WebGestureEvent; |
| 22 using blink::WebInputEvent; | 22 using blink::WebInputEvent; |
| 23 using blink::WebTouchEvent; | 23 using blink::WebTouchEvent; |
| 24 using blink::WebTouchPoint; | 24 using blink::WebTouchPoint; |
| 25 using ui::MotionEvent; | 25 using ui::MotionEvent; |
| 26 | 26 |
| 27 namespace { | |
| 28 | |
| 29 const char* GetKeyIdentifier(ui::KeyboardCode key_code) { | |
| 30 switch (key_code) { | |
| 31 case ui::VKEY_MENU: | |
| 32 return "Alt"; | |
| 33 case ui::VKEY_CONTROL: | |
| 34 return "Control"; | |
| 35 case ui::VKEY_SHIFT: | |
| 36 return "Shift"; | |
| 37 case ui::VKEY_CAPITAL: | |
| 38 return "CapsLock"; | |
| 39 case ui::VKEY_LWIN: | |
| 40 case ui::VKEY_RWIN: | |
| 41 return "Win"; | |
| 42 case ui::VKEY_CLEAR: | |
| 43 return "Clear"; | |
| 44 case ui::VKEY_DOWN: | |
| 45 return "Down"; | |
| 46 case ui::VKEY_END: | |
| 47 return "End"; | |
| 48 case ui::VKEY_RETURN: | |
| 49 return "Enter"; | |
| 50 case ui::VKEY_EXECUTE: | |
| 51 return "Execute"; | |
| 52 case ui::VKEY_F1: | |
| 53 return "F1"; | |
| 54 case ui::VKEY_F2: | |
| 55 return "F2"; | |
| 56 case ui::VKEY_F3: | |
| 57 return "F3"; | |
| 58 case ui::VKEY_F4: | |
| 59 return "F4"; | |
| 60 case ui::VKEY_F5: | |
| 61 return "F5"; | |
| 62 case ui::VKEY_F6: | |
| 63 return "F6"; | |
| 64 case ui::VKEY_F7: | |
| 65 return "F7"; | |
| 66 case ui::VKEY_F8: | |
| 67 return "F8"; | |
| 68 case ui::VKEY_F9: | |
| 69 return "F9"; | |
| 70 case ui::VKEY_F10: | |
| 71 return "F10"; | |
| 72 case ui::VKEY_F11: | |
| 73 return "F11"; | |
| 74 case ui::VKEY_F12: | |
| 75 return "F12"; | |
| 76 case ui::VKEY_F13: | |
| 77 return "F13"; | |
| 78 case ui::VKEY_F14: | |
| 79 return "F14"; | |
| 80 case ui::VKEY_F15: | |
| 81 return "F15"; | |
| 82 case ui::VKEY_F16: | |
| 83 return "F16"; | |
| 84 case ui::VKEY_F17: | |
| 85 return "F17"; | |
| 86 case ui::VKEY_F18: | |
| 87 return "F18"; | |
| 88 case ui::VKEY_F19: | |
| 89 return "F19"; | |
| 90 case ui::VKEY_F20: | |
| 91 return "F20"; | |
| 92 case ui::VKEY_F21: | |
| 93 return "F21"; | |
| 94 case ui::VKEY_F22: | |
| 95 return "F22"; | |
| 96 case ui::VKEY_F23: | |
| 97 return "F23"; | |
| 98 case ui::VKEY_F24: | |
| 99 return "F24"; | |
| 100 case ui::VKEY_HELP: | |
| 101 return "Help"; | |
| 102 case ui::VKEY_HOME: | |
| 103 return "Home"; | |
| 104 case ui::VKEY_INSERT: | |
| 105 return "Insert"; | |
| 106 case ui::VKEY_LEFT: | |
| 107 return "Left"; | |
| 108 case ui::VKEY_NEXT: | |
| 109 return "PageDown"; | |
| 110 case ui::VKEY_PRIOR: | |
| 111 return "PageUp"; | |
| 112 case ui::VKEY_PAUSE: | |
| 113 return "Pause"; | |
| 114 case ui::VKEY_SNAPSHOT: | |
| 115 return "PrintScreen"; | |
| 116 case ui::VKEY_RIGHT: | |
| 117 return "Right"; | |
| 118 case ui::VKEY_SCROLL: | |
| 119 return "Scroll"; | |
| 120 case ui::VKEY_SELECT: | |
| 121 return "Select"; | |
| 122 case ui::VKEY_UP: | |
| 123 return "Up"; | |
| 124 case ui::VKEY_DELETE: | |
| 125 return "U+007F"; // Standard says that DEL becomes U+007F. | |
| 126 case ui::VKEY_MEDIA_NEXT_TRACK: | |
| 127 return "MediaNextTrack"; | |
| 128 case ui::VKEY_MEDIA_PREV_TRACK: | |
| 129 return "MediaPreviousTrack"; | |
| 130 case ui::VKEY_MEDIA_STOP: | |
| 131 return "MediaStop"; | |
| 132 case ui::VKEY_MEDIA_PLAY_PAUSE: | |
| 133 return "MediaPlayPause"; | |
| 134 case ui::VKEY_VOLUME_MUTE: | |
| 135 return "VolumeMute"; | |
| 136 case ui::VKEY_VOLUME_DOWN: | |
| 137 return "VolumeDown"; | |
| 138 case ui::VKEY_VOLUME_UP: | |
| 139 return "VolumeUp"; | |
| 140 default: | |
| 141 return NULL; | |
| 142 }; | |
| 143 } | |
| 144 | |
| 145 } // namespace | |
| 146 | |
| 147 namespace content { | 27 namespace content { |
| 148 | 28 |
| 149 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, | |
| 150 ui::KeyboardCode windows_key_code) { | |
| 151 event->windowsKeyCode = windows_key_code; | |
| 152 | |
| 153 const char* id = GetKeyIdentifier(windows_key_code); | |
| 154 if (id) { | |
| 155 base::strlcpy(event->keyIdentifier, id, sizeof(event->keyIdentifier) - 1); | |
| 156 } else { | |
| 157 base::snprintf( | |
| 158 event->keyIdentifier, | |
| 159 sizeof(event->keyIdentifier), | |
| 160 "U+%04X", | |
| 161 base::ToUpperASCII(static_cast<base::char16>(windows_key_code))); | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 int WebEventModifiersToEventFlags(int modifiers) { | 29 int WebEventModifiersToEventFlags(int modifiers) { |
| 166 int flags = 0; | 30 int flags = 0; |
| 167 | 31 |
| 168 if (modifiers & blink::WebInputEvent::ShiftKey) | 32 if (modifiers & blink::WebInputEvent::ShiftKey) |
| 169 flags |= ui::EF_SHIFT_DOWN; | 33 flags |= ui::EF_SHIFT_DOWN; |
| 170 if (modifiers & blink::WebInputEvent::ControlKey) | 34 if (modifiers & blink::WebInputEvent::ControlKey) |
| 171 flags |= ui::EF_CONTROL_DOWN; | 35 flags |= ui::EF_CONTROL_DOWN; |
| 172 if (modifiers & blink::WebInputEvent::AltKey) | 36 if (modifiers & blink::WebInputEvent::AltKey) |
| 173 flags |= ui::EF_ALT_DOWN; | 37 flags |= ui::EF_ALT_DOWN; |
| 174 if (modifiers & blink::WebInputEvent::MetaKey) | 38 if (modifiers & blink::WebInputEvent::MetaKey) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 197 return blink::WebInputEvent::IsRight; | 61 return blink::WebInputEvent::IsRight; |
| 198 case ui::DomKeyLocation::NUMPAD: | 62 case ui::DomKeyLocation::NUMPAD: |
| 199 return blink::WebInputEvent::IsKeyPad; | 63 return blink::WebInputEvent::IsKeyPad; |
| 200 case ui::DomKeyLocation::STANDARD: | 64 case ui::DomKeyLocation::STANDARD: |
| 201 break; | 65 break; |
| 202 } | 66 } |
| 203 return static_cast<blink::WebInputEvent::Modifiers>(0); | 67 return static_cast<blink::WebInputEvent::Modifiers>(0); |
| 204 } | 68 } |
| 205 | 69 |
| 206 } // namespace content | 70 } // namespace content |
| OLD | NEW |