OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/aura/window_tree_host.h" | 5 #include "ui/aura/window_tree_host.h" |
6 | 6 |
7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "ui/aura/client/capture_client.h" | 9 #include "ui/aura/client/capture_client.h" |
10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/aura/window_targeter.h" | 14 #include "ui/aura/window_targeter.h" |
15 #include "ui/aura/window_tree_host_observer.h" | 15 #include "ui/aura/window_tree_host_observer.h" |
16 #include "ui/base/ime/input_method.h" | |
17 #include "ui/base/ime/input_method_factory.h" | |
16 #include "ui/base/view_prop.h" | 18 #include "ui/base/view_prop.h" |
17 #include "ui/compositor/dip_util.h" | 19 #include "ui/compositor/dip_util.h" |
18 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
19 #include "ui/gfx/display.h" | 21 #include "ui/gfx/display.h" |
20 #include "ui/gfx/geometry/insets.h" | 22 #include "ui/gfx/geometry/insets.h" |
21 #include "ui/gfx/geometry/point.h" | 23 #include "ui/gfx/geometry/point.h" |
22 #include "ui/gfx/geometry/point3_f.h" | 24 #include "ui/gfx/geometry/point3_f.h" |
23 #include "ui/gfx/geometry/point_conversions.h" | 25 #include "ui/gfx/geometry/point_conversions.h" |
24 #include "ui/gfx/geometry/size_conversions.h" | 26 #include "ui/gfx/geometry/size_conversions.h" |
25 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
26 | 28 |
27 namespace aura { | 29 namespace aura { |
28 | 30 |
29 const char kWindowTreeHostForAcceleratedWidget[] = | 31 const char kWindowTreeHostForAcceleratedWidget[] = |
30 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; | 32 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; |
31 | 33 |
32 float GetDeviceScaleFactorFromDisplay(Window* window) { | 34 float GetDeviceScaleFactorFromDisplay(Window* window) { |
33 gfx::Display display = gfx::Screen::GetScreenFor(window)-> | 35 gfx::Display display = gfx::Screen::GetScreenFor(window)-> |
34 GetDisplayNearestWindow(window); | 36 GetDisplayNearestWindow(window); |
35 DCHECK(display.is_valid()); | 37 DCHECK(display.is_valid()); |
36 return display.device_scale_factor(); | 38 return display.device_scale_factor(); |
37 } | 39 } |
38 | 40 |
39 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
40 // WindowTreeHost, public: | 42 // WindowTreeHost, public: |
41 | 43 |
42 WindowTreeHost::~WindowTreeHost() { | 44 WindowTreeHost::~WindowTreeHost() { |
43 DCHECK(!compositor_) << "compositor must be destroyed before root window"; | 45 DCHECK(!compositor_) << "compositor must be destroyed before root window"; |
46 if (owned_input_method_) { | |
47 delete input_method_; | |
48 input_method_ = nullptr; | |
49 } | |
44 } | 50 } |
45 | 51 |
46 #if defined(OS_ANDROID) | 52 #if defined(OS_ANDROID) |
47 // static | 53 // static |
48 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | 54 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
49 // This is only hit for tests and ash, right now these aren't an issue so | 55 // This is only hit for tests and ash, right now these aren't an issue so |
50 // adding the CHECK. | 56 // adding the CHECK. |
51 // TODO(sky): decide if we want a factory. | 57 // TODO(sky): decide if we want a factory. |
52 CHECK(false); | 58 CHECK(false); |
53 return NULL; | 59 return nullptr; |
54 } | 60 } |
55 #endif | 61 #endif |
56 | 62 |
57 // static | 63 // static |
58 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( | 64 WindowTreeHost* WindowTreeHost::GetForAcceleratedWidget( |
59 gfx::AcceleratedWidget widget) { | 65 gfx::AcceleratedWidget widget) { |
60 return reinterpret_cast<WindowTreeHost*>( | 66 return reinterpret_cast<WindowTreeHost*>( |
61 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); | 67 ui::ViewProp::GetValue(widget, kWindowTreeHostForAcceleratedWidget)); |
62 } | 68 } |
63 | 69 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 ConvertPointToHost(&host_location); | 171 ConvertPointToHost(&host_location); |
166 MoveCursorToInternal(location_in_dip, host_location); | 172 MoveCursorToInternal(location_in_dip, host_location); |
167 } | 173 } |
168 | 174 |
169 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { | 175 void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { |
170 gfx::Point root_location(host_location); | 176 gfx::Point root_location(host_location); |
171 ConvertPointFromHost(&root_location); | 177 ConvertPointFromHost(&root_location); |
172 MoveCursorToInternal(root_location, host_location); | 178 MoveCursorToInternal(root_location, host_location); |
173 } | 179 } |
174 | 180 |
181 ui::InputMethod* WindowTreeHost::GetInputMethod() { | |
182 if (!input_method_) { | |
183 input_method_ = | |
184 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); | |
185 // Makes sure the input method is focused by default when created, because | |
186 // some environment doesn't have activated/focused state in WindowTreeHost. | |
187 // TODO(shuchen): move this to DisplayController so it's only for Ash. | |
188 input_method_->OnFocus(); | |
189 owned_input_method_ = true; | |
190 } | |
191 return input_method_; | |
192 } | |
193 | |
194 void WindowTreeHost::SetInputMethod(ui::InputMethod* input_method) { | |
195 DCHECK(!input_method_); | |
196 input_method_ = input_method; | |
197 owned_input_method_ = false; | |
198 } | |
199 | |
200 bool WindowTreeHost::DispatchKeyEventPostIME(const ui::KeyEvent& event) { | |
sadrul
2015/06/08 22:45:12
Not for this CL, but would it be possible for Disp
Shu Chen
2015/06/09 02:28:49
The caller of InputMethod::DispatchKeyEvent() want
sadrul
2015/06/09 15:29:32
You could send a pointer to the KeyEvent in Dispat
Shu Chen
2015/06/10 03:01:35
Actually I meant "InputMethod can intercept the ke
| |
201 ui::KeyEvent copied_event(event); | |
202 ui::EventDispatchDetails details = | |
203 event_processor()->OnEventFromSource(&copied_event); | |
204 DCHECK(!details.dispatcher_destroyed); | |
205 return copied_event.handled(); | |
206 } | |
207 | |
175 void WindowTreeHost::Show() { | 208 void WindowTreeHost::Show() { |
176 if (compositor()) | 209 if (compositor()) |
177 compositor()->SetVisible(true); | 210 compositor()->SetVisible(true); |
178 ShowImpl(); | 211 ShowImpl(); |
179 } | 212 } |
180 | 213 |
181 void WindowTreeHost::Hide() { | 214 void WindowTreeHost::Hide() { |
182 HideImpl(); | 215 HideImpl(); |
183 if (compositor()) | 216 if (compositor()) |
184 compositor()->SetVisible(false); | 217 compositor()->SetVisible(false); |
185 } | 218 } |
186 | 219 |
187 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
188 // WindowTreeHost, protected: | 221 // WindowTreeHost, protected: |
189 | 222 |
190 WindowTreeHost::WindowTreeHost() | 223 WindowTreeHost::WindowTreeHost() |
191 : window_(new Window(NULL)), | 224 : window_(new Window(nullptr)), |
192 last_cursor_(ui::kCursorNull) { | 225 last_cursor_(ui::kCursorNull), |
226 input_method_(nullptr), | |
227 owned_input_method_(false) { | |
193 } | 228 } |
194 | 229 |
195 void WindowTreeHost::DestroyCompositor() { | 230 void WindowTreeHost::DestroyCompositor() { |
196 compositor_.reset(); | 231 compositor_.reset(); |
197 } | 232 } |
198 | 233 |
199 void WindowTreeHost::DestroyDispatcher() { | 234 void WindowTreeHost::DestroyDispatcher() { |
200 delete window_; | 235 delete window_; |
201 window_ = NULL; | 236 window_ = nullptr; |
202 dispatcher_.reset(); | 237 dispatcher_.reset(); |
203 | 238 |
204 // TODO(beng): this comment is no longer quite valid since this function | 239 // TODO(beng): this comment is no longer quite valid since this function |
205 // isn't called from WED, and WED isn't a subclass of Window. So it seems | 240 // isn't called from WED, and WED isn't a subclass of Window. So it seems |
206 // like we could just rely on ~Window now. | 241 // like we could just rely on ~Window now. |
207 // Destroy child windows while we're still valid. This is also done by | 242 // Destroy child windows while we're still valid. This is also done by |
208 // ~Window, but by that time any calls to virtual methods overriden here (such | 243 // ~Window, but by that time any calls to virtual methods overriden here (such |
209 // as GetRootWindow()) result in Window's implementation. By destroying here | 244 // as GetRootWindow()) result in Window's implementation. By destroying here |
210 // we ensure GetRootWindow() still returns this. | 245 // we ensure GetRootWindow() still returns this. |
211 //window()->RemoveOrDestroyChildren(); | 246 //window()->RemoveOrDestroyChildren(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 void WindowTreeHost::OnHostActivated() { | 299 void WindowTreeHost::OnHostActivated() { |
265 Env::GetInstance()->NotifyHostActivated(this); | 300 Env::GetInstance()->NotifyHostActivated(this); |
266 } | 301 } |
267 | 302 |
268 void WindowTreeHost::OnHostLostWindowCapture() { | 303 void WindowTreeHost::OnHostLostWindowCapture() { |
269 Window* capture_window = client::GetCaptureWindow(window()); | 304 Window* capture_window = client::GetCaptureWindow(window()); |
270 if (capture_window && capture_window->GetRootWindow() == window()) | 305 if (capture_window && capture_window->GetRootWindow() == window()) |
271 capture_window->ReleaseCapture(); | 306 capture_window->ReleaseCapture(); |
272 } | 307 } |
273 | 308 |
309 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { | |
310 return event_processor(); | |
311 } | |
312 | |
313 ui::EventDispatchDetails WindowTreeHost::DeliverEventToProcessor( | |
314 ui::Event* event) { | |
315 if (event->IsKeyEvent()) { | |
316 if (GetInputMethod()->DispatchKeyEvent( | |
317 *static_cast<ui::KeyEvent*>(event))) { | |
318 event->StopPropagation(); | |
319 return ui::EventDispatchDetails(); | |
320 } | |
321 } | |
322 return ui::EventSource::DeliverEventToProcessor(event); | |
323 } | |
324 | |
274 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
275 // WindowTreeHost, private: | 326 // WindowTreeHost, private: |
276 | 327 |
277 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, | 328 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, |
278 const gfx::Point& host_location) { | 329 const gfx::Point& host_location) { |
279 last_cursor_request_position_in_host_ = host_location; | 330 last_cursor_request_position_in_host_ = host_location; |
280 MoveCursorToNative(host_location); | 331 MoveCursorToNative(host_location); |
281 client::CursorClient* cursor_client = client::GetCursorClient(window()); | 332 client::CursorClient* cursor_client = client::GetCursorClient(window()); |
282 if (cursor_client) { | 333 if (cursor_client) { |
283 const gfx::Display& display = | 334 const gfx::Display& display = |
284 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); | 335 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); |
285 cursor_client->SetDisplay(display); | 336 cursor_client->SetDisplay(display); |
286 } | 337 } |
287 dispatcher()->OnCursorMovedToRootLocation(root_location); | 338 dispatcher()->OnCursorMovedToRootLocation(root_location); |
288 } | 339 } |
289 | 340 |
290 } // namespace aura | 341 } // namespace aura |
OLD | NEW |