| 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/public/interfaces/input_event_constants.mojom.h" |
| 11 #include "components/mus/ws/connection_manager.h" | 11 #include "components/mus/ws/connection_manager.h" |
| 12 #include "components/mus/ws/display_manager.h" | 12 #include "components/mus/ws/display_manager.h" |
| 13 #include "components/mus/ws/focus_controller.h" | 13 #include "components/mus/ws/focus_controller.h" |
| 14 #include "components/mus/ws/window_tree_host_delegate.h" | 14 #include "components/mus/ws/window_tree_host_connection.h" |
| 15 #include "components/mus/ws/window_tree_impl.h" | 15 #include "components/mus/ws/window_tree_impl.h" |
| 16 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
| 17 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 18 #include "mojo/converters/input_events/input_events_type_converters.h" | 18 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 19 | 19 |
| 20 namespace mus { | 20 namespace mus { |
| 21 namespace ws { | 21 namespace ws { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 base::TimeDelta GetDefaultAckTimerDelay() { | 24 base::TimeDelta GetDefaultAckTimerDelay() { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 WindowTreeHostImpl::QueuedEvent::QueuedEvent() {} | 85 WindowTreeHostImpl::QueuedEvent::QueuedEvent() {} |
| 86 WindowTreeHostImpl::QueuedEvent::~QueuedEvent() {} | 86 WindowTreeHostImpl::QueuedEvent::~QueuedEvent() {} |
| 87 | 87 |
| 88 WindowTreeHostImpl::WindowTreeHostImpl( | 88 WindowTreeHostImpl::WindowTreeHostImpl( |
| 89 ConnectionManager* connection_manager, | 89 ConnectionManager* connection_manager, |
| 90 mojo::Connector* connector, | 90 mojo::Connector* connector, |
| 91 const scoped_refptr<GpuState>& gpu_state, | 91 const scoped_refptr<GpuState>& gpu_state, |
| 92 const scoped_refptr<SurfacesState>& surfaces_state) | 92 const scoped_refptr<SurfacesState>& surfaces_state) |
| 93 : id_(next_id++), | 93 : id_(next_id++), |
| 94 delegate_(nullptr), | |
| 95 connection_manager_(connection_manager), | 94 connection_manager_(connection_manager), |
| 96 event_dispatcher_(this), | 95 event_dispatcher_(this), |
| 97 display_manager_( | 96 display_manager_( |
| 98 DisplayManager::Create(connector, gpu_state, surfaces_state)), | 97 DisplayManager::Create(connector, gpu_state, surfaces_state)), |
| 99 tree_awaiting_input_ack_(nullptr), | 98 tree_awaiting_input_ack_(nullptr), |
| 100 last_cursor_(0) { | 99 last_cursor_(0) { |
| 101 frame_decoration_values_ = mojom::FrameDecorationValues::New(); | 100 frame_decoration_values_ = mojom::FrameDecorationValues::New(); |
| 102 frame_decoration_values_->normal_client_area_insets = mojo::Insets::New(); | 101 frame_decoration_values_->normal_client_area_insets = mojo::Insets::New(); |
| 103 frame_decoration_values_->maximized_client_area_insets = mojo::Insets::New(); | 102 frame_decoration_values_->maximized_client_area_insets = mojo::Insets::New(); |
| 104 frame_decoration_values_->max_title_bar_button_width = 0u; | 103 frame_decoration_values_->max_title_bar_button_width = 0u; |
| 105 | 104 |
| 106 display_manager_->Init(this); | 105 display_manager_->Init(this); |
| 107 } | 106 } |
| 108 | 107 |
| 109 WindowTreeHostImpl::~WindowTreeHostImpl() { | 108 WindowTreeHostImpl::~WindowTreeHostImpl() { |
| 110 DestroyFocusController(); | 109 DestroyFocusController(); |
| 111 for (ServerWindow* window : windows_needing_frame_destruction_) | 110 for (ServerWindow* window : windows_needing_frame_destruction_) |
| 112 window->RemoveObserver(this); | 111 window->RemoveObserver(this); |
| 113 } | 112 } |
| 114 | 113 |
| 115 void WindowTreeHostImpl::Init(WindowTreeHostDelegate* delegate) { | 114 void WindowTreeHostImpl::Init(scoped_ptr<WindowTreeHostConnection> connection) { |
| 116 delegate_ = delegate; | 115 window_tree_host_connection_ = std::move(connection); |
| 117 if (delegate_ && root_) | 116 connection_manager_->AddHost(this); |
| 118 delegate_->OnDisplayInitialized(); | 117 CallOnDisplayInitializedIfNecessary(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 const WindowTreeImpl* WindowTreeHostImpl::GetWindowTree() const { | 120 const WindowTreeImpl* WindowTreeHostImpl::GetWindowTree() const { |
| 122 return delegate_ ? delegate_->GetWindowTree() : nullptr; | 121 return window_tree_; |
| 123 } | 122 } |
| 124 | 123 |
| 125 WindowTreeImpl* WindowTreeHostImpl::GetWindowTree() { | 124 WindowTreeImpl* WindowTreeHostImpl::GetWindowTree() { |
| 126 return delegate_ ? delegate_->GetWindowTree() : nullptr; | 125 return window_tree_; |
| 127 } | 126 } |
| 128 | 127 |
| 129 void WindowTreeHostImpl::SetFrameDecorationValues( | 128 void WindowTreeHostImpl::SetFrameDecorationValues( |
| 130 mojom::FrameDecorationValuesPtr values) { | 129 mojom::FrameDecorationValuesPtr values) { |
| 131 frame_decoration_values_ = values.Clone(); | 130 frame_decoration_values_ = values.Clone(); |
| 132 connection_manager_->ProcessFrameDecorationValuesChanged(this); | 131 connection_manager_->ProcessFrameDecorationValuesChanged(this); |
| 133 } | 132 } |
| 134 | 133 |
| 135 bool WindowTreeHostImpl::IsWindowAttachedToRoot( | 134 bool WindowTreeHostImpl::IsWindowAttachedToRoot( |
| 136 const ServerWindow* window) const { | 135 const ServerWindow* window) const { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (tree_awaiting_input_ack_ != tree) { | 247 if (tree_awaiting_input_ack_ != tree) { |
| 249 // TODO(sad): The ack must have arrived after the timeout. We should do | 248 // TODO(sad): The ack must have arrived after the timeout. We should do |
| 250 // something here, and in OnEventAckTimeout(). | 249 // something here, and in OnEventAckTimeout(). |
| 251 return; | 250 return; |
| 252 } | 251 } |
| 253 tree_awaiting_input_ack_ = nullptr; | 252 tree_awaiting_input_ack_ = nullptr; |
| 254 event_ack_timer_.Stop(); | 253 event_ack_timer_.Stop(); |
| 255 ProcessNextEventFromQueue(); | 254 ProcessNextEventFromQueue(); |
| 256 } | 255 } |
| 257 | 256 |
| 257 void WindowTreeHostImpl::CallOnDisplayInitializedIfNecessary() { |
| 258 if (window_tree_host_connection_ && root_) { |
| 259 connection_manager_->OnWindowTreeHostDisplayAvailable(this); |
| 260 window_tree_ = window_tree_host_connection_->CreateWindowTree(root_.get()); |
| 261 } |
| 262 } |
| 263 |
| 258 void WindowTreeHostImpl::OnEventAckTimeout() { | 264 void WindowTreeHostImpl::OnEventAckTimeout() { |
| 259 // TODO(sad): Figure out what we should do. | 265 // TODO(sad): Figure out what we should do. |
| 260 NOTIMPLEMENTED() << "Event ACK timed out."; | 266 NOTIMPLEMENTED() << "Event ACK timed out."; |
| 261 OnEventAck(tree_awaiting_input_ack_); | 267 OnEventAck(tree_awaiting_input_ack_); |
| 262 } | 268 } |
| 263 | 269 |
| 264 void WindowTreeHostImpl::QueueEvent( | 270 void WindowTreeHostImpl::QueueEvent( |
| 265 mojom::EventPtr event, | 271 mojom::EventPtr event, |
| 266 scoped_ptr<ProcessedEventTarget> processed_event_target) { | 272 scoped_ptr<ProcessedEventTarget> processed_event_target) { |
| 267 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); | 273 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return; | 355 return; |
| 350 } | 356 } |
| 351 event_dispatcher_.ProcessEvent(std::move(mojo_event)); | 357 event_dispatcher_.ProcessEvent(std::move(mojo_event)); |
| 352 } | 358 } |
| 353 | 359 |
| 354 void WindowTreeHostImpl::OnNativeCaptureLost() { | 360 void WindowTreeHostImpl::OnNativeCaptureLost() { |
| 355 SetCapture(nullptr, false); | 361 SetCapture(nullptr, false); |
| 356 } | 362 } |
| 357 | 363 |
| 358 void WindowTreeHostImpl::OnDisplayClosed() { | 364 void WindowTreeHostImpl::OnDisplayClosed() { |
| 359 if (delegate_) | 365 connection_manager_->DestroyHost(this); |
| 360 delegate_->OnDisplayClosed(); | |
| 361 } | 366 } |
| 362 | 367 |
| 363 void WindowTreeHostImpl::OnViewportMetricsChanged( | 368 void WindowTreeHostImpl::OnViewportMetricsChanged( |
| 364 const mojom::ViewportMetrics& old_metrics, | 369 const mojom::ViewportMetrics& old_metrics, |
| 365 const mojom::ViewportMetrics& new_metrics) { | 370 const mojom::ViewportMetrics& new_metrics) { |
| 366 if (!root_) { | 371 if (!root_) { |
| 367 root_.reset(connection_manager_->CreateServerWindow( | 372 root_.reset(connection_manager_->CreateServerWindow( |
| 368 RootWindowId(connection_manager_->GetAndAdvanceNextHostId()), | 373 RootWindowId(connection_manager_->GetAndAdvanceNextHostId()), |
| 369 ServerWindow::Properties())); | 374 ServerWindow::Properties())); |
| 370 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 375 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 371 root_->SetVisible(true); | 376 root_->SetVisible(true); |
| 372 focus_controller_.reset(new FocusController(this, root_.get())); | 377 focus_controller_.reset(new FocusController(this, root_.get())); |
| 373 focus_controller_->AddObserver(this); | 378 focus_controller_->AddObserver(this); |
| 374 if (delegate_) | 379 CallOnDisplayInitializedIfNecessary(); |
| 375 delegate_->OnDisplayInitialized(); | |
| 376 event_dispatcher_.set_root(root_.get()); | 380 event_dispatcher_.set_root(root_.get()); |
| 377 } else { | 381 } else { |
| 378 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 382 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 379 } | 383 } |
| 380 connection_manager_->ProcessViewportMetricsChanged(this, old_metrics, | 384 connection_manager_->ProcessViewportMetricsChanged(this, old_metrics, |
| 381 new_metrics); | 385 new_metrics); |
| 382 } | 386 } |
| 383 | 387 |
| 384 void WindowTreeHostImpl::OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) { | 388 void WindowTreeHostImpl::OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) { |
| 385 event_dispatcher_.set_surface_id(surface_id); | 389 event_dispatcher_.set_surface_id(surface_id); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (embedded_connection_new && | 457 if (embedded_connection_new && |
| 454 embedded_connection_new != owning_connection_old && | 458 embedded_connection_new != owning_connection_old && |
| 455 embedded_connection_new != embedded_connection_old) { | 459 embedded_connection_new != embedded_connection_old) { |
| 456 DCHECK_NE(owning_connection_new, embedded_connection_new); | 460 DCHECK_NE(owning_connection_new, embedded_connection_new); |
| 457 embedded_connection_new->ProcessFocusChanged(old_focused_window, | 461 embedded_connection_new->ProcessFocusChanged(old_focused_window, |
| 458 new_focused_window); | 462 new_focused_window); |
| 459 } | 463 } |
| 460 } | 464 } |
| 461 | 465 |
| 462 // Ensure that we always notify the root connection of a focus change. | 466 // Ensure that we always notify the root connection of a focus change. |
| 463 WindowTreeImpl* root_tree = GetWindowTree(); | 467 if (window_tree_ != owning_connection_old && |
| 464 if (root_tree != owning_connection_old && | 468 window_tree_ != embedded_connection_old && |
| 465 root_tree != embedded_connection_old && | 469 window_tree_ != owning_connection_new && |
| 466 root_tree != owning_connection_new && | 470 window_tree_ != embedded_connection_new) { |
| 467 root_tree != embedded_connection_new) { | 471 window_tree_->ProcessFocusChanged(old_focused_window, new_focused_window); |
| 468 root_tree->ProcessFocusChanged(old_focused_window, new_focused_window); | |
| 469 } | 472 } |
| 470 | 473 |
| 471 UpdateTextInputState(new_focused_window, | 474 UpdateTextInputState(new_focused_window, |
| 472 new_focused_window->text_input_state()); | 475 new_focused_window->text_input_state()); |
| 473 } | 476 } |
| 474 | 477 |
| 475 void WindowTreeHostImpl::OnAccelerator(uint32_t accelerator_id, | 478 void WindowTreeHostImpl::OnAccelerator(uint32_t accelerator_id, |
| 476 mojom::EventPtr event) { | 479 mojom::EventPtr event) { |
| 477 GetWindowTree()->OnAccelerator(accelerator_id, std::move(event)); | 480 window_tree_->OnAccelerator(accelerator_id, std::move(event)); |
| 478 } | 481 } |
| 479 | 482 |
| 480 void WindowTreeHostImpl::SetFocusedWindowFromEventDispatcher( | 483 void WindowTreeHostImpl::SetFocusedWindowFromEventDispatcher( |
| 481 ServerWindow* new_focused_window) { | 484 ServerWindow* new_focused_window) { |
| 482 SetFocusedWindow(new_focused_window); | 485 SetFocusedWindow(new_focused_window); |
| 483 } | 486 } |
| 484 | 487 |
| 485 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { | 488 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { |
| 486 return GetFocusedWindow(); | 489 return GetFocusedWindow(); |
| 487 } | 490 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 512 DispatchInputEventToWindowImpl(target, in_nonclient_area, std::move(event)); | 515 DispatchInputEventToWindowImpl(target, in_nonclient_area, std::move(event)); |
| 513 } | 516 } |
| 514 | 517 |
| 515 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { | 518 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { |
| 516 windows_needing_frame_destruction_.erase(window); | 519 windows_needing_frame_destruction_.erase(window); |
| 517 window->RemoveObserver(this); | 520 window->RemoveObserver(this); |
| 518 } | 521 } |
| 519 | 522 |
| 520 } // namespace ws | 523 } // namespace ws |
| 521 } // namespace mus | 524 } // namespace mus |
| OLD | NEW |