Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: content/browser/devtools/protocol/input_handler.cc

Issue 2584193002: Revert of Delay Input.dispatchKeyEvent response until after key event ack. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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),
134 page_scale_factor_(1.0), 133 page_scale_factor_(1.0),
135 weak_factory_(this) { 134 weak_factory_(this) {
136 } 135 }
137 136
138 InputHandler::~InputHandler() { 137 InputHandler::~InputHandler() {
139 } 138 }
140 139
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
157 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) { 140 void InputHandler::SetRenderWidgetHost(RenderWidgetHostImpl* host) {
158 ClearPendingKeyCommands();
159 ClearPendingMouseCommands();
160 if (host_)
161 host_->RemoveInputEventObserver(this);
162 host_ = host; 141 host_ = host;
163 if (host)
164 host->AddInputEventObserver(this);
165 } 142 }
166 143
167 void InputHandler::SetClient(std::unique_ptr<Client> client) { 144 void InputHandler::SetClient(std::unique_ptr<Client> client) {
168 client_.swap(client); 145 client_.swap(client);
169 } 146 }
170 147
171 void InputHandler::OnSwapCompositorFrame( 148 void InputHandler::OnSwapCompositorFrame(
172 const cc::CompositorFrameMetadata& frame_metadata) { 149 const cc::CompositorFrameMetadata& frame_metadata) {
173 page_scale_factor_ = frame_metadata.page_scale_factor; 150 page_scale_factor_ = frame_metadata.page_scale_factor;
174 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; 151 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size;
175 } 152 }
176 153
177 void InputHandler::Detached() {
178 ClearPendingKeyCommands();
179 ClearPendingMouseCommands();
180 if (host_)
181 host_->RemoveInputEventObserver(this);
182 }
183
184 Response InputHandler::DispatchKeyEvent( 154 Response InputHandler::DispatchKeyEvent(
185 DevToolsCommandId command_id,
186 const std::string& type, 155 const std::string& type,
187 const int* modifiers, 156 const int* modifiers,
188 const double* timestamp, 157 const double* timestamp,
189 const std::string* text, 158 const std::string* text,
190 const std::string* unmodified_text, 159 const std::string* unmodified_text,
191 const std::string* key_identifier, 160 const std::string* key_identifier,
192 const std::string* code, 161 const std::string* code,
193 const std::string* key, 162 const std::string* key,
194 const int* windows_virtual_key_code, 163 const int* windows_virtual_key_code,
195 const int* native_virtual_key_code, 164 const int* native_virtual_key_code,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 206
238 if (key) { 207 if (key) {
239 event.domKey = static_cast<int>( 208 event.domKey = static_cast<int>(
240 ui::KeycodeConverter::KeyStringToDomKey(*key)); 209 ui::KeycodeConverter::KeyStringToDomKey(*key));
241 } 210 }
242 211
243 if (!host_) 212 if (!host_)
244 return Response::ServerError("Could not connect to view"); 213 return Response::ServerError("Could not connect to view");
245 214
246 host_->Focus(); 215 host_->Focus();
247 input_queued_ = false;
248 host_->ForwardKeyboardEvent(event); 216 host_->ForwardKeyboardEvent(event);
249 if (input_queued_)
250 pending_key_command_ids_.push_back(command_id);
251 else
252 SendDispatchKeyEventResponse(command_id);
253 return Response::OK(); 217 return Response::OK();
254 } 218 }
255 219
256 Response InputHandler::DispatchMouseEvent( 220 Response InputHandler::DispatchMouseEvent(
257 DevToolsCommandId command_id,
258 const std::string& type, 221 const std::string& type,
259 int x, 222 int x,
260 int y, 223 int y,
261 const int* modifiers, 224 const int* modifiers,
262 const double* timestamp, 225 const double* timestamp,
263 const std::string* button, 226 const std::string* button,
264 const int* click_count) { 227 const int* click_count) {
265 blink::WebMouseEvent event; 228 blink::WebMouseEvent event;
266 229
267 if (!SetMouseEventType(&event, type)) { 230 if (!SetMouseEventType(&event, type)) {
(...skipping 11 matching lines...) Expand all
279 event.windowY = y * page_scale_factor_; 242 event.windowY = y * page_scale_factor_;
280 event.globalX = x * page_scale_factor_; 243 event.globalX = x * page_scale_factor_;
281 event.globalY = y * page_scale_factor_; 244 event.globalY = y * page_scale_factor_;
282 event.clickCount = click_count ? *click_count : 0; 245 event.clickCount = click_count ? *click_count : 0;
283 event.pointerType = blink::WebPointerProperties::PointerType::Mouse; 246 event.pointerType = blink::WebPointerProperties::PointerType::Mouse;
284 247
285 if (!host_) 248 if (!host_)
286 return Response::ServerError("Could not connect to view"); 249 return Response::ServerError("Could not connect to view");
287 250
288 host_->Focus(); 251 host_->Focus();
289 input_queued_ = false;
290 host_->ForwardMouseEvent(event); 252 host_->ForwardMouseEvent(event);
291 if (input_queued_)
292 pending_mouse_command_ids_.push_back(command_id);
293 else
294 SendDispatchMouseEventResponse(command_id);
295 return Response::OK(); 253 return Response::OK();
296 } 254 }
297 255
298 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, 256 Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type,
299 int x, 257 int x,
300 int y, 258 int y,
301 double timestamp, 259 double timestamp,
302 const std::string& button, 260 const std::string& button,
303 double* delta_x, 261 double* delta_x,
304 double* delta_y, 262 double* delta_y,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 472 }
515 473
516 Response InputHandler::DispatchTouchEvent( 474 Response InputHandler::DispatchTouchEvent(
517 const std::string& type, 475 const std::string& type,
518 const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points, 476 const std::vector<std::unique_ptr<base::DictionaryValue>>& touch_points,
519 const int* modifiers, 477 const int* modifiers,
520 const double* timestamp) { 478 const double* timestamp) {
521 return Response::FallThrough(); 479 return Response::FallThrough();
522 } 480 }
523 481
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
535 void InputHandler::SendSynthesizePinchGestureResponse( 482 void InputHandler::SendSynthesizePinchGestureResponse(
536 DevToolsCommandId command_id, 483 DevToolsCommandId command_id,
537 SyntheticGesture::Result result) { 484 SyntheticGesture::Result result) {
538 if (result == SyntheticGesture::Result::GESTURE_FINISHED) { 485 if (result == SyntheticGesture::Result::GESTURE_FINISHED) {
539 client_->SendSynthesizePinchGestureResponse( 486 client_->SendSynthesizePinchGestureResponse(
540 command_id, SynthesizePinchGestureResponse::Create()); 487 command_id, SynthesizePinchGestureResponse::Create());
541 } else { 488 } else {
542 client_->SendError(command_id, 489 client_->SendError(command_id,
543 Response::InternalError(base::StringPrintf( 490 Response::InternalError(base::StringPrintf(
544 "Synthetic pinch failed, result was %d", result))); 491 "Synthetic pinch failed, result was %d", result)));
(...skipping 22 matching lines...) Expand all
567 client_->SendSynthesizeTapGestureResponse( 514 client_->SendSynthesizeTapGestureResponse(
568 command_id, SynthesizeTapGestureResponse::Create()); 515 command_id, SynthesizeTapGestureResponse::Create());
569 } 516 }
570 } else { 517 } else {
571 client_->SendError(command_id, 518 client_->SendError(command_id,
572 Response::InternalError(base::StringPrintf( 519 Response::InternalError(base::StringPrintf(
573 "Synthetic tap failed, result was %d", result))); 520 "Synthetic tap failed, result was %d", result)));
574 } 521 }
575 } 522 }
576 523
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
589 } // namespace input 524 } // namespace input
590 } // namespace devtools 525 } // namespace devtools
591 } // namespace content 526 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/input_handler.h ('k') | content/browser/devtools/render_frame_devtools_agent_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698