Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/devtools/input_domain_handler.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "content/browser/devtools/devtools_protocol_constants.h" | |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 10 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 11 | |
| 12 namespace content { | |
| 13 namespace devtools { | |
| 14 | |
| 15 typedef DevToolsProtocolFrontend::Response Response; | |
| 16 typedef DevToolsProtocolFrontend::ResponseStatus ResponseStatus; | |
| 17 | |
| 18 InputDomainHandler::InputDomainHandler() | |
| 19 : host_(NULL) { | |
| 20 } | |
| 21 | |
| 22 InputDomainHandler::~InputDomainHandler() { | |
| 23 } | |
| 24 | |
| 25 void InputDomainHandler::OnClientDetached() { | |
| 26 } | |
| 27 | |
| 28 void InputDomainHandler::SetRenderViewHost(RenderViewHostImpl* host) { | |
| 29 host_ = host; | |
| 30 } | |
| 31 | |
| 32 Response InputDomainHandler::EmulateTouchFromMouseEvent(std::string in_type, | |
| 33 int in_x, | |
| 34 int in_y, | |
| 35 double* in_deltaX, | |
| 36 double* in_deltaY, | |
| 37 int* in_modifiers, | |
| 38 double* in_timestamp, | |
| 39 std::string* in_button, | |
| 40 int* in_clickCount) { | |
| 41 blink::WebMouseWheelEvent wheel_event; | |
| 42 blink::WebMouseEvent mouse_event; | |
| 43 blink::WebMouseEvent* event = &mouse_event; | |
| 44 | |
| 45 if (in_type == | |
| 46 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMousePressed) { | |
| 47 event->type = blink::WebInputEvent::MouseDown; | |
| 48 } else if (in_type == | |
| 49 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseReleased) { | |
| 50 event->type = blink::WebInputEvent::MouseUp; | |
| 51 } else if (in_type == | |
| 52 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseMoved) { | |
| 53 event->type = blink::WebInputEvent::MouseMove; | |
| 54 } else if (in_type == | |
| 55 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseWheel) { | |
| 56 if (!in_deltaX || !in_deltaY) { | |
| 57 return Response( | |
| 58 ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, | |
| 59 "'deltaX' and 'deltaY' are expected for mouseWheel event"); | |
| 60 } | |
| 61 wheel_event.deltaX = static_cast<float>(*in_deltaX); | |
| 62 wheel_event.deltaY = static_cast<float>(*in_deltaY); | |
| 63 event = &wheel_event; | |
| 64 event->type = blink::WebInputEvent::MouseWheel; | |
| 65 } else { | |
| 66 return Response( | |
| 67 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
| |
| 68 base::StringPrintf("Unexpected event type '%s'", in_type.c_str())); | |
| 69 } | |
| 70 | |
| 71 if (in_modifiers) { | |
| 72 if (*in_modifiers & 1) | |
| 73 event->modifiers |= blink::WebInputEvent::AltKey; | |
| 74 if (*in_modifiers & 2) | |
| 75 event->modifiers |= blink::WebInputEvent::ControlKey; | |
| 76 if (*in_modifiers & 4) | |
| 77 event->modifiers |= blink::WebInputEvent::MetaKey; | |
| 78 if (*in_modifiers & 8) | |
| 79 event->modifiers |= blink::WebInputEvent::ShiftKey; | |
| 80 } | |
| 81 | |
| 82 if (in_timestamp) | |
| 83 event->timeStampSeconds = *in_timestamp; | |
| 84 | |
| 85 event->x = in_x; | |
| 86 event->y = in_y; | |
| 87 event->windowX = in_x; | |
| 88 event->windowY = in_y; | |
| 89 event->globalX = in_x; | |
| 90 event->globalY = in_y; | |
| 91 | |
| 92 if (in_clickCount) | |
| 93 event->clickCount = *in_clickCount; | |
| 94 | |
| 95 if (!in_button) { | |
| 96 // TODO(vkuzkokov): make not optional | |
| 97 return Response(ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, | |
| 98 "'button' parameter missing"); | |
| 99 } | |
| 100 | |
| 101 if (*in_button == "none") { | |
| 102 event->button = blink::WebMouseEvent::ButtonNone; | |
| 103 } else if (*in_button == "left") { | |
| 104 event->button = blink::WebMouseEvent::ButtonLeft; | |
| 105 event->modifiers |= blink::WebInputEvent::LeftButtonDown; | |
| 106 } else if (*in_button == "middle") { | |
| 107 event->button = blink::WebMouseEvent::ButtonMiddle; | |
| 108 event->modifiers |= blink::WebInputEvent::MiddleButtonDown; | |
| 109 } else if (*in_button == "right") { | |
| 110 event->button = blink::WebMouseEvent::ButtonRight; | |
| 111 event->modifiers |= blink::WebInputEvent::RightButtonDown; | |
| 112 } else { | |
| 113 return Response( | |
| 114 ResponseStatus::RESPONSE_STATUS_INVALID_PARAMS, | |
| 115 base::StringPrintf("Unexpected mouse button '%s'", in_button->c_str())); | |
| 116 } | |
| 117 | |
| 118 if (!host_) { | |
| 119 return Response(ResponseStatus::RESPONSE_STATUS_SERVER_ERROR, | |
| 120 "Could not connect to view"); | |
| 121 } | |
| 122 | |
| 123 if (event->type == blink::WebInputEvent::MouseWheel) | |
| 124 host_->ForwardWheelEvent(wheel_event); | |
| 125 else | |
| 126 host_->ForwardMouseEvent(mouse_event); | |
| 127 return Response(ResponseStatus::RESPONSE_STATUS_OK, ""); | |
| 128 } | |
| 129 | |
| 130 } // namespace devtools | |
| 131 } // namespace content | |
| OLD | NEW |