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

Side by Side Diff: ui/aura/window.cc

Issue 10831297: Attempt 2 at: Makes Window not change focus and send out (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: The fix Created 8 years, 4 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
352 DCHECK(std::find(children_.begin(), children_.end(), child) == 354 DCHECK(std::find(children_.begin(), children_.end(), child) ==
353 children_.end()); 355 children_.end());
354 if (child->parent()) 356 if (child->parent())
355 child->parent()->RemoveChild(child); 357 child->parent()->RemoveChildImpl(child, this);
356 child->parent_ = this; 358 child->parent_ = this;
357 359
358 layer_->Add(child->layer_); 360 layer_->Add(child->layer_);
359 361
360 children_.push_back(child); 362 children_.push_back(child);
361 if (layout_manager_.get()) 363 if (layout_manager_.get())
362 layout_manager_->OnWindowAddedToLayout(child); 364 layout_manager_->OnWindowAddedToLayout(child);
363 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); 365 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child));
364 child->OnParentChanged(); 366 child->OnParentChanged();
365 367
366 RootWindow* root_window = child->GetRootWindow(); 368 RootWindow* root_window = GetRootWindow();
367 if (root_window) { 369 if (root_window && old_root != root_window) {
368 root_window->OnWindowAddedToRootWindow(child); 370 root_window->OnWindowAddedToRootWindow(child);
369 child->NotifyAddedToRootWindow(); 371 child->NotifyAddedToRootWindow();
370 } 372 }
371 } 373 }
372 374
373 void Window::AddTransientChild(Window* child) { 375 void Window::AddTransientChild(Window* child) {
374 if (child->transient_parent_) 376 if (child->transient_parent_)
375 child->transient_parent_->RemoveTransientChild(child); 377 child->transient_parent_->RemoveTransientChild(child);
376 DCHECK(std::find(transient_children_.begin(), transient_children_.end(), 378 DCHECK(std::find(transient_children_.begin(), transient_children_.end(),
377 child) == transient_children_.end()); 379 child) == transient_children_.end());
378 transient_children_.push_back(child); 380 transient_children_.push_back(child);
379 child->transient_parent_ = this; 381 child->transient_parent_ = this;
380 } 382 }
381 383
382 void Window::RemoveTransientChild(Window* child) { 384 void Window::RemoveTransientChild(Window* child) {
383 Windows::iterator i = 385 Windows::iterator i =
384 std::find(transient_children_.begin(), transient_children_.end(), child); 386 std::find(transient_children_.begin(), transient_children_.end(), child);
385 DCHECK(i != transient_children_.end()); 387 DCHECK(i != transient_children_.end());
386 transient_children_.erase(i); 388 transient_children_.erase(i);
387 if (child->transient_parent_ == this) 389 if (child->transient_parent_ == this)
388 child->transient_parent_ = NULL; 390 child->transient_parent_ = NULL;
389 } 391 }
390 392
391 void Window::RemoveChild(Window* child) { 393 void Window::RemoveChild(Window* child) {
392 Windows::iterator i = std::find(children_.begin(), children_.end(), child); 394 RemoveChildImpl(child, NULL);
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);
412 } 395 }
413 396
414 bool Window::Contains(const Window* other) const { 397 bool Window::Contains(const Window* other) const {
415 for (const Window* parent = other; parent; parent = parent->parent_) { 398 for (const Window* parent = other; parent; parent = parent->parent_) {
416 if (parent == this) 399 if (parent == this)
417 return true; 400 return true;
418 } 401 }
419 return false; 402 return false;
420 } 403 }
421 404
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 Window* match = child->GetWindowForPoint(point_in_child_coords, 752 Window* match = child->GetWindowForPoint(point_in_child_coords,
770 return_tightest, 753 return_tightest,
771 for_event_handling); 754 for_event_handling);
772 if (match) 755 if (match)
773 return match; 756 return match;
774 } 757 }
775 758
776 return delegate_ ? this : NULL; 759 return delegate_ ? this : NULL;
777 } 760 }
778 761
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
779 void Window::OnParentChanged() { 786 void Window::OnParentChanged() {
780 FOR_EACH_OBSERVER( 787 FOR_EACH_OBSERVER(
781 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); 788 WindowObserver, observers_, OnWindowParentChanged(this, parent_));
782 } 789 }
783 790
784 void Window::StackChildRelativeTo(Window* child, 791 void Window::StackChildRelativeTo(Window* child,
785 Window* target, 792 Window* target,
786 StackDirection direction) { 793 StackDirection direction) {
787 DCHECK_NE(child, target); 794 DCHECK_NE(child, target);
788 DCHECK(child); 795 DCHECK(child);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 for (Windows::const_reverse_iterator it = children_.rbegin(), 955 for (Windows::const_reverse_iterator it = children_.rbegin(),
949 rend = children_.rend(); 956 rend = children_.rend();
950 it != rend; ++it) { 957 it != rend; ++it) {
951 Window* child = *it; 958 Window* child = *it;
952 child->PrintWindowHierarchy(depth + 1); 959 child->PrintWindowHierarchy(depth + 1);
953 } 960 }
954 } 961 }
955 #endif 962 #endif
956 963
957 } // namespace aura 964 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698