1 // Copyright 2014 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 "content/shell/browser/shell_platform_data_aura.h"
7 #include "content/shell/browser/shell.h"
8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/default_capture_client.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/layout_manager.h"
12 #include "ui/aura/test/test_focus_client.h"
13 #include "ui/aura/test/test_window_tree_client.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/base/ime/input_method.h"
17 #include "ui/base/ime/input_method_delegate.h"
18 #include "ui/base/ime/input_method_factory.h"
19 #include "ui/gfx/screen.h"
20 #include "ui/wm/core/default_activation_client.h"
26 class FillLayout
: public aura::LayoutManager
{
28 explicit FillLayout(aura::Window
* root
)
32 virtual ~FillLayout() {}
35 // aura::LayoutManager:
36 virtual void OnWindowResized() OVERRIDE
{
39 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
{
40 child
->SetBounds(root_
->bounds());
43 virtual void OnWillRemoveWindowFromLayout(aura::Window
* child
) OVERRIDE
{
46 virtual void OnWindowRemovedFromLayout(aura::Window
* child
) OVERRIDE
{
49 virtual void OnChildWindowVisibilityChanged(aura::Window
* child
,
50 bool visible
) OVERRIDE
{
53 virtual void SetChildBounds(aura::Window
* child
,
54 const gfx::Rect
& requested_bounds
) OVERRIDE
{
55 SetChildBoundsDirect(child
, requested_bounds
);
60 DISALLOW_COPY_AND_ASSIGN(FillLayout
);
63 class MinimalInputEventFilter
: public ui::internal::InputMethodDelegate
,
64 public ui::EventHandler
{
66 explicit MinimalInputEventFilter(aura::WindowTreeHost
* host
)
68 input_method_(ui::CreateInputMethod(this,
69 gfx::kNullAcceleratedWidget
)) {
70 input_method_
->Init(true);
71 host_
->window()->AddPreTargetHandler(this);
72 host_
->window()->SetProperty(aura::client::kRootWindowInputMethodKey
,
76 virtual ~MinimalInputEventFilter() {
77 host_
->window()->RemovePreTargetHandler(this);
78 host_
->window()->SetProperty(aura::client::kRootWindowInputMethodKey
,
79 static_cast<ui::InputMethod
*>(NULL
));
84 virtual void OnKeyEvent(ui::KeyEvent
* event
) OVERRIDE
{
85 // See the comment in InputMethodEventFilter::OnKeyEvent() for details.
86 if (event
->IsTranslated()) {
87 event
->SetTranslated(false);
89 if (input_method_
->DispatchKeyEvent(*event
))
90 event
->StopPropagation();
94 // ui::internal::InputMethodDelegate:
95 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent
& event
) OVERRIDE
{
96 // See the comment in InputMethodEventFilter::DispatchKeyEventPostIME() for
98 ui::KeyEvent
aura_event(event
);
99 aura_event
.SetTranslated(true);
100 ui::EventDispatchDetails details
=
101 host_
->dispatcher()->OnEventFromSource(&aura_event
);
102 return aura_event
.handled() || details
.dispatcher_destroyed
;
105 aura::WindowTreeHost
* host_
;
106 scoped_ptr
<ui::InputMethod
> input_method_
;
108 DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter
);
113 ShellPlatformDataAura
* Shell::platform_
= NULL
;
115 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size
& initial_size
) {
116 CHECK(aura::Env::GetInstance());
117 host_
.reset(aura::WindowTreeHost::Create(gfx::Rect(initial_size
)));
119 host_
->window()->SetLayoutManager(new FillLayout(host_
->window()));
121 focus_client_
.reset(new aura::test::TestFocusClient());
122 aura::client::SetFocusClient(host_
->window(), focus_client_
.get());
124 new wm::DefaultActivationClient(host_
->window());
125 capture_client_
.reset(
126 new aura::client::DefaultCaptureClient(host_
->window()));
127 window_tree_client_
.reset(
128 new aura::test::TestWindowTreeClient(host_
->window()));
129 ime_filter_
.reset(new MinimalInputEventFilter(host_
.get()));
132 ShellPlatformDataAura::~ShellPlatformDataAura() {
135 void ShellPlatformDataAura::ShowWindow() {
139 void ShellPlatformDataAura::ResizeWindow(const gfx::Size
& size
) {
140 host_
->SetBounds(gfx::Rect(size
));
143 } // namespace content