1 // Copyright 2013 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 "ash/first_run/desktop_cleaner.h"
8 #include "ash/shell_window_ids.h"
9 #include "ui/aura/root_window.h"
10 #include "ui/aura/window_observer.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h"
12 #include "ui/message_center/message_center.h"
13 #include "ui/message_center/notification_blocker.h"
20 const int kContainerIdsToHide
[] = {
21 kShellWindowId_DefaultContainer
,
22 kShellWindowId_AlwaysOnTopContainer
,
23 kShellWindowId_PanelContainer
,
24 // TODO(dzhioev): uncomment this when issue with BrowserView::CanActivate
26 // kShellWindowId_SystemModalContainer
31 class ContainerHider
: public aura::WindowObserver
,
32 public ui::ImplicitAnimationObserver
{
34 explicit ContainerHider(aura::Window
* container
)
35 : container_was_hidden_(!container
->IsVisible()),
36 container_(container
) {
37 if (container_was_hidden_
)
39 ui::Layer
* layer
= container_
->layer();
40 ui::ScopedLayerAnimationSettings
animation_settings(layer
->GetAnimator());
41 animation_settings
.AddObserver(this);
42 layer
->SetOpacity(0.0);
45 virtual ~ContainerHider() {
46 if (container_was_hidden_
|| !container_
)
48 if (!WasAnimationCompletedForProperty(ui::LayerAnimationElement::OPACITY
)) {
49 // We are in the middle of animation.
50 StopObservingImplicitAnimations();
54 ui::Layer
* layer
= container_
->layer();
55 ui::ScopedLayerAnimationSettings
animation_settings(layer
->GetAnimator());
56 layer
->SetOpacity(1.0);
60 // Overriden from ui::ImplicitAnimationObserver.
61 virtual void OnImplicitAnimationsCompleted() OVERRIDE
{
65 // Overriden from aura::WindowObserver.
66 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
{
67 DCHECK(window
== container_
);
71 const bool container_was_hidden_
;
72 aura::Window
* container_
;
74 DISALLOW_COPY_AND_ASSIGN(ContainerHider
);
77 class NotificationBlocker
: public message_center::NotificationBlocker
{
80 : message_center::NotificationBlocker(
81 message_center::MessageCenter::Get()) {
82 NotifyBlockingStateChanged();
85 virtual ~NotificationBlocker() {};
88 // Overriden from message_center::NotificationBlocker.
89 virtual bool ShouldShowNotificationAsPopup(
90 const message_center::NotifierId
& notifier_id
) const OVERRIDE
{
94 DISALLOW_COPY_AND_ASSIGN(NotificationBlocker
);
97 DesktopCleaner::DesktopCleaner() {
98 // TODO(dzhioev): Add support for secondary displays.
99 aura::Window
* root_window
= Shell::GetInstance()->GetPrimaryRootWindow();
100 for (size_t i
= 0; i
< arraysize(kContainerIdsToHide
); ++i
) {
101 aura::Window
* container
=
102 Shell::GetContainer(root_window
, kContainerIdsToHide
[i
]);
103 container_hiders_
.push_back(make_linked_ptr(new ContainerHider(container
)));
105 notification_blocker_
.reset(new NotificationBlocker());
108 DesktopCleaner::~DesktopCleaner() {}
111 std::vector
<int> DesktopCleaner::GetContainersToHideForTest() {
112 return std::vector
<int>(kContainerIdsToHide
,
113 kContainerIdsToHide
+ arraysize(kContainerIdsToHide
));
116 } // namespace internal