| 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() { |
| 65 touch_device_to_display_map_.clear(); |
| 66 |
| 68 for (int i = 0; i < kMaxDeviceNum; i++) { | 67 for (int i = 0; i < kMaxDeviceNum; i++) { |
| 69 touch_device_transformer_map_[i] = gfx::Transform(); | 68 touch_device_transformer_map_[i] = gfx::Transform(); |
| 70 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
| 71 touch_radius_scale_map_[i] = 1.0; | 69 touch_radius_scale_map_[i] = 1.0; |
| 72 } | 70 } |
| 73 } | 71 } |
| 74 | 72 |
| 75 bool DeviceDataManager::IsTouchDeviceIdValid( | 73 bool DeviceDataManager::IsTouchDeviceIdValid( |
| 76 unsigned int touch_device_id) const { | 74 unsigned int touch_device_id) const { |
| 77 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | 75 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void DeviceDataManager::UpdateTouchInfoForDisplay( | 78 void DeviceDataManager::UpdateTouchInfoForDisplay( |
| 81 int64_t display_id, | 79 const gfx::Display& display, |
| 82 unsigned int touch_device_id, | 80 unsigned int touch_device_id, |
| 83 const gfx::Transform& touch_transformer) { | 81 const gfx::Transform& touch_transformer) { |
| 84 if (IsTouchDeviceIdValid(touch_device_id)) { | 82 if (IsTouchDeviceIdValid(touch_device_id)) { |
| 85 touch_device_to_display_map_[touch_device_id] = display_id; | 83 touch_device_to_display_map_[touch_device_id] = display; |
| 86 touch_device_transformer_map_[touch_device_id] = touch_transformer; | 84 touch_device_transformer_map_[touch_device_id] = touch_transformer; |
| 87 } | 85 } |
| 88 } | 86 } |
| 89 | 87 |
| 90 void DeviceDataManager::UpdateTouchRadiusScale(unsigned int touch_device_id, | 88 void DeviceDataManager::UpdateTouchRadiusScale(unsigned int touch_device_id, |
| 91 double scale) { | 89 double scale) { |
| 92 if (IsTouchDeviceIdValid(touch_device_id)) | 90 if (IsTouchDeviceIdValid(touch_device_id)) |
| 93 touch_radius_scale_map_[touch_device_id] = scale; | 91 touch_radius_scale_map_[touch_device_id] = scale; |
| 94 } | 92 } |
| 95 | 93 |
| 96 void DeviceDataManager::ApplyTouchRadiusScale(unsigned int touch_device_id, | 94 void DeviceDataManager::ApplyTouchRadiusScale(unsigned int touch_device_id, |
| 97 double* radius) { | 95 double* radius) { |
| 98 if (IsTouchDeviceIdValid(touch_device_id)) | 96 if (IsTouchDeviceIdValid(touch_device_id)) |
| 99 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; | 97 *radius = (*radius) * touch_radius_scale_map_[touch_device_id]; |
| 100 } | 98 } |
| 101 | 99 |
| 102 void DeviceDataManager::ApplyTouchTransformer(unsigned int touch_device_id, | 100 void DeviceDataManager::ApplyTouchTransformer(unsigned int touch_device_id, |
| 103 float* x, | 101 float* x, |
| 104 float* y) { | 102 float* y) { |
| 105 if (IsTouchDeviceIdValid(touch_device_id)) { | 103 if (IsTouchDeviceIdValid(touch_device_id)) { |
| 106 gfx::Point3F point(*x, *y, 0.0); | 104 gfx::Point3F point(*x, *y, 0.0); |
| 107 const gfx::Transform& trans = | 105 const gfx::Transform& trans = |
| 108 touch_device_transformer_map_[touch_device_id]; | 106 touch_device_transformer_map_[touch_device_id]; |
| 109 trans.TransformPoint(&point); | 107 trans.TransformPoint(&point); |
| 110 *x = point.x(); | 108 *x = point.x(); |
| 111 *y = point.y(); | 109 *y = point.y(); |
| 112 } | 110 } |
| 113 } | 111 } |
| 114 | 112 |
| 115 int64_t DeviceDataManager::GetDisplayForTouchDevice( | 113 gfx::Display DeviceDataManager::GetDisplayForTouchDevice( |
| 116 unsigned int touch_device_id) const { | 114 unsigned int touch_device_id) const { |
| 117 if (IsTouchDeviceIdValid(touch_device_id)) | 115 if (!IsTouchDeviceIdValid(touch_device_id)) |
| 118 return touch_device_to_display_map_[touch_device_id]; | 116 return gfx::Display(); |
| 119 return gfx::Display::kInvalidDisplayID; | 117 |
| 118 std::map<unsigned int, gfx::Display>::const_iterator it = |
| 119 touch_device_to_display_map_.find(touch_device_id); |
| 120 return it == touch_device_to_display_map_.end() ? gfx::Display() : it->second; |
| 120 } | 121 } |
| 121 | 122 |
| 122 void DeviceDataManager::OnTouchscreenDevicesUpdated( | 123 void DeviceDataManager::OnTouchscreenDevicesUpdated( |
| 123 const std::vector<TouchscreenDevice>& devices) { | 124 const std::vector<TouchscreenDevice>& devices) { |
| 124 if (devices.size() == touchscreen_devices_.size() && | 125 if (devices.size() == touchscreen_devices_.size() && |
| 125 std::equal(devices.begin(), | 126 std::equal(devices.begin(), |
| 126 devices.end(), | 127 devices.end(), |
| 127 touchscreen_devices_.begin(), | 128 touchscreen_devices_.begin(), |
| 128 InputDeviceEquals)) { | 129 InputDeviceEquals)) { |
| 129 return; | 130 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 166 |
| 166 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { | 167 void DeviceDataManager::AddObserver(InputDeviceEventObserver* observer) { |
| 167 observers_.AddObserver(observer); | 168 observers_.AddObserver(observer); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { | 171 void DeviceDataManager::RemoveObserver(InputDeviceEventObserver* observer) { |
| 171 observers_.RemoveObserver(observer); | 172 observers_.RemoveObserver(observer); |
| 172 } | 173 } |
| 173 | 174 |
| 174 } // namespace ui | 175 } // namespace ui |
| OLD | NEW |