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 "ash/wm/window_animations.h" | 5 #include "ash/wm/window_animations.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
13 #include "ash/launcher/launcher.h" | 13 #include "ash/launcher/launcher.h" |
14 #include "ash/screen_ash.h" | 14 #include "ash/screen_ash.h" |
15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/wm/window_util.h" |
16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
20 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
21 #include "base/time.h" | 22 #include "base/time.h" |
22 #include "ui/aura/client/aura_constants.h" | 23 #include "ui/aura/client/aura_constants.h" |
23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
24 #include "ui/aura/window_observer.h" | 25 #include "ui/aura/window_observer.h" |
25 #include "ui/aura/window_property.h" | 26 #include "ui/aura/window_property.h" |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 return true; | 610 return true; |
610 case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: | 611 case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: |
611 AnimateHideWindow_BrightnessGrayscale(window); | 612 AnimateHideWindow_BrightnessGrayscale(window); |
612 return true; | 613 return true; |
613 default: | 614 default: |
614 NOTREACHED(); | 615 NOTREACHED(); |
615 return false; | 616 return false; |
616 } | 617 } |
617 } | 618 } |
618 | 619 |
619 // Recreates a fresh layer for |window| and all its child windows. Does not | |
620 // recreate shadows or other non-window layers. Returns the old layer and its | |
621 // children, maintaining the hierarchy. | |
622 Layer* RecreateWindowLayers(Window* window) { | |
623 Layer* old_layer = window->RecreateLayer(); | |
624 DCHECK(old_layer); | |
625 for (Window::Windows::const_iterator it = window->children().begin(); | |
626 it != window->children().end(); | |
627 ++it) { | |
628 aura::Window* child = *it; | |
629 Layer* old_child_layer = RecreateWindowLayers(child); | |
630 // Maintain the hierarchy of the detached layers. | |
631 old_layer->Add(old_child_layer); | |
632 } | |
633 return old_layer; | |
634 } | |
635 | |
636 // Deletes |layer| and all its child layers. | |
637 void DeepDelete(Layer* layer) { | |
638 std::vector<Layer*> children = layer->children(); | |
639 for (std::vector<Layer*>::const_iterator it = children.begin(); | |
640 it != children.end(); | |
641 ++it) { | |
642 Layer* child = *it; | |
643 DeepDelete(child); | |
644 } | |
645 delete layer; | |
646 } | |
647 | |
648 // Observer for a window cross-fade animation. If either the window closes or | 620 // Observer for a window cross-fade animation. If either the window closes or |
649 // the layer's animation completes or compositing is aborted due to GPU crash, | 621 // the layer's animation completes or compositing is aborted due to GPU crash, |
650 // it deletes the layer and removes itself as an observer. | 622 // it deletes the layer and removes itself as an observer. |
651 class CrossFadeObserver : public ui::CompositorObserver, | 623 class CrossFadeObserver : public ui::CompositorObserver, |
652 public aura::WindowObserver, | 624 public aura::WindowObserver, |
653 public ui::ImplicitAnimationObserver { | 625 public ui::ImplicitAnimationObserver { |
654 public: | 626 public: |
655 // Observes |window| for destruction, but does not take ownership. | 627 // Observes |window| for destruction, but does not take ownership. |
656 // Takes ownership of |layer| and its child layers. | 628 // Takes ownership of |layer| and its child layers. |
657 CrossFadeObserver(Window* window, Layer* layer) | 629 CrossFadeObserver(Window* window, Layer* layer) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 private: | 675 private: |
704 // Can be called multiple times if the window is closed or the compositor | 676 // Can be called multiple times if the window is closed or the compositor |
705 // fails in the middle of the animation. | 677 // fails in the middle of the animation. |
706 void Cleanup() { | 678 void Cleanup() { |
707 if (window_) { | 679 if (window_) { |
708 window_->RemoveObserver(this); | 680 window_->RemoveObserver(this); |
709 window_ = NULL; | 681 window_ = NULL; |
710 } | 682 } |
711 if (layer_) { | 683 if (layer_) { |
712 layer_->GetCompositor()->RemoveObserver(this); | 684 layer_->GetCompositor()->RemoveObserver(this); |
713 DeepDelete(layer_); | 685 wm::DeepDeleteLayers(layer_); |
714 layer_ = NULL; | 686 layer_ = NULL; |
715 } | 687 } |
716 } | 688 } |
717 | 689 |
718 Window* window_; // not owned | 690 Window* window_; // not owned |
719 Layer* layer_; // owned | 691 Layer* layer_; // owned |
720 | 692 |
721 DISALLOW_COPY_AND_ASSIGN(CrossFadeObserver); | 693 DISALLOW_COPY_AND_ASSIGN(CrossFadeObserver); |
722 }; | 694 }; |
723 | 695 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 return new internal::HidingWindowAnimationObserver(window); | 733 return new internal::HidingWindowAnimationObserver(window); |
762 } | 734 } |
763 | 735 |
764 void CrossFadeToBounds(aura::Window* window, const gfx::Rect& new_bounds) { | 736 void CrossFadeToBounds(aura::Window* window, const gfx::Rect& new_bounds) { |
765 DCHECK(window->TargetVisibility()); | 737 DCHECK(window->TargetVisibility()); |
766 gfx::Rect old_bounds = window->bounds(); | 738 gfx::Rect old_bounds = window->bounds(); |
767 | 739 |
768 // Create fresh layers for the window and all its children to paint into. | 740 // Create fresh layers for the window and all its children to paint into. |
769 // Takes ownership of the old layer and all its children, which will be | 741 // Takes ownership of the old layer and all its children, which will be |
770 // cleaned up after the animation completes. | 742 // cleaned up after the animation completes. |
771 ui::Layer* old_layer = internal::RecreateWindowLayers(window); | 743 ui::Layer* old_layer = wm::RecreateWindowLayers(window); |
772 ui::Layer* new_layer = window->layer(); | 744 ui::Layer* new_layer = window->layer(); |
773 | 745 |
774 // Ensure the higher-resolution layer is on top. | 746 // Ensure the higher-resolution layer is on top. |
775 bool old_on_top = (old_bounds.width() > new_bounds.width()); | 747 bool old_on_top = (old_bounds.width() > new_bounds.width()); |
776 if (old_on_top) | 748 if (old_on_top) |
777 old_layer->parent()->StackBelow(new_layer, old_layer); | 749 old_layer->parent()->StackBelow(new_layer, old_layer); |
778 else | 750 else |
779 old_layer->parent()->StackAbove(new_layer, old_layer); | 751 old_layer->parent()->StackAbove(new_layer, old_layer); |
780 | 752 |
781 // Tween types for transform animations must match to keep the window edges | 753 // Tween types for transform animations must match to keep the window edges |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 AnimateHideWindow(window); | 849 AnimateHideWindow(window); |
878 } | 850 } |
879 } | 851 } |
880 | 852 |
881 void SetDelayedOldLayerDeletionInCrossFadeForTest(bool value) { | 853 void SetDelayedOldLayerDeletionInCrossFadeForTest(bool value) { |
882 delayed_old_layer_deletion_in_cross_fade_for_test_ = value; | 854 delayed_old_layer_deletion_in_cross_fade_for_test_ = value; |
883 } | 855 } |
884 | 856 |
885 } // namespace internal | 857 } // namespace internal |
886 } // namespace ash | 858 } // namespace ash |
OLD | NEW |