OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ozone/evdev/libgestures_glue/gesture_property_provider.h" | 5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
6 | 6 |
7 #include <gestures/gestures.h> | 7 #include <gestures/gestures.h> |
8 #include <libevdev/libevdev.h> | 8 #include <libevdev/libevdev.h> |
9 | 9 |
10 #include <fnmatch.h> | 10 #include <fnmatch.h> |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 "MatchIsKeyboard", | 424 "MatchIsKeyboard", |
425 "MatchIsJoystick", | 425 "MatchIsJoystick", |
426 "MatchIsTablet"}; | 426 "MatchIsTablet"}; |
427 | 427 |
428 // Special keywords for boolean values. | 428 // Special keywords for boolean values. |
429 const char* kTrue[] = {"on", "true", "yes"}; | 429 const char* kTrue[] = {"on", "true", "yes"}; |
430 const char* kFalse[] = {"off", "false", "no"}; | 430 const char* kFalse[] = {"off", "false", "no"}; |
431 | 431 |
432 // Check if a device falls into one device type category. | 432 // Check if a device falls into one device type category. |
433 bool IsDeviceOfType(const ui::GesturePropertyProvider::DevicePtr device, | 433 bool IsDeviceOfType(const ui::GesturePropertyProvider::DevicePtr device, |
434 const ui::EventDeviceType type) { | 434 const ui::EventDeviceType type, |
435 const GesturesProp* device_mouse, | |
spang
2015/02/04 17:47:10
device_mouse_property
Shecky Lin
2015/02/06 04:51:14
Done.
| |
436 const GesturesProp* device_touchpad) { | |
spang
2015/02/04 17:47:10
device_touchpad_property
Shecky Lin
2015/02/06 04:51:14
Done.
| |
437 // Get the device type info from gesture properties if they are available. | |
438 bool is_mouse = false, is_touchpad = false; | |
439 if (device_mouse) | |
440 is_mouse = device_mouse->GetBoolValue()[0]; | |
spang
2015/02/04 17:47:10
else
is_mouse = (evdev_class == EvdevClassMouse
Shecky Lin
2015/02/06 04:51:14
Done.
| |
441 if (device_touchpad) | |
442 is_touchpad = device_touchpad->GetBoolValue()[0]; | |
spang
2015/02/04 17:47:10
else
is_touchpad = (evdev_class == EvdevClassTou
Shecky Lin
2015/02/06 04:51:14
Done.
| |
443 | |
444 // If the device type properties are unavailable, fallback to the libevdev | |
445 // device info. | |
435 EvdevClass evdev_class = device->info.evdev_class; | 446 EvdevClass evdev_class = device->info.evdev_class; |
436 switch (type) { | 447 switch (type) { |
437 case ui::DT_KEYBOARD: | 448 case ui::DT_KEYBOARD: |
438 return (evdev_class == EvdevClassKeyboard); | 449 return (evdev_class == EvdevClassKeyboard); |
439 break; | 450 break; |
440 case ui::DT_MOUSE: | 451 case ui::DT_MOUSE: |
452 if (device_mouse) | |
453 return is_mouse; | |
441 return (evdev_class == EvdevClassMouse || | 454 return (evdev_class == EvdevClassMouse || |
442 evdev_class == EvdevClassMultitouchMouse); | 455 evdev_class == EvdevClassMultitouchMouse); |
443 break; | 456 break; |
444 case ui::DT_TOUCHPAD: | 457 case ui::DT_TOUCHPAD: |
445 // Note that the behavior here is different from the inputcontrol script | 458 if (device_mouse && device_mouse) |
446 // which actually returns touchscreen devices as well. | 459 return (!is_mouse) && is_touchpad; |
447 return (evdev_class == EvdevClassTouchpad); | 460 return (evdev_class == EvdevClassTouchpad); |
448 break; | 461 break; |
449 case ui::DT_TOUCHSCREEN: | 462 case ui::DT_TOUCHSCREEN: |
450 return (evdev_class == EvdevClassTouchscreen); | 463 return (evdev_class == EvdevClassTouchscreen); |
451 break; | 464 break; |
452 case ui::DT_MULTITOUCH: | 465 case ui::DT_MULTITOUCH: |
466 if (device_touchpad) | |
467 return is_touchpad; | |
453 return (evdev_class == EvdevClassTouchpad || | 468 return (evdev_class == EvdevClassTouchpad || |
454 evdev_class == EvdevClassTouchscreen || | 469 evdev_class == EvdevClassTouchscreen || |
455 evdev_class == EvdevClassMultitouchMouse); | 470 evdev_class == EvdevClassMultitouchMouse); |
456 break; | 471 break; |
457 case ui::DT_MULTITOUCH_MOUSE: | 472 case ui::DT_MULTITOUCH_MOUSE: |
473 if (device_mouse && device_mouse) | |
474 return is_mouse && is_touchpad; | |
458 return (evdev_class == EvdevClassMultitouchMouse); | 475 return (evdev_class == EvdevClassMultitouchMouse); |
459 break; | 476 break; |
460 case ui::DT_ALL: | 477 case ui::DT_ALL: |
461 return true; | 478 return true; |
462 break; | 479 break; |
463 default: | 480 default: |
464 break; | 481 break; |
465 } | 482 } |
466 return false; | 483 return false; |
467 } | 484 } |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 | 865 |
849 GesturePropertyProvider::~GesturePropertyProvider() { | 866 GesturePropertyProvider::~GesturePropertyProvider() { |
850 } | 867 } |
851 | 868 |
852 bool GesturePropertyProvider::GetDeviceIdsByType( | 869 bool GesturePropertyProvider::GetDeviceIdsByType( |
853 const EventDeviceType type, | 870 const EventDeviceType type, |
854 std::vector<DeviceId>* device_ids) { | 871 std::vector<DeviceId>* device_ids) { |
855 bool exists = false; | 872 bool exists = false; |
856 DeviceMap::const_iterator it = device_map_.begin(); | 873 DeviceMap::const_iterator it = device_map_.begin(); |
857 for (; it != device_map_.end(); ++it) { | 874 for (; it != device_map_.end(); ++it) { |
858 if (IsDeviceOfType(it->second, type)) { | 875 if (IsDeviceIdOfType(it->first, type)) { |
859 exists = true; | 876 exists = true; |
860 if (device_ids) | 877 if (device_ids) |
861 device_ids->push_back(it->first); | 878 device_ids->push_back(it->first); |
862 } | 879 } |
863 } | 880 } |
864 return exists; | 881 return exists; |
865 } | 882 } |
866 | 883 |
867 bool GesturePropertyProvider::IsDeviceIdOfType(const DeviceId device_id, | 884 bool GesturePropertyProvider::IsDeviceIdOfType(const DeviceId device_id, |
868 const EventDeviceType type) { | 885 const EventDeviceType type) { |
869 DeviceMap::const_iterator it = device_map_.find(device_id); | 886 DeviceMap::const_iterator it = device_map_.find(device_id); |
870 if (it == device_map_.end()) | 887 if (it == device_map_.end()) |
871 return false; | 888 return false; |
872 return IsDeviceOfType(it->second, type); | 889 return IsDeviceOfType(it->second, type, |
890 GetProperty(device_id, "Device Mouse"), | |
891 GetProperty(device_id, "Device Touchpad")); | |
873 } | 892 } |
874 | 893 |
875 GesturesProp* GesturePropertyProvider::GetProperty(const DeviceId device_id, | 894 GesturesProp* GesturePropertyProvider::GetProperty(const DeviceId device_id, |
876 const std::string& name) { | 895 const std::string& name) { |
877 return FindProperty(device_id, name); | 896 return FindProperty(device_id, name); |
878 } | 897 } |
879 | 898 |
880 std::vector<std::string> GesturePropertyProvider::GetPropertyNamesById( | 899 std::vector<std::string> GesturePropertyProvider::GetPropertyNamesById( |
881 const DeviceId device_id) { | 900 const DeviceId device_id) { |
882 internal::GestureDevicePropertyData* device_data = | 901 internal::GestureDevicePropertyData* device_data = |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1524 const GesturesPropProvider kGesturePropProvider = { | 1543 const GesturesPropProvider kGesturePropProvider = { |
1525 GesturesPropFunctionsWrapper::CreateInt, | 1544 GesturesPropFunctionsWrapper::CreateInt, |
1526 GesturesPropFunctionsWrapper::CreateShort, | 1545 GesturesPropFunctionsWrapper::CreateShort, |
1527 GesturesPropFunctionsWrapper::CreateBool, | 1546 GesturesPropFunctionsWrapper::CreateBool, |
1528 GesturesPropFunctionsWrapper::CreateString, | 1547 GesturesPropFunctionsWrapper::CreateString, |
1529 GesturesPropFunctionsWrapper::CreateReal, | 1548 GesturesPropFunctionsWrapper::CreateReal, |
1530 GesturesPropFunctionsWrapper::RegisterHandlers, | 1549 GesturesPropFunctionsWrapper::RegisterHandlers, |
1531 GesturesPropFunctionsWrapper::Free}; | 1550 GesturesPropFunctionsWrapper::Free}; |
1532 | 1551 |
1533 } // namespace ui | 1552 } // namespace ui |
OLD | NEW |