| 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 #include "content/browser/renderer_host/input/web_input_event_builders_win.h" | 5 #include "content/browser/renderer_host/input/web_input_event_builders_win.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 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 using blink::WebInputEvent; | 10 using blink::WebInputEvent; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 // Loads the state for toggle keys into the event. | 96 // Loads the state for toggle keys into the event. |
| 97 static void SetToggleKeyState(WebInputEvent* event) { | 97 static void SetToggleKeyState(WebInputEvent* event) { |
| 98 // Low bit set from GetKeyState indicates "toggled". | 98 // Low bit set from GetKeyState indicates "toggled". |
| 99 if (::GetKeyState(VK_NUMLOCK) & 1) | 99 if (::GetKeyState(VK_NUMLOCK) & 1) |
| 100 event->modifiers |= WebInputEvent::NumLockOn; | 100 event->modifiers |= WebInputEvent::NumLockOn; |
| 101 if (::GetKeyState(VK_CAPITAL) & 1) | 101 if (::GetKeyState(VK_CAPITAL) & 1) |
| 102 event->modifiers |= WebInputEvent::CapsLockOn; | 102 event->modifiers |= WebInputEvent::CapsLockOn; |
| 103 } | 103 } |
| 104 | 104 |
| 105 WebKeyboardEvent WebKeyboardEventBuilder::Build(HWND hwnd, UINT message, | 105 WebKeyboardEvent WebKeyboardEventBuilder::Build(HWND hwnd, |
| 106 WPARAM wparam, LPARAM lparam) { | 106 UINT message, |
| 107 WPARAM wparam, |
| 108 LPARAM lparam, |
| 109 DWORD time_ms) { |
| 107 WebKeyboardEvent result; | 110 WebKeyboardEvent result; |
| 108 | 111 |
| 109 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that | 112 DCHECK(time_ms); |
| 110 // GetMessageTime() refers to is the same one that we're passed in? Perhaps | 113 result.timeStampSeconds = time_ms / 1000.0; |
| 111 // one of the construction parameters should be the time passed by the | |
| 112 // caller, who would know for sure. | |
| 113 result.timeStampSeconds = ::GetMessageTime() / 1000.0; | |
| 114 | 114 |
| 115 result.windowsKeyCode = static_cast<int>(wparam); | 115 result.windowsKeyCode = static_cast<int>(wparam); |
| 116 // Record the scan code (along with other context bits) for this key event. | 116 // Record the scan code (along with other context bits) for this key event. |
| 117 result.nativeKeyCode = static_cast<int>(lparam); | 117 result.nativeKeyCode = static_cast<int>(lparam); |
| 118 | 118 |
| 119 switch (message) { | 119 switch (message) { |
| 120 case WM_SYSKEYDOWN: | 120 case WM_SYSKEYDOWN: |
| 121 result.isSystemKey = true; | 121 result.isSystemKey = true; |
| 122 case WM_KEYDOWN: | 122 case WM_KEYDOWN: |
| 123 result.type = WebInputEvent::RawKeyDown; | 123 result.type = WebInputEvent::RawKeyDown; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 static int g_last_click_count = 0; | 174 static int g_last_click_count = 0; |
| 175 static double g_last_click_time = 0; | 175 static double g_last_click_time = 0; |
| 176 | 176 |
| 177 static LPARAM GetRelativeCursorPos(HWND hwnd) { | 177 static LPARAM GetRelativeCursorPos(HWND hwnd) { |
| 178 POINT pos = {-1, -1}; | 178 POINT pos = {-1, -1}; |
| 179 GetCursorPos(&pos); | 179 GetCursorPos(&pos); |
| 180 ScreenToClient(hwnd, &pos); | 180 ScreenToClient(hwnd, &pos); |
| 181 return MAKELPARAM(pos.x, pos.y); | 181 return MAKELPARAM(pos.x, pos.y); |
| 182 } | 182 } |
| 183 | 183 |
| 184 WebMouseEvent WebMouseEventBuilder::Build(HWND hwnd, UINT message, | 184 WebMouseEvent WebMouseEventBuilder::Build(HWND hwnd, |
| 185 WPARAM wparam, LPARAM lparam) { | 185 UINT message, |
| 186 WPARAM wparam, |
| 187 LPARAM lparam, |
| 188 DWORD time_ms) { |
| 186 WebMouseEvent result; | 189 WebMouseEvent result; |
| 187 | 190 |
| 188 switch (message) { | 191 switch (message) { |
| 189 case WM_MOUSEMOVE: | 192 case WM_MOUSEMOVE: |
| 190 result.type = WebInputEvent::MouseMove; | 193 result.type = WebInputEvent::MouseMove; |
| 191 if (wparam & MK_LBUTTON) | 194 if (wparam & MK_LBUTTON) |
| 192 result.button = WebMouseEvent::ButtonLeft; | 195 result.button = WebMouseEvent::ButtonLeft; |
| 193 else if (wparam & MK_MBUTTON) | 196 else if (wparam & MK_MBUTTON) |
| 194 result.button = WebMouseEvent::ButtonMiddle; | 197 result.button = WebMouseEvent::ButtonMiddle; |
| 195 else if (wparam & MK_RBUTTON) | 198 else if (wparam & MK_RBUTTON) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 result.button = WebMouseEvent::ButtonMiddle; | 231 result.button = WebMouseEvent::ButtonMiddle; |
| 229 break; | 232 break; |
| 230 case WM_RBUTTONUP: | 233 case WM_RBUTTONUP: |
| 231 result.type = WebInputEvent::MouseUp; | 234 result.type = WebInputEvent::MouseUp; |
| 232 result.button = WebMouseEvent::ButtonRight; | 235 result.button = WebMouseEvent::ButtonRight; |
| 233 break; | 236 break; |
| 234 default: | 237 default: |
| 235 NOTREACHED(); | 238 NOTREACHED(); |
| 236 } | 239 } |
| 237 | 240 |
| 238 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that | 241 DCHECK(time_ms); |
| 239 // GetMessageTime() refers to is the same one that we're passed in? Perhaps | 242 result.timeStampSeconds = time_ms / 1000.0; |
| 240 // one of the construction parameters should be the time passed by the | |
| 241 // caller, who would know for sure. | |
| 242 result.timeStampSeconds = ::GetMessageTime() / 1000.0; | |
| 243 | 243 |
| 244 // set position fields: | 244 // set position fields: |
| 245 | 245 |
| 246 result.x = static_cast<short>(LOWORD(lparam)); | 246 result.x = static_cast<short>(LOWORD(lparam)); |
| 247 result.y = static_cast<short>(HIWORD(lparam)); | 247 result.y = static_cast<short>(HIWORD(lparam)); |
| 248 result.windowX = result.x; | 248 result.windowX = result.x; |
| 249 result.windowY = result.y; | 249 result.windowY = result.y; |
| 250 | 250 |
| 251 POINT global_point = { result.x, result.y }; | 251 POINT global_point = { result.x, result.y }; |
| 252 ClientToScreen(hwnd, &global_point); | 252 ClientToScreen(hwnd, &global_point); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 result.modifiers |= WebInputEvent::MiddleButtonDown; | 305 result.modifiers |= WebInputEvent::MiddleButtonDown; |
| 306 if (wparam & MK_RBUTTON) | 306 if (wparam & MK_RBUTTON) |
| 307 result.modifiers |= WebInputEvent::RightButtonDown; | 307 result.modifiers |= WebInputEvent::RightButtonDown; |
| 308 | 308 |
| 309 SetToggleKeyState(&result); | 309 SetToggleKeyState(&result); |
| 310 return result; | 310 return result; |
| 311 } | 311 } |
| 312 | 312 |
| 313 // WebMouseWheelEvent --------------------------------------------------------- | 313 // WebMouseWheelEvent --------------------------------------------------------- |
| 314 | 314 |
| 315 WebMouseWheelEvent | 315 WebMouseWheelEvent WebMouseWheelEventBuilder::Build(HWND hwnd, |
| 316 WebMouseWheelEventBuilder::Build(HWND hwnd, UINT message, | 316 UINT message, |
| 317 WPARAM wparam, LPARAM lparam) { | 317 WPARAM wparam, |
| 318 LPARAM lparam, |
| 319 DWORD time_ms) { |
| 318 WebMouseWheelEvent result; | 320 WebMouseWheelEvent result; |
| 319 | 321 |
| 320 result.type = WebInputEvent::MouseWheel; | 322 result.type = WebInputEvent::MouseWheel; |
| 321 | 323 |
| 322 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that | 324 DCHECK(time_ms); |
| 323 // GetMessageTime() refers to is the same one that we're passed in? Perhaps | 325 result.timeStampSeconds = time_ms / 1000.0; |
| 324 // one of the construction parameters should be the time passed by the | |
| 325 // caller, who would know for sure. | |
| 326 result.timeStampSeconds = ::GetMessageTime() / 1000.0; | |
| 327 | 326 |
| 328 result.button = WebMouseEvent::ButtonNone; | 327 result.button = WebMouseEvent::ButtonNone; |
| 329 | 328 |
| 330 // Get key state, coordinates, and wheel delta from event. | 329 // Get key state, coordinates, and wheel delta from event. |
| 331 typedef SHORT (WINAPI *GetKeyStateFunction)(int key); | 330 typedef SHORT (WINAPI *GetKeyStateFunction)(int key); |
| 332 GetKeyStateFunction get_key_state_func; | 331 GetKeyStateFunction get_key_state_func; |
| 333 UINT key_state; | 332 UINT key_state; |
| 334 float wheel_delta; | 333 float wheel_delta; |
| 335 bool horizontal_scroll = false; | 334 bool horizontal_scroll = false; |
| 336 if ((message == WM_VSCROLL) || (message == WM_HSCROLL)) { | 335 if ((message == WM_VSCROLL) || (message == WM_HSCROLL)) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 result.wheelTicksX = wheel_delta; | 452 result.wheelTicksX = wheel_delta; |
| 454 } else { | 453 } else { |
| 455 result.deltaY = scroll_delta; | 454 result.deltaY = scroll_delta; |
| 456 result.wheelTicksY = wheel_delta; | 455 result.wheelTicksY = wheel_delta; |
| 457 } | 456 } |
| 458 | 457 |
| 459 return result; | 458 return result; |
| 460 } | 459 } |
| 461 | 460 |
| 462 } // namespace content | 461 } // namespace content |
| OLD | NEW |