OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mash/wm/user_window_controller_impl.h" |
| 6 |
| 7 #include "components/mus/public/cpp/window.h" |
| 8 #include "mash/wm/public/interfaces/container.mojom.h" |
| 9 #include "mash/wm/window_manager_application.h" |
| 10 |
| 11 namespace mash { |
| 12 namespace wm { |
| 13 |
| 14 UserWindowControllerImpl::UserWindowControllerImpl() : state_(nullptr) {} |
| 15 |
| 16 UserWindowControllerImpl::~UserWindowControllerImpl() { |
| 17 if (state_) |
| 18 GetUserWindowContainer()->RemoveObserver(this); |
| 19 } |
| 20 |
| 21 void UserWindowControllerImpl::Initialize(WindowManagerApplication* state) { |
| 22 DCHECK(state); |
| 23 DCHECK(!state_); |
| 24 state_ = state; |
| 25 GetUserWindowContainer()->AddObserver(this); |
| 26 } |
| 27 |
| 28 mus::Window* UserWindowControllerImpl::GetUserWindowContainer() const { |
| 29 return state_->GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS); |
| 30 } |
| 31 |
| 32 void UserWindowControllerImpl::OnTreeChanging(const TreeChangeParams& params) { |
| 33 DCHECK(state_); |
| 34 if (user_window_observer_) { |
| 35 mus::Window* user_window_container = GetUserWindowContainer(); |
| 36 if (params.new_parent == user_window_container) |
| 37 user_window_observer_->OnUserWindowAdded(params.target->id()); |
| 38 else if (params.old_parent == user_window_container) |
| 39 user_window_observer_->OnUserWindowRemoved(params.target->id()); |
| 40 } |
| 41 } |
| 42 |
| 43 void UserWindowControllerImpl::AddUserWindowObserver( |
| 44 mash::wm::mojom::UserWindowObserverPtr observer) { |
| 45 // TODO(msw): Support multiple observers. |
| 46 user_window_observer_ = std::move(observer); |
| 47 |
| 48 const mus::Window::Children& windows = GetUserWindowContainer()->children(); |
| 49 mojo::Array<uint32_t> user_windows = |
| 50 mojo::Array<uint32_t>::New(windows.size()); |
| 51 for (size_t i = 0; i < windows.size(); ++i) |
| 52 user_windows[i] = windows[i]->id(); |
| 53 user_window_observer_->OnUserWindowObserverAdded(std::move(user_windows)); |
| 54 } |
| 55 |
| 56 void UserWindowControllerImpl::FocusUserWindow(uint32_t window_id) { |
| 57 mus::Window* window = GetUserWindowContainer()->GetChildById(window_id); |
| 58 if (window) |
| 59 window->SetFocus(); |
| 60 } |
| 61 |
| 62 } // namespace wm |
| 63 } // namespace mash |
OLD | NEW |