Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "views/views_delegate.h" | 37 #include "views/views_delegate.h" |
| 38 #include "views/widget/native_widget.h" | 38 #include "views/widget/native_widget.h" |
| 39 #include "views/widget/root_view.h" | 39 #include "views/widget/root_view.h" |
| 40 | 40 |
| 41 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
| 42 #include "views/test/test_views_delegate.h" | 42 #include "views/test/test_views_delegate.h" |
| 43 #endif | 43 #endif |
| 44 #if defined(USE_AURA) | 44 #if defined(USE_AURA) |
| 45 #include "ui/aura/desktop.h" | 45 #include "ui/aura/desktop.h" |
| 46 #endif | 46 #endif |
| 47 #if defined(TOUCH_UI) | |
| 48 #include "views/touchui/gesture_recognizer.h" | |
| 49 #endif | |
| 47 | 50 |
| 48 using ::testing::_; | 51 using ::testing::_; |
| 49 | 52 |
| 50 namespace { | 53 namespace { |
| 51 | 54 |
| 52 // Returns true if |ancestor| is an ancestor of |layer|. | 55 // Returns true if |ancestor| is an ancestor of |layer|. |
| 53 bool LayerIsAncestor(const ui::Layer* ancestor, const ui::Layer* layer) { | 56 bool LayerIsAncestor(const ui::Layer* ancestor, const ui::Layer* layer) { |
| 54 while (layer && layer != ancestor) | 57 while (layer && layer != ancestor) |
| 55 layer = layer->parent(); | 58 layer = layer->parent(); |
| 56 return layer == ancestor; | 59 return layer == ancestor; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 TestView() : View(), in_touch_sequence_(false) {} | 201 TestView() : View(), in_touch_sequence_(false) {} |
| 199 virtual ~TestView() {} | 202 virtual ~TestView() {} |
| 200 | 203 |
| 201 // Reset all test state | 204 // Reset all test state |
| 202 void Reset() { | 205 void Reset() { |
| 203 did_change_bounds_ = false; | 206 did_change_bounds_ = false; |
| 204 last_mouse_event_type_ = 0; | 207 last_mouse_event_type_ = 0; |
| 205 location_.SetPoint(0, 0); | 208 location_.SetPoint(0, 0); |
| 206 last_touch_event_type_ = 0; | 209 last_touch_event_type_ = 0; |
| 207 last_touch_event_was_handled_ = false; | 210 last_touch_event_was_handled_ = false; |
| 211 last_gesture_event_type_ = 0; | |
| 212 last_gesture_event_was_handled_ = false; | |
| 208 last_clip_.setEmpty(); | 213 last_clip_.setEmpty(); |
| 209 accelerator_count_map_.clear(); | 214 accelerator_count_map_.clear(); |
| 210 } | 215 } |
| 211 | 216 |
| 212 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 217 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
| 213 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; | 218 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; |
| 214 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; | 219 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; |
| 215 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; | 220 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; |
| 216 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | 221 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; |
| 222 | |
| 223 // Ignores GestureEvent by default. | |
| 224 virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; | |
| 217 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; | 225 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; |
| 218 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | 226 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; |
| 219 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 227 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 220 | 228 |
| 221 // OnBoundsChanged. | 229 // OnBoundsChanged. |
| 222 bool did_change_bounds_; | 230 bool did_change_bounds_; |
| 223 gfx::Rect new_bounds_; | 231 gfx::Rect new_bounds_; |
| 224 | 232 |
| 225 // MouseEvent. | 233 // MouseEvent. |
| 226 int last_mouse_event_type_; | 234 int last_mouse_event_type_; |
| 227 gfx::Point location_; | 235 gfx::Point location_; |
| 228 | 236 |
| 229 // Painting. | 237 // Painting. |
| 230 std::vector<gfx::Rect> scheduled_paint_rects_; | 238 std::vector<gfx::Rect> scheduled_paint_rects_; |
| 231 | 239 |
| 232 // TouchEvent. | 240 // TouchEvent. |
| 233 int last_touch_event_type_; | 241 int last_touch_event_type_; |
| 234 bool last_touch_event_was_handled_; | 242 bool last_touch_event_was_handled_; |
| 235 bool in_touch_sequence_; | 243 bool in_touch_sequence_; |
| 236 | 244 |
| 245 // GestureEvent | |
| 246 int last_gesture_event_type_; | |
| 247 bool last_gesture_event_was_handled_; | |
| 248 | |
| 237 // Painting. | 249 // Painting. |
| 238 SkRect last_clip_; | 250 SkRect last_clip_; |
| 239 | 251 |
| 240 // Accelerators. | 252 // Accelerators. |
| 241 std::map<ui::Accelerator, int> accelerator_count_map_; | 253 std::map<ui::Accelerator, int> accelerator_count_map_; |
| 242 }; | 254 }; |
| 243 | 255 |
| 244 // Mock instance of the GestureManager for testing. | 256 // Mock instance of the GestureManager for testing. |
| 245 class MockGestureManager : public GestureManager { | 257 class MockGestureManager : public GestureManager { |
| 246 public: | 258 public: |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 258 MockGestureManager(); | 270 MockGestureManager(); |
| 259 | 271 |
| 260 bool previously_handled_flag_; | 272 bool previously_handled_flag_; |
| 261 int last_touch_event_; | 273 int last_touch_event_; |
| 262 View *last_view_; | 274 View *last_view_; |
| 263 bool dispatched_synthetic_event_; | 275 bool dispatched_synthetic_event_; |
| 264 | 276 |
| 265 DISALLOW_COPY_AND_ASSIGN(MockGestureManager); | 277 DISALLOW_COPY_AND_ASSIGN(MockGestureManager); |
| 266 }; | 278 }; |
| 267 | 279 |
| 280 // GestureRecognizer for testing. | |
| 281 class TestGestureRecognizer: public GestureRecognizer { | |
|
sky
2011/11/15 16:54:44
'r: ' -> 'r : '
Gajen
2011/11/16 15:08:41
Done.
| |
| 282 public: | |
| 283 // Reset all test state. | |
| 284 void reset() { | |
| 285 last_touch_event_ = 0; | |
| 286 previously_handled_flag_ = false; | |
| 287 } | |
| 288 Gestures* ProcessTouchEventForGesture(const TouchEvent& event, | |
|
sky
2011/11/15 16:54:44
virtual
Gajen
2011/11/16 15:08:41
Done.
| |
| 289 ui::TouchStatus status) OVERRIDE; | |
| 290 TestGestureRecognizer(); | |
|
sky
2011/11/15 16:54:44
constructor first
Gajen
2011/11/16 15:08:41
Done.
| |
| 291 | |
| 292 bool previously_handled_flag_; | |
| 293 int last_touch_event_; | |
| 294 | |
| 295 DISALLOW_COPY_AND_ASSIGN(TestGestureRecognizer); | |
| 296 }; | |
| 297 | |
| 268 // A view subclass that ignores all touch events for testing purposes. | 298 // A view subclass that ignores all touch events for testing purposes. |
| 269 class TestViewIgnoreTouch : public TestView { | 299 class TestViewIgnoreTouch : public TestView { |
| 270 public: | 300 public: |
| 271 TestViewIgnoreTouch() : TestView() {} | 301 TestViewIgnoreTouch() : TestView() {} |
| 272 virtual ~TestViewIgnoreTouch() {} | 302 virtual ~TestViewIgnoreTouch() {} |
| 273 | 303 |
| 274 private: | 304 private: |
| 275 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | 305 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; |
| 276 }; | 306 }; |
| 277 | 307 |
| 308 // A view subclass that consumes all Gesture events for testing purposes. | |
| 309 class TestViewConsumeGesture : public TestView { | |
| 310 public: | |
| 311 TestViewConsumeGesture() : TestView() {} | |
| 312 virtual ~TestViewConsumeGesture() {} | |
| 313 | |
| 314 private: | |
| 315 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | |
| 316 virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; | |
| 317 }; | |
|
sky
2011/11/15 16:54:44
DISALLOW_COPY_AND_ASSIGN
Gajen
2011/11/16 15:08:41
Done.
| |
| 318 | |
| 319 // A view subclass that ignores all Gesture and touch events. | |
| 320 class TestViewIgnoreTouchAndGesture: public TestView { | |
| 321 public: | |
| 322 TestViewIgnoreTouchAndGesture() : TestView() {} | |
| 323 virtual ~TestViewIgnoreTouchAndGesture() {} | |
| 324 | |
| 325 private: | |
| 326 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | |
| 327 virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; | |
|
sky
2011/11/15 16:54:44
DISALLOW_COPY_AND_ASSIGN
Gajen
2011/11/16 15:08:41
Done.
| |
| 328 }; | |
| 329 | |
| 278 //////////////////////////////////////////////////////////////////////////////// | 330 //////////////////////////////////////////////////////////////////////////////// |
| 279 // OnBoundsChanged | 331 // OnBoundsChanged |
| 280 //////////////////////////////////////////////////////////////////////////////// | 332 //////////////////////////////////////////////////////////////////////////////// |
| 281 | 333 |
| 282 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 334 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 283 did_change_bounds_ = true; | 335 did_change_bounds_ = true; |
| 284 new_bounds_ = bounds(); | 336 new_bounds_ = bounds(); |
| 285 } | 337 } |
| 286 | 338 |
| 287 TEST_F(ViewTest, OnBoundsChanged) { | 339 TEST_F(ViewTest, OnBoundsChanged) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 EXPECT_EQ(v1->last_touch_event_type_, 0); | 584 EXPECT_EQ(v1->last_touch_event_type_, 0); |
| 533 | 585 |
| 534 EXPECT_EQ(gm.last_touch_event_, 0); | 586 EXPECT_EQ(gm.last_touch_event_, 0); |
| 535 EXPECT_EQ(NULL, gm.last_view_); | 587 EXPECT_EQ(NULL, gm.last_view_); |
| 536 EXPECT_EQ(gm.previously_handled_flag_, false); | 588 EXPECT_EQ(gm.previously_handled_flag_, false); |
| 537 | 589 |
| 538 widget->CloseNow(); | 590 widget->CloseNow(); |
| 539 } | 591 } |
| 540 | 592 |
| 541 //////////////////////////////////////////////////////////////////////////////// | 593 //////////////////////////////////////////////////////////////////////////////// |
| 594 // GestureEvent | |
| 595 //////////////////////////////////////////////////////////////////////////////// | |
| 596 | |
| 597 GestureRecognizer::Gestures* TestGestureRecognizer::ProcessTouchEventForGesture( | |
| 598 const TouchEvent& event, | |
| 599 ui::TouchStatus status) { | |
| 600 if (status != ui::TOUCH_STATUS_UNKNOWN) { | |
| 601 return NULL; | |
| 602 } | |
| 603 last_touch_event_ = event.type(); | |
| 604 previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN; | |
| 605 return GestureRecognizer::ProcessTouchEventForGesture(event, status); | |
| 606 } | |
| 607 | |
| 608 TestGestureRecognizer::TestGestureRecognizer() { | |
| 609 } | |
| 610 | |
| 611 ui::GestureStatus TestView::OnGestureEvent(const GestureEvent& event) { | |
| 612 return ui::GESTURE_STATUS_UNKNOWN; | |
| 613 } | |
| 614 | |
| 615 // GestureConsumer view should ignore TouchEvent for testing purposes. | |
| 616 ui::TouchStatus TestViewConsumeGesture::OnTouchEvent( | |
| 617 const TouchEvent& event) { | |
| 618 return ui::TOUCH_STATUS_UNKNOWN; | |
| 619 } | |
| 620 | |
| 621 ui::GestureStatus TestViewConsumeGesture::OnGestureEvent( | |
| 622 const GestureEvent& event) { | |
| 623 last_gesture_event_type_ = event.type(); | |
| 624 location_.SetPoint(event.x(), event.y()); | |
| 625 return ui::GESTURE_STATUS_CONSUMED; | |
| 626 } | |
| 627 | |
| 628 // IgnoreTouchAndGesture view should ignore touch and Gesture event for | |
| 629 // testing purposes. | |
| 630 ui::TouchStatus TestViewIgnoreTouchAndGesture::OnTouchEvent( | |
| 631 const TouchEvent& event) { | |
| 632 return ui::TOUCH_STATUS_UNKNOWN; | |
| 633 } | |
| 634 | |
| 635 ui::GestureStatus TestViewIgnoreTouchAndGesture::OnGestureEvent( | |
| 636 const GestureEvent& event) { | |
| 637 return ui::GESTURE_STATUS_UNKNOWN; | |
| 638 } | |
| 639 | |
| 640 #if defined(TOUCH_UI) | |
| 641 TEST_F(ViewTest, GestureEvent) { | |
| 642 MockGestureManager gm; | |
| 643 TestGestureRecognizer gr; | |
| 644 | |
| 645 // Views hierarchy for non delivery of GestureEvent. | |
| 646 TestView* v1 = new TestViewConsumeGesture(); | |
| 647 v1->SetBounds(0, 0, 300, 300); | |
| 648 | |
| 649 TestView* v2 = new TestView(); | |
| 650 v2->SetBounds(100, 100, 100, 100); | |
| 651 | |
| 652 TestView* v3 = new TestViewConsumeGesture(); | |
| 653 v3->SetBounds(0, 0, 100, 100); | |
| 654 | |
| 655 // Views hierarchy for delivery of GestureEvent. | |
| 656 TestView* v4 = new TestViewConsumeGesture(); | |
| 657 v4->SetBounds(200, 200, 100, 100); | |
| 658 | |
| 659 scoped_ptr<Widget> widget(new Widget()); | |
| 660 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | |
| 661 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 662 params.bounds = gfx::Rect(50, 50, 650, 650); | |
| 663 widget->Init(params); | |
| 664 View* root = widget->GetRootView(); | |
| 665 | |
| 666 root->AddChildView(v1); | |
| 667 static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm); | |
| 668 static_cast<internal::RootView*>(root)->SetGestureRecognizerForTesting(&gr); | |
| 669 v1->AddChildView(v2); | |
| 670 v2->AddChildView(v3); | |
| 671 v1->AddChildView(v4); | |
| 672 | |
| 673 // |v3| completely obscures |v2|, but all the touch events on |v3| should | |
| 674 // reach |v2| because |v3| doesn't process any touch events, hence no gesture | |
| 675 // conversion take place. | |
| 676 | |
| 677 // Both |v4| and |v1| ignore touch events, hence |v4| should recieve gesture | |
| 678 // events. | |
| 679 | |
| 680 // Make sure if none of the views handle the touch event, the gesture manager | |
| 681 // does. | |
| 682 v1->Reset(); | |
| 683 v2->Reset(); | |
| 684 v3->Reset(); | |
| 685 v4->Reset(); | |
| 686 gr.reset(); | |
| 687 gm.Reset(); | |
| 688 | |
| 689 TouchEvent unhandled(ui::ET_TOUCH_MOVED, | |
| 690 400, | |
| 691 400, | |
| 692 0, /* no flags */ | |
| 693 0, /* first finger touch */ | |
| 694 1.0, 0.0, 1.0, 0.0); | |
| 695 root->OnTouchEvent(unhandled); | |
| 696 | |
| 697 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 698 EXPECT_EQ(v2->last_touch_event_type_, 0); | |
| 699 EXPECT_EQ(v4->last_touch_event_type_, 0); | |
| 700 EXPECT_EQ(v4->last_gesture_event_type_, 0); | |
| 701 | |
| 702 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 703 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_MOVED); | |
| 704 | |
| 705 // Test press, drag, release touch sequence. | |
| 706 v1->Reset(); | |
| 707 v2->Reset(); | |
| 708 v3->Reset(); | |
| 709 v4->Reset(); | |
| 710 gr.reset(); | |
| 711 gm.Reset(); | |
| 712 | |
| 713 TouchEvent pressed(ui::ET_TOUCH_PRESSED, | |
| 714 110, | |
| 715 120, | |
| 716 0, /* no flags */ | |
| 717 0, /* first finger touch */ | |
| 718 1.0, 0.0, 1.0, 0.0); | |
| 719 v2->last_touch_event_was_handled_ = true; | |
| 720 root->OnTouchEvent(pressed); | |
| 721 | |
| 722 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_PRESSED); | |
| 723 EXPECT_EQ(v2->location_.x(), 10); | |
| 724 EXPECT_EQ(v2->location_.y(), 20); | |
| 725 // Make sure v1 did not receive the event | |
| 726 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 727 | |
| 728 // Since v2 handled the touch-event, the gesture recognizer should not | |
| 729 // handle it. | |
| 730 EXPECT_EQ(gr.last_touch_event_, 0); | |
| 731 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 732 | |
| 733 // Drag event out of bounds. Should still go to v2 | |
| 734 v1->Reset(); | |
| 735 v2->Reset(); | |
| 736 TouchEvent dragged(ui::ET_TOUCH_MOVED, | |
| 737 50, | |
| 738 40, | |
| 739 0, /* no flags */ | |
| 740 0, /* first finger touch */ | |
| 741 1.0, 0.0, 1.0, 0.0); | |
| 742 root->OnTouchEvent(dragged); | |
| 743 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_MOVED); | |
| 744 EXPECT_EQ(v2->location_.x(), -50); | |
| 745 EXPECT_EQ(v2->location_.y(), -60); | |
| 746 // Make sure v1 did not receive the event | |
| 747 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 748 | |
| 749 EXPECT_EQ(gr.last_touch_event_, 0); | |
| 750 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 751 | |
| 752 // Released event out of bounds. Should still go to v2 | |
| 753 v1->Reset(); | |
| 754 v2->Reset(); | |
| 755 TouchEvent released(ui::ET_TOUCH_RELEASED, 0, 0, 0, 0 /* first finger */, | |
| 756 1.0, 0.0, 1.0, 0.0); | |
| 757 v2->last_touch_event_was_handled_ = true; | |
| 758 root->OnTouchEvent(released); | |
| 759 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); | |
| 760 EXPECT_EQ(v2->location_.x(), -100); | |
| 761 EXPECT_EQ(v2->location_.y(), -100); | |
| 762 // Make sure v1 did not receive the event | |
| 763 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 764 | |
| 765 EXPECT_EQ(gr.last_touch_event_, 0); | |
| 766 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 767 | |
| 768 // Gesture event handling test. | |
| 769 // 1) Test gesture type ui::ET_GESTURE_TAP_DOWN. | |
| 770 v1->Reset(); | |
| 771 v4->Reset(); | |
| 772 gr.reset(); | |
| 773 gm.Reset(); | |
| 774 | |
| 775 TouchEvent second_pressed(ui::ET_TOUCH_PRESSED, | |
| 776 210, | |
| 777 220, | |
| 778 0, /* no flags */ | |
| 779 0, /* first finger touch */ | |
| 780 1.0, 0.0, 1.0, 0.0); | |
| 781 base::Time pressed_time = second_pressed.time_stamp(); | |
| 782 root->OnTouchEvent(second_pressed); | |
| 783 | |
| 784 // Since v1 and V4 didn't handled touch event, the gesture manager should | |
| 785 // handle it. | |
| 786 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 787 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 788 | |
| 789 // Check v4 should receive gesture event but not v1. | |
| 790 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 791 EXPECT_EQ(v4->last_touch_event_type_, 0); | |
| 792 EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP_DOWN); | |
| 793 EXPECT_EQ(v4->location_.x(), 10); | |
| 794 EXPECT_EQ(v4->location_.y(), 20); | |
| 795 | |
| 796 // 2) Test gesture type ui::ET_GESTURE_TAP. | |
| 797 v1->Reset(); | |
| 798 v4->Reset(); | |
| 799 gr.reset(); | |
| 800 gm.Reset(); | |
| 801 | |
| 802 TouchEvent second_released(ui::ET_TOUCH_RELEASED, | |
| 803 210, | |
| 804 220, | |
| 805 0, /* no flags */ | |
| 806 0, /* first finger touch */ | |
| 807 1.0, 0.0, 1.0, 0.0); | |
| 808 | |
| 809 // Set touch time with-in click window. | |
| 810 second_released.set_time_stamp(base::Time::FromDoubleT( | |
| 811 pressed_time.ToDoubleT() + 0.7)); | |
| 812 root->OnTouchEvent(second_released); | |
| 813 | |
| 814 // Since v1 and V4 didn't handled touch event, the gesture manager should | |
| 815 // handle it. | |
| 816 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_RELEASED); | |
| 817 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 818 | |
| 819 // Check v4 should receive gesture event but not v1. | |
| 820 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 821 EXPECT_EQ(v4->last_touch_event_type_, 0); | |
| 822 EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP); | |
| 823 EXPECT_EQ(v4->location_.x(), 10); | |
| 824 EXPECT_EQ(v4->location_.y(), 20); | |
| 825 | |
| 826 // 3) Test Gesture to mouse conversion. | |
| 827 // Views hierarchy for delivery of mouse event in absence of Touch and | |
| 828 // Gesture handlers. | |
| 829 TestView* v5 = new TestViewIgnoreTouchAndGesture(); | |
| 830 v5->SetBounds(0, 0, 300, 300); | |
| 831 | |
| 832 TestView* v6 = new TestViewIgnoreTouchAndGesture(); | |
| 833 v6->SetBounds(100, 100, 100, 100); | |
| 834 | |
| 835 root->AddChildView(v5); | |
| 836 v5->AddChildView(v6); | |
| 837 | |
| 838 v5->Reset(); | |
| 839 v6->Reset(); | |
| 840 gr.reset(); | |
| 841 gm.Reset(); | |
| 842 | |
| 843 TouchEvent third_pressed(ui::ET_TOUCH_PRESSED, | |
| 844 110, | |
| 845 120, | |
| 846 0, /* no flags */ | |
| 847 0, /* first finger touch */ | |
| 848 1.0, 0.0, 1.0, 0.0); | |
| 849 root->OnTouchEvent(third_pressed); | |
| 850 | |
| 851 // Since v5 and V6 didn't handled touch and gesture event, gesture recognizer | |
| 852 // and manager should recieve touch event. | |
| 853 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 854 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 855 EXPECT_EQ(gm.previously_handled_flag_, false); | |
| 856 EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 857 EXPECT_EQ(gm.last_view_, root); | |
| 858 EXPECT_EQ(gm.dispatched_synthetic_event_, true); | |
| 859 | |
| 860 // Check v6 shouldn't recieve touch and gesture event but mouse event. | |
| 861 EXPECT_EQ(v6->last_touch_event_type_, 0); | |
| 862 EXPECT_EQ(v6->last_gesture_event_type_, 0); | |
| 863 | |
| 864 // Check v5 shouldn't recieve touch, gesture and mouse event. | |
| 865 EXPECT_EQ(v5->last_touch_event_type_, 0); | |
| 866 EXPECT_EQ(v5->last_gesture_event_type_, 0); | |
| 867 widget->CloseNow(); | |
| 868 } | |
| 869 #endif | |
| 870 | |
| 871 //////////////////////////////////////////////////////////////////////////////// | |
| 542 // Painting | 872 // Painting |
| 543 //////////////////////////////////////////////////////////////////////////////// | 873 //////////////////////////////////////////////////////////////////////////////// |
| 544 | 874 |
| 545 void TestView::Paint(gfx::Canvas* canvas) { | 875 void TestView::Paint(gfx::Canvas* canvas) { |
| 546 canvas->GetSkCanvas()->getClipBounds(&last_clip_); | 876 canvas->GetSkCanvas()->getClipBounds(&last_clip_); |
| 547 } | 877 } |
| 548 | 878 |
| 549 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { | 879 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { |
| 550 scheduled_paint_rects_.push_back(rect); | 880 scheduled_paint_rects_.push_back(rect); |
| 551 View::SchedulePaintInRect(rect); | 881 View::SchedulePaintInRect(rect); |
| (...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3097 ScrambleTree(content); | 3427 ScrambleTree(content); |
| 3098 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3428 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3099 | 3429 |
| 3100 ScrambleTree(content); | 3430 ScrambleTree(content); |
| 3101 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3431 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3102 } | 3432 } |
| 3103 | 3433 |
| 3104 #endif // VIEWS_COMPOSITOR | 3434 #endif // VIEWS_COMPOSITOR |
| 3105 | 3435 |
| 3106 } // namespace views | 3436 } // namespace views |
| OLD | NEW |