OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/always_on_top_controller.h" | 5 #include "ash/wm/always_on_top_controller.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/wm/property_util.h" | 8 #include "ash/wm/property_util.h" |
9 #include "ash/wm/workspace_controller.h" | 9 #include "ash/wm/workspace_controller.h" |
10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 | 12 |
13 namespace ash { | 13 namespace ash { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 AlwaysOnTopController::AlwaysOnTopController() | 16 AlwaysOnTopController::AlwaysOnTopController() |
17 : default_container_(NULL), | 17 : always_on_top_container_(NULL) { |
18 always_on_top_container_(NULL) { | |
19 } | 18 } |
20 | 19 |
21 AlwaysOnTopController::~AlwaysOnTopController() { | 20 AlwaysOnTopController::~AlwaysOnTopController() { |
22 if (default_container_) | |
23 default_container_->RemoveObserver(this); | |
24 if (always_on_top_container_) | 21 if (always_on_top_container_) |
25 always_on_top_container_->RemoveObserver(this); | 22 always_on_top_container_->RemoveObserver(this); |
26 } | 23 } |
27 | 24 |
28 void AlwaysOnTopController::SetContainers( | 25 void AlwaysOnTopController::SetAlwaysOnTopContainer( |
29 aura::Window* default_container, | |
30 aura::Window* always_on_top_container) { | 26 aura::Window* always_on_top_container) { |
31 if (WorkspaceController::IsWorkspace2Enabled()) | 27 // Container should be empty. |
32 default_container = NULL; | |
33 | |
34 // Both containers should have no children. | |
35 DCHECK(always_on_top_container->children().empty()); | 28 DCHECK(always_on_top_container->children().empty()); |
36 | 29 |
37 // We are not handling any containers yet. | 30 // We are not handling any containers yet. |
38 DCHECK(default_container_ == NULL && always_on_top_container_ == NULL); | 31 DCHECK(always_on_top_container_ == NULL); |
39 | |
40 default_container_ = default_container; | |
41 if (default_container_) | |
42 default_container_->AddObserver(this); | |
43 | 32 |
44 always_on_top_container_ = always_on_top_container; | 33 always_on_top_container_ = always_on_top_container; |
45 always_on_top_container_->AddObserver(this); | 34 always_on_top_container_->AddObserver(this); |
46 } | 35 } |
47 | 36 |
48 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const { | 37 aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const { |
49 DCHECK(always_on_top_container_ && | 38 DCHECK(always_on_top_container_); |
50 (default_container_ || WorkspaceController::IsWorkspace2Enabled())); | |
51 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) | 39 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) |
52 return always_on_top_container_; | 40 return always_on_top_container_; |
53 if (default_container_) | |
54 return default_container_; | |
55 return GetRootWindowController(always_on_top_container_->GetRootWindow())-> | 41 return GetRootWindowController(always_on_top_container_->GetRootWindow())-> |
56 workspace_controller()->GetParentForNewWindow(window); | 42 workspace_controller()->GetParentForNewWindow(window); |
57 } | 43 } |
58 | 44 |
59 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) { | 45 void AlwaysOnTopController::OnWindowAdded(aura::Window* child) { |
60 // Observe direct child of the containers. | 46 // Observe direct child of the containers. |
61 if ((default_container_ && child->parent() == default_container_) || | 47 if (child->parent() == always_on_top_container_) |
62 child->parent() == always_on_top_container_) { | |
63 child->AddObserver(this); | 48 child->AddObserver(this); |
64 } | |
65 } | 49 } |
66 | 50 |
67 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) { | 51 void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) { |
68 child->RemoveObserver(this); | 52 child->RemoveObserver(this); |
69 } | 53 } |
70 | 54 |
71 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, | 55 void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, |
72 const void* key, | 56 const void* key, |
73 intptr_t old) { | 57 intptr_t old) { |
74 if (key == aura::client::kAlwaysOnTopKey) { | 58 if (key == aura::client::kAlwaysOnTopKey) { |
75 DCHECK(window->type() == aura::client::WINDOW_TYPE_NORMAL || | 59 DCHECK(window->type() == aura::client::WINDOW_TYPE_NORMAL || |
76 window->type() == aura::client::WINDOW_TYPE_POPUP); | 60 window->type() == aura::client::WINDOW_TYPE_POPUP); |
77 aura::Window* container = GetContainer(window); | 61 aura::Window* container = GetContainer(window); |
78 if (window->parent() != container) | 62 if (window->parent() != container) |
79 container->AddChild(window); | 63 container->AddChild(window); |
80 } | 64 } |
81 } | 65 } |
82 | 66 |
83 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) { | 67 void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) { |
84 if (window == default_container_) | |
85 default_container_ = NULL; | |
86 if (window == always_on_top_container_) | 68 if (window == always_on_top_container_) |
87 always_on_top_container_ = NULL; | 69 always_on_top_container_ = NULL; |
88 } | 70 } |
89 | 71 |
90 } // namespace internal | 72 } // namespace internal |
91 } // namespace ash | 73 } // namespace ash |
OLD | NEW |