15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windowsx.h> 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_constants.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/win_util.h" 12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_utils.h" 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/keycodes/keyboard_code_conversion_win.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/point.h" 15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/win/dpi.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// From MSDN: "Mouse" events are flagged with 0xFF515700 if they come 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// from a touch or stylus device. In Vista or later, they are also flagged 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// with 0x80 if they come from touch. 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define MOUSEEVENTF_FROMTOUCH (0xFF515700 | 0x80) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the native mouse key state from the native event message type. 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int GetNativeMouseKey(const base::NativeEvent& native_event) { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (native_event.message) { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_LBUTTONDBLCLK: 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_LBUTTONDOWN: 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_LBUTTONUP: 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCLBUTTONDBLCLK: 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCLBUTTONDOWN: 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCLBUTTONUP: 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return MK_LBUTTON; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MBUTTONDBLCLK: 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MBUTTONDOWN: 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MBUTTONUP: 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMBUTTONDBLCLK: 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMBUTTONDOWN: 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMBUTTONUP: 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return MK_MBUTTON; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_RBUTTONDBLCLK: 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_RBUTTONDOWN: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_RBUTTONUP: 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCRBUTTONDBLCLK: 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCRBUTTONDOWN: 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCRBUTTONUP: 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return MK_RBUTTON; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCXBUTTONDBLCLK: 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCXBUTTONDOWN: 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCXBUTTONUP: 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_XBUTTONDBLCLK: 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_XBUTTONDOWN: 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_XBUTTONUP: 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return MK_XBUTTON1; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsButtonDown(const base::NativeEvent& native_event) { 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ((MK_LBUTTON | MK_MBUTTON | MK_RBUTTON | MK_XBUTTON1 | MK_XBUTTON2) & 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.wParam) != 0; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsClientMouseEvent(const base::NativeEvent& native_event) { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_event.message == WM_MOUSELEAVE || 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_MOUSEHOVER || 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (native_event.message >= WM_MOUSEFIRST && 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message <= WM_MOUSELAST); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsNonClientMouseEvent(const base::NativeEvent& native_event) { 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_event.message == WM_NCMOUSELEAVE || 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_NCMOUSEHOVER || 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (native_event.message >= WM_NCMOUSEMOVE && 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message <= WM_NCXBUTTONDBLCLK); 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsMouseWheelEvent(const base::NativeEvent& native_event) { 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_event.message == WM_MOUSEWHEEL || 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_MOUSEHWHEEL; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsKeyEvent(const base::NativeEvent& native_event) { 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_event.message == WM_KEYDOWN || 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_SYSKEYDOWN || 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_CHAR || 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_KEYUP || 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) native_event.message == WM_SYSKEYUP; 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9381843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles)bool IsScrollEvent(const base::NativeEvent& native_event) { 9481843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) return native_event.message == WM_VSCROLL || 9581843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) native_event.message == WM_HSCROLL; 9681843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles)} 9781843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a mask corresponding to the set of pressed modifier keys. 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Checks the current global state and the state sent by client mouse messages. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int KeyStateFlagsFromNative(const base::NativeEvent& native_event) { 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int flags = 0; 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= base::win::IsAltPressed() ? EF_ALT_DOWN : EF_NONE; 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= base::win::IsShiftPressed() ? EF_SHIFT_DOWN : EF_NONE; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= base::win::IsCtrlPressed() ? EF_CONTROL_DOWN : EF_NONE; 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check key messages for the extended key flag. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsKeyEvent(native_event)) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= (HIWORD(native_event.lParam) & KF_EXTENDED) ? EF_EXTENDED : 0; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Most client mouse messages include key state information. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsClientMouseEvent(native_event)) { 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= (win_flags & MK_SHIFT) ? EF_SHIFT_DOWN : 0; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= (win_flags & MK_CONTROL) ? EF_CONTROL_DOWN : 0; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return flags; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a mask corresponding to the set of pressed mouse buttons. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This includes the button of the given message, even if it is being released. 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int MouseStateFlagsFromNative(const base::NativeEvent& native_event) { 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int win_flags = GetNativeMouseKey(native_event); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Client mouse messages provide key states in their WPARAMs. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsClientMouseEvent(native_event)) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) win_flags |= GET_KEYSTATE_WPARAM(native_event.wParam); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int flags = 0; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= (win_flags & MK_LBUTTON) ? EF_LEFT_MOUSE_BUTTON : 0; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= (win_flags & MK_MBUTTON) ? EF_MIDDLE_MOUSE_BUTTON : 0; 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= (win_flags & MK_RBUTTON) ? EF_RIGHT_MOUSE_BUTTON : 0; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= IsNonClientMouseEvent(native_event) ? EF_IS_NON_CLIENT : 0; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return flags; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void UpdateDeviceList() { 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)EventType EventTypeFromNative(const base::NativeEvent& native_event) { 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (native_event.message) { 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_KEYDOWN: 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_SYSKEYDOWN: 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_CHAR: 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_KEY_PRESSED; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_KEYUP: 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_SYSKEYUP: 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_KEY_RELEASED; 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_LBUTTONDBLCLK: 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_LBUTTONDOWN: 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MBUTTONDBLCLK: 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MBUTTONDOWN: 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCLBUTTONDBLCLK: 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCLBUTTONDOWN: 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMBUTTONDBLCLK: 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMBUTTONDOWN: 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCRBUTTONDBLCLK: 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCRBUTTONDOWN: 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCXBUTTONDBLCLK: 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCXBUTTONDOWN: 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_RBUTTONDBLCLK: 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_RBUTTONDOWN: 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_XBUTTONDBLCLK: 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_XBUTTONDOWN: 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_MOUSE_PRESSED; 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_LBUTTONUP: 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MBUTTONUP: 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCLBUTTONUP: 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMBUTTONUP: 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCRBUTTONUP: 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCXBUTTONUP: 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_RBUTTONUP: 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_XBUTTONUP: 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_MOUSE_RELEASED; 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MOUSEMOVE: 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return IsButtonDown(native_event) ? ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMOUSEMOVE: 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_MOUSE_MOVED; 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MOUSEWHEEL: 18381843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) case WM_MOUSEHWHEEL: 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_MOUSEWHEEL; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_MOUSELEAVE: 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case WM_NCMOUSELEAVE: 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_MOUSE_EXITED; 18881843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) case WM_VSCROLL: 18981843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) case WM_HSCROLL: 19081843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) return ET_SCROLL; 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We can't NOTREACHED() here, since this function can be called for any 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // message. 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ET_UNKNOWN; 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int EventFlagsFromNative(const base::NativeEvent& native_event) { 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int flags = KeyStateFlagsFromNative(native_event); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsMouseEvent(native_event)) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) flags |= MouseStateFlagsFromNative(native_event); 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return flags; 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return base::TimeDelta::FromMilliseconds(native_event.time); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { 21281843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) POINT native_point; 2137da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) if ((native_event.message == WM_MOUSELEAVE || 2147da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) native_event.message == WM_NCMOUSELEAVE) || 2157da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) IsScrollEvent(native_event)) { 2167da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) // These events have no coordinates. For sanity with rest of events grab 2177da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) // coordinates from the OS. 21881843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) ::GetCursorPos(&native_point); 2197da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) } else if (IsClientMouseEvent(native_event) && 2207da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) !IsMouseWheelEvent(native_event)) { 2217da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) // Note: Wheel events are considered client, but their position is in screen 2227da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) // coordinates. 2237da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) // Client message. The position is contained in the LPARAM. 2247da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) return gfx::Point(native_event.lParam); 22581843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) } else { 2267da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) DCHECK(IsNonClientMouseEvent(native_event) || 2277da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) IsMouseWheelEvent(native_event) || IsScrollEvent(native_event)); 22881843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) // Non-client message. The position is contained in a POINTS structure in 22981843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) // LPARAM, and is in screen coordinates so we have to convert to client. 23081843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) native_point.x = GET_X_LPARAM(native_event.lParam); 23181843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) native_point.y = GET_Y_LPARAM(native_event.lParam); 23281843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) } 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ScreenToClient(native_event.hwnd, &native_point); 2347da551c69e84cdee501ba0193ee132bc3b5b2c1dTorne (Richard Coles) return gfx::win::ScreenToDIPPoint(gfx::Point(native_point)); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Point EventSystemLocationFromNative( 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::NativeEvent& native_event) { 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(ben): Needs to always return screen position here. Returning normal 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // origin for now since that's obviously wrong. 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Point(0, 0); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return KeyboardCodeForWindowsKeyCode(native_event.wParam); 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const char* CodeFromNative(const base::NativeEvent& native_event) { 249a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const uint16 scan_code = GetScanCodeFromLParam(native_event.lParam); 250a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return CodeForWindowsScanCode(scan_code); 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsMouseEvent(const base::NativeEvent& native_event) { 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return IsClientMouseEvent(native_event) || 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IsNonClientMouseEvent(native_event); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int GetChangedMouseButtonFlagsFromNative( 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::NativeEvent& native_event) { 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (GetNativeMouseKey(native_event)) { 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case MK_LBUTTON: 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return EF_LEFT_MOUSE_BUTTON; 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case MK_MBUTTON: 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return EF_MIDDLE_MOUSE_BUTTON; 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case MK_RBUTTON: 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return EF_RIGHT_MOUSE_BUTTON; 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO: add support for MK_XBUTTON1. 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) { 27581843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) DCHECK(native_event.message == WM_MOUSEWHEEL || 27681843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) native_event.message == WM_MOUSEHWHEEL); 27781843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) if (native_event.message == WM_MOUSEWHEEL) 27881843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) return gfx::Vector2d(0, GET_WHEEL_DELTA_WPARAM(native_event.wParam)); 27981843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) return gfx::Vector2d(GET_WHEEL_DELTA_WPARAM(native_event.wParam), 0); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 282a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void ClearTouchIdIfReleased(const base::NativeEvent& xev) { 283a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) NOTIMPLEMENTED(); 284a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 285a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int GetTouchId(const base::NativeEvent& xev) { 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0; 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)float GetTouchRadiusX(const base::NativeEvent& native_event) { 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 1.0; 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)float GetTouchRadiusY(const base::NativeEvent& native_event) { 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 1.0; 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)float GetTouchAngle(const base::NativeEvent& native_event) { 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0.0; 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)float GetTouchForce(const base::NativeEvent& native_event) { 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return 0.0; 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool GetScrollOffsets(const base::NativeEvent& native_event, 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float* x_offset, 3132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float* y_offset, 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float* x_offset_ordinal, 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float* y_offset_ordinal, 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int* finger_count) { 31781843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) // TODO(ananta) 31881843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) // Support retrieving the scroll offsets from the scroll event. 31981843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) if (native_event.message == WM_VSCROLL || native_event.message == WM_HSCROLL) 32081843c7b1423e241009db79d34acf2450330fcc5Torne (Richard Coles) return true; 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool GetFlingData(const base::NativeEvent& native_event, 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float* vx, 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float* vy, 3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float* vx_ordinal, 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float* vy_ordinal, 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* is_cancel) { 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Not supported in Windows. 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool GetGestureTimes(const base::NativeEvent& native_event, 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) double* start_time, 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) double* end_time) { 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Not supported in Windows. 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *start_time = 0; 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *end_time = 0; 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetNaturalScroll(bool enabled) { 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsNaturalScrollEnabled() { 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsTouchpadEvent(const base::NativeEvent& event) { 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsNoopEvent(const base::NativeEvent& event) { 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return event.message == WM_USER + 310; 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)base::NativeEvent CreateNoopEvent() { 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MSG event = { NULL }; 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.message = WM_USER + 310; 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return event; 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int GetModifiersFromACCEL(const ACCEL& accel) { 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int modifiers = EF_NONE; 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (accel.fVirt & FSHIFT) 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) modifiers |= EF_SHIFT_DOWN; 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (accel.fVirt & FCONTROL) 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) modifiers |= EF_CONTROL_DOWN; 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (accel.fVirt & FALT) 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) modifiers |= EF_ALT_DOWN; 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return modifiers; 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int GetModifiersFromKeyState() { 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int modifiers = EF_NONE; 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::IsShiftPressed()) 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) modifiers |= EF_SHIFT_DOWN; 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::IsCtrlPressed()) 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) modifiers |= EF_CONTROL_DOWN; 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (base::win::IsAltPressed()) 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) modifiers |= EF_ALT_DOWN; 387424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (base::win::IsAltGrPressed()) 388424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) modifiers |= EF_ALTGR_DOWN; 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return modifiers; 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Windows emulates mouse messages for touch events. 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsMouseEventFromTouch(UINT message) { 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return (message >= WM_MOUSEFIRST) && (message <= WM_MOUSELAST) && 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MOUSEEVENTF_FROMTOUCH; 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 399a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Conversion scan_code and LParam each other. 400a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// uint16 scan_code: 401a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// ui/events/keycodes/dom4/keycode_converter_data.h 402a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 0 - 15bits: represetns the scan code. 403a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 28 - 30 bits (0xE000): represents whether this is an extended key or not. 404a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 405a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// LPARAM lParam: 406a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644984.aspx 407a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 16 - 23bits: represetns the scan code. 408a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// 24bit (0x0100): represents whether this is an extended key or not. 409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)uint16 GetScanCodeFromLParam(LPARAM l_param) { 410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) uint16 scan_code = ((l_param >> 16) & 0x00FF); 411a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (l_param & (1 << 24)) 412a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scan_code |= 0xE000; 413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return scan_code; 414a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 415a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 416a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)LPARAM GetLParamFromScanCode(uint16 scan_code) { 417a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) LPARAM l_param = static_cast<LPARAM>(scan_code & 0x00FF) << 16; 418a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if ((scan_code & 0xE000) == 0xE000) 419a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) l_param |= (1 << 24); 420a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return l_param; 421a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 422a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 424