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

Side by Side Diff: ui/wm/core/window_util.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase Created 4 years, 2 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
« ui/compositor/layer.cc ('K') | « ui/wm/core/window_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/wm/core/window_util.h" 5 #include "ui/wm/core/window_util.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
8 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
9 #include "ui/compositor/layer_tree_owner.h" 10 #include "ui/compositor/layer_tree_owner.h"
10 #include "ui/wm/core/transient_window_manager.h" 11 #include "ui/wm/core/transient_window_manager.h"
11 #include "ui/wm/public/activation_client.h" 12 #include "ui/wm/public/activation_client.h"
12 13
13 namespace { 14 namespace {
14 15
15 // Invokes RecreateLayer() on all the children of |to_clone|, adding the newly 16 // Invokes RecreateLayer() on all the children of |to_clone|, adding the newly
16 // cloned children to |parent|. 17 // cloned children to |parent|.
(...skipping 13 matching lines...) Expand all
30 old_layer->set_delegate( 31 old_layer->set_delegate(
31 factory->CreateDelegate(old_layer, owner->layer())); 32 factory->CreateDelegate(old_layer, owner->layer()));
32 parent->Add(old_layer); 33 parent->Add(old_layer);
33 // RecreateLayer() moves the existing children to the new layer. Create a 34 // RecreateLayer() moves the existing children to the new layer. Create a
34 // copy of those. 35 // copy of those.
35 CloneChildren(owner->layer(), old_layer, factory); 36 CloneChildren(owner->layer(), old_layer, factory);
36 } 37 }
37 } 38 }
38 } 39 }
39 40
41 // Invokes Mirror() on all the children of |to_mirror|, adding the newly cloned
42 // children to |parent|.
43 //
44 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner.
45 void MirrorChildren(ui::Layer* to_mirror,
46 ui::Layer* parent,
47 wm::LayerDelegateFactory* factory,
48 bool sync_bounds) {
49 for (auto* child : to_mirror->children()) {
50 child->set_sync_bounds(sync_bounds);
51 ui::Layer* mirror = child->Mirror().release();
52 if (factory && child->delegate())
53 mirror->set_delegate(factory->CreateDelegate(mirror, child));
54 parent->Add(mirror);
55 MirrorChildren(child, mirror, factory, sync_bounds);
56 }
57 }
58
40 } // namespace 59 } // namespace
41 60
42 namespace wm { 61 namespace wm {
43 62
44 void ActivateWindow(aura::Window* window) { 63 void ActivateWindow(aura::Window* window) {
45 DCHECK(window); 64 DCHECK(window);
46 DCHECK(window->GetRootWindow()); 65 DCHECK(window->GetRootWindow());
47 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( 66 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow(
48 window); 67 window);
49 } 68 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 100
82 aura::Window* GetToplevelWindow(aura::Window* window) { 101 aura::Window* GetToplevelWindow(aura::Window* window) {
83 aura::client::ActivationClient* client = 102 aura::client::ActivationClient* client =
84 aura::client::GetActivationClient(window->GetRootWindow()); 103 aura::client::GetActivationClient(window->GetRootWindow());
85 return client ? client->GetToplevelWindow(window) : NULL; 104 return client ? client->GetToplevelWindow(window) : NULL;
86 } 105 }
87 106
88 std::unique_ptr<ui::LayerTreeOwner> RecreateLayers( 107 std::unique_ptr<ui::LayerTreeOwner> RecreateLayers(
89 ui::LayerOwner* root, 108 ui::LayerOwner* root,
90 LayerDelegateFactory* factory) { 109 LayerDelegateFactory* factory) {
91 std::unique_ptr<ui::LayerTreeOwner> old_layer( 110 auto old_layer = base::MakeUnique<ui::LayerTreeOwner>(root->RecreateLayer());
92 new ui::LayerTreeOwner(root->RecreateLayer().release()));
93 if (old_layer->root()) { 111 if (old_layer->root()) {
94 if (factory) { 112 if (factory) {
95 old_layer->root()->set_delegate( 113 old_layer->root()->set_delegate(
96 factory->CreateDelegate(old_layer->root(), root->layer())); 114 factory->CreateDelegate(old_layer->root(), root->layer()));
97 } 115 }
98 CloneChildren(root->layer(), old_layer->root(), factory); 116 CloneChildren(root->layer(), old_layer->root(), factory);
99 } 117 }
100 return old_layer; 118 return old_layer;
101 } 119 }
102 120
121 std::unique_ptr<ui::LayerTreeOwner> MirrorLayers(
122 ui::LayerOwner* root,
123 LayerDelegateFactory* factory,
124 bool sync_bounds) {
125 auto mirror = base::MakeUnique<ui::LayerTreeOwner>(root->layer()->Mirror());
126 if (factory) {
127 mirror->root()->set_delegate(
128 factory->CreateDelegate(mirror->root(), root->layer()));
129 }
130 MirrorChildren(root->layer(), mirror->root(), factory, sync_bounds);
131 return mirror;
132 }
133
103 aura::Window* GetTransientParent(aura::Window* window) { 134 aura::Window* GetTransientParent(aura::Window* window) {
104 return const_cast<aura::Window*>(GetTransientParent( 135 return const_cast<aura::Window*>(GetTransientParent(
105 const_cast<const aura::Window*>(window))); 136 const_cast<const aura::Window*>(window)));
106 } 137 }
107 138
108 const aura::Window* GetTransientParent(const aura::Window* window) { 139 const aura::Window* GetTransientParent(const aura::Window* window) {
109 const TransientWindowManager* manager = TransientWindowManager::Get(window); 140 const TransientWindowManager* manager = TransientWindowManager::Get(window);
110 return manager ? manager->transient_parent() : NULL; 141 return manager ? manager->transient_parent() : NULL;
111 } 142 }
112 143
(...skipping 18 matching lines...) Expand all
131 bool HasTransientAncestor(const aura::Window* window, 162 bool HasTransientAncestor(const aura::Window* window,
132 const aura::Window* ancestor) { 163 const aura::Window* ancestor) {
133 const aura::Window* transient_parent = GetTransientParent(window); 164 const aura::Window* transient_parent = GetTransientParent(window);
134 if (transient_parent == ancestor) 165 if (transient_parent == ancestor)
135 return true; 166 return true;
136 return transient_parent ? 167 return transient_parent ?
137 HasTransientAncestor(transient_parent, ancestor) : false; 168 HasTransientAncestor(transient_parent, ancestor) : false;
138 } 169 }
139 170
140 } // namespace wm 171 } // namespace wm
OLDNEW
« ui/compositor/layer.cc ('K') | « ui/wm/core/window_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698