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