Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / wm / always_on_top_controller.cc
blob89783f87e6835e936ddf8b2f1d8d1caf81097c1b
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/root_window_controller.h"
8 #include "ash/wm/property_util.h"
9 #include "ash/wm/workspace_controller.h"
10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/window.h"
13 namespace ash {
14 namespace internal {
16 AlwaysOnTopController::AlwaysOnTopController()
17 : always_on_top_container_(NULL) {
20 AlwaysOnTopController::~AlwaysOnTopController() {
21 if (always_on_top_container_)
22 always_on_top_container_->RemoveObserver(this);
25 void AlwaysOnTopController::SetAlwaysOnTopContainer(
26 aura::Window* always_on_top_container) {
27 // Container should be empty.
28 DCHECK(always_on_top_container->children().empty());
30 // We are not handling any containers yet.
31 DCHECK(always_on_top_container_ == NULL);
33 always_on_top_container_ = always_on_top_container;
34 always_on_top_container_->AddObserver(this);
37 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const {
38 DCHECK(always_on_top_container_);
39 if (window->GetProperty(aura::client::kAlwaysOnTopKey))
40 return always_on_top_container_;
41 return GetRootWindowController(always_on_top_container_->GetRootWindow())->
42 workspace_controller()->GetParentForNewWindow(window);
45 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) {
46 // Observe direct child of the containers.
47 if (child->parent() == always_on_top_container_)
48 child->AddObserver(this);
51 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) {
52 child->RemoveObserver(this);
55 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window,
56 const void* key,
57 intptr_t old) {
58 if (key == aura::client::kAlwaysOnTopKey) {
59 DCHECK(window->type() == aura::client::WINDOW_TYPE_NORMAL ||
60 window->type() == aura::client::WINDOW_TYPE_POPUP);
61 aura::Window* container = GetContainer(window);
62 if (window->parent() != container)
63 container->AddChild(window);
67 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) {
68 if (window == always_on_top_container_)
69 always_on_top_container_ = NULL;
72 } // namespace internal
73 } // namespace ash