| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 if (button == "middle") |
| 45 return SyntheticPointerActionParams::Button::MIDDLE; |
| 46 if (button == "right") |
| 47 return SyntheticPointerActionParams::Button::RIGHT; |
| 48 NOTREACHED() << "Unexpected button"; |
| 49 return SyntheticPointerActionParams::Button(); |
| 50 } |
| 51 |
| 40 } // namespace | 52 } // namespace |
| 41 | 53 |
| 42 ActionsParser::ActionsParser(base::Value* pointer_actions_value) | 54 ActionsParser::ActionsParser(base::Value* pointer_actions_value) |
| 43 : longest_action_sequence_(0), | 55 : longest_action_sequence_(0), |
| 44 pointer_actions_value_(pointer_actions_value), | 56 pointer_actions_value_(pointer_actions_value), |
| 45 action_index_(0) {} | 57 action_index_(0) {} |
| 46 | 58 |
| 47 ActionsParser::~ActionsParser() {} | 59 ActionsParser::~ActionsParser() {} |
| 48 | 60 |
| 49 bool ActionsParser::ParsePointerActionSequence() { | 61 bool ActionsParser::ParsePointerActionSequence() { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 action_index_); | 197 action_index_); |
| 186 return false; | 198 return false; |
| 187 } | 199 } |
| 188 | 200 |
| 189 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) { | 201 if (action.HasKey("y") && !action.GetDouble("y", &position_y)) { |
| 190 error_message_ = base::StringPrintf("actions[%d].actions.y is not a number", | 202 error_message_ = base::StringPrintf("actions[%d].actions.y is not a number", |
| 191 action_index_); | 203 action_index_); |
| 192 return false; | 204 return false; |
| 193 } | 205 } |
| 194 | 206 |
| 207 std::string button_name = "left"; |
| 208 if (action.HasKey("button") && !action.GetString("button", &button_name)) { |
| 209 error_message_ = base::StringPrintf( |
| 210 "actions[%d].actions.button is not a string", action_index_); |
| 211 return false; |
| 212 } else if (button_name != "left" && button_name != "middle" && |
| 213 button_name != "right") { |
| 214 error_message_ = base::StringPrintf( |
| 215 "actions[%d].actions.button is an unsupported button", action_index_); |
| 216 return false; |
| 217 } |
| 218 SyntheticPointerActionParams::Button button = |
| 219 ToSyntheticMouseButton(button_name); |
| 220 |
| 195 double duration = 0; | 221 double duration = 0; |
| 196 int num_idle = 0; | 222 int num_idle = 0; |
| 197 if (pointer_action_type == | 223 if (pointer_action_type == |
| 198 SyntheticPointerActionParams::PointerActionType::IDLE) { | 224 SyntheticPointerActionParams::PointerActionType::IDLE) { |
| 199 num_idle = 1; | 225 num_idle = 1; |
| 200 if (action.HasKey("duration") && !action.GetDouble("duration", &duration)) { | 226 if (action.HasKey("duration") && !action.GetDouble("duration", &duration)) { |
| 201 error_message_ = base::StringPrintf( | 227 error_message_ = base::StringPrintf( |
| 202 "actions[%d].actions.x is not a number", action_index_); | 228 "actions[%d].actions.x is not a number", action_index_); |
| 203 return false; | 229 return false; |
| 204 } | 230 } |
| 205 } | 231 } |
| 206 | 232 |
| 207 // If users pause for given seconds, we convert to the number of idle frames. | 233 // If users pause for given seconds, we convert to the number of idle frames. |
| 208 if (duration > 0) { | 234 if (duration > 0) { |
| 209 num_idle = static_cast<int>(std::ceil( | 235 num_idle = static_cast<int>(std::ceil( |
| 210 duration / cc::BeginFrameArgs::DefaultInterval().InSecondsF())); | 236 duration / cc::BeginFrameArgs::DefaultInterval().InSecondsF())); |
| 211 } | 237 } |
| 212 | 238 |
| 213 SyntheticPointerActionParams action_param(pointer_action_type); | 239 SyntheticPointerActionParams action_param(pointer_action_type); |
| 214 action_param.set_index(action_index_); | 240 action_param.set_index(action_index_); |
| 215 if (pointer_action_type == | 241 switch (pointer_action_type) { |
| 216 SyntheticPointerActionParams::PointerActionType::PRESS || | 242 case SyntheticPointerActionParams::PointerActionType::PRESS: |
| 217 pointer_action_type == | 243 action_param.set_position(gfx::PointF(position_x, position_y)); |
| 218 SyntheticPointerActionParams::PointerActionType::MOVE) { | 244 action_param.set_button(button); |
| 219 action_param.set_position(gfx::PointF(position_x, position_y)); | 245 break; |
| 246 case SyntheticPointerActionParams::PointerActionType::MOVE: |
| 247 action_param.set_position(gfx::PointF(position_x, position_y)); |
| 248 break; |
| 249 case SyntheticPointerActionParams::PointerActionType::RELEASE: |
| 250 action_param.set_button(button); |
| 251 break; |
| 252 case SyntheticPointerActionParams::PointerActionType::IDLE: |
| 253 case SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED: |
| 254 break; |
| 220 } | 255 } |
| 221 param_list.push_back(action_param); | 256 param_list.push_back(action_param); |
| 222 | 257 |
| 223 // We queue all the IDLE actions in the action parameter list to make sure we | 258 // We queue all the IDLE actions in the action parameter list to make sure we |
| 224 // will pause long enough on the given pointer. | 259 // will pause long enough on the given pointer. |
| 225 for (int count = 1; count < num_idle; ++count) | 260 for (int count = 1; count < num_idle; ++count) |
| 226 param_list.push_back(action_param); | 261 param_list.push_back(action_param); |
| 227 | 262 |
| 228 return true; | 263 return true; |
| 229 } | 264 } |
| 230 | 265 |
| 231 } // namespace content | 266 } // namespace content |
| OLD | NEW |