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/event_filter.h" | 5 #include "ui/aura/event_filter.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "ui/aura/event.h" | |
10 #include "ui/aura/focus_manager.h" | 9 #include "ui/aura/focus_manager.h" |
11 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
12 #include "ui/aura/test/aura_test_base.h" | 11 #include "ui/aura/test/aura_test_base.h" |
13 #include "ui/aura/test/event_generator.h" | 12 #include "ui/aura/test/event_generator.h" |
14 #include "ui/aura/test/test_event_filter.h" | 13 #include "ui/aura/test/test_event_filter.h" |
15 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 15 #include "ui/base/event.h" |
16 | 16 |
17 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
18 // Windows headers define macros for these function names which screw with us. | 18 // Windows headers define macros for these function names which screw with us. |
19 #if defined(CreateWindow) | 19 #if defined(CreateWindow) |
20 #undef CreateWindow | 20 #undef CreateWindow |
21 #endif | 21 #endif |
22 #endif | 22 #endif |
23 | 23 |
24 namespace aura { | 24 namespace aura { |
25 namespace test { | 25 namespace test { |
(...skipping 12 matching lines...) Expand all Loading... |
38 key_event_count_ = 0; | 38 key_event_count_ = 0; |
39 mouse_event_count_ = 0; | 39 mouse_event_count_ = 0; |
40 touch_event_count_ = 0; | 40 touch_event_count_ = 0; |
41 } | 41 } |
42 | 42 |
43 int key_event_count() const { return key_event_count_; } | 43 int key_event_count() const { return key_event_count_; } |
44 int mouse_event_count() const { return mouse_event_count_; } | 44 int mouse_event_count() const { return mouse_event_count_; } |
45 int touch_event_count() const { return touch_event_count_; } | 45 int touch_event_count() const { return touch_event_count_; } |
46 | 46 |
47 // Overridden from TestWindowDelegate: | 47 // Overridden from TestWindowDelegate: |
48 virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE { | 48 virtual bool OnKeyEvent(ui::KeyEvent* event) OVERRIDE { |
49 ++key_event_count_; | 49 ++key_event_count_; |
50 return true; | 50 return true; |
51 } | 51 } |
52 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { | 52 virtual bool OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
53 ++mouse_event_count_; | 53 ++mouse_event_count_; |
54 return true; | 54 return true; |
55 } | 55 } |
56 virtual ui::TouchStatus OnTouchEvent(TouchEvent* event) OVERRIDE { | 56 virtual ui::TouchStatus OnTouchEvent(ui::TouchEventImpl* event) OVERRIDE { |
57 ++touch_event_count_; | 57 ++touch_event_count_; |
58 return ui::TOUCH_STATUS_UNKNOWN; | 58 return ui::TOUCH_STATUS_UNKNOWN; |
59 } | 59 } |
60 virtual ui::GestureStatus OnGestureEvent(GestureEvent* event) OVERRIDE { | 60 virtual ui::GestureStatus OnGestureEvent( |
| 61 ui::GestureEventImpl* event) OVERRIDE { |
61 return ui::GESTURE_STATUS_UNKNOWN; | 62 return ui::GESTURE_STATUS_UNKNOWN; |
62 } | 63 } |
63 | 64 |
64 private: | 65 private: |
65 int key_event_count_; | 66 int key_event_count_; |
66 int mouse_event_count_; | 67 int mouse_event_count_; |
67 int touch_event_count_; | 68 int touch_event_count_; |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(TestEventFilterWindowDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(TestEventFilterWindowDelegate); |
70 }; | 71 }; |
(...skipping 28 matching lines...) Expand all Loading... |
99 root_window()->SetEventFilter(root_window_filter); | 100 root_window()->SetEventFilter(root_window_filter); |
100 w1->SetEventFilter(w1_filter); | 101 w1->SetEventFilter(w1_filter); |
101 w111->SetEventFilter(w111_filter); | 102 w111->SetEventFilter(w111_filter); |
102 | 103 |
103 w1111->GetFocusManager()->SetFocusedWindow(w1111.get(), NULL); | 104 w1111->GetFocusManager()->SetFocusedWindow(w1111.get(), NULL); |
104 | 105 |
105 // To start with, no one is going to consume any events. All three filters | 106 // To start with, no one is going to consume any events. All three filters |
106 // and the w1111's delegate should receive the event. | 107 // and the w1111's delegate should receive the event. |
107 EventGenerator generator(root_window(), w1111.get()); | 108 EventGenerator generator(root_window(), w1111.get()); |
108 generator.PressLeftButton(); | 109 generator.PressLeftButton(); |
109 KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 110 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
110 root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); | 111 root_window()->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); |
111 | 112 |
112 // TODO(sadrul): TouchEvent! | 113 // TODO(sadrul): TouchEvent! |
113 EXPECT_EQ(1, root_window_filter->key_event_count()); | 114 EXPECT_EQ(1, root_window_filter->key_event_count()); |
114 EXPECT_EQ(1, w1_filter->key_event_count()); | 115 EXPECT_EQ(1, w1_filter->key_event_count()); |
115 EXPECT_EQ(1, w111_filter->key_event_count()); | 116 EXPECT_EQ(1, w111_filter->key_event_count()); |
116 EXPECT_EQ(1, d1111->key_event_count()); | 117 EXPECT_EQ(1, d1111->key_event_count()); |
117 EXPECT_EQ(1, root_window_filter->mouse_event_count()); | 118 EXPECT_EQ(1, root_window_filter->mouse_event_count()); |
118 EXPECT_EQ(1, w1_filter->mouse_event_count()); | 119 EXPECT_EQ(1, w1_filter->mouse_event_count()); |
119 EXPECT_EQ(1, w111_filter->mouse_event_count()); | 120 EXPECT_EQ(1, w111_filter->mouse_event_count()); |
(...skipping 25 matching lines...) Expand all Loading... |
145 EXPECT_EQ(0, w111_filter->mouse_event_count()); | 146 EXPECT_EQ(0, w111_filter->mouse_event_count()); |
146 EXPECT_EQ(0, d1111->mouse_event_count()); | 147 EXPECT_EQ(0, d1111->mouse_event_count()); |
147 EXPECT_EQ(0, root_window_filter->touch_event_count()); | 148 EXPECT_EQ(0, root_window_filter->touch_event_count()); |
148 EXPECT_EQ(0, w1_filter->touch_event_count()); | 149 EXPECT_EQ(0, w1_filter->touch_event_count()); |
149 EXPECT_EQ(0, w111_filter->touch_event_count()); | 150 EXPECT_EQ(0, w111_filter->touch_event_count()); |
150 EXPECT_EQ(0, d1111->touch_event_count()); | 151 EXPECT_EQ(0, d1111->touch_event_count()); |
151 } | 152 } |
152 | 153 |
153 } // namespace test | 154 } // namespace test |
154 } // namespace aura | 155 } // namespace aura |
OLD | NEW |