OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006-2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006-2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 keypad = false; | 84 keypad = false; |
85 } | 85 } |
86 return keypad; | 86 return keypad; |
87 } | 87 } |
88 | 88 |
89 WebKeyboardEvent WebInputEventFactory::keyboardEvent(HWND hwnd, UINT message, | 89 WebKeyboardEvent WebInputEventFactory::keyboardEvent(HWND hwnd, UINT message, |
90 WPARAM wparam, LPARAM lparam) | 90 WPARAM wparam, LPARAM lparam) |
91 { | 91 { |
92 WebKeyboardEvent result; | 92 WebKeyboardEvent result; |
93 | 93 |
| 94 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that |
| 95 // GetMessageTime() refers to is the same one that we're passed in? Perhaps |
| 96 // one of the construction parameters should be the time passed by the |
| 97 // caller, who would know for sure. |
| 98 result.timeStampSeconds = GetMessageTime() / 1000.0; |
| 99 |
94 result.windowsKeyCode = result.nativeKeyCode = static_cast<int>(wparam); | 100 result.windowsKeyCode = result.nativeKeyCode = static_cast<int>(wparam); |
95 | 101 |
96 switch (message) { | 102 switch (message) { |
97 case WM_SYSKEYDOWN: | 103 case WM_SYSKEYDOWN: |
98 result.isSystemKey = true; | 104 result.isSystemKey = true; |
99 case WM_KEYDOWN: | 105 case WM_KEYDOWN: |
100 result.type = WebInputEvent::RawKeyDown; | 106 result.type = WebInputEvent::RawKeyDown; |
101 break; | 107 break; |
102 case WM_SYSKEYUP: | 108 case WM_SYSKEYUP: |
103 result.isSystemKey = true; | 109 result.isSystemKey = true; |
(...skipping 19 matching lines...) Expand all Loading... |
123 } | 129 } |
124 if (result.type != WebInputEvent::Char) | 130 if (result.type != WebInputEvent::Char) |
125 result.setKeyIdentifierFromWindowsKeyCode(); | 131 result.setKeyIdentifierFromWindowsKeyCode(); |
126 | 132 |
127 if (GetKeyState(VK_SHIFT) & 0x8000) | 133 if (GetKeyState(VK_SHIFT) & 0x8000) |
128 result.modifiers |= WebInputEvent::ShiftKey; | 134 result.modifiers |= WebInputEvent::ShiftKey; |
129 if (GetKeyState(VK_CONTROL) & 0x8000) | 135 if (GetKeyState(VK_CONTROL) & 0x8000) |
130 result.modifiers |= WebInputEvent::ControlKey; | 136 result.modifiers |= WebInputEvent::ControlKey; |
131 if (GetKeyState(VK_MENU) & 0x8000) | 137 if (GetKeyState(VK_MENU) & 0x8000) |
132 result.modifiers |= WebInputEvent::AltKey; | 138 result.modifiers |= WebInputEvent::AltKey; |
| 139 // NOTE: There doesn't seem to be a way to query the mouse button state in |
| 140 // this case. |
133 | 141 |
134 if (LOWORD(lparam) > 1) | 142 if (LOWORD(lparam) > 1) |
135 result.modifiers |= WebInputEvent::IsAutoRepeat; | 143 result.modifiers |= WebInputEvent::IsAutoRepeat; |
136 if (isKeyPad(wparam, lparam)) | 144 if (isKeyPad(wparam, lparam)) |
137 result.modifiers |= WebInputEvent::IsKeyPad; | 145 result.modifiers |= WebInputEvent::IsKeyPad; |
138 | 146 |
139 return result; | 147 return result; |
140 } | 148 } |
141 | 149 |
142 // WebMouseEvent -------------------------------------------------------------- | 150 // WebMouseEvent -------------------------------------------------------------- |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that | 223 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that |
216 // GetMessageTime() refers to is the same one that we're passed in? Perhaps | 224 // GetMessageTime() refers to is the same one that we're passed in? Perhaps |
217 // one of the construction parameters should be the time passed by the | 225 // one of the construction parameters should be the time passed by the |
218 // caller, who would know for sure. | 226 // caller, who would know for sure. |
219 result.timeStampSeconds = GetMessageTime() / 1000.0; | 227 result.timeStampSeconds = GetMessageTime() / 1000.0; |
220 | 228 |
221 // set position fields: | 229 // set position fields: |
222 | 230 |
223 result.x = static_cast<short>(LOWORD(lparam)); | 231 result.x = static_cast<short>(LOWORD(lparam)); |
224 result.y = static_cast<short>(HIWORD(lparam)); | 232 result.y = static_cast<short>(HIWORD(lparam)); |
| 233 result.windowX = result.x; |
| 234 result.windowY = result.y; |
225 | 235 |
226 POINT globalPoint = { result.x, result.y }; | 236 POINT globalPoint = { result.x, result.y }; |
227 ClientToScreen(hwnd, &globalPoint); | 237 ClientToScreen(hwnd, &globalPoint); |
228 | 238 |
229 result.globalX = globalPoint.x; | 239 result.globalX = globalPoint.x; |
230 result.globalY = globalPoint.y; | 240 result.globalY = globalPoint.y; |
231 | 241 |
232 // calculate number of clicks: | 242 // calculate number of clicks: |
233 | 243 |
234 // This differs slightly from the WebKit code in WebKit/win/WebView.cpp | 244 // This differs slightly from the WebKit code in WebKit/win/WebView.cpp |
(...skipping 30 matching lines...) Expand all Loading... |
265 result.clickCount = gLastClickCount; | 275 result.clickCount = gLastClickCount; |
266 | 276 |
267 // set modifiers: | 277 // set modifiers: |
268 | 278 |
269 if (wparam & MK_CONTROL) | 279 if (wparam & MK_CONTROL) |
270 result.modifiers |= WebInputEvent::ControlKey; | 280 result.modifiers |= WebInputEvent::ControlKey; |
271 if (wparam & MK_SHIFT) | 281 if (wparam & MK_SHIFT) |
272 result.modifiers |= WebInputEvent::ShiftKey; | 282 result.modifiers |= WebInputEvent::ShiftKey; |
273 if (GetKeyState(VK_MENU) & 0x8000) | 283 if (GetKeyState(VK_MENU) & 0x8000) |
274 result.modifiers |= WebInputEvent::AltKey; | 284 result.modifiers |= WebInputEvent::AltKey; |
| 285 if (wparam & MK_LBUTTON) |
| 286 result.modifiers |= WebInputEvent::LeftButtonDown; |
| 287 if (wparam & MK_MBUTTON) |
| 288 result.modifiers |= WebInputEvent::MiddleButtonDown; |
| 289 if (wparam & MK_RBUTTON) |
| 290 result.modifiers |= WebInputEvent::RightButtonDown; |
275 | 291 |
276 return result; | 292 return result; |
277 } | 293 } |
278 | 294 |
279 // WebMouseWheelEvent --------------------------------------------------------- | 295 // WebMouseWheelEvent --------------------------------------------------------- |
280 | 296 |
281 WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(HWND hwnd, UINT message, | 297 WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(HWND hwnd, UINT message, |
282 WPARAM wparam, LPARAM lparam) | 298 WPARAM wparam, LPARAM lparam) |
283 { | 299 { |
284 WebMouseWheelEvent result; //(WebInputEvent::Uninitialized()); | 300 WebMouseWheelEvent result; //(WebInputEvent::Uninitialized()); |
285 | 301 |
286 result.type = WebInputEvent::MouseWheel; | 302 result.type = WebInputEvent::MouseWheel; |
| 303 |
| 304 // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that |
| 305 // GetMessageTime() refers to is the same one that we're passed in? Perhaps |
| 306 // one of the construction parameters should be the time passed by the |
| 307 // caller, who would know for sure. |
| 308 result.timeStampSeconds = GetMessageTime() / 1000.0; |
| 309 |
287 result.button = WebMouseEvent::ButtonNone; | 310 result.button = WebMouseEvent::ButtonNone; |
288 | 311 |
289 // Get key state, coordinates, and wheel delta from event. | 312 // Get key state, coordinates, and wheel delta from event. |
290 typedef SHORT (WINAPI *GetKeyStateFunction)(int key); | 313 typedef SHORT (WINAPI *GetKeyStateFunction)(int key); |
291 GetKeyStateFunction getKeyState; | 314 GetKeyStateFunction getKeyState; |
292 UINT keyState; | 315 UINT keyState; |
293 float wheelDelta; | 316 float wheelDelta; |
294 bool horizontalScroll = false; | 317 bool horizontalScroll = false; |
295 if ((message == WM_VSCROLL) || (message == WM_HSCROLL)) { | 318 if ((message == WM_VSCROLL) || (message == WM_HSCROLL)) { |
296 // Synthesize mousewheel event from a scroll event. This is needed to | 319 // Synthesize mousewheel event from a scroll event. This is needed to |
297 // simulate middle mouse scrolling in some laptops. Use GetAsyncKeyState | 320 // simulate middle mouse scrolling in some laptops. Use GetAsyncKeyState |
298 // for key state since we are synthesizing the input event. | 321 // for key state since we are synthesizing the input event. |
299 getKeyState = GetAsyncKeyState; | 322 getKeyState = GetAsyncKeyState; |
300 keyState = 0; | 323 keyState = 0; |
301 if (getKeyState(VK_SHIFT)) | 324 if (getKeyState(VK_SHIFT)) |
302 keyState |= MK_SHIFT; | 325 keyState |= MK_SHIFT; |
303 if (getKeyState(VK_CONTROL)) | 326 if (getKeyState(VK_CONTROL)) |
304 keyState |= MK_CONTROL; | 327 keyState |= MK_CONTROL; |
| 328 // NOTE: There doesn't seem to be a way to query the mouse button state |
| 329 // in this case. |
305 | 330 |
306 POINT cursorPosition = {0}; | 331 POINT cursorPosition = {0}; |
307 GetCursorPos(&cursorPosition); | 332 GetCursorPos(&cursorPosition); |
308 result.globalX = cursorPosition.x; | 333 result.globalX = cursorPosition.x; |
309 result.globalY = cursorPosition.y; | 334 result.globalY = cursorPosition.y; |
310 | 335 |
311 switch (LOWORD(wparam)) { | 336 switch (LOWORD(wparam)) { |
312 case SB_LINEUP: // == SB_LINELEFT | 337 case SB_LINEUP: // == SB_LINELEFT |
313 wheelDelta = WHEEL_DELTA; | 338 wheelDelta = WHEEL_DELTA; |
314 break; | 339 break; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (keyState & MK_SHIFT) | 372 if (keyState & MK_SHIFT) |
348 horizontalScroll = true; | 373 horizontalScroll = true; |
349 | 374 |
350 // Set modifiers based on key state. | 375 // Set modifiers based on key state. |
351 if (keyState & MK_SHIFT) | 376 if (keyState & MK_SHIFT) |
352 result.modifiers |= WebInputEvent::ShiftKey; | 377 result.modifiers |= WebInputEvent::ShiftKey; |
353 if (keyState & MK_CONTROL) | 378 if (keyState & MK_CONTROL) |
354 result.modifiers |= WebInputEvent::ControlKey; | 379 result.modifiers |= WebInputEvent::ControlKey; |
355 if (getKeyState(VK_MENU) & 0x8000) | 380 if (getKeyState(VK_MENU) & 0x8000) |
356 result.modifiers |= WebInputEvent::AltKey; | 381 result.modifiers |= WebInputEvent::AltKey; |
| 382 if (keyState & MK_LBUTTON) |
| 383 result.modifiers |= WebInputEvent::LeftButtonDown; |
| 384 if (keyState & MK_MBUTTON) |
| 385 result.modifiers |= WebInputEvent::MiddleButtonDown; |
| 386 if (keyState & MK_RBUTTON) |
| 387 result.modifiers |= WebInputEvent::RightButtonDown; |
357 | 388 |
358 // Set coordinates by translating event coordinates from screen to client. | 389 // Set coordinates by translating event coordinates from screen to client. |
359 POINT clientPoint = { result.globalX, result.globalY }; | 390 POINT clientPoint = { result.globalX, result.globalY }; |
360 MapWindowPoints(NULL, hwnd, &clientPoint, 1); | 391 MapWindowPoints(NULL, hwnd, &clientPoint, 1); |
361 result.x = clientPoint.x; | 392 result.x = clientPoint.x; |
362 result.y = clientPoint.y; | 393 result.y = clientPoint.y; |
| 394 result.windowX = result.x; |
| 395 result.windowY = result.y; |
363 | 396 |
364 // Convert wheel delta amount to a number of pixels to scroll. | 397 // Convert wheel delta amount to a number of pixels to scroll. |
365 // | 398 // |
366 // How many pixels should we scroll per line? Gecko uses the height of the | 399 // How many pixels should we scroll per line? Gecko uses the height of the |
367 // current line, which means scroll distance changes as you go through the | 400 // current line, which means scroll distance changes as you go through the |
368 // page or go to different pages. IE 7 is ~50 px/line, although the value | 401 // page or go to different pages. IE 7 is ~50 px/line, although the value |
369 // seems to vary slightly by page and zoom level. Since IE 7 has a smoothing | 402 // seems to vary slightly by page and zoom level. Since IE 7 has a smoothing |
370 // algorithm on scrolling, it can get away with slightly larger scroll values | 403 // algorithm on scrolling, it can get away with slightly larger scroll values |
371 // without feeling jerky. Here we use 100 px per three lines (the default | 404 // without feeling jerky. Here we use 100 px per three lines (the default |
372 // scroll amount is three lines per wheel tick). | 405 // scroll amount is three lines per wheel tick). |
(...skipping 22 matching lines...) Expand all Loading... |
395 result.wheelTicksX = wheelDelta; | 428 result.wheelTicksX = wheelDelta; |
396 } else { | 429 } else { |
397 result.deltaY = scrollDelta; | 430 result.deltaY = scrollDelta; |
398 result.wheelTicksY = wheelDelta; | 431 result.wheelTicksY = wheelDelta; |
399 } | 432 } |
400 | 433 |
401 return result; | 434 return result; |
402 } | 435 } |
403 | 436 |
404 } // namespace WebKit | 437 } // namespace WebKit |
OLD | NEW |