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

Side by Side Diff: content/renderer/gpu/actions_parser.cc

Issue 2621353003: Replace mouse actions in pointer event tests with pointerActionSequence (Closed)
Patch Set: pointer mouse tests 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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/renderer/gpu/actions_parser.h" 5 #include "content/renderer/gpu/actions_parser.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 19 matching lines...) Expand all
30 SyntheticGestureParams::GestureSourceType ToSyntheticGestureSourceType( 30 SyntheticGestureParams::GestureSourceType ToSyntheticGestureSourceType(
31 std::string source_type) { 31 std::string source_type) {
32 if (source_type == "touch") 32 if (source_type == "touch")
33 return SyntheticGestureParams::TOUCH_INPUT; 33 return SyntheticGestureParams::TOUCH_INPUT;
34 else if (source_type == "mouse") 34 else if (source_type == "mouse")
35 return SyntheticGestureParams::MOUSE_INPUT; 35 return SyntheticGestureParams::MOUSE_INPUT;
36 else 36 else
37 return SyntheticGestureParams::DEFAULT_INPUT; 37 return SyntheticGestureParams::DEFAULT_INPUT;
38 } 38 }
39 39
40 SyntheticPointerActionParams::Button ToSyntheticMouseButton(
41 std::string button) {
42 if (button == "left")
43 return SyntheticPointerActionParams::Button::LEFT;
44 else if (button == "middle")
45 return SyntheticPointerActionParams::Button::MIDDLE;
46 else
tdresser 2017/01/19 14:41:57 Let's be explicit here, DCHECK if the string isn't
47 return SyntheticPointerActionParams::Button::RIGHT;
48 }
49
40 } // namespace 50 } // namespace
41 51
42 ActionsParser::ActionsParser(base::Value* pointer_actions_value) 52 ActionsParser::ActionsParser(base::Value* pointer_actions_value)
43 : longest_action_sequence_(0), 53 : longest_action_sequence_(0),
44 pointer_actions_value_(pointer_actions_value), 54 pointer_actions_value_(pointer_actions_value),
45 action_index_(0) {} 55 action_index_(0) {}
46 56
47 ActionsParser::~ActionsParser() {} 57 ActionsParser::~ActionsParser() {}
48 58
49 bool ActionsParser::ParsePointerActionSequence() { 59 bool ActionsParser::ParsePointerActionSequence() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 action_index_); 195 action_index_);
186 return false; 196 return false;
187 } 197 }
188 198
189 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) { 199 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) {
190 error_message_ = base::StringPrintf("actions[%d].actions.y is not a number", 200 error_message_ = base::StringPrintf("actions[%d].actions.y is not a number",
191 action_index_); 201 action_index_);
192 return false; 202 return false;
193 } 203 }
194 204
205 std::string button_name = "left";
206 if (action.HasKey("button") && !action.GetString("button", &button_name)) {
207 error_message_ = base::StringPrintf(
208 "actions[%d].actions.button is not a string", action_index_);
209 return false;
210 } else if (button_name != "left" && button_name != "middle" &&
211 button_name != "right") {
212 error_message_ = base::StringPrintf(
213 "actions[%d].actions.button is an unsupported button", action_index_);
214 return false;
215 }
216 SyntheticPointerActionParams::Button button =
217 ToSyntheticMouseButton(button_name);
218
195 double duration = 0; 219 double duration = 0;
196 int num_idle = 0; 220 int num_idle = 0;
197 if (pointer_action_type == 221 if (pointer_action_type ==
198 SyntheticPointerActionParams::PointerActionType::IDLE) { 222 SyntheticPointerActionParams::PointerActionType::IDLE) {
199 num_idle = 1; 223 num_idle = 1;
200 if (action.HasKey("duration") && !action.GetDouble("duration", &duration)) { 224 if (action.HasKey("duration") && !action.GetDouble("duration", &duration)) {
201 error_message_ = base::StringPrintf( 225 error_message_ = base::StringPrintf(
202 "actions[%d].actions.x is not a number", action_index_); 226 "actions[%d].actions.x is not a number", action_index_);
203 return false; 227 return false;
204 } 228 }
205 } 229 }
206 230
207 // If users pause for given seconds, we convert to the number of idle frames. 231 // If users pause for given seconds, we convert to the number of idle frames.
208 if (duration > 0) { 232 if (duration > 0) {
209 num_idle = static_cast<int>(std::ceil( 233 num_idle = static_cast<int>(std::ceil(
210 duration / cc::BeginFrameArgs::DefaultInterval().InSecondsF())); 234 duration / cc::BeginFrameArgs::DefaultInterval().InSecondsF()));
211 } 235 }
212 236
213 SyntheticPointerActionParams action_param(pointer_action_type); 237 SyntheticPointerActionParams action_param(pointer_action_type);
214 action_param.set_index(action_index_); 238 action_param.set_index(action_index_);
215 if (pointer_action_type == 239 switch (pointer_action_type) {
216 SyntheticPointerActionParams::PointerActionType::PRESS || 240 case SyntheticPointerActionParams::PointerActionType::PRESS:
217 pointer_action_type == 241 action_param.set_position(gfx::PointF(position_x, position_y));
218 SyntheticPointerActionParams::PointerActionType::MOVE) { 242 action_param.set_button(button);
219 action_param.set_position(gfx::PointF(position_x, position_y)); 243 break;
244 case SyntheticPointerActionParams::PointerActionType::MOVE:
245 action_param.set_position(gfx::PointF(position_x, position_y));
246 break;
247 case SyntheticPointerActionParams::PointerActionType::RELEASE:
248 action_param.set_button(button);
249 break;
250 case SyntheticPointerActionParams::PointerActionType::IDLE:
251 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED:
252 break;
220 } 253 }
221 param_list.push_back(action_param); 254 param_list.push_back(action_param);
222 255
223 // We queue all the IDLE actions in the action parameter list to make sure we 256 // We queue all the IDLE actions in the action parameter list to make sure we
224 // will pause long enough on the given pointer. 257 // will pause long enough on the given pointer.
225 for (int count = 1; count < num_idle; ++count) 258 for (int count = 1; count < num_idle; ++count)
226 param_list.push_back(action_param); 259 param_list.push_back(action_param);
227 260
228 return true; 261 return true;
229 } 262 }
230 263
231 } // namespace content 264 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698