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 3 // found in the LICENSE file. 4 5 #include "ui/wm/core/visibility_controller.h" 6 7 #include "ui/aura/window.h" 8 #include "ui/aura/window_property.h" 9 #include "ui/compositor/layer.h" 10 #include "ui/wm/core/window_animations.h" 11 12 namespace wm { 13 14 namespace { 15 16 // Property set on all windows whose child windows' visibility changes are 17 // animated. 18 DEFINE_WINDOW_PROPERTY_KEY( 19 bool, kChildWindowVisibilityChangesAnimatedKey, false); 20 21 bool ShouldAnimateWindow(aura::Window* window) { 22 return window->parent() && window->parent()->GetProperty( 23 kChildWindowVisibilityChangesAnimatedKey); 24 } 25 26 } // namespace 27 28 VisibilityController::VisibilityController() { 29 } 30 31 VisibilityController::~VisibilityController() { 32 } 33 34 bool VisibilityController::CallAnimateOnChildWindowVisibilityChanged( 35 aura::Window* window, 36 bool visible) { 37 return AnimateOnChildWindowVisibilityChanged(window, visible); 38 } 39 40 void VisibilityController::UpdateLayerVisibility(aura::Window* window, 41 bool visible) { 42 bool animated = window->type() != ui::wm::WINDOW_TYPE_CONTROL && 43 window->type() != ui::wm::WINDOW_TYPE_UNKNOWN && 44 ShouldAnimateWindow(window); 45 animated = animated && 46 CallAnimateOnChildWindowVisibilityChanged(window, visible); 47 48 // If we're already in the process of hiding don't do anything. Otherwise we 49 // may end up prematurely canceling the animation. 50 // This does not check opacity as when fading out a visibility change should 51 // also be scheduled (to do otherwise would mean the window can not be seen, 52 // opacity is 0, yet the window is marked as visible) (see CL 132903003). 53 // TODO(vollick): remove this. 54 if (!visible && 55 window->layer()->GetAnimator()->IsAnimatingProperty( 56 ui::LayerAnimationElement::VISIBILITY) && 57 !window->layer()->GetTargetVisibility()) { 58 return; 59 } 60 61 // When a window is made visible, we always make its layer visible 62 // immediately. When a window is hidden, the layer must be left visible and 63 // only made not visible once the animation is complete. 64 if (!animated || visible) 65 window->layer()->SetVisible(visible); 66 } 67 68 SuspendChildWindowVisibilityAnimations::SuspendChildWindowVisibilityAnimations( 69 aura::Window* window) 70 : window_(window), 71 original_enabled_(window->GetProperty( 72 kChildWindowVisibilityChangesAnimatedKey)) { 73 window_->ClearProperty(kChildWindowVisibilityChangesAnimatedKey); 74 } 75 76 SuspendChildWindowVisibilityAnimations:: 77 ~SuspendChildWindowVisibilityAnimations() { 78 if (original_enabled_) 79 window_->SetProperty(kChildWindowVisibilityChangesAnimatedKey, true); 80 else 81 window_->ClearProperty(kChildWindowVisibilityChangesAnimatedKey); 82 } 83 84 void SetChildWindowVisibilityChangesAnimated(aura::Window* window) { 85 window->SetProperty(kChildWindowVisibilityChangesAnimatedKey, true); 86 } 87 88 } // namespace wm 89 90