| OLD | NEW |
| 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" |
| 11 #include "cc/output/begin_frame_args.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 SyntheticPointerActionParams::PointerActionType ToSyntheticPointerActionType( | 17 SyntheticPointerActionParams::PointerActionType ToSyntheticPointerActionType( |
| 17 std::string action_type) { | 18 std::string action_type) { |
| 18 if (action_type == "pointerDown") | 19 if (action_type == "pointerDown") |
| 19 return SyntheticPointerActionParams::PointerActionType::PRESS; | 20 return SyntheticPointerActionParams::PointerActionType::PRESS; |
| 20 if (action_type == "pointerMove") | 21 if (action_type == "pointerMove") |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return false; | 125 return false; |
| 125 } | 126 } |
| 126 | 127 |
| 127 const base::ListValue* actions; | 128 const base::ListValue* actions; |
| 128 if (!pointer.GetList("actions", &actions)) { | 129 if (!pointer.GetList("actions", &actions)) { |
| 129 error_message_ = base::StringPrintf( | 130 error_message_ = base::StringPrintf( |
| 130 "pointer[%d].actions is missing or not a list", action_index_); | 131 "pointer[%d].actions is missing or not a list", action_index_); |
| 131 return false; | 132 return false; |
| 132 } | 133 } |
| 133 | 134 |
| 134 if (actions->GetSize() > longest_action_sequence_) | |
| 135 longest_action_sequence_ = actions->GetSize(); | |
| 136 | |
| 137 if (!ParseActions(*actions)) | 135 if (!ParseActions(*actions)) |
| 138 return false; | 136 return false; |
| 139 | 137 |
| 140 return true; | 138 return true; |
| 141 } | 139 } |
| 142 | 140 |
| 143 bool ActionsParser::ParseActions(const base::ListValue& actions) { | 141 bool ActionsParser::ParseActions(const base::ListValue& actions) { |
| 144 SyntheticPointerActionListParams::ParamList param_list; | 142 SyntheticPointerActionListParams::ParamList param_list; |
| 145 for (const auto& action_value : actions) { | 143 for (const auto& action_value : actions) { |
| 146 const base::DictionaryValue* action; | 144 const base::DictionaryValue* action; |
| 147 if (!action_value->GetAsDictionary(&action)) { | 145 if (!action_value->GetAsDictionary(&action)) { |
| 148 error_message_ = base::StringPrintf( | 146 error_message_ = base::StringPrintf( |
| 149 "actions[%d].actions is missing or not a dictionary", action_index_); | 147 "actions[%d].actions is missing or not a dictionary", action_index_); |
| 150 return false; | 148 return false; |
| 151 } else if (!ParseAction(*action, param_list)) { | 149 } else if (!ParseAction(*action, param_list)) { |
| 152 return false; | 150 return false; |
| 153 } | 151 } |
| 154 } | 152 } |
| 153 |
| 154 if (param_list.size() > longest_action_sequence_) |
| 155 longest_action_sequence_ = param_list.size(); |
| 156 |
| 155 pointer_actions_list_.push_back(param_list); | 157 pointer_actions_list_.push_back(param_list); |
| 156 return true; | 158 return true; |
| 157 } | 159 } |
| 158 | 160 |
| 159 bool ActionsParser::ParseAction( | 161 bool ActionsParser::ParseAction( |
| 160 const base::DictionaryValue& action, | 162 const base::DictionaryValue& action, |
| 161 SyntheticPointerActionListParams::ParamList& param_list) { | 163 SyntheticPointerActionListParams::ParamList& param_list) { |
| 162 SyntheticPointerActionParams::PointerActionType pointer_action_type = | 164 SyntheticPointerActionParams::PointerActionType pointer_action_type = |
| 163 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED; | 165 SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED; |
| 164 std::string name; | 166 std::string name; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 183 action_index_); | 185 action_index_); |
| 184 return false; | 186 return false; |
| 185 } | 187 } |
| 186 | 188 |
| 187 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) { | 189 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) { |
| 188 error_message_ = base::StringPrintf("actions[%d].actions.y is not a number", | 190 error_message_ = base::StringPrintf("actions[%d].actions.y is not a number", |
| 189 action_index_); | 191 action_index_); |
| 190 return false; | 192 return false; |
| 191 } | 193 } |
| 192 | 194 |
| 195 double duration = 0; |
| 196 int num_idle = 0; |
| 197 if (pointer_action_type == |
| 198 SyntheticPointerActionParams::PointerActionType::IDLE) { |
| 199 num_idle = 1; |
| 200 if (action.HasKey("duration") && !action.GetDouble("duration", &duration)) { |
| 201 error_message_ = base::StringPrintf( |
| 202 "actions[%d].actions.x is not a number", action_index_); |
| 203 return false; |
| 204 } |
| 205 } |
| 206 |
| 207 // If users pause for given seconds, we convert to the number of idle frames. |
| 208 if (duration > 0) { |
| 209 num_idle = static_cast<int>(std::ceil( |
| 210 duration / cc::BeginFrameArgs::DefaultInterval().InSecondsF())); |
| 211 } |
| 212 |
| 193 SyntheticPointerActionParams action_param(pointer_action_type); | 213 SyntheticPointerActionParams action_param(pointer_action_type); |
| 194 action_param.set_index(action_index_); | 214 action_param.set_index(action_index_); |
| 195 if (pointer_action_type == | 215 if (pointer_action_type == |
| 196 SyntheticPointerActionParams::PointerActionType::PRESS || | 216 SyntheticPointerActionParams::PointerActionType::PRESS || |
| 197 pointer_action_type == | 217 pointer_action_type == |
| 198 SyntheticPointerActionParams::PointerActionType::MOVE) { | 218 SyntheticPointerActionParams::PointerActionType::MOVE) { |
| 199 action_param.set_position(gfx::PointF(position_x, position_y)); | 219 action_param.set_position(gfx::PointF(position_x, position_y)); |
| 200 } | 220 } |
| 201 param_list.push_back(action_param); | 221 param_list.push_back(action_param); |
| 222 |
| 223 // We queue all the IDLE actions in the action parameter list to make sure we |
| 224 // will pause long enough on the given pointer. |
| 225 for (int count = 1; count < num_idle; ++count) |
| 226 param_list.push_back(action_param); |
| 227 |
| 202 return true; | 228 return true; |
| 203 } | 229 } |
| 204 | 230 |
| 205 } // namespace content | 231 } // namespace content |
| OLD | NEW |