Chromium Code Reviews| 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 NULL; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 175 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
| 176 // WindowTreeHost, protected: | 182 // WindowTreeHost, protected: |
| 177 | 183 |
| 178 WindowTreeHost::WindowTreeHost() | 184 WindowTreeHost::WindowTreeHost() |
| 179 : window_(new Window(NULL)), | 185 : window_(new Window(NULL)), |
| 180 last_cursor_(ui::kCursorNull) { | 186 last_cursor_(ui::kCursorNull), |
| 187 input_method_(NULL), | |
|
James Su
2015/06/03 06:41:16
nullptr?
Shu Chen
2015/06/03 07:29:57
Done.
| |
| 188 owned_input_method_(false) { | |
| 189 } | |
| 190 | |
| 191 ui::InputMethod* WindowTreeHost::GetInputMethod() { | |
| 192 if (!input_method_) { | |
| 193 input_method_ = | |
| 194 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); | |
| 195 // Makes sure the input method is focused by default when created. | |
| 196 input_method_->OnFocus(); | |
| 197 owned_input_method_ = true; | |
| 198 } | |
| 199 return input_method_; | |
| 200 }; | |
| 201 | |
| 202 void WindowTreeHost::SetInputMethod(ui::InputMethod* input_method) { | |
| 203 DCHECK(!input_method_); | |
| 204 input_method_ = input_method; | |
| 205 owned_input_method_ = false; | |
| 181 } | 206 } |
| 182 | 207 |
| 183 void WindowTreeHost::DestroyCompositor() { | 208 void WindowTreeHost::DestroyCompositor() { |
| 184 compositor_.reset(); | 209 compositor_.reset(); |
| 185 } | 210 } |
| 186 | 211 |
| 187 void WindowTreeHost::DestroyDispatcher() { | 212 void WindowTreeHost::DestroyDispatcher() { |
| 188 delete window_; | 213 delete window_; |
| 189 window_ = NULL; | 214 window_ = NULL; |
| 190 dispatcher_.reset(); | 215 dispatcher_.reset(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 void WindowTreeHost::OnHostActivated() { | 277 void WindowTreeHost::OnHostActivated() { |
| 253 Env::GetInstance()->NotifyHostActivated(this); | 278 Env::GetInstance()->NotifyHostActivated(this); |
| 254 } | 279 } |
| 255 | 280 |
| 256 void WindowTreeHost::OnHostLostWindowCapture() { | 281 void WindowTreeHost::OnHostLostWindowCapture() { |
| 257 Window* capture_window = client::GetCaptureWindow(window()); | 282 Window* capture_window = client::GetCaptureWindow(window()); |
| 258 if (capture_window && capture_window->GetRootWindow() == window()) | 283 if (capture_window && capture_window->GetRootWindow() == window()) |
| 259 capture_window->ReleaseCapture(); | 284 capture_window->ReleaseCapture(); |
| 260 } | 285 } |
| 261 | 286 |
| 287 bool WindowTreeHost::DispatchKeyEventPostIME(const ui::KeyEvent& event) { | |
| 288 ui::KeyEvent copied_event(event); | |
| 289 ui::EventDispatchDetails details = | |
| 290 event_processor()->OnEventFromSource(&copied_event); | |
| 291 DCHECK(!details.dispatcher_destroyed); | |
| 292 return copied_event.handled(); | |
| 293 } | |
| 294 | |
| 295 ui::EventProcessor* WindowTreeHost::GetEventProcessor() { | |
| 296 return event_processor(); | |
| 297 } | |
| 298 | |
| 299 ui::EventDispatchDetails WindowTreeHost::DeliverEventToProcessor( | |
| 300 ui::Event* event) { | |
| 301 if (event->IsKeyEvent()) { | |
| 302 if (GetInputMethod()->DispatchKeyEvent( | |
| 303 *static_cast<ui::KeyEvent*>(event))) { | |
| 304 event->StopPropagation(); | |
| 305 return ui::EventDispatchDetails(); | |
| 306 } | |
| 307 } | |
| 308 return ui::EventSource::DeliverEventToProcessor(event); | |
| 309 } | |
| 310 | |
| 262 //////////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////////// |
| 263 // WindowTreeHost, private: | 312 // WindowTreeHost, private: |
| 264 | 313 |
| 265 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, | 314 void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, |
| 266 const gfx::Point& host_location) { | 315 const gfx::Point& host_location) { |
| 267 last_cursor_request_position_in_host_ = host_location; | 316 last_cursor_request_position_in_host_ = host_location; |
| 268 MoveCursorToNative(host_location); | 317 MoveCursorToNative(host_location); |
| 269 client::CursorClient* cursor_client = client::GetCursorClient(window()); | 318 client::CursorClient* cursor_client = client::GetCursorClient(window()); |
| 270 if (cursor_client) { | 319 if (cursor_client) { |
| 271 const gfx::Display& display = | 320 const gfx::Display& display = |
| 272 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); | 321 gfx::Screen::GetScreenFor(window())->GetDisplayNearestWindow(window()); |
| 273 cursor_client->SetDisplay(display); | 322 cursor_client->SetDisplay(display); |
| 274 } | 323 } |
| 275 dispatcher()->OnCursorMovedToRootLocation(root_location); | 324 dispatcher()->OnCursorMovedToRootLocation(root_location); |
| 276 } | 325 } |
| 277 | 326 |
| 278 } // namespace aura | 327 } // namespace aura |
| OLD | NEW |