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 "ash/wm/always_on_top_controller.h"
8 #include "ash/shell_window_ids.h"
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/window.h"
14 AlwaysOnTopController::AlwaysOnTopController()
15 : always_on_top_container_(NULL
) {
18 AlwaysOnTopController::~AlwaysOnTopController() {
19 if (always_on_top_container_
)
20 always_on_top_container_
->RemoveObserver(this);
23 void AlwaysOnTopController::SetAlwaysOnTopContainer(
24 aura::Window
* always_on_top_container
) {
25 // Container should be empty.
26 DCHECK(always_on_top_container
->children().empty());
28 // We are not handling any containers yet.
29 DCHECK(always_on_top_container_
== NULL
);
31 always_on_top_container_
= always_on_top_container
;
32 always_on_top_container_
->AddObserver(this);
35 aura::Window
* AlwaysOnTopController::GetContainer(aura::Window
* window
) const {
36 DCHECK(always_on_top_container_
);
37 if (window
->GetProperty(aura::client::kAlwaysOnTopKey
))
38 return always_on_top_container_
;
39 return Shell::GetContainer(always_on_top_container_
->GetRootWindow(),
40 kShellWindowId_DefaultContainer
);
43 void AlwaysOnTopController::OnWindowAdded(aura::Window
* child
) {
44 // Observe direct child of the containers.
45 if (child
->parent() == always_on_top_container_
)
46 child
->AddObserver(this);
49 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window
* child
) {
50 child
->RemoveObserver(this);
53 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window
* window
,
56 if (key
== aura::client::kAlwaysOnTopKey
) {
57 DCHECK(window
->type() == ui::wm::WINDOW_TYPE_NORMAL
||
58 window
->type() == ui::wm::WINDOW_TYPE_POPUP
);
59 aura::Window
* container
= GetContainer(window
);
60 if (window
->parent() != container
)
61 container
->AddChild(window
);
65 void AlwaysOnTopController::OnWindowDestroyed(aura::Window
* window
) {
66 if (window
== always_on_top_container_
)
67 always_on_top_container_
= NULL
;