| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/desktop.h" | 9 #include "ui/aura/desktop.h" |
| 10 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
| 11 #include "ui/aura/test/aura_test_base.h" | 11 #include "ui/aura/test/aura_test_base.h" |
| 12 #include "ui/aura/test/event_generator.h" | 12 #include "ui/aura/test/event_generator.h" |
| 13 #include "ui/aura/test/test_event_filter.h" |
| 13 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 14 | 15 |
| 15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 16 // Windows headers define macros for these function names which screw with us. | 17 // Windows headers define macros for these function names which screw with us. |
| 17 #if defined(CreateWindow) | 18 #if defined(CreateWindow) |
| 18 #undef CreateWindow | 19 #undef CreateWindow |
| 19 #endif | 20 #endif |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 namespace aura { | 23 namespace aura { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { | 68 Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { |
| 68 Window* window = new Window(delegate ? delegate : new TestWindowDelegate); | 69 Window* window = new Window(delegate ? delegate : new TestWindowDelegate); |
| 69 window->set_id(id); | 70 window->set_id(id); |
| 70 window->Init(ui::Layer::LAYER_HAS_TEXTURE); | 71 window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| 71 window->SetParent(parent); | 72 window->SetParent(parent); |
| 72 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 73 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 73 window->Show(); | 74 window->Show(); |
| 74 return window; | 75 return window; |
| 75 } | 76 } |
| 76 | 77 |
| 77 class TestEventFilter : public EventFilter { | |
| 78 public: | |
| 79 explicit TestEventFilter(Window* owner) | |
| 80 : EventFilter(owner), | |
| 81 key_event_count_(0), | |
| 82 mouse_event_count_(0), | |
| 83 touch_event_count_(0), | |
| 84 consumes_key_events_(false), | |
| 85 consumes_mouse_events_(false), | |
| 86 consumes_touch_events_(false) { | |
| 87 } | |
| 88 virtual ~TestEventFilter() {} | |
| 89 | |
| 90 void ResetCounts() { | |
| 91 key_event_count_ = 0; | |
| 92 mouse_event_count_ = 0; | |
| 93 touch_event_count_ = 0; | |
| 94 } | |
| 95 | |
| 96 int key_event_count() const { return key_event_count_; } | |
| 97 int mouse_event_count() const { return mouse_event_count_; } | |
| 98 int touch_event_count() const { return touch_event_count_; } | |
| 99 | |
| 100 void set_consumes_key_events(bool consumes_key_events) { | |
| 101 consumes_key_events_ = consumes_key_events; | |
| 102 } | |
| 103 void set_consumes_mouse_events(bool consumes_mouse_events) { | |
| 104 consumes_mouse_events_ = consumes_mouse_events; | |
| 105 } | |
| 106 void set_consumes_touch_events(bool consumes_touch_events) { | |
| 107 consumes_touch_events_ = consumes_touch_events; | |
| 108 } | |
| 109 | |
| 110 // Overridden from EventFilter: | |
| 111 virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE { | |
| 112 ++key_event_count_; | |
| 113 return consumes_key_events_; | |
| 114 } | |
| 115 virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE { | |
| 116 ++mouse_event_count_; | |
| 117 return consumes_mouse_events_; | |
| 118 } | |
| 119 virtual ui::TouchStatus PreHandleTouchEvent(Window* target, | |
| 120 TouchEvent* event) OVERRIDE { | |
| 121 ++touch_event_count_; | |
| 122 // TODO(sadrul): ! | |
| 123 return ui::TOUCH_STATUS_UNKNOWN; | |
| 124 } | |
| 125 | |
| 126 private: | |
| 127 int key_event_count_; | |
| 128 int mouse_event_count_; | |
| 129 int touch_event_count_; | |
| 130 | |
| 131 bool consumes_key_events_; | |
| 132 bool consumes_mouse_events_; | |
| 133 bool consumes_touch_events_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(TestEventFilter); | |
| 136 }; | |
| 137 | |
| 138 // Creates this hierarchy: | 78 // Creates this hierarchy: |
| 139 // | 79 // |
| 140 // Desktop Window (EF) | 80 // Desktop Window (EF) |
| 141 // +- w1 (EF) | 81 // +- w1 (EF) |
| 142 // +- w11 | 82 // +- w11 |
| 143 // +- w111 (EF) | 83 // +- w111 (EF) |
| 144 // +- w1111 <-- target window | 84 // +- w1111 <-- target window |
| 145 TEST_F(EventFilterTest, Basic) { | 85 TEST_F(EventFilterTest, Basic) { |
| 146 scoped_ptr<Window> w1(CreateWindow(1, Desktop::GetInstance(), NULL)); | 86 scoped_ptr<Window> w1(CreateWindow(1, Desktop::GetInstance(), NULL)); |
| 147 scoped_ptr<Window> w11(CreateWindow(11, w1.get(), NULL)); | 87 scoped_ptr<Window> w11(CreateWindow(11, w1.get(), NULL)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 EXPECT_EQ(0, w111_filter->mouse_event_count()); | 141 EXPECT_EQ(0, w111_filter->mouse_event_count()); |
| 202 EXPECT_EQ(0, d1111->mouse_event_count()); | 142 EXPECT_EQ(0, d1111->mouse_event_count()); |
| 203 EXPECT_EQ(0, desktop_filter->touch_event_count()); | 143 EXPECT_EQ(0, desktop_filter->touch_event_count()); |
| 204 EXPECT_EQ(0, w1_filter->touch_event_count()); | 144 EXPECT_EQ(0, w1_filter->touch_event_count()); |
| 205 EXPECT_EQ(0, w111_filter->touch_event_count()); | 145 EXPECT_EQ(0, w111_filter->touch_event_count()); |
| 206 EXPECT_EQ(0, d1111->touch_event_count()); | 146 EXPECT_EQ(0, d1111->touch_event_count()); |
| 207 } | 147 } |
| 208 | 148 |
| 209 } // namespace test | 149 } // namespace test |
| 210 } // namespace aura | 150 } // namespace aura |
| OLD | NEW |