OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/compositor/layer.h" | 5 #include "ui/gfx/compositor/layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 #if defined(USE_WEBKIT_COMPOSITOR) | 108 #if defined(USE_WEBKIT_COMPOSITOR) |
109 child->web_layer_.removeFromParent(); | 109 child->web_layer_.removeFromParent(); |
110 #endif | 110 #endif |
111 | 111 |
112 RecomputeHole(); | 112 RecomputeHole(); |
113 | 113 |
114 child->DropTextures(); | 114 child->DropTextures(); |
115 } | 115 } |
116 | 116 |
117 void Layer::MoveToFront(Layer* child) { | 117 void Layer::MoveToFront(Layer* child) { |
118 std::vector<Layer*>::iterator i = | 118 if (children_.size() <= 1 || child == children_.back()) |
119 std::find(children_.begin(), children_.end(), child); | 119 return; // Already in front. |
120 DCHECK(i != children_.end()); | 120 MoveAbove(child, children_.back()); |
121 children_.erase(i); | 121 } |
122 children_.push_back(child); | 122 |
| 123 void Layer::MoveAbove(Layer* child, Layer* other) { |
| 124 DCHECK_NE(child, other); |
| 125 DCHECK_EQ(this, child->parent()); |
| 126 DCHECK_EQ(this, other->parent()); |
| 127 size_t child_i = |
| 128 std::find(children_.begin(), children_.end(), child) - children_.begin(); |
| 129 size_t other_i = |
| 130 std::find(children_.begin(), children_.end(), other) - children_.begin(); |
| 131 if (child_i > other_i) |
| 132 return; // Already in front of |other|. |
| 133 |
| 134 // Reorder children. |
| 135 children_.erase(children_.begin() + child_i); |
| 136 children_.insert(children_.begin() + other_i, child); |
| 137 |
123 #if defined(USE_WEBKIT_COMPOSITOR) | 138 #if defined(USE_WEBKIT_COMPOSITOR) |
124 child->web_layer_.removeFromParent(); | 139 child->web_layer_.removeFromParent(); |
125 web_layer_.addChild(child->web_layer_); | 140 web_layer_.insertChild(child->web_layer_, other_i); |
126 #endif | 141 #endif |
127 } | 142 } |
128 | 143 |
129 bool Layer::Contains(const Layer* other) const { | 144 bool Layer::Contains(const Layer* other) const { |
130 for (const Layer* parent = other; parent; parent = parent->parent()) { | 145 for (const Layer* parent = other; parent; parent = parent->parent()) { |
131 if (parent == this) | 146 if (parent == this) |
132 return true; | 147 return true; |
133 } | 148 } |
134 return false; | 149 return false; |
135 } | 150 } |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 #else | 678 #else |
664 unsigned int texture_id = 0; | 679 unsigned int texture_id = 0; |
665 #endif | 680 #endif |
666 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( | 681 web_layer_.to<WebKit::WebExternalTextureLayer>().setTextureId( |
667 should_draw ? texture_id : 0); | 682 should_draw ? texture_id : 0); |
668 } | 683 } |
669 } | 684 } |
670 #endif | 685 #endif |
671 | 686 |
672 } // namespace ui | 687 } // namespace ui |
OLD | NEW |