| Index: content/browser/devtools/protocol/input_handler.cc
|
| diff --git a/content/browser/devtools/protocol/input_handler.cc b/content/browser/devtools/protocol/input_handler.cc
|
| index b963044209c287436628372f8df442313c35867a..12dd6bbe95690896ac50521db01c32213678ab61 100644
|
| --- a/content/browser/devtools/protocol/input_handler.cc
|
| +++ b/content/browser/devtools/protocol/input_handler.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "base/trace_event/trace_event.h"
|
| #include "cc/output/compositor_frame_metadata.h"
|
| +#include "content/browser/frame_host/render_frame_host_impl.h"
|
| #include "content/browser/renderer_host/render_widget_host_impl.h"
|
| #include "content/common/input/synthetic_pinch_gesture_params.h"
|
| #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
|
| @@ -20,8 +21,7 @@
|
| #include "ui/gfx/geometry/point.h"
|
|
|
| namespace content {
|
| -namespace devtools {
|
| -namespace input {
|
| +namespace protocol {
|
|
|
| namespace {
|
|
|
| @@ -33,56 +33,53 @@ gfx::Vector2dF CssPixelsToVector2dF(int x, int y, float page_scale_factor) {
|
| return gfx::Vector2dF(x * page_scale_factor, y * page_scale_factor);
|
| }
|
|
|
| -bool StringToGestureSourceType(const std::string& in,
|
| +bool StringToGestureSourceType(Maybe<std::string> in,
|
| SyntheticGestureParams::GestureSourceType& out) {
|
| - if (in == kGestureSourceTypeDefault) {
|
| + if (!in.isJust()) {
|
| out = SyntheticGestureParams::GestureSourceType::DEFAULT_INPUT;
|
| return true;
|
| - } else if (in == kGestureSourceTypeTouch) {
|
| + }
|
| + if (in.fromJust() == Input::GestureSourceTypeEnum::Default) {
|
| + out = SyntheticGestureParams::GestureSourceType::DEFAULT_INPUT;
|
| + return true;
|
| + }
|
| + if (in.fromJust() == Input::GestureSourceTypeEnum::Touch) {
|
| out = SyntheticGestureParams::GestureSourceType::TOUCH_INPUT;
|
| return true;
|
| - } else if (in == kGestureSourceTypeMouse) {
|
| + }
|
| + if (in.fromJust() == Input::GestureSourceTypeEnum::Mouse) {
|
| out = SyntheticGestureParams::GestureSourceType::MOUSE_INPUT;
|
| return true;
|
| - } else {
|
| - return false;
|
| }
|
| + return false;
|
| }
|
|
|
| -}
|
| -
|
| -typedef DevToolsProtocolClient::Response Response;
|
| -
|
| -namespace {
|
| -
|
| -void SetEventModifiers(blink::WebInputEvent* event, const int* modifiers) {
|
| - if (!modifiers)
|
| - return;
|
| - if (*modifiers & 1)
|
| +void SetEventModifiers(blink::WebInputEvent* event, int modifiers) {
|
| + if (modifiers & 1)
|
| event->modifiers |= blink::WebInputEvent::AltKey;
|
| - if (*modifiers & 2)
|
| + if (modifiers & 2)
|
| event->modifiers |= blink::WebInputEvent::ControlKey;
|
| - if (*modifiers & 4)
|
| + if (modifiers & 4)
|
| event->modifiers |= blink::WebInputEvent::MetaKey;
|
| - if (*modifiers & 8)
|
| + if (modifiers & 8)
|
| event->modifiers |= blink::WebInputEvent::ShiftKey;
|
| }
|
|
|
| -void SetEventTimestamp(blink::WebInputEvent* event, const double* timestamp) {
|
| +void SetEventTimestamp(blink::WebInputEvent* event, Maybe<double> timestamp) {
|
| // Convert timestamp, in seconds since unix epoch, to an event timestamp
|
| // which is time ticks since platform start time.
|
| - base::TimeTicks ticks = timestamp
|
| - ? base::TimeDelta::FromSecondsD(*timestamp) +
|
| - base::TimeTicks::UnixEpoch()
|
| - : base::TimeTicks::Now();
|
| + base::TimeTicks ticks = timestamp.isJust()
|
| + ? base::TimeDelta::FromSecondsD(timestamp.fromJust()) +
|
| + base::TimeTicks::UnixEpoch()
|
| + : base::TimeTicks::Now();
|
| event->timeStampSeconds = (ticks - base::TimeTicks()).InSecondsF();
|
| }
|
|
|
| -bool SetKeyboardEventText(blink::WebUChar* to, const std::string* from) {
|
| - if (!from)
|
| +bool SetKeyboardEventText(blink::WebUChar* to, Maybe<std::string> from) {
|
| + if (!from.isJust())
|
| return true;
|
|
|
| - base::string16 text16 = base::UTF8ToUTF16(*from);
|
| + base::string16 text16 = base::UTF8ToUTF16(from.fromJust());
|
| if (text16.size() > blink::WebKeyboardEvent::textLengthCap)
|
| return false;
|
|
|
| @@ -92,19 +89,19 @@ bool SetKeyboardEventText(blink::WebUChar* to, const std::string* from) {
|
| }
|
|
|
| bool SetMouseEventButton(blink::WebMouseEvent* event,
|
| - const std::string* button) {
|
| - if (!button)
|
| + const std::string& button) {
|
| + if (button.empty())
|
| return true;
|
|
|
| - if (*button == dispatch_mouse_event::kButtonNone) {
|
| + if (button == Input::DispatchMouseEvent::ButtonEnum::None) {
|
| event->button = blink::WebMouseEvent::Button::NoButton;
|
| - } else if (*button == dispatch_mouse_event::kButtonLeft) {
|
| + } else if (button == Input::DispatchMouseEvent::ButtonEnum::Left) {
|
| event->button = blink::WebMouseEvent::Button::Left;
|
| event->modifiers |= blink::WebInputEvent::LeftButtonDown;
|
| - } else if (*button == dispatch_mouse_event::kButtonMiddle) {
|
| + } else if (button == Input::DispatchMouseEvent::ButtonEnum::Middle) {
|
| event->button = blink::WebMouseEvent::Button::Middle;
|
| event->modifiers |= blink::WebInputEvent::MiddleButtonDown;
|
| - } else if (*button == dispatch_mouse_event::kButtonRight) {
|
| + } else if (button == Input::DispatchMouseEvent::ButtonEnum::Right) {
|
| event->button = blink::WebMouseEvent::Button::Right;
|
| event->modifiers |= blink::WebInputEvent::RightButtonDown;
|
| } else {
|
| @@ -114,11 +111,11 @@ bool SetMouseEventButton(blink::WebMouseEvent* event,
|
| }
|
|
|
| bool SetMouseEventType(blink::WebMouseEvent* event, const std::string& type) {
|
| - if (type == dispatch_mouse_event::kTypeMousePressed) {
|
| + if (type == Input::DispatchMouseEvent::TypeEnum::MousePressed) {
|
| event->type = blink::WebInputEvent::MouseDown;
|
| - } else if (type == dispatch_mouse_event::kTypeMouseReleased) {
|
| + } else if (type == Input::DispatchMouseEvent::TypeEnum::MouseReleased) {
|
| event->type = blink::WebInputEvent::MouseUp;
|
| - } else if (type == dispatch_mouse_event::kTypeMouseMoved) {
|
| + } else if (type == Input::DispatchMouseEvent::TypeEnum::MouseMoved) {
|
| event->type = blink::WebInputEvent::MouseMove;
|
| } else {
|
| return false;
|
| @@ -126,23 +123,78 @@ bool SetMouseEventType(blink::WebMouseEvent* event, const std::string& type) {
|
| return true;
|
| }
|
|
|
| +void SendSynthesizePinchGestureResponse(
|
| + std::unique_ptr<Input::Backend::SynthesizePinchGestureCallback> callback,
|
| + SyntheticGesture::Result result) {
|
| + if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
|
| + callback->sendSuccess();
|
| + } else {
|
| + callback->sendFailure(Response::Error(
|
| + base::StringPrintf("Synthetic pinch failed, result was %d", result)));
|
| + }
|
| +}
|
| +
|
| +class TapGestureResponse {
|
| + public:
|
| + TapGestureResponse(
|
| + std::unique_ptr<Input::Backend::SynthesizeTapGestureCallback> callback,
|
| + int count)
|
| + : callback_(std::move(callback)),
|
| + count_(count) {
|
| + }
|
| +
|
| + void OnGestureResult(SyntheticGesture::Result result) {
|
| + --count_;
|
| + // Still waiting for more taps to finish.
|
| + if (result == SyntheticGesture::Result::GESTURE_FINISHED && count_)
|
| + return;
|
| + if (callback_) {
|
| + if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
|
| + callback_->sendSuccess();
|
| + } else {
|
| + callback_->sendFailure(Response::Error(
|
| + base::StringPrintf("Synthetic tap failed, result was %d", result)));
|
| + }
|
| + callback_.reset();
|
| + }
|
| + if (!count_)
|
| + delete this;
|
| + }
|
| +
|
| + private:
|
| + std::unique_ptr<Input::Backend::SynthesizeTapGestureCallback> callback_;
|
| + int count_;
|
| +};
|
| +
|
| +void SendSynthesizeScrollGestureResponse(
|
| + std::unique_ptr<Input::Backend::SynthesizeScrollGestureCallback> callback,
|
| + SyntheticGesture::Result result) {
|
| + if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
|
| + callback->sendSuccess();
|
| + } else {
|
| + callback->sendFailure(Response::Error(
|
| + base::StringPrintf("Synthetic scroll failed, result was %d", result)));
|
| + }
|
| +}
|
| +
|
| } // namespace
|
|
|
| InputHandler::InputHandler()
|
| : host_(NULL),
|
| page_scale_factor_(1.0),
|
| + last_id_(0),
|
| weak_factory_(this) {
|
| }
|
|
|
| InputHandler::~InputHandler() {
|
| }
|
|
|
| -void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) {
|
| +void InputHandler::SetRenderFrameHost(RenderFrameHostImpl* host) {
|
| host_ = host;
|
| }
|
|
|
| -void InputHandler::SetClient(std::unique_ptr<Client> client) {
|
| - client_.swap(client);
|
| +void InputHandler::Wire(UberDispatcher* dispatcher) {
|
| + Input::Dispatcher::wire(dispatcher, this);
|
| }
|
|
|
| void InputHandler::OnSwapCompositorFrame(
|
| @@ -151,69 +203,73 @@ void InputHandler::OnSwapCompositorFrame(
|
| scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size;
|
| }
|
|
|
| +Response InputHandler::Disable() {
|
| + return Response::OK();
|
| +}
|
| +
|
| Response InputHandler::DispatchKeyEvent(
|
| const std::string& type,
|
| - const int* modifiers,
|
| - const double* timestamp,
|
| - const std::string* text,
|
| - const std::string* unmodified_text,
|
| - const std::string* key_identifier,
|
| - const std::string* code,
|
| - const std::string* key,
|
| - const int* windows_virtual_key_code,
|
| - const int* native_virtual_key_code,
|
| - const bool* auto_repeat,
|
| - const bool* is_keypad,
|
| - const bool* is_system_key) {
|
| + Maybe<int> modifiers,
|
| + Maybe<double> timestamp,
|
| + Maybe<std::string> text,
|
| + Maybe<std::string> unmodified_text,
|
| + Maybe<std::string> key_identifier,
|
| + Maybe<std::string> code,
|
| + Maybe<std::string> key,
|
| + Maybe<int> windows_virtual_key_code,
|
| + Maybe<int> native_virtual_key_code,
|
| + Maybe<bool> auto_repeat,
|
| + Maybe<bool> is_keypad,
|
| + Maybe<bool> is_system_key) {
|
| NativeWebKeyboardEvent event;
|
| event.skip_in_browser = true;
|
|
|
| - if (type == dispatch_key_event::kTypeKeyDown) {
|
| + if (type == Input::DispatchKeyEvent::TypeEnum::KeyDown) {
|
| event.type = blink::WebInputEvent::KeyDown;
|
| - } else if (type == dispatch_key_event::kTypeKeyUp) {
|
| + } else if (type == Input::DispatchKeyEvent::TypeEnum::KeyUp) {
|
| event.type = blink::WebInputEvent::KeyUp;
|
| - } else if (type == dispatch_key_event::kTypeChar) {
|
| + } else if (type == Input::DispatchKeyEvent::TypeEnum::Char) {
|
| event.type = blink::WebInputEvent::Char;
|
| - } else if (type == dispatch_key_event::kTypeRawKeyDown) {
|
| + } else if (type == Input::DispatchKeyEvent::TypeEnum::RawKeyDown) {
|
| event.type = blink::WebInputEvent::RawKeyDown;
|
| } else {
|
| return Response::InvalidParams(
|
| base::StringPrintf("Unexpected event type '%s'", type.c_str()));
|
| }
|
|
|
| - SetEventModifiers(&event, modifiers);
|
| - SetEventTimestamp(&event, timestamp);
|
| - if (!SetKeyboardEventText(event.text, text))
|
| + SetEventModifiers(&event, modifiers.fromMaybe(0));
|
| + SetEventTimestamp(&event, std::move(timestamp));
|
| + if (!SetKeyboardEventText(event.text, std::move(text)))
|
| return Response::InvalidParams("Invalid 'text' parameter");
|
| - if (!SetKeyboardEventText(event.unmodifiedText, unmodified_text))
|
| + if (!SetKeyboardEventText(event.unmodifiedText, std::move(unmodified_text)))
|
| return Response::InvalidParams("Invalid 'unmodifiedText' parameter");
|
|
|
| - if (windows_virtual_key_code)
|
| - event.windowsKeyCode = *windows_virtual_key_code;
|
| - if (native_virtual_key_code)
|
| - event.nativeKeyCode = *native_virtual_key_code;
|
| - if (auto_repeat && *auto_repeat)
|
| + if (windows_virtual_key_code.isJust())
|
| + event.windowsKeyCode = windows_virtual_key_code.fromJust();
|
| + if (native_virtual_key_code.isJust())
|
| + event.nativeKeyCode = native_virtual_key_code.fromJust();
|
| + if (auto_repeat.fromMaybe(false))
|
| event.modifiers |= blink::WebInputEvent::IsAutoRepeat;
|
| - if (is_keypad && *is_keypad)
|
| + if (is_keypad.fromMaybe(false))
|
| event.modifiers |= blink::WebInputEvent::IsKeyPad;
|
| - if (is_system_key)
|
| - event.isSystemKey = *is_system_key;
|
| + if (is_system_key.isJust())
|
| + event.isSystemKey = is_system_key.fromJust();
|
|
|
| - if (code) {
|
| + if (code.isJust()) {
|
| event.domCode = static_cast<int>(
|
| - ui::KeycodeConverter::CodeStringToDomCode(*code));
|
| + ui::KeycodeConverter::CodeStringToDomCode(code.fromJust()));
|
| }
|
|
|
| - if (key) {
|
| + if (key.isJust()) {
|
| event.domKey = static_cast<int>(
|
| - ui::KeycodeConverter::KeyStringToDomKey(*key));
|
| + ui::KeycodeConverter::KeyStringToDomKey(key.fromJust()));
|
| }
|
|
|
| - if (!host_)
|
| - return Response::ServerError("Could not connect to view");
|
| + if (!host_ || !host_->GetRenderWidgetHost())
|
| + return Response::InternalError();
|
|
|
| - host_->Focus();
|
| - host_->ForwardKeyboardEvent(event);
|
| + host_->GetRenderWidgetHost()->Focus();
|
| + host_->GetRenderWidgetHost()->ForwardKeyboardEvent(event);
|
| return Response::OK();
|
| }
|
|
|
| @@ -221,19 +277,19 @@ Response InputHandler::DispatchMouseEvent(
|
| const std::string& type,
|
| int x,
|
| int y,
|
| - const int* modifiers,
|
| - const double* timestamp,
|
| - const std::string* button,
|
| - const int* click_count) {
|
| + Maybe<int> modifiers,
|
| + Maybe<double> timestamp,
|
| + Maybe<std::string> button,
|
| + Maybe<int> click_count) {
|
| blink::WebMouseEvent event;
|
|
|
| if (!SetMouseEventType(&event, type)) {
|
| return Response::InvalidParams(
|
| base::StringPrintf("Unexpected event type '%s'", type.c_str()));
|
| }
|
| - SetEventModifiers(&event, modifiers);
|
| - SetEventTimestamp(&event, timestamp);
|
| - if (!SetMouseEventButton(&event, button))
|
| + SetEventModifiers(&event, modifiers.fromMaybe(0));
|
| + SetEventTimestamp(&event, std::move(timestamp));
|
| + if (!SetMouseEventButton(&event, button.fromMaybe("")))
|
| return Response::InvalidParams("Invalid mouse button");
|
|
|
| event.x = x * page_scale_factor_;
|
| @@ -242,14 +298,14 @@ Response InputHandler::DispatchMouseEvent(
|
| event.windowY = y * page_scale_factor_;
|
| event.globalX = x * page_scale_factor_;
|
| event.globalY = y * page_scale_factor_;
|
| - event.clickCount = click_count ? *click_count : 0;
|
| + event.clickCount = click_count.fromMaybe(0);
|
| event.pointerType = blink::WebPointerProperties::PointerType::Mouse;
|
|
|
| - if (!host_)
|
| - return Response::ServerError("Could not connect to view");
|
| + if (!host_ || !host_->GetRenderWidgetHost())
|
| + return Response::InternalError();
|
|
|
| - host_->Focus();
|
| - host_->ForwardMouseEvent(event);
|
| + host_->GetRenderWidgetHost()->Focus();
|
| + host_->GetRenderWidgetHost()->ForwardMouseEvent(event);
|
| return Response::OK();
|
| }
|
|
|
| @@ -258,21 +314,21 @@ Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type,
|
| int y,
|
| double timestamp,
|
| const std::string& button,
|
| - double* delta_x,
|
| - double* delta_y,
|
| - int* modifiers,
|
| - int* click_count) {
|
| + Maybe<double> delta_x,
|
| + Maybe<double> delta_y,
|
| + Maybe<int> modifiers,
|
| + Maybe<int> click_count) {
|
| blink::WebMouseWheelEvent wheel_event;
|
| blink::WebMouseEvent mouse_event;
|
| blink::WebMouseEvent* event = &mouse_event;
|
|
|
| - if (type == emulate_touch_from_mouse_event::kTypeMouseWheel) {
|
| - if (!delta_x || !delta_y) {
|
| + if (type == Input::EmulateTouchFromMouseEvent::TypeEnum::MouseWheel) {
|
| + if (!delta_x.isJust() || !delta_y.isJust()) {
|
| return Response::InvalidParams(
|
| "'deltaX' and 'deltaY' are expected for mouseWheel event");
|
| }
|
| - wheel_event.deltaX = static_cast<float>(*delta_x);
|
| - wheel_event.deltaY = static_cast<float>(*delta_y);
|
| + wheel_event.deltaX = static_cast<float>(delta_x.fromJust());
|
| + wheel_event.deltaY = static_cast<float>(delta_y.fromJust());
|
| event = &wheel_event;
|
| event->type = blink::WebInputEvent::MouseWheel;
|
| } else if (!SetMouseEventType(event, type)) {
|
| @@ -280,9 +336,9 @@ Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type,
|
| base::StringPrintf("Unexpected event type '%s'", type.c_str()));
|
| }
|
|
|
| - SetEventModifiers(event, modifiers);
|
| - SetEventTimestamp(event, ×tamp);
|
| - if (!SetMouseEventButton(event, &button))
|
| + SetEventModifiers(event, modifiers.fromMaybe(0));
|
| + SetEventTimestamp(event, Maybe<double>(timestamp));
|
| + if (!SetMouseEventButton(event, button))
|
| return Response::InvalidParams("Invalid mouse button");
|
|
|
| event->x = x;
|
| @@ -291,28 +347,30 @@ Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type,
|
| event->windowY = y;
|
| event->globalX = x;
|
| event->globalY = y;
|
| - event->clickCount = click_count ? *click_count : 0;
|
| + event->clickCount = click_count.fromMaybe(0);
|
| event->pointerType = blink::WebPointerProperties::PointerType::Touch;
|
|
|
| - if (!host_)
|
| - return Response::ServerError("Could not connect to view");
|
| + if (!host_ || !host_->GetRenderWidgetHost())
|
| + return Response::InternalError();
|
|
|
| if (event->type == blink::WebInputEvent::MouseWheel)
|
| - host_->ForwardWheelEvent(wheel_event);
|
| + host_->GetRenderWidgetHost()->ForwardWheelEvent(wheel_event);
|
| else
|
| - host_->ForwardMouseEvent(mouse_event);
|
| + host_->GetRenderWidgetHost()->ForwardMouseEvent(mouse_event);
|
| return Response::OK();
|
| }
|
|
|
| -Response InputHandler::SynthesizePinchGesture(
|
| - DevToolsCommandId command_id,
|
| +void InputHandler::SynthesizePinchGesture(
|
| int x,
|
| int y,
|
| double scale_factor,
|
| - const int* relative_speed,
|
| - const std::string* gesture_source_type) {
|
| - if (!host_)
|
| - return Response::ServerError("Could not connect to view");
|
| + Maybe<int> relative_speed,
|
| + Maybe<std::string> gesture_source_type,
|
| + std::unique_ptr<SynthesizePinchGestureCallback> callback) {
|
| + if (!host_ || !host_->GetRenderWidgetHost()) {
|
| + callback->sendFailure(Response::InternalError());
|
| + return;
|
| + }
|
|
|
| SyntheticPinchGestureParams gesture_params;
|
| const int kDefaultRelativeSpeed = 800;
|
| @@ -320,38 +378,40 @@ Response InputHandler::SynthesizePinchGesture(
|
| gesture_params.scale_factor = scale_factor;
|
| gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_);
|
| gesture_params.relative_pointer_speed_in_pixels_s =
|
| - relative_speed ? *relative_speed : kDefaultRelativeSpeed;
|
| + relative_speed.fromMaybe(kDefaultRelativeSpeed);
|
|
|
| if (!StringToGestureSourceType(
|
| - gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault,
|
| + std::move(gesture_source_type),
|
| gesture_params.gesture_source_type)) {
|
| - return Response::InvalidParams("gestureSourceType");
|
| + callback->sendFailure(
|
| + Response::InvalidParams("Unknown gestureSourceType"));
|
| + return;
|
| }
|
|
|
| - host_->QueueSyntheticGesture(
|
| + host_->GetRenderWidgetHost()->QueueSyntheticGesture(
|
| SyntheticGesture::Create(gesture_params),
|
| - base::Bind(&InputHandler::SendSynthesizePinchGestureResponse,
|
| - weak_factory_.GetWeakPtr(), command_id));
|
| -
|
| - return Response::OK();
|
| + base::Bind(&SendSynthesizePinchGestureResponse,
|
| + base::Passed(std::move(callback))));
|
| }
|
|
|
| -Response InputHandler::SynthesizeScrollGesture(
|
| - DevToolsCommandId command_id,
|
| +void InputHandler::SynthesizeScrollGesture(
|
| int x,
|
| int y,
|
| - const int* x_distance,
|
| - const int* y_distance,
|
| - const int* x_overscroll,
|
| - const int* y_overscroll,
|
| - const bool* prevent_fling,
|
| - const int* speed,
|
| - const std::string* gesture_source_type,
|
| - const int* repeat_count,
|
| - const int* repeat_delay_ms,
|
| - const std::string* interaction_marker_name) {
|
| - if (!host_)
|
| - return Response::ServerError("Could not connect to view");
|
| + Maybe<int> x_distance,
|
| + Maybe<int> y_distance,
|
| + Maybe<int> x_overscroll,
|
| + Maybe<int> y_overscroll,
|
| + Maybe<bool> prevent_fling,
|
| + Maybe<int> speed,
|
| + Maybe<std::string> gesture_source_type,
|
| + Maybe<int> repeat_count,
|
| + Maybe<int> repeat_delay_ms,
|
| + Maybe<std::string> interaction_marker_name,
|
| + std::unique_ptr<SynthesizeScrollGestureCallback> callback) {
|
| + if (!host_ || !host_->GetRenderWidgetHost()) {
|
| + callback->sendFailure(Response::InternalError());
|
| + return;
|
| + }
|
|
|
| SyntheticSmoothScrollGestureParams gesture_params;
|
| const bool kDefaultPreventFling = true;
|
| @@ -359,34 +419,33 @@ Response InputHandler::SynthesizeScrollGesture(
|
|
|
| gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_);
|
| gesture_params.prevent_fling =
|
| - prevent_fling ? *prevent_fling : kDefaultPreventFling;
|
| - gesture_params.speed_in_pixels_s = speed ? *speed : kDefaultSpeed;
|
| + prevent_fling.fromMaybe(kDefaultPreventFling);
|
| + gesture_params.speed_in_pixels_s = speed.fromMaybe(kDefaultSpeed);
|
|
|
| - if (x_distance || y_distance) {
|
| + if (x_distance.fromJust() || y_distance.fromJust()) {
|
| gesture_params.distances.push_back(
|
| - CssPixelsToVector2dF(x_distance ? *x_distance : 0,
|
| - y_distance ? *y_distance : 0, page_scale_factor_));
|
| + CssPixelsToVector2dF(x_distance.fromMaybe(0),
|
| + y_distance.fromMaybe(0), page_scale_factor_));
|
| }
|
|
|
| - if (x_overscroll || y_overscroll) {
|
| + if (x_overscroll.isJust() || y_overscroll.isJust()) {
|
| gesture_params.distances.push_back(CssPixelsToVector2dF(
|
| - x_overscroll ? -*x_overscroll : 0, y_overscroll ? -*y_overscroll : 0,
|
| + -x_overscroll.fromMaybe(0), -y_overscroll.fromMaybe(0),
|
| page_scale_factor_));
|
| }
|
|
|
| if (!StringToGestureSourceType(
|
| - gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault,
|
| + std::move(gesture_source_type),
|
| gesture_params.gesture_source_type)) {
|
| - return Response::InvalidParams("gestureSourceType");
|
| + callback->sendFailure(
|
| + Response::InvalidParams("Unknown gestureSourceType"));
|
| + return;
|
| }
|
|
|
| SynthesizeRepeatingScroll(
|
| - gesture_params, repeat_count ? *repeat_count : 0,
|
| - base::TimeDelta::FromMilliseconds(repeat_delay_ms ? *repeat_delay_ms
|
| - : 250),
|
| - interaction_marker_name ? *interaction_marker_name : "", command_id);
|
| -
|
| - return Response::OK();
|
| + gesture_params, repeat_count.fromMaybe(0),
|
| + base::TimeDelta::FromMilliseconds(repeat_delay_ms.fromMaybe(250)),
|
| + interaction_marker_name.fromMaybe(""), ++last_id_, std::move(callback));
|
| }
|
|
|
| void InputHandler::SynthesizeRepeatingScroll(
|
| @@ -394,18 +453,20 @@ void InputHandler::SynthesizeRepeatingScroll(
|
| int repeat_count,
|
| base::TimeDelta repeat_delay,
|
| std::string interaction_marker_name,
|
| - DevToolsCommandId command_id) {
|
| + int id,
|
| + std::unique_ptr<SynthesizeScrollGestureCallback> callback) {
|
| if (!interaction_marker_name.empty()) {
|
| // TODO(alexclarke): Can we move this elsewhere? It doesn't really fit here.
|
| TRACE_EVENT_COPY_ASYNC_BEGIN0("benchmark", interaction_marker_name.c_str(),
|
| - command_id.call_id);
|
| + id);
|
| }
|
|
|
| - host_->QueueSyntheticGesture(
|
| + host_->GetRenderWidgetHost()->QueueSyntheticGesture(
|
| SyntheticGesture::Create(gesture_params),
|
| base::Bind(&InputHandler::OnScrollFinished, weak_factory_.GetWeakPtr(),
|
| gesture_params, repeat_count, repeat_delay,
|
| - interaction_marker_name, command_id));
|
| + interaction_marker_name, id,
|
| + base::Passed(std::move(callback))));
|
| }
|
|
|
| void InputHandler::OnScrollFinished(
|
| @@ -413,11 +474,12 @@ void InputHandler::OnScrollFinished(
|
| int repeat_count,
|
| base::TimeDelta repeat_delay,
|
| std::string interaction_marker_name,
|
| - DevToolsCommandId command_id,
|
| + int id,
|
| + std::unique_ptr<SynthesizeScrollGestureCallback> callback,
|
| SyntheticGesture::Result result) {
|
| if (!interaction_marker_name.empty()) {
|
| TRACE_EVENT_COPY_ASYNC_END0("benchmark", interaction_marker_name.c_str(),
|
| - command_id.call_id);
|
| + id);
|
| }
|
|
|
| if (repeat_count > 0) {
|
| @@ -425,102 +487,56 @@ void InputHandler::OnScrollFinished(
|
| FROM_HERE,
|
| base::Bind(&InputHandler::SynthesizeRepeatingScroll,
|
| weak_factory_.GetWeakPtr(), gesture_params, repeat_count - 1,
|
| - repeat_delay, interaction_marker_name, command_id),
|
| + repeat_delay, interaction_marker_name, id,
|
| + base::Passed(std::move(callback))),
|
| repeat_delay);
|
| } else {
|
| - SendSynthesizeScrollGestureResponse(command_id, result);
|
| + SendSynthesizeScrollGestureResponse(std::move(callback), result);
|
| }
|
| }
|
|
|
| -Response InputHandler::SynthesizeTapGesture(
|
| - DevToolsCommandId command_id,
|
| +void InputHandler::SynthesizeTapGesture(
|
| int x,
|
| int y,
|
| - const int* duration,
|
| - const int* tap_count,
|
| - const std::string* gesture_source_type) {
|
| - if (!host_)
|
| - return Response::ServerError("Could not connect to view");
|
| + Maybe<int> duration,
|
| + Maybe<int> tap_count,
|
| + Maybe<std::string> gesture_source_type,
|
| + std::unique_ptr<SynthesizeTapGestureCallback> callback) {
|
| + if (!host_ || !host_->GetRenderWidgetHost()) {
|
| + callback->sendFailure(Response::InternalError());
|
| + return;
|
| + }
|
|
|
| SyntheticTapGestureParams gesture_params;
|
| const int kDefaultDuration = 50;
|
| const int kDefaultTapCount = 1;
|
|
|
| gesture_params.position = CssPixelsToPointF(x, y, page_scale_factor_);
|
| - gesture_params.duration_ms = duration ? *duration : kDefaultDuration;
|
| + gesture_params.duration_ms = duration.fromMaybe(kDefaultDuration);
|
|
|
| if (!StringToGestureSourceType(
|
| - gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault,
|
| + std::move(gesture_source_type),
|
| gesture_params.gesture_source_type)) {
|
| - return Response::InvalidParams("gestureSourceType");
|
| - }
|
| -
|
| - if (!tap_count)
|
| - tap_count = &kDefaultTapCount;
|
| -
|
| - for (int i = 0; i < *tap_count; i++) {
|
| - // If we're doing more than one tap, don't send the response to the client
|
| - // until we've completed the last tap.
|
| - bool is_last_tap = i == *tap_count - 1;
|
| - host_->QueueSyntheticGesture(
|
| - SyntheticGesture::Create(gesture_params),
|
| - base::Bind(&InputHandler::SendSynthesizeTapGestureResponse,
|
| - weak_factory_.GetWeakPtr(), command_id, is_last_tap));
|
| - }
|
| -
|
| - return Response::OK();
|
| -}
|
| -
|
| -Response InputHandler::DispatchTouchEvent(
|
| - const std::string& type,
|
| - const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points,
|
| - const int* modifiers,
|
| - const double* timestamp) {
|
| - return Response::FallThrough();
|
| -}
|
| -
|
| -void InputHandler::SendSynthesizePinchGestureResponse(
|
| - DevToolsCommandId command_id,
|
| - SyntheticGesture::Result result) {
|
| - if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
|
| - client_->SendSynthesizePinchGestureResponse(
|
| - command_id, SynthesizePinchGestureResponse::Create());
|
| - } else {
|
| - client_->SendError(command_id,
|
| - Response::InternalError(base::StringPrintf(
|
| - "Synthetic pinch failed, result was %d", result)));
|
| + callback->sendFailure(
|
| + Response::InvalidParams("Unknown gestureSourceType"));
|
| + return;
|
| }
|
| -}
|
|
|
| -void InputHandler::SendSynthesizeScrollGestureResponse(
|
| - DevToolsCommandId command_id,
|
| - SyntheticGesture::Result result) {
|
| - if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
|
| - client_->SendSynthesizeScrollGestureResponse(
|
| - command_id, SynthesizeScrollGestureResponse::Create());
|
| - } else {
|
| - client_->SendError(command_id,
|
| - Response::InternalError(base::StringPrintf(
|
| - "Synthetic scroll failed, result was %d", result)));
|
| + int count = tap_count.fromMaybe(kDefaultTapCount);
|
| + if (!count) {
|
| + callback->sendSuccess();
|
| + return;
|
| }
|
| -}
|
|
|
| -void InputHandler::SendSynthesizeTapGestureResponse(
|
| - DevToolsCommandId command_id,
|
| - bool send_success,
|
| - SyntheticGesture::Result result) {
|
| - if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
|
| - if (send_success) {
|
| - client_->SendSynthesizeTapGestureResponse(
|
| - command_id, SynthesizeTapGestureResponse::Create());
|
| - }
|
| - } else {
|
| - client_->SendError(command_id,
|
| - Response::InternalError(base::StringPrintf(
|
| - "Synthetic tap failed, result was %d", result)));
|
| + TapGestureResponse* response =
|
| + new TapGestureResponse(std::move(callback), count);
|
| + for (int i = 0; i < count; i++) {
|
| + host_->GetRenderWidgetHost()->QueueSyntheticGesture(
|
| + SyntheticGesture::Create(gesture_params),
|
| + base::Bind(&TapGestureResponse::OnGestureResult,
|
| + base::Unretained(response)));
|
| }
|
| }
|
|
|
| -} // namespace input
|
| -} // namespace devtools
|
| +} // namespace protocol
|
| } // namespace content
|
|
|