OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
6 #include "base/timer.h" | 6 #include "base/timer.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/aura/event.h" | 8 #include "ui/aura/event.h" |
9 #include "ui/aura/root_window.h" | 9 #include "ui/aura/root_window.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 : tap_(false), | 30 : tap_(false), |
31 tap_down_(false), | 31 tap_down_(false), |
32 double_tap_(false), | 32 double_tap_(false), |
33 scroll_begin_(false), | 33 scroll_begin_(false), |
34 scroll_update_(false), | 34 scroll_update_(false), |
35 scroll_end_(false), | 35 scroll_end_(false), |
36 pinch_begin_(false), | 36 pinch_begin_(false), |
37 pinch_update_(false), | 37 pinch_update_(false), |
38 pinch_end_(false), | 38 pinch_end_(false), |
39 long_press_(false), | 39 long_press_(false), |
| 40 three_finger_swipe_(false), |
40 scroll_x_(0), | 41 scroll_x_(0), |
41 scroll_y_(0), | 42 scroll_y_(0), |
42 velocity_x_(0), | 43 velocity_x_(0), |
43 velocity_y_(0) { | 44 velocity_y_(0) { |
44 } | 45 } |
45 | 46 |
46 virtual ~GestureEventConsumeDelegate() {} | 47 virtual ~GestureEventConsumeDelegate() {} |
47 | 48 |
48 void Reset() { | 49 void Reset() { |
49 tap_ = false; | 50 tap_ = false; |
50 tap_down_ = false; | 51 tap_down_ = false; |
51 double_tap_ = false; | 52 double_tap_ = false; |
52 scroll_begin_ = false; | 53 scroll_begin_ = false; |
53 scroll_update_ = false; | 54 scroll_update_ = false; |
54 scroll_end_ = false; | 55 scroll_end_ = false; |
55 pinch_begin_ = false; | 56 pinch_begin_ = false; |
56 pinch_update_ = false; | 57 pinch_update_ = false; |
57 pinch_end_ = false; | 58 pinch_end_ = false; |
58 long_press_ = false; | 59 long_press_ = false; |
| 60 three_finger_swipe_ = false; |
59 | 61 |
60 scroll_begin_position_.SetPoint(0, 0); | 62 scroll_begin_position_.SetPoint(0, 0); |
61 | 63 |
62 scroll_x_ = 0; | 64 scroll_x_ = 0; |
63 scroll_y_ = 0; | 65 scroll_y_ = 0; |
64 velocity_x_ = 0; | 66 velocity_x_ = 0; |
65 velocity_y_ = 0; | 67 velocity_y_ = 0; |
66 } | 68 } |
67 | 69 |
68 bool tap() const { return tap_; } | 70 bool tap() const { return tap_; } |
69 bool tap_down() const { return tap_down_; } | 71 bool tap_down() const { return tap_down_; } |
70 bool double_tap() const { return double_tap_; } | 72 bool double_tap() const { return double_tap_; } |
71 bool scroll_begin() const { return scroll_begin_; } | 73 bool scroll_begin() const { return scroll_begin_; } |
72 bool scroll_update() const { return scroll_update_; } | 74 bool scroll_update() const { return scroll_update_; } |
73 bool scroll_end() const { return scroll_end_; } | 75 bool scroll_end() const { return scroll_end_; } |
74 bool pinch_begin() const { return pinch_begin_; } | 76 bool pinch_begin() const { return pinch_begin_; } |
75 bool pinch_update() const { return pinch_update_; } | 77 bool pinch_update() const { return pinch_update_; } |
76 bool pinch_end() const { return pinch_end_; } | 78 bool pinch_end() const { return pinch_end_; } |
77 bool long_press() const { return long_press_; } | 79 bool long_press() const { return long_press_; } |
| 80 bool three_finger_swipe() const { return three_finger_swipe_; } |
78 | 81 |
79 const gfx::Point scroll_begin_position() const { | 82 const gfx::Point scroll_begin_position() const { |
80 return scroll_begin_position_; | 83 return scroll_begin_position_; |
81 } | 84 } |
82 | 85 |
83 float scroll_x() const { return scroll_x_; } | 86 float scroll_x() const { return scroll_x_; } |
84 float scroll_y() const { return scroll_y_; } | 87 float scroll_y() const { return scroll_y_; } |
85 int touch_id() const { return touch_id_; } | 88 int touch_id() const { return touch_id_; } |
86 float velocity_x() const { return velocity_x_; } | 89 float velocity_x() const { return velocity_x_; } |
87 float velocity_y() const { return velocity_y_; } | 90 float velocity_y() const { return velocity_y_; } |
(...skipping 29 matching lines...) Expand all Loading... |
117 case ui::ET_GESTURE_PINCH_UPDATE: | 120 case ui::ET_GESTURE_PINCH_UPDATE: |
118 pinch_update_ = true; | 121 pinch_update_ = true; |
119 break; | 122 break; |
120 case ui::ET_GESTURE_PINCH_END: | 123 case ui::ET_GESTURE_PINCH_END: |
121 pinch_end_ = true; | 124 pinch_end_ = true; |
122 break; | 125 break; |
123 case ui::ET_GESTURE_LONG_PRESS: | 126 case ui::ET_GESTURE_LONG_PRESS: |
124 long_press_ = true; | 127 long_press_ = true; |
125 touch_id_ = gesture->delta_x(); | 128 touch_id_ = gesture->delta_x(); |
126 break; | 129 break; |
| 130 case ui::ET_GESTURE_THREE_FINGER_SWIPE: |
| 131 three_finger_swipe_ = true; |
| 132 velocity_x_ = gesture->delta_x(); |
| 133 velocity_y_ = gesture->delta_y(); |
| 134 break; |
127 default: | 135 default: |
128 NOTREACHED(); | 136 NOTREACHED(); |
129 } | 137 } |
130 return ui::GESTURE_STATUS_CONSUMED; | 138 return ui::GESTURE_STATUS_CONSUMED; |
131 } | 139 } |
132 | 140 |
133 private: | 141 private: |
134 bool tap_; | 142 bool tap_; |
135 bool tap_down_; | 143 bool tap_down_; |
136 bool double_tap_; | 144 bool double_tap_; |
137 bool scroll_begin_; | 145 bool scroll_begin_; |
138 bool scroll_update_; | 146 bool scroll_update_; |
139 bool scroll_end_; | 147 bool scroll_end_; |
140 bool pinch_begin_; | 148 bool pinch_begin_; |
141 bool pinch_update_; | 149 bool pinch_update_; |
142 bool pinch_end_; | 150 bool pinch_end_; |
143 bool long_press_; | 151 bool long_press_; |
| 152 bool three_finger_swipe_; |
144 | 153 |
145 gfx::Point scroll_begin_position_; | 154 gfx::Point scroll_begin_position_; |
146 | 155 |
147 float scroll_x_; | 156 float scroll_x_; |
148 float scroll_y_; | 157 float scroll_y_; |
149 float velocity_x_; | 158 float velocity_x_; |
150 float velocity_y_; | 159 float velocity_y_; |
151 int touch_id_; | 160 int touch_id_; |
152 | 161 |
153 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); | 162 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 int dy, | 318 int dy, |
310 int touch_id, | 319 int touch_id, |
311 int time_step, | 320 int time_step, |
312 int num_steps, | 321 int num_steps, |
313 GestureEventConsumeDelegate* delegate) { | 322 GestureEventConsumeDelegate* delegate) { |
314 int x = x_start; | 323 int x = x_start; |
315 int y = y_start; | 324 int y = y_start; |
316 base::TimeDelta time = time_start; | 325 base::TimeDelta time = time_start; |
317 | 326 |
318 for (int i = 0; i < num_steps; i++) { | 327 for (int i = 0; i < num_steps; i++) { |
319 delegate->Reset(); | |
320 x += dx; | 328 x += dx; |
321 y += dy; | 329 y += dy; |
322 time = time + base::TimeDelta::FromMilliseconds(time_step); | 330 time = time + base::TimeDelta::FromMilliseconds(time_step); |
323 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), | 331 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), |
324 touch_id, time); | 332 touch_id, time); |
325 root_window->DispatchTouchEvent(&move); | 333 root_window->DispatchTouchEvent(&move); |
326 } | 334 } |
327 } | 335 } |
328 | 336 |
329 void SendScrollEvent(RootWindow* root_window, | 337 void SendScrollEvent(RootWindow* root_window, |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 root_window()->DispatchTouchEvent(&release); | 1486 root_window()->DispatchTouchEvent(&release); |
1479 | 1487 |
1480 delegate->Reset(); | 1488 delegate->Reset(); |
1481 delegate->ReceivedAck(); | 1489 delegate->ReceivedAck(); |
1482 EXPECT_TRUE(delegate->tap_down()); | 1490 EXPECT_TRUE(delegate->tap_down()); |
1483 delegate->Reset(); | 1491 delegate->Reset(); |
1484 delegate->ReceivedAckPreventDefaulted(); | 1492 delegate->ReceivedAckPreventDefaulted(); |
1485 EXPECT_FALSE(delegate->tap()); | 1493 EXPECT_FALSE(delegate->tap()); |
1486 } | 1494 } |
1487 | 1495 |
| 1496 TEST_F(GestureRecognizerTest, GestureEventThreeFingerSwipe) { |
| 1497 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1498 new GestureEventConsumeDelegate()); |
| 1499 const int kTouchId1 = 7; |
| 1500 const int kTouchId2 = 2; |
| 1501 const int kTouchId3 = 9; |
| 1502 gfx::Rect bounds(0, 0, 1000, 1000); |
| 1503 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1504 delegate.get(), -1234, bounds, NULL)); |
| 1505 |
| 1506 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
| 1507 kTouchId1, GetTime()); |
| 1508 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
| 1509 kTouchId2, GetTime()); |
| 1510 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
| 1511 kTouchId3, GetTime()); |
| 1512 |
| 1513 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), |
| 1514 kTouchId1, GetTime()); |
| 1515 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), |
| 1516 kTouchId2, GetTime()); |
| 1517 TouchEvent release3(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), |
| 1518 kTouchId3, GetTime()); |
| 1519 |
| 1520 root_window()->DispatchTouchEvent(&press1); |
| 1521 root_window()->DispatchTouchEvent(&press2); |
| 1522 root_window()->DispatchTouchEvent(&press3); |
| 1523 |
| 1524 delegate->Reset(); |
| 1525 |
| 1526 // Start by testing all four directions |
| 1527 |
| 1528 int kBufferedPoints = |
| 1529 ui::GestureConfiguration::points_buffered_for_velocity(); |
| 1530 |
| 1531 // Swipe right |
| 1532 SendScrollEvents(root_window(), 1, 1, press1.time_stamp(), |
| 1533 100, 10, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1534 SendScrollEvents(root_window(), 1, 1, press2.time_stamp(), |
| 1535 100, 10, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1536 SendScrollEvents(root_window(), 1, 1, press3.time_stamp(), |
| 1537 100, 10, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1538 |
| 1539 EXPECT_TRUE(delegate->three_finger_swipe()); |
| 1540 EXPECT_EQ(1, delegate->velocity_x()); |
| 1541 EXPECT_EQ(0, delegate->velocity_y()); |
| 1542 |
| 1543 root_window()->DispatchTouchEvent(&release1); |
| 1544 root_window()->DispatchTouchEvent(&release2); |
| 1545 root_window()->DispatchTouchEvent(&release3); |
| 1546 |
| 1547 root_window()->DispatchTouchEvent(&press1); |
| 1548 root_window()->DispatchTouchEvent(&press2); |
| 1549 root_window()->DispatchTouchEvent(&press3); |
| 1550 |
| 1551 delegate->Reset(); |
| 1552 |
| 1553 // Swipe left |
| 1554 SendScrollEvents(root_window(), 1, 1, |
| 1555 press1.time_stamp(), |
| 1556 -100, 10, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1557 SendScrollEvents(root_window(), 1, 1, |
| 1558 press2.time_stamp(), |
| 1559 -100, 10, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1560 SendScrollEvents(root_window(), 1, 1, |
| 1561 press3.time_stamp(), |
| 1562 -100, 10, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1563 |
| 1564 EXPECT_TRUE(delegate->three_finger_swipe()); |
| 1565 EXPECT_EQ(-1, delegate->velocity_x()); |
| 1566 EXPECT_EQ(0, delegate->velocity_y()); |
| 1567 |
| 1568 root_window()->DispatchTouchEvent(&release1); |
| 1569 root_window()->DispatchTouchEvent(&release2); |
| 1570 root_window()->DispatchTouchEvent(&release3); |
| 1571 |
| 1572 root_window()->DispatchTouchEvent(&press1); |
| 1573 root_window()->DispatchTouchEvent(&press2); |
| 1574 root_window()->DispatchTouchEvent(&press3); |
| 1575 |
| 1576 delegate->Reset(); |
| 1577 |
| 1578 // Swipe down |
| 1579 SendScrollEvents(root_window(), 1, 1, |
| 1580 press1.time_stamp(), |
| 1581 10, 100, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1582 SendScrollEvents(root_window(), 1, 1, |
| 1583 press2.time_stamp(), |
| 1584 10, 100, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1585 SendScrollEvents(root_window(), 1, 1, |
| 1586 press3.time_stamp(), |
| 1587 10, 100, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1588 |
| 1589 EXPECT_TRUE(delegate->three_finger_swipe()); |
| 1590 EXPECT_EQ(0, delegate->velocity_x()); |
| 1591 EXPECT_EQ(1, delegate->velocity_y()); |
| 1592 |
| 1593 root_window()->DispatchTouchEvent(&release1); |
| 1594 root_window()->DispatchTouchEvent(&release2); |
| 1595 root_window()->DispatchTouchEvent(&release3); |
| 1596 |
| 1597 root_window()->DispatchTouchEvent(&press1); |
| 1598 root_window()->DispatchTouchEvent(&press2); |
| 1599 root_window()->DispatchTouchEvent(&press3); |
| 1600 |
| 1601 delegate->Reset(); |
| 1602 |
| 1603 // Swipe up |
| 1604 SendScrollEvents(root_window(), 1, 1, |
| 1605 press1.time_stamp(), |
| 1606 10, -100, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1607 SendScrollEvents(root_window(), 1, 1, |
| 1608 press2.time_stamp(), |
| 1609 10, -100, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1610 SendScrollEvents(root_window(), 1, 1, |
| 1611 press3.time_stamp(), |
| 1612 10, -100, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1613 |
| 1614 EXPECT_TRUE(delegate->three_finger_swipe()); |
| 1615 EXPECT_EQ(0, delegate->velocity_x()); |
| 1616 EXPECT_EQ(-1, delegate->velocity_y()); |
| 1617 |
| 1618 // Only one swipe can occur per press of three fingers |
| 1619 delegate->Reset(); |
| 1620 |
| 1621 SendScrollEvents(root_window(), 1, 1, |
| 1622 press1.time_stamp(), |
| 1623 10, -100, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1624 SendScrollEvents(root_window(), 1, 1, |
| 1625 press2.time_stamp(), |
| 1626 10, -100, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1627 SendScrollEvents(root_window(), 1, 1, |
| 1628 press3.time_stamp(), |
| 1629 10, -100, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1630 |
| 1631 EXPECT_FALSE(delegate->three_finger_swipe()); |
| 1632 |
| 1633 root_window()->DispatchTouchEvent(&release1); |
| 1634 root_window()->DispatchTouchEvent(&release2); |
| 1635 root_window()->DispatchTouchEvent(&release3); |
| 1636 |
| 1637 root_window()->DispatchTouchEvent(&press1); |
| 1638 root_window()->DispatchTouchEvent(&press2); |
| 1639 root_window()->DispatchTouchEvent(&press3); |
| 1640 |
| 1641 delegate->Reset(); |
| 1642 |
| 1643 // Swiping diagonally doesn't fire an event |
| 1644 SendScrollEvents(root_window(), 1, 1, |
| 1645 press1.time_stamp(), |
| 1646 100, -100, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1647 SendScrollEvents(root_window(), 1, 1, |
| 1648 press2.time_stamp(), |
| 1649 100, -100, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1650 SendScrollEvents(root_window(), 1, 1, |
| 1651 press3.time_stamp(), |
| 1652 100, -100, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1653 |
| 1654 EXPECT_FALSE(delegate->three_finger_swipe()); |
| 1655 |
| 1656 root_window()->DispatchTouchEvent(&release1); |
| 1657 root_window()->DispatchTouchEvent(&release2); |
| 1658 root_window()->DispatchTouchEvent(&release3); |
| 1659 |
| 1660 root_window()->DispatchTouchEvent(&press1); |
| 1661 root_window()->DispatchTouchEvent(&press2); |
| 1662 root_window()->DispatchTouchEvent(&press3); |
| 1663 |
| 1664 delegate->Reset(); |
| 1665 |
| 1666 // Have to swipe in a consistent direction |
| 1667 SendScrollEvents(root_window(), 1, 1, |
| 1668 press1.time_stamp(), |
| 1669 100, 10, kTouchId1, 1, kBufferedPoints, delegate.get()); |
| 1670 SendScrollEvents(root_window(), 1, 1, |
| 1671 press2.time_stamp(), |
| 1672 100, 10, kTouchId2, 1, kBufferedPoints, delegate.get()); |
| 1673 SendScrollEvents(root_window(), 1, 1, |
| 1674 press3.time_stamp(), |
| 1675 -100, 10, kTouchId3, 1, kBufferedPoints, delegate.get()); |
| 1676 |
| 1677 EXPECT_FALSE(delegate->three_finger_swipe()); |
| 1678 |
| 1679 // Three fingers should transition to pinch |
| 1680 root_window()->DispatchTouchEvent(&release1); |
| 1681 |
| 1682 EXPECT_TRUE(delegate->pinch_begin()); |
| 1683 } |
| 1684 |
1488 } // namespace test | 1685 } // namespace test |
1489 } // namespace aura | 1686 } // namespace aura |
OLD | NEW |