| 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/display.h" | 5 #include "components/mus/ws/display.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/ws/connection_manager.h" | 10 #include "components/mus/ws/connection_manager.h" |
| 11 #include "components/mus/ws/connection_manager_delegate.h" | 11 #include "components/mus/ws/connection_manager_delegate.h" |
| 12 #include "components/mus/ws/display_binding.h" | 12 #include "components/mus/ws/display_binding.h" |
| 13 #include "components/mus/ws/display_manager.h" |
| 13 #include "components/mus/ws/focus_controller.h" | 14 #include "components/mus/ws/focus_controller.h" |
| 14 #include "components/mus/ws/platform_display.h" | 15 #include "components/mus/ws/platform_display.h" |
| 15 #include "components/mus/ws/window_manager_factory_service.h" | 16 #include "components/mus/ws/window_manager_factory_service.h" |
| 16 #include "components/mus/ws/window_manager_state.h" | 17 #include "components/mus/ws/window_manager_state.h" |
| 17 #include "components/mus/ws/window_tree.h" | 18 #include "components/mus/ws/window_tree.h" |
| 18 #include "components/mus/ws/window_tree_binding.h" | 19 #include "components/mus/ws/window_tree_binding.h" |
| 19 #include "mojo/common/common_type_converters.h" | 20 #include "mojo/common/common_type_converters.h" |
| 20 #include "mojo/converters/geometry/geometry_type_converters.h" | 21 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 21 #include "mojo/converters/input_events/input_events_type_converters.h" | 22 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 22 #include "mojo/shell/public/interfaces/connector.mojom.h" | 23 #include "mojo/shell/public/interfaces/connector.mojom.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 std::set<WindowManagerState*> states; | 122 std::set<WindowManagerState*> states; |
| 122 for (auto& pair : window_manager_state_map_) | 123 for (auto& pair : window_manager_state_map_) |
| 123 states.insert(pair.second.get()); | 124 states.insert(pair.second.get()); |
| 124 for (WindowManagerState* state : states) | 125 for (WindowManagerState* state : states) |
| 125 connection_manager_->DestroyTree(state->tree()); | 126 connection_manager_->DestroyTree(state->tree()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void Display::Init(scoped_ptr<DisplayBinding> binding) { | 129 void Display::Init(scoped_ptr<DisplayBinding> binding) { |
| 129 init_called_ = true; | 130 init_called_ = true; |
| 130 binding_ = std::move(binding); | 131 binding_ = std::move(binding); |
| 131 connection_manager_->AddDisplay(this); | 132 display_manager()->AddDisplay(this); |
| 132 InitWindowManagersIfNecessary(); | 133 InitWindowManagersIfNecessary(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void Display::SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values) { | 136 void Display::SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values) { |
| 136 // TODO(sky): this needs to be moved to WindowManagerState. | 137 // TODO(sky): this needs to be moved to WindowManagerState. |
| 137 frame_decoration_values_ = values.Clone(); | 138 frame_decoration_values_ = values.Clone(); |
| 138 connection_manager_->ProcessFrameDecorationValuesChanged(this); | 139 connection_manager_->ProcessFrameDecorationValuesChanged(this); |
| 139 } | 140 } |
| 140 | 141 |
| 141 bool Display::SchedulePaintIfInViewport(const ServerWindow* window, | 142 void Display::SchedulePaint(const ServerWindow* window, |
| 142 const gfx::Rect& bounds) { | 143 const gfx::Rect& bounds) { |
| 143 if (root_->Contains(window)) { | 144 DCHECK(root_->Contains(window)); |
| 144 platform_display_->SchedulePaint(window, bounds); | 145 platform_display_->SchedulePaint(window, bounds); |
| 145 return true; | |
| 146 } | |
| 147 return false; | |
| 148 } | 146 } |
| 149 | 147 |
| 150 void Display::ScheduleSurfaceDestruction(ServerWindow* window) { | 148 void Display::ScheduleSurfaceDestruction(ServerWindow* window) { |
| 151 if (!platform_display_->IsFramePending()) { | 149 if (!platform_display_->IsFramePending()) { |
| 152 window->DestroySurfacesScheduledForDestruction(); | 150 window->DestroySurfacesScheduledForDestruction(); |
| 153 return; | 151 return; |
| 154 } | 152 } |
| 155 if (windows_needing_frame_destruction_.count(window)) | 153 if (windows_needing_frame_destruction_.count(window)) |
| 156 return; | 154 return; |
| 157 windows_needing_frame_destruction_.insert(window); | 155 windows_needing_frame_destruction_.insert(window); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 platform_display_->UpdateTextInputState(state); | 238 platform_display_->UpdateTextInputState(state); |
| 241 } | 239 } |
| 242 | 240 |
| 243 void Display::SetImeVisibility(ServerWindow* window, bool visible) { | 241 void Display::SetImeVisibility(ServerWindow* window, bool visible) { |
| 244 // Do not need to show or hide IME for unfocused window. | 242 // Do not need to show or hide IME for unfocused window. |
| 245 if (focus_controller_->GetFocusedWindow() != window) | 243 if (focus_controller_->GetFocusedWindow() != window) |
| 246 return; | 244 return; |
| 247 platform_display_->SetImeVisibility(visible); | 245 platform_display_->SetImeVisibility(visible); |
| 248 } | 246 } |
| 249 | 247 |
| 250 void Display::OnWindowTreeConnectionError(WindowTree* tree) { | 248 void Display::OnWillDestroyTree(WindowTree* tree) { |
| 251 for (auto it = window_manager_state_map_.begin(); | 249 for (auto it = window_manager_state_map_.begin(); |
| 252 it != window_manager_state_map_.end(); ++it) { | 250 it != window_manager_state_map_.end(); ++it) { |
| 253 if (it->second->tree() == tree) { | 251 if (it->second->tree() == tree) { |
| 254 window_manager_state_map_.erase(it); | 252 window_manager_state_map_.erase(it); |
| 255 break; | 253 break; |
| 256 } | 254 } |
| 257 } | 255 } |
| 258 | 256 |
| 259 if (tree_awaiting_input_ack_ != tree) | 257 if (tree_awaiting_input_ack_ != tree) |
| 260 return; | 258 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 291 } | 289 } |
| 292 tree_awaiting_input_ack_ = nullptr; | 290 tree_awaiting_input_ack_ = nullptr; |
| 293 event_ack_timer_.Stop(); | 291 event_ack_timer_.Stop(); |
| 294 ProcessNextEventFromQueue(); | 292 ProcessNextEventFromQueue(); |
| 295 } | 293 } |
| 296 | 294 |
| 297 void Display::InitWindowManagersIfNecessary() { | 295 void Display::InitWindowManagersIfNecessary() { |
| 298 if (!init_called_ || !root_) | 296 if (!init_called_ || !root_) |
| 299 return; | 297 return; |
| 300 | 298 |
| 301 connection_manager_->OnDisplayAcceleratedWidgetAvailable(this); | 299 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); |
| 302 if (binding_) { | 300 if (binding_) { |
| 303 scoped_ptr<WindowManagerState> wms_ptr(new WindowManagerState(this)); | 301 scoped_ptr<WindowManagerState> wms_ptr(new WindowManagerState(this)); |
| 304 WindowManagerState* wms = wms_ptr.get(); | 302 WindowManagerState* wms = wms_ptr.get(); |
| 305 // For this case we never create additional WindowManagerStates, so any | 303 // For this case we never create additional WindowManagerStates, so any |
| 306 // id works. | 304 // id works. |
| 307 window_manager_state_map_[mojo::shell::mojom::kRootUserID] = | 305 window_manager_state_map_[mojo::shell::mojom::kRootUserID] = |
| 308 std::move(wms_ptr); | 306 std::move(wms_ptr); |
| 309 wms->tree_ = binding_->CreateWindowTree(wms->root()); | 307 wms->tree_ = binding_->CreateWindowTree(wms->root()); |
| 310 } else { | 308 } else { |
| 311 CreateWindowManagerStatesFromRegistry(); | 309 CreateWindowManagerStatesFromRegistry(); |
| 312 } | 310 } |
| 313 } | 311 } |
| 314 | 312 |
| 313 DisplayManager* Display::display_manager() { |
| 314 return connection_manager_->display_manager(); |
| 315 } |
| 316 |
| 317 const DisplayManager* Display::display_manager() const { |
| 318 return connection_manager_->display_manager(); |
| 319 } |
| 320 |
| 315 void Display::OnEventAckTimeout() { | 321 void Display::OnEventAckTimeout() { |
| 316 // TODO(sad): Figure out what we should do. | 322 // TODO(sad): Figure out what we should do. |
| 317 NOTIMPLEMENTED() << "Event ACK timed out."; | 323 NOTIMPLEMENTED() << "Event ACK timed out."; |
| 318 OnEventAck(tree_awaiting_input_ack_); | 324 OnEventAck(tree_awaiting_input_ack_); |
| 319 } | 325 } |
| 320 | 326 |
| 321 void Display::QueueEvent( | 327 void Display::QueueEvent( |
| 322 const ui::Event& event, | 328 const ui::Event& event, |
| 323 scoped_ptr<ProcessedEventTarget> processed_event_target) { | 329 scoped_ptr<ProcessedEventTarget> processed_event_target) { |
| 324 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); | 330 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 return; | 434 return; |
| 429 } | 435 } |
| 430 event_dispatcher_.ProcessEvent(event); | 436 event_dispatcher_.ProcessEvent(event); |
| 431 } | 437 } |
| 432 | 438 |
| 433 void Display::OnNativeCaptureLost() { | 439 void Display::OnNativeCaptureLost() { |
| 434 SetCapture(nullptr, false); | 440 SetCapture(nullptr, false); |
| 435 } | 441 } |
| 436 | 442 |
| 437 void Display::OnDisplayClosed() { | 443 void Display::OnDisplayClosed() { |
| 438 connection_manager_->DestroyDisplay(this); | 444 display_manager()->DestroyDisplay(this); |
| 439 } | 445 } |
| 440 | 446 |
| 441 void Display::OnViewportMetricsChanged( | 447 void Display::OnViewportMetricsChanged( |
| 442 const mojom::ViewportMetrics& old_metrics, | 448 const mojom::ViewportMetrics& old_metrics, |
| 443 const mojom::ViewportMetrics& new_metrics) { | 449 const mojom::ViewportMetrics& new_metrics) { |
| 444 if (!root_) { | 450 if (!root_) { |
| 445 root_.reset(connection_manager_->CreateServerWindow( | 451 root_.reset(connection_manager_->CreateServerWindow( |
| 446 RootWindowId(connection_manager_->GetAndAdvanceNextRootId()), | 452 display_manager()->GetAndAdvanceNextRootId(), |
| 447 ServerWindow::Properties())); | 453 ServerWindow::Properties())); |
| 448 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 454 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 449 root_->SetVisible(true); | 455 root_->SetVisible(true); |
| 450 focus_controller_.reset(new FocusController(this, root_.get())); | 456 focus_controller_.reset(new FocusController(this, root_.get())); |
| 451 focus_controller_->AddObserver(this); | 457 focus_controller_->AddObserver(this); |
| 452 InitWindowManagersIfNecessary(); | 458 InitWindowManagersIfNecessary(); |
| 453 event_dispatcher_.set_root(root_.get()); | 459 event_dispatcher_.set_root(root_.get()); |
| 454 } else { | 460 } else { |
| 455 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 461 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 456 const gfx::Rect wm_bounds(root_->bounds().size()); | 462 const gfx::Rect wm_bounds(root_->bounds().size()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 DCHECK_NE(owning_tree_new, embedded_tree_new); | 541 DCHECK_NE(owning_tree_new, embedded_tree_new); |
| 536 embedded_tree_new->ProcessFocusChanged(old_focused_window, | 542 embedded_tree_new->ProcessFocusChanged(old_focused_window, |
| 537 new_focused_window); | 543 new_focused_window); |
| 538 } | 544 } |
| 539 } | 545 } |
| 540 | 546 |
| 541 // WindowManagers are always notified of focus changes. | 547 // WindowManagers are always notified of focus changes. |
| 542 WindowTree* wms_tree_with_old_focused_window = nullptr; | 548 WindowTree* wms_tree_with_old_focused_window = nullptr; |
| 543 if (old_focused_window) { | 549 if (old_focused_window) { |
| 544 WindowManagerState* wms = | 550 WindowManagerState* wms = |
| 545 connection_manager_->GetWindowManagerAndDisplay(old_focused_window) | 551 display_manager() |
| 552 ->GetWindowManagerAndDisplay(old_focused_window) |
| 546 .window_manager_state; | 553 .window_manager_state; |
| 547 wms_tree_with_old_focused_window = wms ? wms->tree() : nullptr; | 554 wms_tree_with_old_focused_window = wms ? wms->tree() : nullptr; |
| 548 if (wms_tree_with_old_focused_window && | 555 if (wms_tree_with_old_focused_window && |
| 549 wms_tree_with_old_focused_window != owning_tree_old && | 556 wms_tree_with_old_focused_window != owning_tree_old && |
| 550 wms_tree_with_old_focused_window != embedded_tree_old && | 557 wms_tree_with_old_focused_window != embedded_tree_old && |
| 551 wms_tree_with_old_focused_window != owning_tree_new && | 558 wms_tree_with_old_focused_window != owning_tree_new && |
| 552 wms_tree_with_old_focused_window != embedded_tree_new) { | 559 wms_tree_with_old_focused_window != embedded_tree_new) { |
| 553 wms_tree_with_old_focused_window->ProcessFocusChanged(old_focused_window, | 560 wms_tree_with_old_focused_window->ProcessFocusChanged(old_focused_window, |
| 554 new_focused_window); | 561 new_focused_window); |
| 555 } | 562 } |
| 556 } | 563 } |
| 557 if (new_focused_window) { | 564 if (new_focused_window) { |
| 558 WindowManagerState* wms = | 565 WindowManagerState* wms = |
| 559 connection_manager_->GetWindowManagerAndDisplay(new_focused_window) | 566 display_manager() |
| 567 ->GetWindowManagerAndDisplay(new_focused_window) |
| 560 .window_manager_state; | 568 .window_manager_state; |
| 561 WindowTree* wms_tree = wms ? wms->tree() : nullptr; | 569 WindowTree* wms_tree = wms ? wms->tree() : nullptr; |
| 562 if (wms_tree && wms_tree != wms_tree_with_old_focused_window && | 570 if (wms_tree && wms_tree != wms_tree_with_old_focused_window && |
| 563 wms_tree != owning_tree_old && wms_tree != embedded_tree_old && | 571 wms_tree != owning_tree_old && wms_tree != embedded_tree_old && |
| 564 wms_tree != owning_tree_new && wms_tree != embedded_tree_new) { | 572 wms_tree != owning_tree_new && wms_tree != embedded_tree_new) { |
| 565 wms_tree->ProcessFocusChanged(old_focused_window, new_focused_window); | 573 wms_tree->ProcessFocusChanged(old_focused_window, new_focused_window); |
| 566 } | 574 } |
| 567 } | 575 } |
| 568 | 576 |
| 569 UpdateTextInputState(new_focused_window, | 577 UpdateTextInputState(new_focused_window, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 void Display::OnUserIdAdded(const UserId& id) {} | 632 void Display::OnUserIdAdded(const UserId& id) {} |
| 625 | 633 |
| 626 void Display::OnUserIdRemoved(const UserId& id) { | 634 void Display::OnUserIdRemoved(const UserId& id) { |
| 627 if (binding_) | 635 if (binding_) |
| 628 return; | 636 return; |
| 629 | 637 |
| 630 WindowManagerState* state = GetWindowManagerStateForUser(id); | 638 WindowManagerState* state = GetWindowManagerStateForUser(id); |
| 631 if (!state) | 639 if (!state) |
| 632 return; | 640 return; |
| 633 | 641 |
| 634 // DestroyTree() calls back to OnWindowTreeConnectionError() and the | 642 // DestroyTree() calls back to OnWillDestroyTree() and the WindowManagerState |
| 635 // WindowManagerState is destroyed (and removed). | 643 // is destroyed (and removed). |
| 636 connection_manager_->DestroyTree(state->tree()); | 644 connection_manager_->DestroyTree(state->tree()); |
| 637 DCHECK_EQ(0u, window_manager_state_map_.count(id)); | 645 DCHECK_EQ(0u, window_manager_state_map_.count(id)); |
| 638 } | 646 } |
| 639 | 647 |
| 640 void Display::OnWindowManagerFactorySet(WindowManagerFactoryService* service) { | 648 void Display::OnWindowManagerFactorySet(WindowManagerFactoryService* service) { |
| 641 CreateWindowManagerStateFromService(service); | 649 CreateWindowManagerStateFromService(service); |
| 642 } | 650 } |
| 643 | 651 |
| 644 } // namespace ws | 652 } // namespace ws |
| 645 } // namespace mus | 653 } // namespace mus |
| OLD | NEW |