Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / always_on_top_controller.cc
blobab397c9b9170b93b15dd26426be2c49bd44d7ec6
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"
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/window.h"
12 namespace ash {
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,
54 const void* key,
55 intptr_t old) {
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;
70 } // namespace ash