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 "ui/aura/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 1115 matching lines...) Loading... |
1126 } | 1126 } |
1127 EventFilterRecorder::OnTouchEvent(event); | 1127 EventFilterRecorder::OnTouchEvent(event); |
1128 } | 1128 } |
1129 | 1129 |
1130 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 1130 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
1131 EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target()); | 1131 EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target()); |
1132 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 1132 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
1133 if (!reposted_) { | 1133 if (!reposted_) { |
1134 EXPECT_NE(repost_target_, event->target()); | 1134 EXPECT_NE(repost_target_, event->target()); |
1135 reposted_ = true; | 1135 reposted_ = true; |
1136 repost_target_->GetDispatcher()->RepostEvent(*event); | 1136 repost_target_->GetHost()->dispatcher()->RepostEvent(*event); |
1137 // Ensure that the reposted gesture event above goes to the | 1137 // Ensure that the reposted gesture event above goes to the |
1138 // repost_target_; | 1138 // repost_target_; |
1139 repost_source_->GetRootWindow()->RemoveChild(repost_source_); | 1139 repost_source_->GetRootWindow()->RemoveChild(repost_source_); |
1140 return; | 1140 return; |
1141 } | 1141 } |
1142 } | 1142 } |
1143 EventFilterRecorder::OnGestureEvent(event); | 1143 EventFilterRecorder::OnGestureEvent(event); |
1144 } | 1144 } |
1145 | 1145 |
1146 // Ignore mouse events as they don't fire at all times. This causes | 1146 // Ignore mouse events as they don't fire at all times. This causes |
(...skipping 197 matching lines...) Loading... |
1344 | 1344 |
1345 int mouse_event_count() const { return mouse_event_count_; } | 1345 int mouse_event_count() const { return mouse_event_count_; } |
1346 | 1346 |
1347 // TestWindowDelegate: | 1347 // TestWindowDelegate: |
1348 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 1348 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
1349 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && | 1349 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && |
1350 mouse_event_count_++ == 0) { | 1350 mouse_event_count_++ == 0) { |
1351 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, | 1351 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, |
1352 gfx::Point(10, 10), gfx::Point(10, 10), | 1352 gfx::Point(10, 10), gfx::Point(10, 10), |
1353 ui::EF_SHIFT_DOWN, 0); | 1353 ui::EF_SHIFT_DOWN, 0); |
1354 root_->GetDispatcher()->RepostEvent(mouse_event); | 1354 root_->GetHost()->dispatcher()->RepostEvent(mouse_event); |
1355 } | 1355 } |
1356 } | 1356 } |
1357 | 1357 |
1358 private: | 1358 private: |
1359 Window* root_; | 1359 Window* root_; |
1360 int mouse_event_count_; | 1360 int mouse_event_count_; |
1361 | 1361 |
1362 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); | 1362 DISALLOW_COPY_AND_ASSIGN(DontResetHeldEventWindowDelegate); |
1363 }; | 1363 }; |
1364 | 1364 |
1365 } // namespace | 1365 } // namespace |
1366 | 1366 |
1367 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1367 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
1368 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1368 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
1369 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1369 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
1370 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1370 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
1371 // schedule another reposted event. | 1371 // schedule another reposted event. |
1372 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { | 1372 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { |
1373 DontResetHeldEventWindowDelegate delegate(root_window()); | 1373 DontResetHeldEventWindowDelegate delegate(root_window()); |
1374 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1374 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
1375 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1375 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
1376 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, | 1376 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, |
1377 gfx::Point(10, 10), gfx::Point(10, 10), | 1377 gfx::Point(10, 10), gfx::Point(10, 10), |
1378 ui::EF_SHIFT_DOWN, 0); | 1378 ui::EF_SHIFT_DOWN, 0); |
1379 root_window()->GetDispatcher()->RepostEvent(pressed); | 1379 root_window()->GetHost()->dispatcher()->RepostEvent(pressed); |
1380 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, | 1380 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, |
1381 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); | 1381 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); |
1382 // Dispatch an event to flush event scheduled by way of RepostEvent(). | 1382 // Dispatch an event to flush event scheduled by way of RepostEvent(). |
1383 DispatchEventUsingWindowDispatcher(&pressed2); | 1383 DispatchEventUsingWindowDispatcher(&pressed2); |
1384 // Delegate should have seen reposted event (identified by way of | 1384 // Delegate should have seen reposted event (identified by way of |
1385 // EF_SHIFT_DOWN). Dispatch another event to flush the second | 1385 // EF_SHIFT_DOWN). Dispatch another event to flush the second |
1386 // RepostedEvent(). | 1386 // RepostedEvent(). |
1387 EXPECT_EQ(1, delegate.mouse_event_count()); | 1387 EXPECT_EQ(1, delegate.mouse_event_count()); |
1388 DispatchEventUsingWindowDispatcher(&pressed2); | 1388 DispatchEventUsingWindowDispatcher(&pressed2); |
1389 EXPECT_EQ(2, delegate.mouse_event_count()); | 1389 EXPECT_EQ(2, delegate.mouse_event_count()); |
(...skipping 456 matching lines...) Loading... |
1846 virtual ~DispatchEventHandler() {} | 1846 virtual ~DispatchEventHandler() {} |
1847 | 1847 |
1848 bool dispatched() const { return dispatched_; } | 1848 bool dispatched() const { return dispatched_; } |
1849 private: | 1849 private: |
1850 // ui::EventHandler: | 1850 // ui::EventHandler: |
1851 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { | 1851 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { |
1852 if (mouse->type() == ui::ET_MOUSE_MOVED) { | 1852 if (mouse->type() == ui::ET_MOUSE_MOVED) { |
1853 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), | 1853 ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(), |
1854 target_->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE); | 1854 target_->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE); |
1855 ui::EventDispatchDetails details = | 1855 ui::EventDispatchDetails details = |
1856 target_->GetDispatcher()->OnEventFromSource(&move); | 1856 target_->GetHost()->dispatcher()->OnEventFromSource(&move); |
1857 ASSERT_FALSE(details.dispatcher_destroyed); | 1857 ASSERT_FALSE(details.dispatcher_destroyed); |
1858 EXPECT_FALSE(details.target_destroyed); | 1858 EXPECT_FALSE(details.target_destroyed); |
1859 EXPECT_EQ(target_, move.target()); | 1859 EXPECT_EQ(target_, move.target()); |
1860 dispatched_ = true; | 1860 dispatched_ = true; |
1861 } | 1861 } |
1862 ui::EventHandler::OnMouseEvent(mouse); | 1862 ui::EventHandler::OnMouseEvent(mouse); |
1863 } | 1863 } |
1864 | 1864 |
1865 Window* target_; | 1865 Window* target_; |
1866 bool dispatched_; | 1866 bool dispatched_; |
(...skipping 69 matching lines...) Loading... |
1936 EXPECT_TRUE(details.target_destroyed); | 1936 EXPECT_TRUE(details.target_destroyed); |
1937 EXPECT_EQ(first.get(), move.target()); | 1937 EXPECT_EQ(first.get(), move.target()); |
1938 EXPECT_TRUE(dispatch_event.dispatched()); | 1938 EXPECT_TRUE(dispatch_event.dispatched()); |
1939 EXPECT_EQ(second_root, first->GetRootWindow()); | 1939 EXPECT_EQ(second_root, first->GetRootWindow()); |
1940 | 1940 |
1941 first->RemovePreTargetHandler(&dispatch_event); | 1941 first->RemovePreTargetHandler(&dispatch_event); |
1942 second->RemovePreTargetHandler(&move_window); | 1942 second->RemovePreTargetHandler(&move_window); |
1943 } | 1943 } |
1944 | 1944 |
1945 } // namespace aura | 1945 } // namespace aura |
OLD | NEW |