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

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

Issue 11761005: views: Target the synthetic wheel events to the view under the mouse cursor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: aura-test Created 7 years, 11 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 "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/native_widget_types.h" 10 #include "ui/gfx/native_widget_types.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 private: 116 private:
117 int entered_; 117 int entered_;
118 int exited_; 118 int exited_;
119 119
120 int pressed_; 120 int pressed_;
121 121
122 DISALLOW_COPY_AND_ASSIGN(MouseView); 122 DISALLOW_COPY_AND_ASSIGN(MouseView);
123 }; 123 };
124 124
125 // A view that keeps track of the events it receives, but consumes no events.
126 class EventCountView : public View {
127 public:
128 EventCountView() {}
129 virtual ~EventCountView() {}
130
131 int GetEventCount(ui::EventType type) {
132 return event_count_[type];
133 }
134
135 void ResetCounts() {
136 event_count_.clear();
137 }
138
139 private:
140 void RecordEvent(const ui::Event& event) {
141 ++event_count_[event.type()];
142 }
143
144 // Overridden from View:
145 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
146 RecordEvent(event);
147 return false;
148 }
149 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE {
150 RecordEvent(event);
151 return false;
152 }
153 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE {
154 RecordEvent(event);
155 }
156 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE {
157 RecordEvent(event);
158 }
159 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
160 RecordEvent(event);
161 }
162 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
163 RecordEvent(event);
164 }
165 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE {
166 RecordEvent(event);
167 return false;
168 }
169 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE {
170 RecordEvent(event);
171 return false;
172 }
173 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE {
174 RecordEvent(event);
175 return false;
176 }
177
178 // Overridden from ui::EventHandler:
179 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
180 RecordEvent(*event);
181 }
182 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
183 RecordEvent(*event);
184 }
185 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE {
186 RecordEvent(*event);
187 }
188 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
189 RecordEvent(*event);
190 }
191 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
192 RecordEvent(*event);
193 }
194
195 std::map<ui::EventType, int> event_count_;
196
197 DISALLOW_COPY_AND_ASSIGN(EventCountView);
198 };
199
125 // A view that does a capture on gesture-begin events. 200 // A view that does a capture on gesture-begin events.
126 class GestureCaptureView : public View { 201 class GestureCaptureView : public View {
127 public: 202 public:
128 GestureCaptureView() {} 203 GestureCaptureView() {}
129 virtual ~GestureCaptureView() {} 204 virtual ~GestureCaptureView() {}
130 205
131 private: 206 private:
132 // Overridden from View: 207 // Overridden from View:
133 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 208 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
134 if (event->type() == ui::ET_GESTURE_BEGIN) { 209 if (event->type() == ui::ET_GESTURE_BEGIN) {
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 RunPendingMessages(); 1235 RunPendingMessages();
1161 widget.SchedulePaintInRect(init_params.bounds); 1236 widget.SchedulePaintInRect(init_params.bounds);
1162 widget.Hide(); 1237 widget.Hide();
1163 RunPendingMessages(); 1238 RunPendingMessages();
1164 EXPECT_FALSE(widget.received_paint_while_hidden()); 1239 EXPECT_FALSE(widget.received_paint_while_hidden());
1165 widget.Close(); 1240 widget.Close();
1166 } 1241 }
1167 1242
1168 #endif // !defined(OS_CHROMEOS) 1243 #endif // !defined(OS_CHROMEOS)
1169 1244
1245 // Tests that wheel events generted from scroll events are targetted to the
1246 // views under the cursor when the focused view does not processed them.
1247 TEST_F(WidgetTest, WheelEventsFromScrollEventTarget) {
1248 EventCountView* focused_view = new EventCountView;
1249 focused_view->set_focusable(true);
1250
1251 EventCountView* cursor_view = new EventCountView;
1252
1253 focused_view->SetBounds(0, 0, 50, 40);
1254 cursor_view->SetBounds(60, 0, 50, 40);
1255
1256 Widget* widget = CreateTopLevelPlatformWidget();
1257 widget->GetRootView()->AddChildView(focused_view);
1258 widget->GetRootView()->AddChildView(cursor_view);
1259
1260 focused_view->RequestFocus();
1261 EXPECT_TRUE(focused_view->HasFocus());
1262
1263 // Generate a scroll event on the cursor view. The focused view will receive a
1264 // wheel event, but since it doesn't process the event, the view under the
1265 // cursor will receive the wheel event.
1266 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::Point(65, 5), 0, 0, 20);
1267 widget->OnScrollEvent(&scroll);
1268
1269 EXPECT_EQ(0, focused_view->GetEventCount(ui::ET_SCROLL));
1270 EXPECT_EQ(1, focused_view->GetEventCount(ui::ET_MOUSEWHEEL));
1271
1272 EXPECT_EQ(1, cursor_view->GetEventCount(ui::ET_SCROLL));
1273 EXPECT_EQ(1, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL));
1274
1275 focused_view->ResetCounts();
1276 cursor_view->ResetCounts();
1277
1278 ui::ScrollEvent scroll2(ui::ET_SCROLL, gfx::Point(5, 5), 0, 0, 20);
1279 widget->OnScrollEvent(&scroll2);
1280 EXPECT_EQ(1, focused_view->GetEventCount(ui::ET_SCROLL));
1281 EXPECT_EQ(1, focused_view->GetEventCount(ui::ET_MOUSEWHEEL));
1282
1283 EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_SCROLL));
1284 EXPECT_EQ(0, cursor_view->GetEventCount(ui::ET_MOUSEWHEEL));
1285 }
1286
1170 #endif // defined(USE_AURA) 1287 #endif // defined(USE_AURA)
1171 1288
1172 } // namespace 1289 } // namespace
1173 } // namespace views 1290 } // 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