Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/x/device_data_manager.h" | 5 #include "ui/events/x/device_data_manager.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_switches.h" | 15 #include "ui/events/event_switches.h" |
| 16 #include "ui/events/event_utils.h" | |
| 16 #include "ui/events/x/device_list_cache_x.h" | 17 #include "ui/events/x/device_list_cache_x.h" |
| 17 #include "ui/events/x/touch_factory_x11.h" | 18 #include "ui/events/x/touch_factory_x11.h" |
| 18 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
| 19 #include "ui/gfx/point3_f.h" | 20 #include "ui/gfx/point3_f.h" |
| 20 #include "ui/gfx/x/x11_types.h" | 21 #include "ui/gfx/x/x11_types.h" |
| 21 | 22 |
| 22 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 23 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
| 23 // for backward-compatibility with older versions of XInput. | 24 // for backward-compatibility with older versions of XInput. |
| 24 #if !defined(XIScrollClass) | 25 #if !defined(XIScrollClass) |
| 25 #define XIScrollClass 3 | 26 #define XIScrollClass 3 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 bool DeviceDataManager::IsTouchDataType(const int type) { | 109 bool DeviceDataManager::IsTouchDataType(const int type) { |
| 109 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); | 110 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); |
| 110 } | 111 } |
| 111 | 112 |
| 112 DeviceDataManager* DeviceDataManager::GetInstance() { | 113 DeviceDataManager* DeviceDataManager::GetInstance() { |
| 113 return Singleton<DeviceDataManager>::get(); | 114 return Singleton<DeviceDataManager>::get(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 DeviceDataManager::DeviceDataManager() | 117 DeviceDataManager::DeviceDataManager() |
| 117 : xi_opcode_(-1), | 118 : xi_opcode_(-1), |
| 119 blocked_keyboard_(false), | |
| 118 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), | 120 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), |
| 119 button_map_count_(0) { | 121 button_map_count_(0) { |
| 120 CHECK(gfx::GetXDisplay()); | 122 CHECK(gfx::GetXDisplay()); |
| 121 InitializeXInputInternal(); | 123 InitializeXInputInternal(); |
| 122 | 124 |
| 123 // Make sure the sizes of enum and kCachedAtoms are aligned. | 125 // Make sure the sizes of enum and kCachedAtoms are aligned. |
| 124 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); | 126 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); |
| 125 UpdateDeviceList(gfx::GetXDisplay()); | 127 UpdateDeviceList(gfx::GetXDisplay()); |
| 126 UpdateButtonMap(); | 128 UpdateButtonMap(); |
| 127 for (int i = 0; i < kMaxDeviceNum; i++) | 129 for (int i = 0; i < kMaxDeviceNum; i++) |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 646 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
| 645 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); | 647 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); |
| 646 if (base::SysInfo::IsRunningOnChromeOS() && | 648 if (base::SysInfo::IsRunningOnChromeOS() && |
| 647 touch_display_id == gfx::Display::InternalDisplayId()) { | 649 touch_display_id == gfx::Display::InternalDisplayId()) { |
| 648 return true; | 650 return true; |
| 649 } | 651 } |
| 650 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 652 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
| 651 return false; | 653 return false; |
| 652 } | 654 } |
| 653 | 655 |
| 656 void DeviceDataManager::DisableKeyboard( | |
| 657 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { | |
| 658 DCHECK(!blocked_keyboard_); | |
| 659 DCHECK(!blocked_keyboard_allowed_keys_.get()); | |
| 660 DCHECK(excepted_keys); | |
|
sadrul
2014/06/12 21:02:27
This is probably not necessary? It should be possi
flackr
2014/06/18 05:28:32
Done.
| |
| 661 blocked_keyboard_ = true; | |
| 662 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | |
| 663 } | |
| 664 | |
| 665 void DeviceDataManager::EnableKeyboard() { | |
| 666 DCHECK(blocked_keyboard_); | |
| 667 blocked_keyboard_ = false; | |
| 668 blocked_keyboard_allowed_keys_.reset(); | |
| 669 } | |
| 670 | |
| 671 void DeviceDataManager::DisableDevice(unsigned int deviceid) { | |
| 672 blocked_devices_.set(deviceid, true); | |
| 673 } | |
| 674 | |
| 675 void DeviceDataManager::EnableDevice(unsigned int deviceid) { | |
| 676 blocked_devices_.set(deviceid, false); | |
| 677 } | |
| 678 | |
| 679 bool DeviceDataManager::EventBlocked(const base::NativeEvent& native_event) { | |
| 680 switch (native_event->type) { | |
| 681 case KeyPress: | |
| 682 case KeyRelease: | |
| 683 return blocked_keyboard_ && blocked_keyboard_allowed_keys_->find( | |
| 684 KeyboardCodeFromNative(native_event)) == | |
| 685 blocked_keyboard_allowed_keys_->end(); | |
| 686 case GenericEvent: | |
| 687 return blocked_devices_.test( | |
| 688 static_cast<XIDeviceEvent*>(native_event->xcookie.data)->sourceid); | |
| 689 default: | |
| 690 break; | |
| 691 } | |
| 692 return false; | |
| 693 } | |
| 694 | |
| 654 void DeviceDataManager::ClearTouchTransformerRecord() { | 695 void DeviceDataManager::ClearTouchTransformerRecord() { |
| 655 for (int i = 0; i < kMaxDeviceNum; i++) { | 696 for (int i = 0; i < kMaxDeviceNum; i++) { |
| 656 touch_device_transformer_map_[i] = gfx::Transform(); | 697 touch_device_transformer_map_[i] = gfx::Transform(); |
| 657 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | 698 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| 658 } | 699 } |
| 659 } | 700 } |
| 660 | 701 |
| 661 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { | 702 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { |
| 662 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | 703 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
| 663 } | 704 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 684 } | 725 } |
| 685 } | 726 } |
| 686 | 727 |
| 687 int64 DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | 728 int64 DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { |
| 688 if (IsTouchDeviceIdValid(touch_device_id)) | 729 if (IsTouchDeviceIdValid(touch_device_id)) |
| 689 return touch_device_to_display_map_[touch_device_id]; | 730 return touch_device_to_display_map_[touch_device_id]; |
| 690 return gfx::Display::kInvalidDisplayID; | 731 return gfx::Display::kInvalidDisplayID; |
| 691 } | 732 } |
| 692 | 733 |
| 693 } // namespace ui | 734 } // namespace ui |
| OLD | NEW |