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_factory.h" | |
| 16 #include "ui/base/view_prop.h" | 17 #include "ui/base/view_prop.h" |
| 17 #include "ui/compositor/dip_util.h" | 18 #include "ui/compositor/dip_util.h" |
| 18 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
| 19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/geometry/insets.h" | 21 #include "ui/gfx/geometry/insets.h" |
| 21 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
| 22 #include "ui/gfx/geometry/point3_f.h" | 23 #include "ui/gfx/geometry/point3_f.h" |
| 23 #include "ui/gfx/geometry/point_conversions.h" | 24 #include "ui/gfx/geometry/point_conversions.h" |
| 24 #include "ui/gfx/geometry/size_conversions.h" | 25 #include "ui/gfx/geometry/size_conversions.h" |
| 25 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
| 26 | 27 |
| 27 namespace aura { | 28 namespace aura { |
| 28 | 29 |
| 29 const char kWindowTreeHostForAcceleratedWidget[] = | 30 const char kWindowTreeHostForAcceleratedWidget[] = |
| 30 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; | 31 "__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__"; |
| 31 | 32 |
| 32 float GetDeviceScaleFactorFromDisplay(Window* window) { | 33 float GetDeviceScaleFactorFromDisplay(Window* window) { |
| 33 gfx::Display display = gfx::Screen::GetScreenFor(window)-> | 34 gfx::Display display = gfx::Screen::GetScreenFor(window)-> |
| 34 GetDisplayNearestWindow(window); | 35 GetDisplayNearestWindow(window); |
| 35 DCHECK(display.is_valid()); | 36 DCHECK(display.is_valid()); |
| 36 return display.device_scale_factor(); | 37 return display.device_scale_factor(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
| 40 // WindowTreeHost, public: | 41 // WindowTreeHost, public: |
| 41 | 42 |
| 42 WindowTreeHost::~WindowTreeHost() { | 43 WindowTreeHost::~WindowTreeHost() { |
| 43 DCHECK(!compositor_) << "compositor must be destroyed before root window"; | 44 DCHECK(!compositor_) << "compositor must be destroyed before root window"; |
| 45 if (owned_input_method_) { | |
| 46 delete input_method_; | |
| 47 input_method_ = NULL; | |
|
James Cook
2015/06/01 22:21:00
nullptr
Shu Chen
2015/06/02 04:11:16
Done.
| |
| 48 } | |
| 44 } | 49 } |
| 45 | 50 |
| 46 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
| 47 // static | 52 // static |
| 48 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { | 53 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
| 49 // This is only hit for tests and ash, right now these aren't an issue so | 54 // This is only hit for tests and ash, right now these aren't an issue so |
| 50 // adding the CHECK. | 55 // adding the CHECK. |
| 51 // TODO(sky): decide if we want a factory. | 56 // TODO(sky): decide if we want a factory. |
| 52 CHECK(false); | 57 CHECK(false); |
| 53 return NULL; | 58 return NULL; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 gfx::Point root_location(host_location); | 175 gfx::Point root_location(host_location); |
| 171 ConvertPointFromHost(&root_location); | 176 ConvertPointFromHost(&root_location); |
| 172 MoveCursorToInternal(root_location, host_location); | 177 MoveCursorToInternal(root_location, host_location); |
| 173 } | 178 } |
| 174 | 179 |
| 175 //////////////////////////////////////////////////////////////////////////////// | 180 //////////////////////////////////////////////////////////////////////////////// |
| 176 // WindowTreeHost, protected: | 181 // WindowTreeHost, protected: |
| 177 | 182 |
| 178 WindowTreeHost::WindowTreeHost() | 183 WindowTreeHost::WindowTreeHost() |
| 179 : window_(new Window(NULL)), | 184 : window_(new Window(NULL)), |
| 180 last_cursor_(ui::kCursorNull) { | 185 last_cursor_(ui::kCursorNull), |
| 186 input_method_(NULL), | |
| 187 owned_input_method_(false) { | |
| 188 } | |
| 189 | |
| 190 ui::InputMethod* WindowTreeHost::GetInputMethod() { | |
| 191 if (!input_method_) { | |
| 192 input_method_ = | |
| 193 ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); | |
| 194 // Makes sure the input method is focused by default when created. | |
| 195 input_method_->OnFocus(); | |
| 196 owned_input_method_ = true; | |
| 197 } | |
| 198 return input_method_; | |
| 199 }; | |
| 200 | |
| 201 void WindowTreeHost::SetInputMethod(ui::InputMethod* input_method) { | |
| 202 if (input_method_) | |
|
James Cook
2015/06/01 22:21:00
Should it be an error and/or warning to call this
Shu Chen
2015/06/02 04:11:16
Done.
| |
| 203 return; | |
| 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 CHECK(!details.dispatcher_destroyed); | |
|
Avi (use Gerrit)
2015/06/01 15:13:39
DCHECK
Shu Chen
2015/06/02 04:11:16
Done.
| |
| 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 |