| OLD | NEW |
| (Empty) |
| 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 "ash/wm/visibility_controller.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/wm/window_animations.h" | |
| 9 #include "ash/wm/window_properties.h" | |
| 10 #include "ui/aura/window.h" | |
| 11 #include "ui/compositor/layer.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 namespace internal { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 bool ShouldAnimateWindow(aura::Window* window) { | |
| 19 return window->parent() && window->parent()->GetProperty( | |
| 20 internal::kChildWindowVisibilityChangesAnimatedKey); | |
| 21 } | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 VisibilityController::VisibilityController() { | |
| 26 } | |
| 27 | |
| 28 VisibilityController::~VisibilityController() { | |
| 29 } | |
| 30 | |
| 31 void VisibilityController::UpdateLayerVisibility(aura::Window* window, | |
| 32 bool visible) { | |
| 33 bool animated = window->type() != aura::client::WINDOW_TYPE_CONTROL && | |
| 34 window->type() != aura::client::WINDOW_TYPE_UNKNOWN && | |
| 35 ShouldAnimateWindow(window); | |
| 36 animated = animated && AnimateOnChildWindowVisibilityChanged(window, visible); | |
| 37 | |
| 38 if (!visible) { | |
| 39 // For window hiding animation, we want to check if the window is already | |
| 40 // animating, and not do SetVisible(false) if it is. | |
| 41 // TODO(vollick): remove this. | |
| 42 animated = animated || (window->layer()->GetAnimator()-> | |
| 43 IsAnimatingProperty(ui::LayerAnimationElement::OPACITY) && | |
| 44 window->layer()->GetTargetOpacity() == 0.0f); | |
| 45 } | |
| 46 | |
| 47 // When a window is made visible, we always make its layer visible | |
| 48 // immediately. When a window is hidden, the layer must be left visible and | |
| 49 // only made not visible once the animation is complete. | |
| 50 if (!animated || visible) | |
| 51 window->layer()->SetVisible(visible); | |
| 52 } | |
| 53 | |
| 54 } // namespace internal | |
| 55 | |
| 56 SuspendChildWindowVisibilityAnimations::SuspendChildWindowVisibilityAnimations( | |
| 57 aura::Window* window) | |
| 58 : window_(window), | |
| 59 original_enabled_(window->GetProperty( | |
| 60 internal::kChildWindowVisibilityChangesAnimatedKey)) { | |
| 61 window_->ClearProperty(internal::kChildWindowVisibilityChangesAnimatedKey); | |
| 62 } | |
| 63 | |
| 64 SuspendChildWindowVisibilityAnimations:: | |
| 65 ~SuspendChildWindowVisibilityAnimations() { | |
| 66 if (original_enabled_) { | |
| 67 window_->SetProperty(internal::kChildWindowVisibilityChangesAnimatedKey, | |
| 68 true); | |
| 69 } else { | |
| 70 window_->ClearProperty(internal::kChildWindowVisibilityChangesAnimatedKey); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void SetChildWindowVisibilityChangesAnimated(aura::Window* window) { | |
| 75 window->SetProperty(internal::kChildWindowVisibilityChangesAnimatedKey, true); | |
| 76 } | |
| 77 | |
| 78 } // namespace ash | |
| OLD | NEW |