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 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 | 103 |
| 104 bool DeviceDataManager::IsTouchDataType(const int type) { | 104 bool DeviceDataManager::IsTouchDataType(const int type) { |
| 105 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); | 105 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); |
| 106 } | 106 } |
| 107 | 107 |
| 108 DeviceDataManager* DeviceDataManager::GetInstance() { | 108 DeviceDataManager* DeviceDataManager::GetInstance() { |
| 109 return Singleton<DeviceDataManager>::get(); | 109 return Singleton<DeviceDataManager>::get(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 DeviceDataManager::DeviceDataManager() | 112 DeviceDataManager::DeviceDataManager() |
| 113 : natural_scroll_enabled_(false), | 113 : xi_opcode_(-1), |
| 114 xi_opcode_(-1), | |
| 115 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), | 114 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), |
| 116 button_map_count_(0) { | 115 button_map_count_(0) { |
| 117 CHECK(gfx::GetXDisplay()); | 116 CHECK(gfx::GetXDisplay()); |
| 118 InitializeXInputInternal(); | 117 InitializeXInputInternal(); |
| 119 | 118 |
| 120 // Make sure the sizes of enum and kCachedAtoms are aligned. | 119 // Make sure the sizes of enum and kCachedAtoms are aligned. |
| 121 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); | 120 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); |
| 122 UpdateDeviceList(gfx::GetXDisplay()); | 121 UpdateDeviceList(gfx::GetXDisplay()); |
| 123 UpdateButtonMap(); | 122 UpdateButtonMap(); |
| 124 } | 123 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 xi_device_event_types_[XI_TouchUpdate] = true; | 169 xi_device_event_types_[XI_TouchUpdate] = true; |
| 171 xi_device_event_types_[XI_TouchEnd] = true; | 170 xi_device_event_types_[XI_TouchEnd] = true; |
| 172 } | 171 } |
| 173 return true; | 172 return true; |
| 174 } | 173 } |
| 175 | 174 |
| 176 bool DeviceDataManager::IsXInput2Available() const { | 175 bool DeviceDataManager::IsXInput2Available() const { |
| 177 return xi_opcode_ != -1; | 176 return xi_opcode_ != -1; |
| 178 } | 177 } |
| 179 | 178 |
| 180 float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const { | 179 float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const { |
|
achuithb
2014/03/27 00:15:19
Could you please also get rid of this function?
| |
| 181 // Natural scroll is touchpad-only. | 180 return -1.0f; |
| 182 if (sourceid >= kMaxDeviceNum || !touchpads_[sourceid]) | |
| 183 return -1.0f; | |
| 184 | |
| 185 return natural_scroll_enabled_ ? 1.0f : -1.0f; | |
| 186 } | 181 } |
| 187 | 182 |
| 188 void DeviceDataManager::UpdateDeviceList(Display* display) { | 183 void DeviceDataManager::UpdateDeviceList(Display* display) { |
| 189 cmt_devices_.reset(); | 184 cmt_devices_.reset(); |
| 190 touchpads_.reset(); | 185 touchpads_.reset(); |
| 191 for (int i = 0; i < kMaxDeviceNum; ++i) { | 186 for (int i = 0; i < kMaxDeviceNum; ++i) { |
| 192 valuator_count_[i] = 0; | 187 valuator_count_[i] = 0; |
| 193 valuator_lookup_[i].clear(); | 188 valuator_lookup_[i].clear(); |
| 194 data_type_lookup_[i].clear(); | 189 data_type_lookup_[i].clear(); |
| 195 valuator_min_[i].clear(); | 190 valuator_min_[i].clear(); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 float* x_offset, float* y_offset, | 448 float* x_offset, float* y_offset, |
| 454 float* x_offset_ordinal, | 449 float* x_offset_ordinal, |
| 455 float* y_offset_ordinal, | 450 float* y_offset_ordinal, |
| 456 int* finger_count) { | 451 int* finger_count) { |
| 457 *x_offset = 0; | 452 *x_offset = 0; |
| 458 *y_offset = 0; | 453 *y_offset = 0; |
| 459 *x_offset_ordinal = 0; | 454 *x_offset_ordinal = 0; |
| 460 *y_offset_ordinal = 0; | 455 *y_offset_ordinal = 0; |
| 461 *finger_count = 2; | 456 *finger_count = 2; |
| 462 | 457 |
| 463 XIDeviceEvent* xiev = | |
| 464 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
| 465 const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid); | |
| 466 EventData data; | 458 EventData data; |
| 467 GetEventRawData(*native_event, &data); | 459 GetEventRawData(*native_event, &data); |
| 468 | 460 |
| 469 if (data.find(DT_CMT_SCROLL_X) != data.end()) | 461 if (data.find(DT_CMT_SCROLL_X) != data.end()) |
| 470 *x_offset = data[DT_CMT_SCROLL_X] * natural_scroll_factor; | 462 *x_offset = data[DT_CMT_SCROLL_X]; |
| 471 if (data.find(DT_CMT_SCROLL_Y) != data.end()) | 463 if (data.find(DT_CMT_SCROLL_Y) != data.end()) |
| 472 *y_offset = data[DT_CMT_SCROLL_Y] * natural_scroll_factor; | 464 *y_offset = data[DT_CMT_SCROLL_Y]; |
| 473 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 465 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
| 474 *x_offset_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor; | 466 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; |
| 475 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 467 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
| 476 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor; | 468 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; |
| 477 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) | 469 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) |
| 478 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); | 470 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
| 479 } | 471 } |
| 480 | 472 |
| 481 void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event, | 473 void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event, |
| 482 float* vx, float* vy, | 474 float* vx, float* vy, |
| 483 float* vx_ordinal, float* vy_ordinal, | 475 float* vx_ordinal, float* vy_ordinal, |
| 484 bool* is_cancel) { | 476 bool* is_cancel) { |
| 485 *vx = 0; | 477 *vx = 0; |
| 486 *vy = 0; | 478 *vy = 0; |
| 487 *vx_ordinal = 0; | 479 *vx_ordinal = 0; |
| 488 *vy_ordinal = 0; | 480 *vy_ordinal = 0; |
| 489 *is_cancel = false; | 481 *is_cancel = false; |
| 490 | 482 |
| 491 XIDeviceEvent* xiev = | |
| 492 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
| 493 const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid); | |
| 494 EventData data; | 483 EventData data; |
| 495 GetEventRawData(*native_event, &data); | 484 GetEventRawData(*native_event, &data); |
| 496 | 485 |
| 497 if (data.find(DT_CMT_FLING_X) != data.end()) | 486 if (data.find(DT_CMT_FLING_X) != data.end()) |
| 498 *vx = data[DT_CMT_FLING_X] * natural_scroll_factor; | 487 *vx = data[DT_CMT_FLING_X]; |
| 499 if (data.find(DT_CMT_FLING_Y) != data.end()) | 488 if (data.find(DT_CMT_FLING_Y) != data.end()) |
| 500 *vy = data[DT_CMT_FLING_Y] * natural_scroll_factor; | 489 *vy = data[DT_CMT_FLING_Y]; |
| 501 if (data.find(DT_CMT_FLING_STATE) != data.end()) | 490 if (data.find(DT_CMT_FLING_STATE) != data.end()) |
| 502 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); | 491 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); |
| 503 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 492 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
| 504 *vx_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor; | 493 *vx_ordinal = data[DT_CMT_ORDINAL_X]; |
| 505 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 494 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
| 506 *vy_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor; | 495 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; |
| 507 } | 496 } |
| 508 | 497 |
| 509 void DeviceDataManager::GetMetricsData(const base::NativeEvent& native_event, | 498 void DeviceDataManager::GetMetricsData(const base::NativeEvent& native_event, |
| 510 GestureMetricsType* type, | 499 GestureMetricsType* type, |
| 511 float* data1, float* data2) { | 500 float* data1, float* data2) { |
| 512 *type = kGestureMetricsTypeUnknown; | 501 *type = kGestureMetricsTypeUnknown; |
| 513 *data1 = 0; | 502 *data1 = 0; |
| 514 *data2 = 0; | 503 *data2 = 0; |
| 515 | 504 |
| 516 EventData data; | 505 EventData data; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 for (int j = start_valuator; j <= end_valuator; ++j) { | 632 for (int j = start_valuator; j <= end_valuator; ++j) { |
| 644 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 633 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
| 645 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 634 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
| 646 valuator_min_[deviceid][j] = min_value; | 635 valuator_min_[deviceid][j] = min_value; |
| 647 valuator_max_[deviceid][j] = max_value; | 636 valuator_max_[deviceid][j] = max_value; |
| 648 valuator_count_[deviceid]++; | 637 valuator_count_[deviceid]++; |
| 649 } | 638 } |
| 650 } | 639 } |
| 651 | 640 |
| 652 } // namespace ui | 641 } // namespace ui |
| OLD | NEW |