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

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

Issue 1299643004: Make synthesizeScrollGesture repetable and emit interaction markers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a TODO Created 5 years, 4 months 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
« no previous file with comments | « content/browser/devtools/protocol/input_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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 // TODO(alexclarke): Can we move this elsewhere? It doesn't really fit here.
421 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console",
422 interaction_marker_name.c_str(), command_id);
423 }
424
381 host_->QueueSyntheticGesture( 425 host_->QueueSyntheticGesture(
382 SyntheticGesture::Create(gesture_params), 426 SyntheticGesture::Create(gesture_params),
383 base::Bind(&InputHandler::SendSynthesizeScrollGestureResponse, 427 base::Bind(&InputHandler::OnScrollFinished, weak_factory_.GetWeakPtr(),
384 weak_factory_.GetWeakPtr(), command_id)); 428 gesture_params, repeat_count, repeat_delay,
429 interaction_marker_name, command_id));
430 }
385 431
386 return Response::OK(); 432 void InputHandler::OnScrollFinished(
433 SyntheticSmoothScrollGestureParams gesture_params,
434 int repeat_count,
435 base::TimeDelta repeat_delay,
436 std::string interaction_marker_name,
437 DevToolsCommandId command_id,
438 SyntheticGesture::Result result) {
439 if (!interaction_marker_name.empty()) {
440 // Telemetry expects the interaction markers to be in the blink.console
441 // category.
442 TRACE_EVENT_COPY_ASYNC_END0("blink.console",
443 interaction_marker_name.c_str(), command_id);
444 }
445
446 if (repeat_count > 0) {
447 base::MessageLoop::current()->task_runner()->PostDelayedTask(
448 FROM_HERE,
449 base::Bind(&InputHandler::SynthesizeRepeatingScroll,
450 weak_factory_.GetWeakPtr(), gesture_params, repeat_count - 1,
451 repeat_delay, interaction_marker_name, command_id),
452 repeat_delay);
453 } else {
454 SendSynthesizeScrollGestureResponse(command_id, result);
455 }
387 } 456 }
388 457
389 Response InputHandler::SynthesizeTapGesture( 458 Response InputHandler::SynthesizeTapGesture(
390 DevToolsCommandId command_id, 459 DevToolsCommandId command_id,
391 int x, 460 int x,
392 int y, 461 int y,
393 const int* duration, 462 const int* duration,
394 const int* tap_count, 463 const int* tap_count,
395 const std::string* gesture_source_type) { 464 const std::string* gesture_source_type) {
396 if (!host_) 465 if (!host_)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } else { 532 } else {
464 client_->SendError(command_id, 533 client_->SendError(command_id,
465 Response::InternalError(base::StringPrintf( 534 Response::InternalError(base::StringPrintf(
466 "Synthetic tap failed, result was %d", result))); 535 "Synthetic tap failed, result was %d", result)));
467 } 536 }
468 } 537 }
469 538
470 } // namespace input 539 } // namespace input
471 } // namespace devtools 540 } // namespace devtools
472 } // namespace content 541 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/input_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698