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

Side by Side Diff: content/common/input/touch_event_stream_validator.cc

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 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
OLDNEW
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_touch_event_traits.h" 9 #include "content/common/input/web_touch_event_traits.h"
10 #include "ui/events/blink/web_input_event_traits.h" 10 #include "ui/events/blink/web_input_event_traits.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 TouchEventStreamValidator::~TouchEventStreamValidator() { 43 TouchEventStreamValidator::~TouchEventStreamValidator() {
44 } 44 }
45 45
46 bool TouchEventStreamValidator::Validate(const WebTouchEvent& event, 46 bool TouchEventStreamValidator::Validate(const WebTouchEvent& event,
47 std::string* error_msg) { 47 std::string* error_msg) {
48 DCHECK(error_msg); 48 DCHECK(error_msg);
49 error_msg->clear(); 49 error_msg->clear();
50 50
51 // TouchScrollStarted is not part of a regular touch event stream. 51 // TouchScrollStarted is not part of a regular touch event stream.
52 if (event.type == WebInputEvent::TouchScrollStarted) 52 if (event.type() == WebInputEvent::TouchScrollStarted)
53 return true; 53 return true;
54 54
55 WebTouchEvent previous_event = previous_event_; 55 WebTouchEvent previous_event = previous_event_;
56 previous_event_ = event; 56 previous_event_ = event;
57 57
58 if (!event.touchesLength) { 58 if (!event.touchesLength) {
59 error_msg->append("Touch event is empty.\n"); 59 error_msg->append("Touch event is empty.\n");
60 return false; 60 return false;
61 } 61 }
62 62
63 if (!WebInputEvent::isTouchEventType(event.type)) { 63 if (!WebInputEvent::isTouchEventType(event.type())) {
64 error_msg->append(StringPrintf("Touch event has invalid type: %s\n", 64 error_msg->append(StringPrintf("Touch event has invalid type: %s\n",
65 WebInputEvent::GetName(event.type))); 65 WebInputEvent::GetName(event.type())));
66 } 66 }
67 67
68 // Allow "hard" restarting of touch stream validation. This is necessary 68 // Allow "hard" restarting of touch stream validation. This is necessary
69 // in cases where touch event forwarding ceases in response to the event ack 69 // in cases where touch event forwarding ceases in response to the event ack
70 // or removal of touch handlers. 70 // or removal of touch handlers.
71 if (WebTouchEventTraits::IsTouchSequenceStart(event)) 71 if (WebTouchEventTraits::IsTouchSequenceStart(event))
72 previous_event = WebTouchEvent(); 72 previous_event = WebTouchEvent();
73 73
74 // Unreleased points from the previous event should exist in the latest event. 74 // Unreleased points from the previous event should exist in the latest event.
75 for (unsigned i = 0; i < previous_event.touchesLength; ++i) { 75 for (unsigned i = 0; i < previous_event.touchesLength; ++i) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 } 110 }
111 111
112 switch (point.state) { 112 switch (point.state) {
113 case WebTouchPoint::StateUndefined: 113 case WebTouchPoint::StateUndefined:
114 error_msg->append( 114 error_msg->append(
115 StringPrintf("Undefined touch point state (id=%d).\n", point.id)); 115 StringPrintf("Undefined touch point state (id=%d).\n", point.id));
116 break; 116 break;
117 117
118 case WebTouchPoint::StateReleased: 118 case WebTouchPoint::StateReleased:
119 if (event.type != WebInputEvent::TouchEnd) { 119 if (event.type() != WebInputEvent::TouchEnd) {
120 error_msg->append(StringPrintf( 120 error_msg->append(StringPrintf(
121 "Released touch point (id=%d) outside touchend.\n", point.id)); 121 "Released touch point (id=%d) outside touchend.\n", point.id));
122 } else { 122 } else {
123 found_valid_state_for_type = true; 123 found_valid_state_for_type = true;
124 } 124 }
125 break; 125 break;
126 126
127 case WebTouchPoint::StatePressed: 127 case WebTouchPoint::StatePressed:
128 if (event.type != WebInputEvent::TouchStart) { 128 if (event.type() != WebInputEvent::TouchStart) {
129 error_msg->append(StringPrintf( 129 error_msg->append(StringPrintf(
130 "Pressed touch point (id=%d) outside touchstart.\n", point.id)); 130 "Pressed touch point (id=%d) outside touchstart.\n", point.id));
131 } else { 131 } else {
132 found_valid_state_for_type = true; 132 found_valid_state_for_type = true;
133 } 133 }
134 break; 134 break;
135 135
136 case WebTouchPoint::StateMoved: 136 case WebTouchPoint::StateMoved:
137 if (event.type != WebInputEvent::TouchMove) { 137 if (event.type() != WebInputEvent::TouchMove) {
138 error_msg->append(StringPrintf( 138 error_msg->append(StringPrintf(
139 "Moved touch point (id=%d) outside touchmove.\n", point.id)); 139 "Moved touch point (id=%d) outside touchmove.\n", point.id));
140 } else { 140 } else {
141 found_valid_state_for_type = true; 141 found_valid_state_for_type = true;
142 } 142 }
143 break; 143 break;
144 144
145 case WebTouchPoint::StateStationary: 145 case WebTouchPoint::StateStationary:
146 break; 146 break;
147 147
148 case WebTouchPoint::StateCancelled: 148 case WebTouchPoint::StateCancelled:
149 if (event.type != WebInputEvent::TouchCancel) { 149 if (event.type() != WebInputEvent::TouchCancel) {
150 error_msg->append(StringPrintf( 150 error_msg->append(StringPrintf(
151 "Cancelled touch point (id=%d) outside touchcancel.\n", 151 "Cancelled touch point (id=%d) outside touchcancel.\n",
152 point.id)); 152 point.id));
153 } else { 153 } else {
154 found_valid_state_for_type = true; 154 found_valid_state_for_type = true;
155 } 155 }
156 break; 156 break;
157 } 157 }
158 } 158 }
159 159
160 if (!found_valid_state_for_type) { 160 if (!found_valid_state_for_type) {
161 error_msg->append( 161 error_msg->append(
162 StringPrintf("No valid touch point corresponding to event type: %s\n", 162 StringPrintf("No valid touch point corresponding to event type: %s\n",
163 WebInputEvent::GetName(event.type))); 163 WebInputEvent::GetName(event.type())));
164 } 164 }
165 165
166 return error_msg->empty(); 166 return error_msg->empty();
167 } 167 }
168 168
169 } // namespace content 169 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698