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

Unified Diff: ui/gfx/compositor/layer.cc

Issue 8477019: Adds Window::MoveChildToFront, with surrounding changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 years, 1 month 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/gfx/compositor/layer.h ('k') | ui/gfx/rect.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/compositor/layer.cc
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index 67f2cde86f4d91735d590b44c0cf2a98e1714f9b..2b98d44e7a61015df987bcbf31fb4d9513761a49 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -115,14 +115,29 @@ void Layer::Remove(Layer* child) {
}
void Layer::MoveToFront(Layer* child) {
- std::vector<Layer*>::iterator i =
- std::find(children_.begin(), children_.end(), child);
- DCHECK(i != children_.end());
- children_.erase(i);
- children_.push_back(child);
+ if (children_.size() <= 1 || child == children_.back())
+ return; // Already in front.
+ MoveAbove(child, children_.back());
+}
+
+void Layer::MoveAbove(Layer* child, Layer* other) {
+ DCHECK_NE(child, other);
+ DCHECK_EQ(this, child->parent());
+ DCHECK_EQ(this, other->parent());
+ size_t child_i =
+ std::find(children_.begin(), children_.end(), child) - children_.begin();
+ size_t other_i =
+ std::find(children_.begin(), children_.end(), other) - children_.begin();
+ if (child_i > other_i)
+ return; // Already in front of |other|.
+
+ // Reorder children.
+ children_.erase(children_.begin() + child_i);
+ children_.insert(children_.begin() + other_i, child);
+
#if defined(USE_WEBKIT_COMPOSITOR)
child->web_layer_.removeFromParent();
- web_layer_.addChild(child->web_layer_);
+ web_layer_.insertChild(child->web_layer_, other_i);
#endif
}
« no previous file with comments | « ui/gfx/compositor/layer.h ('k') | ui/gfx/rect.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698