Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / wm / always_on_top_controller.cc
blobe968e3591fddb16fc31950b13167e85a8dcde60d
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 "ash/wm/workspace/workspace_layout_manager.h"
10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/window.h"
13 namespace ash {
15 AlwaysOnTopController::AlwaysOnTopController(aura::Window* viewport)
16 : always_on_top_container_(viewport) {
17 always_on_top_container_->SetLayoutManager(
18 new WorkspaceLayoutManager(viewport));
19 // Container should be empty.
20 DCHECK(always_on_top_container_->children().empty());
21 always_on_top_container_->AddObserver(this);
24 AlwaysOnTopController::~AlwaysOnTopController() {
25 if (always_on_top_container_)
26 always_on_top_container_->RemoveObserver(this);
29 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const {
30 DCHECK(always_on_top_container_);
31 if (window->GetProperty(aura::client::kAlwaysOnTopKey))
32 return always_on_top_container_;
33 return Shell::GetContainer(always_on_top_container_->GetRootWindow(),
34 kShellWindowId_DefaultContainer);
37 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) {
38 // Observe direct child of the containers.
39 if (child->parent() == always_on_top_container_)
40 child->AddObserver(this);
43 void AlwaysOnTopController::SetLayoutManagerForTest(
44 WorkspaceLayoutManager* layout_manager) {
45 always_on_top_container_->SetLayoutManager(layout_manager);
48 // TODO(rsadam@): Refactor so that this cast is unneeded.
49 WorkspaceLayoutManager* AlwaysOnTopController::GetLayoutManager() const {
50 return static_cast<WorkspaceLayoutManager*>(
51 always_on_top_container_->layout_manager());
54 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) {
55 child->RemoveObserver(this);
58 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window,
59 const void* key,
60 intptr_t old) {
61 if (key == aura::client::kAlwaysOnTopKey) {
62 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL ||
63 window->type() == ui::wm::WINDOW_TYPE_POPUP);
64 aura::Window* container = GetContainer(window);
65 if (window->parent() != container)
66 container->AddChild(window);
70 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) {
71 if (window == always_on_top_container_)
72 always_on_top_container_ = NULL;
75 } // namespace ash