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

Unified Diff: ui/compositor/clone_layer.cc

Issue 204793004: Makes View::RecreateLayer() and Window::RecreateLayer() the same (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/compositor/clone_layer.h ('k') | ui/compositor/compositor.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/clone_layer.cc
diff --git a/ui/compositor/clone_layer.cc b/ui/compositor/clone_layer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f1337b0c67cf1a6f861bfd3f4568251d20a730fe
--- /dev/null
+++ b/ui/compositor/clone_layer.cc
@@ -0,0 +1,54 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/compositor/clone_layer.h"
+
+#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_delegate.h"
+#include "ui/compositor/layer_owner.h"
+
+namespace ui {
+
+scoped_ptr<ui::Layer> CloneLayer(LayerOwner* layer_owner) {
+ scoped_ptr<ui::Layer> old_layer(layer_owner->AcquireLayer());
+ if (!old_layer)
+ return old_layer.Pass();
+
+ LayerDelegate* old_delegate = old_layer->delegate();
+ old_layer->set_delegate(NULL);
+
+ const gfx::Rect layer_bounds(old_layer->bounds());
+ Layer* new_layer = new ui::Layer(old_layer->type());
+ layer_owner->SetLayer(new_layer);
+ new_layer->SetVisible(old_layer->visible());
+ new_layer->set_scale_content(old_layer->scale_content());
+ new_layer->SetBounds(layer_bounds);
+ new_layer->SetMasksToBounds(old_layer->GetMasksToBounds());
+ new_layer->set_name(old_layer->name());
+ new_layer->SetFillsBoundsOpaquely(old_layer->fills_bounds_opaquely());
+
+ // Install new layer as a sibling of the old layer, stacked below it.
+ if (old_layer->parent()) {
+ old_layer->parent()->Add(new_layer);
+ old_layer->parent()->StackBelow(new_layer, old_layer.get());
+ }
+
+ // Migrate all the child layers over to the new layer. Copy the list because
+ // the items are removed during iteration.
+ std::vector<ui::Layer*> children_copy = old_layer->children();
+ for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin();
+ it != children_copy.end();
+ ++it) {
+ ui::Layer* child = *it;
+ new_layer->Add(child);
+ }
+
+ // Install the delegate last so that the delegate isn't notified as we copy
+ // state to the new layer.
+ new_layer->set_delegate(old_delegate);
+
+ return old_layer.Pass();
+}
+
+} // namespace ui
« no previous file with comments | « ui/compositor/clone_layer.h ('k') | ui/compositor/compositor.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698