Chromium Code Reviews| 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/gfx/geometry/safe_integer_conversions.h" | 19 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 19 | 20 |
| 20 using blink::WebGestureEvent; | 21 using blink::WebGestureEvent; |
| 21 using blink::WebInputEvent; | 22 using blink::WebInputEvent; |
| 22 using blink::WebTouchEvent; | 23 using blink::WebTouchEvent; |
| 23 using blink::WebTouchPoint; | 24 using blink::WebTouchPoint; |
| 24 using ui::MotionEvent; | 25 using ui::MotionEvent; |
| 25 | 26 |
| 26 namespace { | |
| 27 | |
| 28 const char* GetKeyIdentifier(ui::KeyboardCode key_code) { | |
| 29 switch (key_code) { | |
| 30 case ui::VKEY_MENU: | |
| 31 return "Alt"; | |
| 32 case ui::VKEY_CONTROL: | |
| 33 return "Control"; | |
| 34 case ui::VKEY_SHIFT: | |
| 35 return "Shift"; | |
| 36 case ui::VKEY_CAPITAL: | |
| 37 return "CapsLock"; | |
| 38 case ui::VKEY_LWIN: | |
| 39 case ui::VKEY_RWIN: | |
| 40 return "Win"; | |
| 41 case ui::VKEY_CLEAR: | |
| 42 return "Clear"; | |
| 43 case ui::VKEY_DOWN: | |
| 44 return "Down"; | |
| 45 case ui::VKEY_END: | |
| 46 return "End"; | |
| 47 case ui::VKEY_RETURN: | |
| 48 return "Enter"; | |
| 49 case ui::VKEY_EXECUTE: | |
| 50 return "Execute"; | |
| 51 case ui::VKEY_F1: | |
| 52 return "F1"; | |
| 53 case ui::VKEY_F2: | |
| 54 return "F2"; | |
| 55 case ui::VKEY_F3: | |
| 56 return "F3"; | |
| 57 case ui::VKEY_F4: | |
| 58 return "F4"; | |
| 59 case ui::VKEY_F5: | |
| 60 return "F5"; | |
| 61 case ui::VKEY_F6: | |
| 62 return "F6"; | |
| 63 case ui::VKEY_F7: | |
| 64 return "F7"; | |
| 65 case ui::VKEY_F8: | |
| 66 return "F8"; | |
| 67 case ui::VKEY_F9: | |
| 68 return "F9"; | |
| 69 case ui::VKEY_F10: | |
| 70 return "F10"; | |
| 71 case ui::VKEY_F11: | |
| 72 return "F11"; | |
| 73 case ui::VKEY_F12: | |
| 74 return "F12"; | |
| 75 case ui::VKEY_F13: | |
| 76 return "F13"; | |
| 77 case ui::VKEY_F14: | |
| 78 return "F14"; | |
| 79 case ui::VKEY_F15: | |
| 80 return "F15"; | |
| 81 case ui::VKEY_F16: | |
| 82 return "F16"; | |
| 83 case ui::VKEY_F17: | |
| 84 return "F17"; | |
| 85 case ui::VKEY_F18: | |
| 86 return "F18"; | |
| 87 case ui::VKEY_F19: | |
| 88 return "F19"; | |
| 89 case ui::VKEY_F20: | |
| 90 return "F20"; | |
| 91 case ui::VKEY_F21: | |
| 92 return "F21"; | |
| 93 case ui::VKEY_F22: | |
| 94 return "F22"; | |
| 95 case ui::VKEY_F23: | |
| 96 return "F23"; | |
| 97 case ui::VKEY_F24: | |
| 98 return "F24"; | |
| 99 case ui::VKEY_HELP: | |
| 100 return "Help"; | |
| 101 case ui::VKEY_HOME: | |
| 102 return "Home"; | |
| 103 case ui::VKEY_INSERT: | |
| 104 return "Insert"; | |
| 105 case ui::VKEY_LEFT: | |
| 106 return "Left"; | |
| 107 case ui::VKEY_NEXT: | |
| 108 return "PageDown"; | |
| 109 case ui::VKEY_PRIOR: | |
| 110 return "PageUp"; | |
| 111 case ui::VKEY_PAUSE: | |
| 112 return "Pause"; | |
| 113 case ui::VKEY_SNAPSHOT: | |
| 114 return "PrintScreen"; | |
| 115 case ui::VKEY_RIGHT: | |
| 116 return "Right"; | |
| 117 case ui::VKEY_SCROLL: | |
| 118 return "Scroll"; | |
| 119 case ui::VKEY_SELECT: | |
| 120 return "Select"; | |
| 121 case ui::VKEY_UP: | |
| 122 return "Up"; | |
| 123 case ui::VKEY_DELETE: | |
| 124 return "U+007F"; // Standard says that DEL becomes U+007F. | |
| 125 case ui::VKEY_MEDIA_NEXT_TRACK: | |
| 126 return "MediaNextTrack"; | |
| 127 case ui::VKEY_MEDIA_PREV_TRACK: | |
| 128 return "MediaPreviousTrack"; | |
| 129 case ui::VKEY_MEDIA_STOP: | |
| 130 return "MediaStop"; | |
| 131 case ui::VKEY_MEDIA_PLAY_PAUSE: | |
| 132 return "MediaPlayPause"; | |
| 133 case ui::VKEY_VOLUME_MUTE: | |
| 134 return "VolumeMute"; | |
| 135 case ui::VKEY_VOLUME_DOWN: | |
| 136 return "VolumeDown"; | |
| 137 case ui::VKEY_VOLUME_UP: | |
| 138 return "VolumeUp"; | |
| 139 default: | |
| 140 return NULL; | |
| 141 }; | |
| 142 } | |
| 143 | |
| 144 } // namespace | |
| 145 | |
| 146 namespace content { | 27 namespace content { |
| 147 | 28 |
| 148 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, | |
| 149 ui::KeyboardCode windows_key_code) { | |
| 150 event->windowsKeyCode = windows_key_code; | |
| 151 | |
| 152 const char* id = GetKeyIdentifier(windows_key_code); | |
| 153 if (id) { | |
| 154 base::strlcpy(event->keyIdentifier, id, sizeof(event->keyIdentifier) - 1); | |
| 155 } else { | |
| 156 base::snprintf( | |
| 157 event->keyIdentifier, | |
| 158 sizeof(event->keyIdentifier), | |
| 159 "U+%04X", | |
| 160 base::ToUpperASCII(static_cast<base::char16>(windows_key_code))); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 int WebEventModifiersToEventFlags(int modifiers) { | 29 int WebEventModifiersToEventFlags(int modifiers) { |
| 165 int flags = 0; | 30 int flags = 0; |
| 166 | 31 |
| 167 if (modifiers & blink::WebInputEvent::ShiftKey) | 32 if (modifiers & blink::WebInputEvent::ShiftKey) |
| 168 flags |= ui::EF_SHIFT_DOWN; | 33 flags |= ui::EF_SHIFT_DOWN; |
| 169 if (modifiers & blink::WebInputEvent::ControlKey) | 34 if (modifiers & blink::WebInputEvent::ControlKey) |
| 170 flags |= ui::EF_CONTROL_DOWN; | 35 flags |= ui::EF_CONTROL_DOWN; |
| 171 if (modifiers & blink::WebInputEvent::AltKey) | 36 if (modifiers & blink::WebInputEvent::AltKey) |
| 172 flags |= ui::EF_ALT_DOWN; | 37 flags |= ui::EF_ALT_DOWN; |
| 173 if (modifiers & blink::WebInputEvent::MetaKey) | 38 if (modifiers & blink::WebInputEvent::MetaKey) |
| 174 flags |= ui::EF_COMMAND_DOWN; | 39 flags |= ui::EF_COMMAND_DOWN; |
| 175 | 40 |
| 176 if (modifiers & blink::WebInputEvent::LeftButtonDown) | 41 if (modifiers & blink::WebInputEvent::LeftButtonDown) |
| 177 flags |= ui::EF_LEFT_MOUSE_BUTTON; | 42 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 178 if (modifiers & blink::WebInputEvent::MiddleButtonDown) | 43 if (modifiers & blink::WebInputEvent::MiddleButtonDown) |
| 179 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; | 44 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
| 180 if (modifiers & blink::WebInputEvent::RightButtonDown) | 45 if (modifiers & blink::WebInputEvent::RightButtonDown) |
| 181 flags |= ui::EF_RIGHT_MOUSE_BUTTON; | 46 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 182 if (modifiers & blink::WebInputEvent::CapsLockOn) | 47 if (modifiers & blink::WebInputEvent::CapsLockOn) |
| 183 flags |= ui::EF_CAPS_LOCK_DOWN; | 48 flags |= ui::EF_CAPS_LOCK_DOWN; |
| 184 if (modifiers & blink::WebInputEvent::IsAutoRepeat) | 49 if (modifiers & blink::WebInputEvent::IsAutoRepeat) |
| 185 flags |= ui::EF_IS_REPEAT; | 50 flags |= ui::EF_IS_REPEAT; |
| 186 | 51 |
| 187 return flags; | 52 return flags; |
| 188 } | 53 } |
| 189 | 54 |
| 55 blink::WebInputEvent::Modifiers DomCodeToWebInputEventModifiers( | |
|
Wez
2015/09/09 06:06:11
Don't we already have this for Aura? Could we get
dtapuska
2015/09/09 18:45:49
This is making it the common copy.. I removed this
| |
| 56 ui::DomCode code) { | |
| 57 switch (ui::KeycodeConverter::DomCodeToLocation(code)) { | |
| 58 case ui::DomKeyLocation::LEFT: | |
| 59 return blink::WebInputEvent::IsLeft; | |
| 60 case ui::DomKeyLocation::RIGHT: | |
| 61 return blink::WebInputEvent::IsRight; | |
| 62 case ui::DomKeyLocation::NUMPAD: | |
| 63 return blink::WebInputEvent::IsKeyPad; | |
| 64 case ui::DomKeyLocation::STANDARD: | |
| 65 break; | |
| 66 } | |
| 67 return static_cast<blink::WebInputEvent::Modifiers>(0); | |
| 68 } | |
| 69 | |
| 190 } // namespace content | 70 } // namespace content |
| OLD | NEW |