| 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 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 // Tests that wheel events generated from scroll events are targetted to the | 1467 // Tests that wheel events generated from scroll events are targetted to the |
| 1468 // views under the cursor when the focused view does not processed them. | 1468 // views under the cursor when the focused view does not processed them. |
| 1469 TEST_F(WidgetTest, WheelEventsFromScrollEventTarget) { | 1469 TEST_F(WidgetTest, WheelEventsFromScrollEventTarget) { |
| 1470 EventCountView* cursor_view = new EventCountView; | 1470 EventCountView* cursor_view = new EventCountView; |
| 1471 cursor_view->SetBounds(60, 0, 50, 40); | 1471 cursor_view->SetBounds(60, 0, 50, 40); |
| 1472 | 1472 |
| 1473 Widget* widget = CreateTopLevelPlatformWidget(); | 1473 Widget* widget = CreateTopLevelPlatformWidget(); |
| 1474 widget->GetRootView()->AddChildView(cursor_view); | 1474 widget->GetRootView()->AddChildView(cursor_view); |
| 1475 | 1475 |
| 1476 // Generate a scroll event on the cursor view. | 1476 // Generate a scroll event on the cursor view. |
| 1477 ui::ScrollEvent scroll(ui::ET_SCROLL, | 1477 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::PointF(65.f, 5.f), |
| 1478 gfx::Point(65, 5), | 1478 ui::EventTimeForNow(), 0, 0, 20, 0, 20, 2); |
| 1479 ui::EventTimeForNow(), | |
| 1480 0, | |
| 1481 0, 20, | |
| 1482 0, 20, | |
| 1483 2); | |
| 1484 widget->OnScrollEvent(&scroll); | 1479 widget->OnScrollEvent(&scroll); |
| 1485 | 1480 |
| 1486 EXPECT_EQ(1, cursor_view->GetEventCount(ui::ET_SCROLL)); | 1481 EXPECT_EQ(1, cursor_view->GetEventCount(ui::ET_SCROLL)); |
| 1487 EXPECT_EQ(1, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL)); | 1482 EXPECT_EQ(1, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1488 | 1483 |
| 1489 cursor_view->ResetCounts(); | 1484 cursor_view->ResetCounts(); |
| 1490 | 1485 |
| 1491 ui::ScrollEvent scroll2(ui::ET_SCROLL, | 1486 ui::ScrollEvent scroll2(ui::ET_SCROLL, gfx::PointF(5.f, 5.f), |
| 1492 gfx::Point(5, 5), | 1487 ui::EventTimeForNow(), 0, 0, 20, 0, 20, 2); |
| 1493 ui::EventTimeForNow(), | |
| 1494 0, | |
| 1495 0, 20, | |
| 1496 0, 20, | |
| 1497 2); | |
| 1498 widget->OnScrollEvent(&scroll2); | 1488 widget->OnScrollEvent(&scroll2); |
| 1499 | 1489 |
| 1500 EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_SCROLL)); | 1490 EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_SCROLL)); |
| 1501 EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL)); | 1491 EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1502 | 1492 |
| 1503 widget->CloseNow(); | 1493 widget->CloseNow(); |
| 1504 } | 1494 } |
| 1505 | 1495 |
| 1506 // Tests that if a scroll-begin gesture is not handled, then subsequent scroll | 1496 // Tests that if a scroll-begin gesture is not handled, then subsequent scroll |
| 1507 // events are not dispatched to any view. | 1497 // events are not dispatched to any view. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 root_view->AddPreTargetHandler(&h1); | 1578 root_view->AddPreTargetHandler(&h1); |
| 1589 | 1579 |
| 1590 EventCountHandler h2; | 1580 EventCountHandler h2; |
| 1591 root_view->AddPostTargetHandler(&h2); | 1581 root_view->AddPostTargetHandler(&h2); |
| 1592 | 1582 |
| 1593 widget->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1583 widget->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1594 widget->Show(); | 1584 widget->Show(); |
| 1595 | 1585 |
| 1596 // Dispatch a ui::ET_SCROLL event. The event remains unhandled and should | 1586 // Dispatch a ui::ET_SCROLL event. The event remains unhandled and should |
| 1597 // bubble up the views hierarchy to be re-dispatched on the root view. | 1587 // bubble up the views hierarchy to be re-dispatched on the root view. |
| 1598 ui::ScrollEvent scroll(ui::ET_SCROLL, | 1588 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::PointF(5.f, 5.f), |
| 1599 gfx::Point(5, 5), | 1589 ui::EventTimeForNow(), 0, 0, 20, 0, 20, 2); |
| 1600 ui::EventTimeForNow(), | |
| 1601 0, | |
| 1602 0, 20, | |
| 1603 0, 20, | |
| 1604 2); | |
| 1605 widget->OnScrollEvent(&scroll); | 1590 widget->OnScrollEvent(&scroll); |
| 1606 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL)); | 1591 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL)); |
| 1607 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL)); | 1592 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL)); |
| 1608 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL)); | 1593 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL)); |
| 1609 | 1594 |
| 1610 // Unhandled scroll events are turned into wheel events and re-dispatched. | 1595 // Unhandled scroll events are turned into wheel events and re-dispatched. |
| 1611 EXPECT_EQ(1, h1.GetEventCount(ui::ET_MOUSEWHEEL)); | 1596 EXPECT_EQ(1, h1.GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1612 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSEWHEEL)); | 1597 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1613 EXPECT_EQ(1, h2.GetEventCount(ui::ET_MOUSEWHEEL)); | 1598 EXPECT_EQ(1, h2.GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1614 | 1599 |
| 1615 h1.ResetCounts(); | 1600 h1.ResetCounts(); |
| 1616 view->ResetCounts(); | 1601 view->ResetCounts(); |
| 1617 h2.ResetCounts(); | 1602 h2.ResetCounts(); |
| 1618 | 1603 |
| 1619 // Dispatch a ui::ET_SCROLL_FLING_START event. The event remains unhandled and | 1604 // Dispatch a ui::ET_SCROLL_FLING_START event. The event remains unhandled and |
| 1620 // should bubble up the views hierarchy to be re-dispatched on the root view. | 1605 // should bubble up the views hierarchy to be re-dispatched on the root view. |
| 1621 ui::ScrollEvent fling(ui::ET_SCROLL_FLING_START, | 1606 ui::ScrollEvent fling(ui::ET_SCROLL_FLING_START, gfx::PointF(5.f, 5.f), |
| 1622 gfx::Point(5, 5), | 1607 ui::EventTimeForNow(), 0, 0, 20, 0, 20, 2); |
| 1623 ui::EventTimeForNow(), | |
| 1624 0, | |
| 1625 0, 20, | |
| 1626 0, 20, | |
| 1627 2); | |
| 1628 widget->OnScrollEvent(&fling); | 1608 widget->OnScrollEvent(&fling); |
| 1629 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL_FLING_START)); | 1609 EXPECT_EQ(2, h1.GetEventCount(ui::ET_SCROLL_FLING_START)); |
| 1630 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL_FLING_START)); | 1610 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL_FLING_START)); |
| 1631 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL_FLING_START)); | 1611 EXPECT_EQ(2, h2.GetEventCount(ui::ET_SCROLL_FLING_START)); |
| 1632 | 1612 |
| 1633 // Unhandled scroll events which are not of type ui::ET_SCROLL should not | 1613 // Unhandled scroll events which are not of type ui::ET_SCROLL should not |
| 1634 // be turned into wheel events and re-dispatched. | 1614 // be turned into wheel events and re-dispatched. |
| 1635 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL)); | 1615 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1636 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL)); | 1616 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1637 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL)); | 1617 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1667 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); | 1647 EXPECT_EQ(1, h1.GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); |
| 1668 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); | 1648 EXPECT_EQ(1, view->GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); |
| 1669 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); | 1649 EXPECT_EQ(0, h2.GetEventCount(ui::ET_GESTURE_TAP_CANCEL)); |
| 1670 | 1650 |
| 1671 h1.ResetCounts(); | 1651 h1.ResetCounts(); |
| 1672 view->ResetCounts(); | 1652 view->ResetCounts(); |
| 1673 h2.ResetCounts(); | 1653 h2.ResetCounts(); |
| 1674 | 1654 |
| 1675 // Dispatch a ui::ET_SCROLL event. The event is handled at the target phase | 1655 // Dispatch a ui::ET_SCROLL event. The event is handled at the target phase |
| 1676 // and should not reach the post-target handler. | 1656 // and should not reach the post-target handler. |
| 1677 ui::ScrollEvent consumed_scroll(ui::ET_SCROLL, | 1657 ui::ScrollEvent consumed_scroll(ui::ET_SCROLL, gfx::PointF(5.f, 5.f), |
| 1678 gfx::Point(5, 5), | 1658 ui::EventTimeForNow(), 0, 0, 20, 0, 20, 2); |
| 1679 ui::EventTimeForNow(), | |
| 1680 0, | |
| 1681 0, 20, | |
| 1682 0, 20, | |
| 1683 2); | |
| 1684 widget->OnScrollEvent(&consumed_scroll); | 1659 widget->OnScrollEvent(&consumed_scroll); |
| 1685 EXPECT_EQ(1, h1.GetEventCount(ui::ET_SCROLL)); | 1660 EXPECT_EQ(1, h1.GetEventCount(ui::ET_SCROLL)); |
| 1686 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL)); | 1661 EXPECT_EQ(1, view->GetEventCount(ui::ET_SCROLL)); |
| 1687 EXPECT_EQ(0, h2.GetEventCount(ui::ET_SCROLL)); | 1662 EXPECT_EQ(0, h2.GetEventCount(ui::ET_SCROLL)); |
| 1688 | 1663 |
| 1689 // Handled scroll events are not turned into wheel events and re-dispatched. | 1664 // Handled scroll events are not turned into wheel events and re-dispatched. |
| 1690 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL)); | 1665 EXPECT_EQ(0, h1.GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1691 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL)); | 1666 EXPECT_EQ(0, view->GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1692 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL)); | 1667 EXPECT_EQ(0, h2.GetEventCount(ui::ET_MOUSEWHEEL)); |
| 1693 | 1668 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1708 | 1683 |
| 1709 widget->Show(); | 1684 widget->Show(); |
| 1710 | 1685 |
| 1711 // SynthesizeMouseMoveEvent does nothing until the mouse is entered. | 1686 // SynthesizeMouseMoveEvent does nothing until the mouse is entered. |
| 1712 widget->SynthesizeMouseMoveEvent(); | 1687 widget->SynthesizeMouseMoveEvent(); |
| 1713 EXPECT_EQ(0, v1->GetEventCount(ui::ET_MOUSE_MOVED)); | 1688 EXPECT_EQ(0, v1->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1714 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1689 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1715 | 1690 |
| 1716 gfx::Point cursor_location(5, 5); | 1691 gfx::Point cursor_location(5, 5); |
| 1717 View::ConvertPointToScreen(widget->GetRootView(), &cursor_location); | 1692 View::ConvertPointToScreen(widget->GetRootView(), &cursor_location); |
| 1718 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 1693 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::PointF(cursor_location), |
| 1719 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 1694 gfx::PointF(cursor_location), ui::EventTimeForNow(), |
| 1695 ui::EF_NONE, ui::EF_NONE); |
| 1720 ui::EventDispatchDetails details = | 1696 ui::EventDispatchDetails details = |
| 1721 WidgetTest::GetEventProcessor(widget)->OnEventFromSource(&move); | 1697 WidgetTest::GetEventProcessor(widget)->OnEventFromSource(&move); |
| 1722 EXPECT_FALSE(details.dispatcher_destroyed); | 1698 EXPECT_FALSE(details.dispatcher_destroyed); |
| 1723 | 1699 |
| 1724 EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_MOVED)); | 1700 EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1725 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); | 1701 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 1726 | 1702 |
| 1727 // SynthesizeMouseMoveEvent dispatches an mousemove event. | 1703 // SynthesizeMouseMoveEvent dispatches an mousemove event. |
| 1728 widget->SynthesizeMouseMoveEvent(); | 1704 widget->SynthesizeMouseMoveEvent(); |
| 1729 EXPECT_EQ(2, v1->GetEventCount(ui::ET_MOUSE_MOVED)); | 1705 EXPECT_EQ(2, v1->GetEventCount(ui::ET_MOUSE_MOVED)); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); | 2127 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); |
| 2152 View* view = new RootViewTestView(); | 2128 View* view = new RootViewTestView(); |
| 2153 view->SetBounds(0, 0, 300, 300); | 2129 view->SetBounds(0, 0, 300, 300); |
| 2154 internal::RootView* root_view = | 2130 internal::RootView* root_view = |
| 2155 static_cast<internal::RootView*>(widget->GetRootView()); | 2131 static_cast<internal::RootView*>(widget->GetRootView()); |
| 2156 root_view->AddChildView(view); | 2132 root_view->AddChildView(view); |
| 2157 | 2133 |
| 2158 // Check RootView::mouse_pressed_handler_. | 2134 // Check RootView::mouse_pressed_handler_. |
| 2159 widget->Show(); | 2135 widget->Show(); |
| 2160 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); | 2136 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); |
| 2161 gfx::Point click_location(45, 15); | 2137 gfx::PointF click_location(45.f, 15.f); |
| 2162 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 2138 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, |
| 2163 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 2139 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 2164 ui::EF_LEFT_MOUSE_BUTTON); | 2140 ui::EF_LEFT_MOUSE_BUTTON); |
| 2165 widget->OnMouseEvent(&press); | 2141 widget->OnMouseEvent(&press); |
| 2166 EXPECT_EQ(view, GetMousePressedHandler(root_view)); | 2142 EXPECT_EQ(view, GetMousePressedHandler(root_view)); |
| 2167 widget->Hide(); | 2143 widget->Hide(); |
| 2168 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); | 2144 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); |
| 2169 | 2145 |
| 2170 // Check RootView::mouse_move_handler_. | 2146 // Check RootView::mouse_move_handler_. |
| 2171 widget->Show(); | 2147 widget->Show(); |
| 2172 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); | 2148 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); |
| 2173 gfx::Point move_location(45, 15); | 2149 gfx::PointF move_location(45.f, 15.f); |
| 2174 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, | 2150 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, |
| 2175 ui::EventTimeForNow(), 0, 0); | 2151 ui::EventTimeForNow(), 0, 0); |
| 2176 widget->OnMouseEvent(&move); | 2152 widget->OnMouseEvent(&move); |
| 2177 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); | 2153 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); |
| 2178 widget->Hide(); | 2154 widget->Hide(); |
| 2179 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); | 2155 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); |
| 2180 | 2156 |
| 2181 // Check RootView::gesture_handler_. | 2157 // Check RootView::gesture_handler_. |
| 2182 widget->Show(); | 2158 widget->Show(); |
| 2183 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2159 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 2184 ui::GestureEvent tap_down(15, | 2160 ui::GestureEvent tap_down(15.f, 15.f, 0, base::TimeDelta(), |
| 2185 15, | |
| 2186 0, | |
| 2187 base::TimeDelta(), | |
| 2188 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 2161 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
| 2189 widget->OnGestureEvent(&tap_down); | 2162 widget->OnGestureEvent(&tap_down); |
| 2190 EXPECT_EQ(view, GetGestureHandler(root_view)); | 2163 EXPECT_EQ(view, GetGestureHandler(root_view)); |
| 2191 widget->Hide(); | 2164 widget->Hide(); |
| 2192 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2165 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 2193 | 2166 |
| 2194 widget->Close(); | 2167 widget->Close(); |
| 2195 } | 2168 } |
| 2196 | 2169 |
| 2197 // Convenience to make constructing a GestureEvent simpler. | 2170 // Convenience to make constructing a GestureEvent simpler. |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3257 EXPECT_FALSE(widget->IsAlwaysOnTop()); | 3230 EXPECT_FALSE(widget->IsAlwaysOnTop()); |
| 3258 widget->SetAlwaysOnTop(true); | 3231 widget->SetAlwaysOnTop(true); |
| 3259 EXPECT_TRUE(widget->IsAlwaysOnTop()); | 3232 EXPECT_TRUE(widget->IsAlwaysOnTop()); |
| 3260 widget->SetAlwaysOnTop(false); | 3233 widget->SetAlwaysOnTop(false); |
| 3261 EXPECT_FALSE(widget->IsAlwaysOnTop()); | 3234 EXPECT_FALSE(widget->IsAlwaysOnTop()); |
| 3262 widget->CloseNow(); | 3235 widget->CloseNow(); |
| 3263 } | 3236 } |
| 3264 | 3237 |
| 3265 } // namespace test | 3238 } // namespace test |
| 3266 } // namespace views | 3239 } // namespace views |
| OLD | NEW |