Index: content/browser/devtools/input_domain_handler.cc |
diff --git a/content/browser/devtools/input_domain_handler.cc b/content/browser/devtools/input_domain_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8649ed7f403cbb621b8c73632994daba94333b4e |
--- /dev/null |
+++ b/content/browser/devtools/input_domain_handler.cc |
@@ -0,0 +1,131 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/devtools/input_domain_handler.h" |
+ |
+#include "base/strings/stringprintf.h" |
+#include "content/browser/devtools/devtools_protocol_constants.h" |
+#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "third_party/WebKit/public/web/WebInputEvent.h" |
+ |
+namespace content { |
+namespace devtools { |
+ |
+typedef DevToolsProtocolFrontend::Response Response; |
+typedef DevToolsProtocolFrontend::ResponseStatus ResponseStatus; |
+ |
+InputDomainHandler::InputDomainHandler() |
+ : host_(NULL) { |
+} |
+ |
+InputDomainHandler::~InputDomainHandler() { |
+} |
+ |
+void InputDomainHandler::OnClientDetached() { |
+} |
+ |
+void InputDomainHandler::SetRenderViewHost(RenderViewHostImpl* host) { |
+ host_ = host; |
+} |
+ |
+Response InputDomainHandler::EmulateTouchFromMouseEvent(std::string in_type, |
+ int in_x, |
+ int in_y, |
+ double* in_deltaX, |
+ double* in_deltaY, |
+ int* in_modifiers, |
+ double* in_timestamp, |
+ std::string* in_button, |
+ int* in_clickCount) { |
+ blink::WebMouseWheelEvent wheel_event; |
+ blink::WebMouseEvent mouse_event; |
+ blink::WebMouseEvent* event = &mouse_event; |
+ |
+ if (in_type == |
+ devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMousePressed) { |
+ event->type = blink::WebInputEvent::MouseDown; |
+ } else if (in_type == |
+ devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseReleased) { |
+ event->type = blink::WebInputEvent::MouseUp; |
+ } else if (in_type == |
+ devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseMoved) { |
+ event->type = blink::WebInputEvent::MouseMove; |
+ } else if (in_type == |
+ devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseWheel) { |
+ if (!in_deltaX || !in_deltaY) { |
+ return Response( |
+ ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, |
+ "'deltaX' and 'deltaY' are expected for mouseWheel event"); |
+ } |
+ wheel_event.deltaX = static_cast<float>(*in_deltaX); |
+ wheel_event.deltaY = static_cast<float>(*in_deltaY); |
+ event = &wheel_event; |
+ event->type = blink::WebInputEvent::MouseWheel; |
+ } else { |
+ return Response( |
+ ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, |
dgozman
2014/09/09 14:30:59
Can this be just RESPONSE_STATUS_XXXX?
vkuzkokov
2014/09/10 10:33:12
Used Response::InvalidParams instead
|
+ base::StringPrintf("Unexpected event type '%s'", in_type.c_str())); |
+ } |
+ |
+ if (in_modifiers) { |
+ if (*in_modifiers & 1) |
+ event->modifiers |= blink::WebInputEvent::AltKey; |
+ if (*in_modifiers & 2) |
+ event->modifiers |= blink::WebInputEvent::ControlKey; |
+ if (*in_modifiers & 4) |
+ event->modifiers |= blink::WebInputEvent::MetaKey; |
+ if (*in_modifiers & 8) |
+ event->modifiers |= blink::WebInputEvent::ShiftKey; |
+ } |
+ |
+ if (in_timestamp) |
+ event->timeStampSeconds = *in_timestamp; |
+ |
+ event->x = in_x; |
+ event->y = in_y; |
+ event->windowX = in_x; |
+ event->windowY = in_y; |
+ event->globalX = in_x; |
+ event->globalY = in_y; |
+ |
+ if (in_clickCount) |
+ event->clickCount = *in_clickCount; |
+ |
+ if (!in_button) { |
+ // TODO(vkuzkokov): make not optional |
+ return Response(ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, |
+ "'button' parameter missing"); |
+ } |
+ |
+ if (*in_button == "none") { |
+ event->button = blink::WebMouseEvent::ButtonNone; |
+ } else if (*in_button == "left") { |
+ event->button = blink::WebMouseEvent::ButtonLeft; |
+ event->modifiers |= blink::WebInputEvent::LeftButtonDown; |
+ } else if (*in_button == "middle") { |
+ event->button = blink::WebMouseEvent::ButtonMiddle; |
+ event->modifiers |= blink::WebInputEvent::MiddleButtonDown; |
+ } else if (*in_button == "right") { |
+ event->button = blink::WebMouseEvent::ButtonRight; |
+ event->modifiers |= blink::WebInputEvent::RightButtonDown; |
+ } else { |
+ return Response( |
+ ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, |
+ base::StringPrintf("Unexpected mouse button '%s'", in_button->c_str())); |
+ } |
+ |
+ if (!host_) { |
+ return Response(ResponseStatus::RESPONSE_STATUS_SERVER_ERROR, |
+ "Could not connect to view"); |
+ } |
+ |
+ if (event->type == blink::WebInputEvent::MouseWheel) |
+ host_->ForwardWheelEvent(wheel_event); |
+ else |
+ host_->ForwardMouseEvent(mouse_event); |
+ return Response(ResponseStatus::RESPONSE_STATUS_OK, ""); |
+} |
+ |
+} // namespace devtools |
+} // namespace content |