| 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/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "cc/output/compositor_frame_metadata.h" | 11 #include "cc/output/compositor_frame_metadata.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 13 #include "content/common/input/synthetic_pinch_gesture_params.h" | 13 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 14 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 14 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 15 #include "content/common/input/synthetic_tap_gesture_params.h" | 15 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 16 #include "third_party/WebKit/public/web/WebInputEvent.h" | 16 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 17 #include "ui/events/keycodes/dom/keycode_converter.h" | 17 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 18 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 namespace devtools { | 21 namespace devtools { |
| 22 namespace input { | 22 namespace input { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 gfx::Point CssPixelsToPoint(int x, int y, float page_scale_factor) { | 26 gfx::PointF CssPixelsToPointF(int x, int y, float page_scale_factor) { |
| 27 return gfx::Point(x * page_scale_factor, y * page_scale_factor); | 27 return gfx::PointF(x * page_scale_factor, y * page_scale_factor); |
| 28 } | 28 } |
| 29 | 29 |
| 30 gfx::Vector2d CssPixelsToVector2d(int x, int y, float page_scale_factor) { | 30 gfx::Vector2dF CssPixelsToVector2dF(int x, int y, float page_scale_factor) { |
| 31 return gfx::Vector2d(x * page_scale_factor, y * page_scale_factor); | 31 return gfx::Vector2dF(x * page_scale_factor, y * page_scale_factor); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool StringToGestureSourceType(const std::string& in, | 34 bool StringToGestureSourceType(const std::string& in, |
| 35 SyntheticGestureParams::GestureSourceType& out) { | 35 SyntheticGestureParams::GestureSourceType& out) { |
| 36 if (in == kGestureSourceTypeDefault) { | 36 if (in == kGestureSourceTypeDefault) { |
| 37 out = SyntheticGestureParams::GestureSourceType::DEFAULT_INPUT; | 37 out = SyntheticGestureParams::GestureSourceType::DEFAULT_INPUT; |
| 38 return true; | 38 return true; |
| 39 } else if (in == kGestureSourceTypeTouch) { | 39 } else if (in == kGestureSourceTypeTouch) { |
| 40 out = SyntheticGestureParams::GestureSourceType::TOUCH_INPUT; | 40 out = SyntheticGestureParams::GestureSourceType::TOUCH_INPUT; |
| 41 return true; | 41 return true; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 double scale_factor, | 312 double scale_factor, |
| 313 const int* relative_speed, | 313 const int* relative_speed, |
| 314 const std::string* gesture_source_type) { | 314 const std::string* gesture_source_type) { |
| 315 if (!host_) | 315 if (!host_) |
| 316 return Response::ServerError("Could not connect to view"); | 316 return Response::ServerError("Could not connect to view"); |
| 317 | 317 |
| 318 SyntheticPinchGestureParams gesture_params; | 318 SyntheticPinchGestureParams gesture_params; |
| 319 const int kDefaultRelativeSpeed = 800; | 319 const int kDefaultRelativeSpeed = 800; |
| 320 | 320 |
| 321 gesture_params.scale_factor = scale_factor; | 321 gesture_params.scale_factor = scale_factor; |
| 322 gesture_params.anchor = CssPixelsToPoint(x, y, page_scale_factor_); | 322 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); |
| 323 gesture_params.relative_pointer_speed_in_pixels_s = | 323 gesture_params.relative_pointer_speed_in_pixels_s = |
| 324 relative_speed ? *relative_speed : kDefaultRelativeSpeed; | 324 relative_speed ? *relative_speed : kDefaultRelativeSpeed; |
| 325 | 325 |
| 326 if (!StringToGestureSourceType( | 326 if (!StringToGestureSourceType( |
| 327 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, | 327 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, |
| 328 gesture_params.gesture_source_type)) { | 328 gesture_params.gesture_source_type)) { |
| 329 return Response::InvalidParams("gestureSourceType"); | 329 return Response::InvalidParams("gestureSourceType"); |
| 330 } | 330 } |
| 331 | 331 |
| 332 host_->QueueSyntheticGesture( | 332 host_->QueueSyntheticGesture( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 351 const int* repeat_count, | 351 const int* repeat_count, |
| 352 const int* repeat_delay_ms, | 352 const int* repeat_delay_ms, |
| 353 const std::string* interaction_marker_name) { | 353 const std::string* interaction_marker_name) { |
| 354 if (!host_) | 354 if (!host_) |
| 355 return Response::ServerError("Could not connect to view"); | 355 return Response::ServerError("Could not connect to view"); |
| 356 | 356 |
| 357 SyntheticSmoothScrollGestureParams gesture_params; | 357 SyntheticSmoothScrollGestureParams gesture_params; |
| 358 const bool kDefaultPreventFling = true; | 358 const bool kDefaultPreventFling = true; |
| 359 const int kDefaultSpeed = 800; | 359 const int kDefaultSpeed = 800; |
| 360 | 360 |
| 361 gesture_params.anchor = CssPixelsToPoint(x, y, page_scale_factor_); | 361 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); |
| 362 gesture_params.prevent_fling = | 362 gesture_params.prevent_fling = |
| 363 prevent_fling ? *prevent_fling : kDefaultPreventFling; | 363 prevent_fling ? *prevent_fling : kDefaultPreventFling; |
| 364 gesture_params.speed_in_pixels_s = speed ? *speed : kDefaultSpeed; | 364 gesture_params.speed_in_pixels_s = speed ? *speed : kDefaultSpeed; |
| 365 | 365 |
| 366 if (x_distance || y_distance) { | 366 if (x_distance || y_distance) { |
| 367 gesture_params.distances.push_back( | 367 gesture_params.distances.push_back( |
| 368 CssPixelsToVector2d(x_distance ? *x_distance : 0, | 368 CssPixelsToVector2dF(x_distance ? *x_distance : 0, |
| 369 y_distance ? *y_distance : 0, | 369 y_distance ? *y_distance : 0, page_scale_factor_)); |
| 370 page_scale_factor_)); | |
| 371 } | 370 } |
| 372 | 371 |
| 373 if (x_overscroll || y_overscroll) { | 372 if (x_overscroll || y_overscroll) { |
| 374 gesture_params.distances.push_back( | 373 gesture_params.distances.push_back(CssPixelsToVector2dF( |
| 375 CssPixelsToVector2d(x_overscroll ? -*x_overscroll : 0, | 374 x_overscroll ? -*x_overscroll : 0, y_overscroll ? -*y_overscroll : 0, |
| 376 y_overscroll ? -*y_overscroll : 0, | 375 page_scale_factor_)); |
| 377 page_scale_factor_)); | |
| 378 } | 376 } |
| 379 | 377 |
| 380 if (!StringToGestureSourceType( | 378 if (!StringToGestureSourceType( |
| 381 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, | 379 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, |
| 382 gesture_params.gesture_source_type)) { | 380 gesture_params.gesture_source_type)) { |
| 383 return Response::InvalidParams("gestureSourceType"); | 381 return Response::InvalidParams("gestureSourceType"); |
| 384 } | 382 } |
| 385 | 383 |
| 386 SynthesizeRepeatingScroll( | 384 SynthesizeRepeatingScroll( |
| 387 gesture_params, repeat_count ? *repeat_count : 0, | 385 gesture_params, repeat_count ? *repeat_count : 0, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 const int* duration, | 440 const int* duration, |
| 443 const int* tap_count, | 441 const int* tap_count, |
| 444 const std::string* gesture_source_type) { | 442 const std::string* gesture_source_type) { |
| 445 if (!host_) | 443 if (!host_) |
| 446 return Response::ServerError("Could not connect to view"); | 444 return Response::ServerError("Could not connect to view"); |
| 447 | 445 |
| 448 SyntheticTapGestureParams gesture_params; | 446 SyntheticTapGestureParams gesture_params; |
| 449 const int kDefaultDuration = 50; | 447 const int kDefaultDuration = 50; |
| 450 const int kDefaultTapCount = 1; | 448 const int kDefaultTapCount = 1; |
| 451 | 449 |
| 452 gesture_params.position = CssPixelsToPoint(x, y, page_scale_factor_); | 450 gesture_params.position = CssPixelsToPointF(x, y, page_scale_factor_); |
| 453 gesture_params.duration_ms = duration ? *duration : kDefaultDuration; | 451 gesture_params.duration_ms = duration ? *duration : kDefaultDuration; |
| 454 | 452 |
| 455 if (!StringToGestureSourceType( | 453 if (!StringToGestureSourceType( |
| 456 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, | 454 gesture_source_type ? *gesture_source_type : kGestureSourceTypeDefault, |
| 457 gesture_params.gesture_source_type)) { | 455 gesture_params.gesture_source_type)) { |
| 458 return Response::InvalidParams("gestureSourceType"); | 456 return Response::InvalidParams("gestureSourceType"); |
| 459 } | 457 } |
| 460 | 458 |
| 461 if (!tap_count) | 459 if (!tap_count) |
| 462 tap_count = &kDefaultTapCount; | 460 tap_count = &kDefaultTapCount; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } else { | 510 } else { |
| 513 client_->SendError(command_id, | 511 client_->SendError(command_id, |
| 514 Response::InternalError(base::StringPrintf( | 512 Response::InternalError(base::StringPrintf( |
| 515 "Synthetic tap failed, result was %d", result))); | 513 "Synthetic tap failed, result was %d", result))); |
| 516 } | 514 } |
| 517 } | 515 } |
| 518 | 516 |
| 519 } // namespace input | 517 } // namespace input |
| 520 } // namespace devtools | 518 } // namespace devtools |
| 521 } // namespace content | 519 } // namespace content |
| OLD | NEW |