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

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

Issue 10983008: views: Reset the capture-view at the end of a gesture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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
« no previous file with comments | « ui/views/widget/root_view.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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/native_widget_types.h" 9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/point.h" 10 #include "ui/gfx/point.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #elif defined(OS_WIN) 67 #elif defined(OS_WIN)
68 typedef NativeWidgetWin NativeWidgetPlatformForTest; 68 typedef NativeWidgetWin NativeWidgetPlatformForTest;
69 #endif 69 #endif
70 70
71 // A view that always processes all mouse events. 71 // A view that always processes all mouse events.
72 class MouseView : public View { 72 class MouseView : public View {
73 public: 73 public:
74 MouseView() 74 MouseView()
75 : View(), 75 : View(),
76 entered_(0), 76 entered_(0),
77 exited_(0) { 77 exited_(0),
78 pressed_(0) {
78 } 79 }
79 virtual ~MouseView() {} 80 virtual ~MouseView() {}
80 81
81 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { 82 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
83 pressed_++;
82 return true; 84 return true;
83 } 85 }
84 86
85 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { 87 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
86 entered_++; 88 entered_++;
87 } 89 }
88 90
89 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { 91 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
90 exited_++; 92 exited_++;
91 } 93 }
92 94
93 // Return the number of OnMouseEntered calls and reset the counter. 95 // Return the number of OnMouseEntered calls and reset the counter.
94 int EnteredCalls() { 96 int EnteredCalls() {
95 int i = entered_; 97 int i = entered_;
96 entered_ = 0; 98 entered_ = 0;
97 return i; 99 return i;
98 } 100 }
99 101
100 // Return the number of OnMouseExited calls and reset the counter. 102 // Return the number of OnMouseExited calls and reset the counter.
101 int ExitedCalls() { 103 int ExitedCalls() {
102 int i = exited_; 104 int i = exited_;
103 exited_ = 0; 105 exited_ = 0;
104 return i; 106 return i;
105 } 107 }
106 108
109 int pressed() const { return pressed_; }
110
107 private: 111 private:
108 int entered_; 112 int entered_;
109 int exited_; 113 int exited_;
110 114
115 int pressed_;
116
111 DISALLOW_COPY_AND_ASSIGN(MouseView); 117 DISALLOW_COPY_AND_ASSIGN(MouseView);
112 }; 118 };
113 119
120 // A view that does a capture on gesture-begin events.
121 class GestureCaptureView : public View {
122 public:
123 GestureCaptureView() {}
124 virtual ~GestureCaptureView() {}
125
126 private:
127 // Overridden from View:
128 virtual ui::EventResult OnGestureEvent(
129 const ui::GestureEvent& event) OVERRIDE {
130 if (event.type() == ui::ET_GESTURE_BEGIN) {
131 GetWidget()->SetCapture(this);
132 return ui::ER_CONSUMED;
133 }
134 return ui::ER_UNHANDLED;
135 }
136
137 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView);
138 };
139
114 typedef ViewsTestBase WidgetTest; 140 typedef ViewsTestBase WidgetTest;
115 141
116 NativeWidget* CreatePlatformNativeWidget( 142 NativeWidget* CreatePlatformNativeWidget(
117 internal::NativeWidgetDelegate* delegate) { 143 internal::NativeWidgetDelegate* delegate) {
118 return new NativeWidgetPlatformForTest(delegate); 144 return new NativeWidgetPlatformForTest(delegate);
119 } 145 }
120 146
121 Widget* CreateTopLevelPlatformWidget() { 147 Widget* CreateTopLevelPlatformWidget() {
122 Widget* toplevel = new Widget; 148 Widget* toplevel = new Widget;
123 Widget::InitParams toplevel_params(Widget::InitParams::TYPE_WINDOW); 149 Widget::InitParams toplevel_params(Widget::InitParams::TYPE_WINDOW);
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 RunPendingMessages(); 921 RunPendingMessages();
896 922
897 // And it stays maximized after getting out of full screen. 923 // And it stays maximized after getting out of full screen.
898 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel)); 924 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetWidgetShowState(toplevel));
899 925
900 // Clean up. 926 // Clean up.
901 toplevel->Close(); 927 toplevel->Close();
902 RunPendingMessages(); 928 RunPendingMessages();
903 } 929 }
904 930
931 TEST_F(WidgetTest, ResetCaptureOnGestureEnd) {
932 Widget* toplevel = CreateTopLevelPlatformWidget();
933 View* container = new View;
934 toplevel->SetContentsView(container);
935
936 View* gesture = new GestureCaptureView;
937 gesture->SetBounds(0, 0, 30, 30);
938 container->AddChildView(gesture);
939
940 MouseView* mouse = new MouseView;
941 mouse->SetBounds(30, 0, 30, 30);
942 container->AddChildView(mouse);
943
944 toplevel->SetSize(gfx::Size(100, 100));
945 toplevel->Show();
946
947 // Start a gesture on |gesture|.
948 ui::GestureEvent begin(ui::ET_GESTURE_BEGIN,
949 15, 15, 0, base::TimeDelta(),
950 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
951 ui::GestureEvent end(ui::ET_GESTURE_END,
952 15, 15, 0, base::TimeDelta(),
953 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
954 toplevel->OnGestureEvent(begin);
955
956 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse|
957 // will not receive the event.
958 gfx::Point click_location(45, 15);
959 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location,
960 ui::EF_LEFT_MOUSE_BUTTON);
961 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location,
962 ui::EF_LEFT_MOUSE_BUTTON);
963
964 toplevel->OnMouseEvent(press);
965 toplevel->OnMouseEvent(release);
966 EXPECT_EQ(0, mouse->pressed());
967
968 // The end of the gesture should release the capture, and pressing on |mouse|
969 // should now reach |mouse|.
970 toplevel->OnGestureEvent(end);
971 toplevel->OnMouseEvent(press);
972 toplevel->OnMouseEvent(release);
973 EXPECT_EQ(1, mouse->pressed());
974
975 toplevel->Close();
976 RunPendingMessages();
977 }
978
905 } // namespace 979 } // namespace
906 } // namespace views 980 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698