| 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/devices/device_data_manager.h" | 5 #include "ui/events/devices/device_data_manager.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/events/devices/input_device_event_observer.h" | 10 #include "ui/events/devices/input_device_event_observer.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // static | 24 // static |
| 25 DeviceDataManager* DeviceDataManager::instance_ = NULL; | 25 DeviceDataManager* DeviceDataManager::instance_ = NULL; |
| 26 | 26 |
| 27 DeviceDataManager::DeviceDataManager() { | 27 DeviceDataManager::DeviceDataManager() { |
| 28 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; | 28 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager"; |
| 29 instance_ = this; | 29 instance_ = this; |
| 30 | 30 |
| 31 base::AtExitManager::RegisterTask( | 31 base::AtExitManager::RegisterTask( |
| 32 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); | 32 base::Bind(&base::DeletePointer<DeviceDataManager>, this)); |
| 33 | 33 |
| 34 for (int i = 0; i < kMaxDeviceNum; ++i) { | 34 ClearTouchDeviceAssociations(); |
| 35 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
| 36 touch_radius_scale_map_[i] = 1.0; | |
| 37 } | |
| 38 } | 35 } |
| 39 | 36 |
| 40 DeviceDataManager::~DeviceDataManager() { | 37 DeviceDataManager::~DeviceDataManager() { |
| 41 CHECK_EQ(this, instance_); | 38 CHECK_EQ(this, instance_); |
| 42 instance_ = NULL; | 39 instance_ = NULL; |
| 43 } | 40 } |
| 44 | 41 |
| 45 // static | 42 // static |
| 46 DeviceDataManager* DeviceDataManager::instance() { return instance_; } | 43 DeviceDataManager* DeviceDataManager::instance() { return instance_; } |
| 47 | 44 |
| 48 // static | 45 // static |
| 49 void DeviceDataManager::CreateInstance() { | 46 void DeviceDataManager::CreateInstance() { |
| 50 if (instance()) | 47 if (instance()) |
| 51 return; | 48 return; |
| 52 | 49 |
| 53 new DeviceDataManager(); | 50 new DeviceDataManager(); |
| 54 } | 51 } |
| 55 | 52 |
| 56 // static | 53 // static |
| 57 DeviceDataManager* DeviceDataManager::GetInstance() { | 54 DeviceDataManager* DeviceDataManager::GetInstance() { |
| 58 CHECK(instance_) << "DeviceDataManager was not created."; | 55 CHECK(instance_) << "DeviceDataManager was not created."; |
| 59 return instance_; | 56 return instance_; |
| 60 } | 57 } |
| 61 | 58 |
| 62 // static | 59 // static |
| 63 bool DeviceDataManager::HasInstance() { | 60 bool DeviceDataManager::HasInstance() { |
| 64 return instance_ != NULL; | 61 return instance_ != NULL; |
| 65 } | 62 } |
| 66 | 63 |
| 67 void DeviceDataManager::ClearTouchTransformerRecord() { | 64 void DeviceDataManager::ClearTouchDeviceAssociations() { |
| 68 for (int i = 0; i < kMaxDeviceNum; i++) { | 65 for (int i = 0; i < kMaxDeviceNum; i++) { |
| 69 touch_device_transformer_map_[i] = gfx::Transform(); | 66 touch_device_transformer_map_[i] = gfx::Transform(); |
| 70 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | 67 touch_device_to_target_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| 71 touch_radius_scale_map_[i] = 1.0; | 68 touch_radius_scale_map_[i] = 1.0; |
| 72 } | 69 } |
| 73 } | 70 } |
| 74 | 71 |
| 75 bool DeviceDataManager::IsTouchDeviceIdValid( | 72 bool DeviceDataManager::IsTouchDeviceIdValid( |
| 76 unsigned int touch_device_id) const { | 73 unsigned int touch_device_id) const { |
| 77 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | 74 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void DeviceDataManager::UpdateTouchInfoForDisplay( | 77 void DeviceDataManager::UpdateTouchInfoForDisplay( |
| 81 int64_t display_id, | 78 int64_t target_display_id, |
| 82 unsigned int touch_device_id, | 79 unsigned int touch_device_id, |
| 83 const gfx::Transform& touch_transformer) { | 80 const gfx::Transform& touch_transformer) { |
| 84 if (IsTouchDeviceIdValid(touch_device_id)) { | 81 if (IsTouchDeviceIdValid(touch_device_id)) { |
| 85 touch_device_to_display_map_[touch_device_id] = display_id; | 82 touch_device_to_target_display_map_[touch_device_id] = target_display_id; |
| 86 touch_device_transformer_map_[touch_device_id] = touch_transformer; | 83 touch_device_transformer_map_[touch_device_id] = touch_transformer; |
| 87 } | 84 } |
| 88 } | 85 } |
| 89 | 86 |
| 90 void DeviceDataManager::UpdateTouchRadiusScale(unsigned int touch_device_id, | 87 void DeviceDataManager::UpdateTouchRadiusScale(unsigned int touch_device_id, |
| 91 double scale) { | 88 double scale) { |
| 92 if (IsTouchDeviceIdValid(touch_device_id)) | 89 if (IsTouchDeviceIdValid(touch_device_id)) |
| 93 touch_radius_scale_map_[touch_device_id] = scale; | 90 touch_radius_scale_map_[touch_device_id] = scale; |
| 94 } | 91 } |
| 95 | 92 |
| 96 void DeviceDataManager::ApplyTouchRadiusScale(unsigned int touch_device_id, | 93 void DeviceDataManager::ApplyTouchRadiusScale(unsigned int touch_device_id, |
| 97 double* radius) { | 94 double* radius) { |
| 98 if (IsTouchDeviceIdValid(touch_device_id)) | 95 if (IsTouchDeviceIdValid(touch_device_id)) |
| 99 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; | 96 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; |
| 100 } | 97 } |
| 101 | 98 |
| 102 void DeviceDataManager::ApplyTouchTransformer(unsigned int touch_device_id, | 99 void DeviceDataManager::ApplyTouchTransformer(unsigned int touch_device_id, |
| 103 float* x, | 100 float* x, |
| 104 float* y) { | 101 float* y) { |
| 105 if (IsTouchDeviceIdValid(touch_device_id)) { | 102 if (IsTouchDeviceIdValid(touch_device_id)) { |
| 106 gfx::Point3F point(*x, *y, 0.0); | 103 gfx::Point3F point(*x, *y, 0.0); |
| 107 const gfx::Transform& trans = | 104 const gfx::Transform& trans = |
| 108 touch_device_transformer_map_[touch_device_id]; | 105 touch_device_transformer_map_[touch_device_id]; |
| 109 trans.TransformPoint(&point); | 106 trans.TransformPoint(&point); |
| 110 *x = point.x(); | 107 *x = point.x(); |
| 111 *y = point.y(); | 108 *y = point.y(); |
| 112 } | 109 } |
| 113 } | 110 } |
| 114 | 111 |
| 115 int64_t DeviceDataManager::GetDisplayForTouchDevice( | 112 int64_t DeviceDataManager::GetTargetDisplayForTouchDevice( |
| 116 unsigned int touch_device_id) const { | 113 unsigned int touch_device_id) const { |
| 117 if (IsTouchDeviceIdValid(touch_device_id)) | 114 if (IsTouchDeviceIdValid(touch_device_id)) |
| 118 return touch_device_to_display_map_[touch_device_id]; | 115 return touch_device_to_target_display_map_[touch_device_id]; |
| 119 return gfx::Display::kInvalidDisplayID; | 116 return gfx::Display::kInvalidDisplayID; |
| 120 } | 117 } |
| 121 | 118 |
| 122 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 119 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
| 123 const std::vector<TouchscreenDevice>& devices) { | 120 const std::vector<TouchscreenDevice>& devices) { |
| 124 if (devices.size() == touchscreen_devices_.size() && | 121 if (devices.size() == touchscreen_devices_.size() && |
| 125 std::equal(devices.begin(), | 122 std::equal(devices.begin(), |
| 126 devices.end(), | 123 devices.end(), |
| 127 touchscreen_devices_.begin(), | 124 touchscreen_devices_.begin(), |
| 128 InputDeviceEquals)) { | 125 InputDeviceEquals)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 178 |
| 182 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 179 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
| 183 observers_.AddObserver(observer); | 180 observers_.AddObserver(observer); |
| 184 } | 181 } |
| 185 | 182 |
| 186 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 183 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
| 187 observers_.RemoveObserver(observer); | 184 observers_.RemoveObserver(observer); |
| 188 } | 185 } |
| 189 | 186 |
| 190 } // namespace ui | 187 } // namespace ui |
| OLD | NEW |