Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: ui/events/x/device_data_manager.cc

Issue 212603005: Don't handle NaturalScroll in Chrome but pass it to CMT instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed Ash unit tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/events/x/device_data_manager.h ('k') | ui/events/x/events_x.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 {
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
188 void DeviceDataManager::UpdateDeviceList(Display* display) { 179 void DeviceDataManager::UpdateDeviceList(Display* display) {
189 cmt_devices_.reset(); 180 cmt_devices_.reset();
190 touchpads_.reset(); 181 touchpads_.reset();
191 for (int i = 0; i < kMaxDeviceNum; ++i) { 182 for (int i = 0; i < kMaxDeviceNum; ++i) {
192 valuator_count_[i] = 0; 183 valuator_count_[i] = 0;
193 valuator_lookup_[i].clear(); 184 valuator_lookup_[i].clear();
194 data_type_lookup_[i].clear(); 185 data_type_lookup_[i].clear();
195 valuator_min_[i].clear(); 186 valuator_min_[i].clear();
196 valuator_max_[i].clear(); 187 valuator_max_[i].clear();
197 for (int j = 0; j < kMaxSlotNum; j++) 188 for (int j = 0; j < kMaxSlotNum; j++)
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 float* x_offset, float* y_offset, 444 float* x_offset, float* y_offset,
454 float* x_offset_ordinal, 445 float* x_offset_ordinal,
455 float* y_offset_ordinal, 446 float* y_offset_ordinal,
456 int* finger_count) { 447 int* finger_count) {
457 *x_offset = 0; 448 *x_offset = 0;
458 *y_offset = 0; 449 *y_offset = 0;
459 *x_offset_ordinal = 0; 450 *x_offset_ordinal = 0;
460 *y_offset_ordinal = 0; 451 *y_offset_ordinal = 0;
461 *finger_count = 2; 452 *finger_count = 2;
462 453
463 XIDeviceEvent* xiev =
464 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
465 const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid);
466 EventData data; 454 EventData data;
467 GetEventRawData(*native_event, &data); 455 GetEventRawData(*native_event, &data);
468 456
469 if (data.find(DT_CMT_SCROLL_X) != data.end()) 457 if (data.find(DT_CMT_SCROLL_X) != data.end())
470 *x_offset = data[DT_CMT_SCROLL_X] * natural_scroll_factor; 458 *x_offset = data[DT_CMT_SCROLL_X];
471 if (data.find(DT_CMT_SCROLL_Y) != data.end()) 459 if (data.find(DT_CMT_SCROLL_Y) != data.end())
472 *y_offset = data[DT_CMT_SCROLL_Y] * natural_scroll_factor; 460 *y_offset = data[DT_CMT_SCROLL_Y];
473 if (data.find(DT_CMT_ORDINAL_X) != data.end()) 461 if (data.find(DT_CMT_ORDINAL_X) != data.end())
474 *x_offset_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor; 462 *x_offset_ordinal = data[DT_CMT_ORDINAL_X];
475 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) 463 if (data.find(DT_CMT_ORDINAL_Y) != data.end())
476 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor; 464 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y];
477 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) 465 if (data.find(DT_CMT_FINGER_COUNT) != data.end())
478 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); 466 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]);
479 } 467 }
480 468
481 void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event, 469 void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event,
482 float* vx, float* vy, 470 float* vx, float* vy,
483 float* vx_ordinal, float* vy_ordinal, 471 float* vx_ordinal, float* vy_ordinal,
484 bool* is_cancel) { 472 bool* is_cancel) {
485 *vx = 0; 473 *vx = 0;
486 *vy = 0; 474 *vy = 0;
487 *vx_ordinal = 0; 475 *vx_ordinal = 0;
488 *vy_ordinal = 0; 476 *vy_ordinal = 0;
489 *is_cancel = false; 477 *is_cancel = false;
490 478
491 XIDeviceEvent* xiev =
492 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
493 const float natural_scroll_factor = GetNaturalScrollFactor(xiev->sourceid);
494 EventData data; 479 EventData data;
495 GetEventRawData(*native_event, &data); 480 GetEventRawData(*native_event, &data);
496 481
497 if (data.find(DT_CMT_FLING_X) != data.end()) 482 if (data.find(DT_CMT_FLING_X) != data.end())
498 *vx = data[DT_CMT_FLING_X] * natural_scroll_factor; 483 *vx = data[DT_CMT_FLING_X];
499 if (data.find(DT_CMT_FLING_Y) != data.end()) 484 if (data.find(DT_CMT_FLING_Y) != data.end())
500 *vy = data[DT_CMT_FLING_Y] * natural_scroll_factor; 485 *vy = data[DT_CMT_FLING_Y];
501 if (data.find(DT_CMT_FLING_STATE) != data.end()) 486 if (data.find(DT_CMT_FLING_STATE) != data.end())
502 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); 487 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]);
503 if (data.find(DT_CMT_ORDINAL_X) != data.end()) 488 if (data.find(DT_CMT_ORDINAL_X) != data.end())
504 *vx_ordinal = data[DT_CMT_ORDINAL_X] * natural_scroll_factor; 489 *vx_ordinal = data[DT_CMT_ORDINAL_X];
505 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) 490 if (data.find(DT_CMT_ORDINAL_Y) != data.end())
506 *vy_ordinal = data[DT_CMT_ORDINAL_Y] * natural_scroll_factor; 491 *vy_ordinal = data[DT_CMT_ORDINAL_Y];
507 } 492 }
508 493
509 void DeviceDataManager::GetMetricsData(const base::NativeEvent& native_event, 494 void DeviceDataManager::GetMetricsData(const base::NativeEvent& native_event,
510 GestureMetricsType* type, 495 GestureMetricsType* type,
511 float* data1, float* data2) { 496 float* data1, float* data2) {
512 *type = kGestureMetricsTypeUnknown; 497 *type = kGestureMetricsTypeUnknown;
513 *data1 = 0; 498 *data1 = 0;
514 *data2 = 0; 499 *data2 = 0;
515 500
516 EventData data; 501 EventData data;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 for (int j = start_valuator; j <= end_valuator; ++j) { 628 for (int j = start_valuator; j <= end_valuator; ++j) {
644 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; 629 valuator_lookup_[deviceid][j] = valuator_count_[deviceid];
645 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; 630 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j;
646 valuator_min_[deviceid][j] = min_value; 631 valuator_min_[deviceid][j] = min_value;
647 valuator_max_[deviceid][j] = max_value; 632 valuator_max_[deviceid][j] = max_value;
648 valuator_count_[deviceid]++; 633 valuator_count_[deviceid]++;
649 } 634 }
650 } 635 }
651 636
652 } // namespace ui 637 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/device_data_manager.h ('k') | ui/events/x/events_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698