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

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