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
3 // found in the LICENSE file.
5 #include "ui/wm/test/wm_test_helper.h"
7 #include "ui/aura/client/default_activation_client.h"
8 #include "ui/aura/client/default_capture_client.h"
9 #include "ui/aura/env.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/aura/test/test_focus_client.h"
12 #include "ui/views/corewm/compound_event_filter.h"
13 #include "ui/views/corewm/input_method_event_filter.h"
17 WMTestHelper::WMTestHelper(const gfx::Size& default_window_size) {
18 aura::Env::CreateInstance();
19 root_window_.reset(new aura::RootWindow(
20 aura::RootWindow::CreateParams(
21 gfx::Rect(default_window_size))));
22 root_window_->host()->InitHost();
23 aura::client::SetWindowTreeClient(root_window_->window(), this);
25 focus_client_.reset(new aura::test::TestFocusClient);
26 aura::client::SetFocusClient(root_window_->window(), focus_client_.get());
28 root_window_event_filter_ = new views::corewm::CompoundEventFilter;
29 // Pass ownership of the filter to the root_window.
30 root_window_->window()->SetEventFilter(root_window_event_filter_);
32 input_method_filter_.reset(new views::corewm::InputMethodEventFilter(
33 root_window_->host()->GetAcceleratedWidget()));
34 input_method_filter_->SetInputMethodPropertyInRootWindow(
35 root_window_->window());
36 root_window_event_filter_->AddHandler(input_method_filter_.get());
38 activation_client_.reset(
39 new aura::client::DefaultActivationClient(root_window_->window()));
41 capture_client_.reset(
42 new aura::client::DefaultCaptureClient(root_window_->window()));
45 WMTestHelper::~WMTestHelper() {
46 root_window_event_filter_->RemoveHandler(input_method_filter_.get());
49 aura::Window* WMTestHelper::GetDefaultParent(aura::Window* context,
51 const gfx::Rect& bounds) {
52 return root_window_->window();