OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windowsx.h> | 5 #include <windowsx.h> |
6 | 6 |
7 #include "ui/base/events.h" | 7 #include "ui/base/events.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/win/win_util.h" | 11 #include "base/win/win_util.h" |
12 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 12 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
13 #include "ui/gfx/point.h" | 13 #include "ui/gfx/point.h" |
14 | 14 |
| 15 namespace ui { |
| 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // From MSDN. | 19 // From MSDN. |
18 #define MOUSEEVENTF_FROMTOUCH 0xFF515700 | 20 #define MOUSEEVENTF_FROMTOUCH 0xFF515700 |
19 | 21 |
20 // Get the native mouse key state from the native event message type. | 22 // Get the native mouse key state from the native event message type. |
21 int GetNativeMouseKey(const base::NativeEvent& native_event) { | 23 int GetNativeMouseKey(const base::NativeEvent& native_event) { |
22 switch (native_event.message) { | 24 switch (native_event.message) { |
23 case WM_LBUTTONDBLCLK: | 25 case WM_LBUTTONDBLCLK: |
24 case WM_LBUTTONDOWN: | 26 case WM_LBUTTONDOWN: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 native_event.message == WM_SYSKEYDOWN || | 83 native_event.message == WM_SYSKEYDOWN || |
82 native_event.message == WM_CHAR || | 84 native_event.message == WM_CHAR || |
83 native_event.message == WM_KEYUP || | 85 native_event.message == WM_KEYUP || |
84 native_event.message == WM_SYSKEYUP; | 86 native_event.message == WM_SYSKEYUP; |
85 } | 87 } |
86 | 88 |
87 // Returns a mask corresponding to the set of pressed modifier keys. | 89 // Returns a mask corresponding to the set of pressed modifier keys. |
88 // Checks the current global state and the state sent by client mouse messages. | 90 // Checks the current global state and the state sent by client mouse messages. |
89 int KeyStateFlagsFromNative(const base::NativeEvent& native_event) { | 91 int KeyStateFlagsFromNative(const base::NativeEvent& native_event) { |
90 int flags = 0; | 92 int flags = 0; |
91 flags |= base::win::IsAltPressed() ? ui::EF_ALT_DOWN : ui::EF_NONE; | 93 flags |= base::win::IsAltPressed() ? EF_ALT_DOWN : EF_NONE; |
92 flags |= base::win::IsShiftPressed() ? ui::EF_SHIFT_DOWN : ui::EF_NONE; | 94 flags |= base::win::IsShiftPressed() ? EF_SHIFT_DOWN : EF_NONE; |
93 flags |= base::win::IsCtrlPressed() ? ui::EF_CONTROL_DOWN : ui::EF_NONE; | 95 flags |= base::win::IsCtrlPressed() ? EF_CONTROL_DOWN : EF_NONE; |
94 | 96 |
95 // Check key messages for the extended key flag. | 97 // Check key messages for the extended key flag. |
96 if (IsKeyEvent(native_event)) | 98 if (IsKeyEvent(native_event)) |
97 flags |= (HIWORD(native_event.lParam) & KF_EXTENDED) ? ui::EF_EXTENDED : 0; | 99 flags |= (HIWORD(native_event.lParam) & KF_EXTENDED) ? EF_EXTENDED : 0; |
98 | 100 |
99 // Most client mouse messages include key state information. | 101 // Most client mouse messages include key state information. |
100 if (IsClientMouseEvent(native_event)) { | 102 if (IsClientMouseEvent(native_event)) { |
101 int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam); | 103 int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam); |
102 flags |= (win_flags & MK_SHIFT) ? ui::EF_SHIFT_DOWN : 0; | 104 flags |= (win_flags & MK_SHIFT) ? EF_SHIFT_DOWN : 0; |
103 flags |= (win_flags & MK_CONTROL) ? ui::EF_CONTROL_DOWN : 0; | 105 flags |= (win_flags & MK_CONTROL) ? EF_CONTROL_DOWN : 0; |
104 } | 106 } |
105 | 107 |
106 return flags; | 108 return flags; |
107 } | 109 } |
108 | 110 |
109 // Returns a mask corresponding to the set of pressed mouse buttons. | 111 // Returns a mask corresponding to the set of pressed mouse buttons. |
110 // This includes the button of the given message, even if it is being released. | 112 // This includes the button of the given message, even if it is being released. |
111 int MouseStateFlagsFromNative(const base::NativeEvent& native_event) { | 113 int MouseStateFlagsFromNative(const base::NativeEvent& native_event) { |
112 // TODO(msw): ORing the pressed/released button into the flags is _wrong_. | 114 // TODO(msw): ORing the pressed/released button into the flags is _wrong_. |
113 // It makes it impossible to tell which button was modified when multiple | 115 // It makes it impossible to tell which button was modified when multiple |
114 // buttons are/were held down. Instead, we need to track the modified button | 116 // buttons are/were held down. Instead, we need to track the modified button |
115 // independently and audit event consumers to do the right thing. | 117 // independently and audit event consumers to do the right thing. |
116 int win_flags = GetNativeMouseKey(native_event); | 118 int win_flags = GetNativeMouseKey(native_event); |
117 | 119 |
118 // Client mouse messages provide key states in their WPARAMs. | 120 // Client mouse messages provide key states in their WPARAMs. |
119 if (IsClientMouseEvent(native_event)) | 121 if (IsClientMouseEvent(native_event)) |
120 win_flags |= GET_KEYSTATE_WPARAM(native_event.wParam); | 122 win_flags |= GET_KEYSTATE_WPARAM(native_event.wParam); |
121 | 123 |
122 int flags = 0; | 124 int flags = 0; |
123 flags |= (win_flags & MK_LBUTTON) ? ui::EF_LEFT_MOUSE_BUTTON : 0; | 125 flags |= (win_flags & MK_LBUTTON) ? EF_LEFT_MOUSE_BUTTON : 0; |
124 flags |= (win_flags & MK_MBUTTON) ? ui::EF_MIDDLE_MOUSE_BUTTON : 0; | 126 flags |= (win_flags & MK_MBUTTON) ? EF_MIDDLE_MOUSE_BUTTON : 0; |
125 flags |= (win_flags & MK_RBUTTON) ? ui::EF_RIGHT_MOUSE_BUTTON : 0; | 127 flags |= (win_flags & MK_RBUTTON) ? EF_RIGHT_MOUSE_BUTTON : 0; |
126 flags |= IsNonClientMouseEvent(native_event) ? ui::EF_IS_NON_CLIENT : 0; | 128 flags |= IsNonClientMouseEvent(native_event) ? EF_IS_NON_CLIENT : 0; |
127 return flags; | 129 return flags; |
128 } | 130 } |
129 | 131 |
130 } // namespace | 132 } // namespace |
131 | 133 |
132 namespace ui { | |
133 | |
134 void UpdateDeviceList() { | 134 void UpdateDeviceList() { |
135 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
136 } | 136 } |
137 | 137 |
138 EventType EventTypeFromNative(const base::NativeEvent& native_event) { | 138 EventType EventTypeFromNative(const base::NativeEvent& native_event) { |
139 switch (native_event.message) { | 139 switch (native_event.message) { |
140 case WM_KEYDOWN: | 140 case WM_KEYDOWN: |
141 case WM_SYSKEYDOWN: | 141 case WM_SYSKEYDOWN: |
142 case WM_CHAR: | 142 case WM_CHAR: |
143 return ET_KEY_PRESSED; | 143 return ET_KEY_PRESSED; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 return event.message == WM_USER + 310; | 298 return event.message == WM_USER + 310; |
299 } | 299 } |
300 | 300 |
301 base::NativeEvent CreateNoopEvent() { | 301 base::NativeEvent CreateNoopEvent() { |
302 MSG event = { NULL }; | 302 MSG event = { NULL }; |
303 event.message = WM_USER + 310; | 303 event.message = WM_USER + 310; |
304 return event; | 304 return event; |
305 } | 305 } |
306 | 306 |
307 int GetModifiersFromACCEL(const ACCEL& accel) { | 307 int GetModifiersFromACCEL(const ACCEL& accel) { |
308 int modifiers = ui::EF_NONE; | 308 int modifiers = EF_NONE; |
309 if (accel.fVirt & FSHIFT) | 309 if (accel.fVirt & FSHIFT) |
310 modifiers |= ui::EF_SHIFT_DOWN; | 310 modifiers |= EF_SHIFT_DOWN; |
311 if (accel.fVirt & FCONTROL) | 311 if (accel.fVirt & FCONTROL) |
312 modifiers |= ui::EF_CONTROL_DOWN; | 312 modifiers |= EF_CONTROL_DOWN; |
313 if (accel.fVirt & FALT) | 313 if (accel.fVirt & FALT) |
314 modifiers |= ui::EF_ALT_DOWN; | 314 modifiers |= EF_ALT_DOWN; |
| 315 return modifiers; |
| 316 } |
| 317 |
| 318 int GetModifiersFromKeyState() { |
| 319 int modifiers = EF_NONE; |
| 320 if (base::win::IsShiftPressed()) |
| 321 modifiers |= EF_SHIFT_DOWN; |
| 322 if (base::win::IsCtrlPressed()) |
| 323 modifiers |= EF_CONTROL_DOWN; |
| 324 if (base::win::IsAltPressed()) |
| 325 modifiers |= EF_ALT_DOWN; |
315 return modifiers; | 326 return modifiers; |
316 } | 327 } |
317 | 328 |
318 // Windows emulates mouse messages for touch events. | 329 // Windows emulates mouse messages for touch events. |
319 bool IsMouseEventFromTouch(UINT message) { | 330 bool IsMouseEventFromTouch(UINT message) { |
320 return (message == WM_MOUSEMOVE || | 331 return (message == WM_MOUSEMOVE || |
321 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || | 332 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || |
322 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && | 333 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && |
323 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == | 334 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == |
324 MOUSEEVENTF_FROMTOUCH; | 335 MOUSEEVENTF_FROMTOUCH; |
325 } | 336 } |
326 | 337 |
327 } // namespace ui | 338 } // namespace ui |
OLD | NEW |