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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING; | 508 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING; |
509 NotifyWindowHierarchyChange(params); | 509 NotifyWindowHierarchyChange(params); |
510 | 510 |
511 Window* old_root = child->GetRootWindow(); | 511 Window* old_root = child->GetRootWindow(); |
512 | 512 |
513 DCHECK(std::find(children_.begin(), children_.end(), child) == | 513 DCHECK(std::find(children_.begin(), children_.end(), child) == |
514 children_.end()); | 514 children_.end()); |
515 if (child->parent()) | 515 if (child->parent()) |
516 child->parent()->RemoveChildImpl(child, this); | 516 child->parent()->RemoveChildImpl(child, this); |
517 | 517 |
518 child->parent_ = this; | |
519 | |
518 gfx::Vector2d offset; | 520 gfx::Vector2d offset; |
519 aura::Window* ancestor_with_layer = GetAncestorWithLayer(&offset); | 521 aura::Window* ancestor_with_layer = GetAncestorWithLayer(&offset); |
520 if (ancestor_with_layer) { | 522 if (ancestor_with_layer) { |
521 offset += child->bounds().OffsetFromOrigin(); | 523 offset += child->GetTargetBounds().OffsetFromOrigin(); |
oshima
2014/04/22 20:47:11
Sorry if I'm misunderstanding something, but I won
varkha
2014/04/22 20:59:05
Isn't that how Window::GetTargetBounds is implemen
oshima
2014/04/22 22:57:11
It looks to me that this is wrong if a) the child
| |
522 child->ReparentLayers(ancestor_with_layer->layer(), offset); | 524 child->ReparentLayers(ancestor_with_layer->layer(), offset); |
523 } | 525 } |
524 | 526 |
525 child->parent_ = this; | |
526 | |
527 children_.push_back(child); | 527 children_.push_back(child); |
528 if (layout_manager_) | 528 if (layout_manager_) |
529 layout_manager_->OnWindowAddedToLayout(child); | 529 layout_manager_->OnWindowAddedToLayout(child); |
530 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); | 530 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); |
531 child->OnParentChanged(); | 531 child->OnParentChanged(); |
532 | 532 |
533 Window* root_window = GetRootWindow(); | 533 Window* root_window = GetRootWindow(); |
534 if (root_window && old_root != root_window) { | 534 if (root_window && old_root != root_window) { |
535 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); | 535 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); |
536 child->NotifyAddedToRootWindow(); | 536 child->NotifyAddedToRootWindow(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const { | 658 bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const { |
659 const Window* root_window = GetRootWindow(); | 659 const Window* root_window = GetRootWindow(); |
660 if (!root_window) | 660 if (!root_window) |
661 return false; | 661 return false; |
662 gfx::Point local_point(point_in_root); | 662 gfx::Point local_point(point_in_root); |
663 ConvertPointToTarget(root_window, this, &local_point); | 663 ConvertPointToTarget(root_window, this, &local_point); |
664 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); | 664 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); |
665 } | 665 } |
666 | 666 |
667 bool Window::ContainsPoint(const gfx::Point& local_point) const { | 667 bool Window::ContainsPoint(const gfx::Point& local_point) const { |
668 return gfx::Rect(bounds().size()).Contains(local_point); | 668 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); |
669 } | 669 } |
670 | 670 |
671 Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point) { | 671 Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point) { |
672 return GetWindowForPoint(local_point, true, true); | 672 return GetWindowForPoint(local_point, true, true); |
673 } | 673 } |
674 | 674 |
675 Window* Window::GetTopWindowContainingPoint(const gfx::Point& local_point) { | 675 Window* Window::GetTopWindowContainingPoint(const gfx::Point& local_point) { |
676 return GetWindowForPoint(local_point, false, false); | 676 return GetWindowForPoint(local_point, false, false); |
677 } | 677 } |
678 | 678 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1043 children_[i]->UnparentLayers(true, new_offset); | 1043 children_[i]->UnparentLayers(true, new_offset); |
1044 } | 1044 } |
1045 } else { | 1045 } else { |
1046 // Only remove the layer if we still own it. Someone else may have acquired | 1046 // Only remove the layer if we still own it. Someone else may have acquired |
1047 // ownership of it via AcquireLayer() and may expect the hierarchy to go | 1047 // ownership of it via AcquireLayer() and may expect the hierarchy to go |
1048 // unchanged as the Window is destroyed. | 1048 // unchanged as the Window is destroyed. |
1049 if (OwnsLayer()) { | 1049 if (OwnsLayer()) { |
1050 if (layer()->parent()) | 1050 if (layer()->parent()) |
1051 layer()->parent()->Remove(layer()); | 1051 layer()->parent()->Remove(layer()); |
1052 if (has_layerless_ancestor) { | 1052 if (has_layerless_ancestor) { |
1053 const gfx::Rect real_bounds(bounds_); | 1053 const gfx::Rect real_bounds(GetTargetBounds()); |
1054 gfx::Rect layer_bounds(layer()->bounds()); | 1054 gfx::Rect layer_bounds(layer()->GetTargetBounds()); |
1055 layer_bounds.Offset(-offset); | 1055 layer_bounds.Offset(-offset); |
1056 layer()->SetBounds(layer_bounds); | 1056 layer()->SetBounds(layer_bounds); |
1057 bounds_ = real_bounds; | 1057 bounds_ = real_bounds; |
1058 } | 1058 } |
1059 } | 1059 } |
1060 } | 1060 } |
1061 } | 1061 } |
1062 | 1062 |
1063 void Window::ReparentLayers(ui::Layer* parent_layer, | 1063 void Window::ReparentLayers(ui::Layer* parent_layer, |
1064 const gfx::Vector2d& offset) { | 1064 const gfx::Vector2d& offset) { |
1065 if (!layer()) { | 1065 if (!layer()) { |
1066 for (size_t i = 0; i < children_.size(); ++i) { | 1066 for (size_t i = 0; i < children_.size(); ++i) { |
1067 children_[i]->ReparentLayers( | 1067 children_[i]->ReparentLayers( |
1068 parent_layer, | 1068 parent_layer, |
1069 offset + children_[i]->bounds().OffsetFromOrigin()); | 1069 offset + children_[i]->GetTargetBounds().OffsetFromOrigin()); |
1070 } | 1070 } |
1071 } else { | 1071 } else { |
1072 const gfx::Rect real_bounds(bounds()); | 1072 const gfx::Rect real_bounds(GetTargetBounds()); |
1073 parent_layer->Add(layer()); | 1073 parent_layer->Add(layer()); |
1074 gfx::Rect layer_bounds(layer()->bounds().size()); | 1074 gfx::Rect layer_bounds(layer()->GetTargetBounds().size()); |
1075 layer_bounds += offset; | 1075 layer_bounds += offset; |
1076 layer()->SetBounds(layer_bounds); | 1076 layer()->SetBounds(layer_bounds); |
1077 bounds_ = real_bounds; | 1077 bounds_ = real_bounds; |
1078 } | 1078 } |
1079 } | 1079 } |
1080 | 1080 |
1081 void Window::OffsetLayerBounds(const gfx::Vector2d& offset) { | 1081 void Window::OffsetLayerBounds(const gfx::Vector2d& offset) { |
1082 if (!layer()) { | 1082 if (!layer()) { |
1083 for (size_t i = 0; i < children_.size(); ++i) | 1083 for (size_t i = 0; i < children_.size(); ++i) |
1084 children_[i]->OffsetLayerBounds(offset); | 1084 children_[i]->OffsetLayerBounds(offset); |
1085 } else { | 1085 } else { |
1086 gfx::Rect layer_bounds(layer()->bounds()); | 1086 gfx::Rect layer_bounds(layer()->GetTargetBounds()); |
1087 layer_bounds += offset; | 1087 layer_bounds += offset; |
1088 layer()->SetBounds(layer_bounds); | 1088 layer()->SetBounds(layer_bounds); |
1089 } | 1089 } |
1090 } | 1090 } |
1091 | 1091 |
1092 void Window::OnParentChanged() { | 1092 void Window::OnParentChanged() { |
1093 FOR_EACH_OBSERVER( | 1093 FOR_EACH_OBSERVER( |
1094 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); | 1094 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); |
1095 } | 1095 } |
1096 | 1096 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1428 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); | 1428 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); |
1429 } | 1429 } |
1430 return contains_mouse; | 1430 return contains_mouse; |
1431 } | 1431 } |
1432 | 1432 |
1433 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { | 1433 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { |
1434 for (const aura::Window* window = this; window; window = window->parent()) { | 1434 for (const aura::Window* window = this; window; window = window->parent()) { |
1435 if (window->layer()) | 1435 if (window->layer()) |
1436 return window; | 1436 return window; |
1437 if (offset) | 1437 if (offset) |
1438 *offset += window->bounds().OffsetFromOrigin(); | 1438 *offset += window->GetTargetBounds().OffsetFromOrigin(); |
1439 } | 1439 } |
1440 if (offset) | 1440 if (offset) |
1441 *offset = gfx::Vector2d(); | 1441 *offset = gfx::Vector2d(); |
1442 return NULL; | 1442 return NULL; |
1443 } | 1443 } |
1444 | 1444 |
1445 } // namespace aura | 1445 } // namespace aura |
OLD | NEW |