| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } else { | 123 } else { |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace | 129 } // namespace |
| 130 | 130 |
| 131 InputHandler::InputHandler() | 131 InputHandler::InputHandler() |
| 132 : host_(NULL), | 132 : host_(NULL), |
| 133 input_queued_(false), |
| 133 page_scale_factor_(1.0), | 134 page_scale_factor_(1.0), |
| 134 weak_factory_(this) { | 135 weak_factory_(this) { |
| 135 } | 136 } |
| 136 | 137 |
| 137 InputHandler::~InputHandler() { | 138 InputHandler::~InputHandler() { |
| 138 } | 139 } |
| 139 | 140 |
| 141 void InputHandler::OnInputEvent(const blink::WebInputEvent& event) { |
| 142 input_queued_ = true; |
| 143 } |
| 144 |
| 145 void InputHandler::OnInputEventAck(const blink::WebInputEvent& event) { |
| 146 if (blink::WebInputEvent::isKeyboardEventType(event.type) && |
| 147 !pending_key_command_ids_.empty()) { |
| 148 SendDispatchKeyEventResponse(pending_key_command_ids_.front()); |
| 149 pending_key_command_ids_.pop_front(); |
| 150 } else if (blink::WebInputEvent::isMouseEventType(event.type) && |
| 151 !pending_mouse_command_ids_.empty()) { |
| 152 SendDispatchMouseEventResponse(pending_mouse_command_ids_.front()); |
| 153 pending_mouse_command_ids_.pop_front(); |
| 154 } |
| 155 } |
| 156 |
| 140 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { | 157 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { |
| 158 ClearPendingKeyCommands(); |
| 159 ClearPendingMouseCommands(); |
| 160 if (host_) |
| 161 host_->RemoveInputEventObserver(this); |
| 141 host_ = host; | 162 host_ = host; |
| 163 if (host) |
| 164 host->AddInputEventObserver(this); |
| 142 } | 165 } |
| 143 | 166 |
| 144 void InputHandler::SetClient(std::unique_ptr<Client> client) { | 167 void InputHandler::SetClient(std::unique_ptr<Client> client) { |
| 145 client_.swap(client); | 168 client_.swap(client); |
| 146 } | 169 } |
| 147 | 170 |
| 148 void InputHandler::OnSwapCompositorFrame( | 171 void InputHandler::OnSwapCompositorFrame( |
| 149 const cc::CompositorFrameMetadata& frame_metadata) { | 172 const cc::CompositorFrameMetadata& frame_metadata) { |
| 150 page_scale_factor_ = frame_metadata.page_scale_factor; | 173 page_scale_factor_ = frame_metadata.page_scale_factor; |
| 151 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; | 174 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; |
| 152 } | 175 } |
| 153 | 176 |
| 177 void InputHandler::Detached() { |
| 178 ClearPendingKeyCommands(); |
| 179 ClearPendingMouseCommands(); |
| 180 if (host_) |
| 181 host_->RemoveInputEventObserver(this); |
| 182 } |
| 183 |
| 154 Response InputHandler::DispatchKeyEvent( | 184 Response InputHandler::DispatchKeyEvent( |
| 185 DevToolsCommandId command_id, |
| 155 const std::string& type, | 186 const std::string& type, |
| 156 const int* modifiers, | 187 const int* modifiers, |
| 157 const double* timestamp, | 188 const double* timestamp, |
| 158 const std::string* text, | 189 const std::string* text, |
| 159 const std::string* unmodified_text, | 190 const std::string* unmodified_text, |
| 160 const std::string* key_identifier, | 191 const std::string* key_identifier, |
| 161 const std::string* code, | 192 const std::string* code, |
| 162 const std::string* key, | 193 const std::string* key, |
| 163 const int* windows_virtual_key_code, | 194 const int* windows_virtual_key_code, |
| 164 const int* native_virtual_key_code, | 195 const int* native_virtual_key_code, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 215 host_->Focus(); | 246 host_->Focus(); |
| 247 input_queued_ = false; |
| 216 host_->ForwardKeyboardEvent(event); | 248 host_->ForwardKeyboardEvent(event); |
| 249 if (input_queued_) |
| 250 pending_key_command_ids_.push_back(command_id); |
| 251 else |
| 252 SendDispatchKeyEventResponse(command_id); |
| 217 return Response::OK(); | 253 return Response::OK(); |
| 218 } | 254 } |
| 219 | 255 |
| 220 Response InputHandler::DispatchMouseEvent( | 256 Response InputHandler::DispatchMouseEvent( |
| 257 DevToolsCommandId command_id, |
| 221 const std::string& type, | 258 const std::string& type, |
| 222 int x, | 259 int x, |
| 223 int y, | 260 int y, |
| 224 const int* modifiers, | 261 const int* modifiers, |
| 225 const double* timestamp, | 262 const double* timestamp, |
| 226 const std::string* button, | 263 const std::string* button, |
| 227 const int* click_count) { | 264 const int* click_count) { |
| 228 blink::WebMouseEvent event; | 265 blink::WebMouseEvent event; |
| 229 | 266 |
| 230 if (!SetMouseEventType(&event, type)) { | 267 if (!SetMouseEventType(&event, type)) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 242 event.windowY = y * page_scale_factor_; | 279 event.windowY = y * page_scale_factor_; |
| 243 event.globalX = x * page_scale_factor_; | 280 event.globalX = x * page_scale_factor_; |
| 244 event.globalY = y * page_scale_factor_; | 281 event.globalY = y * page_scale_factor_; |
| 245 event.clickCount = click_count ? *click_count : 0; | 282 event.clickCount = click_count ? *click_count : 0; |
| 246 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; | 283 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; |
| 247 | 284 |
| 248 if (!host_) | 285 if (!host_) |
| 249 return Response::ServerError("Could not connect to view"); | 286 return Response::ServerError("Could not connect to view"); |
| 250 | 287 |
| 251 host_->Focus(); | 288 host_->Focus(); |
| 289 input_queued_ = false; |
| 252 host_->ForwardMouseEvent(event); | 290 host_->ForwardMouseEvent(event); |
| 291 if (input_queued_) |
| 292 pending_mouse_command_ids_.push_back(command_id); |
| 293 else |
| 294 SendDispatchMouseEventResponse(command_id); |
| 253 return Response::OK(); | 295 return Response::OK(); |
| 254 } | 296 } |
| 255 | 297 |
| 256 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, | 298 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, |
| 257 int x, | 299 int x, |
| 258 int y, | 300 int y, |
| 259 double timestamp, | 301 double timestamp, |
| 260 const std::string& button, | 302 const std::string& button, |
| 261 double* delta_x, | 303 double* delta_x, |
| 262 double* delta_y, | 304 double* delta_y, |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 } | 514 } |
| 473 | 515 |
| 474 Response InputHandler::DispatchTouchEvent( | 516 Response InputHandler::DispatchTouchEvent( |
| 475 const std::string& type, | 517 const std::string& type, |
| 476 const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points, | 518 const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points, |
| 477 const int* modifiers, | 519 const int* modifiers, |
| 478 const double* timestamp) { | 520 const double* timestamp) { |
| 479 return Response::FallThrough(); | 521 return Response::FallThrough(); |
| 480 } | 522 } |
| 481 | 523 |
| 524 void InputHandler::SendDispatchKeyEventResponse(DevToolsCommandId command_id) { |
| 525 client_->SendDispatchKeyEventResponse( |
| 526 command_id, DispatchKeyEventResponse::Create()); |
| 527 } |
| 528 |
| 529 void InputHandler::SendDispatchMouseEventResponse( |
| 530 DevToolsCommandId command_id) { |
| 531 client_->SendDispatchMouseEventResponse( |
| 532 command_id, DispatchMouseEventResponse::Create()); |
| 533 } |
| 534 |
| 482 void InputHandler::SendSynthesizePinchGestureResponse( | 535 void InputHandler::SendSynthesizePinchGestureResponse( |
| 483 DevToolsCommandId command_id, | 536 DevToolsCommandId command_id, |
| 484 SyntheticGesture::Result result) { | 537 SyntheticGesture::Result result) { |
| 485 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { | 538 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { |
| 486 client_->SendSynthesizePinchGestureResponse( | 539 client_->SendSynthesizePinchGestureResponse( |
| 487 command_id, SynthesizePinchGestureResponse::Create()); | 540 command_id, SynthesizePinchGestureResponse::Create()); |
| 488 } else { | 541 } else { |
| 489 client_->SendError(command_id, | 542 client_->SendError(command_id, |
| 490 Response::InternalError(base::StringPrintf( | 543 Response::InternalError(base::StringPrintf( |
| 491 "Synthetic pinch failed, result was %d", result))); | 544 "Synthetic pinch failed, result was %d", result))); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 514 client_->SendSynthesizeTapGestureResponse( | 567 client_->SendSynthesizeTapGestureResponse( |
| 515 command_id, SynthesizeTapGestureResponse::Create()); | 568 command_id, SynthesizeTapGestureResponse::Create()); |
| 516 } | 569 } |
| 517 } else { | 570 } else { |
| 518 client_->SendError(command_id, | 571 client_->SendError(command_id, |
| 519 Response::InternalError(base::StringPrintf( | 572 Response::InternalError(base::StringPrintf( |
| 520 "Synthetic tap failed, result was %d", result))); | 573 "Synthetic tap failed, result was %d", result))); |
| 521 } | 574 } |
| 522 } | 575 } |
| 523 | 576 |
| 577 void InputHandler::ClearPendingKeyCommands() { |
| 578 for (const DevToolsCommandId& command_id : pending_key_command_ids_) |
| 579 SendDispatchKeyEventResponse(command_id); |
| 580 pending_key_command_ids_.clear(); |
| 581 } |
| 582 |
| 583 void InputHandler::ClearPendingMouseCommands() { |
| 584 for (const DevToolsCommandId& command_id : pending_mouse_command_ids_) |
| 585 SendDispatchMouseEventResponse(command_id); |
| 586 pending_mouse_command_ids_.clear(); |
| 587 } |
| 588 |
| 524 } // namespace input | 589 } // namespace input |
| 525 } // namespace devtools | 590 } // namespace devtools |
| 526 } // namespace content | 591 } // namespace content |
| OLD | NEW |