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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 | 287 |
288 layer_->Add(child->layer_); | 288 layer_->Add(child->layer_); |
289 | 289 |
290 children_.push_back(child); | 290 children_.push_back(child); |
291 if (layout_manager_.get()) | 291 if (layout_manager_.get()) |
292 layout_manager_->OnWindowAddedToLayout(child); | 292 layout_manager_->OnWindowAddedToLayout(child); |
293 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); | 293 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); |
294 child->OnParentChanged(); | 294 child->OnParentChanged(); |
295 | 295 |
296 RootWindow* root_window = child->GetRootWindow(); | 296 RootWindow* root_window = child->GetRootWindow(); |
297 if (root_window) | 297 if (root_window) { |
298 root_window->OnWindowAttachedToRootWindow(child); | 298 root_window->OnWindowAddedToRootWindow(child); |
299 NotifyAddedToRootWindow(); | |
300 } | |
299 } | 301 } |
300 | 302 |
301 void Window::AddTransientChild(Window* child) { | 303 void Window::AddTransientChild(Window* child) { |
302 if (child->transient_parent_) | 304 if (child->transient_parent_) |
303 child->transient_parent_->RemoveTransientChild(child); | 305 child->transient_parent_->RemoveTransientChild(child); |
304 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), | 306 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), |
305 child) == transient_children_.end()); | 307 child) == transient_children_.end()); |
306 transient_children_.push_back(child); | 308 transient_children_.push_back(child); |
307 child->transient_parent_ = this; | 309 child->transient_parent_ = this; |
308 } | 310 } |
309 | 311 |
310 void Window::RemoveTransientChild(Window* child) { | 312 void Window::RemoveTransientChild(Window* child) { |
311 Windows::iterator i = | 313 Windows::iterator i = |
312 std::find(transient_children_.begin(), transient_children_.end(), child); | 314 std::find(transient_children_.begin(), transient_children_.end(), child); |
313 DCHECK(i != transient_children_.end()); | 315 DCHECK(i != transient_children_.end()); |
314 transient_children_.erase(i); | 316 transient_children_.erase(i); |
315 if (child->transient_parent_ == this) | 317 if (child->transient_parent_ == this) |
316 child->transient_parent_ = NULL; | 318 child->transient_parent_ = NULL; |
317 } | 319 } |
318 | 320 |
319 void Window::RemoveChild(Window* child) { | 321 void Window::RemoveChild(Window* child) { |
320 Windows::iterator i = std::find(children_.begin(), children_.end(), child); | 322 Windows::iterator i = std::find(children_.begin(), children_.end(), child); |
321 DCHECK(i != children_.end()); | 323 DCHECK(i != children_.end()); |
322 if (layout_manager_.get()) | 324 if (layout_manager_.get()) |
323 layout_manager_->OnWillRemoveWindowFromLayout(child); | 325 layout_manager_->OnWillRemoveWindowFromLayout(child); |
324 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); | 326 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); |
325 RootWindow* root_window = child->GetRootWindow(); | 327 RootWindow* root_window = child->GetRootWindow(); |
326 if (root_window) | 328 if (root_window) { |
327 root_window->OnWindowDetachingFromRootWindow(child); | 329 root_window->OnWindowRemovedFromRootWindow(child); |
330 child->NotifyRemovingFromRootWindow(); | |
331 } | |
328 child->parent_ = NULL; | 332 child->parent_ = NULL; |
329 // We should only remove the child's layer if the child still owns that layer. | 333 // We should only remove the child's layer if the child still owns that layer. |
330 // Someone else may have acquired ownership of it via AcquireLayer() and may | 334 // Someone else may have acquired ownership of it via AcquireLayer() and may |
331 // expect the hierarchy to go unchanged as the Window is destroyed. | 335 // expect the hierarchy to go unchanged as the Window is destroyed. |
332 if (child->layer_owner_.get()) | 336 if (child->layer_owner_.get()) |
333 layer_->Remove(child->layer_); | 337 layer_->Remove(child->layer_); |
334 children_.erase(i); | 338 children_.erase(i); |
335 child->OnParentChanged(); | 339 child->OnParentChanged(); |
336 } | 340 } |
337 | 341 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 | 516 |
513 bool Window::StopsEventPropagation() const { | 517 bool Window::StopsEventPropagation() const { |
514 if (!stops_event_propagation_ || children_.empty()) | 518 if (!stops_event_propagation_ || children_.empty()) |
515 return false; | 519 return false; |
516 aura::Window::Windows::const_iterator it = | 520 aura::Window::Windows::const_iterator it = |
517 std::find_if(children_.begin(), children_.end(), | 521 std::find_if(children_.begin(), children_.end(), |
518 std::mem_fun(&aura::Window::IsVisible)); | 522 std::mem_fun(&aura::Window::IsVisible)); |
519 return it != children_.end(); | 523 return it != children_.end(); |
520 } | 524 } |
521 | 525 |
522 void Window::OnWindowDetachingFromRootWindow(aura::Window* window) { | |
523 } | |
524 | |
525 void Window::OnWindowAttachedToRootWindow(aura::Window* window) { | |
526 } | |
527 | |
528 void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { | 526 void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { |
529 gfx::Rect actual_new_bounds(new_bounds); | 527 gfx::Rect actual_new_bounds(new_bounds); |
530 | 528 |
531 // Ensure we don't go smaller than our minimum bounds. | 529 // Ensure we don't go smaller than our minimum bounds. |
532 if (delegate_) { | 530 if (delegate_) { |
533 const gfx::Size& min_size = delegate_->GetMinimumSize(); | 531 const gfx::Size& min_size = delegate_->GetMinimumSize(); |
534 actual_new_bounds.set_width( | 532 actual_new_bounds.set_width( |
535 std::max(min_size.width(), actual_new_bounds.width())); | 533 std::max(min_size.width(), actual_new_bounds.width())); |
536 actual_new_bounds.set_height( | 534 actual_new_bounds.set_height( |
537 std::max(min_size.height(), actual_new_bounds.height())); | 535 std::max(min_size.height(), actual_new_bounds.height())); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 | 634 |
637 void Window::OnParentChanged() { | 635 void Window::OnParentChanged() { |
638 FOR_EACH_OBSERVER( | 636 FOR_EACH_OBSERVER( |
639 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); | 637 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); |
640 } | 638 } |
641 | 639 |
642 void Window::OnStackingChanged() { | 640 void Window::OnStackingChanged() { |
643 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this)); | 641 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this)); |
644 } | 642 } |
645 | 643 |
644 void Window::NotifyRemovingFromRootWindow() { | |
645 FOR_EACH_OBSERVER(WindowObserver, observers_, | |
646 OnWindowRemovingFromRootWindow(this)); | |
647 Window::Windows::const_iterator it = children_.begin(); | |
sky
2012/01/31 22:20:58
nit: put iterator inside for loop here and 656.
| |
648 for (; it != children_.end(); ++it) | |
649 (*it)->NotifyRemovingFromRootWindow(); | |
650 } | |
651 | |
652 void Window::NotifyAddedToRootWindow() { | |
653 FOR_EACH_OBSERVER(WindowObserver, observers_, | |
654 OnWindowAddedToRootWindow(this)); | |
655 Window::Windows::const_iterator it = children_.begin(); | |
656 for (; it != children_.end(); ++it) | |
657 (*it)->NotifyAddedToRootWindow(); | |
658 } | |
659 | |
646 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 660 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
647 if (delegate_) | 661 if (delegate_) |
648 delegate_->OnPaint(canvas); | 662 delegate_->OnPaint(canvas); |
649 } | 663 } |
650 | 664 |
651 void Window::UpdateLayerName(const std::string& name) { | 665 void Window::UpdateLayerName(const std::string& name) { |
652 #if !defined(NDEBUG) | 666 #if !defined(NDEBUG) |
653 DCHECK(layer()); | 667 DCHECK(layer()); |
654 | 668 |
655 std::string layer_name(name_); | 669 std::string layer_name(name_); |
(...skipping 14 matching lines...) Expand all Loading... | |
670 parent_->children().end(), | 684 parent_->children().end(), |
671 this); | 685 this); |
672 for (++i; i != parent_->children().end(); ++i) { | 686 for (++i; i != parent_->children().end(); ++i) { |
673 if ((*i)->StopsEventPropagation()) | 687 if ((*i)->StopsEventPropagation()) |
674 return true; | 688 return true; |
675 } | 689 } |
676 return false; | 690 return false; |
677 } | 691 } |
678 | 692 |
679 } // namespace aura | 693 } // namespace aura |
OLD | NEW |