| 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 15 matching lines...) Expand all Loading... |
| 26 return SyntheticPointerActionParams::PointerActionType::IDLE; | 26 return SyntheticPointerActionParams::PointerActionType::IDLE; |
| 27 return SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED; | 27 return SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED; |
| 28 } | 28 } |
| 29 | 29 |
| 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 if (source_type == "pen") |
| 37 return SyntheticGestureParams::PEN_INPUT; |
| 36 else | 38 else |
| 37 return SyntheticGestureParams::DEFAULT_INPUT; | 39 return SyntheticGestureParams::DEFAULT_INPUT; |
| 38 } | 40 } |
| 39 | 41 |
| 40 SyntheticPointerActionParams::Button ToSyntheticMouseButton( | 42 SyntheticPointerActionParams::Button ToSyntheticMouseButton( |
| 41 std::string button) { | 43 std::string button) { |
| 42 if (button == "left") | 44 if (button == "left") |
| 43 return SyntheticPointerActionParams::Button::LEFT; | 45 return SyntheticPointerActionParams::Button::LEFT; |
| 44 if (button == "middle") | 46 if (button == "middle") |
| 45 return SyntheticPointerActionParams::Button::MIDDLE; | 47 return SyntheticPointerActionParams::Button::MIDDLE; |
| 46 if (button == "right") | 48 if (button == "right") |
| 47 return SyntheticPointerActionParams::Button::RIGHT; | 49 return SyntheticPointerActionParams::Button::RIGHT; |
| 48 NOTREACHED() << "Unexpected button"; | 50 NOTREACHED() << "Unexpected button"; |
| 49 return SyntheticPointerActionParams::Button(); | 51 return SyntheticPointerActionParams::Button(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 } // namespace | 54 } // namespace |
| 53 | 55 |
| 54 ActionsParser::ActionsParser(base::Value* pointer_actions_value) | 56 ActionsParser::ActionsParser(base::Value* pointer_actions_value) |
| 55 : longest_action_sequence_(0), | 57 : longest_action_sequence_(0), |
| 56 pointer_actions_value_(pointer_actions_value), | 58 pointer_actions_value_(pointer_actions_value), |
| 57 action_index_(0) {} | 59 action_index_(0) {} |
| 58 | 60 |
| 59 ActionsParser::~ActionsParser() {} | 61 ActionsParser::~ActionsParser() {} |
| 60 | 62 |
| 61 bool ActionsParser::ParsePointerActionSequence() { | 63 bool ActionsParser::ParsePointerActionSequence() { |
| 62 const base::ListValue* pointer_list; | 64 const base::ListValue* pointer_list; |
| 63 if (!pointer_actions_value_->GetAsList(&pointer_list)) { | 65 if (!pointer_actions_value_ || |
| 66 !pointer_actions_value_->GetAsList(&pointer_list)) { |
| 64 error_message_ = | 67 error_message_ = |
| 65 base::StringPrintf("pointer_list is missing or not a list"); | 68 base::StringPrintf("pointer_list is missing or not a list"); |
| 66 return false; | 69 return false; |
| 67 } | 70 } |
| 68 | 71 |
| 69 for (const auto& pointer_value : *pointer_list) { | 72 for (const auto& pointer_value : *pointer_list) { |
| 70 const base::DictionaryValue* pointer_actions; | 73 const base::DictionaryValue* pointer_actions; |
| 71 if (!pointer_value->GetAsDictionary(&pointer_actions)) { | 74 if (!pointer_value->GetAsDictionary(&pointer_actions)) { |
| 72 error_message_ = | 75 error_message_ = |
| 73 base::StringPrintf("pointer actions is missing or not a dictionary"); | 76 base::StringPrintf("pointer actions is missing or not a dictionary"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 99 return true; | 102 return true; |
| 100 } | 103 } |
| 101 | 104 |
| 102 bool ActionsParser::ParsePointerActions(const base::DictionaryValue& pointer) { | 105 bool ActionsParser::ParsePointerActions(const base::DictionaryValue& pointer) { |
| 103 std::string source_type; | 106 std::string source_type; |
| 104 if (!pointer.GetString("source", &source_type)) { | 107 if (!pointer.GetString("source", &source_type)) { |
| 105 error_message_ = | 108 error_message_ = |
| 106 base::StringPrintf("source type is missing or not a string"); | 109 base::StringPrintf("source type is missing or not a string"); |
| 107 return false; | 110 return false; |
| 108 } else if (source_type != "touch" && source_type != "mouse" && | 111 } else if (source_type != "touch" && source_type != "mouse" && |
| 109 source_type != "pointer") { | 112 source_type != "pen") { |
| 110 error_message_ = | 113 error_message_ = |
| 111 base::StringPrintf("source type is an unsupported input source"); | 114 base::StringPrintf("source type is an unsupported input source"); |
| 112 return false; | 115 return false; |
| 113 } | 116 } |
| 114 | 117 |
| 115 if (source_type_.empty()) { | 118 if (source_type_.empty()) { |
| 116 source_type_ = source_type; | 119 source_type_ = source_type; |
| 117 | 120 |
| 118 #if defined(OS_MACOSX) | 121 #if defined(OS_MACOSX) |
| 119 if (source_type == "touch") { | 122 if (source_type == "touch") { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 260 |
| 258 // We queue all the IDLE actions in the action parameter list to make sure we | 261 // We queue all the IDLE actions in the action parameter list to make sure we |
| 259 // will pause long enough on the given pointer. | 262 // will pause long enough on the given pointer. |
| 260 for (int count = 1; count < num_idle; ++count) | 263 for (int count = 1; count < num_idle; ++count) |
| 261 param_list.push_back(action_param); | 264 param_list.push_back(action_param); |
| 262 | 265 |
| 263 return true; | 266 return true; |
| 264 } | 267 } |
| 265 | 268 |
| 266 } // namespace content | 269 } // namespace content |
| OLD | NEW |