#ifndef CONTENT_COMMON_INPUT_ACTIONS_PARSER_H_
#define CONTENT_COMMON_INPUT_ACTIONS_PARSER_H_
#include <cstddef>
#include <set>
#include <string>
#include "base/values.h"
#include "content/common/content_export.h"
#include "content/common/input/synthetic_pointer_action_list_params.h"
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
namespace content {
class CONTENT_EXPORT ActionsParser {
public:
explicit ActionsParser(base::Value value);
ActionsParser(const ActionsParser&) = delete;
ActionsParser& operator=(const ActionsParser&) = delete;
~ActionsParser();
bool Parse();
const std::string& error_message() const { return error_message_; }
SyntheticGestureParams::GestureType parsed_gesture_type() const {
CHECK(gesture_params_);
return gesture_params_->GetGestureType();
}
const SyntheticPointerActionListParams& pointer_action_params() const {
CHECK_EQ(parsed_gesture_type(),
SyntheticGestureParams::POINTER_ACTION_LIST);
return static_cast<const SyntheticPointerActionListParams&>(
*gesture_params_.get());
}
const SyntheticSmoothScrollGestureParams& smooth_scroll_params() const {
CHECK_EQ(parsed_gesture_type(),
SyntheticGestureParams::SMOOTH_SCROLL_GESTURE);
return static_cast<const SyntheticSmoothScrollGestureParams&>(
*gesture_params_.get());
}
private:
bool ActionsDictionaryUsesTestDriverApi(
const base::Value::Dict& action_sequence);
bool ParseTestDriverActionSequence(const base::Value::Dict& action_sequence);
bool ParseGpuBenchmarkingActionSequence(
const base::Value::Dict& action_sequence);
bool ParseActionItemList(const base::Value::List& actions,
std::string source_type);
bool ParseAction(const base::Value::Dict& action,
SyntheticPointerActionListParams::ParamList& param_list,
std::string source_type);
bool ParsePointerParameters(const base::Value::Dict& action_sequence);
bool ParseWheelAction(const base::Value::Dict& action, std::string subtype);
bool ParsePointerAction(
const base::Value::Dict& action,
std::string subtype,
SyntheticPointerActionListParams::ParamList& param_list);
bool ParseNullAction(const base::Value::Dict& action,
std::string subtype,
SyntheticPointerActionListParams::ParamList& param_list);
bool GetPosition(const base::Value::Dict& action,
double& position_x,
double& position_y);
bool GetScrollDelta(const base::Value::Dict& action,
int& delta_x,
int& delta_y);
bool GetPauseDuration(const base::Value::Dict& action, int& duration);
std::unique_ptr<SyntheticGestureParams> gesture_params_;
std::vector<SyntheticPointerActionListParams::ParamList>
pointer_actions_lists_;
size_t longest_action_sequence_ = 0;
size_t action_index_ = 0;
size_t input_source_count_ = 0;
std::string source_type_;
std::string pointer_type_;
std::string error_message_;
bool use_testdriver_api_ = false;
base::Value action_sequence_list_;
std::set<std::string> pointer_name_set_;
};
}
#endif