| 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 if (GetKeyState(VK_MENU) & 0x80) |
| 22 flags |= ui::EF_ALT_DOWN; | 22 flags |= ui::Event::EF_ALT_DOWN; |
| 23 if (GetKeyState(VK_SHIFT) & 0x80) | 23 if (GetKeyState(VK_SHIFT) & 0x80) |
| 24 flags |= ui::EF_SHIFT_DOWN; | 24 flags |= ui::Event::EF_SHIFT_DOWN; |
| 25 if (GetKeyState(VK_CONTROL) & 0x80) | 25 if (GetKeyState(VK_CONTROL) & 0x80) |
| 26 flags |= ui::EF_CONTROL_DOWN; | 26 flags |= ui::Event::EF_CONTROL_DOWN; |
| 27 return flags; | 27 return flags; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Convert windows message identifiers to Event types. | 30 // Convert windows message identifiers to Event types. |
| 31 ui::EventType EventTypeFromNative(NativeEvent native_event) { | 31 ui::Event::EventType EventTypeFromNative(NativeEvent native_event) { |
| 32 switch (native_event.message) { | 32 switch (native_event.message) { |
| 33 case WM_KEYDOWN: | 33 case WM_KEYDOWN: |
| 34 case WM_SYSKEYDOWN: | 34 case WM_SYSKEYDOWN: |
| 35 return ui::ET_KEY_PRESSED; | 35 return ui::Event::ET_KEY_PRESSED; |
| 36 case WM_KEYUP: | 36 case WM_KEYUP: |
| 37 case WM_SYSKEYUP: | 37 case WM_SYSKEYUP: |
| 38 return ui::ET_KEY_RELEASED; | 38 return ui::Event::ET_KEY_RELEASED; |
| 39 case WM_LBUTTONDOWN: | 39 case WM_LBUTTONDOWN: |
| 40 case WM_MBUTTONDOWN: | 40 case WM_MBUTTONDOWN: |
| 41 case WM_NCLBUTTONDOWN: | 41 case WM_NCLBUTTONDOWN: |
| 42 case WM_NCMBUTTONDOWN: | 42 case WM_NCMBUTTONDOWN: |
| 43 case WM_NCRBUTTONDOWN: | 43 case WM_NCRBUTTONDOWN: |
| 44 case WM_RBUTTONDOWN: | 44 case WM_RBUTTONDOWN: |
| 45 return ui::ET_MOUSE_PRESSED; | 45 return ui::Event::ET_MOUSE_PRESSED; |
| 46 case WM_LBUTTONDBLCLK: | 46 case WM_LBUTTONDBLCLK: |
| 47 case WM_LBUTTONUP: | 47 case WM_LBUTTONUP: |
| 48 case WM_MBUTTONDBLCLK: | 48 case WM_MBUTTONDBLCLK: |
| 49 case WM_MBUTTONUP: | 49 case WM_MBUTTONUP: |
| 50 case WM_NCLBUTTONDBLCLK: | 50 case WM_NCLBUTTONDBLCLK: |
| 51 case WM_NCLBUTTONUP: | 51 case WM_NCLBUTTONUP: |
| 52 case WM_NCMBUTTONDBLCLK: | 52 case WM_NCMBUTTONDBLCLK: |
| 53 case WM_NCMBUTTONUP: | 53 case WM_NCMBUTTONUP: |
| 54 case WM_NCRBUTTONDBLCLK: | 54 case WM_NCRBUTTONDBLCLK: |
| 55 case WM_NCRBUTTONUP: | 55 case WM_NCRBUTTONUP: |
| 56 case WM_RBUTTONDBLCLK: | 56 case WM_RBUTTONDBLCLK: |
| 57 case WM_RBUTTONUP: | 57 case WM_RBUTTONUP: |
| 58 return ui::ET_MOUSE_RELEASED; | 58 return ui::Event::ET_MOUSE_RELEASED; |
| 59 case WM_MOUSEMOVE: | 59 case WM_MOUSEMOVE: |
| 60 case WM_NCMOUSEMOVE: | 60 case WM_NCMOUSEMOVE: |
| 61 return ui::ET_MOUSE_MOVED; | 61 return ui::Event::ET_MOUSE_MOVED; |
| 62 case WM_MOUSEWHEEL: | 62 case WM_MOUSEWHEEL: |
| 63 return ui::ET_MOUSEWHEEL; | 63 return ui::Event::ET_MOUSEWHEEL; |
| 64 case WM_MOUSELEAVE: | 64 case WM_MOUSELEAVE: |
| 65 case WM_NCMOUSELEAVE: | 65 case WM_NCMOUSELEAVE: |
| 66 return ui::ET_MOUSE_EXITED; | 66 return ui::Event::ET_MOUSE_EXITED; |
| 67 default: | 67 default: |
| 68 NOTREACHED(); | 68 NOTREACHED(); |
| 69 } | 69 } |
| 70 return ui::ET_UNKNOWN; | 70 return ui::Event::ET_UNKNOWN; |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool IsClientMouseEvent(NativeEvent native_event) { | 73 bool IsClientMouseEvent(NativeEvent native_event) { |
| 74 return native_event.message == WM_MOUSELEAVE || | 74 return native_event.message == WM_MOUSELEAVE || |
| 75 (native_event.message >= WM_MOUSEFIRST && | 75 (native_event.message >= WM_MOUSEFIRST && |
| 76 native_event.message <= WM_MOUSELAST); | 76 native_event.message <= WM_MOUSELAST); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool IsNonClientMouseEvent(NativeEvent native_event) { | 79 bool IsNonClientMouseEvent(NativeEvent native_event) { |
| 80 return native_event.message == WM_NCMOUSELEAVE || | 80 return native_event.message == WM_NCMOUSELEAVE || |
| (...skipping 14 matching lines...) Expand all Loading... |
| 95 GET_Y_LPARAM(native_event.lParam) }; | 95 GET_Y_LPARAM(native_event.lParam) }; |
| 96 ScreenToClient(native_event.hwnd, &native_point); | 96 ScreenToClient(native_event.hwnd, &native_point); |
| 97 return gfx::Point(native_point); | 97 return gfx::Point(native_point); |
| 98 } | 98 } |
| 99 | 99 |
| 100 int MouseEventFlagsFromNative(NativeEvent native_event) { | 100 int MouseEventFlagsFromNative(NativeEvent native_event) { |
| 101 int flags = 0; | 101 int flags = 0; |
| 102 | 102 |
| 103 // Check if the event occurred in the non-client area. | 103 // Check if the event occurred in the non-client area. |
| 104 if (IsNonClientMouseEvent(native_event)) | 104 if (IsNonClientMouseEvent(native_event)) |
| 105 flags |= ui::EF_IS_NON_CLIENT; | 105 flags |= ui::MouseEvent::EF_IS_NON_CLIENT; |
| 106 | 106 |
| 107 // Check for double click events. | 107 // Check for double click events. |
| 108 switch (native_event.message) { | 108 switch (native_event.message) { |
| 109 case WM_NCLBUTTONDBLCLK: | 109 case WM_NCLBUTTONDBLCLK: |
| 110 case WM_NCMBUTTONDBLCLK: | 110 case WM_NCMBUTTONDBLCLK: |
| 111 case WM_NCRBUTTONDBLCLK: | 111 case WM_NCRBUTTONDBLCLK: |
| 112 case WM_LBUTTONDBLCLK: | 112 case WM_LBUTTONDBLCLK: |
| 113 case WM_MBUTTONDBLCLK: | 113 case WM_MBUTTONDBLCLK: |
| 114 case WM_RBUTTONDBLCLK: | 114 case WM_RBUTTONDBLCLK: |
| 115 flags |= ui::EF_IS_DOUBLE_CLICK; | 115 flags |= ui::MouseEvent::EF_IS_DOUBLE_CLICK; |
| 116 break; | 116 break; |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Check for pressed buttons. | 119 // Check for pressed buttons. |
| 120 if (IsClientMouseEvent(native_event)) { | 120 if (IsClientMouseEvent(native_event)) { |
| 121 if (native_event.wParam & MK_LBUTTON) | 121 if (native_event.wParam & MK_LBUTTON) |
| 122 flags |= ui::EF_LEFT_BUTTON_DOWN; | 122 flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN; |
| 123 if (native_event.wParam & MK_MBUTTON) | 123 if (native_event.wParam & MK_MBUTTON) |
| 124 flags |= ui::EF_MIDDLE_BUTTON_DOWN; | 124 flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN; |
| 125 if (native_event.wParam & MK_RBUTTON) | 125 if (native_event.wParam & MK_RBUTTON) |
| 126 flags |= ui::EF_RIGHT_BUTTON_DOWN; | 126 flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN; |
| 127 } else if (IsNonClientMouseEvent(native_event)) { | 127 } else if (IsNonClientMouseEvent(native_event)) { |
| 128 switch (native_event.message) { | 128 switch (native_event.message) { |
| 129 case WM_NCLBUTTONDOWN: | 129 case WM_NCLBUTTONDOWN: |
| 130 flags |= ui::EF_LEFT_BUTTON_DOWN; | 130 flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN; |
| 131 break; | 131 break; |
| 132 case WM_NCMBUTTONDOWN: | 132 case WM_NCMBUTTONDOWN: |
| 133 flags |= ui::EF_MIDDLE_BUTTON_DOWN; | 133 flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN; |
| 134 break; | 134 break; |
| 135 case WM_NCRBUTTONDOWN: | 135 case WM_NCRBUTTONDOWN: |
| 136 flags |= ui::EF_RIGHT_BUTTON_DOWN; | 136 flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN; |
| 137 break; | 137 break; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Finally make sure the key state flags are included. | 141 // Finally make sure the key state flags are included. |
| 142 return flags | GetKeyStateFlags(); | 142 return flags | GetKeyStateFlags(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 int MouseWheelEventFlagsFromNative(NativeEvent native_event) { | 145 int MouseWheelEventFlagsFromNative(NativeEvent native_event) { |
| 146 int native_flags = GET_KEYSTATE_WPARAM(native_event.wParam); | 146 int native_flags = GET_KEYSTATE_WPARAM(native_event.wParam); |
| 147 int flags = 0; | 147 int flags = 0; |
| 148 if (native_flags & MK_CONTROL) | 148 if (native_flags & MK_CONTROL) |
| 149 flags |= ui::EF_CONTROL_DOWN; | 149 flags |= ui::Event::EF_CONTROL_DOWN; |
| 150 if (native_flags & MK_SHIFT) | 150 if (native_flags & MK_SHIFT) |
| 151 flags |= ui::EF_SHIFT_DOWN; | 151 flags |= ui::Event::EF_SHIFT_DOWN; |
| 152 if (GetKeyState(VK_MENU) < 0) | 152 if (GetKeyState(VK_MENU) < 0) |
| 153 flags |= ui::EF_ALT_DOWN; | 153 flags |= ui::Event::EF_ALT_DOWN; |
| 154 if (native_flags & MK_LBUTTON) | 154 if (native_flags & MK_LBUTTON) |
| 155 flags |= ui::EF_LEFT_BUTTON_DOWN; | 155 flags |= ui::Event::EF_LEFT_BUTTON_DOWN; |
| 156 if (native_flags & MK_MBUTTON) | 156 if (native_flags & MK_MBUTTON) |
| 157 flags |= ui::EF_MIDDLE_BUTTON_DOWN; | 157 flags |= ui::Event::EF_MIDDLE_BUTTON_DOWN; |
| 158 if (native_flags & MK_RBUTTON) | 158 if (native_flags & MK_RBUTTON) |
| 159 flags |= ui::EF_RIGHT_BUTTON_DOWN; | 159 flags |= ui::Event::EF_RIGHT_BUTTON_DOWN; |
| 160 return flags; | 160 return flags; |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace | 163 } // namespace |
| 164 | 164 |
| 165 //////////////////////////////////////////////////////////////////////////////// | 165 //////////////////////////////////////////////////////////////////////////////// |
| 166 // KeyEvent, public: | 166 // KeyEvent, public: |
| 167 | 167 |
| 168 KeyEvent::KeyEvent(NativeEvent native_event) | 168 KeyEvent::KeyEvent(NativeEvent native_event) |
| 169 : Event(EventTypeFromNative(native_event), GetKeyStateFlags()), | 169 : Event(EventTypeFromNative(native_event), GetKeyStateFlags()), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 186 | 186 |
| 187 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) | 187 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event) |
| 188 : LocatedEvent(ET_MOUSEWHEEL, | 188 : LocatedEvent(ET_MOUSEWHEEL, |
| 189 MousePositionFromNative(native_event), | 189 MousePositionFromNative(native_event), |
| 190 MouseWheelEventFlagsFromNative(native_event)), | 190 MouseWheelEventFlagsFromNative(native_event)), |
| 191 offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) { | 191 offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) { |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace ui | 194 } // namespace ui |
| 195 | 195 |
| OLD | NEW |