OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/input/touch_event_stream_validator.h" | 5 #include "content/common/input/touch_event_stream_validator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/common/input/web_input_event_traits.h" | 9 #include "content/common/input/web_input_event_traits.h" |
10 #include "content/common/input/web_touch_event_traits.h" | 10 #include "content/common/input/web_touch_event_traits.h" |
11 | 11 |
12 using base::StringPrintf; | 12 using base::StringPrintf; |
13 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
14 using blink::WebTouchEvent; | 14 using blink::WebTouchEvent; |
15 using blink::WebTouchPoint; | 15 using blink::WebTouchPoint; |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 namespace { | 18 namespace { |
19 | 19 |
20 const WebTouchPoint* FindTouchPoint(const WebTouchEvent& event, int id) { | 20 const WebTouchPoint* FindTouchPoint(const WebTouchEvent& event, int id) { |
21 for (unsigned i = 0; i < event.touchesLength; ++i) { | 21 for (unsigned i = 0; i < event.touchesLength; ++i) { |
22 if (event.touches[i].id == id) | 22 if (event.touches[i].pointerId == id) |
23 return &event.touches[i]; | 23 return &event.touches[i]; |
24 } | 24 } |
25 return NULL; | 25 return NULL; |
26 } | 26 } |
27 | 27 |
28 std::string TouchPointIdsToString(const WebTouchEvent& event) { | 28 std::string TouchPointIdsToString(const WebTouchEvent& event) { |
29 std::stringstream ss; | 29 std::stringstream ss; |
30 for (unsigned i = 0; i < event.touchesLength; ++i) { | 30 for (unsigned i = 0; i < event.touchesLength; ++i) { |
31 if (i) | 31 if (i) |
32 ss << ","; | 32 ss << ","; |
33 ss << event.touches[i].id; | 33 ss << event.touches[i].pointerId; |
34 } | 34 } |
35 return ss.str(); | 35 return ss.str(); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 TouchEventStreamValidator::TouchEventStreamValidator() { | 40 TouchEventStreamValidator::TouchEventStreamValidator() { |
41 } | 41 } |
42 | 42 |
43 TouchEventStreamValidator::~TouchEventStreamValidator() { | 43 TouchEventStreamValidator::~TouchEventStreamValidator() { |
(...skipping 23 matching lines...) Expand all Loading... |
67 if (WebTouchEventTraits::IsTouchSequenceStart(event)) | 67 if (WebTouchEventTraits::IsTouchSequenceStart(event)) |
68 previous_event = WebTouchEvent(); | 68 previous_event = WebTouchEvent(); |
69 | 69 |
70 // Unreleased points from the previous event should exist in the latest event. | 70 // Unreleased points from the previous event should exist in the latest event. |
71 for (unsigned i = 0; i < previous_event.touchesLength; ++i) { | 71 for (unsigned i = 0; i < previous_event.touchesLength; ++i) { |
72 const WebTouchPoint& previous_point = previous_event.touches[i]; | 72 const WebTouchPoint& previous_point = previous_event.touches[i]; |
73 if (previous_point.state == WebTouchPoint::StateCancelled || | 73 if (previous_point.state == WebTouchPoint::StateCancelled || |
74 previous_point.state == WebTouchPoint::StateReleased) | 74 previous_point.state == WebTouchPoint::StateReleased) |
75 continue; | 75 continue; |
76 | 76 |
77 const WebTouchPoint* point = FindTouchPoint(event, previous_point.id); | 77 const WebTouchPoint* point = |
| 78 FindTouchPoint(event, previous_point.pointerId); |
78 if (!point) { | 79 if (!point) { |
79 error_msg->append(StringPrintf( | 80 error_msg->append(StringPrintf( |
80 "Previously active touch point (id=%d) not in new event (ids=%s).\n", | 81 "Previously active touch point (id=%d) not in new event (ids=%s).\n", |
81 previous_point.id, TouchPointIdsToString(event).c_str())); | 82 previous_point.pointerId, TouchPointIdsToString(event).c_str())); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 bool found_valid_state_for_type = false; | 86 bool found_valid_state_for_type = false; |
86 for (unsigned i = 0; i < event.touchesLength; ++i) { | 87 for (unsigned i = 0; i < event.touchesLength; ++i) { |
87 const WebTouchPoint& point = event.touches[i]; | 88 const WebTouchPoint& point = event.touches[i]; |
88 const WebTouchPoint* previous_point = | 89 const WebTouchPoint* previous_point = |
89 FindTouchPoint(previous_event, point.id); | 90 FindTouchPoint(previous_event, point.pointerId); |
90 | 91 |
91 // The point should exist in the previous event if it is not a new point. | 92 // The point should exist in the previous event if it is not a new point. |
92 if (!previous_point) { | 93 if (!previous_point) { |
93 if (point.state != WebTouchPoint::StatePressed) | 94 if (point.state != WebTouchPoint::StatePressed) |
94 error_msg->append(StringPrintf( | 95 error_msg->append(StringPrintf( |
95 "Active touch point (id=%d) not in previous event (ids=%s).\n", | 96 "Active touch point (id=%d) not in previous event (ids=%s).\n", |
96 point.id, TouchPointIdsToString(previous_event).c_str())); | 97 point.pointerId, TouchPointIdsToString(previous_event).c_str())); |
97 } else { | 98 } else { |
98 if (point.state == WebTouchPoint::StatePressed && | 99 if (point.state == WebTouchPoint::StatePressed && |
99 previous_point->state != WebTouchPoint::StateCancelled && | 100 previous_point->state != WebTouchPoint::StateCancelled && |
100 previous_point->state != WebTouchPoint::StateReleased) { | 101 previous_point->state != WebTouchPoint::StateReleased) { |
101 error_msg->append(StringPrintf( | 102 error_msg->append(StringPrintf( |
102 "Pressed touch point (id=%d) already exists in previous event " | 103 "Pressed touch point (id=%d) already exists in previous event " |
103 "(ids=%s).\n", | 104 "(ids=%s).\n", |
104 point.id, TouchPointIdsToString(previous_event).c_str())); | 105 point.pointerId, TouchPointIdsToString(previous_event).c_str())); |
105 } | 106 } |
106 } | 107 } |
107 | 108 |
108 switch (point.state) { | 109 switch (point.state) { |
109 case WebTouchPoint::StateUndefined: | 110 case WebTouchPoint::StateUndefined: |
110 error_msg->append( | 111 error_msg->append(StringPrintf("Undefined touch point state (id=%d).\n", |
111 StringPrintf("Undefined touch point state (id=%d).\n", point.id)); | 112 point.pointerId)); |
112 break; | 113 break; |
113 | 114 |
114 case WebTouchPoint::StateReleased: | 115 case WebTouchPoint::StateReleased: |
115 if (event.type != WebInputEvent::TouchEnd) { | 116 if (event.type != WebInputEvent::TouchEnd) { |
116 error_msg->append(StringPrintf( | 117 error_msg->append( |
117 "Released touch point (id=%d) outside touchend.\n", point.id)); | 118 StringPrintf("Released touch point (id=%d) outside touchend.\n", |
| 119 point.pointerId)); |
118 } else { | 120 } else { |
119 found_valid_state_for_type = true; | 121 found_valid_state_for_type = true; |
120 } | 122 } |
121 break; | 123 break; |
122 | 124 |
123 case WebTouchPoint::StatePressed: | 125 case WebTouchPoint::StatePressed: |
124 if (event.type != WebInputEvent::TouchStart) { | 126 if (event.type != WebInputEvent::TouchStart) { |
125 error_msg->append(StringPrintf( | 127 error_msg->append( |
126 "Pressed touch point (id=%d) outside touchstart.\n", point.id)); | 128 StringPrintf("Pressed touch point (id=%d) outside touchstart.\n", |
| 129 point.pointerId)); |
127 } else { | 130 } else { |
128 found_valid_state_for_type = true; | 131 found_valid_state_for_type = true; |
129 } | 132 } |
130 break; | 133 break; |
131 | 134 |
132 case WebTouchPoint::StateMoved: | 135 case WebTouchPoint::StateMoved: |
133 if (event.type != WebInputEvent::TouchMove) { | 136 if (event.type != WebInputEvent::TouchMove) { |
134 error_msg->append(StringPrintf( | 137 error_msg->append( |
135 "Moved touch point (id=%d) outside touchmove.\n", point.id)); | 138 StringPrintf("Moved touch point (id=%d) outside touchmove.\n", |
| 139 point.pointerId)); |
136 } else { | 140 } else { |
137 found_valid_state_for_type = true; | 141 found_valid_state_for_type = true; |
138 } | 142 } |
139 break; | 143 break; |
140 | 144 |
141 case WebTouchPoint::StateStationary: | 145 case WebTouchPoint::StateStationary: |
142 break; | 146 break; |
143 | 147 |
144 case WebTouchPoint::StateCancelled: | 148 case WebTouchPoint::StateCancelled: |
145 if (event.type != WebInputEvent::TouchCancel) { | 149 if (event.type != WebInputEvent::TouchCancel) { |
146 error_msg->append(StringPrintf( | 150 error_msg->append(StringPrintf( |
147 "Cancelled touch point (id=%d) outside touchcancel.\n", | 151 "Cancelled touch point (id=%d) outside touchcancel.\n", |
148 point.id)); | 152 point.pointerId)); |
149 } else { | 153 } else { |
150 found_valid_state_for_type = true; | 154 found_valid_state_for_type = true; |
151 } | 155 } |
152 break; | 156 break; |
153 } | 157 } |
154 } | 158 } |
155 | 159 |
156 if (!found_valid_state_for_type) { | 160 if (!found_valid_state_for_type) { |
157 error_msg->append( | 161 error_msg->append( |
158 StringPrintf("No valid touch point corresponding to event type: %s\n", | 162 StringPrintf("No valid touch point corresponding to event type: %s\n", |
159 WebInputEventTraits::GetName(event.type))); | 163 WebInputEventTraits::GetName(event.type))); |
160 } | 164 } |
161 | 165 |
162 return error_msg->empty(); | 166 return error_msg->empty(); |
163 } | 167 } |
164 | 168 |
165 } // namespace content | 169 } // namespace content |
OLD | NEW |