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/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
7 #include "base/timer.h" | 7 #include "base/timer.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/aura/event.h" | 9 #include "ui/aura/event.h" |
10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 scroll_end_(false), | 44 scroll_end_(false), |
45 pinch_begin_(false), | 45 pinch_begin_(false), |
46 pinch_update_(false), | 46 pinch_update_(false), |
47 pinch_end_(false), | 47 pinch_end_(false), |
48 long_press_(false), | 48 long_press_(false), |
49 fling_(false), | 49 fling_(false), |
50 two_finger_tap_(false), | 50 two_finger_tap_(false), |
51 scroll_x_(0), | 51 scroll_x_(0), |
52 scroll_y_(0), | 52 scroll_y_(0), |
53 velocity_x_(0), | 53 velocity_x_(0), |
54 velocity_y_(0), | 54 velocity_y_(0) { |
55 radius_x_(0), | |
56 radius_y_(0) { | |
57 } | 55 } |
58 | 56 |
59 virtual ~GestureEventConsumeDelegate() {} | 57 virtual ~GestureEventConsumeDelegate() {} |
60 | 58 |
61 void Reset() { | 59 void Reset() { |
62 tap_ = false; | 60 tap_ = false; |
63 tap_down_ = false; | 61 tap_down_ = false; |
64 begin_ = false; | 62 begin_ = false; |
65 end_ = false; | 63 end_ = false; |
66 double_tap_ = false; | 64 double_tap_ = false; |
67 scroll_begin_ = false; | 65 scroll_begin_ = false; |
68 scroll_update_ = false; | 66 scroll_update_ = false; |
69 scroll_end_ = false; | 67 scroll_end_ = false; |
70 pinch_begin_ = false; | 68 pinch_begin_ = false; |
71 pinch_update_ = false; | 69 pinch_update_ = false; |
72 pinch_end_ = false; | 70 pinch_end_ = false; |
73 long_press_ = false; | 71 long_press_ = false; |
74 fling_ = false; | 72 fling_ = false; |
75 two_finger_tap_ = false; | 73 two_finger_tap_ = false; |
76 | 74 |
77 scroll_begin_position_.SetPoint(0, 0); | 75 scroll_begin_position_.SetPoint(0, 0); |
78 tap_location_.SetPoint(0, 0); | 76 tap_location_.SetPoint(0, 0); |
79 | 77 |
80 scroll_x_ = 0; | 78 scroll_x_ = 0; |
81 scroll_y_ = 0; | 79 scroll_y_ = 0; |
82 velocity_x_ = 0; | 80 velocity_x_ = 0; |
83 velocity_y_ = 0; | 81 velocity_y_ = 0; |
84 radius_x_ = 0; | |
85 radius_y_ = 0; | |
86 } | 82 } |
87 | 83 |
88 bool tap() const { return tap_; } | 84 bool tap() const { return tap_; } |
89 bool tap_down() const { return tap_down_; } | 85 bool tap_down() const { return tap_down_; } |
90 bool begin() const { return begin_; } | 86 bool begin() const { return begin_; } |
91 bool end() const { return end_; } | 87 bool end() const { return end_; } |
92 bool double_tap() const { return double_tap_; } | 88 bool double_tap() const { return double_tap_; } |
93 bool scroll_begin() const { return scroll_begin_; } | 89 bool scroll_begin() const { return scroll_begin_; } |
94 bool scroll_update() const { return scroll_update_; } | 90 bool scroll_update() const { return scroll_update_; } |
95 bool scroll_end() const { return scroll_end_; } | 91 bool scroll_end() const { return scroll_end_; } |
(...skipping 10 matching lines...) Expand all Loading... |
106 | 102 |
107 const gfx::Point tap_location() const { | 103 const gfx::Point tap_location() const { |
108 return tap_location_; | 104 return tap_location_; |
109 } | 105 } |
110 | 106 |
111 float scroll_x() const { return scroll_x_; } | 107 float scroll_x() const { return scroll_x_; } |
112 float scroll_y() const { return scroll_y_; } | 108 float scroll_y() const { return scroll_y_; } |
113 int touch_id() const { return touch_id_; } | 109 int touch_id() const { return touch_id_; } |
114 float velocity_x() const { return velocity_x_; } | 110 float velocity_x() const { return velocity_x_; } |
115 float velocity_y() const { return velocity_y_; } | 111 float velocity_y() const { return velocity_y_; } |
116 float radius_x() const { return radius_x_; } | 112 const gfx::Rect& bounding_box() const { return bounding_box_; } |
117 float radius_y() const { return radius_y_; } | |
118 | 113 |
119 virtual ui::GestureStatus OnGestureEvent(GestureEvent* gesture) OVERRIDE { | 114 virtual ui::GestureStatus OnGestureEvent(GestureEvent* gesture) OVERRIDE { |
| 115 bounding_box_ = gesture->details().bounding_box(); |
120 switch (gesture->type()) { | 116 switch (gesture->type()) { |
121 case ui::ET_GESTURE_TAP: | 117 case ui::ET_GESTURE_TAP: |
122 radius_x_ = gesture->details().radius_x(); | |
123 radius_y_ = gesture->details().radius_y(); | |
124 tap_location_ = gesture->location(); | 118 tap_location_ = gesture->location(); |
125 tap_ = true; | 119 tap_ = true; |
126 break; | 120 break; |
127 case ui::ET_GESTURE_TAP_DOWN: | 121 case ui::ET_GESTURE_TAP_DOWN: |
128 tap_down_ = true; | 122 tap_down_ = true; |
129 break; | 123 break; |
130 case ui::ET_GESTURE_BEGIN: | 124 case ui::ET_GESTURE_BEGIN: |
131 begin_ = true; | 125 begin_ = true; |
132 break; | 126 break; |
133 case ui::ET_GESTURE_END: | 127 case ui::ET_GESTURE_END: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 bool fling_; | 187 bool fling_; |
194 bool two_finger_tap_; | 188 bool two_finger_tap_; |
195 | 189 |
196 gfx::Point scroll_begin_position_; | 190 gfx::Point scroll_begin_position_; |
197 gfx::Point tap_location_; | 191 gfx::Point tap_location_; |
198 | 192 |
199 float scroll_x_; | 193 float scroll_x_; |
200 float scroll_y_; | 194 float scroll_y_; |
201 float velocity_x_; | 195 float velocity_x_; |
202 float velocity_y_; | 196 float velocity_y_; |
203 int radius_x_; | |
204 int radius_y_; | |
205 int touch_id_; | 197 int touch_id_; |
| 198 gfx::Rect bounding_box_; |
206 | 199 |
207 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); | 200 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); |
208 }; | 201 }; |
209 | 202 |
210 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { | 203 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { |
211 public: | 204 public: |
212 explicit QueueTouchEventDelegate(RootWindow* root_window) | 205 explicit QueueTouchEventDelegate(RootWindow* root_window) |
213 : window_(NULL), | 206 : window_(NULL), |
214 root_window_(root_window) { | 207 root_window_(root_window) { |
215 } | 208 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 EXPECT_TRUE(delegate->tap()); | 475 EXPECT_TRUE(delegate->tap()); |
483 EXPECT_FALSE(delegate->tap_down()); | 476 EXPECT_FALSE(delegate->tap_down()); |
484 EXPECT_FALSE(delegate->begin()); | 477 EXPECT_FALSE(delegate->begin()); |
485 EXPECT_TRUE(delegate->end()); | 478 EXPECT_TRUE(delegate->end()); |
486 EXPECT_FALSE(delegate->double_tap()); | 479 EXPECT_FALSE(delegate->double_tap()); |
487 EXPECT_FALSE(delegate->scroll_begin()); | 480 EXPECT_FALSE(delegate->scroll_begin()); |
488 EXPECT_FALSE(delegate->scroll_update()); | 481 EXPECT_FALSE(delegate->scroll_update()); |
489 EXPECT_FALSE(delegate->scroll_end()); | 482 EXPECT_FALSE(delegate->scroll_end()); |
490 | 483 |
491 gfx::Point actual_point(delegate->tap_location()); | 484 gfx::Point actual_point(delegate->tap_location()); |
492 EXPECT_EQ(12, delegate->radius_x()); | 485 EXPECT_EQ(24, delegate->bounding_box().width()); |
493 EXPECT_EQ(12, delegate->radius_y()); | 486 EXPECT_EQ(24, delegate->bounding_box().height()); |
494 EXPECT_EQ(100, actual_point.x()); | 487 EXPECT_EQ(100, actual_point.x()); |
495 EXPECT_EQ(200, actual_point.y()); | 488 EXPECT_EQ(200, actual_point.y()); |
496 } | 489 } |
497 | 490 |
498 // Test with no ET_TOUCH_MOVED events but different touch points and radii. | 491 // Test with no ET_TOUCH_MOVED events but different touch points and radii. |
499 { | 492 { |
500 delegate->Reset(); | 493 delegate->Reset(); |
501 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), | 494 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), |
502 kTouchId, GetTime()); | 495 kTouchId, GetTime()); |
503 press.set_radius_x(8); | 496 press.set_radius_x(8); |
(...skipping 19 matching lines...) Expand all Loading... |
523 EXPECT_TRUE(delegate->tap()); | 516 EXPECT_TRUE(delegate->tap()); |
524 EXPECT_FALSE(delegate->tap_down()); | 517 EXPECT_FALSE(delegate->tap_down()); |
525 EXPECT_FALSE(delegate->begin()); | 518 EXPECT_FALSE(delegate->begin()); |
526 EXPECT_TRUE(delegate->end()); | 519 EXPECT_TRUE(delegate->end()); |
527 EXPECT_FALSE(delegate->double_tap()); | 520 EXPECT_FALSE(delegate->double_tap()); |
528 EXPECT_FALSE(delegate->scroll_begin()); | 521 EXPECT_FALSE(delegate->scroll_begin()); |
529 EXPECT_FALSE(delegate->scroll_update()); | 522 EXPECT_FALSE(delegate->scroll_update()); |
530 EXPECT_FALSE(delegate->scroll_end()); | 523 EXPECT_FALSE(delegate->scroll_end()); |
531 | 524 |
532 gfx::Point actual_point(delegate->tap_location()); | 525 gfx::Point actual_point(delegate->tap_location()); |
533 EXPECT_EQ(23, delegate->radius_x()); | 526 EXPECT_EQ(46, delegate->bounding_box().width()); |
534 EXPECT_EQ(20, delegate->radius_y()); | 527 EXPECT_EQ(40, delegate->bounding_box().height()); |
535 EXPECT_EQ(373, actual_point.x()); | 528 EXPECT_EQ(373, actual_point.x()); |
536 EXPECT_EQ(290, actual_point.y()); | 529 EXPECT_EQ(290, actual_point.y()); |
537 } | 530 } |
538 | 531 |
539 // Test with a single ET_TOUCH_MOVED event. | 532 // Test with a single ET_TOUCH_MOVED event. |
540 { | 533 { |
541 delegate->Reset(); | 534 delegate->Reset(); |
542 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), | 535 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), |
543 kTouchId, GetTime()); | 536 kTouchId, GetTime()); |
544 press.set_radius_x(6); | 537 press.set_radius_x(6); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 EXPECT_TRUE(delegate->tap()); | 573 EXPECT_TRUE(delegate->tap()); |
581 EXPECT_FALSE(delegate->tap_down()); | 574 EXPECT_FALSE(delegate->tap_down()); |
582 EXPECT_FALSE(delegate->begin()); | 575 EXPECT_FALSE(delegate->begin()); |
583 EXPECT_TRUE(delegate->end()); | 576 EXPECT_TRUE(delegate->end()); |
584 EXPECT_FALSE(delegate->double_tap()); | 577 EXPECT_FALSE(delegate->double_tap()); |
585 EXPECT_FALSE(delegate->scroll_begin()); | 578 EXPECT_FALSE(delegate->scroll_begin()); |
586 EXPECT_FALSE(delegate->scroll_update()); | 579 EXPECT_FALSE(delegate->scroll_update()); |
587 EXPECT_FALSE(delegate->scroll_end()); | 580 EXPECT_FALSE(delegate->scroll_end()); |
588 | 581 |
589 gfx::Point actual_point(delegate->tap_location()); | 582 gfx::Point actual_point(delegate->tap_location()); |
590 EXPECT_EQ(14, delegate->radius_x()); | 583 EXPECT_EQ(28, delegate->bounding_box().width()); |
591 EXPECT_EQ(14, delegate->radius_y()); | 584 EXPECT_EQ(28, delegate->bounding_box().height()); |
592 EXPECT_EQ(49, actual_point.x()); | 585 EXPECT_EQ(49, actual_point.x()); |
593 EXPECT_EQ(200, actual_point.y()); | 586 EXPECT_EQ(200, actual_point.y()); |
594 } | 587 } |
595 | 588 |
596 // Test with a few ET_TOUCH_MOVED events. | 589 // Test with a few ET_TOUCH_MOVED events. |
597 { | 590 { |
598 delegate->Reset(); | 591 delegate->Reset(); |
599 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), | 592 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), |
600 kTouchId, GetTime()); | 593 kTouchId, GetTime()); |
601 press.set_radius_x(7); | 594 press.set_radius_x(7); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 EXPECT_TRUE(delegate->tap()); | 662 EXPECT_TRUE(delegate->tap()); |
670 EXPECT_FALSE(delegate->tap_down()); | 663 EXPECT_FALSE(delegate->tap_down()); |
671 EXPECT_FALSE(delegate->begin()); | 664 EXPECT_FALSE(delegate->begin()); |
672 EXPECT_TRUE(delegate->end()); | 665 EXPECT_TRUE(delegate->end()); |
673 EXPECT_FALSE(delegate->double_tap()); | 666 EXPECT_FALSE(delegate->double_tap()); |
674 EXPECT_FALSE(delegate->scroll_begin()); | 667 EXPECT_FALSE(delegate->scroll_begin()); |
675 EXPECT_FALSE(delegate->scroll_update()); | 668 EXPECT_FALSE(delegate->scroll_update()); |
676 EXPECT_FALSE(delegate->scroll_end()); | 669 EXPECT_FALSE(delegate->scroll_end()); |
677 | 670 |
678 gfx::Point actual_point(delegate->tap_location()); | 671 gfx::Point actual_point(delegate->tap_location()); |
679 EXPECT_EQ(17, delegate->radius_x()); | 672 EXPECT_EQ(35, delegate->bounding_box().width()); |
680 EXPECT_EQ(18, delegate->radius_y()); | 673 EXPECT_EQ(36, delegate->bounding_box().height()); |
681 EXPECT_EQ(396, actual_point.x()); | 674 EXPECT_EQ(396, actual_point.x()); |
682 EXPECT_EQ(149, actual_point.y()); | 675 EXPECT_EQ(149, actual_point.y()); |
683 } | 676 } |
684 } | 677 } |
685 | 678 |
686 // Check that appropriate touch events generate scroll gesture events. | 679 // Check that appropriate touch events generate scroll gesture events. |
687 TEST_F(GestureRecognizerTest, GestureEventScroll) { | 680 TEST_F(GestureRecognizerTest, GestureEventScroll) { |
688 scoped_ptr<GestureEventConsumeDelegate> delegate( | 681 scoped_ptr<GestureEventConsumeDelegate> delegate( |
689 new GestureEventConsumeDelegate()); | 682 new GestureEventConsumeDelegate()); |
690 const int kWindowWidth = 123; | 683 const int kWindowWidth = 123; |
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 EXPECT_FALSE(delegate->begin()); | 2292 EXPECT_FALSE(delegate->begin()); |
2300 EXPECT_TRUE(delegate->end()); | 2293 EXPECT_TRUE(delegate->end()); |
2301 EXPECT_FALSE(delegate->double_tap()); | 2294 EXPECT_FALSE(delegate->double_tap()); |
2302 EXPECT_FALSE(delegate->scroll_begin()); | 2295 EXPECT_FALSE(delegate->scroll_begin()); |
2303 EXPECT_FALSE(delegate->scroll_update()); | 2296 EXPECT_FALSE(delegate->scroll_update()); |
2304 EXPECT_TRUE(delegate->scroll_end()); | 2297 EXPECT_TRUE(delegate->scroll_end()); |
2305 } | 2298 } |
2306 | 2299 |
2307 } // namespace test | 2300 } // namespace test |
2308 } // namespace aura | 2301 } // namespace aura |
OLD | NEW |