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_activation_client.h"
10 #include "ui/aura/client/default_capture_client.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/layout_manager.h"
13 #include "ui/aura/root_window.h"
14 #include "ui/aura/test/test_focus_client.h"
15 #include "ui/aura/test/test_window_tree_client.h"
16 #include "ui/aura/window.h"
17 #include "ui/base/ime/input_method.h"
18 #include "ui/base/ime/input_method_delegate.h"
19 #include "ui/base/ime/input_method_factory.h"
20 #include "ui/gfx/screen.h"
26 class FillLayout
: public aura::LayoutManager
{
28 explicit FillLayout(aura::RootWindow
* root
)
32 virtual ~FillLayout() {}
35 // aura::LayoutManager:
36 virtual void OnWindowResized() OVERRIDE
{
39 virtual void OnWindowAddedToLayout(aura::Window
* child
) OVERRIDE
{
40 child
->SetBounds(root_
->window()->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
);
58 aura::RootWindow
* root_
;
60 DISALLOW_COPY_AND_ASSIGN(FillLayout
);
63 class MinimalInputEventFilter
: public ui::internal::InputMethodDelegate
,
64 public ui::EventHandler
{
66 explicit MinimalInputEventFilter(aura::RootWindow
* root
)
68 input_method_(ui::CreateInputMethod(this,
69 gfx::kNullAcceleratedWidget
)) {
70 input_method_
->Init(true);
71 root_
->window()->AddPreTargetHandler(this);
72 root_
->window()->SetProperty(aura::client::kRootWindowInputMethodKey
,
76 virtual ~MinimalInputEventFilter() {
77 root_
->window()->RemovePreTargetHandler(this);
78 root_
->window()->SetProperty(aura::client::kRootWindowInputMethodKey
,
79 static_cast<ui::InputMethod
*>(NULL
));
84 virtual void OnKeyEvent(ui::KeyEvent
* event
) OVERRIDE
{
85 const ui::EventType type
= event
->type();
86 if (type
== ui::ET_TRANSLATED_KEY_PRESS
||
87 type
== ui::ET_TRANSLATED_KEY_RELEASE
) {
88 // The |event| is already handled by this object, change the type of the
89 // event to ui::ET_KEY_* and pass it to the next filter.
90 static_cast<ui::TranslatedKeyEvent
*>(event
)->ConvertToKeyEvent();
92 if (input_method_
->DispatchKeyEvent(*event
))
93 event
->StopPropagation();
97 // ui::internal::InputMethodDelegate:
98 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent
& event
) OVERRIDE
{
99 ui::TranslatedKeyEvent
aura_event(event
);
100 ui::EventDispatchDetails details
= root_
->OnEventFromSource(&aura_event
);
101 return aura_event
.handled() || details
.dispatcher_destroyed
;
104 aura::RootWindow
* root_
;
105 scoped_ptr
<ui::InputMethod
> input_method_
;
107 DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter
);
112 ShellPlatformDataAura
* Shell::platform_
= NULL
;
114 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size
& initial_size
) {
115 aura::Env::CreateInstance();
116 root_window_
.reset(new aura::RootWindow(
117 aura::RootWindow::CreateParams(gfx::Rect(initial_size
))));
118 root_window_
->Init();
119 root_window_
->window()->SetLayoutManager(new FillLayout(root_window_
.get()));
121 focus_client_
.reset(new aura::test::TestFocusClient());
122 aura::client::SetFocusClient(root_window_
->window(), focus_client_
.get());
124 activation_client_
.reset(
125 new aura::client::DefaultActivationClient(root_window_
->window()));
126 capture_client_
.reset(
127 new aura::client::DefaultCaptureClient(root_window_
->window()));
128 window_tree_client_
.reset(
129 new aura::test::TestWindowTreeClient(root_window_
->window()));
130 ime_filter_
.reset(new MinimalInputEventFilter(root_window_
.get()));
133 ShellPlatformDataAura::~ShellPlatformDataAura() {
136 void ShellPlatformDataAura::ShowWindow() {
137 root_window_
->host()->Show();
140 void ShellPlatformDataAura::ResizeWindow(const gfx::Size
& size
) {
141 root_window_
->host()->SetBounds(gfx::Rect(size
));
146 } // namespace content