Replace IdleNotification calls with IdleNotificationDeadline
[chromium-blink-merge.git] / content / shell / browser / shell_platform_data_aura.cc
blobd1ac37950390a6bb4a5af1e08e2edce2cfb62883
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"
22 namespace content {
24 namespace {
26 class FillLayout : public aura::LayoutManager {
27 public:
28 explicit FillLayout(aura::Window* root)
29 : root_(root) {
32 ~FillLayout() override {}
34 private:
35 // aura::LayoutManager:
36 void OnWindowResized() override {}
38 void OnWindowAddedToLayout(aura::Window* child) override {
39 child->SetBounds(root_->bounds());
42 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
44 void OnWindowRemovedFromLayout(aura::Window* child) override {}
46 void OnChildWindowVisibilityChanged(aura::Window* child,
47 bool visible) override {}
49 void SetChildBounds(aura::Window* child,
50 const gfx::Rect& requested_bounds) override {
51 SetChildBoundsDirect(child, requested_bounds);
54 aura::Window* root_;
56 DISALLOW_COPY_AND_ASSIGN(FillLayout);
59 class MinimalInputEventFilter : public ui::internal::InputMethodDelegate,
60 public ui::EventHandler {
61 public:
62 explicit MinimalInputEventFilter(aura::WindowTreeHost* host)
63 : host_(host),
64 input_method_(ui::CreateInputMethod(this,
65 gfx::kNullAcceleratedWidget)) {
66 input_method_->Init(true);
67 host_->window()->AddPreTargetHandler(this);
68 host_->window()->SetProperty(aura::client::kRootWindowInputMethodKey,
69 input_method_.get());
72 ~MinimalInputEventFilter() override {
73 host_->window()->RemovePreTargetHandler(this);
74 host_->window()->SetProperty(aura::client::kRootWindowInputMethodKey,
75 static_cast<ui::InputMethod*>(NULL));
78 private:
79 // ui::EventHandler:
80 void OnKeyEvent(ui::KeyEvent* event) override {
81 // See the comment in InputMethodEventFilter::OnKeyEvent() for details.
82 if (event->IsTranslated()) {
83 event->SetTranslated(false);
84 } else {
85 if (input_method_->DispatchKeyEvent(*event))
86 event->StopPropagation();
90 // ui::internal::InputMethodDelegate:
91 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override {
92 // See the comment in InputMethodEventFilter::DispatchKeyEventPostIME() for
93 // details.
94 ui::KeyEvent aura_event(event);
95 aura_event.SetTranslated(true);
96 ui::EventDispatchDetails details =
97 host_->dispatcher()->OnEventFromSource(&aura_event);
98 return aura_event.handled() || details.dispatcher_destroyed;
101 aura::WindowTreeHost* host_;
102 scoped_ptr<ui::InputMethod> input_method_;
104 DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter);
109 ShellPlatformDataAura* Shell::platform_ = NULL;
111 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
112 CHECK(aura::Env::GetInstance());
113 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(initial_size)));
114 host_->InitHost();
115 host_->window()->SetLayoutManager(new FillLayout(host_->window()));
117 focus_client_.reset(new aura::test::TestFocusClient());
118 aura::client::SetFocusClient(host_->window(), focus_client_.get());
120 new wm::DefaultActivationClient(host_->window());
121 capture_client_.reset(
122 new aura::client::DefaultCaptureClient(host_->window()));
123 window_tree_client_.reset(
124 new aura::test::TestWindowTreeClient(host_->window()));
125 ime_filter_.reset(new MinimalInputEventFilter(host_.get()));
128 ShellPlatformDataAura::~ShellPlatformDataAura() {
131 void ShellPlatformDataAura::ShowWindow() {
132 host_->Show();
135 void ShellPlatformDataAura::ResizeWindow(const gfx::Size& size) {
136 host_->SetBounds(gfx::Rect(size));
139 } // namespace content