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