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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 Widget* widget = CreateTopLevelNativeWidget(); | 1985 Widget* widget = CreateTopLevelNativeWidget(); |
1986 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); | 1986 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); |
1987 EventCountView* view = new EventCountView(); | 1987 EventCountView* view = new EventCountView(); |
1988 view->SetBounds(0, 0, 300, 300); | 1988 view->SetBounds(0, 0, 300, 300); |
1989 internal::RootView* root_view = | 1989 internal::RootView* root_view = |
1990 static_cast<internal::RootView*>(widget->GetRootView()); | 1990 static_cast<internal::RootView*>(widget->GetRootView()); |
1991 root_view->AddChildView(view); | 1991 root_view->AddChildView(view); |
1992 widget->Show(); | 1992 widget->Show(); |
1993 | 1993 |
1994 // If no gesture handler is set, a ui::ET_GESTURE_END event should not set | 1994 // If no gesture handler is set, a ui::ET_GESTURE_END event should not set |
1995 // the gesture handler and the event should remain unhandled because the | 1995 // the gesture handler. |
1996 // handle mode of |view| indicates that events should not be consumed. | |
1997 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 1996 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
1998 GestureEventForTest end(ui::ET_GESTURE_END, 15, 15); | 1997 GestureEventForTest end(ui::ET_GESTURE_END, 15, 15); |
1999 widget->OnGestureEvent(&end); | 1998 widget->OnGestureEvent(&end); |
2000 EXPECT_FALSE(end.handled()); | |
2001 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 1999 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
2002 | 2000 |
2003 // Change the handle mode of |view| to indicate that it would like | 2001 // Change the handle mode of |view| to indicate that it would like |
2004 // to handle all events, then send a GESTURE_TAP to set the gesture handler. | 2002 // to handle all events, then send a GESTURE_TAP to set the gesture handler. |
2005 view->set_handle_mode(EventCountView::CONSUME_EVENTS); | 2003 view->set_handle_mode(EventCountView::CONSUME_EVENTS); |
2006 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15); | 2004 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15); |
2007 widget->OnGestureEvent(&tap); | 2005 widget->OnGestureEvent(&tap); |
2008 EXPECT_TRUE(tap.handled()); | 2006 EXPECT_TRUE(tap.handled()); |
2009 EXPECT_EQ(view, GetGestureHandler(root_view)); | 2007 EXPECT_EQ(view, GetGestureHandler(root_view)); |
2010 | 2008 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_BEGIN)); | 2082 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_BEGIN)); |
2085 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_BEGIN)); | 2083 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_BEGIN)); |
2086 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_BEGIN)); | 2084 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_BEGIN)); |
2087 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2085 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
2088 EXPECT_TRUE(begin.handled()); | 2086 EXPECT_TRUE(begin.handled()); |
2089 v1->ResetCounts(); | 2087 v1->ResetCounts(); |
2090 v2->ResetCounts(); | 2088 v2->ResetCounts(); |
2091 v3->ResetCounts(); | 2089 v3->ResetCounts(); |
2092 v4->ResetCounts(); | 2090 v4->ResetCounts(); |
2093 | 2091 |
| 2092 // ui::ET_GESTURE_END events should not be seen by any view when there is |
| 2093 // no default gesture handler set, but they should be marked as handled by |
| 2094 // OnEventProcessingStarted(). |
| 2095 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5); |
| 2096 widget->OnGestureEvent(&end); |
| 2097 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); |
| 2098 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); |
| 2099 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); |
| 2100 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END)); |
| 2101 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 2102 EXPECT_TRUE(end.handled()); |
| 2103 v1->ResetCounts(); |
| 2104 v2->ResetCounts(); |
| 2105 v3->ResetCounts(); |
| 2106 v4->ResetCounts(); |
| 2107 |
2094 // ui::ET_GESTURE_END events not corresponding to the release of the | 2108 // ui::ET_GESTURE_END events not corresponding to the release of the |
2095 // final touch point should never be seen by any view, but they should | 2109 // final touch point should never be seen by any view, but they should |
2096 // be marked as handled by OnEventProcessingStarted(). | 2110 // be marked as handled by OnEventProcessingStarted(). |
2097 ui::GestureEventDetails details(ui::ET_GESTURE_END); | 2111 ui::GestureEventDetails details(ui::ET_GESTURE_END); |
2098 details.set_touch_points(2); | 2112 details.set_touch_points(2); |
2099 GestureEventForTest end_second_touch_point(details, 5, 5); | 2113 GestureEventForTest end_second_touch_point(details, 5, 5); |
2100 widget->OnGestureEvent(&end_second_touch_point); | 2114 widget->OnGestureEvent(&end_second_touch_point); |
2101 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); | 2115 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); |
2102 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); | 2116 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); |
2103 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); | 2117 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2541 | 2555 |
2542 widget->Show(); | 2556 widget->Show(); |
2543 | 2557 |
2544 // |v1|, |v2|, and |v3| all handle gesture events but |v3| is marked as | 2558 // |v1|, |v2|, and |v3| all handle gesture events but |v3| is marked as |
2545 // disabled. | 2559 // disabled. |
2546 v1->set_handle_mode(EventCountView::CONSUME_EVENTS); | 2560 v1->set_handle_mode(EventCountView::CONSUME_EVENTS); |
2547 v2->set_handle_mode(EventCountView::CONSUME_EVENTS); | 2561 v2->set_handle_mode(EventCountView::CONSUME_EVENTS); |
2548 v3->set_handle_mode(EventCountView::CONSUME_EVENTS); | 2562 v3->set_handle_mode(EventCountView::CONSUME_EVENTS); |
2549 v3->SetEnabled(false); | 2563 v3->SetEnabled(false); |
2550 | 2564 |
2551 // No gesture handler is set in the root view, so it should remain unset | |
2552 // after a GESTURE_END. GESTURE_END events are not dispatched unless | |
2553 // a gesture handler is already set in the root view, so none of the | |
2554 // views should see this event and it should not be marked as handled. | |
2555 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5); | |
2556 widget->OnGestureEvent(&end); | |
2557 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); | |
2558 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); | |
2559 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); | |
2560 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END)); | |
2561 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | |
2562 EXPECT_FALSE(end.handled()); | |
2563 v1->ResetCounts(); | |
2564 v2->ResetCounts(); | |
2565 v3->ResetCounts(); | |
2566 v4->ResetCounts(); | |
2567 | |
2568 // No gesture handler is set in the root view. In this case the tap event | 2565 // No gesture handler is set in the root view. In this case the tap event |
2569 // should be dispatched only to |v4|, the gesture handler should be set to | 2566 // should be dispatched only to |v4|, the gesture handler should be set to |
2570 // |v3|, and the event should be marked as handled. | 2567 // |v3|, and the event should be marked as handled. |
2571 GestureEventForTest tap(ui::ET_GESTURE_TAP, 5, 5); | 2568 GestureEventForTest tap(ui::ET_GESTURE_TAP, 5, 5); |
2572 widget->OnGestureEvent(&tap); | 2569 widget->OnGestureEvent(&tap); |
2573 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP)); | 2570 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP)); |
2574 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP)); | 2571 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP)); |
2575 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_TAP)); | 2572 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_TAP)); |
2576 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP)); | 2573 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP)); |
2577 EXPECT_EQ(v3, GetGestureHandler(root_view)); | 2574 EXPECT_EQ(v3, GetGestureHandler(root_view)); |
(...skipping 12 matching lines...) Expand all Loading... |
2590 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP)); | 2587 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP)); |
2591 EXPECT_EQ(v3, GetGestureHandler(root_view)); | 2588 EXPECT_EQ(v3, GetGestureHandler(root_view)); |
2592 EXPECT_TRUE(tap.handled()); | 2589 EXPECT_TRUE(tap.handled()); |
2593 v1->ResetCounts(); | 2590 v1->ResetCounts(); |
2594 v2->ResetCounts(); | 2591 v2->ResetCounts(); |
2595 v3->ResetCounts(); | 2592 v3->ResetCounts(); |
2596 v4->ResetCounts(); | 2593 v4->ResetCounts(); |
2597 | 2594 |
2598 // A GESTURE_END should reset the default gesture handler to NULL. It should | 2595 // A GESTURE_END should reset the default gesture handler to NULL. It should |
2599 // also not be dispatched to |v3| but still marked as handled. | 2596 // also not be dispatched to |v3| but still marked as handled. |
2600 end = GestureEventForTest(ui::ET_GESTURE_END, 5, 5); | 2597 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5); |
2601 widget->OnGestureEvent(&end); | 2598 widget->OnGestureEvent(&end); |
2602 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); | 2599 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); |
2603 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); | 2600 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); |
2604 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); | 2601 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); |
2605 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END)); | 2602 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END)); |
2606 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2603 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
2607 EXPECT_TRUE(end.handled()); | 2604 EXPECT_TRUE(end.handled()); |
2608 v1->ResetCounts(); | 2605 v1->ResetCounts(); |
2609 v2->ResetCounts(); | 2606 v2->ResetCounts(); |
2610 v3->ResetCounts(); | 2607 v3->ResetCounts(); |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3350 | 3347 |
3351 EXPECT_EQ(test_rect, root_view->bounds()); | 3348 EXPECT_EQ(test_rect, root_view->bounds()); |
3352 widget->ReorderNativeViews(); | 3349 widget->ReorderNativeViews(); |
3353 EXPECT_EQ(test_rect, root_view->bounds()); | 3350 EXPECT_EQ(test_rect, root_view->bounds()); |
3354 | 3351 |
3355 widget->CloseNow(); | 3352 widget->CloseNow(); |
3356 } | 3353 } |
3357 | 3354 |
3358 } // namespace test | 3355 } // namespace test |
3359 } // namespace views | 3356 } // namespace views |
OLD | NEW |