OLD | NEW |
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 "base/memory/ptr_util.h" |
8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
11 #include "ui/compositor/layer_tree_owner.h" | 11 #include "ui/compositor/layer_tree_owner.h" |
12 #include "ui/wm/core/transient_window_manager.h" | 12 #include "ui/wm/core/transient_window_manager.h" |
13 #include "ui/wm/public/activation_client.h" | 13 #include "ui/wm/public/activation_client.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Invokes RecreateLayer() on all the children of |to_clone|, adding the newly | 17 // Invokes |map_func| on all the children of |to_clone|, adding the newly |
18 // cloned children to |parent|. | 18 // cloned children to |parent|. If |map_func| returns nullptr on |
| 19 // the layer owner, all its layer's children will not be cloned. |
19 // | 20 // |
20 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. | 21 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. |
21 void CloneChildren(ui::Layer* to_clone, ui::Layer* parent) { | 22 void CloneChildren(ui::Layer* to_clone, |
| 23 ui::Layer* parent, |
| 24 const wm::MapLayerFunc& map_func) { |
22 typedef std::vector<ui::Layer*> Layers; | 25 typedef std::vector<ui::Layer*> Layers; |
23 // Make a copy of the children since RecreateLayer() mutates it. | 26 // Make a copy of the children since RecreateLayer() mutates it. |
24 Layers children(to_clone->children()); | 27 Layers children(to_clone->children()); |
25 for (Layers::const_iterator i = children.begin(); i != children.end(); ++i) { | 28 for (Layers::const_iterator i = children.begin(); i != children.end(); ++i) { |
26 ui::LayerOwner* owner = (*i)->owner(); | 29 ui::LayerOwner* owner = (*i)->owner(); |
27 ui::Layer* old_layer = owner ? owner->RecreateLayer().release() : NULL; | 30 ui::Layer* old_layer = owner ? map_func.Run(owner).release() : NULL; |
28 if (old_layer) { | 31 if (old_layer) { |
29 parent->Add(old_layer); | 32 parent->Add(old_layer); |
30 // RecreateLayer() moves the existing children to the new layer. Create a | 33 // RecreateLayer() moves the existing children to the new layer. Create a |
31 // copy of those. | 34 // copy of those. |
32 CloneChildren(owner->layer(), old_layer); | 35 CloneChildren(owner->layer(), old_layer, map_func); |
33 } | 36 } |
34 } | 37 } |
35 } | 38 } |
36 | 39 |
37 // Invokes Mirror() on all the children of |to_mirror|, adding the newly cloned | 40 // Invokes Mirror() on all the children of |to_mirror|, adding the newly cloned |
38 // children to |parent|. | 41 // children to |parent|. |
39 // | 42 // |
40 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. | 43 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. |
41 void MirrorChildren(ui::Layer* to_mirror, | 44 void MirrorChildren(ui::Layer* to_mirror, |
42 ui::Layer* parent, | 45 ui::Layer* parent, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 128 } |
126 | 129 |
127 aura::Window* GetToplevelWindow(aura::Window* window) { | 130 aura::Window* GetToplevelWindow(aura::Window* window) { |
128 aura::client::ActivationClient* client = | 131 aura::client::ActivationClient* client = |
129 aura::client::GetActivationClient(window->GetRootWindow()); | 132 aura::client::GetActivationClient(window->GetRootWindow()); |
130 return client ? client->GetToplevelWindow(window) : NULL; | 133 return client ? client->GetToplevelWindow(window) : NULL; |
131 } | 134 } |
132 | 135 |
133 std::unique_ptr<ui::LayerTreeOwner> RecreateLayers(ui::LayerOwner* root) { | 136 std::unique_ptr<ui::LayerTreeOwner> RecreateLayers(ui::LayerOwner* root) { |
134 DCHECK(root->OwnsLayer()); | 137 DCHECK(root->OwnsLayer()); |
135 auto old_layer = base::MakeUnique<ui::LayerTreeOwner>(root->RecreateLayer()); | 138 return MapLayers(root, base::Bind([](ui::LayerOwner* owner) { |
136 CloneChildren(root->layer(), old_layer->root()); | 139 return owner->RecreateLayer(); |
| 140 })); |
| 141 } |
| 142 |
| 143 std::unique_ptr<ui::LayerTreeOwner> MapLayers(ui::LayerOwner* root, |
| 144 const MapLayerFunc& map_func) { |
| 145 DCHECK(root->OwnsLayer()); |
| 146 auto layer = map_func.Run(root); |
| 147 if (!layer) |
| 148 return nullptr; |
| 149 auto old_layer = base::MakeUnique<ui::LayerTreeOwner>(std::move(layer)); |
| 150 CloneChildren(root->layer(), old_layer->root(), map_func); |
137 return old_layer; | 151 return old_layer; |
138 } | 152 } |
139 | 153 |
140 std::unique_ptr<ui::LayerTreeOwner> MirrorLayers( | 154 std::unique_ptr<ui::LayerTreeOwner> MirrorLayers( |
141 ui::LayerOwner* root, bool sync_bounds) { | 155 ui::LayerOwner* root, bool sync_bounds) { |
142 auto mirror = base::MakeUnique<ui::LayerTreeOwner>(root->layer()->Mirror()); | 156 auto mirror = base::MakeUnique<ui::LayerTreeOwner>(root->layer()->Mirror()); |
143 MirrorChildren(root->layer(), mirror->root(), sync_bounds); | 157 MirrorChildren(root->layer(), mirror->root(), sync_bounds); |
144 return mirror; | 158 return mirror; |
145 } | 159 } |
146 | 160 |
(...skipping 28 matching lines...) Expand all Loading... |
175 bool HasTransientAncestor(const aura::Window* window, | 189 bool HasTransientAncestor(const aura::Window* window, |
176 const aura::Window* ancestor) { | 190 const aura::Window* ancestor) { |
177 const aura::Window* transient_parent = GetTransientParent(window); | 191 const aura::Window* transient_parent = GetTransientParent(window); |
178 if (transient_parent == ancestor) | 192 if (transient_parent == ancestor) |
179 return true; | 193 return true; |
180 return transient_parent ? | 194 return transient_parent ? |
181 HasTransientAncestor(transient_parent, ancestor) : false; | 195 HasTransientAncestor(transient_parent, ancestor) : false; |
182 } | 196 } |
183 | 197 |
184 } // namespace wm | 198 } // namespace wm |
OLD | NEW |