| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_server.h" | 5 #include "components/mus/ws/window_server.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" | 13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" |
| 14 #include "components/mus/ws/display.h" | 14 #include "components/mus/ws/display.h" |
| 15 #include "components/mus/ws/display_binding.h" | 15 #include "components/mus/ws/display_binding.h" |
| 16 #include "components/mus/ws/display_manager.h" | 16 #include "components/mus/ws/display_manager.h" |
| 17 #include "components/mus/ws/global_window_manager_state.h" | |
| 18 #include "components/mus/ws/operation.h" | 17 #include "components/mus/ws/operation.h" |
| 19 #include "components/mus/ws/server_window.h" | 18 #include "components/mus/ws/server_window.h" |
| 20 #include "components/mus/ws/window_coordinate_conversions.h" | 19 #include "components/mus/ws/window_coordinate_conversions.h" |
| 21 #include "components/mus/ws/window_manager_access_policy.h" | 20 #include "components/mus/ws/window_manager_access_policy.h" |
| 21 #include "components/mus/ws/window_manager_display_root.h" |
| 22 #include "components/mus/ws/window_manager_state.h" | 22 #include "components/mus/ws/window_manager_state.h" |
| 23 #include "components/mus/ws/window_manager_window_tree_factory.h" | 23 #include "components/mus/ws/window_manager_window_tree_factory.h" |
| 24 #include "components/mus/ws/window_server_delegate.h" | 24 #include "components/mus/ws/window_server_delegate.h" |
| 25 #include "components/mus/ws/window_tree.h" | 25 #include "components/mus/ws/window_tree.h" |
| 26 #include "components/mus/ws/window_tree_binding.h" | 26 #include "components/mus/ws/window_tree_binding.h" |
| 27 #include "services/shell/public/cpp/connection.h" | 27 #include "services/shell/public/cpp/connection.h" |
| 28 #include "ui/gfx/geometry/size_conversions.h" | 28 #include "ui/gfx/geometry/size_conversions.h" |
| 29 | 29 |
| 30 namespace mus { | 30 namespace mus { |
| 31 namespace ws { | 31 namespace ws { |
| 32 | 32 |
| 33 WindowServer::WindowServer( | 33 WindowServer::WindowServer( |
| 34 WindowServerDelegate* delegate, | 34 WindowServerDelegate* delegate, |
| 35 const scoped_refptr<mus::SurfacesState>& surfaces_state) | 35 const scoped_refptr<mus::SurfacesState>& surfaces_state) |
| 36 : delegate_(delegate), | 36 : delegate_(delegate), |
| 37 surfaces_state_(surfaces_state), | 37 surfaces_state_(surfaces_state), |
| 38 next_client_id_(1), | 38 next_client_id_(1), |
| 39 display_manager_(new DisplayManager(this)), | 39 display_manager_(new DisplayManager(this, &user_id_tracker_)), |
| 40 current_operation_(nullptr), | 40 current_operation_(nullptr), |
| 41 in_destructor_(false), | 41 in_destructor_(false), |
| 42 next_wm_change_id_(0), | 42 next_wm_change_id_(0), |
| 43 window_manager_window_tree_factory_set_(this, &user_id_tracker_) {} | 43 window_manager_window_tree_factory_set_(this, &user_id_tracker_) {} |
| 44 | 44 |
| 45 WindowServer::~WindowServer() { | 45 WindowServer::~WindowServer() { |
| 46 in_destructor_ = true; | 46 in_destructor_ = true; |
| 47 | 47 |
| 48 // Destroys the window trees results in querying for the display. Tear down | 48 // Destroys the window trees results in querying for the display. Tear down |
| 49 // the displays first so that the trees are notified of the display going | 49 // the displays first so that the trees are notified of the display going |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 current_operation_ = op; | 424 current_operation_ = op; |
| 425 } | 425 } |
| 426 | 426 |
| 427 void WindowServer::FinishOperation() { | 427 void WindowServer::FinishOperation() { |
| 428 // PrepareForOperation/FinishOperation should be balanced. | 428 // PrepareForOperation/FinishOperation should be balanced. |
| 429 CHECK(current_operation_); | 429 CHECK(current_operation_); |
| 430 current_operation_ = nullptr; | 430 current_operation_ = nullptr; |
| 431 } | 431 } |
| 432 | 432 |
| 433 void WindowServer::UpdateNativeCursorFromMouseLocation(ServerWindow* window) { | 433 void WindowServer::UpdateNativeCursorFromMouseLocation(ServerWindow* window) { |
| 434 WindowManagerAndDisplay wm_and_display = | 434 WindowManagerDisplayRoot* display_root = |
| 435 display_manager_->GetWindowManagerAndDisplay(window); | 435 display_manager_->GetWindowManagerDisplayRoot(window); |
| 436 WindowManagerState* wms = wm_and_display.window_manager_state; | 436 if (display_root) { |
| 437 if (wms && wm_and_display.display) { | 437 EventDispatcher* event_dispatcher = |
| 438 wms->event_dispatcher()->UpdateCursorProviderByLastKnownLocation(); | 438 display_root->window_manager_state()->event_dispatcher(); |
| 439 event_dispatcher->UpdateCursorProviderByLastKnownLocation(); |
| 439 int32_t cursor_id = 0; | 440 int32_t cursor_id = 0; |
| 440 if (wms->event_dispatcher()->GetCurrentMouseCursor(&cursor_id)) | 441 if (event_dispatcher->GetCurrentMouseCursor(&cursor_id)) |
| 441 wm_and_display.display->UpdateNativeCursor(cursor_id); | 442 display_root->display()->UpdateNativeCursor(cursor_id); |
| 442 } | 443 } |
| 443 } | 444 } |
| 444 | 445 |
| 445 void WindowServer::UpdateNativeCursorIfOver(ServerWindow* window) { | 446 void WindowServer::UpdateNativeCursorIfOver(ServerWindow* window) { |
| 446 WindowManagerAndDisplay wm_and_display = | 447 WindowManagerDisplayRoot* display_root = |
| 447 display_manager_->GetWindowManagerAndDisplay(window); | 448 display_manager_->GetWindowManagerDisplayRoot(window); |
| 448 WindowManagerState* wms = wm_and_display.window_manager_state; | 449 if (!display_root) |
| 449 if (wms && wm_and_display.display && | 450 return; |
| 450 window == wms->event_dispatcher()->mouse_cursor_source_window()) { | 451 |
| 451 wms->event_dispatcher()->UpdateNonClientAreaForCurrentWindow(); | 452 EventDispatcher* event_dispatcher = |
| 452 int32_t cursor_id = 0; | 453 display_root->window_manager_state()->event_dispatcher(); |
| 453 if (wms->event_dispatcher()->GetCurrentMouseCursor(&cursor_id)) | 454 if (window != event_dispatcher->mouse_cursor_source_window()) |
| 454 wm_and_display.display->UpdateNativeCursor(cursor_id); | 455 return; |
| 455 } | 456 |
| 457 event_dispatcher->UpdateNonClientAreaForCurrentWindow(); |
| 458 int32_t cursor_id = 0; |
| 459 if (event_dispatcher->GetCurrentMouseCursor(&cursor_id)) |
| 460 display_root->display()->UpdateNativeCursor(cursor_id); |
| 456 } | 461 } |
| 457 | 462 |
| 458 mus::SurfacesState* WindowServer::GetSurfacesState() { | 463 mus::SurfacesState* WindowServer::GetSurfacesState() { |
| 459 return surfaces_state_.get(); | 464 return surfaces_state_.get(); |
| 460 } | 465 } |
| 461 | 466 |
| 462 void WindowServer::OnScheduleWindowPaint(ServerWindow* window) { | 467 void WindowServer::OnScheduleWindowPaint(ServerWindow* window) { |
| 463 if (in_destructor_) | 468 if (in_destructor_) |
| 464 return; | 469 return; |
| 465 | 470 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 492 | 497 |
| 493 ProcessWillChangeWindowHierarchy(window, new_parent, old_parent); | 498 ProcessWillChangeWindowHierarchy(window, new_parent, old_parent); |
| 494 } | 499 } |
| 495 | 500 |
| 496 void WindowServer::OnWindowHierarchyChanged(ServerWindow* window, | 501 void WindowServer::OnWindowHierarchyChanged(ServerWindow* window, |
| 497 ServerWindow* new_parent, | 502 ServerWindow* new_parent, |
| 498 ServerWindow* old_parent) { | 503 ServerWindow* old_parent) { |
| 499 if (in_destructor_) | 504 if (in_destructor_) |
| 500 return; | 505 return; |
| 501 | 506 |
| 502 WindowManagerState* wms = | 507 WindowManagerDisplayRoot* display_root = |
| 503 display_manager_->GetWindowManagerAndDisplay(window).window_manager_state; | 508 display_manager_->GetWindowManagerDisplayRoot(window); |
| 504 if (wms) | 509 if (display_root) |
| 505 wms->ReleaseCaptureBlockedByAnyModalWindow(); | 510 display_root->window_manager_state() |
| 511 ->ReleaseCaptureBlockedByAnyModalWindow(); |
| 506 | 512 |
| 507 ProcessWindowHierarchyChanged(window, new_parent, old_parent); | 513 ProcessWindowHierarchyChanged(window, new_parent, old_parent); |
| 508 | 514 |
| 509 // TODO(beng): optimize. | 515 // TODO(beng): optimize. |
| 510 if (old_parent) | 516 if (old_parent) |
| 511 SchedulePaint(old_parent, gfx::Rect(old_parent->bounds().size())); | 517 SchedulePaint(old_parent, gfx::Rect(old_parent->bounds().size())); |
| 512 if (new_parent) | 518 if (new_parent) |
| 513 SchedulePaint(new_parent, gfx::Rect(new_parent->bounds().size())); | 519 SchedulePaint(new_parent, gfx::Rect(new_parent->bounds().size())); |
| 514 | 520 |
| 515 UpdateNativeCursorFromMouseLocation(window); | 521 UpdateNativeCursorFromMouseLocation(window); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 for (auto& pair : tree_map_) { | 585 for (auto& pair : tree_map_) { |
| 580 pair.second->ProcessWindowOpacityChanged(window, old_opacity, new_opacity, | 586 pair.second->ProcessWindowOpacityChanged(window, old_opacity, new_opacity, |
| 581 IsOperationSource(pair.first)); | 587 IsOperationSource(pair.first)); |
| 582 } | 588 } |
| 583 } | 589 } |
| 584 | 590 |
| 585 void WindowServer::OnWindowVisibilityChanged(ServerWindow* window) { | 591 void WindowServer::OnWindowVisibilityChanged(ServerWindow* window) { |
| 586 if (in_destructor_) | 592 if (in_destructor_) |
| 587 return; | 593 return; |
| 588 | 594 |
| 589 WindowManagerState* wms = | 595 WindowManagerDisplayRoot* display_root = |
| 590 display_manager_->GetWindowManagerAndDisplay(window).window_manager_state; | 596 display_manager_->GetWindowManagerDisplayRoot(window); |
| 591 if (wms) | 597 if (display_root) |
| 592 wms->ReleaseCaptureBlockedByModalWindow(window); | 598 display_root->window_manager_state()->ReleaseCaptureBlockedByModalWindow( |
| 599 window); |
| 593 } | 600 } |
| 594 | 601 |
| 595 void WindowServer::OnWindowPredefinedCursorChanged(ServerWindow* window, | 602 void WindowServer::OnWindowPredefinedCursorChanged(ServerWindow* window, |
| 596 int32_t cursor_id) { | 603 int32_t cursor_id) { |
| 597 if (in_destructor_) | 604 if (in_destructor_) |
| 598 return; | 605 return; |
| 599 | 606 |
| 600 ProcessWillChangeWindowPredefinedCursor(window, cursor_id); | 607 ProcessWillChangeWindowPredefinedCursor(window, cursor_id); |
| 601 | 608 |
| 602 UpdateNativeCursorIfOver(window); | 609 UpdateNativeCursorIfOver(window); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 // If we're deleting a window, then this is a superfluous message. | 647 // If we're deleting a window, then this is a superfluous message. |
| 641 if (current_operation_type() == OperationType::DELETE_WINDOW) | 648 if (current_operation_type() == OperationType::DELETE_WINDOW) |
| 642 return; | 649 return; |
| 643 for (auto& pair : tree_map_) { | 650 for (auto& pair : tree_map_) { |
| 644 pair.second->ProcessTransientWindowRemoved(window, transient_child, | 651 pair.second->ProcessTransientWindowRemoved(window, transient_child, |
| 645 IsOperationSource(pair.first)); | 652 IsOperationSource(pair.first)); |
| 646 } | 653 } |
| 647 } | 654 } |
| 648 | 655 |
| 649 void WindowServer::OnFirstDisplayReady() { | 656 void WindowServer::OnFirstDisplayReady() { |
| 650 // TODO(sky): remove this, temporary until window manager state made | |
| 651 // global. | |
| 652 if (!created_one_display_) { | |
| 653 created_one_display_ = true; | |
| 654 std::vector<WindowManagerWindowTreeFactory*> factories = | |
| 655 window_manager_window_tree_factory_set_.GetFactories(); | |
| 656 for (WindowManagerWindowTreeFactory* factory : factories) | |
| 657 factory->BindPendingRequest(); | |
| 658 } | |
| 659 delegate_->OnFirstDisplayReady(); | 657 delegate_->OnFirstDisplayReady(); |
| 660 } | 658 } |
| 661 | 659 |
| 662 void WindowServer::OnNoMoreDisplays() { | 660 void WindowServer::OnNoMoreDisplays() { |
| 663 delegate_->OnNoMoreDisplays(); | 661 delegate_->OnNoMoreDisplays(); |
| 664 } | 662 } |
| 665 | 663 |
| 666 bool WindowServer::GetFrameDecorationsForUser( | 664 bool WindowServer::GetFrameDecorationsForUser( |
| 667 const UserId& user_id, | 665 const UserId& user_id, |
| 668 mojom::FrameDecorationValuesPtr* values) { | 666 mojom::FrameDecorationValuesPtr* values) { |
| 669 GlobalWindowManagerState* global_window_manager_state = | 667 WindowManagerState* window_manager_state = |
| 670 window_manager_window_tree_factory_set_ | 668 window_manager_window_tree_factory_set_.GetWindowManagerStateForUser( |
| 671 .GetGlobalWindowManagerStateForUser(user_id); | 669 user_id); |
| 672 if (!global_window_manager_state) | 670 if (!window_manager_state) |
| 673 return false; | 671 return false; |
| 674 if (values && global_window_manager_state->got_frame_decoration_values()) | 672 if (values && window_manager_state->got_frame_decoration_values()) |
| 675 *values = global_window_manager_state->frame_decoration_values().Clone(); | 673 *values = window_manager_state->frame_decoration_values().Clone(); |
| 676 return global_window_manager_state->got_frame_decoration_values(); | 674 return window_manager_state->got_frame_decoration_values(); |
| 675 } |
| 676 |
| 677 WindowManagerState* WindowServer::GetWindowManagerStateForUser( |
| 678 const UserId& user_id) { |
| 679 return window_manager_window_tree_factory_set_.GetWindowManagerStateForUser( |
| 680 user_id); |
| 677 } | 681 } |
| 678 | 682 |
| 679 } // namespace ws | 683 } // namespace ws |
| 680 } // namespace mus | 684 } // namespace mus |
| OLD | NEW |