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 default: | |
msw
2012/08/16 23:42:33
Oops, one nit: maybe add a TODO to support MK_XBUT
| |
233 break; | |
234 } | |
230 return 0; | 235 return 0; |
231 } | 236 } |
232 | 237 |
233 int GetMouseWheelOffset(const base::NativeEvent& native_event) { | 238 int GetMouseWheelOffset(const base::NativeEvent& native_event) { |
234 DCHECK(native_event.message == WM_MOUSEWHEEL); | 239 DCHECK(native_event.message == WM_MOUSEWHEEL); |
235 return GET_WHEEL_DELTA_WPARAM(native_event.wParam); | 240 return GET_WHEEL_DELTA_WPARAM(native_event.wParam); |
236 } | 241 } |
237 | 242 |
238 int GetTouchId(const base::NativeEvent& xev) { | 243 int GetTouchId(const base::NativeEvent& xev) { |
239 NOTIMPLEMENTED(); | 244 NOTIMPLEMENTED(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 // Windows emulates mouse messages for touch events. | 340 // Windows emulates mouse messages for touch events. |
336 bool IsMouseEventFromTouch(UINT message) { | 341 bool IsMouseEventFromTouch(UINT message) { |
337 return (message == WM_MOUSEMOVE || | 342 return (message == WM_MOUSEMOVE || |
338 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || | 343 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || |
339 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && | 344 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && |
340 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == | 345 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == |
341 MOUSEEVENTF_FROMTOUCH; | 346 MOUSEEVENTF_FROMTOUCH; |
342 } | 347 } |
343 | 348 |
344 } // namespace ui | 349 } // namespace ui |
OLD | NEW |