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/events/event_constants.h" | 7 #include "ui/events/event_constants.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 bool IsKeyEvent(const base::NativeEvent& native_event) { | 85 bool IsKeyEvent(const base::NativeEvent& native_event) { |
86 return native_event.message == WM_KEYDOWN || | 86 return native_event.message == WM_KEYDOWN || |
87 native_event.message == WM_SYSKEYDOWN || | 87 native_event.message == WM_SYSKEYDOWN || |
88 native_event.message == WM_CHAR || | 88 native_event.message == WM_CHAR || |
89 native_event.message == WM_KEYUP || | 89 native_event.message == WM_KEYUP || |
90 native_event.message == WM_SYSKEYUP; | 90 native_event.message == WM_SYSKEYUP; |
91 } | 91 } |
92 | 92 |
| 93 bool IsScrollEvent(const base::NativeEvent& native_event) { |
| 94 return native_event.message == WM_VSCROLL || |
| 95 native_event.message == WM_HSCROLL; |
| 96 } |
| 97 |
93 // Returns a mask corresponding to the set of pressed modifier keys. | 98 // Returns a mask corresponding to the set of pressed modifier keys. |
94 // Checks the current global state and the state sent by client mouse messages. | 99 // Checks the current global state and the state sent by client mouse messages. |
95 int KeyStateFlagsFromNative(const base::NativeEvent& native_event) { | 100 int KeyStateFlagsFromNative(const base::NativeEvent& native_event) { |
96 int flags = 0; | 101 int flags = 0; |
97 flags |= base::win::IsAltPressed() ? EF_ALT_DOWN : EF_NONE; | 102 flags |= base::win::IsAltPressed() ? EF_ALT_DOWN : EF_NONE; |
98 flags |= base::win::IsShiftPressed() ? EF_SHIFT_DOWN : EF_NONE; | 103 flags |= base::win::IsShiftPressed() ? EF_SHIFT_DOWN : EF_NONE; |
99 flags |= base::win::IsCtrlPressed() ? EF_CONTROL_DOWN : EF_NONE; | 104 flags |= base::win::IsCtrlPressed() ? EF_CONTROL_DOWN : EF_NONE; |
100 | 105 |
101 // Check key messages for the extended key flag. | 106 // Check key messages for the extended key flag. |
102 if (IsKeyEvent(native_event)) | 107 if (IsKeyEvent(native_event)) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return ET_MOUSE_RELEASED; | 177 return ET_MOUSE_RELEASED; |
173 case WM_MOUSEMOVE: | 178 case WM_MOUSEMOVE: |
174 return IsButtonDown(native_event) ? ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; | 179 return IsButtonDown(native_event) ? ET_MOUSE_DRAGGED : ET_MOUSE_MOVED; |
175 case WM_NCMOUSEMOVE: | 180 case WM_NCMOUSEMOVE: |
176 return ET_MOUSE_MOVED; | 181 return ET_MOUSE_MOVED; |
177 case WM_MOUSEWHEEL: | 182 case WM_MOUSEWHEEL: |
178 return ET_MOUSEWHEEL; | 183 return ET_MOUSEWHEEL; |
179 case WM_MOUSELEAVE: | 184 case WM_MOUSELEAVE: |
180 case WM_NCMOUSELEAVE: | 185 case WM_NCMOUSELEAVE: |
181 return ET_MOUSE_EXITED; | 186 return ET_MOUSE_EXITED; |
| 187 case WM_VSCROLL: |
| 188 case WM_HSCROLL: |
| 189 return ET_SCROLL; |
182 default: | 190 default: |
183 // We can't NOTREACHED() here, since this function can be called for any | 191 // We can't NOTREACHED() here, since this function can be called for any |
184 // message. | 192 // message. |
185 break; | 193 break; |
186 } | 194 } |
187 return ET_UNKNOWN; | 195 return ET_UNKNOWN; |
188 } | 196 } |
189 | 197 |
190 int EventFlagsFromNative(const base::NativeEvent& native_event) { | 198 int EventFlagsFromNative(const base::NativeEvent& native_event) { |
191 int flags = KeyStateFlagsFromNative(native_event); | 199 int flags = KeyStateFlagsFromNative(native_event); |
192 if (IsMouseEvent(native_event)) | 200 if (IsMouseEvent(native_event)) |
193 flags |= MouseStateFlagsFromNative(native_event); | 201 flags |= MouseStateFlagsFromNative(native_event); |
194 | 202 |
195 return flags; | 203 return flags; |
196 } | 204 } |
197 | 205 |
198 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { | 206 base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) { |
199 return base::TimeDelta::FromMilliseconds(native_event.time); | 207 return base::TimeDelta::FromMilliseconds(native_event.time); |
200 } | 208 } |
201 | 209 |
202 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 210 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
203 // Note: Wheel events are considered client, but their position is in screen | 211 // Note: Wheel events are considered client, but their position is in screen |
204 // coordinates. | 212 // coordinates. |
205 // Client message. The position is contained in the LPARAM. | 213 // Client message. The position is contained in the LPARAM. |
206 if (IsClientMouseEvent(native_event) && !IsMouseWheelEvent(native_event)) | 214 if (IsClientMouseEvent(native_event) && !IsMouseWheelEvent(native_event)) |
207 return gfx::Point(native_event.lParam); | 215 return gfx::Point(native_event.lParam); |
208 DCHECK(IsNonClientMouseEvent(native_event) || | 216 DCHECK(IsNonClientMouseEvent(native_event) || |
209 IsMouseWheelEvent(native_event)); | 217 IsMouseWheelEvent(native_event) || IsScrollEvent(native_event)); |
210 // Non-client message. The position is contained in a POINTS structure in | 218 POINT native_point; |
211 // LPARAM, and is in screen coordinates so we have to convert to client. | 219 if (IsScrollEvent(native_event)) { |
212 POINT native_point = { GET_X_LPARAM(native_event.lParam), | 220 ::GetCursorPos(&native_point); |
213 GET_Y_LPARAM(native_event.lParam) }; | 221 } else { |
| 222 // Non-client message. The position is contained in a POINTS structure in |
| 223 // LPARAM, and is in screen coordinates so we have to convert to client. |
| 224 native_point.x = GET_X_LPARAM(native_event.lParam); |
| 225 native_point.y = GET_Y_LPARAM(native_event.lParam); |
| 226 } |
214 ScreenToClient(native_event.hwnd, &native_point); | 227 ScreenToClient(native_event.hwnd, &native_point); |
215 gfx::Point location(native_point); | 228 gfx::Point location(native_point); |
216 location = gfx::win::ScreenToDIPPoint(location); | 229 location = gfx::win::ScreenToDIPPoint(location); |
217 return location; | 230 return location; |
218 } | 231 } |
219 | 232 |
220 gfx::Point EventSystemLocationFromNative( | 233 gfx::Point EventSystemLocationFromNative( |
221 const base::NativeEvent& native_event) { | 234 const base::NativeEvent& native_event) { |
222 // TODO(ben): Needs to always return screen position here. Returning normal | 235 // TODO(ben): Needs to always return screen position here. Returning normal |
223 // origin for now since that's obviously wrong. | 236 // origin for now since that's obviously wrong. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 NOTIMPLEMENTED(); | 300 NOTIMPLEMENTED(); |
288 return 0.0; | 301 return 0.0; |
289 } | 302 } |
290 | 303 |
291 bool GetScrollOffsets(const base::NativeEvent& native_event, | 304 bool GetScrollOffsets(const base::NativeEvent& native_event, |
292 float* x_offset, | 305 float* x_offset, |
293 float* y_offset, | 306 float* y_offset, |
294 float* x_offset_ordinal, | 307 float* x_offset_ordinal, |
295 float* y_offset_ordinal, | 308 float* y_offset_ordinal, |
296 int* finger_count) { | 309 int* finger_count) { |
297 // Not supported in Windows. | 310 // TODO(ananta) |
298 NOTIMPLEMENTED(); | 311 // Support retrieving the scroll offsets from the scroll event. |
| 312 if (native_event.message == WM_VSCROLL || native_event.message == WM_HSCROLL) |
| 313 return true; |
299 return false; | 314 return false; |
300 } | 315 } |
301 | 316 |
302 bool GetFlingData(const base::NativeEvent& native_event, | 317 bool GetFlingData(const base::NativeEvent& native_event, |
303 float* vx, | 318 float* vx, |
304 float* vy, | 319 float* vy, |
305 float* vx_ordinal, | 320 float* vx_ordinal, |
306 float* vy_ordinal, | 321 float* vy_ordinal, |
307 bool* is_cancel) { | 322 bool* is_cancel) { |
308 // Not supported in Windows. | 323 // Not supported in Windows. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 407 } |
393 | 408 |
394 LPARAM GetLParamFromScanCode(uint16 scan_code) { | 409 LPARAM GetLParamFromScanCode(uint16 scan_code) { |
395 LPARAM l_param = static_cast<LPARAM>(scan_code & 0x00FF) << 16; | 410 LPARAM l_param = static_cast<LPARAM>(scan_code & 0x00FF) << 16; |
396 if ((scan_code & 0xE000) == 0xE000) | 411 if ((scan_code & 0xE000) == 0xE000) |
397 l_param |= (1 << 24); | 412 l_param |= (1 << 24); |
398 return l_param; | 413 return l_param; |
399 } | 414 } |
400 | 415 |
401 } // namespace ui | 416 } // namespace ui |
OLD | NEW |