| 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 <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 | 1481 |
| 1482 noscroll_view->SetBounds(0, 0, 50, 40); | 1482 noscroll_view->SetBounds(0, 0, 50, 40); |
| 1483 scroll_view->SetBounds(60, 0, 40, 40); | 1483 scroll_view->SetBounds(60, 0, 40, 40); |
| 1484 | 1484 |
| 1485 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); | 1485 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget()); |
| 1486 widget->GetRootView()->AddChildView(noscroll_view); | 1486 widget->GetRootView()->AddChildView(noscroll_view); |
| 1487 widget->GetRootView()->AddChildView(scroll_view); | 1487 widget->GetRootView()->AddChildView(scroll_view); |
| 1488 | 1488 |
| 1489 { | 1489 { |
| 1490 ui::GestureEvent begin( | 1490 ui::GestureEvent begin( |
| 1491 5, | 1491 5, 5, 0, base::TimeTicks(), |
| 1492 5, | |
| 1493 0, | |
| 1494 base::TimeDelta(), | |
| 1495 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); | 1492 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 1496 widget->OnGestureEvent(&begin); | 1493 widget->OnGestureEvent(&begin); |
| 1497 ui::GestureEvent update( | 1494 ui::GestureEvent update( |
| 1498 25, | 1495 25, 15, 0, base::TimeTicks(), |
| 1499 15, | |
| 1500 0, | |
| 1501 base::TimeDelta(), | |
| 1502 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10)); | 1496 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10)); |
| 1503 widget->OnGestureEvent(&update); | 1497 widget->OnGestureEvent(&update); |
| 1504 ui::GestureEvent end(25, | 1498 ui::GestureEvent end(25, 15, 0, base::TimeTicks(), |
| 1505 15, | |
| 1506 0, | |
| 1507 base::TimeDelta(), | |
| 1508 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); | 1499 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); |
| 1509 widget->OnGestureEvent(&end); | 1500 widget->OnGestureEvent(&end); |
| 1510 | 1501 |
| 1511 EXPECT_EQ(1, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); | 1502 EXPECT_EQ(1, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 1512 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); | 1503 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); |
| 1513 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); | 1504 EXPECT_EQ(0, noscroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); |
| 1514 } | 1505 } |
| 1515 | 1506 |
| 1516 { | 1507 { |
| 1517 ui::GestureEvent begin( | 1508 ui::GestureEvent begin( |
| 1518 65, | 1509 65, 5, 0, base::TimeTicks(), |
| 1519 5, | |
| 1520 0, | |
| 1521 base::TimeDelta(), | |
| 1522 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); | 1510 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 1523 widget->OnGestureEvent(&begin); | 1511 widget->OnGestureEvent(&begin); |
| 1524 ui::GestureEvent update( | 1512 ui::GestureEvent update( |
| 1525 85, | 1513 85, 15, 0, base::TimeTicks(), |
| 1526 15, | |
| 1527 0, | |
| 1528 base::TimeDelta(), | |
| 1529 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10)); | 1514 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 20, 10)); |
| 1530 widget->OnGestureEvent(&update); | 1515 widget->OnGestureEvent(&update); |
| 1531 ui::GestureEvent end(85, | 1516 ui::GestureEvent end(85, 15, 0, base::TimeTicks(), |
| 1532 15, | |
| 1533 0, | |
| 1534 base::TimeDelta(), | |
| 1535 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); | 1517 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END)); |
| 1536 widget->OnGestureEvent(&end); | 1518 widget->OnGestureEvent(&end); |
| 1537 | 1519 |
| 1538 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); | 1520 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_BEGIN)); |
| 1539 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); | 1521 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_UPDATE)); |
| 1540 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); | 1522 EXPECT_EQ(1, scroll_view->GetEventCount(ui::ET_GESTURE_SCROLL_END)); |
| 1541 } | 1523 } |
| 1542 } | 1524 } |
| 1543 | 1525 |
| 1544 // Tests that event-handlers installed on the RootView get triggered correctly. | 1526 // Tests that event-handlers installed on the RootView get triggered correctly. |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, | 2133 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, |
| 2152 ui::EventTimeForNow(), 0, 0); | 2134 ui::EventTimeForNow(), 0, 0); |
| 2153 widget->OnMouseEvent(&move); | 2135 widget->OnMouseEvent(&move); |
| 2154 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); | 2136 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); |
| 2155 widget->Hide(); | 2137 widget->Hide(); |
| 2156 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); | 2138 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); |
| 2157 | 2139 |
| 2158 // Check RootView::gesture_handler_. | 2140 // Check RootView::gesture_handler_. |
| 2159 widget->Show(); | 2141 widget->Show(); |
| 2160 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2142 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 2161 ui::GestureEvent tap_down(15, | 2143 ui::GestureEvent tap_down(15, 15, 0, base::TimeTicks(), |
| 2162 15, | |
| 2163 0, | |
| 2164 base::TimeDelta(), | |
| 2165 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 2144 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
| 2166 widget->OnGestureEvent(&tap_down); | 2145 widget->OnGestureEvent(&tap_down); |
| 2167 EXPECT_EQ(view, GetGestureHandler(root_view)); | 2146 EXPECT_EQ(view, GetGestureHandler(root_view)); |
| 2168 widget->Hide(); | 2147 widget->Hide(); |
| 2169 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2148 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 2170 | 2149 |
| 2171 widget->Close(); | 2150 widget->Close(); |
| 2172 } | 2151 } |
| 2173 | 2152 |
| 2174 // Convenience to make constructing a GestureEvent simpler. | 2153 // Convenience to make constructing a GestureEvent simpler. |
| 2175 class GestureEventForTest : public ui::GestureEvent { | 2154 class GestureEventForTest : public ui::GestureEvent { |
| 2176 public: | 2155 public: |
| 2177 GestureEventForTest(ui::EventType type, int x, int y) | 2156 GestureEventForTest(ui::EventType type, int x, int y) |
| 2178 : GestureEvent(x, | 2157 : GestureEvent(x, |
| 2179 y, | 2158 y, |
| 2180 0, | 2159 0, |
| 2181 base::TimeDelta(), | 2160 base::TimeTicks(), |
| 2182 ui::GestureEventDetails(type)) {} | 2161 ui::GestureEventDetails(type)) {} |
| 2183 | 2162 |
| 2184 GestureEventForTest(ui::GestureEventDetails details, int x, int y) | 2163 GestureEventForTest(ui::GestureEventDetails details, int x, int y) |
| 2185 : GestureEvent(x, y, 0, base::TimeDelta(), details) {} | 2164 : GestureEvent(x, y, 0, base::TimeTicks(), details) {} |
| 2186 }; | 2165 }; |
| 2187 | 2166 |
| 2188 // Tests that the |gesture_handler_| member in RootView is always NULL | 2167 // Tests that the |gesture_handler_| member in RootView is always NULL |
| 2189 // after the dispatch of a ui::ET_GESTURE_END event corresponding to | 2168 // after the dispatch of a ui::ET_GESTURE_END event corresponding to |
| 2190 // the release of the final touch point on the screen, but that | 2169 // the release of the final touch point on the screen, but that |
| 2191 // ui::ET_GESTURE_END events corresponding to the removal of any other touch | 2170 // ui::ET_GESTURE_END events corresponding to the removal of any other touch |
| 2192 // point do not modify |gesture_handler_|. | 2171 // point do not modify |gesture_handler_|. |
| 2193 TEST_F(WidgetTest, GestureEndEvents) { | 2172 TEST_F(WidgetTest, GestureEndEvents) { |
| 2194 Widget* widget = CreateTopLevelNativeWidget(); | 2173 Widget* widget = CreateTopLevelNativeWidget(); |
| 2195 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); | 2174 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); |
| (...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3515 // Moving the child to a different widget should call the removals observer. | 3494 // Moving the child to a different widget should call the removals observer. |
| 3516 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); | 3495 WidgetAutoclosePtr widget2(CreateTopLevelPlatformWidget()); |
| 3517 widget2->client_view()->AddChildView(child); | 3496 widget2->client_view()->AddChildView(child); |
| 3518 EXPECT_TRUE(removals_observer.DidRemoveView(child)); | 3497 EXPECT_TRUE(removals_observer.DidRemoveView(child)); |
| 3519 | 3498 |
| 3520 widget->RemoveRemovalsObserver(&removals_observer); | 3499 widget->RemoveRemovalsObserver(&removals_observer); |
| 3521 } | 3500 } |
| 3522 | 3501 |
| 3523 } // namespace test | 3502 } // namespace test |
| 3524 } // namespace views | 3503 } // namespace views |
| OLD | NEW |