| 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 "ui/events/event_constants.h" | 5 #include "ui/events/event_constants.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
| 10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| 11 #include <X11/Xlib.h> | 11 #include <X11/Xlib.h> |
| 12 #include <X11/Xutil.h> |
| 12 | 13 |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
| 15 #include "base/message_loop/message_pump_x11.h" | 16 #include "base/message_loop/message_pump_x11.h" |
| 16 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
| 17 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 18 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 18 #include "ui/events/x/device_data_manager.h" | 19 #include "ui/events/x/device_data_manager.h" |
| 19 #include "ui/events/x/device_list_cache_x.h" | 20 #include "ui/events/x/device_list_cache_x.h" |
| 20 #include "ui/events/x/touch_factory_x11.h" | 21 #include "ui/events/x/touch_factory_x11.h" |
| 21 #include "ui/gfx/display.h" | 22 #include "ui/gfx/display.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 flags |= ui::EF_ALTGR_DOWN; | 142 flags |= ui::EF_ALTGR_DOWN; |
| 142 if (state & Button1Mask) | 143 if (state & Button1Mask) |
| 143 flags |= ui::EF_LEFT_MOUSE_BUTTON; | 144 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 144 if (state & Button2Mask) | 145 if (state & Button2Mask) |
| 145 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; | 146 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
| 146 if (state & Button3Mask) | 147 if (state & Button3Mask) |
| 147 flags |= ui::EF_RIGHT_MOUSE_BUTTON; | 148 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 148 return flags; | 149 return flags; |
| 149 } | 150 } |
| 150 | 151 |
| 152 int GetEventFlagsFromXKeyEvent(XEvent* xevent) { |
| 153 return GetEventFlagsFromXState(xevent->xkey.state) | |
| 154 (IsKeypadKey(XLookupKeysym(&xevent->xkey, 0)) ? ui::EF_NUMPAD_KEY : 0); |
| 155 } |
| 156 |
| 151 // Get the event flag for the button in XButtonEvent. During a ButtonPress | 157 // Get the event flag for the button in XButtonEvent. During a ButtonPress |
| 152 // event, |state| in XButtonEvent does not include the button that has just been | 158 // event, |state| in XButtonEvent does not include the button that has just been |
| 153 // pressed. Instead |state| contains flags for the buttons (if any) that had | 159 // pressed. Instead |state| contains flags for the buttons (if any) that had |
| 154 // already been pressed before the current button, and |button| stores the most | 160 // already been pressed before the current button, and |button| stores the most |
| 155 // current pressed button. So, if you press down left mouse button, and while | 161 // current pressed button. So, if you press down left mouse button, and while |
| 156 // pressing it down, press down the right mouse button, then for the latter | 162 // pressing it down, press down the right mouse button, then for the latter |
| 157 // event, |state| would have Button1Mask set but not Button3Mask, and |button| | 163 // event, |state| would have Button1Mask set but not Button3Mask, and |button| |
| 158 // would be 3. | 164 // would be 3. |
| 159 int GetEventFlagsForButton(int button) { | 165 int GetEventFlagsForButton(int button) { |
| 160 switch (button) { | 166 switch (button) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 break; | 327 break; |
| 322 } | 328 } |
| 323 return ET_UNKNOWN; | 329 return ET_UNKNOWN; |
| 324 } | 330 } |
| 325 | 331 |
| 326 int EventFlagsFromNative(const base::NativeEvent& native_event) { | 332 int EventFlagsFromNative(const base::NativeEvent& native_event) { |
| 327 switch (native_event->type) { | 333 switch (native_event->type) { |
| 328 case KeyPress: | 334 case KeyPress: |
| 329 case KeyRelease: { | 335 case KeyRelease: { |
| 330 XModifierStateWatcher::GetInstance()->UpdateStateFromEvent(native_event); | 336 XModifierStateWatcher::GetInstance()->UpdateStateFromEvent(native_event); |
| 331 return GetEventFlagsFromXState(native_event->xkey.state); | 337 return GetEventFlagsFromXKeyEvent(native_event); |
| 332 } | 338 } |
| 333 case ButtonPress: | 339 case ButtonPress: |
| 334 case ButtonRelease: { | 340 case ButtonRelease: { |
| 335 int flags = GetEventFlagsFromXState(native_event->xbutton.state); | 341 int flags = GetEventFlagsFromXState(native_event->xbutton.state); |
| 336 const EventType type = EventTypeFromNative(native_event); | 342 const EventType type = EventTypeFromNative(native_event); |
| 337 if (type == ET_MOUSE_PRESSED || type == ET_MOUSE_RELEASED) | 343 if (type == ET_MOUSE_PRESSED || type == ET_MOUSE_RELEASED) |
| 338 flags |= GetEventFlagsForButton(native_event->xbutton.button); | 344 flags |= GetEventFlagsForButton(native_event->xbutton.button); |
| 339 return flags; | 345 return flags; |
| 340 } | 346 } |
| 341 case EnterNotify: | 347 case EnterNotify: |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 DeviceDataManager::GetInstance()->GetGestureTimes( | 671 DeviceDataManager::GetInstance()->GetGestureTimes( |
| 666 native_event, start_time, end_time); | 672 native_event, start_time, end_time); |
| 667 return true; | 673 return true; |
| 668 } | 674 } |
| 669 | 675 |
| 670 bool IsTouchpadEvent(const base::NativeEvent& event) { | 676 bool IsTouchpadEvent(const base::NativeEvent& event) { |
| 671 return DeviceDataManager::GetInstance()->IsTouchpadXInputEvent(event); | 677 return DeviceDataManager::GetInstance()->IsTouchpadXInputEvent(event); |
| 672 } | 678 } |
| 673 | 679 |
| 674 } // namespace ui | 680 } // namespace ui |
| OLD | NEW |