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 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 (blink::WebInputEvent::isKeyboardEventType(event.type) && is_synthetic && | |
| 143 !pending_key_event_ids_.empty()) { | |
| 144 SendDispatchKeyEventResponse(pending_key_event_ids_.front()); | |
| 145 pending_key_event_ids_.pop(); | |
| 146 } | |
| 147 } | |
| 148 | |
| 140 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { | 149 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { |
| 141 host_ = host; | 150 host_ = host; |
| 142 } | 151 } |
| 143 | 152 |
| 144 void InputHandler::SetClient(std::unique_ptr<Client> client) { | 153 void InputHandler::SetClient(std::unique_ptr<Client> client) { |
| 145 client_.swap(client); | 154 client_.swap(client); |
| 146 } | 155 } |
| 147 | 156 |
| 148 void InputHandler::OnSwapCompositorFrame( | 157 void InputHandler::OnSwapCompositorFrame( |
| 149 const cc::CompositorFrameMetadata& frame_metadata) { | 158 const cc::CompositorFrameMetadata& frame_metadata) { |
| 150 page_scale_factor_ = frame_metadata.page_scale_factor; | 159 page_scale_factor_ = frame_metadata.page_scale_factor; |
| 151 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; | 160 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; |
| 152 } | 161 } |
| 153 | 162 |
| 154 Response InputHandler::DispatchKeyEvent( | 163 Response InputHandler::DispatchKeyEvent( |
| 164 DevToolsCommandId command_id, | |
| 155 const std::string& type, | 165 const std::string& type, |
| 156 const int* modifiers, | 166 const int* modifiers, |
| 157 const double* timestamp, | 167 const double* timestamp, |
| 158 const std::string* text, | 168 const std::string* text, |
| 159 const std::string* unmodified_text, | 169 const std::string* unmodified_text, |
| 160 const std::string* key_identifier, | 170 const std::string* key_identifier, |
| 161 const std::string* code, | 171 const std::string* code, |
| 162 const std::string* key, | 172 const std::string* key, |
| 163 const int* windows_virtual_key_code, | 173 const int* windows_virtual_key_code, |
| 164 const int* native_virtual_key_code, | 174 const int* native_virtual_key_code, |
| 165 const bool* auto_repeat, | 175 const bool* auto_repeat, |
| 166 const bool* is_keypad, | 176 const bool* is_keypad, |
| 167 const bool* is_system_key) { | 177 const bool* is_system_key) { |
| 168 NativeWebKeyboardEvent event; | 178 NativeWebKeyboardEvent event; |
| 169 event.skip_in_browser = true; | 179 event.skip_in_browser = true; |
| 180 event.is_synthetic = true; | |
| 170 | 181 |
| 171 if (type == dispatch_key_event::kTypeKeyDown) { | 182 if (type == dispatch_key_event::kTypeKeyDown) { |
| 172 event.type = blink::WebInputEvent::KeyDown; | 183 event.type = blink::WebInputEvent::KeyDown; |
| 173 } else if (type == dispatch_key_event::kTypeKeyUp) { | 184 } else if (type == dispatch_key_event::kTypeKeyUp) { |
| 174 event.type = blink::WebInputEvent::KeyUp; | 185 event.type = blink::WebInputEvent::KeyUp; |
| 175 } else if (type == dispatch_key_event::kTypeChar) { | 186 } else if (type == dispatch_key_event::kTypeChar) { |
| 176 event.type = blink::WebInputEvent::Char; | 187 event.type = blink::WebInputEvent::Char; |
| 177 } else if (type == dispatch_key_event::kTypeRawKeyDown) { | 188 } else if (type == dispatch_key_event::kTypeRawKeyDown) { |
| 178 event.type = blink::WebInputEvent::RawKeyDown; | 189 event.type = blink::WebInputEvent::RawKeyDown; |
| 179 } else { | 190 } else { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 205 } | 216 } |
| 206 | 217 |
| 207 if (key) { | 218 if (key) { |
| 208 event.domKey = static_cast<int>( | 219 event.domKey = static_cast<int>( |
| 209 ui::KeycodeConverter::KeyStringToDomKey(*key)); | 220 ui::KeycodeConverter::KeyStringToDomKey(*key)); |
| 210 } | 221 } |
| 211 | 222 |
| 212 if (!host_) | 223 if (!host_) |
| 213 return Response::ServerError("Could not connect to view"); | 224 return Response::ServerError("Could not connect to view"); |
| 214 | 225 |
| 226 pending_key_event_ids_.push(command_id); | |
| 215 host_->Focus(); | 227 host_->Focus(); |
| 228 host_->AddInputEventObserver(this); | |
|
dtapuska
2016/10/14 19:06:29
So is it possible to call this API twice in a row?
samuong
2016/10/20 23:36:18
The RWHI will check if the observer has already be
| |
| 216 host_->ForwardKeyboardEvent(event); | 229 host_->ForwardKeyboardEvent(event); |
| 217 return Response::OK(); | 230 return Response::OK(); |
| 218 } | 231 } |
| 219 | 232 |
| 220 Response InputHandler::DispatchMouseEvent( | 233 Response InputHandler::DispatchMouseEvent( |
| 221 const std::string& type, | 234 const std::string& type, |
| 222 int x, | 235 int x, |
| 223 int y, | 236 int y, |
| 224 const int* modifiers, | 237 const int* modifiers, |
| 225 const double* timestamp, | 238 const double* timestamp, |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 bool is_last_tap = i == *tap_count - 1; | 477 bool is_last_tap = i == *tap_count - 1; |
| 465 host_->QueueSyntheticGesture( | 478 host_->QueueSyntheticGesture( |
| 466 SyntheticGesture::Create(gesture_params), | 479 SyntheticGesture::Create(gesture_params), |
| 467 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse, | 480 base::Bind(&InputHandler::SendSynthesizeTapGestureResponse, |
| 468 weak_factory_.GetWeakPtr(), command_id, is_last_tap)); | 481 weak_factory_.GetWeakPtr(), command_id, is_last_tap)); |
| 469 } | 482 } |
| 470 | 483 |
| 471 return Response::OK(); | 484 return Response::OK(); |
| 472 } | 485 } |
| 473 | 486 |
| 487 void InputHandler::SendDispatchKeyEventResponse(DevToolsCommandId command_id) { | |
| 488 client_->SendDispatchKeyEventResponse( | |
| 489 command_id, DispatchKeyEventResponse::Create()); | |
| 490 host_->RemoveInputEventObserver(this); | |
| 491 } | |
| 492 | |
| 474 void InputHandler::SendSynthesizePinchGestureResponse( | 493 void InputHandler::SendSynthesizePinchGestureResponse( |
| 475 DevToolsCommandId command_id, | 494 DevToolsCommandId command_id, |
| 476 SyntheticGesture::Result result) { | 495 SyntheticGesture::Result result) { |
| 477 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { | 496 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { |
| 478 client_->SendSynthesizePinchGestureResponse( | 497 client_->SendSynthesizePinchGestureResponse( |
| 479 command_id, SynthesizePinchGestureResponse::Create()); | 498 command_id, SynthesizePinchGestureResponse::Create()); |
| 480 } else { | 499 } else { |
| 481 client_->SendError(command_id, | 500 client_->SendError(command_id, |
| 482 Response::InternalError(base::StringPrintf( | 501 Response::InternalError(base::StringPrintf( |
| 483 "Synthetic pinch failed, result was %d", result))); | 502 "Synthetic pinch failed, result was %d", result))); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 509 } else { | 528 } else { |
| 510 client_->SendError(command_id, | 529 client_->SendError(command_id, |
| 511 Response::InternalError(base::StringPrintf( | 530 Response::InternalError(base::StringPrintf( |
| 512 "Synthetic tap failed, result was %d", result))); | 531 "Synthetic tap failed, result was %d", result))); |
| 513 } | 532 } |
| 514 } | 533 } |
| 515 | 534 |
| 516 } // namespace input | 535 } // namespace input |
| 517 } // namespace devtools | 536 } // namespace devtools |
| 518 } // namespace content | 537 } // namespace content |
| OLD | NEW |