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

Side by Side 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: comment 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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
oshima 2014/03/19 18:12:44 two spaces between } and //
sky 2014/03/19 18:24:13 That's what I get for copying from another file.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698