Index: ui/aura/window_tree_host_x11_unittest.cc |
diff --git a/ui/aura/window_tree_host_x11_unittest.cc b/ui/aura/window_tree_host_x11_unittest.cc |
index 0deb034af47d6bfae1bff60d97c882b6e759dc9c..c1e55796f57e0cb4881319e67c2111649c69a75a 100644 |
--- a/ui/aura/window_tree_host_x11_unittest.cc |
+++ b/ui/aura/window_tree_host_x11_unittest.cc |
@@ -6,8 +6,8 @@ |
#include "base/sys_info.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "ui/aura/test/aura_test_base.h" |
-#include "ui/aura/window.h" |
#include "ui/aura/window_event_dispatcher.h" |
+#include "ui/aura/window_tree_host_delegate.h" |
#include "ui/aura/window_tree_host_x11.h" |
#include "ui/events/event_processor.h" |
#include "ui/events/event_target.h" |
@@ -15,14 +15,37 @@ |
#include "ui/events/test/events_test_utils_x11.h" |
namespace { |
- |
-class RootWindowEventHandler : public ui::EventHandler { |
+class TestWindowTreeHostDelegate : public aura::WindowTreeHostDelegate, |
+ public ui::EventProcessor, |
+ public ui::EventTarget { |
public: |
- RootWindowEventHandler() : last_touch_type_(ui::ET_UNKNOWN), |
- last_touch_id_(-1), |
- last_touch_location_(0, 0) { |
- } |
- virtual ~RootWindowEventHandler () {} |
+ TestWindowTreeHostDelegate() : last_touch_type_(ui::ET_UNKNOWN), |
+ last_touch_id_(-1), |
+ last_touch_location_(0, 0) { |
+ } |
+ virtual ~TestWindowTreeHostDelegate() {} |
+ |
+ // aura::WindowTreeHostDelegate: |
+ virtual void OnHostCancelMode() OVERRIDE {} |
+ virtual void OnHostActivated() OVERRIDE {} |
+ virtual void OnHostLostWindowCapture() OVERRIDE {} |
+ virtual void OnHostLostMouseGrab() OVERRIDE {} |
+ virtual void OnHostResized(const gfx::Size& size) OVERRIDE {} |
+ virtual void OnCursorMovedToRootLocation( |
+ const gfx::Point& root_location) OVERRIDE {} |
+ virtual aura::WindowEventDispatcher* AsDispatcher() OVERRIDE { return NULL; } |
+ virtual const aura::WindowEventDispatcher* AsDispatcher() const OVERRIDE { |
+ return NULL; |
+ } |
+ virtual ui::EventProcessor* GetEventProcessor() OVERRIDE { |
+ return this; |
+ } |
+ |
+ // ui::EventProcessor: |
+ virtual ui::EventTarget* GetRootTarget() OVERRIDE { return this; } |
+ virtual bool CanDispatchToTarget(ui::EventTarget* target) OVERRIDE { |
+ return true; |
+ } |
// ui::EventHandler: |
virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
@@ -31,6 +54,17 @@ |
last_touch_location_ = event->location(); |
} |
+ // ui::EventTarget: |
+ virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE { |
+ return true; |
+ } |
+ virtual ui::EventTarget* GetParentTarget() OVERRIDE { return NULL; } |
+ virtual scoped_ptr<ui::EventTargetIterator> |
+ GetChildIterator() const OVERRIDE { |
+ return scoped_ptr<ui::EventTargetIterator>(); |
+ } |
+ virtual ui::EventTargeter* GetEventTargeter() OVERRIDE { return &targeter_; } |
+ |
ui::EventType last_touch_type() { |
return last_touch_type_; |
} |
@@ -47,8 +81,9 @@ |
ui::EventType last_touch_type_; |
int last_touch_id_; |
gfx::Point last_touch_location_; |
- |
- DISALLOW_COPY_AND_ASSIGN(RootWindowEventHandler); |
+ ui::EventTargeter targeter_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostDelegate); |
}; |
} // namespace |
@@ -69,17 +104,17 @@ |
scoped_ptr<WindowTreeHostX11> window_tree_host( |
new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); |
- window_tree_host->InitHost(); |
- scoped_ptr<RootWindowEventHandler> handler(new RootWindowEventHandler()); |
- window_tree_host->window()->AddPreTargetHandler(handler.get()); |
+ scoped_ptr<TestWindowTreeHostDelegate> delegate( |
+ new TestWindowTreeHostDelegate()); |
+ window_tree_host->set_delegate(delegate.get()); |
std::vector<unsigned int> devices; |
devices.push_back(0); |
ui::SetUpTouchDevicesForTest(devices); |
std::vector<ui::Valuator> valuators; |
- EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); |
- EXPECT_EQ(-1, handler->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate->last_touch_type()); |
+ EXPECT_EQ(-1, delegate->last_touch_id()); |
ui::ScopedXI2Event scoped_xevent; |
#if defined(OS_CHROMEOS) |
@@ -87,32 +122,32 @@ |
scoped_xevent.InitTouchEvent( |
0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators); |
window_tree_host->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); |
- EXPECT_EQ(-1, handler->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler->last_touch_location()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate->last_touch_type()); |
+ EXPECT_EQ(-1, delegate->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate->last_touch_location()); |
#endif // defined(OS_CHROMEOS) |
// Following touchs are within bounds and are passed to delegate. |
scoped_xevent.InitTouchEvent( |
0, XI_TouchBegin, 5, gfx::Point(1500, 1500), valuators); |
window_tree_host->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler->last_touch_type()); |
- EXPECT_EQ(0, handler->last_touch_id()); |
- EXPECT_EQ(gfx::Point(1500, 1500), handler->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, delegate->last_touch_type()); |
+ EXPECT_EQ(0, delegate->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(1500, 1500), delegate->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchUpdate, 5, gfx::Point(1500, 1600), valuators); |
window_tree_host->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_TOUCH_MOVED, handler->last_touch_type()); |
- EXPECT_EQ(0, handler->last_touch_id()); |
- EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, delegate->last_touch_type()); |
+ EXPECT_EQ(0, delegate->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(1500, 1600), delegate->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchEnd, 5, gfx::Point(1500, 1600), valuators); |
window_tree_host->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler->last_touch_type()); |
- EXPECT_EQ(0, handler->last_touch_id()); |
- EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, delegate->last_touch_type()); |
+ EXPECT_EQ(0, delegate->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(1500, 1600), delegate->last_touch_location()); |
// Revert the CrOS testing env otherwise the following non-CrOS aura |
// tests will fail. |
@@ -134,26 +169,26 @@ |
scoped_ptr<WindowTreeHostX11> window_tree_host1( |
new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); |
- window_tree_host1->InitHost(); |
- scoped_ptr<RootWindowEventHandler> handler1(new RootWindowEventHandler()); |
- window_tree_host1->window()->AddPreTargetHandler(handler1.get()); |
+ scoped_ptr<TestWindowTreeHostDelegate> delegate1( |
+ new TestWindowTreeHostDelegate()); |
+ window_tree_host1->set_delegate(delegate1.get()); |
int host2_y_offset = 1700; |
scoped_ptr<WindowTreeHostX11> window_tree_host2( |
new WindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080))); |
- window_tree_host2->InitHost(); |
- scoped_ptr<RootWindowEventHandler> handler2(new RootWindowEventHandler()); |
- window_tree_host2->window()->AddPreTargetHandler(handler2.get()); |
+ scoped_ptr<TestWindowTreeHostDelegate> delegate2( |
+ new TestWindowTreeHostDelegate()); |
+ window_tree_host2->set_delegate(delegate2.get()); |
std::vector<unsigned int> devices; |
devices.push_back(0); |
ui::SetUpTouchDevicesForTest(devices); |
std::vector<ui::Valuator> valuators; |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler2->last_touch_type()); |
- EXPECT_EQ(-1, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate2->last_touch_type()); |
+ EXPECT_EQ(-1, delegate2->last_touch_id()); |
// 2 Touch events are targeted at the second WindowTreeHost. |
ui::ScopedXI2Event scoped_xevent; |
@@ -161,73 +196,73 @@ |
0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators); |
window_tree_host1->Dispatch(scoped_xevent); |
window_tree_host2->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); |
- EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler2->last_touch_type()); |
- EXPECT_EQ(0, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, delegate2->last_touch_type()); |
+ EXPECT_EQ(0, delegate2->last_touch_id()); |
EXPECT_EQ(gfx::Point(1500, 2500 - host2_y_offset), |
- handler2->last_touch_location()); |
+ delegate2->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchBegin, 6, gfx::Point(1600, 2600), valuators); |
window_tree_host1->Dispatch(scoped_xevent); |
window_tree_host2->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); |
- EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler2->last_touch_type()); |
- EXPECT_EQ(1, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_PRESSED, delegate2->last_touch_type()); |
+ EXPECT_EQ(1, delegate2->last_touch_id()); |
EXPECT_EQ(gfx::Point(1600, 2600 - host2_y_offset), |
- handler2->last_touch_location()); |
+ delegate2->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchUpdate, 5, gfx::Point(1500, 2550), valuators); |
window_tree_host1->Dispatch(scoped_xevent); |
window_tree_host2->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); |
- EXPECT_EQ(ui::ET_TOUCH_MOVED, handler2->last_touch_type()); |
- EXPECT_EQ(0, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, delegate2->last_touch_type()); |
+ EXPECT_EQ(0, delegate2->last_touch_id()); |
EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset), |
- handler2->last_touch_location()); |
+ delegate2->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchUpdate, 6, gfx::Point(1600, 2650), valuators); |
window_tree_host1->Dispatch(scoped_xevent); |
window_tree_host2->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); |
- EXPECT_EQ(ui::ET_TOUCH_MOVED, handler2->last_touch_type()); |
- EXPECT_EQ(1, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_MOVED, delegate2->last_touch_type()); |
+ EXPECT_EQ(1, delegate2->last_touch_id()); |
EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset), |
- handler2->last_touch_location()); |
+ delegate2->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchEnd, 5, gfx::Point(1500, 2550), valuators); |
window_tree_host1->Dispatch(scoped_xevent); |
window_tree_host2->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); |
- EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type()); |
- EXPECT_EQ(0, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, delegate2->last_touch_type()); |
+ EXPECT_EQ(0, delegate2->last_touch_id()); |
EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset), |
- handler2->last_touch_location()); |
+ delegate2->last_touch_location()); |
scoped_xevent.InitTouchEvent( |
0, XI_TouchEnd, 6, gfx::Point(1600, 2650), valuators); |
window_tree_host1->Dispatch(scoped_xevent); |
window_tree_host2->Dispatch(scoped_xevent); |
- EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); |
- EXPECT_EQ(-1, handler1->last_touch_id()); |
- EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); |
- EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type()); |
- EXPECT_EQ(1, handler2->last_touch_id()); |
+ EXPECT_EQ(ui::ET_UNKNOWN, delegate1->last_touch_type()); |
+ EXPECT_EQ(-1, delegate1->last_touch_id()); |
+ EXPECT_EQ(gfx::Point(0, 0), delegate1->last_touch_location()); |
+ EXPECT_EQ(ui::ET_TOUCH_RELEASED, delegate2->last_touch_type()); |
+ EXPECT_EQ(1, delegate2->last_touch_id()); |
EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset), |
- handler2->last_touch_location()); |
+ delegate2->last_touch_location()); |
// Revert the CrOS testing env otherwise the following non-CrOS aura |
// tests will fail. |