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