Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: ash/mus/disconnected_app_handler.cc

Issue 2629523006: chromeos: changes DisconnectedAppHandler to be associated with a single window (Closed)
Patch Set: merge Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/disconnected_app_handler.h ('k') | ash/mus/root_window_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
OLDNEW
« no previous file with comments | « ash/mus/disconnected_app_handler.h ('k') | ash/mus/root_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698