OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/views/events/event.h" | 5 #include "ui/views/events/event.h" |
6 | 6 |
7 #include <windowsx.h> | 7 #include <windowsx.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 10 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Returns a mask corresponding to the set of modifier keys that are currently | 16 // Returns a mask corresponding to the set of modifier keys that are currently |
17 // pressed. Windows key messages don't come with control key state as parameters | 17 // pressed. Windows key messages don't come with control key state as parameters |
18 // as with mouse messages, so we need to explicitly ask for these states. | 18 // as with mouse messages, so we need to explicitly ask for these states. |
19 int GetKeyStateFlags() { | 19 int GetKeyStateFlags() { |
20 int flags = 0; | 20 int flags = 0; |
21 if (GetKeyState(VK_MENU) & 0x80) | 21 flags |= (GetKeyState(VK_MENU) & 0x80)? ui::EF_ALT_DOWN : 0; |
22 flags |= ui::Event::EF_ALT_DOWN; | 22 flags |= (GetKeyState(VK_SHIFT) & 0x80)? ui::EF_SHIFT_DOWN : 0; |
23 if (GetKeyState(VK_SHIFT) & 0x80) | 23 flags |= (GetKeyState(VK_CONTROL) & 0x80)? ui::EF_CONTROL_DOWN : 0; |
24 flags |= ui::Event::EF_SHIFT_DOWN; | |
25 if (GetKeyState(VK_CONTROL) & 0x80) | |
26 flags |= ui::Event::EF_CONTROL_DOWN; | |
27 return flags; | 24 return flags; |
28 } | 25 } |
29 | 26 |
30 // Convert windows message identifiers to Event types. | 27 // Convert windows message identifiers to Event types. |
31 ui::Event::EventType EventTypeFromNative(NativeEvent native_event) { | 28 ui::Event::EventType EventTypeFromNative(NativeEvent native_event) { |
32 switch (native_event.message) { | 29 switch (native_event.message) { |
33 case WM_KEYDOWN: | 30 case WM_KEYDOWN: |
34 case WM_SYSKEYDOWN: | 31 case WM_SYSKEYDOWN: |
| 32 case WM_CHAR: |
35 return ui::Event::ET_KEY_PRESSED; | 33 return ui::Event::ET_KEY_PRESSED; |
36 case WM_KEYUP: | 34 case WM_KEYUP: |
37 case WM_SYSKEYUP: | 35 case WM_SYSKEYUP: |
38 return ui::Event::ET_KEY_RELEASED; | 36 return ui::Event::ET_KEY_RELEASED; |
39 case WM_LBUTTONDOWN: | 37 case WM_LBUTTONDOWN: |
40 case WM_MBUTTONDOWN: | 38 case WM_MBUTTONDOWN: |
41 case WM_NCLBUTTONDOWN: | 39 case WM_NCLBUTTONDOWN: |
42 case WM_NCMBUTTONDOWN: | 40 case WM_NCMBUTTONDOWN: |
43 case WM_NCRBUTTONDOWN: | 41 case WM_NCRBUTTONDOWN: |
44 case WM_RBUTTONDOWN: | 42 case WM_RBUTTONDOWN: |
(...skipping 20 matching lines...) Expand all Loading... |
65 case WM_NCMOUSELEAVE: | 63 case WM_NCMOUSELEAVE: |
66 return ui::Event::ET_MOUSE_EXITED; | 64 return ui::Event::ET_MOUSE_EXITED; |
67 default: | 65 default: |
68 NOTREACHED(); | 66 NOTREACHED(); |
69 } | 67 } |
70 return ui::Event::ET_UNKNOWN; | 68 return ui::Event::ET_UNKNOWN; |
71 } | 69 } |
72 | 70 |
73 bool IsClientMouseEvent(NativeEvent native_event) { | 71 bool IsClientMouseEvent(NativeEvent native_event) { |
74 return native_event.message == WM_MOUSELEAVE || | 72 return native_event.message == WM_MOUSELEAVE || |
| 73 native_event.message == WM_MOUSEHOVER || |
75 (native_event.message >= WM_MOUSEFIRST && | 74 (native_event.message >= WM_MOUSEFIRST && |
76 native_event.message <= WM_MOUSELAST); | 75 native_event.message <= WM_MOUSELAST); |
77 } | 76 } |
78 | 77 |
79 bool IsNonClientMouseEvent(NativeEvent native_event) { | 78 bool IsNonClientMouseEvent(NativeEvent native_event) { |
80 return native_event.message == WM_NCMOUSELEAVE || | 79 return native_event.message == WM_NCMOUSELEAVE || |
| 80 native_event.message == WM_NCMOUSEHOVER || |
81 (native_event.message >= WM_NCMOUSEMOVE && | 81 (native_event.message >= WM_NCMOUSEMOVE && |
82 native_event.message <= WM_NCMBUTTONDBLCLK); | 82 native_event.message <= WM_NCXBUTTONDBLCLK); |
83 } | 83 } |
84 | 84 |
85 gfx::Point MousePositionFromNative(NativeEvent native_event) { | 85 gfx::Point MousePositionFromNative(NativeEvent native_event) { |
86 if (IsClientMouseEvent(native_event)) { | 86 // Client message. The position is contained in the LPARAM. |
87 // Client message. The position is contained in the LPARAM. | 87 if (IsClientMouseEvent(native_event)) |
88 return gfx::Point(GET_X_LPARAM(native_event.lParam), | 88 return gfx::Point(native_event.lParam); |
89 GET_Y_LPARAM(native_event.lParam)); | |
90 } | |
91 DCHECK(IsNonClientMouseEvent(native_event)); | 89 DCHECK(IsNonClientMouseEvent(native_event)); |
92 // Non-client message. The position is contained in a POINTS structure in | 90 // Non-client message. The position is contained in a POINTS structure in |
93 // LPARAM, and is in screen coordinates so we have to convert to client. | 91 // LPARAM, and is in screen coordinates so we have to convert to client. |
94 POINT native_point = { GET_X_LPARAM(native_event.lParam), | 92 POINT native_point = { GET_X_LPARAM(native_event.lParam), |
95 GET_Y_LPARAM(native_event.lParam) }; | 93 GET_Y_LPARAM(native_event.lParam) }; |
96 ScreenToClient(native_event.hwnd, &native_point); | 94 ScreenToClient(native_event.hwnd, &native_point); |
97 return gfx::Point(native_point); | 95 return gfx::Point(native_point); |
98 } | 96 } |
99 | 97 |
100 int MouseEventFlagsFromNative(NativeEvent native_event) { | 98 int MouseEventFlagsFromNative(NativeEvent native_event) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN; | 134 flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN; |
137 break; | 135 break; |
138 } | 136 } |
139 } | 137 } |
140 | 138 |
141 // Finally make sure the key state flags are included. | 139 // Finally make sure the key state flags are included. |
142 return flags | GetKeyStateFlags(); | 140 return flags | GetKeyStateFlags(); |
143 } | 141 } |
144 | 142 |
145 int MouseWheelEventFlagsFromNative(NativeEvent native_event) { | 143 int MouseWheelEventFlagsFromNative(NativeEvent native_event) { |
146 int native_flags = GET_KEYSTATE_WPARAM(native_event.wParam); | 144 int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam); |
147 int flags = 0; | 145 int flags = 0; |
148 if (native_flags & MK_CONTROL) | 146 flags |= (win_flags & MK_CONTROL) ? ui::MouseEvent::EF_CONTROL_DOWN : 0; |
149 flags |= ui::Event::EF_CONTROL_DOWN; | 147 flags |= (win_flags & MK_SHIFT) ? ui::MouseEvent::EF_SHIFT_DOWN : 0; |
150 if (native_flags & MK_SHIFT) | 148 flags |= (GetKeyState(VK_MENU) < 0) ? ui::MouseEvent::EF_ALT_DOWN : 0; |
151 flags |= ui::Event::EF_SHIFT_DOWN; | 149 flags |= (win_flags & MK_LBUTTON) ? ui::MouseEvent::EF_LEFT_BUTTON_DOWN : 0; |
152 if (GetKeyState(VK_MENU) < 0) | 150 flags |= (win_flags & MK_MBUTTON) ? ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN : 0; |
153 flags |= ui::Event::EF_ALT_DOWN; | 151 flags |= (win_flags & MK_RBUTTON) ? ui::MouseEvent::EF_RIGHT_BUTTON_DOWN : 0; |
154 if (native_flags & MK_LBUTTON) | |
155 flags |= ui::Event::EF_LEFT_BUTTON_DOWN; | |
156 if (native_flags & MK_MBUTTON) | |
157 flags |= ui::Event::EF_MIDDLE_BUTTON_DOWN; | |
158 if (native_flags & MK_RBUTTON) | |
159 flags |= ui::Event::EF_RIGHT_BUTTON_DOWN; | |
160 return flags; | 152 return flags; |
161 } | 153 } |
162 | 154 |
163 } // namespace | 155 } // namespace |
164 | 156 |
165 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
166 // KeyEvent, public: | 158 // KeyEvent, public: |
167 | 159 |
168 KeyEvent::KeyEvent(NativeEvent native_event) | 160 KeyEvent::KeyEvent(NativeEvent native_event) |
169 : Event(EventTypeFromNative(native_event), GetKeyStateFlags()), | 161 : Event(EventTypeFromNative(native_event), GetKeyStateFlags()), |
(...skipping 16 matching lines...) Expand all Loading... |
186 | 178 |
187 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) | 179 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) |
188 : LocatedEvent(ET_MOUSEWHEEL, | 180 : LocatedEvent(ET_MOUSEWHEEL, |
189 MousePositionFromNative(native_event), | 181 MousePositionFromNative(native_event), |
190 MouseWheelEventFlagsFromNative(native_event)), | 182 MouseWheelEventFlagsFromNative(native_event)), |
191 offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) { | 183 offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) { |
192 } | 184 } |
193 | 185 |
194 } // namespace ui | 186 } // namespace ui |
195 | 187 |
OLD | NEW |