Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / wm / core / visibility_controller.cc
blobfc187a949028c0d6b7683d5b78f8b041abb99782
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.
5 #include "ui/wm/core/visibility_controller.h"
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"
12 namespace wm {
14 namespace {
16 // Property set on all windows whose child windows' visibility changes are
17 // animated.
18 DEFINE_WINDOW_PROPERTY_KEY(
19 bool, kChildWindowVisibilityChangesAnimatedKey, false);
21 bool ShouldAnimateWindow(aura::Window* window) {
22 return window->parent() && window->parent()->GetProperty(
23 kChildWindowVisibilityChangesAnimatedKey);
26 } // namespace
28 VisibilityController::VisibilityController() {
31 VisibilityController::~VisibilityController() {
34 bool VisibilityController::CallAnimateOnChildWindowVisibilityChanged(
35 aura::Window* window,
36 bool visible) {
37 return AnimateOnChildWindowVisibilityChanged(window, visible);
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);
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;
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);
68 SuspendChildWindowVisibilityAnimations::SuspendChildWindowVisibilityAnimations(
69 aura::Window* window)
70 : window_(window),
71 original_enabled_(window->GetProperty(
72 kChildWindowVisibilityChangesAnimatedKey)) {
73 window_->ClearProperty(kChildWindowVisibilityChangesAnimatedKey);
76 SuspendChildWindowVisibilityAnimations::
77 ~SuspendChildWindowVisibilityAnimations() {
78 if (original_enabled_)
79 window_->SetProperty(kChildWindowVisibilityChangesAnimatedKey, true);
80 else
81 window_->ClearProperty(kChildWindowVisibilityChangesAnimatedKey);
84 void SetChildWindowVisibilityChangesAnimated(aura::Window* window) {
85 window->SetProperty(kChildWindowVisibilityChangesAnimatedKey, true);
88 } // namespace wm