Move render_view_context_menu.* and related files out of tab_contents.
[chromium-blink-merge.git] / ash / wm / always_on_top_controller.cc
blobc0f73568cd09b9009e01c5f022a49ab554a49293
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 {
13 namespace internal {
15 AlwaysOnTopController::AlwaysOnTopController()
16 : always_on_top_container_(NULL) {
19 AlwaysOnTopController::~AlwaysOnTopController() {
20 if (always_on_top_container_)
21 always_on_top_container_->RemoveObserver(this);
24 void AlwaysOnTopController::SetAlwaysOnTopContainer(
25 aura::Window* always_on_top_container) {
26 // Container should be empty.
27 DCHECK(always_on_top_container->children().empty());
29 // We are not handling any containers yet.
30 DCHECK(always_on_top_container_ == NULL);
32 always_on_top_container_ = always_on_top_container;
33 always_on_top_container_->AddObserver(this);
36 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const {
37 DCHECK(always_on_top_container_);
38 if (window->GetProperty(aura::client::kAlwaysOnTopKey))
39 return always_on_top_container_;
40 return Shell::GetContainer(always_on_top_container_->GetRootWindow(),
41 kShellWindowId_DefaultContainer);
44 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) {
45 // Observe direct child of the containers.
46 if (child->parent() == always_on_top_container_)
47 child->AddObserver(this);
50 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) {
51 child->RemoveObserver(this);
54 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window,
55 const void* key,
56 intptr_t old) {
57 if (key == aura::client::kAlwaysOnTopKey) {
58 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL ||
59 window->type() == ui::wm::WINDOW_TYPE_POPUP);
60 aura::Window* container = GetContainer(window);
61 if (window->parent() != container)
62 container->AddChild(window);
66 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) {
67 if (window == always_on_top_container_)
68 always_on_top_container_ = NULL;
71 } // namespace internal
72 } // namespace ash