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/root_window.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/client/event_client.h" | 10 #include "ui/aura/client/event_client.h" |
11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
12 #include "ui/aura/focus_manager.h" | 12 #include "ui/aura/focus_manager.h" |
13 #include "ui/aura/test/aura_test_base.h" | 13 #include "ui/aura/test/aura_test_base.h" |
14 #include "ui/aura/test/event_generator.h" | 14 #include "ui/aura/test/event_generator.h" |
15 #include "ui/aura/test/test_event_handler.h" | 15 #include "ui/aura/test/test_event_handler.h" |
16 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
17 #include "ui/aura/test/test_windows.h" | 17 #include "ui/aura/test/test_windows.h" |
18 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
19 #include "ui/base/events/event.h" | 19 #include "ui/base/events/event.h" |
20 #include "ui/base/events/event_handler.h" | 20 #include "ui/base/events/event_handler.h" |
| 21 #include "ui/base/events/event_utils.h" |
21 #include "ui/base/gestures/gesture_configuration.h" | 22 #include "ui/base/gestures/gesture_configuration.h" |
22 #include "ui/base/hit_test.h" | 23 #include "ui/base/hit_test.h" |
23 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
24 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
25 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 // Windows headers define macros for these function names which screw with us. | 30 // Windows headers define macros for these function names which screw with us. |
30 #if defined(CreateWindow) | 31 #if defined(CreateWindow) |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 position = root_window()->bounds().origin(); | 364 position = root_window()->bounds().origin(); |
364 position.Offset(root_window()->bounds().width() + 10, | 365 position.Offset(root_window()->bounds().width() + 10, |
365 root_window()->bounds().height() + 10); | 366 root_window()->bounds().height() + 10); |
366 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); | 367 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); |
367 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 368 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
368 EXPECT_EQ(2, filter->num_touch_events()); | 369 EXPECT_EQ(2, filter->num_touch_events()); |
369 } | 370 } |
370 | 371 |
371 // Tests that scroll events are dispatched correctly. | 372 // Tests that scroll events are dispatched correctly. |
372 TEST_F(RootWindowTest, ScrollEventDispatch) { | 373 TEST_F(RootWindowTest, ScrollEventDispatch) { |
| 374 base::TimeDelta now = ui::EventTimeForNow(); |
373 test::TestEventHandler* filter = new test::TestEventHandler; | 375 test::TestEventHandler* filter = new test::TestEventHandler; |
374 root_window()->SetEventFilter(filter); | 376 root_window()->SetEventFilter(filter); |
375 | 377 |
376 test::TestWindowDelegate delegate; | 378 test::TestWindowDelegate delegate; |
377 scoped_ptr<Window> w1(CreateWindow(1, root_window(), &delegate)); | 379 scoped_ptr<Window> w1(CreateWindow(1, root_window(), &delegate)); |
378 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); | 380 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); |
379 | 381 |
380 // A scroll event on the root-window itself is not dispatched. | 382 // A scroll event on the root-window itself is dispatched. |
381 ui::ScrollEvent scroll1(ui::ET_SCROLL, gfx::Point(10, 10), 0, 0, -10); | 383 ui::ScrollEvent scroll1(ui::ET_SCROLL, gfx::Point(10, 10), now, 0, 0, -10, 2); |
382 root_window()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll1); | 384 root_window()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll1); |
383 EXPECT_EQ(0, filter->num_scroll_events()); | 385 EXPECT_EQ(1, filter->num_scroll_events()); |
384 | 386 |
385 // Scroll event on a window should be dispatched properly. | 387 // Scroll event on a window should be dispatched properly. |
386 ui::ScrollEvent scroll2(ui::ET_SCROLL, gfx::Point(25, 30), 0, -10, 0); | 388 ui::ScrollEvent scroll2(ui::ET_SCROLL, gfx::Point(25, 30), now, 0, -10, 0, 2); |
387 root_window()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll2); | 389 root_window()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll2); |
388 EXPECT_EQ(1, filter->num_scroll_events()); | 390 EXPECT_EQ(2, filter->num_scroll_events()); |
389 } | 391 } |
390 | 392 |
391 namespace { | 393 namespace { |
392 | 394 |
393 // FilterFilter that tracks the types of events it's seen. | 395 // FilterFilter that tracks the types of events it's seen. |
394 class EventFilterRecorder : public ui::EventHandler { | 396 class EventFilterRecorder : public ui::EventHandler { |
395 public: | 397 public: |
396 typedef std::vector<ui::EventType> Events; | 398 typedef std::vector<ui::EventType> Events; |
397 | 399 |
398 EventFilterRecorder() {} | 400 EventFilterRecorder() {} |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { | 723 TEST_F(RootWindowTest, GestureRecognizerResetsTargetWhenParentHides) { |
722 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); | 724 scoped_ptr<Window> w1(CreateWindow(1, root_window(), NULL)); |
723 DetachesParentOnTapDelegate delegate; | 725 DetachesParentOnTapDelegate delegate; |
724 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); | 726 scoped_ptr<Window> parent(CreateWindow(22, w1.get(), NULL)); |
725 Window* child = CreateWindow(11, parent.get(), &delegate); | 727 Window* child = CreateWindow(11, parent.get(), &delegate); |
726 test::EventGenerator generator(root_window(), child); | 728 test::EventGenerator generator(root_window(), child); |
727 generator.GestureTapAt(gfx::Point(40, 40)); | 729 generator.GestureTapAt(gfx::Point(40, 40)); |
728 } | 730 } |
729 | 731 |
730 } // namespace aura | 732 } // namespace aura |
OLD | NEW |