Chromium Code Reviews| 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 for (const DevToolsCommandId& command_id : pending_key_command_ids_) | |
|
dgozman
2016/11/21 19:14:39
You'll need to do the same on detach. See Detached
samuong
2016/11/21 22:28:43
I've added an InputHandler::Detached method, but t
samuong
2016/11/23 00:37:47
Done - added a call from RFDTAH::OnClientDetached
| |
| 159 SendDispatchKeyEventResponse(command_id); | |
| 160 pending_key_command_ids_.clear(); | |
| 161 | |
| 162 for (const DevToolsCommandId& command_id : pending_mouse_command_ids_) | |
| 163 SendDispatchMouseEventResponse(command_id); | |
| 164 pending_mouse_command_ids_.clear(); | |
| 165 | |
| 166 if (host_) | |
| 167 host_->RemoveInputEventObserver(this); | |
| 141 host_ = host; | 168 host_ = host; |
| 169 if (host) | |
| 170 host->AddInputEventObserver(this); | |
| 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, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 236 |
| 207 if (key) { | 237 if (key) { |
| 208 event.domKey = static_cast<int>( | 238 event.domKey = static_cast<int>( |
| 209 ui::KeycodeConverter::KeyStringToDomKey(*key)); | 239 ui::KeycodeConverter::KeyStringToDomKey(*key)); |
| 210 } | 240 } |
| 211 | 241 |
| 212 if (!host_) | 242 if (!host_) |
| 213 return Response::ServerError("Could not connect to view"); | 243 return Response::ServerError("Could not connect to view"); |
| 214 | 244 |
| 215 host_->Focus(); | 245 host_->Focus(); |
| 246 input_queued_ = false; | |
| 216 host_->ForwardKeyboardEvent(event); | 247 host_->ForwardKeyboardEvent(event); |
| 248 if (input_queued_) | |
| 249 pending_key_command_ids_.push_back(command_id); | |
| 250 else | |
| 251 SendDispatchKeyEventResponse(command_id); | |
| 217 return Response::OK(); | 252 return Response::OK(); |
| 218 } | 253 } |
| 219 | 254 |
| 220 Response InputHandler::DispatchMouseEvent( | 255 Response InputHandler::DispatchMouseEvent( |
| 256 DevToolsCommandId command_id, | |
| 221 const std::string& type, | 257 const std::string& type, |
| 222 int x, | 258 int x, |
| 223 int y, | 259 int y, |
| 224 const int* modifiers, | 260 const int* modifiers, |
| 225 const double* timestamp, | 261 const double* timestamp, |
| 226 const std::string* button, | 262 const std::string* button, |
| 227 const int* click_count) { | 263 const int* click_count) { |
| 228 blink::WebMouseEvent event; | 264 blink::WebMouseEvent event; |
| 229 | 265 |
| 230 if (!SetMouseEventType(&event, type)) { | 266 if (!SetMouseEventType(&event, type)) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 242 event.windowY = y * page_scale_factor_; | 278 event.windowY = y * page_scale_factor_; |
| 243 event.globalX = x * page_scale_factor_; | 279 event.globalX = x * page_scale_factor_; |
| 244 event.globalY = y * page_scale_factor_; | 280 event.globalY = y * page_scale_factor_; |
| 245 event.clickCount = click_count ? *click_count : 0; | 281 event.clickCount = click_count ? *click_count : 0; |
| 246 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; | 282 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; |
| 247 | 283 |
| 248 if (!host_) | 284 if (!host_) |
| 249 return Response::ServerError("Could not connect to view"); | 285 return Response::ServerError("Could not connect to view"); |
| 250 | 286 |
| 251 host_->Focus(); | 287 host_->Focus(); |
| 288 input_queued_ = false; | |
| 252 host_->ForwardMouseEvent(event); | 289 host_->ForwardMouseEvent(event); |
| 290 if (input_queued_) | |
| 291 pending_mouse_command_ids_.push_back(command_id); | |
| 292 else | |
| 293 SendDispatchMouseEventResponse(command_id); | |
| 253 return Response::OK(); | 294 return Response::OK(); |
| 254 } | 295 } |
| 255 | 296 |
| 256 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, | 297 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, |
| 257 int x, | 298 int x, |
| 258 int y, | 299 int y, |
| 259 double timestamp, | 300 double timestamp, |
| 260 const std::string& button, | 301 const std::string& button, |
| 261 double* delta_x, | 302 double* delta_x, |
| 262 double* delta_y, | 303 double* delta_y, |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 } | 513 } |
| 473 | 514 |
| 474 Response InputHandler::DispatchTouchEvent( | 515 Response InputHandler::DispatchTouchEvent( |
| 475 const std::string& type, | 516 const std::string& type, |
| 476 const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points, | 517 const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points, |
| 477 const int* modifiers, | 518 const int* modifiers, |
| 478 const double* timestamp) { | 519 const double* timestamp) { |
| 479 return Response::FallThrough(); | 520 return Response::FallThrough(); |
| 480 } | 521 } |
| 481 | 522 |
| 523 void InputHandler::SendDispatchKeyEventResponse(DevToolsCommandId command_id) { | |
| 524 client_->SendDispatchKeyEventResponse( | |
| 525 command_id, DispatchKeyEventResponse::Create()); | |
| 526 } | |
| 527 | |
| 528 void InputHandler::SendDispatchMouseEventResponse( | |
| 529 DevToolsCommandId command_id) { | |
| 530 client_->SendDispatchMouseEventResponse( | |
| 531 command_id, DispatchMouseEventResponse::Create()); | |
| 532 } | |
| 533 | |
| 482 void InputHandler::SendSynthesizePinchGestureResponse( | 534 void InputHandler::SendSynthesizePinchGestureResponse( |
| 483 DevToolsCommandId command_id, | 535 DevToolsCommandId command_id, |
| 484 SyntheticGesture::Result result) { | 536 SyntheticGesture::Result result) { |
| 485 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { | 537 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { |
| 486 client_->SendSynthesizePinchGestureResponse( | 538 client_->SendSynthesizePinchGestureResponse( |
| 487 command_id, SynthesizePinchGestureResponse::Create()); | 539 command_id, SynthesizePinchGestureResponse::Create()); |
| 488 } else { | 540 } else { |
| 489 client_->SendError(command_id, | 541 client_->SendError(command_id, |
| 490 Response::InternalError(base::StringPrintf( | 542 Response::InternalError(base::StringPrintf( |
| 491 "Synthetic pinch failed, result was %d", result))); | 543 "Synthetic pinch failed, result was %d", result))); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 517 } else { | 569 } else { |
| 518 client_->SendError(command_id, | 570 client_->SendError(command_id, |
| 519 Response::InternalError(base::StringPrintf( | 571 Response::InternalError(base::StringPrintf( |
| 520 "Synthetic tap failed, result was %d", result))); | 572 "Synthetic tap failed, result was %d", result))); |
| 521 } | 573 } |
| 522 } | 574 } |
| 523 | 575 |
| 524 } // namespace input | 576 } // namespace input |
| 525 } // namespace devtools | 577 } // namespace devtools |
| 526 } // namespace content | 578 } // namespace content |
| OLD | NEW |