OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 void Window::StackChildAbove(Window* child, Window* target) { | 343 void Window::StackChildAbove(Window* child, Window* target) { |
344 StackChildRelativeTo(child, target, STACK_ABOVE); | 344 StackChildRelativeTo(child, target, STACK_ABOVE); |
345 } | 345 } |
346 | 346 |
347 void Window::StackChildBelow(Window* child, Window* target) { | 347 void Window::StackChildBelow(Window* child, Window* target) { |
348 StackChildRelativeTo(child, target, STACK_BELOW); | 348 StackChildRelativeTo(child, target, STACK_BELOW); |
349 } | 349 } |
350 | 350 |
351 void Window::AddChild(Window* child) { | 351 void Window::AddChild(Window* child) { |
352 RootWindow* old_root = child->GetRootWindow(); | |
353 | |
354 DCHECK(std::find(children_.begin(), children_.end(), child) == | 352 DCHECK(std::find(children_.begin(), children_.end(), child) == |
355 children_.end()); | 353 children_.end()); |
356 if (child->parent()) | 354 if (child->parent()) |
357 child->parent()->RemoveChildImpl(child, this); | 355 child->parent()->RemoveChild(child); |
358 child->parent_ = this; | 356 child->parent_ = this; |
359 | 357 |
360 layer_->Add(child->layer_); | 358 layer_->Add(child->layer_); |
361 | 359 |
362 children_.push_back(child); | 360 children_.push_back(child); |
363 if (layout_manager_.get()) | 361 if (layout_manager_.get()) |
364 layout_manager_->OnWindowAddedToLayout(child); | 362 layout_manager_->OnWindowAddedToLayout(child); |
365 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); | 363 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); |
366 child->OnParentChanged(); | 364 child->OnParentChanged(); |
367 | 365 |
368 RootWindow* root_window = GetRootWindow(); | 366 RootWindow* root_window = child->GetRootWindow(); |
369 if (root_window && old_root != root_window) { | 367 if (root_window) { |
370 root_window->OnWindowAddedToRootWindow(child); | 368 root_window->OnWindowAddedToRootWindow(child); |
371 child->NotifyAddedToRootWindow(); | 369 child->NotifyAddedToRootWindow(); |
372 } | 370 } |
373 } | 371 } |
374 | 372 |
375 void Window::AddTransientChild(Window* child) { | 373 void Window::AddTransientChild(Window* child) { |
376 if (child->transient_parent_) | 374 if (child->transient_parent_) |
377 child->transient_parent_->RemoveTransientChild(child); | 375 child->transient_parent_->RemoveTransientChild(child); |
378 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), | 376 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), |
379 child) == transient_children_.end()); | 377 child) == transient_children_.end()); |
380 transient_children_.push_back(child); | 378 transient_children_.push_back(child); |
381 child->transient_parent_ = this; | 379 child->transient_parent_ = this; |
382 } | 380 } |
383 | 381 |
384 void Window::RemoveTransientChild(Window* child) { | 382 void Window::RemoveTransientChild(Window* child) { |
385 Windows::iterator i = | 383 Windows::iterator i = |
386 std::find(transient_children_.begin(), transient_children_.end(), child); | 384 std::find(transient_children_.begin(), transient_children_.end(), child); |
387 DCHECK(i != transient_children_.end()); | 385 DCHECK(i != transient_children_.end()); |
388 transient_children_.erase(i); | 386 transient_children_.erase(i); |
389 if (child->transient_parent_ == this) | 387 if (child->transient_parent_ == this) |
390 child->transient_parent_ = NULL; | 388 child->transient_parent_ = NULL; |
391 } | 389 } |
392 | 390 |
393 void Window::RemoveChild(Window* child) { | 391 void Window::RemoveChild(Window* child) { |
394 RemoveChildImpl(child, NULL); | 392 Windows::iterator i = std::find(children_.begin(), children_.end(), child); |
| 393 DCHECK(i != children_.end()); |
| 394 if (layout_manager_.get()) |
| 395 layout_manager_->OnWillRemoveWindowFromLayout(child); |
| 396 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); |
| 397 RootWindow* root_window = child->GetRootWindow(); |
| 398 if (root_window) { |
| 399 root_window->OnWindowRemovedFromRootWindow(child); |
| 400 child->NotifyRemovingFromRootWindow(); |
| 401 } |
| 402 child->parent_ = NULL; |
| 403 // We should only remove the child's layer if the child still owns that layer. |
| 404 // Someone else may have acquired ownership of it via AcquireLayer() and may |
| 405 // expect the hierarchy to go unchanged as the Window is destroyed. |
| 406 if (child->layer_owner_.get()) |
| 407 layer_->Remove(child->layer_); |
| 408 children_.erase(i); |
| 409 child->OnParentChanged(); |
| 410 if (layout_manager_.get()) |
| 411 layout_manager_->OnWindowRemovedFromLayout(child); |
395 } | 412 } |
396 | 413 |
397 bool Window::Contains(const Window* other) const { | 414 bool Window::Contains(const Window* other) const { |
398 for (const Window* parent = other; parent; parent = parent->parent_) { | 415 for (const Window* parent = other; parent; parent = parent->parent_) { |
399 if (parent == this) | 416 if (parent == this) |
400 return true; | 417 return true; |
401 } | 418 } |
402 return false; | 419 return false; |
403 } | 420 } |
404 | 421 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 Window* match = child->GetWindowForPoint(point_in_child_coords, | 769 Window* match = child->GetWindowForPoint(point_in_child_coords, |
753 return_tightest, | 770 return_tightest, |
754 for_event_handling); | 771 for_event_handling); |
755 if (match) | 772 if (match) |
756 return match; | 773 return match; |
757 } | 774 } |
758 | 775 |
759 return delegate_ ? this : NULL; | 776 return delegate_ ? this : NULL; |
760 } | 777 } |
761 | 778 |
762 void Window::RemoveChildImpl(Window* child, Window* new_parent) { | |
763 Windows::iterator i = std::find(children_.begin(), children_.end(), child); | |
764 DCHECK(i != children_.end()); | |
765 if (layout_manager_.get()) | |
766 layout_manager_->OnWillRemoveWindowFromLayout(child); | |
767 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); | |
768 RootWindow* root_window = child->GetRootWindow(); | |
769 if (root_window && | |
770 (!new_parent || new_parent->GetRootWindow() != root_window)) { | |
771 root_window->OnWindowRemovedFromRootWindow(child); | |
772 child->NotifyRemovingFromRootWindow(); | |
773 } | |
774 child->parent_ = NULL; | |
775 // We should only remove the child's layer if the child still owns that layer. | |
776 // Someone else may have acquired ownership of it via AcquireLayer() and may | |
777 // expect the hierarchy to go unchanged as the Window is destroyed. | |
778 if (child->layer_owner_.get()) | |
779 layer_->Remove(child->layer_); | |
780 children_.erase(i); | |
781 child->OnParentChanged(); | |
782 if (layout_manager_.get()) | |
783 layout_manager_->OnWindowRemovedFromLayout(child); | |
784 } | |
785 | |
786 void Window::OnParentChanged() { | 779 void Window::OnParentChanged() { |
787 FOR_EACH_OBSERVER( | 780 FOR_EACH_OBSERVER( |
788 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); | 781 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); |
789 } | 782 } |
790 | 783 |
791 void Window::StackChildRelativeTo(Window* child, | 784 void Window::StackChildRelativeTo(Window* child, |
792 Window* target, | 785 Window* target, |
793 StackDirection direction) { | 786 StackDirection direction) { |
794 DCHECK_NE(child, target); | 787 DCHECK_NE(child, target); |
795 DCHECK(child); | 788 DCHECK(child); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 for (Windows::const_reverse_iterator it = children_.rbegin(), | 948 for (Windows::const_reverse_iterator it = children_.rbegin(), |
956 rend = children_.rend(); | 949 rend = children_.rend(); |
957 it != rend; ++it) { | 950 it != rend; ++it) { |
958 Window* child = *it; | 951 Window* child = *it; |
959 child->PrintWindowHierarchy(depth + 1); | 952 child->PrintWindowHierarchy(depth + 1); |
960 } | 953 } |
961 } | 954 } |
962 #endif | 955 #endif |
963 | 956 |
964 } // namespace aura | 957 } // namespace aura |
OLD | NEW |