| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/ws/window_tree_host_impl.h" | 5 #include "components/mus/ws/window_tree_host_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/public/interfaces/input_event_constants.mojom.h" |
| 10 #include "components/mus/ws/connection_manager.h" | 11 #include "components/mus/ws/connection_manager.h" |
| 11 #include "components/mus/ws/display_manager.h" | 12 #include "components/mus/ws/display_manager.h" |
| 12 #include "components/mus/ws/focus_controller.h" | 13 #include "components/mus/ws/focus_controller.h" |
| 13 #include "components/mus/ws/window_tree_host_delegate.h" | 14 #include "components/mus/ws/window_tree_host_delegate.h" |
| 14 #include "components/mus/ws/window_tree_impl.h" | 15 #include "components/mus/ws/window_tree_impl.h" |
| 15 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
| 16 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 17 | 18 |
| 18 namespace mus { | 19 namespace mus { |
| 19 namespace ws { | 20 namespace ws { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 36 const scoped_refptr<GpuState>& gpu_state, | 37 const scoped_refptr<GpuState>& gpu_state, |
| 37 const scoped_refptr<SurfacesState>& surfaces_state, | 38 const scoped_refptr<SurfacesState>& surfaces_state, |
| 38 mojom::WindowManagerPtr window_manager) | 39 mojom::WindowManagerPtr window_manager) |
| 39 : delegate_(nullptr), | 40 : delegate_(nullptr), |
| 40 connection_manager_(connection_manager), | 41 connection_manager_(connection_manager), |
| 41 client_(client.Pass()), | 42 client_(client.Pass()), |
| 42 event_dispatcher_(this), | 43 event_dispatcher_(this), |
| 43 display_manager_( | 44 display_manager_( |
| 44 DisplayManager::Create(app_impl, gpu_state, surfaces_state)), | 45 DisplayManager::Create(app_impl, gpu_state, surfaces_state)), |
| 45 window_manager_(window_manager.Pass()), | 46 window_manager_(window_manager.Pass()), |
| 46 tree_awaiting_input_ack_(nullptr) { | 47 tree_awaiting_input_ack_(nullptr), |
| 48 last_cursor_(0) { |
| 47 display_manager_->Init(this); | 49 display_manager_->Init(this); |
| 48 if (client_) { | 50 if (client_) { |
| 49 client_.set_connection_error_handler(base::Bind( | 51 client_.set_connection_error_handler(base::Bind( |
| 50 &WindowTreeHostImpl::OnClientClosed, base::Unretained(this))); | 52 &WindowTreeHostImpl::OnClientClosed, base::Unretained(this))); |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 | 55 |
| 54 WindowTreeHostImpl::~WindowTreeHostImpl() { | 56 WindowTreeHostImpl::~WindowTreeHostImpl() { |
| 55 DestroyFocusController(); | 57 DestroyFocusController(); |
| 56 for (ServerWindow* window : windows_needing_frame_destruction_) | 58 for (ServerWindow* window : windows_needing_frame_destruction_) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 display_manager_->UpdateTextInputState(state); | 126 display_manager_->UpdateTextInputState(state); |
| 125 } | 127 } |
| 126 | 128 |
| 127 void WindowTreeHostImpl::SetImeVisibility(ServerWindow* window, bool visible) { | 129 void WindowTreeHostImpl::SetImeVisibility(ServerWindow* window, bool visible) { |
| 128 // Do not need to show or hide IME for unfocused window. | 130 // Do not need to show or hide IME for unfocused window. |
| 129 if (focus_controller_->GetFocusedWindow() != window) | 131 if (focus_controller_->GetFocusedWindow() != window) |
| 130 return; | 132 return; |
| 131 display_manager_->SetImeVisibility(visible); | 133 display_manager_->SetImeVisibility(visible); |
| 132 } | 134 } |
| 133 | 135 |
| 136 void WindowTreeHostImpl::OnCursorUpdated(ServerWindow* window) { |
| 137 if (window == event_dispatcher_.mouse_cursor_source_window()) |
| 138 UpdateNativeCursor(window->cursor()); |
| 139 } |
| 140 |
| 134 void WindowTreeHostImpl::SetSize(mojo::SizePtr size) { | 141 void WindowTreeHostImpl::SetSize(mojo::SizePtr size) { |
| 135 display_manager_->SetViewportSize(size.To<gfx::Size>()); | 142 display_manager_->SetViewportSize(size.To<gfx::Size>()); |
| 136 } | 143 } |
| 137 | 144 |
| 138 void WindowTreeHostImpl::SetTitle(const mojo::String& title) { | 145 void WindowTreeHostImpl::SetTitle(const mojo::String& title) { |
| 139 display_manager_->SetTitle(title.To<base::string16>()); | 146 display_manager_->SetTitle(title.To<base::string16>()); |
| 140 } | 147 } |
| 141 | 148 |
| 142 void WindowTreeHostImpl::AddAccelerator( | 149 void WindowTreeHostImpl::AddAccelerator( |
| 143 uint32_t id, | 150 uint32_t id, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 } | 217 } |
| 211 | 218 |
| 212 void WindowTreeHostImpl::DispatchNextEventFromQueue() { | 219 void WindowTreeHostImpl::DispatchNextEventFromQueue() { |
| 213 if (event_queue_.empty()) | 220 if (event_queue_.empty()) |
| 214 return; | 221 return; |
| 215 mojom::EventPtr next_event = event_queue_.front().Pass(); | 222 mojom::EventPtr next_event = event_queue_.front().Pass(); |
| 216 event_queue_.pop(); | 223 event_queue_.pop(); |
| 217 event_dispatcher_.OnEvent(next_event.Pass()); | 224 event_dispatcher_.OnEvent(next_event.Pass()); |
| 218 } | 225 } |
| 219 | 226 |
| 227 void WindowTreeHostImpl::UpdateNativeCursor(int32_t cursor_id) { |
| 228 if (cursor_id != last_cursor_) { |
| 229 display_manager_->SetCursorById(cursor_id); |
| 230 last_cursor_ = cursor_id; |
| 231 } |
| 232 } |
| 233 |
| 220 ServerWindow* WindowTreeHostImpl::GetRootWindow() { | 234 ServerWindow* WindowTreeHostImpl::GetRootWindow() { |
| 221 return root_.get(); | 235 return root_.get(); |
| 222 } | 236 } |
| 223 | 237 |
| 224 void WindowTreeHostImpl::OnEvent(mojom::EventPtr event) { | 238 void WindowTreeHostImpl::OnEvent(mojom::EventPtr event) { |
| 225 // If this is still waiting for an ack from a previously sent event, then | 239 // If this is still waiting for an ack from a previously sent event, then |
| 226 // queue up the event to be dispatched once the ack is received. | 240 // queue up the event to be dispatched once the ack is received. |
| 227 if (event_ack_timer_.IsRunning()) { | 241 if (event_ack_timer_.IsRunning()) { |
| 228 // TODO(sad): Coalesce if possible. | 242 // TODO(sad): Coalesce if possible. |
| 229 event_queue_.push(event.Pass()); | 243 event_queue_.push(event.Pass()); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 373 } |
| 360 | 374 |
| 361 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { | 375 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { |
| 362 return GetFocusedWindow(); | 376 return GetFocusedWindow(); |
| 363 } | 377 } |
| 364 | 378 |
| 365 void WindowTreeHostImpl::DispatchInputEventToWindow(ServerWindow* target, | 379 void WindowTreeHostImpl::DispatchInputEventToWindow(ServerWindow* target, |
| 366 bool in_nonclient_area, | 380 bool in_nonclient_area, |
| 367 mojom::EventPtr event) { | 381 mojom::EventPtr event) { |
| 368 DCHECK(!event_ack_timer_.IsRunning()); | 382 DCHECK(!event_ack_timer_.IsRunning()); |
| 383 |
| 384 if (event->pointer_data && |
| 385 event->pointer_data->kind == mojom::PointerKind::POINTER_KIND_MOUSE) { |
| 386 UpdateNativeCursor( |
| 387 event_dispatcher_.mouse_cursor_source_window()->cursor()); |
| 388 } |
| 389 |
| 369 // If the event is in the non-client area the event goes to the owner of | 390 // If the event is in the non-client area the event goes to the owner of |
| 370 // the window. Otherwise if the window is an embed root, forward to the | 391 // the window. Otherwise if the window is an embed root, forward to the |
| 371 // embedded window. | 392 // embedded window. |
| 372 WindowTreeImpl* connection = | 393 WindowTreeImpl* connection = |
| 373 in_nonclient_area | 394 in_nonclient_area |
| 374 ? connection_manager_->GetConnection(target->id().connection_id) | 395 ? connection_manager_->GetConnection(target->id().connection_id) |
| 375 : connection_manager_->GetConnectionWithRoot(target->id()); | 396 : connection_manager_->GetConnectionWithRoot(target->id()); |
| 376 if (!connection) { | 397 if (!connection) { |
| 377 DCHECK(!in_nonclient_area); | 398 DCHECK(!in_nonclient_area); |
| 378 connection = connection_manager_->GetConnection(target->id().connection_id); | 399 connection = connection_manager_->GetConnection(target->id().connection_id); |
| 379 } | 400 } |
| 380 tree_awaiting_input_ack_ = connection; | 401 tree_awaiting_input_ack_ = connection; |
| 381 connection->DispatchInputEvent(target, event.Pass()); | 402 connection->DispatchInputEvent(target, event.Pass()); |
| 382 | 403 |
| 383 // TOOD(sad): Adjust this delay, possibly make this dynamic. | 404 // TOOD(sad): Adjust this delay, possibly make this dynamic. |
| 384 const base::TimeDelta max_delay = base::debug::BeingDebugged() | 405 const base::TimeDelta max_delay = base::debug::BeingDebugged() |
| 385 ? base::TimeDelta::FromDays(1) | 406 ? base::TimeDelta::FromDays(1) |
| 386 : GetDefaultAckTimerDelay(); | 407 : GetDefaultAckTimerDelay(); |
| 387 event_ack_timer_.Start(FROM_HERE, max_delay, this, | 408 event_ack_timer_.Start(FROM_HERE, max_delay, this, |
| 388 &WindowTreeHostImpl::OnEventAckTimeout); | 409 &WindowTreeHostImpl::OnEventAckTimeout); |
| 389 } | 410 } |
| 390 | 411 |
| 391 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { | 412 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { |
| 392 windows_needing_frame_destruction_.erase(window); | 413 windows_needing_frame_destruction_.erase(window); |
| 393 window->RemoveObserver(this); | 414 window->RemoveObserver(this); |
| 394 } | 415 } |
| 395 | 416 |
| 396 } // namespace ws | 417 } // namespace ws |
| 397 } // namespace mus | 418 } // namespace mus |
| OLD | NEW |