| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "ui/aura_shell/always_on_top_controller.h" | |
| 6 | |
| 7 #include "ui/aura/client/aura_constants.h" | |
| 8 #include "ui/aura/window.h" | |
| 9 | |
| 10 namespace aura_shell { | |
| 11 namespace internal { | |
| 12 | |
| 13 AlwaysOnTopController::AlwaysOnTopController() | |
| 14 : default_container_(NULL), | |
| 15 always_on_top_container_(NULL) { | |
| 16 } | |
| 17 | |
| 18 AlwaysOnTopController::~AlwaysOnTopController() { | |
| 19 if (default_container_) | |
| 20 default_container_->RemoveObserver(this); | |
| 21 if (always_on_top_container_) | |
| 22 always_on_top_container_->RemoveObserver(this); | |
| 23 } | |
| 24 | |
| 25 void AlwaysOnTopController::SetContainers(aura::Window* default_container, | |
| 26 aura::Window* always_on_top_container) { | |
| 27 // Both containers should have no children. | |
| 28 DCHECK(default_container->children().empty()); | |
| 29 DCHECK(always_on_top_container->children().empty()); | |
| 30 | |
| 31 // We are not handling any containers yet. | |
| 32 DCHECK(default_container_ == NULL && always_on_top_container_ == NULL); | |
| 33 | |
| 34 default_container_ = default_container; | |
| 35 default_container_->AddObserver(this); | |
| 36 | |
| 37 always_on_top_container_ = always_on_top_container; | |
| 38 always_on_top_container_->AddObserver(this); | |
| 39 } | |
| 40 | |
| 41 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const { | |
| 42 DCHECK(default_container_ && always_on_top_container_); | |
| 43 return !window->GetProperty(aura::client::kAlwaysOnTopKey) ? | |
| 44 default_container_ : always_on_top_container_; | |
| 45 } | |
| 46 | |
| 47 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) { | |
| 48 // Observe direct child of the containers. | |
| 49 if (child->parent() == default_container_ || | |
| 50 child->parent() == always_on_top_container_) { | |
| 51 child->AddObserver(this); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) { | |
| 56 child->RemoveObserver(this); | |
| 57 } | |
| 58 | |
| 59 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, | |
| 60 const char* name, | |
| 61 void* old) { | |
| 62 if (name == aura::client::kAlwaysOnTopKey) { | |
| 63 DCHECK(window->type() == aura::client::WINDOW_TYPE_NORMAL || | |
| 64 window->type() == aura::client::WINDOW_TYPE_POPUP); | |
| 65 aura::Window* container = GetContainer(window); | |
| 66 if (window->parent() != container) | |
| 67 container->AddChild(window); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) { | |
| 72 if (window == default_container_) | |
| 73 default_container_ = NULL; | |
| 74 if (window == always_on_top_container_) | |
| 75 always_on_top_container_ = NULL; | |
| 76 } | |
| 77 | |
| 78 } // namespace internal | |
| 79 } // namespace aura_shell | |
| OLD | NEW |