| 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 if (!host_ || !host_->GetRenderWidgetHost()) { | 468 if (!host_ || !host_->GetRenderWidgetHost()) { |
| 469 callback->sendFailure(Response::InternalError()); | 469 callback->sendFailure(Response::InternalError()); |
| 470 return; | 470 return; |
| 471 } | 471 } |
| 472 | 472 |
| 473 SyntheticPinchGestureParams gesture_params; | 473 SyntheticPinchGestureParams gesture_params; |
| 474 const int kDefaultRelativeSpeed = 800; | 474 const int kDefaultRelativeSpeed = 800; |
| 475 | 475 |
| 476 gesture_params.scale_factor = scale_factor; | 476 gesture_params.scale_factor = scale_factor; |
| 477 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); | 477 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); |
| 478 if (!PointIsWithinContents(gesture_params.anchor)) { |
| 479 callback->sendFailure(Response::InvalidParams("Position out of bounds")); |
| 480 return; |
| 481 } |
| 482 |
| 478 gesture_params.relative_pointer_speed_in_pixels_s = | 483 gesture_params.relative_pointer_speed_in_pixels_s = |
| 479 relative_speed.fromMaybe(kDefaultRelativeSpeed); | 484 relative_speed.fromMaybe(kDefaultRelativeSpeed); |
| 480 | 485 |
| 481 if (!StringToGestureSourceType( | 486 if (!StringToGestureSourceType( |
| 482 std::move(gesture_source_type), | 487 std::move(gesture_source_type), |
| 483 gesture_params.gesture_source_type)) { | 488 gesture_params.gesture_source_type)) { |
| 484 callback->sendFailure( | 489 callback->sendFailure( |
| 485 Response::InvalidParams("Unknown gestureSourceType")); | 490 Response::InvalidParams("Unknown gestureSourceType")); |
| 486 return; | 491 return; |
| 487 } | 492 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 509 if (!host_ || !host_->GetRenderWidgetHost()) { | 514 if (!host_ || !host_->GetRenderWidgetHost()) { |
| 510 callback->sendFailure(Response::InternalError()); | 515 callback->sendFailure(Response::InternalError()); |
| 511 return; | 516 return; |
| 512 } | 517 } |
| 513 | 518 |
| 514 SyntheticSmoothScrollGestureParams gesture_params; | 519 SyntheticSmoothScrollGestureParams gesture_params; |
| 515 const bool kDefaultPreventFling = true; | 520 const bool kDefaultPreventFling = true; |
| 516 const int kDefaultSpeed = 800; | 521 const int kDefaultSpeed = 800; |
| 517 | 522 |
| 518 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); | 523 gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_); |
| 524 if (!PointIsWithinContents(gesture_params.anchor)) { |
| 525 callback->sendFailure(Response::InvalidParams("Position out of bounds")); |
| 526 return; |
| 527 } |
| 528 |
| 519 gesture_params.prevent_fling = | 529 gesture_params.prevent_fling = |
| 520 prevent_fling.fromMaybe(kDefaultPreventFling); | 530 prevent_fling.fromMaybe(kDefaultPreventFling); |
| 521 gesture_params.speed_in_pixels_s = speed.fromMaybe(kDefaultSpeed); | 531 gesture_params.speed_in_pixels_s = speed.fromMaybe(kDefaultSpeed); |
| 522 | 532 |
| 523 if (x_distance.fromJust() || y_distance.fromJust()) { | 533 if (x_distance.isJust() || y_distance.isJust()) { |
| 524 gesture_params.distances.push_back( | 534 gesture_params.distances.push_back( |
| 525 CssPixelsToVector2dF(x_distance.fromMaybe(0), | 535 CssPixelsToVector2dF(x_distance.fromMaybe(0), |
| 526 y_distance.fromMaybe(0), page_scale_factor_)); | 536 y_distance.fromMaybe(0), page_scale_factor_)); |
| 527 } | 537 } |
| 528 | 538 |
| 529 if (x_overscroll.isJust() || y_overscroll.isJust()) { | 539 if (x_overscroll.isJust() || y_overscroll.isJust()) { |
| 530 gesture_params.distances.push_back(CssPixelsToVector2dF( | 540 gesture_params.distances.push_back(CssPixelsToVector2dF( |
| 531 -x_overscroll.fromMaybe(0), -y_overscroll.fromMaybe(0), | 541 -x_overscroll.fromMaybe(0), -y_overscroll.fromMaybe(0), |
| 532 page_scale_factor_)); | 542 page_scale_factor_)); |
| 533 } | 543 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 if (!host_ || !host_->GetRenderWidgetHost()) { | 613 if (!host_ || !host_->GetRenderWidgetHost()) { |
| 604 callback->sendFailure(Response::InternalError()); | 614 callback->sendFailure(Response::InternalError()); |
| 605 return; | 615 return; |
| 606 } | 616 } |
| 607 | 617 |
| 608 SyntheticTapGestureParams gesture_params; | 618 SyntheticTapGestureParams gesture_params; |
| 609 const int kDefaultDuration = 50; | 619 const int kDefaultDuration = 50; |
| 610 const int kDefaultTapCount = 1; | 620 const int kDefaultTapCount = 1; |
| 611 | 621 |
| 612 gesture_params.position = CssPixelsToPointF(x, y, page_scale_factor_); | 622 gesture_params.position = CssPixelsToPointF(x, y, page_scale_factor_); |
| 623 if (!PointIsWithinContents(gesture_params.position)) { |
| 624 callback->sendFailure(Response::InvalidParams("Position out of bounds")); |
| 625 return; |
| 626 } |
| 627 |
| 613 gesture_params.duration_ms = duration.fromMaybe(kDefaultDuration); | 628 gesture_params.duration_ms = duration.fromMaybe(kDefaultDuration); |
| 614 | 629 |
| 615 if (!StringToGestureSourceType( | 630 if (!StringToGestureSourceType( |
| 616 std::move(gesture_source_type), | 631 std::move(gesture_source_type), |
| 617 gesture_params.gesture_source_type)) { | 632 gesture_params.gesture_source_type)) { |
| 618 callback->sendFailure( | 633 callback->sendFailure( |
| 619 Response::InvalidParams("Unknown gestureSourceType")); | 634 Response::InvalidParams("Unknown gestureSourceType")); |
| 620 return; | 635 return; |
| 621 } | 636 } |
| 622 | 637 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 638 | 653 |
| 639 void InputHandler::ClearPendingKeyAndMouseCallbacks() { | 654 void InputHandler::ClearPendingKeyAndMouseCallbacks() { |
| 640 for (auto& callback : pending_key_callbacks_) | 655 for (auto& callback : pending_key_callbacks_) |
| 641 callback->sendSuccess(); | 656 callback->sendSuccess(); |
| 642 pending_key_callbacks_.clear(); | 657 pending_key_callbacks_.clear(); |
| 643 for (auto& callback : pending_mouse_callbacks_) | 658 for (auto& callback : pending_mouse_callbacks_) |
| 644 callback->sendSuccess(); | 659 callback->sendSuccess(); |
| 645 pending_mouse_callbacks_.clear(); | 660 pending_mouse_callbacks_.clear(); |
| 646 } | 661 } |
| 647 | 662 |
| 663 bool InputHandler::PointIsWithinContents(gfx::PointF point) const { |
| 664 gfx::Rect bounds = host_->GetView()->GetViewBounds(); |
| 665 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). |
| 666 return bounds.Contains(point.x(), point.y()); |
| 667 } |
| 668 |
| 648 } // namespace protocol | 669 } // namespace protocol |
| 649 } // namespace content | 670 } // namespace content |
| OLD | NEW |