| 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 "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|. |
| 17 // | 18 // |
| 18 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. | 19 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. |
| 19 void CloneChildren(ui::Layer* to_clone, | 20 void CloneChildren(ui::Layer* to_clone, ui::Layer* parent) { |
| 20 ui::Layer* parent, | |
| 21 wm::LayerDelegateFactory* factory) { | |
| 22 typedef std::vector<ui::Layer*> Layers; | 21 typedef std::vector<ui::Layer*> Layers; |
| 23 // Make a copy of the children since RecreateLayer() mutates it. | 22 // Make a copy of the children since RecreateLayer() mutates it. |
| 24 Layers children(to_clone->children()); | 23 Layers children(to_clone->children()); |
| 25 for (Layers::const_iterator i = children.begin(); i != children.end(); ++i) { | 24 for (Layers::const_iterator i = children.begin(); i != children.end(); ++i) { |
| 26 ui::LayerOwner* owner = (*i)->owner(); | 25 ui::LayerOwner* owner = (*i)->owner(); |
| 27 ui::Layer* old_layer = owner ? owner->RecreateLayer().release() : NULL; | 26 ui::Layer* old_layer = owner ? owner->RecreateLayer().release() : NULL; |
| 28 if (old_layer) { | 27 if (old_layer) { |
| 29 if (factory && owner->layer()->delegate()) | |
| 30 old_layer->set_delegate( | |
| 31 factory->CreateDelegate(old_layer, owner->layer())); | |
| 32 parent->Add(old_layer); | 28 parent->Add(old_layer); |
| 33 // RecreateLayer() moves the existing children to the new layer. Create a | 29 // RecreateLayer() moves the existing children to the new layer. Create a |
| 34 // copy of those. | 30 // copy of those. |
| 35 CloneChildren(owner->layer(), old_layer, factory); | 31 CloneChildren(owner->layer(), old_layer); |
| 36 } | 32 } |
| 37 } | 33 } |
| 38 } | 34 } |
| 39 | 35 |
| 36 // Invokes Mirror() on all the children of |to_mirror|, adding the newly cloned |
| 37 // children to |parent|. |
| 38 // |
| 39 // WARNING: It is assumed that |parent| is ultimately owned by a LayerTreeOwner. |
| 40 void MirrorChildren(ui::Layer* to_mirror, |
| 41 ui::Layer* parent, |
| 42 bool sync_bounds) { |
| 43 for (auto* child : to_mirror->children()) { |
| 44 child->set_sync_bounds(sync_bounds); |
| 45 ui::Layer* mirror = child->Mirror().release(); |
| 46 parent->Add(mirror); |
| 47 MirrorChildren(child, mirror, sync_bounds); |
| 48 } |
| 49 } |
| 50 |
| 40 } // namespace | 51 } // namespace |
| 41 | 52 |
| 42 namespace wm { | 53 namespace wm { |
| 43 | 54 |
| 44 void ActivateWindow(aura::Window* window) { | 55 void ActivateWindow(aura::Window* window) { |
| 45 DCHECK(window); | 56 DCHECK(window); |
| 46 DCHECK(window->GetRootWindow()); | 57 DCHECK(window->GetRootWindow()); |
| 47 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( | 58 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( |
| 48 window); | 59 window); |
| 49 } | 60 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 aura::client::GetActivationClient(window->GetRootWindow()); | 89 aura::client::GetActivationClient(window->GetRootWindow()); |
| 79 return client ? client->GetActivatableWindow(window) : NULL; | 90 return client ? client->GetActivatableWindow(window) : NULL; |
| 80 } | 91 } |
| 81 | 92 |
| 82 aura::Window* GetToplevelWindow(aura::Window* window) { | 93 aura::Window* GetToplevelWindow(aura::Window* window) { |
| 83 aura::client::ActivationClient* client = | 94 aura::client::ActivationClient* client = |
| 84 aura::client::GetActivationClient(window->GetRootWindow()); | 95 aura::client::GetActivationClient(window->GetRootWindow()); |
| 85 return client ? client->GetToplevelWindow(window) : NULL; | 96 return client ? client->GetToplevelWindow(window) : NULL; |
| 86 } | 97 } |
| 87 | 98 |
| 88 std::unique_ptr<ui::LayerTreeOwner> RecreateLayers( | 99 std::unique_ptr<ui::LayerTreeOwner> RecreateLayers(ui::LayerOwner* root) { |
| 89 ui::LayerOwner* root, | 100 DCHECK(root->OwnsLayer()); |
| 90 LayerDelegateFactory* factory) { | 101 auto old_layer = base::MakeUnique<ui::LayerTreeOwner>(root->RecreateLayer()); |
| 91 std::unique_ptr<ui::LayerTreeOwner> old_layer( | 102 CloneChildren(root->layer(), old_layer->root()); |
| 92 new ui::LayerTreeOwner(root->RecreateLayer().release())); | |
| 93 if (old_layer->root()) { | |
| 94 if (factory) { | |
| 95 old_layer->root()->set_delegate( | |
| 96 factory->CreateDelegate(old_layer->root(), root->layer())); | |
| 97 } | |
| 98 CloneChildren(root->layer(), old_layer->root(), factory); | |
| 99 } | |
| 100 return old_layer; | 103 return old_layer; |
| 101 } | 104 } |
| 102 | 105 |
| 106 std::unique_ptr<ui::LayerTreeOwner> MirrorLayers( |
| 107 ui::LayerOwner* root, bool sync_bounds) { |
| 108 auto mirror = base::MakeUnique<ui::LayerTreeOwner>(root->layer()->Mirror()); |
| 109 MirrorChildren(root->layer(), mirror->root(), sync_bounds); |
| 110 return mirror; |
| 111 } |
| 112 |
| 103 aura::Window* GetTransientParent(aura::Window* window) { | 113 aura::Window* GetTransientParent(aura::Window* window) { |
| 104 return const_cast<aura::Window*>(GetTransientParent( | 114 return const_cast<aura::Window*>(GetTransientParent( |
| 105 const_cast<const aura::Window*>(window))); | 115 const_cast<const aura::Window*>(window))); |
| 106 } | 116 } |
| 107 | 117 |
| 108 const aura::Window* GetTransientParent(const aura::Window* window) { | 118 const aura::Window* GetTransientParent(const aura::Window* window) { |
| 109 const TransientWindowManager* manager = TransientWindowManager::Get(window); | 119 const TransientWindowManager* manager = TransientWindowManager::Get(window); |
| 110 return manager ? manager->transient_parent() : NULL; | 120 return manager ? manager->transient_parent() : NULL; |
| 111 } | 121 } |
| 112 | 122 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 bool HasTransientAncestor(const aura::Window* window, | 141 bool HasTransientAncestor(const aura::Window* window, |
| 132 const aura::Window* ancestor) { | 142 const aura::Window* ancestor) { |
| 133 const aura::Window* transient_parent = GetTransientParent(window); | 143 const aura::Window* transient_parent = GetTransientParent(window); |
| 134 if (transient_parent == ancestor) | 144 if (transient_parent == ancestor) |
| 135 return true; | 145 return true; |
| 136 return transient_parent ? | 146 return transient_parent ? |
| 137 HasTransientAncestor(transient_parent, ancestor) : false; | 147 HasTransientAncestor(transient_parent, ancestor) : false; |
| 138 } | 148 } |
| 139 | 149 |
| 140 } // namespace wm | 150 } // namespace wm |
| OLD | NEW |