| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/browser/shell_platform_data_aura.h" | 5 #include "content/shell/browser/shell_platform_data_aura.h" |
| 6 | 6 |
| 7 #include "content/shell/browser/shell.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" | 8 #include "ui/aura/client/default_capture_client.h" |
| 10 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
| 11 #include "ui/aura/layout_manager.h" | 10 #include "ui/aura/layout_manager.h" |
| 12 #include "ui/aura/test/test_focus_client.h" | 11 #include "ui/aura/test/test_focus_client.h" |
| 13 #include "ui/aura/test/test_window_tree_client.h" | 12 #include "ui/aura/test/test_window_tree_client.h" |
| 14 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 16 #include "ui/base/ime/input_method.h" | 15 #include "ui/base/ime/input_method.h" |
| 17 #include "ui/base/ime/input_method_delegate.h" | 16 #include "ui/base/ime/input_method_delegate.h" |
| 18 #include "ui/base/ime/input_method_factory.h" | 17 #include "ui/base/ime/input_method_factory.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 49 void SetChildBounds(aura::Window* child, | 48 void SetChildBounds(aura::Window* child, |
| 50 const gfx::Rect& requested_bounds) override { | 49 const gfx::Rect& requested_bounds) override { |
| 51 SetChildBoundsDirect(child, requested_bounds); | 50 SetChildBoundsDirect(child, requested_bounds); |
| 52 } | 51 } |
| 53 | 52 |
| 54 aura::Window* root_; | 53 aura::Window* root_; |
| 55 | 54 |
| 56 DISALLOW_COPY_AND_ASSIGN(FillLayout); | 55 DISALLOW_COPY_AND_ASSIGN(FillLayout); |
| 57 }; | 56 }; |
| 58 | 57 |
| 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_->OnFocus(); | |
| 67 host_->window()->AddPreTargetHandler(this); | |
| 68 host_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, | |
| 69 input_method_.get()); | |
| 70 } | |
| 71 | |
| 72 ~MinimalInputEventFilter() override { | |
| 73 host_->window()->RemovePreTargetHandler(this); | |
| 74 host_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, | |
| 75 static_cast<ui::InputMethod*>(NULL)); | |
| 76 } | |
| 77 | |
| 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(); | |
| 87 } | |
| 88 } | |
| 89 | |
| 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; | |
| 99 } | |
| 100 | |
| 101 aura::WindowTreeHost* host_; | |
| 102 scoped_ptr<ui::InputMethod> input_method_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter); | |
| 105 }; | |
| 106 | |
| 107 } | 58 } |
| 108 | 59 |
| 109 ShellPlatformDataAura* Shell::platform_ = NULL; | 60 ShellPlatformDataAura* Shell::platform_ = NULL; |
| 110 | 61 |
| 111 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) { | 62 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) { |
| 112 CHECK(aura::Env::GetInstance()); | 63 CHECK(aura::Env::GetInstance()); |
| 113 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(initial_size))); | 64 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(initial_size))); |
| 114 host_->InitHost(); | 65 host_->InitHost(); |
| 115 host_->window()->SetLayoutManager(new FillLayout(host_->window())); | 66 host_->window()->SetLayoutManager(new FillLayout(host_->window())); |
| 116 | 67 |
| 117 focus_client_.reset(new aura::test::TestFocusClient()); | 68 focus_client_.reset(new aura::test::TestFocusClient()); |
| 118 aura::client::SetFocusClient(host_->window(), focus_client_.get()); | 69 aura::client::SetFocusClient(host_->window(), focus_client_.get()); |
| 119 | 70 |
| 120 new wm::DefaultActivationClient(host_->window()); | 71 new wm::DefaultActivationClient(host_->window()); |
| 121 capture_client_.reset( | 72 capture_client_.reset( |
| 122 new aura::client::DefaultCaptureClient(host_->window())); | 73 new aura::client::DefaultCaptureClient(host_->window())); |
| 123 window_tree_client_.reset( | 74 window_tree_client_.reset( |
| 124 new aura::test::TestWindowTreeClient(host_->window())); | 75 new aura::test::TestWindowTreeClient(host_->window())); |
| 125 ime_filter_.reset(new MinimalInputEventFilter(host_.get())); | |
| 126 } | 76 } |
| 127 | 77 |
| 128 ShellPlatformDataAura::~ShellPlatformDataAura() { | 78 ShellPlatformDataAura::~ShellPlatformDataAura() { |
| 129 } | 79 } |
| 130 | 80 |
| 131 void ShellPlatformDataAura::ShowWindow() { | 81 void ShellPlatformDataAura::ShowWindow() { |
| 132 host_->Show(); | 82 host_->Show(); |
| 133 } | 83 } |
| 134 | 84 |
| 135 void ShellPlatformDataAura::ResizeWindow(const gfx::Size& size) { | 85 void ShellPlatformDataAura::ResizeWindow(const gfx::Size& size) { |
| 136 host_->SetBounds(gfx::Rect(size)); | 86 host_->SetBounds(gfx::Rect(size)); |
| 137 } | 87 } |
| 138 | 88 |
| 139 } // namespace content | 89 } // namespace content |
| OLD | NEW |