Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: content/shell/browser/shell_platform_data_aura.cc

Issue 1155013005: Refactoring the ownership of ui::InputMethod. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pls be green! Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/default_capture_client.h" 9 #include "ui/aura/client/default_capture_client.h"
10 #include "ui/aura/env.h" 10 #include "ui/aura/env.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 void SetChildBounds(aura::Window* child, 49 void SetChildBounds(aura::Window* child,
50 const gfx::Rect& requested_bounds) override { 50 const gfx::Rect& requested_bounds) override {
51 SetChildBoundsDirect(child, requested_bounds); 51 SetChildBoundsDirect(child, requested_bounds);
52 } 52 }
53 53
54 aura::Window* root_; 54 aura::Window* root_;
55 55
56 DISALLOW_COPY_AND_ASSIGN(FillLayout); 56 DISALLOW_COPY_AND_ASSIGN(FillLayout);
57 }; 57 };
58 58
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 } 59 }
108 60
109 ShellPlatformDataAura* Shell::platform_ = NULL; 61 ShellPlatformDataAura* Shell::platform_ = NULL;
110 62
111 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) { 63 ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
112 CHECK(aura::Env::GetInstance()); 64 CHECK(aura::Env::GetInstance());
113 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(initial_size))); 65 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(initial_size)));
114 host_->InitHost(); 66 host_->InitHost();
115 host_->window()->SetLayoutManager(new FillLayout(host_->window())); 67 host_->window()->SetLayoutManager(new FillLayout(host_->window()));
116 68
117 focus_client_.reset(new aura::test::TestFocusClient()); 69 focus_client_.reset(new aura::test::TestFocusClient());
118 aura::client::SetFocusClient(host_->window(), focus_client_.get()); 70 aura::client::SetFocusClient(host_->window(), focus_client_.get());
119 71
120 new wm::DefaultActivationClient(host_->window()); 72 new wm::DefaultActivationClient(host_->window());
121 capture_client_.reset( 73 capture_client_.reset(
122 new aura::client::DefaultCaptureClient(host_->window())); 74 new aura::client::DefaultCaptureClient(host_->window()));
123 window_tree_client_.reset( 75 window_tree_client_.reset(
124 new aura::test::TestWindowTreeClient(host_->window())); 76 new aura::test::TestWindowTreeClient(host_->window()));
125 ime_filter_.reset(new MinimalInputEventFilter(host_.get()));
126 } 77 }
127 78
128 ShellPlatformDataAura::~ShellPlatformDataAura() { 79 ShellPlatformDataAura::~ShellPlatformDataAura() {
129 } 80 }
130 81
131 void ShellPlatformDataAura::ShowWindow() { 82 void ShellPlatformDataAura::ShowWindow() {
132 host_->Show(); 83 host_->Show();
133 } 84 }
134 85
135 void ShellPlatformDataAura::ResizeWindow(const gfx::Size& size) { 86 void ShellPlatformDataAura::ResizeWindow(const gfx::Size& size) {
136 host_->SetBounds(gfx::Rect(size)); 87 host_->SetBounds(gfx::Rect(size));
137 } 88 }
138 89
139 } // namespace content 90 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698