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

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

Issue 533793002: Only target ui::ET_GESTURE_END to the default gesture handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « ui/views/widget/root_view_targeter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 ui::GestureEventDetails(type, 0.0f, 0.0f)) {} 1966 ui::GestureEventDetails(type, 0.0f, 0.0f)) {}
1967 1967
1968 GestureEventForTest(ui::GestureEventDetails details, int x, int y) 1968 GestureEventForTest(ui::GestureEventDetails details, int x, int y)
1969 : GestureEvent(x, y, 0, base::TimeDelta(), details) {} 1969 : GestureEvent(x, y, 0, base::TimeDelta(), details) {}
1970 }; 1970 };
1971 1971
1972 // Tests that the |gesture_handler_| member in RootView is always NULL 1972 // Tests that the |gesture_handler_| member in RootView is always NULL
1973 // after the dispatch of a ui::ET_GESTURE_END event corresponding to 1973 // after the dispatch of a ui::ET_GESTURE_END event corresponding to
1974 // the release of the final touch point on the screen and that 1974 // the release of the final touch point on the screen and that
1975 // ui::ET_GESTURE_END events corresponding to the removal of any other touch 1975 // ui::ET_GESTURE_END events corresponding to the removal of any other touch
1976 // point are never dispatched to a view. Also verifies that 1976 // point are never dispatched to a view. Also verifies that
1977 // ui::ET_GESTURE_BEGIN is never dispatched to a view and does not change the 1977 // ui::ET_GESTURE_BEGIN is never dispatched to a view and does not change the
1978 // value of |gesture_handler_|. 1978 // value of |gesture_handler_|.
1979 TEST_F(WidgetTest, GestureBeginAndEndEvents) { 1979 TEST_F(WidgetTest, GestureBeginAndEndEvents) {
1980 Widget* widget = CreateTopLevelNativeWidget(); 1980 Widget* widget = CreateTopLevelNativeWidget();
1981 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); 1981 widget->SetBounds(gfx::Rect(0, 0, 300, 300));
1982 EventCountView* view = new EventCountView(); 1982 EventCountView* view = new EventCountView();
1983 view->SetBounds(0, 0, 300, 300); 1983 view->SetBounds(0, 0, 300, 300);
1984 internal::RootView* root_view = 1984 internal::RootView* root_view =
1985 static_cast<internal::RootView*>(widget->GetRootView()); 1985 static_cast<internal::RootView*>(widget->GetRootView());
1986 root_view->AddChildView(view); 1986 root_view->AddChildView(view);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 // and should not be marked as handled because it is never dispatched. 2018 // and should not be marked as handled because it is never dispatched.
2019 ui::GestureEventDetails details(ui::ET_GESTURE_END, 15, 15); 2019 ui::GestureEventDetails details(ui::ET_GESTURE_END, 15, 15);
2020 details.set_touch_points(2); 2020 details.set_touch_points(2);
2021 GestureEventForTest end_second_touch_point(details, 15, 15); 2021 GestureEventForTest end_second_touch_point(details, 15, 15);
2022 widget->OnGestureEvent(&end_second_touch_point); 2022 widget->OnGestureEvent(&end_second_touch_point);
2023 EXPECT_FALSE(end_second_touch_point.handled()); 2023 EXPECT_FALSE(end_second_touch_point.handled());
2024 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2024 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2025 2025
2026 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END 2026 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END
2027 // event corresponding to the final touch point should not set the gesture 2027 // event corresponding to the final touch point should not set the gesture
2028 // handler, but it should be marked as handled because it was dispatched to 2028 // handler. Furthermore, it should not be marked as handled because it was
2029 // the view targeted by the event's location. 2029 // not dispatched (GESTURE_END events are only dispatched in cases where
2030 // a gesture handler is already set).
2030 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); 2031 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15);
2031 widget->OnGestureEvent(&end); 2032 widget->OnGestureEvent(&end);
2032 EXPECT_TRUE(end.handled()); 2033 EXPECT_FALSE(end.handled());
2033 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2034 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2034 2035
2035 // If the gesture handler has been set by a previous gesture, then it should 2036 // If the gesture handler has been set by a previous gesture, then it should
2036 // remain unchanged on a ui::ET_GESTURE_BEGIN or a ui::ET_GESTURE_END 2037 // remain unchanged on a ui::ET_GESTURE_BEGIN or a ui::ET_GESTURE_END
2037 // corresponding to a second touch point. It should be reset to NULL by a 2038 // corresponding to a second touch point. It should be reset to NULL by a
2038 // ui::ET_GESTURE_END corresponding to the final touch point. 2039 // ui::ET_GESTURE_END corresponding to the final touch point.
2039 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15); 2040 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15);
2040 widget->OnGestureEvent(&tap); 2041 widget->OnGestureEvent(&tap);
2041 EXPECT_TRUE(tap.handled()); 2042 EXPECT_TRUE(tap.handled());
2042 EXPECT_EQ(view, GetGestureHandler(root_view)); 2043 EXPECT_EQ(view, GetGestureHandler(root_view));
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 widget->Show(); 2381 widget->Show();
2381 2382
2382 // |v1|, |v2|, and |v3| all handle gesture events but |v3| is marked as 2383 // |v1|, |v2|, and |v3| all handle gesture events but |v3| is marked as
2383 // disabled. 2384 // disabled.
2384 v1->set_handle_mode(EventCountView::CONSUME_EVENTS); 2385 v1->set_handle_mode(EventCountView::CONSUME_EVENTS);
2385 v2->set_handle_mode(EventCountView::CONSUME_EVENTS); 2386 v2->set_handle_mode(EventCountView::CONSUME_EVENTS);
2386 v3->set_handle_mode(EventCountView::CONSUME_EVENTS); 2387 v3->set_handle_mode(EventCountView::CONSUME_EVENTS);
2387 v3->SetEnabled(false); 2388 v3->SetEnabled(false);
2388 2389
2389 // No gesture handler is set in the root view, so it should remain unset 2390 // No gesture handler is set in the root view, so it should remain unset
2390 // after a GESTURE_END. The event is first dispatched to |v4| (which does 2391 // after a GESTURE_END. GESTURE_END events are not dispatched unless
2391 // not want to handle the event) and is then targeted at |v3|. Since |v3| 2392 // a gesture handler is already set in the root view, so none of the
2392 // is disabled, the event is not dispatched but is still marked as handled. 2393 // views should see this event and it should not be marked as handled.
2393 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5); 2394 GestureEventForTest end(ui::ET_GESTURE_END, 5, 5);
2394 widget->OnGestureEvent(&end); 2395 widget->OnGestureEvent(&end);
2395 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END)); 2396 EXPECT_EQ(0, v1->GetEventCount(ui::ET_GESTURE_END));
2396 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END)); 2397 EXPECT_EQ(0, v2->GetEventCount(ui::ET_GESTURE_END));
2397 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END)); 2398 EXPECT_EQ(0, v3->GetEventCount(ui::ET_GESTURE_END));
2398 EXPECT_EQ(1, v4->GetEventCount(ui::ET_GESTURE_END)); 2399 EXPECT_EQ(0, v4->GetEventCount(ui::ET_GESTURE_END));
2399 EXPECT_EQ(NULL, GetGestureHandler(root_view)); 2400 EXPECT_EQ(NULL, GetGestureHandler(root_view));
2400 EXPECT_TRUE(end.handled()); 2401 EXPECT_FALSE(end.handled());
2401 v1->ResetCounts(); 2402 v1->ResetCounts();
2402 v2->ResetCounts(); 2403 v2->ResetCounts();
2403 v3->ResetCounts(); 2404 v3->ResetCounts();
2404 v4->ResetCounts(); 2405 v4->ResetCounts();
2405 2406
2406 // No gesture handler is set in the root view. In this case the tap event 2407 // No gesture handler is set in the root view. In this case the tap event
2407 // should be dispatched only to |v4|, the gesture handler should be set to 2408 // should be dispatched only to |v4|, the gesture handler should be set to
2408 // |v3|, and the event should be marked as handled. 2409 // |v3|, and the event should be marked as handled.
2409 GestureEventForTest tap(ui::ET_GESTURE_TAP, 5, 5); 2410 GestureEventForTest tap(ui::ET_GESTURE_TAP, 5, 5);
2410 widget->OnGestureEvent(&tap); 2411 widget->OnGestureEvent(&tap);
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
3088 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); 3089 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED));
3089 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); 3090 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED));
3090 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); 3091 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED));
3091 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); 3092 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags());
3092 3093
3093 widget->CloseNow(); 3094 widget->CloseNow();
3094 } 3095 }
3095 3096
3096 } // namespace test 3097 } // namespace test
3097 } // namespace views 3098 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view_targeter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698