| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/browser/devtools/protocol/input_handler.h" | 5 #include "content/browser/devtools/protocol/input_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 InputHandler::InputHandler() | 131 InputHandler::InputHandler() |
| 132 : host_(NULL), | 132 : host_(NULL), |
| 133 page_scale_factor_(1.0), | 133 page_scale_factor_(1.0), |
| 134 weak_factory_(this) { | 134 weak_factory_(this) { |
| 135 } | 135 } |
| 136 | 136 |
| 137 InputHandler::~InputHandler() { | 137 InputHandler::~InputHandler() { |
| 138 } | 138 } |
| 139 | 139 |
| 140 void InputHandler::OnInputEventAck(const blink::WebInputEvent& event, |
| 141 bool is_synthetic) { |
| 142 if (!is_synthetic) |
| 143 return; |
| 144 |
| 145 if (blink::WebInputEvent::isKeyboardEventType(event.type) && |
| 146 !pending_key_event_ids_.empty()) { |
| 147 SendDispatchKeyEventResponse(pending_key_event_ids_.front()); |
| 148 pending_key_event_ids_.pop_front(); |
| 149 } else if (blink::WebInputEvent::isMouseEventType(event.type) && |
| 150 !pending_mouse_event_ids_.empty()) { |
| 151 SendDispatchMouseEventResponse(pending_mouse_event_ids_.front()); |
| 152 pending_mouse_event_ids_.pop_front(); |
| 153 } |
| 154 } |
| 155 |
| 140 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { | 156 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { |
| 157 for (const DevToolsCommandId& command_id : pending_key_event_ids_) |
| 158 SendDispatchKeyEventResponse(command_id); |
| 159 pending_key_event_ids_.clear(); |
| 160 |
| 161 for (const DevToolsCommandId& command_id : pending_mouse_event_ids_) |
| 162 SendDispatchMouseEventResponse(command_id); |
| 163 pending_mouse_event_ids_.clear(); |
| 164 |
| 165 if (host_) |
| 166 host_->RemoveInputEventObserver(this); |
| 167 if (host) |
| 168 host->AddInputEventObserver(this); |
| 169 |
| 141 host_ = host; | 170 host_ = host; |
| 142 } | 171 } |
| 143 | 172 |
| 144 void InputHandler::SetClient(std::unique_ptr<Client> client) { | 173 void InputHandler::SetClient(std::unique_ptr<Client> client) { |
| 145 client_.swap(client); | 174 client_.swap(client); |
| 146 } | 175 } |
| 147 | 176 |
| 148 void InputHandler::OnSwapCompositorFrame( | 177 void InputHandler::OnSwapCompositorFrame( |
| 149 const cc::CompositorFrameMetadata& frame_metadata) { | 178 const cc::CompositorFrameMetadata& frame_metadata) { |
| 150 page_scale_factor_ = frame_metadata.page_scale_factor; | 179 page_scale_factor_ = frame_metadata.page_scale_factor; |
| 151 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; | 180 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; |
| 152 } | 181 } |
| 153 | 182 |
| 154 Response InputHandler::DispatchKeyEvent( | 183 Response InputHandler::DispatchKeyEvent( |
| 184 DevToolsCommandId command_id, |
| 155 const std::string& type, | 185 const std::string& type, |
| 156 const int* modifiers, | 186 const int* modifiers, |
| 157 const double* timestamp, | 187 const double* timestamp, |
| 158 const std::string* text, | 188 const std::string* text, |
| 159 const std::string* unmodified_text, | 189 const std::string* unmodified_text, |
| 160 const std::string* key_identifier, | 190 const std::string* key_identifier, |
| 161 const std::string* code, | 191 const std::string* code, |
| 162 const std::string* key, | 192 const std::string* key, |
| 163 const int* windows_virtual_key_code, | 193 const int* windows_virtual_key_code, |
| 164 const int* native_virtual_key_code, | 194 const int* native_virtual_key_code, |
| 165 const bool* auto_repeat, | 195 const bool* auto_repeat, |
| 166 const bool* is_keypad, | 196 const bool* is_keypad, |
| 167 const bool* is_system_key) { | 197 const bool* is_system_key) { |
| 168 NativeWebKeyboardEvent event; | 198 NativeWebKeyboardEvent event; |
| 169 event.skip_in_browser = true; | 199 event.skip_in_browser = true; |
| 200 event.is_synthetic = true; |
| 170 | 201 |
| 171 if (type == dispatch_key_event::kTypeKeyDown) { | 202 if (type == dispatch_key_event::kTypeKeyDown) { |
| 172 event.type = blink::WebInputEvent::KeyDown; | 203 event.type = blink::WebInputEvent::KeyDown; |
| 173 } else if (type == dispatch_key_event::kTypeKeyUp) { | 204 } else if (type == dispatch_key_event::kTypeKeyUp) { |
| 174 event.type = blink::WebInputEvent::KeyUp; | 205 event.type = blink::WebInputEvent::KeyUp; |
| 175 } else if (type == dispatch_key_event::kTypeChar) { | 206 } else if (type == dispatch_key_event::kTypeChar) { |
| 176 event.type = blink::WebInputEvent::Char; | 207 event.type = blink::WebInputEvent::Char; |
| 177 } else if (type == dispatch_key_event::kTypeRawKeyDown) { | 208 } else if (type == dispatch_key_event::kTypeRawKeyDown) { |
| 178 event.type = blink::WebInputEvent::RawKeyDown; | 209 event.type = blink::WebInputEvent::RawKeyDown; |
| 179 } else { | 210 } else { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 205 } | 236 } |
| 206 | 237 |
| 207 if (key) { | 238 if (key) { |
| 208 event.domKey = static_cast<int>( | 239 event.domKey = static_cast<int>( |
| 209 ui::KeycodeConverter::KeyStringToDomKey(*key)); | 240 ui::KeycodeConverter::KeyStringToDomKey(*key)); |
| 210 } | 241 } |
| 211 | 242 |
| 212 if (!host_) | 243 if (!host_) |
| 213 return Response::ServerError("Could not connect to view"); | 244 return Response::ServerError("Could not connect to view"); |
| 214 | 245 |
| 246 pending_key_event_ids_.push_back(command_id); |
| 215 host_->Focus(); | 247 host_->Focus(); |
| 216 host_->ForwardKeyboardEvent(event); | 248 host_->ForwardKeyboardEvent(event); |
| 217 return Response::OK(); | 249 return Response::OK(); |
| 218 } | 250 } |
| 219 | 251 |
| 220 Response InputHandler::DispatchMouseEvent( | 252 Response InputHandler::DispatchMouseEvent( |
| 253 DevToolsCommandId command_id, |
| 221 const std::string& type, | 254 const std::string& type, |
| 222 int x, | 255 int x, |
| 223 int y, | 256 int y, |
| 224 const int* modifiers, | 257 const int* modifiers, |
| 225 const double* timestamp, | 258 const double* timestamp, |
| 226 const std::string* button, | 259 const std::string* button, |
| 227 const int* click_count) { | 260 const int* click_count) { |
| 228 blink::WebMouseEvent event; | 261 blink::WebMouseEvent event; |
| 229 | 262 |
| 230 if (!SetMouseEventType(&event, type)) { | 263 if (!SetMouseEventType(&event, type)) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 241 event.windowX = x * page_scale_factor_; | 274 event.windowX = x * page_scale_factor_; |
| 242 event.windowY = y * page_scale_factor_; | 275 event.windowY = y * page_scale_factor_; |
| 243 event.globalX = x * page_scale_factor_; | 276 event.globalX = x * page_scale_factor_; |
| 244 event.globalY = y * page_scale_factor_; | 277 event.globalY = y * page_scale_factor_; |
| 245 event.clickCount = click_count ? *click_count : 0; | 278 event.clickCount = click_count ? *click_count : 0; |
| 246 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; | 279 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; |
| 247 | 280 |
| 248 if (!host_) | 281 if (!host_) |
| 249 return Response::ServerError("Could not connect to view"); | 282 return Response::ServerError("Could not connect to view"); |
| 250 | 283 |
| 284 pending_mouse_event_ids_.push_back(command_id); |
| 251 host_->Focus(); | 285 host_->Focus(); |
| 252 host_->ForwardMouseEvent(event); | 286 host_->ForwardMouseEvent(event); |
| 253 return Response::OK(); | 287 return Response::OK(); |
| 254 } | 288 } |
| 255 | 289 |
| 256 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, | 290 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, |
| 257 int x, | 291 int x, |
| 258 int y, | 292 int y, |
| 259 double timestamp, | 293 double timestamp, |
| 260 const std::string& button, | 294 const std::string& button, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 bool is_last_tap = i == *tap_count - 1; | 498 bool is_last_tap = i == *tap_count - 1; |
| 465 host_->QueueSyntheticGesture( | 499 host_->QueueSyntheticGesture( |
| 466 SyntheticGesture::Create(gesture_params), | 500 SyntheticGesture::Create(gesture_params), |
| 467 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse, | 501 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse, |
| 468 weak_factory_.GetWeakPtr(), command_id, is_last_tap)); | 502 weak_factory_.GetWeakPtr(), command_id, is_last_tap)); |
| 469 } | 503 } |
| 470 | 504 |
| 471 return Response::OK(); | 505 return Response::OK(); |
| 472 } | 506 } |
| 473 | 507 |
| 508 void InputHandler::SendDispatchKeyEventResponse(DevToolsCommandId command_id) { |
| 509 client_->SendDispatchKeyEventResponse( |
| 510 command_id, DispatchKeyEventResponse::Create()); |
| 511 } |
| 512 |
| 513 void InputHandler::SendDispatchMouseEventResponse( |
| 514 DevToolsCommandId command_id) { |
| 515 client_->SendDispatchMouseEventResponse( |
| 516 command_id, DispatchMouseEventResponse::Create()); |
| 517 } |
| 518 |
| 474 void InputHandler::SendSynthesizePinchGestureResponse( | 519 void InputHandler::SendSynthesizePinchGestureResponse( |
| 475 DevToolsCommandId command_id, | 520 DevToolsCommandId command_id, |
| 476 SyntheticGesture::Result result) { | 521 SyntheticGesture::Result result) { |
| 477 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { | 522 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { |
| 478 client_->SendSynthesizePinchGestureResponse( | 523 client_->SendSynthesizePinchGestureResponse( |
| 479 command_id, SynthesizePinchGestureResponse::Create()); | 524 command_id, SynthesizePinchGestureResponse::Create()); |
| 480 } else { | 525 } else { |
| 481 client_->SendError(command_id, | 526 client_->SendError(command_id, |
| 482 Response::InternalError(base::StringPrintf( | 527 Response::InternalError(base::StringPrintf( |
| 483 "Synthetic pinch failed, result was %d", result))); | 528 "Synthetic pinch failed, result was %d", result))); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 509 } else { | 554 } else { |
| 510 client_->SendError(command_id, | 555 client_->SendError(command_id, |
| 511 Response::InternalError(base::StringPrintf( | 556 Response::InternalError(base::StringPrintf( |
| 512 "Synthetic tap failed, result was %d", result))); | 557 "Synthetic tap failed, result was %d", result))); |
| 513 } | 558 } |
| 514 } | 559 } |
| 515 | 560 |
| 516 } // namespace input | 561 } // namespace input |
| 517 } // namespace devtools | 562 } // namespace devtools |
| 518 } // namespace content | 563 } // namespace content |
| OLD | NEW |