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

Side by Side Diff: ui/base/x/valuators.h

Issue 17049002: Revert "Merge CMTEventData and ValuatorTracker" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/base/x/events_x.cc ('k') | ui/base/x/valuators.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_BASE_X_VALUATORS_H_
6 #define UI_BASE_X_VALUATORS_H_
7
8 #include "base/basictypes.h"
9 #include "ui/base/ui_export.h"
10
11 template <typename T> struct DefaultSingletonTraits;
12
13 typedef union _XEvent XEvent;
14
15 namespace ui {
16
17 // A valuator is not reported in an XEvent if it hasn't changed from the
18 // previous event from the same device. As a result, it is necessary to track
19 // the last reported valuator values for a specific device.
20 // Right now, this is only used to keep track of valuators for events coming in
21 // from touch-devices, but it can be used for other devices as well.
22 class UI_EXPORT ValuatorTracker {
23 private:
24 ValuatorTracker();
25 ~ValuatorTracker();
26
27 public:
28 // Define the valuators following the Multi-touch Protocol.
29 enum Valuator {
30 VAL_TOUCH_MAJOR = 0, // Length of the touch area.
31 VAL_TOUCH_MINOR, // Width of the touch area.
32 VAL_ORIENTATION, // Angle between the X-axis and the major axis of the
33 // touch area.
34 VAL_PRESSURE, // Pressure of the touch contact.
35
36 // NOTE: A touch event can have multiple touch points. So when we receive a
37 // touch event, we need to determine which point triggered the event.
38 // A touch point can have both a 'Slot ID' and a 'Tracking ID', and they can
39 // be (in fact, usually are) different. The 'Slot ID' ranges between 0 and
40 // (X - 1), where X is the maximum touch points supported by the device. The
41 // 'Tracking ID' can be any 16-bit value. With XInput 2.0, an XI_Motion
42 // event that comes from a currently-unused 'Slot ID' indicates the creation
43 // of a new touch point, and any event that comes with a 0 value for
44 // 'Tracking ID' marks the removal of a touch point. During the lifetime of
45 // a touchpoint, we use the 'Slot ID' as its identifier. The XI_ButtonPress
46 // and XI_ButtonRelease events are ignored.
47 #if !defined(USE_XI2_MT)
48 VAL_SLOT_ID, // ID of the finger that triggered a touch event
49 // (useful when tracking multiple simultaneous
50 // touches)
51 #endif
52 // NOTE for XInput MT: 'Tracking ID' is provided in every touch event to
53 // track individual touch. 'Tracking ID' is an unsigned 32-bit value and
54 // is increased for each new touch. It will wrap back to 0 when reaching
55 // the numerical limit.
56 VAL_TRACKING_ID, // ID of the touch point.
57
58 // Kernel timestamp from touch screen (if available).
59 VAL_TOUCH_RAW_TIMESTAMP,
60
61 VAL_LAST_ENTRY
62 };
63
64 // Returns the ValuatorTracker singleton.
65 static ValuatorTracker* GetInstance();
66
67 // Extract the Valuator from the XEvent. Return true and the value is set
68 // if the Valuator is found, false and value unchanged if the Valuator
69 // is not found.
70 bool ExtractValuator(const XEvent& xev, Valuator val, double* value);
71
72 // Normalize the Valuator with value on deviceid to fall into [0, 1].
73 // *value = (*value - min_value_of_tp) / (max_value_of_tp - min_value_of_tp)
74 // Returns true and sets the normalized value in|value| if normalization is
75 // successful. Returns false and |value| is unchanged otherwise.
76 bool NormalizeValuator(unsigned int deviceid, Valuator val, double* value);
77
78 // Extract the range of the Valuator. Return true if the range is available
79 // and written into min & max, false if the range is not available.
80 bool GetValuatorRange(unsigned int deviceid,
81 Valuator val,
82 double* min,
83 double* max);
84
85 // Sets up the internal bookkeeping of the valuator information. It currently
86 // does this for touch devices only.
87 void SetupValuator();
88
89 private:
90 // Requirement for Singleton.
91 friend struct DefaultSingletonTraits<ValuatorTracker>;
92
93 static const int kMaxDeviceNum = 128;
94
95 // Index table to find the valuator for the Valuator on the specific device
96 // by valuator_lookup_[device_id][valuator]. Use 2-D array to get fast
97 // index at the expense of space. If the kMaxDeviceNum grows larger so that
98 // the space waste becomes a concern, the 2D lookup table can be replaced by a
99 // hash map.
100 signed char valuator_lookup_[kMaxDeviceNum][VAL_LAST_ENTRY];
101
102 // Index table to find the min & max value of the Valuator on a specific
103 // device.
104 double valuator_min_[kMaxDeviceNum][VAL_LAST_ENTRY];
105 double valuator_max_[kMaxDeviceNum][VAL_LAST_ENTRY];
106
107 // Table to keep track of the last seen value for the specified valuator for
108 // a device. Defaults to 0 if the valuator was not specified in an earlier
109 // event.
110 double last_seen_valuator_[kMaxDeviceNum][VAL_LAST_ENTRY];
111
112 DISALLOW_COPY_AND_ASSIGN(ValuatorTracker);
113 };
114
115 } // namespace ui
116
117 #endif // UI_BASE_X_VALUATORS_H_
OLDNEW
« no previous file with comments | « ui/base/x/events_x.cc ('k') | ui/base/x/valuators.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698