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 "base/message_loop/message_loop.h" | |
7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/trace_event/trace_event.h" | |
9 #include "cc/output/compositor_frame_metadata.h" | 11 #include "cc/output/compositor_frame_metadata.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
11 #include "content/common/input/synthetic_pinch_gesture_params.h" | 13 #include "content/common/input/synthetic_pinch_gesture_params.h" |
12 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 14 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
13 #include "content/common/input/synthetic_tap_gesture_params.h" | 15 #include "content/common/input/synthetic_tap_gesture_params.h" |
14 #include "third_party/WebKit/public/web/WebInputEvent.h" | 16 #include "third_party/WebKit/public/web/WebInputEvent.h" |
15 #include "ui/events/keycodes/dom/keycode_converter.h" | 17 #include "ui/events/keycodes/dom/keycode_converter.h" |
16 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
17 | 19 |
18 namespace content { | 20 namespace content { |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 DevToolsCommandId command_id, | 341 DevToolsCommandId command_id, |
340 int x, | 342 int x, |
341 int y, | 343 int y, |
342 const int* x_distance, | 344 const int* x_distance, |
343 const int* y_distance, | 345 const int* y_distance, |
344 const int* x_overscroll, | 346 const int* x_overscroll, |
345 const int* y_overscroll, | 347 const int* y_overscroll, |
346 const bool* prevent_fling, | 348 const bool* prevent_fling, |
347 const int* speed, | 349 const int* speed, |
348 const std::string* gesture_source_type) { | 350 const std::string* gesture_source_type) { |
351 return SynthesizeScrollGesture( | |
352 command_id, x, y, x_distance, y_distance, x_overscroll, y_overscroll, | |
353 prevent_fling, speed, gesture_source_type, nullptr, nullptr, nullptr); | |
354 } | |
355 | |
356 Response InputHandler::SynthesizeScrollGesture( | |
357 DevToolsCommandId command_id, | |
358 int x, | |
359 int y, | |
360 const int* x_distance, | |
361 const int* y_distance, | |
362 const int* x_overscroll, | |
363 const int* y_overscroll, | |
364 const bool* prevent_fling, | |
365 const int* speed, | |
366 const std::string* gesture_source_type, | |
367 const int* repeat_count, | |
368 const int* repeat_delay_ms, | |
369 const std::string* interaction_marker_name) { | |
349 if (!host_) | 370 if (!host_) |
350 return Response::ServerError("Could not connect to view"); | 371 return Response::ServerError("Could not connect to view"); |
351 | 372 |
352 SyntheticSmoothScrollGestureParams gesture_params; | 373 SyntheticSmoothScrollGestureParams gesture_params; |
353 const bool kDefaultPreventFling = true; | 374 const bool kDefaultPreventFling = true; |
354 const int kDefaultSpeed = 800; | 375 const int kDefaultSpeed = 800; |
355 | 376 |
356 gesture_params.anchor = CssPixelsToPoint(x, y, page_scale_factor_); | 377 gesture_params.anchor = CssPixelsToPoint(x, y, page_scale_factor_); |
357 gesture_params.prevent_fling = | 378 gesture_params.prevent_fling = |
358 prevent_fling ? *prevent_fling : kDefaultPreventFling; | 379 prevent_fling ? *prevent_fling : kDefaultPreventFling; |
(...skipping 12 matching lines...) Expand all Loading... | |
371 y_overscroll ? -*y_overscroll : 0, | 392 y_overscroll ? -*y_overscroll : 0, |
372 page_scale_factor_)); | 393 page_scale_factor_)); |
373 } | 394 } |
374 | 395 |
375 if (!StringToGestureSourceType( | 396 if (!StringToGestureSourceType( |
376 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, | 397 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, |
377 gesture_params.gesture_source_type)) { | 398 gesture_params.gesture_source_type)) { |
378 return Response::InvalidParams("gestureSourceType"); | 399 return Response::InvalidParams("gestureSourceType"); |
379 } | 400 } |
380 | 401 |
402 SynthesizeRepeatingScroll( | |
403 gesture_params, repeat_count ? *repeat_count : 0, | |
404 base::TimeDelta::FromMilliseconds(repeat_delay_ms ? *repeat_delay_ms | |
405 : 250), | |
406 interaction_marker_name ? *interaction_marker_name : "", command_id); | |
407 | |
408 return Response::OK(); | |
409 } | |
410 | |
411 void InputHandler::SynthesizeRepeatingScroll( | |
412 SyntheticSmoothScrollGestureParams gesture_params, | |
413 int repeat_count, | |
414 base::TimeDelta repeat_delay, | |
415 std::string interaction_marker_name, | |
416 DevToolsCommandId command_id) { | |
417 if (!interaction_marker_name.empty()) { | |
418 // Telemetry expects the interaction markers to be in the blink.console | |
419 // category. | |
420 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", | |
421 interaction_marker_name.c_str(), command_id); | |
422 } | |
423 | |
381 host_->QueueSyntheticGesture( | 424 host_->QueueSyntheticGesture( |
382 SyntheticGesture::Create(gesture_params), | 425 SyntheticGesture::Create(gesture_params), |
383 base::Bind(&InputHandler::SendSynthesizeScrollGestureResponse, | 426 base::Bind(&InputHandler::OnScrollFinished, weak_factory_.GetWeakPtr(), |
384 weak_factory_.GetWeakPtr(), command_id)); | 427 gesture_params, repeat_count, repeat_delay, |
428 interaction_marker_name, command_id)); | |
429 } | |
385 | 430 |
386 return Response::OK(); | 431 void InputHandler::OnScrollFinished( |
432 SyntheticSmoothScrollGestureParams gesture_params, | |
433 int repeat_count, | |
434 base::TimeDelta repeat_delay, | |
435 std::string interaction_marker_name, | |
436 DevToolsCommandId command_id, | |
437 SyntheticGesture::Result result) { | |
438 if (!interaction_marker_name.empty()) { | |
439 // Telemetry expects the interaction markers to be in the blink.console | |
440 // category. | |
441 TRACE_EVENT_COPY_ASYNC_END0("blink.console", | |
442 interaction_marker_name.c_str(), command_id); | |
443 } | |
444 | |
445 if (repeat_count > 0) { | |
446 base::MessageLoop::current()->task_runner()->PostDelayedTask( | |
447 FROM_HERE, | |
448 base::Bind(&InputHandler::SynthesizeRepeatingScroll, | |
449 weak_factory_.GetWeakPtr(), gesture_params, repeat_count - 1, | |
450 repeat_delay, interaction_marker_name, command_id), | |
451 repeat_delay); | |
452 } else { | |
453 SendSynthesizePinchGestureResponse(command_id, result); | |
Sami
2015/08/17 16:35:48
Should this be a scroll gesture response instead?
alex clarke (OOO till 29th)
2015/08/17 16:42:22
Whoops. Yes :)
| |
454 } | |
387 } | 455 } |
388 | 456 |
389 Response InputHandler::SynthesizeTapGesture( | 457 Response InputHandler::SynthesizeTapGesture( |
390 DevToolsCommandId command_id, | 458 DevToolsCommandId command_id, |
391 int x, | 459 int x, |
392 int y, | 460 int y, |
393 const int* duration, | 461 const int* duration, |
394 const int* tap_count, | 462 const int* tap_count, |
395 const std::string* gesture_source_type) { | 463 const std::string* gesture_source_type) { |
396 if (!host_) | 464 if (!host_) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 } else { | 531 } else { |
464 client_->SendError(command_id, | 532 client_->SendError(command_id, |
465 Response::InternalError(base::StringPrintf( | 533 Response::InternalError(base::StringPrintf( |
466 "Synthetic tap failed, result was %d", result))); | 534 "Synthetic tap failed, result was %d", result))); |
467 } | 535 } |
468 } | 536 } |
469 | 537 |
470 } // namespace input | 538 } // namespace input |
471 } // namespace devtools | 539 } // namespace devtools |
472 } // namespace content | 540 } // namespace content |
OLD | NEW |