| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 NOTIMPLEMENTED(); | 295 NOTIMPLEMENTED(); |
| 283 return 0.0; | 296 return 0.0; |
| 284 } | 297 } |
| 285 | 298 |
| 286 bool GetScrollOffsets(const base::NativeEvent& native_event, | 299 bool GetScrollOffsets(const base::NativeEvent& native_event, |
| 287 float* x_offset, | 300 float* x_offset, |
| 288 float* y_offset, | 301 float* y_offset, |
| 289 float* x_offset_ordinal, | 302 float* x_offset_ordinal, |
| 290 float* y_offset_ordinal, | 303 float* y_offset_ordinal, |
| 291 int* finger_count) { | 304 int* finger_count) { |
| 292 // Not supported in Windows. | 305 // TODO(ananta) |
| 293 NOTIMPLEMENTED(); | 306 // Support retrieving the scroll offsets from the scroll event. |
| 307 if (native_event.message == WM_VSCROLL || native_event.message == WM_HSCROLL) |
| 308 return true; |
| 294 return false; | 309 return false; |
| 295 } | 310 } |
| 296 | 311 |
| 297 bool GetFlingData(const base::NativeEvent& native_event, | 312 bool GetFlingData(const base::NativeEvent& native_event, |
| 298 float* vx, | 313 float* vx, |
| 299 float* vy, | 314 float* vy, |
| 300 float* vx_ordinal, | 315 float* vx_ordinal, |
| 301 float* vy_ordinal, | 316 float* vy_ordinal, |
| 302 bool* is_cancel) { | 317 bool* is_cancel) { |
| 303 // Not supported in Windows. | 318 // Not supported in Windows. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 378 } |
| 364 | 379 |
| 365 // Windows emulates mouse messages for touch events. | 380 // Windows emulates mouse messages for touch events. |
| 366 bool IsMouseEventFromTouch(UINT message) { | 381 bool IsMouseEventFromTouch(UINT message) { |
| 367 return (message >= WM_MOUSEFIRST) && (message <= WM_MOUSELAST) && | 382 return (message >= WM_MOUSEFIRST) && (message <= WM_MOUSELAST) && |
| 368 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == | 383 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == |
| 369 MOUSEEVENTF_FROMTOUCH; | 384 MOUSEEVENTF_FROMTOUCH; |
| 370 } | 385 } |
| 371 | 386 |
| 372 } // namespace ui | 387 } // namespace ui |
| OLD | NEW |