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