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 11 matching lines...) Expand all Loading... | |
22 #include "ui/aura/client/window_stacking_client.h" | 22 #include "ui/aura/client/window_stacking_client.h" |
23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
24 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
25 #include "ui/aura/window_delegate.h" | 25 #include "ui/aura/window_delegate.h" |
26 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
27 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
28 #include "ui/aura/window_tracker.h" | 28 #include "ui/aura/window_tracker.h" |
29 #include "ui/aura/window_tree_host.h" | 29 #include "ui/aura/window_tree_host.h" |
30 #include "ui/compositor/compositor.h" | 30 #include "ui/compositor/compositor.h" |
31 #include "ui/compositor/layer.h" | 31 #include "ui/compositor/layer.h" |
32 #include "ui/compositor/scoped_layer_animation_settings.h" | |
32 #include "ui/events/event_target_iterator.h" | 33 #include "ui/events/event_target_iterator.h" |
33 #include "ui/gfx/animation/multi_animation.h" | |
34 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/path.h" | 35 #include "ui/gfx/path.h" |
36 #include "ui/gfx/scoped_canvas.h" | 36 #include "ui/gfx/scoped_canvas.h" |
37 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
38 | 38 |
39 namespace aura { | 39 namespace aura { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 ui::LayerType WindowLayerTypeToUILayerType(WindowLayerType window_layer_type) { | 43 ui::LayerType WindowLayerTypeToUILayerType(WindowLayerType window_layer_type) { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 if (children_.size() <= 1 || child == children_.front()) | 493 if (children_.size() <= 1 || child == children_.front()) |
494 return; // At the bottom already. | 494 return; // At the bottom already. |
495 StackChildBelow(child, children_.front()); | 495 StackChildBelow(child, children_.front()); |
496 } | 496 } |
497 | 497 |
498 void Window::StackChildBelow(Window* child, Window* target) { | 498 void Window::StackChildBelow(Window* child, Window* target) { |
499 StackChildRelativeTo(child, target, STACK_BELOW); | 499 StackChildRelativeTo(child, target, STACK_BELOW); |
500 } | 500 } |
501 | 501 |
502 void Window::AddChild(Window* child) { | 502 void Window::AddChild(Window* child) { |
503 scoped_ptr<ui::ScopedLayerAnimationSettings> animation_settings; | |
504 if (child->layer() && | |
505 child->layer()->GetAnimator() && | |
506 child->layer()->GetAnimator()->is_animating()) { | |
507 animation_settings.reset( | |
508 new ui::ScopedLayerAnimationSettings(child->layer()->GetAnimator())); | |
509 animation_settings->SetPreemptionStrategy( | |
510 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
oshima
2014/04/23 16:34:44
I feels like animation should be canceled upon par
varkha
2014/04/23 16:44:05
I was thinking that this would be an option. It is
| |
511 } | |
503 WindowObserver::HierarchyChangeParams params; | 512 WindowObserver::HierarchyChangeParams params; |
504 params.target = child; | 513 params.target = child; |
505 params.new_parent = this; | 514 params.new_parent = this; |
506 params.old_parent = child->parent(); | 515 params.old_parent = child->parent(); |
507 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING; | 516 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING; |
508 NotifyWindowHierarchyChange(params); | 517 NotifyWindowHierarchyChange(params); |
509 | 518 |
510 Window* old_root = child->GetRootWindow(); | 519 Window* old_root = child->GetRootWindow(); |
511 | 520 |
512 DCHECK(std::find(children_.begin(), children_.end(), child) == | 521 DCHECK(std::find(children_.begin(), children_.end(), child) == |
513 children_.end()); | 522 children_.end()); |
514 if (child->parent()) | 523 if (child->parent()) |
515 child->parent()->RemoveChildImpl(child, this); | 524 child->parent()->RemoveChildImpl(child, this); |
516 | 525 |
517 gfx::Vector2d offset; | 526 gfx::Vector2d offset; |
518 aura::Window* ancestor_with_layer = GetAncestorWithLayer(&offset); | 527 aura::Window* ancestor_with_layer = GetAncestorWithLayer(&offset); |
528 gfx::Rect target_bounds = child->GetTargetBounds(); | |
529 | |
530 child->parent_ = this; | |
531 | |
519 if (ancestor_with_layer) { | 532 if (ancestor_with_layer) { |
520 offset += child->bounds().OffsetFromOrigin(); | 533 offset += target_bounds.OffsetFromOrigin(); |
521 child->ReparentLayers(ancestor_with_layer->layer(), offset); | 534 child->ReparentLayers(ancestor_with_layer->layer(), offset); |
522 } | 535 } |
523 | 536 |
524 child->parent_ = this; | |
525 | |
526 children_.push_back(child); | 537 children_.push_back(child); |
527 if (layout_manager_) | 538 if (layout_manager_) |
528 layout_manager_->OnWindowAddedToLayout(child); | 539 layout_manager_->OnWindowAddedToLayout(child); |
529 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); | 540 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); |
530 child->OnParentChanged(); | 541 child->OnParentChanged(); |
531 | 542 |
532 Window* root_window = GetRootWindow(); | 543 Window* root_window = GetRootWindow(); |
533 if (root_window && old_root != root_window) { | 544 if (root_window && old_root != root_window) { |
534 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); | 545 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); |
535 child->NotifyAddedToRootWindow(); | 546 child->NotifyAddedToRootWindow(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const { | 668 bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const { |
658 const Window* root_window = GetRootWindow(); | 669 const Window* root_window = GetRootWindow(); |
659 if (!root_window) | 670 if (!root_window) |
660 return false; | 671 return false; |
661 gfx::Point local_point(point_in_root); | 672 gfx::Point local_point(point_in_root); |
662 ConvertPointToTarget(root_window, this, &local_point); | 673 ConvertPointToTarget(root_window, this, &local_point); |
663 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); | 674 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); |
664 } | 675 } |
665 | 676 |
666 bool Window::ContainsPoint(const gfx::Point& local_point) const { | 677 bool Window::ContainsPoint(const gfx::Point& local_point) const { |
667 return gfx::Rect(bounds().size()).Contains(local_point); | 678 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); |
668 } | 679 } |
669 | 680 |
670 Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point) { | 681 Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point) { |
671 return GetWindowForPoint(local_point, true, true); | 682 return GetWindowForPoint(local_point, true, true); |
672 } | 683 } |
673 | 684 |
674 Window* Window::GetTopWindowContainingPoint(const gfx::Point& local_point) { | 685 Window* Window::GetTopWindowContainingPoint(const gfx::Point& local_point) { |
675 return GetWindowForPoint(local_point, false, false); | 686 return GetWindowForPoint(local_point, false, false); |
676 } | 687 } |
677 | 688 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1042 children_[i]->UnparentLayers(true, new_offset); | 1053 children_[i]->UnparentLayers(true, new_offset); |
1043 } | 1054 } |
1044 } else { | 1055 } else { |
1045 // Only remove the layer if we still own it. Someone else may have acquired | 1056 // Only remove the layer if we still own it. Someone else may have acquired |
1046 // ownership of it via AcquireLayer() and may expect the hierarchy to go | 1057 // ownership of it via AcquireLayer() and may expect the hierarchy to go |
1047 // unchanged as the Window is destroyed. | 1058 // unchanged as the Window is destroyed. |
1048 if (OwnsLayer()) { | 1059 if (OwnsLayer()) { |
1049 if (layer()->parent()) | 1060 if (layer()->parent()) |
1050 layer()->parent()->Remove(layer()); | 1061 layer()->parent()->Remove(layer()); |
1051 if (has_layerless_ancestor) { | 1062 if (has_layerless_ancestor) { |
1052 const gfx::Rect real_bounds(bounds_); | 1063 const gfx::Rect real_bounds(bounds()); |
1053 gfx::Rect layer_bounds(layer()->bounds()); | 1064 gfx::Rect layer_bounds(layer()->GetTargetBounds()); |
1054 layer_bounds.Offset(-offset); | 1065 layer_bounds.Offset(-offset); |
1055 layer()->SetBounds(layer_bounds); | 1066 layer()->SetBounds(layer_bounds); |
1056 bounds_ = real_bounds; | 1067 bounds_ = real_bounds; |
1057 } | 1068 } |
1058 } | 1069 } |
1059 } | 1070 } |
1060 } | 1071 } |
1061 | 1072 |
1062 void Window::ReparentLayers(ui::Layer* parent_layer, | 1073 void Window::ReparentLayers(ui::Layer* parent_layer, |
1063 const gfx::Vector2d& offset) { | 1074 const gfx::Vector2d& offset) { |
1064 if (!layer()) { | 1075 if (!layer()) { |
1065 for (size_t i = 0; i < children_.size(); ++i) { | 1076 for (size_t i = 0; i < children_.size(); ++i) { |
1066 children_[i]->ReparentLayers( | 1077 children_[i]->ReparentLayers( |
1067 parent_layer, | 1078 parent_layer, |
1068 offset + children_[i]->bounds().OffsetFromOrigin()); | 1079 offset + children_[i]->bounds().OffsetFromOrigin()); |
1069 } | 1080 } |
1070 } else { | 1081 } else { |
1071 const gfx::Rect real_bounds(bounds()); | 1082 const gfx::Rect real_bounds(bounds()); |
1072 parent_layer->Add(layer()); | 1083 parent_layer->Add(layer()); |
1073 gfx::Rect layer_bounds(layer()->bounds().size()); | 1084 gfx::Rect layer_bounds(layer()->GetTargetBounds().size()); |
1074 layer_bounds += offset; | 1085 layer_bounds += offset; |
1075 layer()->SetBounds(layer_bounds); | 1086 layer()->SetBounds(layer_bounds); |
1076 bounds_ = real_bounds; | 1087 bounds_ = real_bounds; |
1077 } | 1088 } |
1078 } | 1089 } |
1079 | 1090 |
1080 void Window::OffsetLayerBounds(const gfx::Vector2d& offset) { | 1091 void Window::OffsetLayerBounds(const gfx::Vector2d& offset) { |
1081 if (!layer()) { | 1092 if (!layer()) { |
1082 for (size_t i = 0; i < children_.size(); ++i) | 1093 for (size_t i = 0; i < children_.size(); ++i) |
1083 children_[i]->OffsetLayerBounds(offset); | 1094 children_[i]->OffsetLayerBounds(offset); |
1084 } else { | 1095 } else { |
1085 gfx::Rect layer_bounds(layer()->bounds()); | 1096 gfx::Rect layer_bounds(layer()->GetTargetBounds()); |
1086 layer_bounds += offset; | 1097 layer_bounds += offset; |
1087 layer()->SetBounds(layer_bounds); | 1098 layer()->SetBounds(layer_bounds); |
1088 } | 1099 } |
1089 } | 1100 } |
1090 | 1101 |
1091 void Window::OnParentChanged() { | 1102 void Window::OnParentChanged() { |
1092 FOR_EACH_OBSERVER( | 1103 FOR_EACH_OBSERVER( |
1093 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); | 1104 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); |
1094 } | 1105 } |
1095 | 1106 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1427 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); | 1438 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); |
1428 } | 1439 } |
1429 return contains_mouse; | 1440 return contains_mouse; |
1430 } | 1441 } |
1431 | 1442 |
1432 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { | 1443 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { |
1433 for (const aura::Window* window = this; window; window = window->parent()) { | 1444 for (const aura::Window* window = this; window; window = window->parent()) { |
1434 if (window->layer()) | 1445 if (window->layer()) |
1435 return window; | 1446 return window; |
1436 if (offset) | 1447 if (offset) |
1437 *offset += window->bounds().OffsetFromOrigin(); | 1448 *offset += window->GetTargetBounds().OffsetFromOrigin(); |
1438 } | 1449 } |
1439 if (offset) | 1450 if (offset) |
1440 *offset = gfx::Vector2d(); | 1451 *offset = gfx::Vector2d(); |
1441 return NULL; | 1452 return NULL; |
1442 } | 1453 } |
1443 | 1454 |
1444 } // namespace aura | 1455 } // namespace aura |
OLD | NEW |