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" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 flags |= (win_flags & MK_SHIFT) ? EF_SHIFT_DOWN : 0; | 104 flags |= (win_flags & MK_SHIFT) ? EF_SHIFT_DOWN : 0; |
105 flags |= (win_flags & MK_CONTROL) ? EF_CONTROL_DOWN : 0; | 105 flags |= (win_flags & MK_CONTROL) ? EF_CONTROL_DOWN : 0; |
106 } | 106 } |
107 | 107 |
108 return flags; | 108 return flags; |
109 } | 109 } |
110 | 110 |
111 // Returns a mask corresponding to the set of pressed mouse buttons. | 111 // Returns a mask corresponding to the set of pressed mouse buttons. |
112 // 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. |
113 int MouseStateFlagsFromNative(const base::NativeEvent& native_event) { | 113 int MouseStateFlagsFromNative(const base::NativeEvent& native_event) { |
114 // TODO(msw): ORing the pressed/released button into the flags is _wrong_. | |
115 // It makes it impossible to tell which button was modified when multiple | |
116 // buttons are/were held down. Instead, we need to track the modified button | |
117 // independently and audit event consumers to do the right thing. | |
118 int win_flags = GetNativeMouseKey(native_event); | 114 int win_flags = GetNativeMouseKey(native_event); |
119 | 115 |
120 // Client mouse messages provide key states in their WPARAMs. | 116 // Client mouse messages provide key states in their WPARAMs. |
121 if (IsClientMouseEvent(native_event)) | 117 if (IsClientMouseEvent(native_event)) |
122 win_flags |= GET_KEYSTATE_WPARAM(native_event.wParam); | 118 win_flags |= GET_KEYSTATE_WPARAM(native_event.wParam); |
123 | 119 |
124 int flags = 0; | 120 int flags = 0; |
125 flags |= (win_flags & MK_LBUTTON) ? EF_LEFT_MOUSE_BUTTON : 0; | 121 flags |= (win_flags & MK_LBUTTON) ? EF_LEFT_MOUSE_BUTTON : 0; |
126 flags |= (win_flags & MK_MBUTTON) ? EF_MIDDLE_MOUSE_BUTTON : 0; | 122 flags |= (win_flags & MK_MBUTTON) ? EF_MIDDLE_MOUSE_BUTTON : 0; |
127 flags |= (win_flags & MK_RBUTTON) ? EF_RIGHT_MOUSE_BUTTON : 0; | 123 flags |= (win_flags & MK_RBUTTON) ? EF_RIGHT_MOUSE_BUTTON : 0; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return KeyboardCodeForWindowsKeyCode(native_event.wParam); | 215 return KeyboardCodeForWindowsKeyCode(native_event.wParam); |
220 } | 216 } |
221 | 217 |
222 bool IsMouseEvent(const base::NativeEvent& native_event) { | 218 bool IsMouseEvent(const base::NativeEvent& native_event) { |
223 return IsClientMouseEvent(native_event) || | 219 return IsClientMouseEvent(native_event) || |
224 IsNonClientMouseEvent(native_event); | 220 IsNonClientMouseEvent(native_event); |
225 } | 221 } |
226 | 222 |
227 int GetChangedMouseButtonFlagsFromNative( | 223 int GetChangedMouseButtonFlagsFromNative( |
228 const base::NativeEvent& native_event) { | 224 const base::NativeEvent& native_event) { |
229 // TODO(sky): implement me. | 225 switch (GetNativeMouseKey(native_event)) { |
| 226 case MK_LBUTTON: |
| 227 return EF_LEFT_MOUSE_BUTTON; |
| 228 case MK_MBUTTON: |
| 229 return EF_MIDDLE_MOUSE_BUTTON; |
| 230 case MK_RBUTTON: |
| 231 return EF_RIGHT_MOUSE_BUTTON; |
| 232 // TODO: add support for MK_XBUTTON1. |
| 233 default: |
| 234 break; |
| 235 } |
230 return 0; | 236 return 0; |
231 } | 237 } |
232 | 238 |
233 int GetMouseWheelOffset(const base::NativeEvent& native_event) { | 239 int GetMouseWheelOffset(const base::NativeEvent& native_event) { |
234 DCHECK(native_event.message == WM_MOUSEWHEEL); | 240 DCHECK(native_event.message == WM_MOUSEWHEEL); |
235 return GET_WHEEL_DELTA_WPARAM(native_event.wParam); | 241 return GET_WHEEL_DELTA_WPARAM(native_event.wParam); |
236 } | 242 } |
237 | 243 |
238 int GetTouchId(const base::NativeEvent& xev) { | 244 int GetTouchId(const base::NativeEvent& xev) { |
239 NOTIMPLEMENTED(); | 245 NOTIMPLEMENTED(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // Windows emulates mouse messages for touch events. | 341 // Windows emulates mouse messages for touch events. |
336 bool IsMouseEventFromTouch(UINT message) { | 342 bool IsMouseEventFromTouch(UINT message) { |
337 return (message == WM_MOUSEMOVE || | 343 return (message == WM_MOUSEMOVE || |
338 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || | 344 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || |
339 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && | 345 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && |
340 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == | 346 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == |
341 MOUSEEVENTF_FROMTOUCH; | 347 MOUSEEVENTF_FROMTOUCH; |
342 } | 348 } |
343 | 349 |
344 } // namespace ui | 350 } // namespace ui |
OLD | NEW |