Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1015)

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 404213003: [WIP] Allow scroll events to permanently change the default gesture handler in RootView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: friend test Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 1392
1393 EventCountHandler h1; 1393 EventCountHandler h1;
1394 root_view->AddPreTargetHandler(&h1); 1394 root_view->AddPreTargetHandler(&h1);
1395 1395
1396 EventCountHandler h2; 1396 EventCountHandler h2;
1397 root_view->AddPostTargetHandler(&h2); 1397 root_view->AddPostTargetHandler(&h2);
1398 1398
1399 widget->SetBounds(gfx::Rect(0, 0, 100, 100)); 1399 widget->SetBounds(gfx::Rect(0, 0, 100, 100));
1400 widget->Show(); 1400 widget->Show();
1401 1401
1402 ui::GestureEvent begin(5, 1402 // Dispatch a ui::ET_SCROLL event. The event remains unhandled and should
1403 5, 1403 // bubble up the views hierarchy to be re-dispatched on the root view.
1404 0,
1405 ui::EventTimeForNow(),
1406 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0));
1407 ui::GestureEvent end(5,
1408 5,
1409 0,
1410 ui::EventTimeForNow(),
1411 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0));
1412 widget->OnGestureEvent(&begin);
1413 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_BEGIN));
1414 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_BEGIN));
1415 EXPECT_EQ(1, h2.GetEventCount(ui::ET_GESTURE_BEGIN));
1416
1417 widget->OnGestureEvent(&end);
1418 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_END));
1419 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_END));
1420 EXPECT_EQ(1, h2.GetEventCount(ui::ET_GESTURE_END));
1421
1422 ui::ScrollEvent scroll(ui::ET_SCROLL, 1404 ui::ScrollEvent scroll(ui::ET_SCROLL,
1423 gfx::Point(5, 5), 1405 gfx::Point(5, 5),
1424 ui::EventTimeForNow(), 1406 ui::EventTimeForNow(),
1425 0, 1407 0,
1426 0, 20, 1408 0, 20,
1427 0, 20, 1409 0, 20,
1428 2); 1410 2);
1429 widget->OnScrollEvent(&scroll); 1411 widget->OnScrollEvent(&scroll);
1430 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL)); 1412 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL));
1431 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL)); 1413 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL));
1432 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL)); 1414 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL));
1433 1415
1434 // Unhandled scroll events are turned into wheel events and re-dispatched. 1416 // Unhandled scroll events are turned into wheel events and re-dispatched.
1435 EXPECT_EQ(1, h1.GetEventCount(ui::ET_MOUSEWHEEL)); 1417 EXPECT_EQ(1, h1.GetEventCount(ui::ET_MOUSEWHEEL));
1436 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSEWHEEL)); 1418 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSEWHEEL));
1437 EXPECT_EQ(1, h2.GetEventCount(ui::ET_MOUSEWHEEL)); 1419 EXPECT_EQ(1, h2.GetEventCount(ui::ET_MOUSEWHEEL));
1438 1420
1439 h1.ResetCounts(); 1421 h1.ResetCounts();
1440 view->ResetCounts(); 1422 view->ResetCounts();
1441 h2.ResetCounts(); 1423 h2.ResetCounts();
1442 1424
1425 // Dispatch a ui::ET_SCROLL_FLING_START event. The event remains unhandled and
1426 // should bubble up the views hierarchy to be re-dispatched on the root view.
1443 ui::ScrollEvent fling(ui::ET_SCROLL_FLING_START, 1427 ui::ScrollEvent fling(ui::ET_SCROLL_FLING_START,
1444 gfx::Point(5, 5), 1428 gfx::Point(5, 5),
1445 ui::EventTimeForNow(), 1429 ui::EventTimeForNow(),
1446 0, 1430 0,
1447 0, 20, 1431 0, 20,
1448 0, 20, 1432 0, 20,
1449 2); 1433 2);
1450 widget->OnScrollEvent(&fling); 1434 widget->OnScrollEvent(&fling);
1451 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL_FLING_START)); 1435 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL_FLING_START));
1452 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL_FLING_START)); 1436 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL_FLING_START));
1453 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL_FLING_START)); 1437 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL_FLING_START));
1454 1438
1455 // Unhandled scroll events which are not of type ui::ET_SCROLL should not 1439 // Unhandled scroll events which are not of type ui::ET_SCROLL should not
1456 // be turned into wheel events and re-dispatched. 1440 // be turned into wheel events and re-dispatched.
1457 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL)); 1441 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL));
1458 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL)); 1442 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL));
1459 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL)); 1443 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL));
1460 1444
1461 h1.ResetCounts(); 1445 h1.ResetCounts();
1462 view->ResetCounts(); 1446 view->ResetCounts();
1463 h2.ResetCounts(); 1447 h2.ResetCounts();
1464 1448
1465 // Replace the child of |root_view| with a ScrollableEventCountView so that 1449 // Change the handle mode of |view| so that events are marked as handled at
1466 // ui::ET_SCROLL events are marked as handled at the target phase. 1450 // the target phase.
1467 root_view->RemoveChildView(view.get()); 1451 view->set_handle_mode(EventCountView::CONSUME_EVENTS);
1468 ScrollableEventCountView* scroll_view = new ScrollableEventCountView;
1469 scroll_view->SetBounds(0, 0, 20, 20);
1470 root_view->AddChildView(scroll_view);
1471 1452
1453 // Dispatch a ui::ET_GESTURE_TAP_DOWN and a ui::ET_GESTURE_TAP_CANCEL event.
1454 // The events are handled at the target phase and should not reach the
1455 // post-target handler.
1456 ui::GestureEvent tap_down(5,
1457 5,
1458 0,
1459 ui::EventTimeForNow(),
1460 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN,
1461 0,
1462 0));
1463 widget->OnGestureEvent(&tap_down);
1464 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_DOWN));
1465 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_DOWN));
1466 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_DOWN));
1467
1468 ui::GestureEvent tap_cancel(5,
1469 5,
1470 0,
1471 ui::EventTimeForNow(),
1472 ui::GestureEventDetails(ui::ET_GESTURE_TAP_CANCEL,
1473 0,
1474 0));
1475 widget->OnGestureEvent(&tap_cancel);
1476 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
1477 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
1478 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
1479
1480 h1.ResetCounts();
1481 view->ResetCounts();
1482 h2.ResetCounts();
1483
1484 // Dispatch a ui::ET_SCROLL event. The event is handled at the target phase
1485 // and should not reach the post-target handler.
1472 ui::ScrollEvent consumed_scroll(ui::ET_SCROLL, 1486 ui::ScrollEvent consumed_scroll(ui::ET_SCROLL,
1473 gfx::Point(5, 5), 1487 gfx::Point(5, 5),
1474 ui::EventTimeForNow(), 1488 ui::EventTimeForNow(),
1475 0, 1489 0,
1476 0, 20, 1490 0, 20,
1477 0, 20, 1491 0, 20,
1478 2); 1492 2);
1479 widget->OnScrollEvent(&consumed_scroll); 1493 widget->OnScrollEvent(&consumed_scroll);
1480
1481 // The event is handled at the target phase and should not reach the
1482 // post-target handler.
1483 EXPECT_EQ(1, h1.GetEventCount(ui::ET_SCROLL)); 1494 EXPECT_EQ(1, h1.GetEventCount(ui::ET_SCROLL));
1484 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_SCROLL)); 1495 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL));
1485 EXPECT_EQ(0, h2.GetEventCount(ui::ET_SCROLL)); 1496 EXPECT_EQ(0, h2.GetEventCount(ui::ET_SCROLL));
1486 1497
1487 // Handled scroll events are not turned into wheel events and re-dispatched. 1498 // Handled scroll events are not turned into wheel events and re-dispatched.
1488 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL)); 1499 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL));
1489 EXPECT_EQ(0, scroll_view->GetEventCount(ui::ET_MOUSEWHEEL)); 1500 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL));
1490 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL)); 1501 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL));
1491 1502
1492 widget->CloseNow(); 1503 widget->CloseNow();
1493 } 1504 }
1494 1505
1495 TEST_F(WidgetTest, SynthesizeMouseMoveEvent) { 1506 TEST_F(WidgetTest, SynthesizeMouseMoveEvent) {
1496 Widget* widget = CreateTopLevelNativeWidget(); 1507 Widget* widget = CreateTopLevelNativeWidget();
1497 View* root_view = widget->GetRootView(); 1508 View* root_view = widget->GetRootView();
1498 1509
1499 EventCountView* v1 = new EventCountView(); 1510 EventCountView* v1 = new EventCountView();
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 GestureEventForTest(ui::EventType type, int x, int y) 1961 GestureEventForTest(ui::EventType type, int x, int y)
1951 : GestureEvent(x, 1962 : GestureEvent(x,
1952 y, 1963 y,
1953 0, 1964 0,
1954 base::TimeDelta(), 1965 base::TimeDelta(),
1955 ui::GestureEventDetails(type, 0.0f, 0.0f)) {} 1966 ui::GestureEventDetails(type, 0.0f, 0.0f)) {}
1956 }; 1967 };
1957 1968
1958 // Tests that the |gesture_handler_| member in RootView is always NULL 1969 // Tests that the |gesture_handler_| member in RootView is always NULL
1959 // after the dispatch of a ui::ET_GESTURE_END event corresponding to 1970 // after the dispatch of a ui::ET_GESTURE_END event corresponding to
1960 // the release of the final touch point on the screen. 1971 // the release of the final touch point on the screen and that
1961 TEST_F(WidgetTest, GestureHandlerNotSetOnGestureEnd) { 1972 // ui::ET_GESTURE_END events are never dispatched to a view. Also
1973 // verifies that ui::ET_GESTURE_BEGIN is never dispatched to a view
1974 // and does not change the value of |gesture_handler_|.
1975 TEST_F(WidgetTest, GestureBeginAndEndEvents) {
1962 Widget* widget = CreateTopLevelNativeWidget(); 1976 Widget* widget = CreateTopLevelNativeWidget();
1963 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); 1977 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
1964 EventCountView* view = new EventCountView(); 1978 EventCountView* view = new EventCountView();
1965 view->SetBounds(0, 0, 300, 300); 1979 view->SetBounds(0, 0, 300, 300);
1966 internal::RootView* root_view = 1980 internal::RootView* root_view =
1967 static_cast<internal::RootView*>(widget->GetRootView()); 1981 static_cast<internal::RootView*>(widget->GetRootView());
1968 root_view->AddChildView(view); 1982 root_view->AddChildView(view);
1969 widget->Show(); 1983 widget->Show();
1970 1984
1971 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END 1985 // If no gesture handler is set, dispatching a ui::ET_GESTURE_END or
1972 // event should not set the gesture handler if the event remains unhandled. 1986 // ui::ET_GESTURE_BEGIN event should not set the gesture handler and
1987 // the events should remain unhandled.
1973 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 1988 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1974 GestureEventForTest end(ui::ET_GESTURE_END, 15, 15); 1989 GestureEventForTest end(ui::ET_GESTURE_END, 15, 15);
1975 widget->OnGestureEvent(&end); 1990 widget->OnGestureEvent(&end);
1976 EXPECT_FALSE(end.handled()); 1991 EXPECT_FALSE(end.handled());
1977 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 1992 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1978 1993
1994 GestureEventForTest begin(ui::ET_GESTURE_BEGIN, 15, 15);
1995 widget->OnGestureEvent(&begin);
1996 EXPECT_FALSE(begin.handled());
1997 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1998
1999 // Change the handle mode of |view| to indicate that it would like
2000 // to handle all events.
2001 view->set_handle_mode(EventCountView::CONSUME_EVENTS);
2002
1979 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END 2003 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END
1980 // event should not set the gesture handler event if the event is handled. 2004 // or ui::ET_GESTURE_BEGIN event should not set the gesture handler.
1981 view->set_handle_mode(EventCountView::CONSUME_EVENTS); 2005 // Furthermore, because these events are never dispatched to any view,
2006 // the events should remain unhandled even if the view has indicated
2007 // that they wish to handle these events.
1982 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); 2008 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
1983 widget->OnGestureEvent(&end); 2009 widget->OnGestureEvent(&end);
1984 EXPECT_TRUE(end.handled()); 2010 EXPECT_FALSE(end.handled());
2011 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2012
2013 begin = GestureEventForTest(ui::ET_GESTURE_BEGIN, 15, 15);
2014 widget->OnGestureEvent(&begin);
2015 EXPECT_FALSE(begin.handled());
1985 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2016 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1986 2017
1987 // If the gesture handler has been set by a previous gesture, then 2018 // If the gesture handler has been set by a previous gesture, then
1988 // it should be reset to NULL by a ui::ET_GESTURE_END. 2019 // it should remain unchanged on a ui::ET_GESTURE_BEGIN and be reset
2020 // to NULL by a ui::ET_GESTURE_END.
1989 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15); 2021 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15);
1990 widget->OnGestureEvent(&tap); 2022 widget->OnGestureEvent(&tap);
1991 EXPECT_TRUE(tap.handled()); 2023 EXPECT_TRUE(tap.handled());
1992 EXPECT_EQ(view, GetGestureHandler(root_view)); 2024 EXPECT_EQ(view, GetGestureHandler(root_view));
2025
2026 begin = GestureEventForTest(ui::ET_GESTURE_BEGIN, 15, 15);
2027 widget->OnGestureEvent(&begin);
2028 EXPECT_FALSE(begin.handled());
2029 EXPECT_EQ(view, GetGestureHandler(root_view));
2030
1993 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); 2031 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
1994 widget->OnGestureEvent(&end); 2032 widget->OnGestureEvent(&end);
1995 EXPECT_TRUE(end.handled()); 2033 EXPECT_FALSE(end.handled());
1996 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2034 EXPECT_EQ(NULL, GetGestureHandler(root_view));
1997 2035
1998 // If the gesture handler has been set by a previous gesture, then 2036 // If the gesture handler has been set by a previous gesture, then
1999 // it should be reset to NULL by a ui::ET_GESTURE_END, even when 2037 // it should remain unchanged on a ui::ET_GESTURE_BEGIN and be reset
2000 // the gesture handler does not actually handle the end event. 2038 // to NULL by a ui::ET_GESTURE_END, even when the gesture handler has
2039 // indicated that it would not like to handle any further events.
2001 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 15, 15); 2040 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 15, 15);
2002 widget->OnGestureEvent(&tap); 2041 widget->OnGestureEvent(&tap);
2003 EXPECT_TRUE(tap.handled()); 2042 EXPECT_TRUE(tap.handled());
2004 EXPECT_EQ(view, GetGestureHandler(root_view)); 2043 EXPECT_EQ(view, GetGestureHandler(root_view));
2044
2045 // Change the handle mode of |view| to indicate that it does not want
2046 // to handle any further events.
2047 view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
2048
2049 begin = GestureEventForTest(ui::ET_GESTURE_BEGIN, 15, 15);
2050 widget->OnGestureEvent(&begin);
2051 EXPECT_FALSE(begin.handled());
2052 EXPECT_EQ(view, GetGestureHandler(root_view));
2053
2005 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); 2054 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
2006 view->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
2007 widget->OnGestureEvent(&end); 2055 widget->OnGestureEvent(&end);
2008 EXPECT_FALSE(end.handled()); 2056 EXPECT_FALSE(end.handled());
2009 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2057 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2010 2058
2011 widget->Close(); 2059 widget->Close();
2012 } 2060 }
2013 2061
2014 // Tests that a (non-scroll) gesture event is dispatched to the correct views 2062 // Tests that a (non-scroll) gesture event is dispatched to the correct views
2015 // in a view hierarchy and that the default gesture handler in RootView is set 2063 // in a view hierarchy and that the default gesture handler in RootView is set
2016 // correctly. 2064 // correctly.
2017 // TODO(tdanderson): Create a test similar to ViewTest.ScrollGestureEvent.
2018 TEST_F(WidgetTest, GestureEventDispatch) { 2065 TEST_F(WidgetTest, GestureEventDispatch) {
2019 Widget* widget = CreateTopLevelNativeWidget(); 2066 Widget* widget = CreateTopLevelNativeWidget();
2020 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); 2067 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2021 2068
2022 // Define a hierarchy of four views (coordinates are in 2069 // Define a hierarchy of four views (coordinates are in
2023 // their parent coordinate space). 2070 // their parent coordinate space).
2024 // v1 (0, 0, 300, 300) 2071 // v1 (0, 0, 300, 300)
2025 // v2 (0, 0, 100, 100) 2072 // v2 (0, 0, 100, 100)
2026 // v3 (0, 0, 50, 50) 2073 // v3 (0, 0, 50, 50)
2027 // v4(0, 0, 10, 10) 2074 // v4(0, 0, 10, 10)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP)); 2164 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP));
2118 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP)); 2165 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP));
2119 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP)); 2166 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP));
2120 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP)); 2167 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP));
2121 EXPECT_FALSE(tap.handled()); 2168 EXPECT_FALSE(tap.handled());
2122 EXPECT_EQ(v3, GetGestureHandler(root_view)); 2169 EXPECT_EQ(v3, GetGestureHandler(root_view));
2123 2170
2124 widget->Close(); 2171 widget->Close();
2125 } 2172 }
2126 2173
2174 // Tests that scroll events will change the default gesture handler in
2175 // RootView if the current handler to which they are dispatched does not
2176 // handle scroll events.
2177 TEST_F(WidgetTest, ScrollGestureEventDispatch) {
2178 Widget* widget = CreateTopLevelNativeWidget();
2179 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
2180
2181 // Define a hierarchy of four views (coordinates are in
2182 // their parent coordinate space).
2183 // v1 (0, 0, 300, 300)
2184 // v2 (0, 0, 100, 100)
2185 // v3 (0, 0, 50, 50)
2186 // v4(0, 0, 10, 10)
2187 EventCountView* v1 = new EventCountView();
2188 v1->SetBounds(0, 0, 300, 300);
2189 EventCountView* v2 = new EventCountView();
2190 v2->SetBounds(0, 0, 100, 100);
2191 EventCountView* v3 = new EventCountView();
2192 v3->SetBounds(0, 0, 50, 50);
2193 EventCountView* v4 = new EventCountView();
2194 v4->SetBounds(0, 0, 10, 10);
2195 internal::RootView* root_view =
2196 static_cast<internal::RootView*>(widget->GetRootView());
2197 root_view->AddChildView(v1);
2198 v1->AddChildView(v2);
2199 v2->AddChildView(v3);
2200 v3->AddChildView(v4);
2201
2202 widget->Show();
2203
2204 // Change the handle mode of |v3| to indicate that it would like to handle
2205 // gesture events.
2206 v3->set_handle_mode(EventCountView::CONSUME_EVENTS);
2207
2208 // When no gesture handler is set, dispatching a ui::ET_GESTURE_TAP_DOWN
2209 // should bubble up the views hierarchy until it reaches the first view
2210 // that will handle it (|v3|) and then sets the handler to |v3|.
2211 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2212 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, 5, 5);
2213 widget->OnGestureEvent(&tap_down);
2214 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP_DOWN));
2215 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP_DOWN));
2216 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP_DOWN));
2217 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_TAP_DOWN));
2218 EXPECT_EQ(v3, GetGestureHandler(root_view));
2219 EXPECT_TRUE(tap_down.handled());
2220 v1->ResetCounts();
2221 v2->ResetCounts();
2222 v3->ResetCounts();
2223 v4->ResetCounts();
2224
2225 // A ui::ET_GESTURE_TAP_CANCEL event should be dispatched to |v3| directly.
2226 GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, 5, 5);
2227 widget->OnGestureEvent(&tap_cancel);
2228 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
2229 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
2230 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
2231 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_TAP_CANCEL));
2232 EXPECT_EQ(v3, GetGestureHandler(root_view));
2233 EXPECT_TRUE(tap_cancel.handled());
2234 v1->ResetCounts();
2235 v2->ResetCounts();
2236 v3->ResetCounts();
2237 v4->ResetCounts();
2238
2239 // Change the handle mode of |v3| to indicate that it would no longer like
2240 // to handle events, and change the mode of |v1| to indicate that it would
2241 // like to handle events.
2242 v3->set_handle_mode(EventCountView::PROPAGATE_EVENTS);
2243 v1->set_handle_mode(EventCountView::CONSUME_EVENTS);
2244
2245 // Dispatch a ui::ET_GESTURE_SCROLL_BEGIN event. Because the current gesture
2246 // handler (|v3|) does not handle scroll events, the event should bubble up
2247 // the views hierarchy until it reaches the first view that will handle
2248 // it (|v1|) and then sets the handler to |v1|.
2249 GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, 5, 5);
2250 widget->OnGestureEvent(&scroll_begin);
2251 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
2252 EXPECT_EQ(1, v2->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
2253 EXPECT_EQ(1, v3->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
2254 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN));
2255 EXPECT_EQ(v1, GetGestureHandler(root_view));
2256 EXPECT_TRUE(scroll_begin.handled());
2257 v1->ResetCounts();
2258 v2->ResetCounts();
2259 v3->ResetCounts();
2260 v4->ResetCounts();
2261
2262 // A ui::ET_GESTURE_SCROLL_UPDATE event should be dispatched to |v1|
2263 // directly.
2264 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, 5, 5);
2265 widget->OnGestureEvent(&scroll_update);
2266 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2267 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2268 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2269 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE));
2270 EXPECT_EQ(v1, GetGestureHandler(root_view));
2271 EXPECT_TRUE(scroll_update.handled());
2272 v1->ResetCounts();
2273 v2->ResetCounts();
2274 v3->ResetCounts();
2275 v4->ResetCounts();
2276
2277 // A ui::ET_GESTURE_SCROLL_END event should be dispatched to |v1|
2278 // directly and should not reset the gesture handler.
2279 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, 5, 5);
2280 widget->OnGestureEvent(&scroll_end);
2281 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2282 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2283 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2284 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_SCROLL_END));
2285 EXPECT_EQ(v1, GetGestureHandler(root_view));
2286 EXPECT_TRUE(scroll_end.handled());
2287 v1->ResetCounts();
2288 v2->ResetCounts();
2289 v3->ResetCounts();
2290 v4->ResetCounts();
2291
2292 // A ui::ET_GESTURE_PINCH_BEGIN event (which is a non-scroll event) should
2293 // still be dispatched to |v1| directly.
2294 GestureEventForTest pinch_begin(ui::ET_GESTURE_PINCH_BEGIN, 5, 5);
2295 widget->OnGestureEvent(&pinch_begin);
2296 EXPECT_EQ(1, v1->GetEventCount(ui::ET_GESTURE_PINCH_BEGIN));
2297 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_PINCH_BEGIN));
2298 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_PINCH_BEGIN));
2299 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_PINCH_BEGIN));
2300 EXPECT_EQ(v1, GetGestureHandler(root_view));
2301 EXPECT_TRUE(pinch_begin.handled());
2302 v1->ResetCounts();
2303 v2->ResetCounts();
2304 v3->ResetCounts();
2305 v4->ResetCounts();
2306
2307 // A ui::ET_GESTURE_END event should not be dispatched to any view and should
2308 // set the gesture handler to NULL.
2309 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5);
2310 widget->OnGestureEvent(&end);
2311 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2312 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2313 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2314 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2315 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2316 EXPECT_FALSE(end.handled());
2317
2318 widget->Close();
2319 }
2320
2127 // Test the result of Widget::GetAllChildWidgets(). 2321 // Test the result of Widget::GetAllChildWidgets().
2128 TEST_F(WidgetTest, GetAllChildWidgets) { 2322 TEST_F(WidgetTest, GetAllChildWidgets) {
2129 // Create the following widget hierarchy: 2323 // Create the following widget hierarchy:
2130 // 2324 //
2131 // toplevel 2325 // toplevel
2132 // +-- w1 2326 // +-- w1
2133 // +-- w11 2327 // +-- w11
2134 // +-- w2 2328 // +-- w2
2135 // +-- w21 2329 // +-- w21
2136 // +-- w22 2330 // +-- w22
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); 2922 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED));
2729 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); 2923 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED));
2730 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); 2924 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED));
2731 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); 2925 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags());
2732 2926
2733 widget->CloseNow(); 2927 widget->CloseNow();
2734 } 2928 }
2735 2929
2736 } // namespace test 2930 } // namespace test
2737 } // namespace views 2931 } // namespace views
OLDNEW
« ui/views/controls/slider.cc ('K') | « ui/views/widget/widget_interactive_uitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698