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" | |
|
sadrul
2011/11/18 19:01:50
You will have to merge with trunk. I think this is
Gajen
2011/11/21 15:56:50
Build issue in my machine,Will do in next patch.
| |
| 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 { | |
| 282 public: | |
| 283 TestGestureRecognizer(); | |
| 284 | |
| 285 // Reset all test state. | |
| 286 void reset() { | |
| 287 last_touch_event_ = 0; | |
| 288 previously_handled_flag_ = false; | |
| 289 } | |
| 290 | |
| 291 virtual Gestures* ProcessTouchEventForGesture( | |
| 292 const TouchEvent& event, | |
| 293 ui::TouchStatus status) OVERRIDE; | |
| 294 | |
| 295 bool previously_handled_flag_; | |
| 296 int last_touch_event_; | |
| 297 | |
| 298 DISALLOW_COPY_AND_ASSIGN(TestGestureRecognizer); | |
| 299 }; | |
| 300 | |
| 268 // A view subclass that ignores all touch events for testing purposes. | 301 // A view subclass that ignores all touch events for testing purposes. |
| 269 class TestViewIgnoreTouch : public TestView { | 302 class TestViewIgnoreTouch : public TestView { |
| 270 public: | 303 public: |
| 271 TestViewIgnoreTouch() : TestView() {} | 304 TestViewIgnoreTouch() : TestView() {} |
| 272 virtual ~TestViewIgnoreTouch() {} | 305 virtual ~TestViewIgnoreTouch() {} |
| 273 | 306 |
| 274 private: | 307 private: |
| 275 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | 308 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; |
| 276 }; | 309 }; |
| 277 | 310 |
| 311 // A view subclass that consumes all Gesture events for testing purposes. | |
| 312 class TestViewConsumeGesture : public TestView { | |
| 313 public: | |
| 314 TestViewConsumeGesture() : TestView() {} | |
| 315 virtual ~TestViewConsumeGesture() {} | |
| 316 | |
| 317 private: | |
| 318 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | |
| 319 virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; | |
| 320 | |
| 321 DISALLOW_COPY_AND_ASSIGN(TestViewConsumeGesture); | |
| 322 }; | |
| 323 | |
| 324 // A view subclass that ignores all Gesture and touch events. | |
| 325 class TestViewIgnoreTouchAndGesture: public TestView { | |
| 326 public: | |
| 327 TestViewIgnoreTouchAndGesture() : TestView() {} | |
| 328 virtual ~TestViewIgnoreTouchAndGesture() {} | |
| 329 | |
| 330 private: | |
| 331 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | |
| 332 virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; | |
| 333 | |
| 334 DISALLOW_COPY_AND_ASSIGN(TestViewIgnoreTouchAndGesture); | |
| 335 }; | |
| 336 | |
| 278 //////////////////////////////////////////////////////////////////////////////// | 337 //////////////////////////////////////////////////////////////////////////////// |
| 279 // OnBoundsChanged | 338 // OnBoundsChanged |
| 280 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
| 281 | 340 |
| 282 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 341 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 283 did_change_bounds_ = true; | 342 did_change_bounds_ = true; |
| 284 new_bounds_ = bounds(); | 343 new_bounds_ = bounds(); |
| 285 } | 344 } |
| 286 | 345 |
| 287 TEST_F(ViewTest, OnBoundsChanged) { | 346 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); | 591 EXPECT_EQ(v1->last_touch_event_type_, 0); |
| 533 | 592 |
| 534 EXPECT_EQ(gm.last_touch_event_, 0); | 593 EXPECT_EQ(gm.last_touch_event_, 0); |
| 535 EXPECT_EQ(NULL, gm.last_view_); | 594 EXPECT_EQ(NULL, gm.last_view_); |
| 536 EXPECT_EQ(gm.previously_handled_flag_, false); | 595 EXPECT_EQ(gm.previously_handled_flag_, false); |
| 537 | 596 |
| 538 widget->CloseNow(); | 597 widget->CloseNow(); |
| 539 } | 598 } |
| 540 | 599 |
| 541 //////////////////////////////////////////////////////////////////////////////// | 600 //////////////////////////////////////////////////////////////////////////////// |
| 601 // GestureEvent | |
| 602 //////////////////////////////////////////////////////////////////////////////// | |
| 603 | |
| 604 GestureRecognizer::Gestures* TestGestureRecognizer::ProcessTouchEventForGesture( | |
| 605 const TouchEvent& event, | |
| 606 ui::TouchStatus status) { | |
| 607 if (status != ui::TOUCH_STATUS_UNKNOWN) { | |
| 608 return NULL; | |
| 609 } | |
| 610 last_touch_event_ = event.type(); | |
| 611 previously_handled_flag_ = status != ui::TOUCH_STATUS_UNKNOWN; | |
| 612 return GestureRecognizer::ProcessTouchEventForGesture(event, status); | |
| 613 } | |
| 614 | |
| 615 TestGestureRecognizer::TestGestureRecognizer() { | |
| 616 } | |
| 617 | |
| 618 ui::GestureStatus TestView::OnGestureEvent(const GestureEvent& event) { | |
| 619 return ui::GESTURE_STATUS_UNKNOWN; | |
| 620 } | |
| 621 | |
| 622 // GestureConsumer view should ignore TouchEvent for testing purposes. | |
| 623 ui::TouchStatus TestViewConsumeGesture::OnTouchEvent( | |
| 624 const TouchEvent& event) { | |
| 625 return ui::TOUCH_STATUS_UNKNOWN; | |
| 626 } | |
| 627 | |
| 628 ui::GestureStatus TestViewConsumeGesture::OnGestureEvent( | |
| 629 const GestureEvent& event) { | |
| 630 last_gesture_event_type_ = event.type(); | |
| 631 location_.SetPoint(event.x(), event.y()); | |
| 632 return ui::GESTURE_STATUS_CONSUMED; | |
| 633 } | |
| 634 | |
| 635 // IgnoreTouchAndGesture view should ignore touch and Gesture event for | |
| 636 // testing purposes. | |
| 637 ui::TouchStatus TestViewIgnoreTouchAndGesture::OnTouchEvent( | |
| 638 const TouchEvent& event) { | |
| 639 return ui::TOUCH_STATUS_UNKNOWN; | |
| 640 } | |
| 641 | |
| 642 ui::GestureStatus TestViewIgnoreTouchAndGesture::OnGestureEvent( | |
| 643 const GestureEvent& event) { | |
| 644 return ui::GESTURE_STATUS_UNKNOWN; | |
| 645 } | |
| 646 | |
| 647 #if defined(TOUCH_UI) | |
| 648 TEST_F(ViewTest, GestureEvent) { | |
| 649 MockGestureManager gm; | |
| 650 TestGestureRecognizer gr; | |
| 651 | |
| 652 // Views hierarchy for non delivery of GestureEvent. | |
| 653 TestView* v1 = new TestViewConsumeGesture(); | |
| 654 v1->SetBounds(0, 0, 300, 300); | |
| 655 | |
| 656 TestView* v2 = new TestView(); | |
| 657 v2->SetBounds(100, 100, 100, 100); | |
| 658 | |
| 659 TestView* v3 = new TestViewConsumeGesture(); | |
| 660 v3->SetBounds(0, 0, 100, 100); | |
| 661 | |
| 662 // Views hierarchy for delivery of GestureEvent. | |
| 663 TestView* v4 = new TestViewConsumeGesture(); | |
| 664 v4->SetBounds(200, 200, 100, 100); | |
| 665 | |
| 666 scoped_ptr<Widget> widget(new Widget()); | |
| 667 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | |
| 668 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 669 params.bounds = gfx::Rect(50, 50, 650, 650); | |
| 670 widget->Init(params); | |
| 671 View* root = widget->GetRootView(); | |
| 672 | |
| 673 root->AddChildView(v1); | |
| 674 static_cast<internal::RootView*>(root)->SetGestureManagerForTesting(&gm); | |
| 675 static_cast<internal::RootView*>(root)->SetGestureRecognizerForTesting(&gr); | |
| 676 v1->AddChildView(v2); | |
| 677 v2->AddChildView(v3); | |
| 678 v1->AddChildView(v4); | |
| 679 | |
| 680 // |v3| completely obscures |v2|, but all the touch events on |v3| should | |
| 681 // reach |v2| because |v3| doesn't process any touch events, hence no gesture | |
| 682 // conversion take place. | |
| 683 | |
| 684 // Both |v4| and |v1| ignore touch events, hence |v4| should recieve gesture | |
| 685 // events. | |
| 686 | |
| 687 // Make sure if none of the views handle the touch event, the gesture manager | |
| 688 // does. | |
| 689 v1->Reset(); | |
| 690 v2->Reset(); | |
| 691 v3->Reset(); | |
| 692 v4->Reset(); | |
| 693 gr.reset(); | |
| 694 gm.Reset(); | |
| 695 | |
| 696 TouchEvent unhandled(ui::ET_TOUCH_MOVED, | |
| 697 400, | |
| 698 400, | |
| 699 0, /* no flags */ | |
| 700 0, /* first finger touch */ | |
| 701 1.0, 0.0, 1.0, 0.0); | |
| 702 root->OnTouchEvent(unhandled); | |
| 703 | |
| 704 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 705 EXPECT_EQ(v2->last_touch_event_type_, 0); | |
| 706 EXPECT_EQ(v4->last_touch_event_type_, 0); | |
| 707 EXPECT_EQ(v4->last_gesture_event_type_, 0); | |
| 708 | |
| 709 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 710 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_MOVED); | |
| 711 | |
| 712 // Test press, drag, release touch sequence. | |
| 713 v1->Reset(); | |
| 714 v2->Reset(); | |
| 715 v3->Reset(); | |
| 716 v4->Reset(); | |
| 717 gr.reset(); | |
| 718 gm.Reset(); | |
| 719 | |
| 720 TouchEvent pressed(ui::ET_TOUCH_PRESSED, | |
| 721 110, | |
| 722 120, | |
| 723 0, /* no flags */ | |
| 724 0, /* first finger touch */ | |
| 725 1.0, 0.0, 1.0, 0.0); | |
| 726 v2->last_touch_event_was_handled_ = true; | |
| 727 root->OnTouchEvent(pressed); | |
| 728 | |
| 729 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_PRESSED); | |
| 730 EXPECT_EQ(v2->location_.x(), 10); | |
| 731 EXPECT_EQ(v2->location_.y(), 20); | |
| 732 // Make sure v1 did not receive the event | |
| 733 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 734 | |
| 735 // Since v2 handled the touch-event, the gesture recognizer should not | |
| 736 // handle it. | |
| 737 EXPECT_EQ(gr.last_touch_event_, 0); | |
| 738 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 739 | |
| 740 // Drag event out of bounds. Should still go to v2 | |
| 741 v1->Reset(); | |
| 742 v2->Reset(); | |
| 743 TouchEvent dragged(ui::ET_TOUCH_MOVED, | |
| 744 50, | |
| 745 40, | |
| 746 0, /* no flags */ | |
| 747 0, /* first finger touch */ | |
| 748 1.0, 0.0, 1.0, 0.0); | |
| 749 root->OnTouchEvent(dragged); | |
| 750 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_MOVED); | |
| 751 EXPECT_EQ(v2->location_.x(), -50); | |
| 752 EXPECT_EQ(v2->location_.y(), -60); | |
| 753 // Make sure v1 did not receive the event | |
| 754 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 755 | |
| 756 EXPECT_EQ(gr.last_touch_event_, 0); | |
| 757 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 758 | |
| 759 // Released event out of bounds. Should still go to v2 | |
| 760 v1->Reset(); | |
| 761 v2->Reset(); | |
| 762 TouchEvent released(ui::ET_TOUCH_RELEASED, 0, 0, 0, 0 /* first finger */, | |
| 763 1.0, 0.0, 1.0, 0.0); | |
| 764 v2->last_touch_event_was_handled_ = true; | |
| 765 root->OnTouchEvent(released); | |
| 766 EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); | |
| 767 EXPECT_EQ(v2->location_.x(), -100); | |
| 768 EXPECT_EQ(v2->location_.y(), -100); | |
| 769 // Make sure v1 did not receive the event | |
| 770 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 771 | |
| 772 EXPECT_EQ(gr.last_touch_event_, 0); | |
| 773 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 774 | |
| 775 // Gesture event handling test. | |
| 776 // 1) Test gesture type ui::ET_GESTURE_TAP_DOWN. | |
| 777 v1->Reset(); | |
| 778 v4->Reset(); | |
| 779 gr.reset(); | |
| 780 gm.Reset(); | |
| 781 | |
| 782 TouchEvent second_pressed(ui::ET_TOUCH_PRESSED, | |
| 783 210, | |
| 784 220, | |
| 785 0, /* no flags */ | |
| 786 0, /* first finger touch */ | |
| 787 1.0, 0.0, 1.0, 0.0); | |
| 788 base::Time pressed_time = second_pressed.time_stamp(); | |
| 789 root->OnTouchEvent(second_pressed); | |
| 790 | |
| 791 // Since v1 and V4 didn't handled touch event, the gesture manager should | |
| 792 // handle it. | |
| 793 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 794 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 795 | |
| 796 // Check v4 should receive gesture event but not v1. | |
| 797 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 798 EXPECT_EQ(v4->last_touch_event_type_, 0); | |
| 799 EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP_DOWN); | |
| 800 EXPECT_EQ(v4->location_.x(), 10); | |
| 801 EXPECT_EQ(v4->location_.y(), 20); | |
| 802 | |
| 803 // 2) Test gesture type ui::ET_GESTURE_TAP. | |
| 804 v1->Reset(); | |
| 805 v4->Reset(); | |
| 806 gr.reset(); | |
| 807 gm.Reset(); | |
| 808 | |
| 809 TouchEvent second_released(ui::ET_TOUCH_RELEASED, | |
| 810 210, | |
| 811 220, | |
| 812 0, /* no flags */ | |
| 813 0, /* first finger touch */ | |
| 814 1.0, 0.0, 1.0, 0.0); | |
| 815 | |
| 816 // Set touch time with-in click window. | |
| 817 second_released.set_time_stamp(base::Time::FromDoubleT( | |
| 818 pressed_time.ToDoubleT() + 0.7)); | |
| 819 root->OnTouchEvent(second_released); | |
| 820 | |
| 821 // Since v1 and V4 didn't handled touch event, the gesture manager should | |
| 822 // handle it. | |
| 823 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_RELEASED); | |
| 824 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 825 | |
| 826 // Check v4 should receive gesture event but not v1. | |
| 827 EXPECT_EQ(v1->last_touch_event_type_, 0); | |
| 828 EXPECT_EQ(v4->last_touch_event_type_, 0); | |
| 829 EXPECT_EQ(v4->last_gesture_event_type_, ui::ET_GESTURE_TAP); | |
| 830 EXPECT_EQ(v4->location_.x(), 10); | |
| 831 EXPECT_EQ(v4->location_.y(), 20); | |
| 832 | |
| 833 // 3) Test Gesture to mouse conversion. | |
| 834 // Views hierarchy for delivery of mouse event in absence of Touch and | |
| 835 // Gesture handlers. | |
| 836 TestView* v5 = new TestViewIgnoreTouchAndGesture(); | |
| 837 v5->SetBounds(0, 0, 300, 300); | |
| 838 | |
| 839 TestView* v6 = new TestViewIgnoreTouchAndGesture(); | |
| 840 v6->SetBounds(100, 100, 100, 100); | |
| 841 | |
| 842 root->AddChildView(v5); | |
| 843 v5->AddChildView(v6); | |
| 844 | |
| 845 v5->Reset(); | |
| 846 v6->Reset(); | |
| 847 gr.reset(); | |
| 848 gm.Reset(); | |
| 849 | |
| 850 TouchEvent third_pressed(ui::ET_TOUCH_PRESSED, | |
| 851 110, | |
| 852 120, | |
| 853 0, /* no flags */ | |
| 854 0, /* first finger touch */ | |
| 855 1.0, 0.0, 1.0, 0.0); | |
| 856 root->OnTouchEvent(third_pressed); | |
| 857 | |
| 858 // Since v5 and V6 didn't handled touch and gesture event, gesture recognizer | |
| 859 // and manager should recieve touch event. | |
| 860 EXPECT_EQ(gr.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 861 EXPECT_EQ(gr.previously_handled_flag_, false); | |
| 862 EXPECT_EQ(gm.previously_handled_flag_, false); | |
| 863 EXPECT_EQ(gm.last_touch_event_, ui::ET_TOUCH_PRESSED); | |
| 864 EXPECT_EQ(gm.last_view_, root); | |
| 865 EXPECT_EQ(gm.dispatched_synthetic_event_, true); | |
| 866 | |
| 867 // Check v6 shouldn't recieve touch and gesture event but mouse event. | |
| 868 EXPECT_EQ(v6->last_touch_event_type_, 0); | |
| 869 EXPECT_EQ(v6->last_gesture_event_type_, 0); | |
| 870 | |
| 871 // Check v5 shouldn't recieve touch, gesture and mouse event. | |
| 872 EXPECT_EQ(v5->last_touch_event_type_, 0); | |
| 873 EXPECT_EQ(v5->last_gesture_event_type_, 0); | |
| 874 widget->CloseNow(); | |
| 875 } | |
| 876 #endif | |
| 877 | |
| 878 //////////////////////////////////////////////////////////////////////////////// | |
| 542 // Painting | 879 // Painting |
| 543 //////////////////////////////////////////////////////////////////////////////// | 880 //////////////////////////////////////////////////////////////////////////////// |
| 544 | 881 |
| 545 void TestView::Paint(gfx::Canvas* canvas) { | 882 void TestView::Paint(gfx::Canvas* canvas) { |
| 546 canvas->GetSkCanvas()->getClipBounds(&last_clip_); | 883 canvas->GetSkCanvas()->getClipBounds(&last_clip_); |
| 547 } | 884 } |
| 548 | 885 |
| 549 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { | 886 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { |
| 550 scheduled_paint_rects_.push_back(rect); | 887 scheduled_paint_rects_.push_back(rect); |
| 551 View::SchedulePaintInRect(rect); | 888 View::SchedulePaintInRect(rect); |
| (...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3097 ScrambleTree(content); | 3434 ScrambleTree(content); |
| 3098 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3435 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3099 | 3436 |
| 3100 ScrambleTree(content); | 3437 ScrambleTree(content); |
| 3101 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3438 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
| 3102 } | 3439 } |
| 3103 | 3440 |
| 3104 #endif // VIEWS_COMPOSITOR | 3441 #endif // VIEWS_COMPOSITOR |
| 3105 | 3442 |
| 3106 } // namespace views | 3443 } // namespace views |
| OLD | NEW |