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

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

Issue 95403006: x11: Cleanup how valuators are set for X events in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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_unittest.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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 return false; 575 return false;
576 if (valuator_lookup_[deviceid][type] >= 0) { 576 if (valuator_lookup_[deviceid][type] >= 0) {
577 *min = valuator_min_[deviceid][type]; 577 *min = valuator_min_[deviceid][type];
578 *max = valuator_max_[deviceid][type]; 578 *max = valuator_max_[deviceid][type];
579 return true; 579 return true;
580 } 580 }
581 return false; 581 return false;
582 } 582 }
583 583
584 void DeviceDataManager::SetDeviceListForTest( 584 void DeviceDataManager::SetDeviceListForTest(
585 const std::vector<unsigned int>& devices, 585 const std::vector<unsigned int>& touchscreen,
586 const std::vector<unsigned int>& cmt_devices, 586 const std::vector<unsigned int>& cmt_devices) {
587 const std::vector<unsigned int>& touchpads) {
588 for (int i = 0; i < kMaxDeviceNum; ++i) { 587 for (int i = 0; i < kMaxDeviceNum; ++i) {
589 valuator_count_[i] = 0; 588 valuator_count_[i] = 0;
590 valuator_lookup_[i].clear(); 589 valuator_lookup_[i].clear();
591 data_type_lookup_[i].clear(); 590 data_type_lookup_[i].clear();
592 valuator_min_[i].clear(); 591 valuator_min_[i].clear();
593 valuator_max_[i].clear(); 592 valuator_max_[i].clear();
594 for (int j = 0; j < kMaxSlotNum; j++) 593 for (int j = 0; j < kMaxSlotNum; j++)
595 last_seen_valuator_[i][j].clear(); 594 last_seen_valuator_[i][j].clear();
596 } 595 }
597 596
598 for (size_t i = 0; i < devices.size(); i++) { 597 for (size_t i = 0; i < touchscreen.size(); i++) {
599 unsigned int deviceid = devices[i]; 598 unsigned int deviceid = touchscreen[i];
600 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); 599 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd,
601 data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY); 600 0, 1000);
602 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
603 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
604 for (int j = 0; j < kMaxSlotNum; j++)
605 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
606 } 601 }
607 602
608 cmt_devices_.reset(); 603 cmt_devices_.reset();
609 for (size_t i = 0; i < cmt_devices.size(); ++i) { 604 for (size_t i = 0; i < cmt_devices.size(); ++i) {
610 unsigned int deviceid = devices[i]; 605 unsigned int deviceid = cmt_devices[i];
611 cmt_devices_[deviceid] = true; 606 cmt_devices_[deviceid] = true;
612 }
613
614 touchpads_.reset();
615 for (size_t i = 0; i < touchpads.size(); ++i) {
616 unsigned int deviceid = devices[i];
617 touchpads_[deviceid] = true; 607 touchpads_[deviceid] = true;
608 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd,
609 -1000, 1000);
618 } 610 }
619 } 611 }
620 612
621 void DeviceDataManager::SetDeviceValuatorForTest(int deviceid, 613 void DeviceDataManager::SetValuatorDataForTest(XIDeviceEvent* xievent,
622 int val_index, 614 DataType type,
623 DataType data_type, 615 double value) {
624 double min, 616 int index = valuator_lookup_[xievent->deviceid][type];
625 double max) { 617 CHECK(!XIMaskIsSet(xievent->valuators.mask, index));
626 valuator_lookup_[deviceid][data_type] = val_index; 618 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]);
627 data_type_lookup_[deviceid][val_index] = data_type; 619 XISetMask(xievent->valuators.mask, index);
628 valuator_min_[deviceid][data_type] = min;
629 valuator_max_[deviceid][data_type] = max;
630 620
631 // Recalulate the number of valuators for the device. 621 double* valuators = xievent->valuators.values;
632 valuator_count_[deviceid] = 0; 622 for (int i = 0; i < index; ++i) {
633 for (size_t i = 0; i < DT_LAST_ENTRY; ++i) { 623 if (XIMaskIsSet(xievent->valuators.mask, i))
634 if (valuator_lookup_[deviceid][i] != -1) 624 valuators++;
635 valuator_count_[deviceid]++; 625 }
626 for (int i = valuators - xievent->valuators.values;
627 i < DT_LAST_ENTRY - 1; ++i)
628 xievent->valuators.values[i + 1] = xievent->valuators.values[i];
629 *valuators = value;
630 }
631
632 void DeviceDataManager::InitializeValuatorsForTest(int deviceid,
633 int start_valuator,
634 int end_valuator,
635 double min_value,
636 double max_value) {
637 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
638 data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY);
639 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
640 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
641 for (int j = 0; j < kMaxSlotNum; j++)
642 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
643 for (int j = start_valuator; j <= end_valuator; ++j) {
644 valuator_lookup_[deviceid][j] = valuator_count_[deviceid];
645 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j;
646 valuator_min_[deviceid][j] = min_value;
647 valuator_max_[deviceid][j] = max_value;
648 valuator_count_[deviceid]++;
636 } 649 }
637 } 650 }
651
638 } // namespace ui 652 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/device_data_manager.h ('k') | ui/events/x/events_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698