| 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 "mash/wm/user_window_controller_impl.h" | 5 #include "mash/wm/user_window_controller_impl.h" |
| 6 | 6 |
| 7 #include "ash/public/interfaces/container.mojom.h" |
| 7 #include "components/mus/public/cpp/property_type_converters.h" | 8 #include "components/mus/public/cpp/property_type_converters.h" |
| 8 #include "components/mus/public/cpp/window.h" | 9 #include "components/mus/public/cpp/window.h" |
| 9 #include "components/mus/public/cpp/window_property.h" | 10 #include "components/mus/public/cpp/window_property.h" |
| 10 #include "components/mus/public/cpp/window_tree_client.h" | 11 #include "components/mus/public/cpp/window_tree_client.h" |
| 11 #include "mash/wm/property_util.h" | 12 #include "mash/wm/property_util.h" |
| 12 #include "mash/wm/public/interfaces/container.mojom.h" | |
| 13 #include "mash/wm/root_window_controller.h" | 13 #include "mash/wm/root_window_controller.h" |
| 14 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
| 15 #include "ui/resources/grit/ui_resources.h" | 15 #include "ui/resources/grit/ui_resources.h" |
| 16 | 16 |
| 17 MUS_DECLARE_WINDOW_PROPERTY_TYPE(uint32_t); | 17 MUS_DECLARE_WINDOW_PROPERTY_TYPE(uint32_t); |
| 18 | 18 |
| 19 namespace mash { | 19 namespace mash { |
| 20 namespace wm { | 20 namespace wm { |
| 21 | 21 |
| 22 // Key used for storing identifier sent to clients for windows. | 22 // Key used for storing identifier sent to clients for windows. |
| 23 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(uint32_t, kUserWindowIdKey, 0u); | 23 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(uint32_t, kUserWindowIdKey, 0u); |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Returns |window|, or an ancestor thereof, parented to |container|, or null. | 27 // Returns |window|, or an ancestor thereof, parented to |container|, or null. |
| 28 mus::Window* GetTopLevelWindow(mus::Window* window, mus::Window* container) { | 28 mus::Window* GetTopLevelWindow(mus::Window* window, mus::Window* container) { |
| 29 while (window && window->parent() != container) | 29 while (window && window->parent() != container) |
| 30 window = window->parent(); | 30 window = window->parent(); |
| 31 return window; | 31 return window; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Get a UserWindow struct from a mus::Window. | 34 // Get a UserWindow struct from a mus::Window. |
| 35 mojom::UserWindowPtr GetUserWindow(mus::Window* window) { | 35 ash::mojom::UserWindowPtr GetUserWindow(mus::Window* window) { |
| 36 mojom::UserWindowPtr user_window(mojom::UserWindow::New()); | 36 ash::mojom::UserWindowPtr user_window(ash::mojom::UserWindow::New()); |
| 37 DCHECK_NE(0u, window->GetLocalProperty(kUserWindowIdKey)); | 37 DCHECK_NE(0u, window->GetLocalProperty(kUserWindowIdKey)); |
| 38 user_window->window_id = window->GetLocalProperty(kUserWindowIdKey); | 38 user_window->window_id = window->GetLocalProperty(kUserWindowIdKey); |
| 39 user_window->window_title = mojo::String::From(GetWindowTitle(window)); | 39 user_window->window_title = mojo::String::From(GetWindowTitle(window)); |
| 40 user_window->window_app_icon = GetWindowAppIcon(window); | 40 user_window->window_app_icon = GetWindowAppIcon(window); |
| 41 user_window->window_app_id = mojo::String::From(GetAppID(window)); | 41 user_window->window_app_id = mojo::String::From(GetAppID(window)); |
| 42 user_window->ignored_by_shelf = GetWindowIgnoredByShelf(window); | 42 user_window->ignored_by_shelf = GetWindowIgnoredByShelf(window); |
| 43 mus::Window* focused = window->window_tree()->GetFocusedWindow(); | 43 mus::Window* focused = window->window_tree()->GetFocusedWindow(); |
| 44 focused = GetTopLevelWindow(focused, window->parent()); | 44 focused = GetTopLevelWindow(focused, window->parent()); |
| 45 user_window->window_has_focus = focused == window; | 45 user_window->window_has_focus = focused == window; |
| 46 return user_window; | 46 return user_window; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 mus::Window* UserWindowControllerImpl::GetUserWindowById(uint32_t id) { | 125 mus::Window* UserWindowControllerImpl::GetUserWindowById(uint32_t id) { |
| 126 for (mus::Window* window : GetUserWindowContainer()->children()) { | 126 for (mus::Window* window : GetUserWindowContainer()->children()) { |
| 127 if (window->GetLocalProperty(kUserWindowIdKey) == id) | 127 if (window->GetLocalProperty(kUserWindowIdKey) == id) |
| 128 return window; | 128 return window; |
| 129 } | 129 } |
| 130 return nullptr; | 130 return nullptr; |
| 131 } | 131 } |
| 132 | 132 |
| 133 mus::Window* UserWindowControllerImpl::GetUserWindowContainer() const { | 133 mus::Window* UserWindowControllerImpl::GetUserWindowContainer() const { |
| 134 return root_controller_->GetWindowForContainer( | 134 return root_controller_->GetWindowForContainer( |
| 135 mojom::Container::USER_PRIVATE_WINDOWS); | 135 ash::mojom::Container::USER_PRIVATE_WINDOWS); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void UserWindowControllerImpl::OnTreeChanging(const TreeChangeParams& params) { | 138 void UserWindowControllerImpl::OnTreeChanging(const TreeChangeParams& params) { |
| 139 DCHECK(root_controller_); | 139 DCHECK(root_controller_); |
| 140 if (params.new_parent == GetUserWindowContainer()) { | 140 if (params.new_parent == GetUserWindowContainer()) { |
| 141 params.target->AddObserver(window_property_observer_.get()); | 141 params.target->AddObserver(window_property_observer_.get()); |
| 142 AssignIdIfNecessary(params.target); | 142 AssignIdIfNecessary(params.target); |
| 143 if (user_window_observer_) | 143 if (user_window_observer_) |
| 144 user_window_observer_->OnUserWindowAdded(GetUserWindow(params.target)); | 144 user_window_observer_->OnUserWindowAdded(GetUserWindow(params.target)); |
| 145 } else if (params.old_parent == GetUserWindowContainer()) { | 145 } else if (params.old_parent == GetUserWindowContainer()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 user_window_observer_->OnUserWindowFocusChanged( | 171 user_window_observer_->OnUserWindowFocusChanged( |
| 172 lost_focus->GetLocalProperty(kUserWindowIdKey), false); | 172 lost_focus->GetLocalProperty(kUserWindowIdKey), false); |
| 173 } | 173 } |
| 174 if (gained_focus) { | 174 if (gained_focus) { |
| 175 user_window_observer_->OnUserWindowFocusChanged( | 175 user_window_observer_->OnUserWindowFocusChanged( |
| 176 gained_focus->GetLocalProperty(kUserWindowIdKey), true); | 176 gained_focus->GetLocalProperty(kUserWindowIdKey), true); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 void UserWindowControllerImpl::AddUserWindowObserver( | 180 void UserWindowControllerImpl::AddUserWindowObserver( |
| 181 mojom::UserWindowObserverPtr observer) { | 181 ash::mojom::UserWindowObserverPtr observer) { |
| 182 // TODO(msw): Support multiple observers. | 182 // TODO(msw): Support multiple observers. |
| 183 user_window_observer_ = std::move(observer); | 183 user_window_observer_ = std::move(observer); |
| 184 | 184 |
| 185 const mus::Window::Children& windows = GetUserWindowContainer()->children(); | 185 const mus::Window::Children& windows = GetUserWindowContainer()->children(); |
| 186 mojo::Array<mojom::UserWindowPtr> user_windows = | 186 mojo::Array<ash::mojom::UserWindowPtr> user_windows = |
| 187 mojo::Array<mojom::UserWindowPtr>::New(windows.size()); | 187 mojo::Array<ash::mojom::UserWindowPtr>::New(windows.size()); |
| 188 for (size_t i = 0; i < windows.size(); ++i) | 188 for (size_t i = 0; i < windows.size(); ++i) |
| 189 user_windows[i] = GetUserWindow(windows[i]); | 189 user_windows[i] = GetUserWindow(windows[i]); |
| 190 user_window_observer_->OnUserWindowObserverAdded(std::move(user_windows)); | 190 user_window_observer_->OnUserWindowObserverAdded(std::move(user_windows)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void UserWindowControllerImpl::FocusUserWindow(uint32_t window_id) { | 193 void UserWindowControllerImpl::FocusUserWindow(uint32_t window_id) { |
| 194 mus::Window* window = GetUserWindowById(window_id); | 194 mus::Window* window = GetUserWindowById(window_id); |
| 195 if (window) | 195 if (window) |
| 196 window->SetFocus(); | 196 window->SetFocus(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace wm | 199 } // namespace wm |
| 200 } // namespace mash | 200 } // namespace mash |
| OLD | NEW |