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 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 base::TimeDelta(), | 1937 base::TimeDelta(), |
1938 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0)); | 1938 ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0)); |
1939 widget->OnGestureEvent(&tap_down); | 1939 widget->OnGestureEvent(&tap_down); |
1940 EXPECT_EQ(view, GetGestureHandler(root_view)); | 1940 EXPECT_EQ(view, GetGestureHandler(root_view)); |
1941 widget->Hide(); | 1941 widget->Hide(); |
1942 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 1942 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
1943 | 1943 |
1944 widget->Close(); | 1944 widget->Close(); |
1945 } | 1945 } |
1946 | 1946 |
1947 class GestureEndConsumerView : public View { | 1947 // Convenience to make constructing a GestureEvent simpler. |
1948 private: | 1948 class GestureEventForTest : public ui::GestureEvent { |
1949 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 1949 public: |
1950 if (event->type() == ui::ET_GESTURE_END) | 1950 GestureEventForTest(ui::EventType type, int x, int y) |
1951 event->SetHandled(); | 1951 : GestureEvent(x, |
1952 } | 1952 y, |
| 1953 0, |
| 1954 base::TimeDelta(), |
| 1955 ui::GestureEventDetails(type, 0.0f, 0.0f)) {} |
1953 }; | 1956 }; |
1954 | 1957 |
| 1958 // Tests that the |gesture_handler_| member in RootView is always NULL |
| 1959 // after the dispatch of a ui::ET_GESTURE_END event corresponding to |
| 1960 // the release of the final touch point on the screen. |
1955 TEST_F(WidgetTest, GestureHandlerNotSetOnGestureEnd) { | 1961 TEST_F(WidgetTest, GestureHandlerNotSetOnGestureEnd) { |
1956 Widget* widget = CreateTopLevelNativeWidget(); | 1962 Widget* widget = CreateTopLevelNativeWidget(); |
1957 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); | 1963 widget->SetBounds(gfx::Rect(0, 0, 300, 300)); |
1958 View* view = new GestureEndConsumerView(); | 1964 EventCountView* view = new EventCountView(); |
1959 view->SetBounds(0, 0, 300, 300); | 1965 view->SetBounds(0, 0, 300, 300); |
1960 internal::RootView* root_view = | 1966 internal::RootView* root_view = |
1961 static_cast<internal::RootView*>(widget->GetRootView()); | 1967 static_cast<internal::RootView*>(widget->GetRootView()); |
1962 root_view->AddChildView(view); | 1968 root_view->AddChildView(view); |
| 1969 widget->Show(); |
1963 | 1970 |
1964 widget->Show(); | 1971 // If no gesture handler is set, dispatching only a ui::ET_GESTURE_END |
| 1972 // event should not set the gesture handler if the event remains unhandled. |
1965 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 1973 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
1966 ui::GestureEvent end(15, | 1974 GestureEventForTest end(ui::ET_GESTURE_END, 15, 15); |
1967 15, | |
1968 0, | |
1969 base::TimeDelta(), | |
1970 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0)); | |
1971 widget->OnGestureEvent(&end); | 1975 widget->OnGestureEvent(&end); |
| 1976 EXPECT_FALSE(end.handled()); |
| 1977 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 1978 |
| 1979 // 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. |
| 1981 view->set_handle_mode(EventCountView::CONSUME_EVENTS); |
| 1982 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); |
| 1983 widget->OnGestureEvent(&end); |
| 1984 EXPECT_TRUE(end.handled()); |
| 1985 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 1986 |
| 1987 // 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. |
| 1989 GestureEventForTest tap(ui::ET_GESTURE_TAP, 15, 15); |
| 1990 widget->OnGestureEvent(&tap); |
| 1991 EXPECT_TRUE(tap.handled()); |
| 1992 EXPECT_EQ(view, GetGestureHandler(root_view)); |
| 1993 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); |
| 1994 widget->OnGestureEvent(&end); |
| 1995 EXPECT_TRUE(end.handled()); |
| 1996 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
| 1997 |
| 1998 // 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 |
| 2000 // the gesture handler does not actually handle the end event. |
| 2001 tap = GestureEventForTest(ui::ET_GESTURE_TAP, 15, 15); |
| 2002 widget->OnGestureEvent(&tap); |
| 2003 EXPECT_TRUE(tap.handled()); |
| 2004 EXPECT_EQ(view, GetGestureHandler(root_view)); |
| 2005 end = GestureEventForTest(ui::ET_GESTURE_END, 15, 15); |
| 2006 view->set_handle_mode(EventCountView::PROPAGATE_EVENTS); |
| 2007 widget->OnGestureEvent(&end); |
| 2008 EXPECT_FALSE(end.handled()); |
1972 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 2009 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
1973 | 2010 |
1974 widget->Close(); | 2011 widget->Close(); |
1975 } | 2012 } |
1976 | 2013 |
1977 // Test the result of Widget::GetAllChildWidgets(). | 2014 // Test the result of Widget::GetAllChildWidgets(). |
1978 TEST_F(WidgetTest, GetAllChildWidgets) { | 2015 TEST_F(WidgetTest, GetAllChildWidgets) { |
1979 // Create the following widget hierarchy: | 2016 // Create the following widget hierarchy: |
1980 // | 2017 // |
1981 // toplevel | 2018 // toplevel |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2441 | 2478 |
2442 bool fullscreen_layout_called() const { return fullscreen_layout_called_; } | 2479 bool fullscreen_layout_called() const { return fullscreen_layout_called_; } |
2443 | 2480 |
2444 private: | 2481 private: |
2445 views::Widget* widget_; | 2482 views::Widget* widget_; |
2446 bool fullscreen_layout_called_; | 2483 bool fullscreen_layout_called_; |
2447 | 2484 |
2448 DISALLOW_COPY_AND_ASSIGN(FullscreenAwareFrame); | 2485 DISALLOW_COPY_AND_ASSIGN(FullscreenAwareFrame); |
2449 }; | 2486 }; |
2450 | 2487 |
2451 // Convenience to make constructing a GestureEvent simpler. | |
2452 class GestureEventForTest : public ui::GestureEvent { | |
2453 public: | |
2454 GestureEventForTest(ui::EventType type, int x, int y) | |
2455 : GestureEvent(x, | |
2456 y, | |
2457 0, | |
2458 base::TimeDelta(), | |
2459 ui::GestureEventDetails(type, 0.0f, 0.0f)) {} | |
2460 | |
2461 private: | |
2462 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); | |
2463 }; | |
2464 | |
2465 } // namespace | 2488 } // namespace |
2466 | 2489 |
2467 // Tests that frame Layout is called when a widget goes fullscreen without | 2490 // Tests that frame Layout is called when a widget goes fullscreen without |
2468 // changing its size or title. | 2491 // changing its size or title. |
2469 TEST_F(WidgetTest, FullscreenFrameLayout) { | 2492 TEST_F(WidgetTest, FullscreenFrameLayout) { |
2470 Widget* widget = CreateTopLevelPlatformWidget(); | 2493 Widget* widget = CreateTopLevelPlatformWidget(); |
2471 FullscreenAwareFrame* frame = new FullscreenAwareFrame(widget); | 2494 FullscreenAwareFrame* frame = new FullscreenAwareFrame(widget); |
2472 widget->non_client_view()->SetFrameView(frame); // Owns |frame|. | 2495 widget->non_client_view()->SetFrameView(frame); // Owns |frame|. |
2473 | 2496 |
2474 widget->Maximize(); | 2497 widget->Maximize(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2592 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 2615 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
2593 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); | 2616 EXPECT_EQ(3, view->GetEventCount(ui::ET_MOUSE_RELEASED)); |
2594 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); | 2617 EXPECT_EQ(1, view->GetEventCount(ui::ET_MOUSE_DRAGGED)); |
2595 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); | 2618 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, view->last_flags()); |
2596 | 2619 |
2597 widget->CloseNow(); | 2620 widget->CloseNow(); |
2598 } | 2621 } |
2599 | 2622 |
2600 } // namespace test | 2623 } // namespace test |
2601 } // namespace views | 2624 } // namespace views |
OLD | NEW |