Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer_host/input/synthetic_gesture_controller.h" | 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 break; | 471 break; |
| 472 } | 472 } |
| 473 } | 473 } |
| 474 }; | 474 }; |
| 475 | 475 |
| 476 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { | 476 class MockSyntheticPointerActionTarget : public MockSyntheticGestureTarget { |
| 477 public: | 477 public: |
| 478 MockSyntheticPointerActionTarget() {} | 478 MockSyntheticPointerActionTarget() {} |
| 479 ~MockSyntheticPointerActionTarget() override {} | 479 ~MockSyntheticPointerActionTarget() override {} |
| 480 | 480 |
| 481 gfx::PointF positions(int index) const { return positions_[index]; } | |
| 482 int indexes(int index) const { return indexes_[index]; } | |
| 483 WebTouchPoint::State states(int index) { return states_[index]; } | |
| 484 unsigned touch_length() const { return touch_length_; } | |
| 485 WebInputEvent::Type type() const { return type_; } | 481 WebInputEvent::Type type() const { return type_; } |
| 486 | 482 |
| 487 protected: | 483 protected: |
| 488 gfx::PointF positions_[kTouchPointersLength]; | |
| 489 unsigned touch_length_; | |
| 490 int indexes_[kTouchPointersLength]; | |
| 491 WebTouchPoint::State states_[kTouchPointersLength]; | |
| 492 WebInputEvent::Type type_; | 484 WebInputEvent::Type type_; |
| 493 }; | 485 }; |
| 494 | 486 |
| 495 class MockSyntheticPointerTouchActionTarget | 487 class MockSyntheticPointerTouchActionTarget |
| 496 : public MockSyntheticPointerActionTarget { | 488 : public MockSyntheticPointerActionTarget { |
| 497 public: | 489 public: |
| 498 MockSyntheticPointerTouchActionTarget() {} | 490 MockSyntheticPointerTouchActionTarget() {} |
| 499 ~MockSyntheticPointerTouchActionTarget() override {} | 491 ~MockSyntheticPointerTouchActionTarget() override {} |
| 500 | 492 |
| 501 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | 493 void DispatchInputEventToPlatform(const WebInputEvent& event) override { |
| 502 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); | 494 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
| 503 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); | 495 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
| 504 type_ = touch_event.type; | 496 type_ = touch_event.type; |
| 505 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 497 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
| 506 indexes_[i] = touch_event.touches[i].id; | 498 indexes_[i] = touch_event.touches[i].id; |
| 507 positions_[i] = gfx::PointF(touch_event.touches[i].position); | 499 positions_[i] = gfx::PointF(touch_event.touches[i].position); |
| 508 states_[i] = touch_event.touches[i].state; | 500 states_[i] = touch_event.touches[i].state; |
| 509 } | 501 } |
| 510 touch_length_ = touch_event.touchesLength; | 502 touch_length_ = touch_event.touchesLength; |
| 511 } | 503 } |
| 504 | |
| 505 gfx::PointF positions(int index) const { return positions_[index]; } | |
| 506 int indexes(int index) const { return indexes_[index]; } | |
| 507 WebTouchPoint::State states(int index) { return states_[index]; } | |
| 508 unsigned touch_length() const { return touch_length_; } | |
| 509 | |
| 510 private: | |
| 511 gfx::PointF positions_[kTouchPointersLength]; | |
| 512 unsigned touch_length_; | |
| 513 int indexes_[kTouchPointersLength]; | |
| 514 WebTouchPoint::State states_[kTouchPointersLength]; | |
| 515 }; | |
| 516 | |
| 517 class MockSyntheticPointerMouseActionTarget | |
| 518 : public MockSyntheticPointerActionTarget { | |
| 519 public: | |
| 520 MockSyntheticPointerMouseActionTarget() {} | |
| 521 ~MockSyntheticPointerMouseActionTarget() override {} | |
| 522 | |
| 523 void DispatchInputEventToPlatform(const WebInputEvent& event) override { | |
| 524 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); | |
| 525 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | |
| 526 type_ = mouse_event.type; | |
| 527 position_ = gfx::PointF(mouse_event.x, mouse_event.y); | |
| 528 clickCount_ = mouse_event.clickCount; | |
| 529 button_ = mouse_event.button; | |
| 530 } | |
| 531 | |
| 532 gfx::PointF position() const { return position_; } | |
| 533 int clickCount() const { return clickCount_; } | |
| 534 WebMouseEvent::Button button() const { return button_; } | |
| 535 | |
| 536 private: | |
| 537 gfx::PointF position_; | |
| 538 int clickCount_; | |
| 539 WebMouseEvent::Button button_; | |
| 512 }; | 540 }; |
| 513 | 541 |
| 514 class SyntheticGestureControllerTestBase { | 542 class SyntheticGestureControllerTestBase { |
| 515 public: | 543 public: |
| 516 SyntheticGestureControllerTestBase() {} | 544 SyntheticGestureControllerTestBase() {} |
| 517 ~SyntheticGestureControllerTestBase() {} | 545 ~SyntheticGestureControllerTestBase() {} |
| 518 | 546 |
| 519 protected: | 547 protected: |
| 520 template<typename MockGestureTarget> | 548 template<typename MockGestureTarget> |
| 521 void CreateControllerAndTarget() { | 549 void CreateControllerAndTarget() { |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 static_cast<MockSyntheticTapMouseTarget*>(target_); | 1493 static_cast<MockSyntheticTapMouseTarget*>(target_); |
| 1466 EXPECT_EQ(1, num_success_); | 1494 EXPECT_EQ(1, num_success_); |
| 1467 EXPECT_EQ(0, num_failure_); | 1495 EXPECT_EQ(0, num_failure_); |
| 1468 EXPECT_TRUE(tap_target->GestureFinished()); | 1496 EXPECT_TRUE(tap_target->GestureFinished()); |
| 1469 EXPECT_EQ(tap_target->position(), params.position); | 1497 EXPECT_EQ(tap_target->position(), params.position); |
| 1470 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 1498 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
| 1471 EXPECT_GE(GetTotalTime(), | 1499 EXPECT_GE(GetTotalTime(), |
| 1472 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 1500 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
| 1473 } | 1501 } |
| 1474 | 1502 |
| 1503 TEST_F(SyntheticGestureControllerTest, PointerTouchAction) { | |
| 1504 CreateControllerAndTarget<MockSyntheticPointerTouchActionTarget>(); | |
| 1505 std::unique_ptr<SyntheticPointer> synthetic_pointer = | |
| 1506 SyntheticPointer::Create(SyntheticGestureParams::TOUCH_INPUT); | |
| 1507 SyntheticPointerAction::IndexMap index_map; | |
| 1508 std::fill(index_map.begin(), index_map.end(), -1); | |
| 1509 SyntheticPointerActionListParams action_list_params; | |
| 1510 action_list_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
| 1511 | |
| 1512 SyntheticPointerActionParams params0 = SyntheticPointerActionParams( | |
| 1513 SyntheticGestureParams::TOUCH_INPUT, | |
| 1514 SyntheticPointerActionParams::PointerActionType::PRESS); | |
| 1515 SyntheticPointerActionParams params1 = SyntheticPointerActionParams( | |
| 1516 SyntheticGestureParams::TOUCH_INPUT, | |
| 1517 SyntheticPointerActionParams::PointerActionType::PRESS); | |
| 1518 params0.set_index(0); | |
| 1519 params0.set_position(gfx::PointF(54, 89)); | |
| 1520 params1.set_index(1); | |
| 1521 params1.set_position(gfx::PointF(79, 132)); | |
| 1522 action_list_params.param_list.push_back(params0); | |
| 1523 action_list_params.param_list.push_back(params1); | |
| 1524 std::unique_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( | |
| 1525 action_list_params, synthetic_pointer.get(), &index_map)); | |
|
tdresser
2016/10/31 14:22:57
We use a single SyntheticPointer for two separate
lanwei
2016/12/04 18:08:01
We are planing to support multiple pointer types i
lanwei
2016/12/04 18:08:02
Done.
| |
| 1526 QueueSyntheticGesture(std::move(gesture)); | |
| 1527 FlushInputUntilComplete(); | |
| 1528 | |
| 1529 MockSyntheticPointerTouchActionTarget* pointer_touch_target = | |
| 1530 static_cast<MockSyntheticPointerTouchActionTarget*>(target_); | |
| 1531 ASSERT_EQ(pointer_touch_target->touch_length(), 2u); | |
| 1532 EXPECT_EQ(pointer_touch_target->indexes(0), params0.index()); | |
| 1533 EXPECT_EQ(pointer_touch_target->positions(0), params0.position()); | |
| 1534 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StatePressed); | |
| 1535 EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); | |
| 1536 EXPECT_EQ(pointer_touch_target->positions(1), params1.position()); | |
| 1537 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StatePressed); | |
| 1538 | |
| 1539 action_list_params.param_list.clear(); | |
| 1540 params0.set_pointer_action_type( | |
| 1541 SyntheticPointerActionParams::PointerActionType::RELEASE); | |
| 1542 params1.set_pointer_action_type( | |
| 1543 SyntheticPointerActionParams::PointerActionType::MOVE); | |
| 1544 params1.set_position(gfx::PointF(183, 239)); | |
| 1545 action_list_params.param_list.push_back(params0); | |
| 1546 action_list_params.param_list.push_back(params1); | |
| 1547 gesture.reset(new SyntheticPointerAction( | |
| 1548 action_list_params, synthetic_pointer.get(), &index_map)); | |
| 1549 QueueSyntheticGesture(std::move(gesture)); | |
| 1550 FlushInputUntilComplete(); | |
| 1551 | |
| 1552 ASSERT_EQ(pointer_touch_target->touch_length(), 2u); | |
| 1553 EXPECT_EQ(pointer_touch_target->indexes(0), params0.index()); | |
| 1554 EXPECT_EQ(pointer_touch_target->states(0), WebTouchPoint::StateReleased); | |
| 1555 EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); | |
| 1556 EXPECT_EQ(pointer_touch_target->positions(1), params1.position()); | |
| 1557 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateMoved); | |
| 1558 | |
| 1559 action_list_params.param_list.clear(); | |
| 1560 params1.set_pointer_action_type( | |
| 1561 SyntheticPointerActionParams::PointerActionType::RELEASE); | |
| 1562 action_list_params.param_list.push_back(params1); | |
| 1563 gesture.reset(new SyntheticPointerAction( | |
| 1564 action_list_params, synthetic_pointer.get(), &index_map)); | |
| 1565 QueueSyntheticGesture(std::move(gesture)); | |
| 1566 FlushInputUntilComplete(); | |
| 1567 | |
| 1568 ASSERT_EQ(pointer_touch_target->touch_length(), 2u); | |
| 1569 EXPECT_EQ(pointer_touch_target->indexes(1), params1.index()); | |
| 1570 EXPECT_EQ(pointer_touch_target->states(1), WebTouchPoint::StateReleased); | |
| 1571 } | |
| 1572 | |
| 1573 TEST_F(SyntheticGestureControllerTest, PointerMouseAction) { | |
| 1574 CreateControllerAndTarget<MockSyntheticPointerMouseActionTarget>(); | |
| 1575 std::unique_ptr<SyntheticPointer> synthetic_pointer = | |
| 1576 SyntheticPointer::Create(SyntheticGestureParams::MOUSE_INPUT); | |
| 1577 SyntheticPointerAction::IndexMap index_map; | |
| 1578 std::fill(index_map.begin(), index_map.end(), -1); | |
| 1579 SyntheticPointerActionListParams action_list_params; | |
| 1580 action_list_params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; | |
| 1581 | |
| 1582 SyntheticPointerActionParams action_params = SyntheticPointerActionParams( | |
| 1583 SyntheticGestureParams::MOUSE_INPUT, | |
| 1584 SyntheticPointerActionParams::PointerActionType::MOVE); | |
| 1585 action_params.set_index(0); | |
| 1586 action_params.set_position(gfx::PointF(54, 89)); | |
| 1587 action_list_params.param_list.push_back(action_params); | |
| 1588 std::unique_ptr<SyntheticPointerAction> gesture(new SyntheticPointerAction( | |
| 1589 action_list_params, synthetic_pointer.get(), &index_map)); | |
| 1590 QueueSyntheticGesture(std::move(gesture)); | |
| 1591 FlushInputUntilComplete(); | |
| 1592 | |
| 1593 MockSyntheticPointerMouseActionTarget* pointer_mouse_target = | |
| 1594 static_cast<MockSyntheticPointerMouseActionTarget*>(target_); | |
| 1595 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | |
| 1596 EXPECT_EQ(pointer_mouse_target->position(), action_params.position()); | |
| 1597 EXPECT_EQ(pointer_mouse_target->clickCount(), 0); | |
| 1598 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::NoButton); | |
| 1599 | |
| 1600 action_list_params.param_list[0].set_pointer_action_type( | |
| 1601 SyntheticPointerActionParams::PointerActionType::PRESS); | |
| 1602 action_list_params.param_list[0].set_position(gfx::PointF(183, 239)); | |
| 1603 gesture.reset(new SyntheticPointerAction( | |
| 1604 action_list_params, synthetic_pointer.get(), &index_map)); | |
| 1605 QueueSyntheticGesture(std::move(gesture)); | |
| 1606 FlushInputUntilComplete(); | |
| 1607 | |
| 1608 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseDown); | |
| 1609 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(183, 239)); | |
| 1610 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | |
| 1611 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | |
| 1612 | |
| 1613 action_list_params.param_list[0].set_pointer_action_type( | |
| 1614 SyntheticPointerActionParams::PointerActionType::MOVE); | |
| 1615 action_list_params.param_list[0].set_position(gfx::PointF(254, 279)); | |
| 1616 gesture.reset(new SyntheticPointerAction( | |
| 1617 action_list_params, synthetic_pointer.get(), &index_map)); | |
| 1618 QueueSyntheticGesture(std::move(gesture)); | |
| 1619 FlushInputUntilComplete(); | |
| 1620 | |
| 1621 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseMove); | |
| 1622 EXPECT_EQ(pointer_mouse_target->position(), gfx::PointF(254, 279)); | |
| 1623 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | |
| 1624 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | |
| 1625 | |
| 1626 action_list_params.param_list[0].set_pointer_action_type( | |
| 1627 SyntheticPointerActionParams::PointerActionType::RELEASE); | |
| 1628 gesture.reset(new SyntheticPointerAction( | |
| 1629 action_list_params, synthetic_pointer.get(), &index_map)); | |
| 1630 QueueSyntheticGesture(std::move(gesture)); | |
| 1631 FlushInputUntilComplete(); | |
| 1632 | |
| 1633 EXPECT_EQ(pointer_mouse_target->type(), WebInputEvent::MouseUp); | |
| 1634 EXPECT_EQ(pointer_mouse_target->clickCount(), 1); | |
| 1635 EXPECT_EQ(pointer_mouse_target->button(), WebMouseEvent::Button::Left); | |
| 1636 } | |
| 1637 | |
| 1475 } // namespace | 1638 } // namespace |
| 1476 | 1639 |
| 1477 } // namespace content | 1640 } // namespace content |
| OLD | NEW |