| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_manager.h" | 5 #include "components/mus/ws/display_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/mus/ws/display.h" | 8 #include "components/mus/ws/display.h" |
| 9 #include "components/mus/ws/display_manager_delegate.h" | 9 #include "components/mus/ws/display_manager_delegate.h" |
| 10 #include "components/mus/ws/event_dispatcher.h" |
| 10 #include "components/mus/ws/server_window.h" | 11 #include "components/mus/ws/server_window.h" |
| 11 #include "components/mus/ws/user_display_manager.h" | 12 #include "components/mus/ws/user_display_manager.h" |
| 13 #include "components/mus/ws/user_id_tracker.h" |
| 14 #include "components/mus/ws/window_manager_state.h" |
| 12 | 15 |
| 13 namespace mus { | 16 namespace mus { |
| 14 namespace ws { | 17 namespace ws { |
| 15 | 18 |
| 16 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate) | 19 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate, |
| 20 UserIdTracker* user_id_tracker) |
| 17 // |next_root_id_| is used as the lower bits, so that starting at 0 is | 21 // |next_root_id_| is used as the lower bits, so that starting at 0 is |
| 18 // fine. |next_display_id_| is used by itself, so we start at 1 to reserve | 22 // fine. |next_display_id_| is used by itself, so we start at 1 to reserve |
| 19 // 0 as invalid. | 23 // 0 as invalid. |
| 20 : delegate_(delegate), | 24 : delegate_(delegate), |
| 25 user_id_tracker_(user_id_tracker), |
| 21 next_root_id_(0), | 26 next_root_id_(0), |
| 22 next_display_id_(1) {} | 27 next_display_id_(1) { |
| 28 user_id_tracker_->AddObserver(this); |
| 29 } |
| 23 | 30 |
| 24 DisplayManager::~DisplayManager() { | 31 DisplayManager::~DisplayManager() { |
| 32 user_id_tracker_->RemoveObserver(this); |
| 25 DestroyAllDisplays(); | 33 DestroyAllDisplays(); |
| 26 } | 34 } |
| 27 | 35 |
| 28 UserDisplayManager* DisplayManager::GetUserDisplayManager( | 36 UserDisplayManager* DisplayManager::GetUserDisplayManager( |
| 29 const UserId& user_id) { | 37 const UserId& user_id) { |
| 30 if (!user_display_managers_.count(user_id)) { | 38 if (!user_display_managers_.count(user_id)) { |
| 31 user_display_managers_[user_id] = | 39 user_display_managers_[user_id] = |
| 32 base::WrapUnique(new UserDisplayManager(this, delegate_, user_id)); | 40 base::WrapUnique(new UserDisplayManager(this, delegate_, user_id)); |
| 33 } | 41 } |
| 34 return user_display_managers_[user_id].get(); | 42 return user_display_managers_[user_id].get(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 const ServerWindow* window) const { | 94 const ServerWindow* window) const { |
| 87 while (window && window->parent()) | 95 while (window && window->parent()) |
| 88 window = window->parent(); | 96 window = window->parent(); |
| 89 for (Display* display : displays_) { | 97 for (Display* display : displays_) { |
| 90 if (window == display->root_window()) | 98 if (window == display->root_window()) |
| 91 return display; | 99 return display; |
| 92 } | 100 } |
| 93 return nullptr; | 101 return nullptr; |
| 94 } | 102 } |
| 95 | 103 |
| 96 WindowManagerAndDisplayConst DisplayManager::GetWindowManagerAndDisplay( | 104 const WindowManagerDisplayRoot* DisplayManager::GetWindowManagerDisplayRoot( |
| 97 const ServerWindow* window) const { | 105 const ServerWindow* window) const { |
| 98 const ServerWindow* last = window; | 106 const ServerWindow* last = window; |
| 99 while (window && window->parent()) { | 107 while (window && window->parent()) { |
| 100 last = window; | 108 last = window; |
| 101 window = window->parent(); | 109 window = window->parent(); |
| 102 } | 110 } |
| 103 for (Display* display : displays_) { | 111 for (Display* display : displays_) { |
| 104 if (window == display->root_window()) { | 112 if (window == display->root_window()) |
| 105 WindowManagerAndDisplayConst result; | 113 return display->GetWindowManagerDisplayRootWithRoot(last); |
| 106 result.display = display; | |
| 107 result.window_manager_state = | |
| 108 display->GetWindowManagerStateWithRoot(last); | |
| 109 return result; | |
| 110 } | |
| 111 } | 114 } |
| 112 return WindowManagerAndDisplayConst(); | 115 return nullptr; |
| 113 } | 116 } |
| 114 | 117 |
| 115 WindowManagerAndDisplay DisplayManager::GetWindowManagerAndDisplay( | 118 WindowManagerDisplayRoot* DisplayManager::GetWindowManagerDisplayRoot( |
| 116 const ServerWindow* window) { | 119 const ServerWindow* window) { |
| 117 WindowManagerAndDisplayConst result_const = | 120 return const_cast<WindowManagerDisplayRoot*>( |
| 118 const_cast<const DisplayManager*>(this)->GetWindowManagerAndDisplay( | 121 const_cast<const DisplayManager*>(this)->GetWindowManagerDisplayRoot( |
| 119 window); | 122 window)); |
| 120 WindowManagerAndDisplay result; | |
| 121 result.display = const_cast<Display*>(result_const.display); | |
| 122 result.window_manager_state = | |
| 123 const_cast<WindowManagerState*>(result_const.window_manager_state); | |
| 124 return result; | |
| 125 } | 123 } |
| 126 | 124 |
| 127 WindowId DisplayManager::GetAndAdvanceNextRootId() { | 125 WindowId DisplayManager::GetAndAdvanceNextRootId() { |
| 128 // TODO(sky): handle wrapping! | 126 // TODO(sky): handle wrapping! |
| 129 const uint16_t id = next_root_id_++; | 127 const uint16_t id = next_root_id_++; |
| 130 DCHECK_LT(id, next_root_id_); | 128 DCHECK_LT(id, next_root_id_); |
| 131 return RootWindowId(id); | 129 return RootWindowId(id); |
| 132 } | 130 } |
| 133 | 131 |
| 134 uint32_t DisplayManager::GetAndAdvanceNextDisplayId() { | 132 uint32_t DisplayManager::GetAndAdvanceNextDisplayId() { |
| 135 // TODO(sky): handle wrapping! | 133 // TODO(sky): handle wrapping! |
| 136 const uint32_t id = next_display_id_++; | 134 const uint32_t id = next_display_id_++; |
| 137 DCHECK_LT(id, next_display_id_); | 135 DCHECK_LT(id, next_display_id_); |
| 138 return id; | 136 return id; |
| 139 } | 137 } |
| 140 | 138 |
| 141 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { | 139 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { |
| 142 DCHECK_NE(0u, pending_displays_.count(display)); | 140 DCHECK_NE(0u, pending_displays_.count(display)); |
| 143 DCHECK_EQ(0u, displays_.count(display)); | 141 DCHECK_EQ(0u, displays_.count(display)); |
| 144 const bool is_first_display = displays_.empty(); | 142 const bool is_first_display = displays_.empty(); |
| 145 displays_.insert(display); | 143 displays_.insert(display); |
| 146 pending_displays_.erase(display); | 144 pending_displays_.erase(display); |
| 147 if (is_first_display) | 145 if (is_first_display) |
| 148 delegate_->OnFirstDisplayReady(); | 146 delegate_->OnFirstDisplayReady(); |
| 149 } | 147 } |
| 150 | 148 |
| 149 void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id, |
| 150 const UserId& active_id) { |
| 151 WindowManagerState* previous_window_manager_state = |
| 152 delegate_->GetWindowManagerStateForUser(previously_active_id); |
| 153 gfx::Point mouse_location_on_screen; |
| 154 if (previous_window_manager_state) { |
| 155 mouse_location_on_screen = previous_window_manager_state->event_dispatcher() |
| 156 ->mouse_pointer_last_location(); |
| 157 previous_window_manager_state->Deactivate(); |
| 158 } |
| 159 |
| 160 WindowManagerState* current_window_manager_state = |
| 161 delegate_->GetWindowManagerStateForUser(active_id); |
| 162 if (current_window_manager_state) |
| 163 current_window_manager_state->Activate(mouse_location_on_screen); |
| 164 } |
| 165 |
| 151 } // namespace ws | 166 } // namespace ws |
| 152 } // namespace mus | 167 } // namespace mus |
| OLD | NEW |