| 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 "ash/mus/disconnected_app_handler.h" | 5 #include "ash/mus/disconnected_app_handler.h" |
| 6 | 6 |
| 7 #include "ash/common/wm_window.h" | 7 #include "ash/common/wm_window.h" |
| 8 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_property.h" |
| 11 |
| 12 DECLARE_WINDOW_PROPERTY_TYPE(ash::mus::DisconnectedAppHandler*); |
| 10 | 13 |
| 11 namespace ash { | 14 namespace ash { |
| 12 namespace mus { | 15 namespace mus { |
| 13 namespace { | 16 namespace { |
| 14 | 17 |
| 15 bool IsContainer(aura::Window* window) { | 18 DEFINE_OWNED_WINDOW_PROPERTY_KEY(DisconnectedAppHandler, |
| 16 return WmWindow::Get(window)->GetShellWindowId() != kShellWindowId_Invalid; | 19 kDisconnectedAppHandlerKey, |
| 17 } | 20 nullptr); |
| 18 | 21 |
| 19 } // namespace | 22 } // namespace |
| 20 | 23 |
| 21 DisconnectedAppHandler::DisconnectedAppHandler(aura::Window* root_window) { | 24 // static |
| 22 WmWindow* root = WmWindow::Get(root_window); | 25 void DisconnectedAppHandler::Create(aura::Window* window) { |
| 23 for (int shell_window_id = kShellWindowId_Min; | 26 window->SetProperty(kDisconnectedAppHandlerKey, |
| 24 shell_window_id < kShellWindowId_Max; ++shell_window_id) { | 27 new DisconnectedAppHandler(window)); |
| 25 // kShellWindowId_VirtualKeyboardContainer is lazily created. | |
| 26 // TODO(sky): http://crbug.com/616909 . | |
| 27 // kShellWindowId_PhantomWindow is not a container, but a window. | |
| 28 if (shell_window_id == kShellWindowId_VirtualKeyboardContainer || | |
| 29 shell_window_id == kShellWindowId_PhantomWindow) | |
| 30 continue; | |
| 31 | |
| 32 // kShellWindowId_MouseCursorContainer is chromeos specific. | |
| 33 #if !defined(OS_CHROMEOS) | |
| 34 if (shell_window_id == kShellWindowId_MouseCursorContainer) | |
| 35 continue; | |
| 36 #endif | |
| 37 | |
| 38 WmWindow* container = root->GetChildByShellWindowId(shell_window_id); | |
| 39 Add(container->aura_window()); | |
| 40 | |
| 41 // Add any pre-existing windows in the container to | |
| 42 // |disconnected_app_handler_|. | |
| 43 for (aura::Window* child : container->aura_window()->children()) { | |
| 44 if (!IsContainer(child)) | |
| 45 Add(child); | |
| 46 } | |
| 47 } | |
| 48 } | 28 } |
| 49 | 29 |
| 50 DisconnectedAppHandler::~DisconnectedAppHandler() {} | 30 DisconnectedAppHandler::DisconnectedAppHandler(aura::Window* window) |
| 31 : window_(window) { |
| 32 window->AddObserver(this); |
| 33 } |
| 34 |
| 35 DisconnectedAppHandler::~DisconnectedAppHandler() { |
| 36 window_->RemoveObserver(this); |
| 37 } |
| 51 | 38 |
| 52 void DisconnectedAppHandler::OnEmbeddedAppDisconnected(aura::Window* window) { | 39 void DisconnectedAppHandler::OnEmbeddedAppDisconnected(aura::Window* window) { |
| 53 if (!IsContainer(window)) | 40 delete window_; |
| 54 delete window; | |
| 55 } | |
| 56 | |
| 57 void DisconnectedAppHandler::OnWindowHierarchyChanging( | |
| 58 const HierarchyChangeParams& params) { | |
| 59 if (params.old_parent == params.receiver && IsContainer(params.old_parent)) | |
| 60 Remove(params.target); | |
| 61 | |
| 62 if (params.new_parent == params.receiver && IsContainer(params.new_parent)) | |
| 63 Add(params.target); | |
| 64 | |
| 65 aura::WindowTracker::OnWindowHierarchyChanging(params); | |
| 66 } | 41 } |
| 67 | 42 |
| 68 } // namespace mus | 43 } // namespace mus |
| 69 } // namespace ash | 44 } // namespace ash |
| OLD | NEW |