| 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 "views/events/event.h" | 5 #include "views/events/event.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return ui::ET_MOUSEWHEEL; | 64 return ui::ET_MOUSEWHEEL; |
| 65 case WM_MOUSELEAVE: | 65 case WM_MOUSELEAVE: |
| 66 case WM_NCMOUSELEAVE: | 66 case WM_NCMOUSELEAVE: |
| 67 return ui::ET_MOUSE_EXITED; | 67 return ui::ET_MOUSE_EXITED; |
| 68 default: | 68 default: |
| 69 NOTREACHED(); | 69 NOTREACHED(); |
| 70 } | 70 } |
| 71 return ui::ET_UNKNOWN; | 71 return ui::ET_UNKNOWN; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Get views::Event flags from a native Windows message |
| 74 int GetFlagsFromNative(NativeEvent native_event) { | 75 int GetFlagsFromNative(NativeEvent native_event) { |
| 75 // Allow other applicable messages as necessary. | 76 UINT win_flags = GET_KEYSTATE_WPARAM(native_event.wParam); |
| 76 DCHECK(native_event.message == WM_MOUSEWHEEL); | 77 |
| 77 return Event::ConvertWindowsFlags(GET_KEYSTATE_WPARAM(native_event.wParam)); | 78 // TODO(msw): ORing the pressed/released button into the flags is _wrong_. |
| 79 // It makes it impossible to tell which button was modified when multiple |
| 80 // buttons are/were held down. We need to instead put the modified button into |
| 81 // a separate member on the MouseEvent, then audit all consumers of |
| 82 // MouseEvents to fix them to use the resulting values correctly. |
| 83 // |
| 84 // TODO(msw): Should I skip WM_NC*BUTTONUP, as WidgetWin::OnNC*ButtonUp did? |
| 85 switch (native_event.message) { |
| 86 case WM_LBUTTONDBLCLK: |
| 87 case WM_LBUTTONDOWN: |
| 88 case WM_LBUTTONUP: |
| 89 case WM_NCLBUTTONDBLCLK: |
| 90 case WM_NCLBUTTONDOWN: |
| 91 case WM_NCLBUTTONUP: |
| 92 win_flags |= MK_LBUTTON; |
| 93 break; |
| 94 case WM_MBUTTONDBLCLK: |
| 95 case WM_MBUTTONDOWN: |
| 96 case WM_MBUTTONUP: |
| 97 case WM_NCMBUTTONDBLCLK: |
| 98 case WM_NCMBUTTONDOWN: |
| 99 case WM_NCMBUTTONUP: |
| 100 win_flags |= MK_MBUTTON; |
| 101 break; |
| 102 case WM_RBUTTONDBLCLK: |
| 103 case WM_RBUTTONDOWN: |
| 104 case WM_RBUTTONUP: |
| 105 case WM_NCRBUTTONDBLCLK: |
| 106 case WM_NCRBUTTONDOWN: |
| 107 case WM_NCRBUTTONUP: |
| 108 win_flags |= MK_RBUTTON; |
| 109 break; |
| 110 } |
| 111 |
| 112 int flags = 0; |
| 113 flags |= (win_flags & MK_CONTROL) ? ui::EF_CONTROL_DOWN : 0; |
| 114 flags |= (win_flags & MK_SHIFT) ? ui::EF_SHIFT_DOWN : 0; |
| 115 flags |= (GetKeyState(VK_MENU) < 0) ? ui::EF_ALT_DOWN : 0; |
| 116 flags |= (win_flags & MK_LBUTTON) ? ui::EF_LEFT_BUTTON_DOWN : 0; |
| 117 flags |= (win_flags & MK_MBUTTON) ? ui::EF_MIDDLE_BUTTON_DOWN : 0; |
| 118 flags |= (win_flags & MK_RBUTTON) ? ui::EF_RIGHT_BUTTON_DOWN : 0; |
| 119 |
| 120 switch (native_event.message) { |
| 121 case WM_LBUTTONDBLCLK: |
| 122 case WM_MBUTTONDBLCLK: |
| 123 case WM_RBUTTONDBLCLK: |
| 124 flags |= ui::EF_IS_DOUBLE_CLICK; |
| 125 break; |
| 126 case WM_NCLBUTTONDOWN: |
| 127 case WM_NCLBUTTONUP: |
| 128 case WM_NCMBUTTONDOWN: |
| 129 case WM_NCMBUTTONUP: |
| 130 case WM_NCRBUTTONDOWN: |
| 131 case WM_NCRBUTTONUP: |
| 132 flags |= ui::EF_IS_NON_CLIENT; |
| 133 break; |
| 134 case WM_NCLBUTTONDBLCLK: |
| 135 case WM_NCMBUTTONDBLCLK: |
| 136 case WM_NCRBUTTONDBLCLK: |
| 137 flags |= ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_NON_CLIENT; |
| 138 break; |
| 139 } |
| 140 |
| 141 return flags; |
| 78 } | 142 } |
| 79 | 143 |
| 80 } // namespace | 144 } // namespace |
| 81 | 145 |
| 82 //////////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////////// |
| 83 // Event, public: | 147 // Event, public: |
| 84 | 148 |
| 85 int Event::GetWindowsFlags() const { | 149 int Event::GetWindowsFlags() const { |
| 86 // TODO: need support for x1/x2. | 150 // TODO: need support for x1/x2. |
| 87 int result = 0; | 151 int result = 0; |
| 88 result |= (flags_ & ui::EF_SHIFT_DOWN) ? MK_SHIFT : 0; | 152 result |= (flags_ & ui::EF_SHIFT_DOWN) ? MK_SHIFT : 0; |
| 89 result |= (flags_ & ui::EF_CONTROL_DOWN) ? MK_CONTROL : 0; | 153 result |= (flags_ & ui::EF_CONTROL_DOWN) ? MK_CONTROL : 0; |
| 90 result |= (flags_ & ui::EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0; | 154 result |= (flags_ & ui::EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0; |
| 91 result |= (flags_ & ui::EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0; | 155 result |= (flags_ & ui::EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0; |
| 92 result |= (flags_ & ui::EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0; | 156 result |= (flags_ & ui::EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0; |
| 93 return result; | 157 return result; |
| 94 } | 158 } |
| 95 | 159 |
| 96 //static | |
| 97 int Event::ConvertWindowsFlags(UINT win_flags) { | |
| 98 int r = 0; | |
| 99 if (win_flags & MK_CONTROL) | |
| 100 r |= ui::EF_CONTROL_DOWN; | |
| 101 if (win_flags & MK_SHIFT) | |
| 102 r |= ui::EF_SHIFT_DOWN; | |
| 103 if (GetKeyState(VK_MENU) < 0) | |
| 104 r |= ui::EF_ALT_DOWN; | |
| 105 if (win_flags & MK_LBUTTON) | |
| 106 r |= ui::EF_LEFT_BUTTON_DOWN; | |
| 107 if (win_flags & MK_MBUTTON) | |
| 108 r |= ui::EF_MIDDLE_BUTTON_DOWN; | |
| 109 if (win_flags & MK_RBUTTON) | |
| 110 r |= ui::EF_RIGHT_BUTTON_DOWN; | |
| 111 return r; | |
| 112 } | |
| 113 | |
| 114 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 115 // Event, private: | 161 // Event, private: |
| 116 | 162 |
| 117 void Event::Init() { | 163 void Event::Init() { |
| 118 ZeroMemory(&native_event_, sizeof(native_event_)); | 164 ZeroMemory(&native_event_, sizeof(native_event_)); |
| 119 native_event_2_ = NULL; | 165 native_event_2_ = NULL; |
| 120 } | 166 } |
| 121 | 167 |
| 122 void Event::InitWithNativeEvent(NativeEvent native_event) { | 168 void Event::InitWithNativeEvent(NativeEvent native_event) { |
| 123 native_event_ = native_event; | 169 native_event_ = native_event; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 223 |
| 178 MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, | 224 MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2, |
| 179 FromNativeEvent2 from_native) | 225 FromNativeEvent2 from_native) |
| 180 : LocatedEvent(native_event_2, from_native) { | 226 : LocatedEvent(native_event_2, from_native) { |
| 181 // No one should ever call this on Windows. | 227 // No one should ever call this on Windows. |
| 182 // TODO(msw): remove once we rid views of Gtk/Gdk. | 228 // TODO(msw): remove once we rid views of Gtk/Gdk. |
| 183 NOTREACHED(); | 229 NOTREACHED(); |
| 184 } | 230 } |
| 185 | 231 |
| 186 } // namespace views | 232 } // namespace views |
| OLD | NEW |