| 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 "services/ui/ws/window_server.h" | 5 #include "services/ui/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" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 pair.second->window_manager_state()->GetOrphanedRootWithId(id); | 207 pair.second->window_manager_state()->GetOrphanedRootWithId(id); |
| 208 if (window) | 208 if (window) |
| 209 return window; | 209 return window; |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 WindowTree* tree = GetTreeWithId(id.client_id); | 213 WindowTree* tree = GetTreeWithId(id.client_id); |
| 214 return tree ? tree->GetWindow(id) : nullptr; | 214 return tree ? tree->GetWindow(id) : nullptr; |
| 215 } | 215 } |
| 216 | 216 |
| 217 void WindowServer::SchedulePaint(ServerWindow* window, | |
| 218 const gfx::Rect& bounds) { | |
| 219 Display* display = display_manager_->GetDisplayContaining(window); | |
| 220 if (display) | |
| 221 display->SchedulePaint(window, bounds); | |
| 222 } | |
| 223 | |
| 224 void WindowServer::OnTreeMessagedClient(ClientSpecificId id) { | 217 void WindowServer::OnTreeMessagedClient(ClientSpecificId id) { |
| 225 if (current_operation_) | 218 if (current_operation_) |
| 226 current_operation_->MarkTreeAsMessaged(id); | 219 current_operation_->MarkTreeAsMessaged(id); |
| 227 } | 220 } |
| 228 | 221 |
| 229 bool WindowServer::DidTreeMessageClient(ClientSpecificId id) const { | 222 bool WindowServer::DidTreeMessageClient(ClientSpecificId id) const { |
| 230 return current_operation_ && current_operation_->DidMessageTree(id); | 223 return current_operation_ && current_operation_->DidMessageTree(id); |
| 231 } | 224 } |
| 232 | 225 |
| 233 const WindowTree* WindowServer::GetTreeWithRoot( | 226 const WindowTree* WindowServer::GetTreeWithRoot( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 return focused_window; | 282 return focused_window; |
| 290 } | 283 } |
| 291 return nullptr; | 284 return nullptr; |
| 292 } | 285 } |
| 293 | 286 |
| 294 bool WindowServer::IsActiveUserInHighContrastMode() const { | 287 bool WindowServer::IsActiveUserInHighContrastMode() const { |
| 295 return IsUserInHighContrastMode(user_id_tracker_.active_id()); | 288 return IsUserInHighContrastMode(user_id_tracker_.active_id()); |
| 296 } | 289 } |
| 297 | 290 |
| 298 void WindowServer::SetHighContrastMode(const UserId& user, bool enabled) { | 291 void WindowServer::SetHighContrastMode(const UserId& user, bool enabled) { |
| 292 // TODO(fsamuel): This doesn't really seem like it's a window server concept? |
| 299 if (IsUserInHighContrastMode(user) == enabled) | 293 if (IsUserInHighContrastMode(user) == enabled) |
| 300 return; | 294 return; |
| 301 high_contrast_mode_[user] = enabled; | 295 high_contrast_mode_[user] = enabled; |
| 302 if (user_id_tracker_.active_id() != user) | |
| 303 return; | |
| 304 for (Display* display : display_manager_->displays()) { | |
| 305 display->SchedulePaint(display->root_window(), | |
| 306 gfx::Rect(display->root_window()->bounds().size())); | |
| 307 } | |
| 308 } | 296 } |
| 309 | 297 |
| 310 uint32_t WindowServer::GenerateWindowManagerChangeId( | 298 uint32_t WindowServer::GenerateWindowManagerChangeId( |
| 311 WindowTree* source, | 299 WindowTree* source, |
| 312 uint32_t client_change_id) { | 300 uint32_t client_change_id) { |
| 313 const uint32_t wm_change_id = next_wm_change_id_++; | 301 const uint32_t wm_change_id = next_wm_change_id_++; |
| 314 in_flight_wm_change_map_[wm_change_id] = {source->id(), client_change_id}; | 302 in_flight_wm_change_map_[wm_change_id] = {source->id(), client_change_id}; |
| 315 return wm_change_id; | 303 return wm_change_id; |
| 316 } | 304 } |
| 317 | 305 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 mojom::Cursor cursor_id = mojom::Cursor::CURSOR_NULL; | 593 mojom::Cursor cursor_id = mojom::Cursor::CURSOR_NULL; |
| 606 if (event_dispatcher->GetCurrentMouseCursor(&cursor_id)) | 594 if (event_dispatcher->GetCurrentMouseCursor(&cursor_id)) |
| 607 display_root->display()->UpdateNativeCursor(cursor_id); | 595 display_root->display()->UpdateNativeCursor(cursor_id); |
| 608 } | 596 } |
| 609 | 597 |
| 610 bool WindowServer::IsUserInHighContrastMode(const UserId& user) const { | 598 bool WindowServer::IsUserInHighContrastMode(const UserId& user) const { |
| 611 const auto iter = high_contrast_mode_.find(user); | 599 const auto iter = high_contrast_mode_.find(user); |
| 612 return (iter == high_contrast_mode_.end()) ? false : iter->second; | 600 return (iter == high_contrast_mode_.end()) ? false : iter->second; |
| 613 } | 601 } |
| 614 | 602 |
| 615 void WindowServer::OnScheduleWindowPaint(ServerWindow* window) { | 603 ServerWindow* WindowServer::GetRootWindow(const ServerWindow* window) { |
| 616 if (in_destructor_) | 604 Display* display = display_manager_->GetDisplayContaining(window); |
| 617 return; | |
| 618 | |
| 619 SchedulePaint(window, gfx::Rect(window->bounds().size())); | |
| 620 if (!window_paint_callback_.is_null()) | |
| 621 window_paint_callback_.Run(window); | |
| 622 } | |
| 623 | |
| 624 const ServerWindow* WindowServer::GetRootWindow( | |
| 625 const ServerWindow* window) const { | |
| 626 const Display* display = display_manager_->GetDisplayContaining(window); | |
| 627 return display ? display->root_window() : nullptr; | 605 return display ? display->root_window() : nullptr; |
| 628 } | 606 } |
| 629 | 607 |
| 630 void WindowServer::OnWindowDestroyed(ServerWindow* window) { | 608 void WindowServer::OnWindowDestroyed(ServerWindow* window) { |
| 631 ProcessWindowDeleted(window); | 609 ProcessWindowDeleted(window); |
| 632 } | 610 } |
| 633 | 611 |
| 634 void WindowServer::OnWillChangeWindowHierarchy(ServerWindow* window, | 612 void WindowServer::OnWillChangeWindowHierarchy(ServerWindow* window, |
| 635 ServerWindow* new_parent, | 613 ServerWindow* new_parent, |
| 636 ServerWindow* old_parent) { | 614 ServerWindow* old_parent) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 647 return; | 625 return; |
| 648 | 626 |
| 649 WindowManagerDisplayRoot* display_root = | 627 WindowManagerDisplayRoot* display_root = |
| 650 display_manager_->GetWindowManagerDisplayRoot(window); | 628 display_manager_->GetWindowManagerDisplayRoot(window); |
| 651 if (display_root) | 629 if (display_root) |
| 652 display_root->window_manager_state() | 630 display_root->window_manager_state() |
| 653 ->ReleaseCaptureBlockedByAnyModalWindow(); | 631 ->ReleaseCaptureBlockedByAnyModalWindow(); |
| 654 | 632 |
| 655 ProcessWindowHierarchyChanged(window, new_parent, old_parent); | 633 ProcessWindowHierarchyChanged(window, new_parent, old_parent); |
| 656 | 634 |
| 657 // TODO(beng): optimize. | |
| 658 if (old_parent) | |
| 659 SchedulePaint(old_parent, gfx::Rect(old_parent->bounds().size())); | |
| 660 if (new_parent) | |
| 661 SchedulePaint(new_parent, gfx::Rect(new_parent->bounds().size())); | |
| 662 | |
| 663 UpdateNativeCursorFromMouseLocation(window); | 635 UpdateNativeCursorFromMouseLocation(window); |
| 664 } | 636 } |
| 665 | 637 |
| 666 void WindowServer::OnWindowBoundsChanged(ServerWindow* window, | 638 void WindowServer::OnWindowBoundsChanged(ServerWindow* window, |
| 667 const gfx::Rect& old_bounds, | 639 const gfx::Rect& old_bounds, |
| 668 const gfx::Rect& new_bounds) { | 640 const gfx::Rect& new_bounds) { |
| 669 if (in_destructor_) | 641 if (in_destructor_) |
| 670 return; | 642 return; |
| 671 | 643 |
| 672 ProcessWindowBoundsChanged(window, old_bounds, new_bounds); | 644 ProcessWindowBoundsChanged(window, old_bounds, new_bounds); |
| 673 if (!window->parent()) | 645 if (!window->parent()) |
| 674 return; | 646 return; |
| 675 | 647 |
| 676 SchedulePaint(window->parent(), old_bounds); | |
| 677 SchedulePaint(window->parent(), new_bounds); | |
| 678 | |
| 679 UpdateNativeCursorFromMouseLocation(window); | 648 UpdateNativeCursorFromMouseLocation(window); |
| 680 } | 649 } |
| 681 | 650 |
| 682 void WindowServer::OnWindowClientAreaChanged( | 651 void WindowServer::OnWindowClientAreaChanged( |
| 683 ServerWindow* window, | 652 ServerWindow* window, |
| 684 const gfx::Insets& new_client_area, | 653 const gfx::Insets& new_client_area, |
| 685 const std::vector<gfx::Rect>& new_additional_client_areas) { | 654 const std::vector<gfx::Rect>& new_additional_client_areas) { |
| 686 if (in_destructor_) | 655 if (in_destructor_) |
| 687 return; | 656 return; |
| 688 | 657 |
| 689 ProcessClientAreaChanged(window, new_client_area, | 658 ProcessClientAreaChanged(window, new_client_area, |
| 690 new_additional_client_areas); | 659 new_additional_client_areas); |
| 691 | 660 |
| 692 UpdateNativeCursorIfOver(window); | 661 UpdateNativeCursorIfOver(window); |
| 693 } | 662 } |
| 694 | 663 |
| 695 void WindowServer::OnWindowReordered(ServerWindow* window, | 664 void WindowServer::OnWindowReordered(ServerWindow* window, |
| 696 ServerWindow* relative, | 665 ServerWindow* relative, |
| 697 mojom::OrderDirection direction) { | 666 mojom::OrderDirection direction) { |
| 698 ProcessWindowReorder(window, relative, direction); | 667 ProcessWindowReorder(window, relative, direction); |
| 699 if (!in_destructor_) | |
| 700 SchedulePaint(window, gfx::Rect(window->bounds().size())); | |
| 701 UpdateNativeCursorFromMouseLocation(window); | 668 UpdateNativeCursorFromMouseLocation(window); |
| 702 } | 669 } |
| 703 | 670 |
| 704 void WindowServer::OnWillChangeWindowVisibility(ServerWindow* window) { | 671 void WindowServer::OnWillChangeWindowVisibility(ServerWindow* window) { |
| 705 if (in_destructor_) | 672 if (in_destructor_) |
| 706 return; | 673 return; |
| 707 | 674 |
| 708 // Need to repaint if the window was drawn (which means it's in the process of | |
| 709 // hiding) or the window is transitioning to drawn. | |
| 710 if (window->parent() && | |
| 711 (window->IsDrawn() || | |
| 712 (!window->visible() && window->parent()->IsDrawn()))) { | |
| 713 SchedulePaint(window->parent(), window->bounds()); | |
| 714 } | |
| 715 | |
| 716 for (auto& pair : tree_map_) { | 675 for (auto& pair : tree_map_) { |
| 717 pair.second->ProcessWillChangeWindowVisibility( | 676 pair.second->ProcessWillChangeWindowVisibility( |
| 718 window, IsOperationSource(pair.first)); | 677 window, IsOperationSource(pair.first)); |
| 719 } | 678 } |
| 720 } | 679 } |
| 721 | 680 |
| 722 void WindowServer::OnWindowOpacityChanged(ServerWindow* window, | 681 void WindowServer::OnWindowOpacityChanged(ServerWindow* window, |
| 723 float old_opacity, | 682 float old_opacity, |
| 724 float new_opacity) { | 683 float new_opacity) { |
| 725 DCHECK(!in_destructor_); | 684 DCHECK(!in_destructor_); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 // If the window doesn't have a parent then we have nothing to propagate. | 774 // If the window doesn't have a parent then we have nothing to propagate. |
| 816 if (!window) | 775 if (!window) |
| 817 return; | 776 return; |
| 818 | 777 |
| 819 // Cache the last submitted surface ID in the window server. | 778 // Cache the last submitted surface ID in the window server. |
| 820 // DisplayCompositorFrameSink may submit a CompositorFrame without | 779 // DisplayCompositorFrameSink may submit a CompositorFrame without |
| 821 // creating a CompositorFrameSinkManager. | 780 // creating a CompositorFrameSinkManager. |
| 822 window->GetOrCreateCompositorFrameSinkManager()->SetLatestSurfaceInfo( | 781 window->GetOrCreateCompositorFrameSinkManager()->SetLatestSurfaceInfo( |
| 823 compositor_frame_sink_type, surface_id, frame_size); | 782 compositor_frame_sink_type, surface_id, frame_size); |
| 824 | 783 |
| 784 // This is only used for testing to observe that a window has a |
| 785 // CompositorFrame. |
| 786 if (!window_paint_callback_.is_null()) |
| 787 window_paint_callback_.Run(window); |
| 788 |
| 825 // We only care about propagating default surface IDs. | 789 // We only care about propagating default surface IDs. |
| 826 // TODO(fsamuel, sadrul): we should get rid of CompositorFrameSinkTypes. | 790 // TODO(fsamuel, sadrul): we should get rid of CompositorFrameSinkTypes. |
| 827 if (compositor_frame_sink_type != mojom::CompositorFrameSinkType::DEFAULT || | 791 if (compositor_frame_sink_type != mojom::CompositorFrameSinkType::DEFAULT || |
| 828 !window->parent()) { | 792 !window->parent()) { |
| 829 return; | 793 return; |
| 830 } | 794 } |
| 831 WindowTree* window_tree = GetTreeWithId(window->parent()->id().client_id); | 795 WindowTree* window_tree = GetTreeWithId(window->parent()->id().client_id); |
| 832 if (window_tree) { | 796 if (window_tree) { |
| 833 window_tree->ProcessWindowSurfaceChanged(window, surface_id, frame_size, | 797 window_tree->ProcessWindowSurfaceChanged(window, surface_id, frame_size, |
| 834 device_scale_factor); | 798 device_scale_factor); |
| 835 } | 799 } |
| 836 } | 800 } |
| 837 | 801 |
| 838 void WindowServer::OnActiveUserIdChanged(const UserId& previously_active_id, | 802 void WindowServer::OnActiveUserIdChanged(const UserId& previously_active_id, |
| 839 const UserId& active_id) { | 803 const UserId& active_id) { |
| 840 if (IsUserInHighContrastMode(previously_active_id) == | |
| 841 IsUserInHighContrastMode(active_id)) | |
| 842 return; | |
| 843 for (Display* display : display_manager_->displays()) { | |
| 844 display->SchedulePaint(display->root_window(), | |
| 845 gfx::Rect(display->root_window()->bounds().size())); | |
| 846 } | |
| 847 } | 804 } |
| 848 | 805 |
| 849 void WindowServer::OnUserIdAdded(const UserId& id) { | 806 void WindowServer::OnUserIdAdded(const UserId& id) { |
| 850 activity_monitor_map_[id] = base::MakeUnique<UserActivityMonitor>(nullptr); | 807 activity_monitor_map_[id] = base::MakeUnique<UserActivityMonitor>(nullptr); |
| 851 } | 808 } |
| 852 | 809 |
| 853 void WindowServer::OnUserIdRemoved(const UserId& id) { | 810 void WindowServer::OnUserIdRemoved(const UserId& id) { |
| 854 activity_monitor_map_.erase(id); | 811 activity_monitor_map_.erase(id); |
| 855 } | 812 } |
| 856 | 813 |
| 857 } // namespace ws | 814 } // namespace ws |
| 858 } // namespace ui | 815 } // namespace ui |
| OLD | NEW |