IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / shell / browser / shell_aura.cc
blob0b72f9c0e53835add01e5c6c11fe1482565f3244
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 "content/shell/browser/shell.h"
7 #include "content/public/browser/web_contents.h"
8 #include "content/public/browser/web_contents_view.h"
9 #include "content/shell/browser/shell_aura.h"
10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/client/default_activation_client.h"
12 #include "ui/aura/client/default_capture_client.h"
13 #include "ui/aura/env.h"
14 #include "ui/aura/layout_manager.h"
15 #include "ui/aura/root_window.h"
16 #include "ui/aura/test/test_focus_client.h"
17 #include "ui/aura/test/test_screen.h"
18 #include "ui/aura/test/test_window_tree_client.h"
19 #include "ui/aura/window.h"
20 #include "ui/base/ime/input_method.h"
21 #include "ui/base/ime/input_method_delegate.h"
22 #include "ui/base/ime/input_method_factory.h"
23 #include "ui/gfx/screen.h"
25 namespace content {
27 namespace {
29 class FillLayout : public aura::LayoutManager {
30 public:
31 explicit FillLayout(aura::RootWindow* root)
32 : root_(root) {
35 virtual ~FillLayout() {}
37 private:
38 // aura::LayoutManager:
39 virtual void OnWindowResized() OVERRIDE {
42 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
43 child->SetBounds(gfx::Rect(root_->host()->GetBounds().size()));
46 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
49 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
52 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
53 bool visible) OVERRIDE {
56 virtual void SetChildBounds(aura::Window* child,
57 const gfx::Rect& requested_bounds) OVERRIDE {
58 SetChildBoundsDirect(child, requested_bounds);
61 aura::RootWindow* root_;
63 DISALLOW_COPY_AND_ASSIGN(FillLayout);
66 class MinimalInputEventFilter : public ui::internal::InputMethodDelegate,
67 public ui::EventHandler {
68 public:
69 explicit MinimalInputEventFilter(aura::RootWindow* root)
70 : root_(root),
71 input_method_(ui::CreateInputMethod(this,
72 gfx::kNullAcceleratedWidget)) {
73 input_method_->Init(true);
74 root_->window()->AddPreTargetHandler(this);
75 root_->window()->SetProperty(aura::client::kRootWindowInputMethodKey,
76 input_method_.get());
79 virtual ~MinimalInputEventFilter() {
80 root_->window()->RemovePreTargetHandler(this);
81 root_->window()->SetProperty(aura::client::kRootWindowInputMethodKey,
82 static_cast<ui::InputMethod*>(NULL));
85 private:
86 // ui::EventHandler:
87 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
88 const ui::EventType type = event->type();
89 if (type == ui::ET_TRANSLATED_KEY_PRESS ||
90 type == ui::ET_TRANSLATED_KEY_RELEASE) {
91 // The |event| is already handled by this object, change the type of the
92 // event to ui::ET_KEY_* and pass it to the next filter.
93 static_cast<ui::TranslatedKeyEvent*>(event)->ConvertToKeyEvent();
94 } else {
95 if (input_method_->DispatchKeyEvent(*event))
96 event->StopPropagation();
100 // ui::InputMethodDelegate:
101 virtual bool DispatchKeyEventPostIME(
102 const base::NativeEvent& event) OVERRIDE {
103 ui::TranslatedKeyEvent aura_event(event, false /* is_char */);
104 return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent(
105 &aura_event);
108 virtual bool DispatchFabricatedKeyEventPostIME(ui::EventType type,
109 ui::KeyboardCode key_code,
110 int flags) OVERRIDE {
111 ui::TranslatedKeyEvent aura_event(type == ui::ET_KEY_PRESSED, key_code,
112 flags);
113 return root_->AsWindowTreeHostDelegate()->OnHostKeyEvent(
114 &aura_event);
117 aura::RootWindow* root_;
118 scoped_ptr<ui::InputMethod> input_method_;
120 DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter);
125 ShellAuraPlatformData* Shell::platform_ = NULL;
127 ShellAuraPlatformData::ShellAuraPlatformData() {
128 aura::TestScreen* screen = aura::TestScreen::Create();
129 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen);
130 root_window_.reset(screen->CreateRootWindowForPrimaryDisplay());
131 root_window_->host()->Show();
132 root_window_->window()->SetLayoutManager(new FillLayout(root_window_.get()));
134 focus_client_.reset(new aura::test::TestFocusClient());
135 aura::client::SetFocusClient(root_window_->window(), focus_client_.get());
137 activation_client_.reset(
138 new aura::client::DefaultActivationClient(root_window_->window()));
139 capture_client_.reset(
140 new aura::client::DefaultCaptureClient(root_window_->window()));
141 window_tree_client_.reset(
142 new aura::test::TestWindowTreeClient(root_window_->window()));
143 ime_filter_.reset(new MinimalInputEventFilter(root_window_.get()));
146 ShellAuraPlatformData::~ShellAuraPlatformData() {
149 void ShellAuraPlatformData::ResizeWindow(int width, int height) {
150 root_window_->SetHostSize(gfx::Size(width, height));
153 // static
154 void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
155 CHECK(!platform_);
156 aura::Env::CreateInstance();
157 platform_ = new ShellAuraPlatformData();
160 void Shell::PlatformExit() {
161 CHECK(platform_);
162 delete platform_;
163 platform_ = NULL;
164 aura::Env::DeleteInstance();
167 void Shell::PlatformCleanUp() {
170 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {
173 void Shell::PlatformSetAddressBarURL(const GURL& url) {
176 void Shell::PlatformSetIsLoading(bool loading) {
179 void Shell::PlatformCreateWindow(int width, int height) {
180 CHECK(platform_);
181 platform_->ResizeWindow(width, height);
184 void Shell::PlatformSetContents() {
185 CHECK(platform_);
186 aura::Window* content = web_contents_->GetView()->GetNativeView();
187 aura::Window* parent = platform_->window()->window();
188 if (parent->Contains(content))
189 return;
190 parent->AddChild(content);
191 content->Show();
194 void Shell::PlatformResizeSubViews() {
197 void Shell::Close() {
198 web_contents_.reset();
201 void Shell::PlatformSetTitle(const base::string16& title) {
204 } // namespace content