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

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

Issue 2348183003: Test synthetic pointer action on pointer event tests (Closed)
Patch Set: pointer event 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/gpu/actions_runner.h"
6
7 #include "base/format_macros.h"
8 #include "base/memory/ptr_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/values.h"
11
12 namespace content {
13
14 namespace {
15
16 SyntheticPointerActionParams::PointerActionType ToSyntheticPointerActionType(
17 std::string action_type) {
18 if (action_type == "pointerDown")
19 return SyntheticPointerActionParams::PointerActionType::PRESS;
20 if (action_type == "pointerMove")
21 return SyntheticPointerActionParams::PointerActionType::MOVE;
22 if (action_type == "pointerUp")
23 return SyntheticPointerActionParams::PointerActionType::RELEASE;
24 if (action_type == "pause")
25 return SyntheticPointerActionParams::PointerActionType::IDLE;
26 NOTREACHED() << "Invalid SyntheticPointerActionParams::PointerActionType.";
27 return SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED;
28 }
29
30 SyntheticGestureParams::GestureSourceType ToSyntheticGestureSourceType(
31 std::string source_type) {
32 if (source_type == "touch")
33 return SyntheticGestureParams::TOUCH_INPUT;
34 else if (source_type == "mouse")
35 return SyntheticGestureParams::MOUSE_INPUT;
36 else
37 return SyntheticGestureParams::DEFAULT_INPUT;
38 }
39
40 } // namespace
41
42 ActionsRunner::ActionsRunner(base::Value* value)
43 : longest_action_sequence_(0), value_(value), index_(0) {}
44
45 ActionsRunner::~ActionsRunner() {}
46
47 bool ActionsRunner::ParseSources() {
48 const base::DictionaryValue* actions;
49 if (!value_->GetAsDictionary(&actions)) {
50 error_message_ =
51 base::StringPrintf("actions is missing or not a dictionary");
52 return false;
53 }
54
55 std::string source_type;
56 if (!actions->GetString("source", &source_type)) {
57 error_message_ =
58 base::StringPrintf("source type is missing or not a string");
59 return false;
60 } else if (source_type != "touch" && source_type != "mouse" &&
61 source_type != "pointer") {
62 error_message_ =
63 base::StringPrintf("source type is an unsupported input source");
64 return false;
65 }
66
67 #if defined(OS_MACOSX)
68 if (source_type == "touch") {
69 error_message_ =
70 base::StringPrintf("Mac OS does not support touch events");
71 return false;
72 }
73 #endif // defined(OS_MACOSX)
74
75 const base::ListValue* pointer_list;
76 if (!actions->GetList("pointer", &pointer_list)) {
77 error_message_ =
78 base::StringPrintf("pointer_list is missing or not a list");
79 return false;
80 }
81
82 for (i = 0; i < pointer_list->GetSize(); i++) {
83 const base::DictionaryValue* pointer_actions;
84 if (!pointer_list->GetDictionary(i, &pointer_actions)) {
85 error_message_ =
86 base::StringPrintf("pointer actions is missing or not a dictionary");
87 return false;
88 } else if (!ParsePointerActions(*pointer_actions)) {
89 return false;
90 }
91 }
92
93 if (!gesture_params_)
94 gesture_params_ = base::MakeUnique<SyntheticPointerActionListParams>();
95
96 gesture_params_->gesture_source_type =
97 ToSyntheticGestureSourceType(source_type);
98 // Group a list of actions from all pointers into a
99 // SyntheticPointerActionListParams object, which is a list of actions, which
100 // will be dispatched together.
101 for (size_t action_index = 0; action_index < longest_action_sequence_;
102 ++action_index) {
103 SyntheticPointerActionListParams::ParamList param_list;
104 for (size_t pointer_index = 0; pointer_index < ids_.size();
105 ++pointer_index) {
106 if (pointer_actions_list_[pointer_index].size() > action_index)
107 param_list.push_back(
108 pointer_actions_list_[pointer_index][action_index]);
109 }
110 gesture_params_->PushPointerActionParamsList(param_list);
111 }
112
113 return true;
114 }
115
116 bool ActionsRunner::ParsePointerActions(
117 const base::DictionaryValue& pointer_actions) {
118 if (!pointer_actions.GetInteger("id", &index_)) {
119 error_message_ =
120 base::StringPrintf("actions[%" PRIuS "].id is missing or not a int", i);
121 return false;
122 } else if (ids_.find(index_) != ids_.end()) {
123 error_message_ =
124 base::StringPrintf("actions[%" PRIuS "].id is not unique", i);
125 return false;
126 }
127 ids_.insert(index_);
128
129 const base::ListValue* actions;
130 if (!pointer_actions.GetList("actions", &actions)) {
131 error_message_ = base::StringPrintf(
132 "actions[%" PRIuS "].actions is missing or not a list", i);
133 return false;
134 }
135
136 if (actions->GetSize() > longest_action_sequence_)
137 longest_action_sequence_ = actions->GetSize();
138 if (!ParseActions(*actions))
139 return false;
140
141 return true;
142 }
143
144 bool ActionsRunner::ParseActions(const base::ListValue& actions) {
145 SyntheticPointerActionListParams::ParamList param_list;
146 for (j = 0; j < actions.GetSize(); j++) {
147 const base::DictionaryValue* action;
148 if (!actions.GetDictionary(j, &action)) {
149 error_message_ = base::StringPrintf("actions[%" PRIuS "].actions[%" PRIuS
150 "] is missing or not a dictionary",
151 i, j);
152 return false;
153 } else if (!ParseAction(*action, param_list)) {
154 return false;
155 }
156 }
157 pointer_actions_list_.push_back(param_list);
158 return true;
159 }
160
161 bool ActionsRunner::ParseAction(
162 const base::DictionaryValue& action,
163 SyntheticPointerActionListParams::ParamList& param_list) {
164 SyntheticPointerActionParams::PointerActionType pointer_action_type =
165 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED;
166 std::string name;
167 if (!action.GetString("name", &name)) {
168 error_message_ = base::StringPrintf("actions[%" PRIuS "].actions[%" PRIuS
169 "].name is missing or not a string",
170 i, j);
171 return false;
172 }
173 if (name != "pointerDown" && name != "pointerUp" && name != "pointerMove" &&
174 name != "pause") {
175 error_message_ = base::StringPrintf("actions[%" PRIuS "].actions[%" PRIuS
176 "].name is an unsupported action name",
177 i, j);
178 return false;
179 }
180 pointer_action_type = ToSyntheticPointerActionType(name);
181
182 double position_x = 0;
183 double position_y = 0;
184 if (action.HasKey("x") && !action.GetDouble("x", &position_x)) {
185 error_message_ = base::StringPrintf(
186 "actions[%" PRIuS "].actions[%" PRIuS "].x is not a number", i, j);
187 return false;
188 }
189
190 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) {
191 error_message_ = base::StringPrintf(
192 "actions[%" PRIuS "].actions[%" PRIuS "].y is not a number", i, j);
193 return false;
194 }
195
196 SyntheticPointerActionParams action_param(pointer_action_type);
197 action_param.set_index(index_);
198 if (pointer_action_type ==
199 SyntheticPointerActionParams::PointerActionType::PRESS ||
200 pointer_action_type ==
201 SyntheticPointerActionParams::PointerActionType::MOVE) {
202 action_param.set_position(gfx::PointF(position_x, position_y));
203 }
204 param_list.push_back(action_param);
205 return true;
206 }
207
208 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/actions_runner.h ('k') | content/renderer/gpu/gpu_benchmarking_extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698