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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 gfx::Point mouse_event_location_; | 62 gfx::Point mouse_event_location_; |
63 int mouse_event_flags_; | 63 int mouse_event_flags_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate); | 65 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate); |
66 }; | 66 }; |
67 | 67 |
68 // A simple EventFilter that keeps track of the number of key events that it's | 68 // A simple EventFilter that keeps track of the number of key events that it's |
69 // seen. | 69 // seen. |
70 class EventCountFilter : public EventFilter { | 70 class EventCountFilter : public EventFilter { |
71 public: | 71 public: |
72 EventCountFilter() : num_key_events_(0), num_mouse_events_(0) {} | 72 EventCountFilter() |
| 73 : num_key_events_(0), |
| 74 num_mouse_events_(0), |
| 75 num_touch_events_(0) { |
| 76 } |
73 virtual ~EventCountFilter() {} | 77 virtual ~EventCountFilter() {} |
74 | 78 |
75 int num_key_events() const { return num_key_events_; } | 79 int num_key_events() const { return num_key_events_; } |
76 int num_mouse_events() const { return num_mouse_events_; } | 80 int num_mouse_events() const { return num_mouse_events_; } |
| 81 int num_touch_events() const { return num_touch_events_; } |
77 | 82 |
78 void Reset() { | 83 void Reset() { |
79 num_key_events_ = 0; | 84 num_key_events_ = 0; |
80 num_mouse_events_ = 0; | 85 num_mouse_events_ = 0; |
81 } | 86 } |
82 | 87 |
83 // EventFilter overrides: | 88 // EventFilter overrides: |
84 virtual bool PreHandleKeyEvent(Window* target, ui::KeyEvent* event) OVERRIDE { | 89 virtual bool PreHandleKeyEvent(Window* target, ui::KeyEvent* event) OVERRIDE { |
85 num_key_events_++; | 90 num_key_events_++; |
86 return true; | 91 return true; |
87 } | 92 } |
88 virtual bool PreHandleMouseEvent(Window* target, | 93 virtual bool PreHandleMouseEvent(Window* target, |
89 ui::MouseEvent* event) OVERRIDE { | 94 ui::MouseEvent* event) OVERRIDE { |
90 num_mouse_events_++; | 95 num_mouse_events_++; |
91 return true; | 96 return true; |
92 } | 97 } |
93 virtual ui::TouchStatus PreHandleTouchEvent( | 98 virtual ui::TouchStatus PreHandleTouchEvent( |
94 Window* target, ui::TouchEvent* event) OVERRIDE { | 99 Window* target, ui::TouchEvent* event) OVERRIDE { |
| 100 num_touch_events_++; |
95 return ui::TOUCH_STATUS_UNKNOWN; | 101 return ui::TOUCH_STATUS_UNKNOWN; |
96 } | 102 } |
97 virtual ui::GestureStatus PreHandleGestureEvent( | 103 virtual ui::GestureStatus PreHandleGestureEvent( |
98 Window* target, ui::GestureEvent* event) OVERRIDE { | 104 Window* target, ui::GestureEvent* event) OVERRIDE { |
99 return ui::GESTURE_STATUS_UNKNOWN; | 105 return ui::GESTURE_STATUS_UNKNOWN; |
100 } | 106 } |
101 | 107 |
102 private: | 108 private: |
103 // How many key events have been received? | 109 // How many key events have been received? |
104 int num_key_events_; | 110 int num_key_events_; |
105 | 111 |
106 // How many mouse events have been received? | 112 // How many mouse events have been received? |
107 int num_mouse_events_; | 113 int num_mouse_events_; |
108 | 114 |
| 115 int num_touch_events_; |
| 116 |
109 DISALLOW_COPY_AND_ASSIGN(EventCountFilter); | 117 DISALLOW_COPY_AND_ASSIGN(EventCountFilter); |
110 }; | 118 }; |
111 | 119 |
112 } // namespace | 120 } // namespace |
113 | 121 |
114 typedef test::AuraTestBase RootWindowTest; | 122 typedef test::AuraTestBase RootWindowTest; |
115 | 123 |
116 TEST_F(RootWindowTest, OnHostMouseEvent) { | 124 TEST_F(RootWindowTest, OnHostMouseEvent) { |
117 // Create two non-overlapping windows so we don't have to worry about which | 125 // Create two non-overlapping windows so we don't have to worry about which |
118 // is on top. | 126 // is on top. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 EXPECT_FALSE(root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent( | 346 EXPECT_FALSE(root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent( |
339 &unknown_event)); | 347 &unknown_event)); |
340 EXPECT_EQ(0, filter->num_key_events()); | 348 EXPECT_EQ(0, filter->num_key_events()); |
341 | 349 |
342 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 350 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
343 EXPECT_TRUE(root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent( | 351 EXPECT_TRUE(root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent( |
344 &known_event)); | 352 &known_event)); |
345 EXPECT_EQ(1, filter->num_key_events()); | 353 EXPECT_EQ(1, filter->num_key_events()); |
346 } | 354 } |
347 | 355 |
| 356 // Tests that touch-events that are beyond the bounds of the root-window do get |
| 357 // propagated to the event filters correctly with the root as the target. |
| 358 TEST_F(RootWindowTest, TouchEventsOutsideBounds) { |
| 359 EventCountFilter* filter = new EventCountFilter; |
| 360 root_window()->SetEventFilter(filter); // passes ownership |
| 361 |
| 362 gfx::Point position = root_window()->bounds().origin(); |
| 363 position.Offset(-10, -10); |
| 364 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); |
| 365 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
| 366 EXPECT_EQ(1, filter->num_touch_events()); |
| 367 |
| 368 position = root_window()->bounds().origin(); |
| 369 position.Offset(root_window()->bounds().width() + 10, |
| 370 root_window()->bounds().height() + 10); |
| 371 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); |
| 372 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
| 373 EXPECT_EQ(2, filter->num_touch_events()); |
| 374 } |
| 375 |
348 namespace { | 376 namespace { |
349 | 377 |
350 // FilterFilter that tracks the types of events it's seen. | 378 // FilterFilter that tracks the types of events it's seen. |
351 class EventFilterRecorder : public EventFilter { | 379 class EventFilterRecorder : public EventFilter { |
352 public: | 380 public: |
353 typedef std::vector<ui::EventType> Events; | 381 typedef std::vector<ui::EventType> Events; |
354 | 382 |
355 EventFilterRecorder() {} | 383 EventFilterRecorder() {} |
356 | 384 |
357 Events& events() { return events_; } | 385 Events& events() { return events_; } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 root_window()->ReleaseMouseMoves(); | 566 root_window()->ReleaseMouseMoves(); |
539 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 567 root_window()->AsRootWindowHostDelegate()->OnHostMouseEvent( |
540 &mouse_dragged_event2); | 568 &mouse_dragged_event2); |
541 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); | 569 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); |
542 filter->events().clear(); | 570 filter->events().clear(); |
543 RunAllPendingInMessageLoop(); | 571 RunAllPendingInMessageLoop(); |
544 EXPECT_TRUE(filter->events().empty()); | 572 EXPECT_TRUE(filter->events().empty()); |
545 } | 573 } |
546 | 574 |
547 } // namespace aura | 575 } // namespace aura |
OLD | NEW |