| 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/aura/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 void Window::SetParent(Window* parent) { | 166 void Window::SetParent(Window* parent) { |
| 167 if (parent) | 167 if (parent) |
| 168 parent->AddChild(this); | 168 parent->AddChild(this); |
| 169 else if (Desktop::GetInstance()->delegate()) | 169 else if (Desktop::GetInstance()->delegate()) |
| 170 Desktop::GetInstance()->delegate()->AddChildToDefaultParent(this); | 170 Desktop::GetInstance()->delegate()->AddChildToDefaultParent(this); |
| 171 else | 171 else |
| 172 NOTREACHED(); | 172 NOTREACHED(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void Window::MoveChildToFront(Window* child) { | 175 void Window::MoveChildToFront(Window* child) { |
| 176 DCHECK_EQ(child->parent(), this); | 176 if (children_.size() <= 1 || child == children_.back()) |
| 177 const Windows::iterator i(std::find(children_.begin(), children_.end(), | 177 return; // In the front already. |
| 178 child)); | 178 MoveChildAbove(child, children_.back()); |
| 179 DCHECK(i != children_.end()); | 179 } |
| 180 children_.erase(i); | |
| 181 | 180 |
| 182 children_.insert(children_.begin() + children_.size(), child); | 181 void Window::MoveChildAbove(Window* child, Window* other) { |
| 183 child->layer()->parent()->MoveToFront(child->layer()); | 182 DCHECK_NE(child, other); |
| 184 // Repaint the window as active status may have changed. | 183 DCHECK(child); |
| 185 SchedulePaintInRect(gfx::Rect()); | 184 DCHECK(other); |
| 185 DCHECK_EQ(this, child->parent()); |
| 186 DCHECK_EQ(this, other->parent()); |
| 187 |
| 188 size_t child_i = |
| 189 std::find(children_.begin(), children_.end(), child) - children_.begin(); |
| 190 size_t other_i = |
| 191 std::find(children_.begin(), children_.end(), other) - children_.begin(); |
| 192 if (child_i > other_i) |
| 193 return; // Already in front of |other|. |
| 194 |
| 195 // Reorder children. |
| 196 children_.erase(children_.begin() + child_i); |
| 197 children_.insert(children_.begin() + other_i, child); |
| 198 |
| 199 // Reorder the layer. |
| 200 layer()->MoveAbove(child->layer(), other->layer()); |
| 186 | 201 |
| 187 // Move any transient children that share the same parent to be in front of | 202 // Move any transient children that share the same parent to be in front of |
| 188 // us. | 203 // 'child'. |
| 204 Window* last_transient = child; |
| 189 for (Windows::iterator i = child->transient_children_.begin(); | 205 for (Windows::iterator i = child->transient_children_.begin(); |
| 190 i != child->transient_children_.end(); ++i) { | 206 i != child->transient_children_.end(); ++i) { |
| 191 Window* transient_child = *i; | 207 Window* transient_child = *i; |
| 192 if (transient_child->parent_ == this) | 208 if (transient_child->parent_ == this) { |
| 193 MoveChildToFront(transient_child); | 209 MoveChildAbove(transient_child, last_transient); |
| 210 last_transient = transient_child; |
| 211 } |
| 194 } | 212 } |
| 195 } | 213 } |
| 196 | 214 |
| 197 bool Window::CanActivate() const { | 215 bool Window::CanActivate() const { |
| 198 return IsVisible() && delegate_ && delegate_->ShouldActivate(NULL); | 216 return IsVisible() && delegate_ && delegate_->ShouldActivate(NULL); |
| 199 } | 217 } |
| 200 | 218 |
| 201 void Window::AddChild(Window* child) { | 219 void Window::AddChild(Window* child) { |
| 202 DCHECK(std::find(children_.begin(), children_.end(), child) == | 220 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 203 children_.end()); | 221 children_.end()); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 492 } |
| 475 | 493 |
| 476 return delegate_ ? this : NULL; | 494 return delegate_ ? this : NULL; |
| 477 } | 495 } |
| 478 | 496 |
| 479 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 497 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 480 delegate_->OnPaint(canvas); | 498 delegate_->OnPaint(canvas); |
| 481 } | 499 } |
| 482 | 500 |
| 483 } // namespace aura | 501 } // namespace aura |
| OLD | NEW |