OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/compositor/clone_layer.h" |
| 6 |
| 7 #include "ui/compositor/layer.h" |
| 8 #include "ui/compositor/layer_delegate.h" |
| 9 #include "ui/compositor/layer_owner.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 scoped_ptr<ui::Layer> CloneLayer(LayerOwner* layer_owner) { |
| 14 scoped_ptr<ui::Layer> old_layer(layer_owner->AcquireLayer()); |
| 15 if (!old_layer) |
| 16 return old_layer.Pass(); |
| 17 |
| 18 LayerDelegate* old_delegate = old_layer->delegate(); |
| 19 old_layer->set_delegate(NULL); |
| 20 |
| 21 const gfx::Rect layer_bounds(old_layer->bounds()); |
| 22 Layer* new_layer = new ui::Layer(old_layer->type()); |
| 23 layer_owner->SetLayer(new_layer); |
| 24 new_layer->SetVisible(old_layer->visible()); |
| 25 new_layer->set_scale_content(old_layer->scale_content()); |
| 26 new_layer->SetBounds(layer_bounds); |
| 27 new_layer->SetMasksToBounds(old_layer->GetMasksToBounds()); |
| 28 new_layer->set_name(old_layer->name()); |
| 29 new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely()); |
| 30 |
| 31 // Install new layer as a sibling of the old layer, stacked below it. |
| 32 if (old_layer->parent()) { |
| 33 old_layer->parent()->Add(new_layer); |
| 34 old_layer->parent()->StackBelow(new_layer, old_layer.get()); |
| 35 } |
| 36 |
| 37 // Migrate all the child layers over to the new layer. Copy the list because |
| 38 // the items are removed during iteration. |
| 39 std::vector<ui::Layer*> children_copy = old_layer->children(); |
| 40 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); |
| 41 it != children_copy.end(); |
| 42 ++it) { |
| 43 ui::Layer* child = *it; |
| 44 new_layer->Add(child); |
| 45 } |
| 46 |
| 47 // Install the delegate last so that the delegate isn't notified as we copy |
| 48 // state to the new layer. |
| 49 new_layer->set_delegate(old_delegate); |
| 50 |
| 51 return old_layer.Pass(); |
| 52 } |
| 53 |
| 54 } // namespace ui |
OLD | NEW |