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> |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return default_value; | 286 return default_value; |
287 } | 287 } |
288 | 288 |
289 void ScaleTouchRadius(XEvent* xev, double* radius) { | 289 void ScaleTouchRadius(XEvent* xev, double* radius) { |
290 DCHECK_EQ(GenericEvent, xev->type); | 290 DCHECK_EQ(GenericEvent, xev->type); |
291 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 291 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
292 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale( | 292 ui::DeviceDataManagerX11::GetInstance()->ApplyTouchRadiusScale( |
293 xiev->sourceid, radius); | 293 xiev->sourceid, radius); |
294 } | 294 } |
295 | 295 |
296 unsigned int UpdateX11EventFlags(int ui_flags, unsigned int old_x_flags) { | |
297 static struct { | |
298 int ui; | |
299 int x; | |
300 } flags[] = { | |
301 {ui::EF_CONTROL_DOWN, ControlMask}, | |
302 {ui::EF_SHIFT_DOWN, ShiftMask}, | |
303 {ui::EF_ALT_DOWN, Mod1Mask}, | |
304 {ui::EF_CAPS_LOCK_DOWN, LockMask}, | |
305 {ui::EF_ALTGR_DOWN, Mod5Mask}, | |
306 {ui::EF_COMMAND_DOWN, Mod4Mask}, | |
307 {ui::EF_MOD3_DOWN, Mod3Mask}, | |
308 {ui::EF_NUMPAD_KEY, Mod2Mask}, | |
309 {ui::EF_LEFT_MOUSE_BUTTON, Button1Mask}, | |
310 {ui::EF_MIDDLE_MOUSE_BUTTON, Button2Mask}, | |
311 {ui::EF_RIGHT_MOUSE_BUTTON, Button3Mask}, | |
312 }; | |
313 unsigned int new_x_flags = old_x_flags; | |
314 for (size_t i = 0; i < arraysize(flags); ++i) { | |
315 if (ui_flags & flags[i].ui) | |
316 new_x_flags |= flags[i].x; | |
317 else | |
318 new_x_flags &= ~flags[i].x; | |
319 } | |
320 return new_x_flags; | |
321 } | |
322 | |
323 unsigned int UpdateX11EventButton(int ui_flag, unsigned int old_x_button) { | |
324 switch (ui_flag) { | |
325 case ui::EF_LEFT_MOUSE_BUTTON: | |
326 return Button1; | |
327 case ui::EF_MIDDLE_MOUSE_BUTTON: | |
328 return Button2; | |
329 case ui::EF_RIGHT_MOUSE_BUTTON: | |
330 return Button3; | |
331 default: | |
332 return old_x_button; | |
333 } | |
334 NOTREACHED(); | |
335 } | |
336 | |
337 bool GetGestureTimes(const base::NativeEvent& native_event, | 296 bool GetGestureTimes(const base::NativeEvent& native_event, |
338 double* start_time, | 297 double* start_time, |
339 double* end_time) { | 298 double* end_time) { |
340 if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event)) | 299 if (!ui::DeviceDataManagerX11::GetInstance()->HasGestureTimes(native_event)) |
341 return false; | 300 return false; |
342 | 301 |
343 double start_time_, end_time_; | 302 double start_time_, end_time_; |
344 if (!start_time) | 303 if (!start_time) |
345 start_time = &start_time_; | 304 start_time = &start_time_; |
346 if (!end_time) | 305 if (!end_time) |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 return gfx::Vector2d(0, -kWheelScrollAmount); | 684 return gfx::Vector2d(0, -kWheelScrollAmount); |
726 case 6: | 685 case 6: |
727 return gfx::Vector2d(kWheelScrollAmount, 0); | 686 return gfx::Vector2d(kWheelScrollAmount, 0); |
728 case 7: | 687 case 7: |
729 return gfx::Vector2d(-kWheelScrollAmount, 0); | 688 return gfx::Vector2d(-kWheelScrollAmount, 0); |
730 default: | 689 default: |
731 return gfx::Vector2d(); | 690 return gfx::Vector2d(); |
732 } | 691 } |
733 } | 692 } |
734 | 693 |
735 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | |
736 if (!event || event->type == GenericEvent) | |
737 return NULL; | |
738 XEvent* copy = new XEvent; | |
739 *copy = *event; | |
740 return copy; | |
741 } | |
742 | |
743 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { | |
744 delete event; | |
745 } | |
746 | |
747 void IncrementTouchIdRefCount(const base::NativeEvent& xev) { | 694 void IncrementTouchIdRefCount(const base::NativeEvent& xev) { |
748 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); | 695 ui::DeviceDataManagerX11* manager = ui::DeviceDataManagerX11::GetInstance(); |
749 double tracking_id; | 696 double tracking_id; |
750 if (!manager->GetEventData( | 697 if (!manager->GetEventData( |
751 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { | 698 *xev, ui::DeviceDataManagerX11::DT_TOUCH_TRACKING_ID, &tracking_id)) { |
752 return; | 699 return; |
753 } | 700 } |
754 | 701 |
755 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 702 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
756 factory->AcquireSlotForTrackingID(tracking_id); | 703 factory->AcquireSlotForTrackingID(tracking_id); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 if (!vy_ordinal) | 816 if (!vy_ordinal) |
870 vy_ordinal = &vy_ordinal_; | 817 vy_ordinal = &vy_ordinal_; |
871 if (!is_cancel) | 818 if (!is_cancel) |
872 is_cancel = &is_cancel_; | 819 is_cancel = &is_cancel_; |
873 | 820 |
874 DeviceDataManagerX11::GetInstance()->GetFlingData( | 821 DeviceDataManagerX11::GetInstance()->GetFlingData( |
875 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel); | 822 native_event, vx, vy, vx_ordinal, vy_ordinal, is_cancel); |
876 return true; | 823 return true; |
877 } | 824 } |
878 | 825 |
879 void UpdateX11EventForFlags(Event* event) { | |
880 XEvent* xev = event->native_event(); | |
881 if (!xev) | |
882 return; | |
883 switch (xev->type) { | |
884 case KeyPress: | |
885 case KeyRelease: | |
886 xev->xkey.state = UpdateX11EventFlags(event->flags(), xev->xkey.state); | |
887 break; | |
888 case ButtonPress: | |
889 case ButtonRelease: | |
890 xev->xbutton.state = | |
891 UpdateX11EventFlags(event->flags(), xev->xbutton.state); | |
892 break; | |
893 case GenericEvent: { | |
894 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
895 DCHECK(xievent); | |
896 xievent->mods.effective = | |
897 UpdateX11EventFlags(event->flags(), xievent->mods.effective); | |
898 break; | |
899 } | |
900 default: | |
901 break; | |
902 } | |
903 } | |
904 | |
905 void UpdateX11EventForChangedButtonFlags(MouseEvent* event) { | |
906 XEvent* xev = event->native_event(); | |
907 if (!xev) | |
908 return; | |
909 switch (xev->type) { | |
910 case ButtonPress: | |
911 case ButtonRelease: | |
912 xev->xbutton.button = UpdateX11EventButton(event->changed_button_flags(), | |
913 xev->xbutton.button); | |
914 break; | |
915 case GenericEvent: { | |
916 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | |
917 CHECK(xievent && (xievent->evtype == XI_ButtonPress || | |
918 xievent->evtype == XI_ButtonRelease)); | |
919 xievent->detail = | |
920 UpdateX11EventButton(event->changed_button_flags(), xievent->detail); | |
921 break; | |
922 } | |
923 default: | |
924 break; | |
925 } | |
926 } | |
927 | |
928 } // namespace ui | 826 } // namespace ui |
OLD | NEW |