OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/wm/test/wm_test_helper.h" | 5 #include "ui/wm/test/wm_test_helper.h" |
6 | 6 |
| 7 #include "base/run_loop.h" |
7 #include "ui/aura/client/default_capture_client.h" | 8 #include "ui/aura/client/default_capture_client.h" |
8 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
9 #include "ui/aura/test/test_focus_client.h" | |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 #include "ui/wm/core/compound_event_filter.h" | 11 #include "ui/wm/core/compound_event_filter.h" |
12 #include "ui/wm/core/default_activation_client.h" | 12 #include "ui/wm/core/default_activation_client.h" |
| 13 #include "ui/wm/core/default_screen_position_client.h" |
| 14 #include "ui/wm/public/dispatcher_client.h" |
| 15 |
| 16 #if defined(OS_ANDROID) && defined(USE_AURA) |
| 17 #include "ui/wm/android/android_focus_rules.h" |
| 18 #include "ui/wm/core/base_focus_rules.h" |
| 19 #include "ui/wm/core/focus_controller.h" |
| 20 #else |
| 21 #include "ui/aura/test/test_focus_client.h" |
| 22 #endif |
13 | 23 |
14 namespace wm { | 24 namespace wm { |
| 25 namespace { |
| 26 class TestDispatcherClient : public aura::client::DispatcherClient { |
| 27 public: |
| 28 TestDispatcherClient() : dispatcher_(nullptr) {} |
| 29 ~TestDispatcherClient() override {} |
| 30 |
| 31 base::MessagePumpDispatcher* dispatcher() { |
| 32 return dispatcher_; |
| 33 } |
| 34 |
| 35 // aura::client::DispatcherClient: |
| 36 void PrepareNestedLoopClosures(base::MessagePumpDispatcher* dispatcher, |
| 37 base::Closure* run_closure, |
| 38 base::Closure* quit_closure) override { |
| 39 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); |
| 40 *quit_closure = run_loop->QuitClosure(); |
| 41 *run_closure = base::Bind(&TestDispatcherClient::RunNestedDispatcher, |
| 42 base::Unretained(this), |
| 43 base::Passed(&run_loop), |
| 44 dispatcher); |
| 45 } |
| 46 |
| 47 private: |
| 48 void RunNestedDispatcher(scoped_ptr<base::RunLoop> run_loop, |
| 49 base::MessagePumpDispatcher* dispatcher) { |
| 50 base::AutoReset<base::MessagePumpDispatcher*> reset_dispatcher(&dispatcher_, |
| 51 dispatcher); |
| 52 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 53 base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 54 run_loop->Run(); |
| 55 } |
| 56 |
| 57 base::MessagePumpDispatcher* dispatcher_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(TestDispatcherClient); |
| 60 }; |
| 61 } // namespace |
| 62 |
15 | 63 |
16 WMTestHelper::WMTestHelper(const gfx::Size& default_window_size, | 64 WMTestHelper::WMTestHelper(const gfx::Size& default_window_size, |
17 ui::ContextFactory* context_factory) { | 65 ui::ContextFactory* context_factory) { |
18 aura::Env::CreateInstance(true); | 66 aura::Env::CreateInstance(true); |
19 aura::Env::GetInstance()->set_context_factory(context_factory); | 67 aura::Env::GetInstance()->set_context_factory(context_factory); |
| 68 LOG(ERROR) << "WMTestHelper ctor: context_factory=" |
| 69 << context_factory; |
| 70 |
20 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size))); | 71 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size))); |
21 host_->InitHost(); | 72 host_->InitHost(); |
| 73 host_->Show(); |
22 aura::client::SetWindowTreeClient(host_->window(), this); | 74 aura::client::SetWindowTreeClient(host_->window(), this); |
23 | 75 |
| 76 #if defined(OS_ANDROID) && defined(USE_AURA) |
| 77 AndroidFocusRules* focus_rules = new AndroidFocusRules(); |
| 78 focus_client_.reset(new FocusController(focus_rules)); |
| 79 #else |
24 focus_client_.reset(new aura::test::TestFocusClient); | 80 focus_client_.reset(new aura::test::TestFocusClient); |
| 81 #endif |
25 aura::client::SetFocusClient(host_->window(), focus_client_.get()); | 82 aura::client::SetFocusClient(host_->window(), focus_client_.get()); |
26 | 83 |
27 root_window_event_filter_.reset(new wm::CompoundEventFilter); | 84 root_window_event_filter_.reset(new wm::CompoundEventFilter); |
28 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); | 85 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); |
29 | 86 |
30 new wm::DefaultActivationClient(host_->window()); | 87 new wm::DefaultActivationClient(host_->window()); |
31 | 88 |
32 capture_client_.reset( | 89 capture_client_.reset( |
33 new aura::client::DefaultCaptureClient(host_->window())); | 90 new aura::client::DefaultCaptureClient(host_->window())); |
| 91 screen_position_client_.reset(new DefaultScreenPositionClient); |
| 92 aura::client::SetScreenPositionClient(host_->window(), |
| 93 screen_position_client_.get()); |
| 94 dispatcher_client_.reset(new TestDispatcherClient); |
| 95 aura::client::SetDispatcherClient(host_->window(), |
| 96 dispatcher_client_.get()); |
| 97 |
34 } | 98 } |
35 | 99 |
36 WMTestHelper::~WMTestHelper() { | 100 WMTestHelper::~WMTestHelper() { |
37 } | 101 } |
38 | 102 |
39 aura::Window* WMTestHelper::GetDefaultParent(aura::Window* context, | 103 aura::Window* WMTestHelper::GetDefaultParent(aura::Window* context, |
40 aura::Window* window, | 104 aura::Window* window, |
41 const gfx::Rect& bounds) { | 105 const gfx::Rect& bounds) { |
42 return host_->window(); | 106 return host_->window(); |
43 } | 107 } |
44 | 108 |
45 } // namespace wm | 109 } // namespace wm |
OLD | NEW |