OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ui/aura_shell/stacking_controller.h" | 5 #include "ui/aura_shell/stacking_controller.h" |
6 | 6 |
7 #include "ui/aura/client/aura_constants.h" | 7 #include "ui/aura/client/aura_constants.h" |
8 #include "ui/aura/root_window.h" | 8 #include "ui/aura/root_window.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura_shell/always_on_top_controller.h" | 10 #include "ui/aura_shell/always_on_top_controller.h" |
11 #include "ui/aura_shell/shell.h" | 11 #include "ui/aura_shell/shell.h" |
12 #include "ui/aura_shell/shell_window_ids.h" | 12 #include "ui/aura_shell/shell_window_ids.h" |
13 | 13 |
14 namespace aura_shell { | 14 namespace aura_shell { |
15 namespace internal { | 15 namespace internal { |
16 namespace { | 16 namespace { |
17 | 17 |
18 aura::Window* GetContainer(int id) { | 18 aura::Window* GetContainer(int id) { |
19 return Shell::GetInstance()->GetContainer(id); | 19 return Shell::GetInstance()->GetContainer(id); |
20 } | 20 } |
21 | 21 |
22 // Returns true if children of |window| can be activated. | |
23 bool SupportsChildActivation(aura::Window* window) { | |
24 return window->id() == kShellWindowId_DefaultContainer || | |
25 window->id() == kShellWindowId_AlwaysOnTopContainer || | |
26 window->id() == kShellWindowId_ModalContainer || | |
27 window->id() == kShellWindowId_LockModalContainer; | |
28 } | |
29 | |
30 bool IsWindowModal(aura::Window* window) { | 22 bool IsWindowModal(aura::Window* window) { |
31 return window->transient_parent() && window->GetIntProperty(aura::kModalKey); | 23 return window->transient_parent() && window->GetIntProperty(aura::kModalKey); |
32 } | 24 } |
33 | 25 |
34 } // namespace | 26 } // namespace |
35 | 27 |
36 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
37 // StackingController, public: | 29 // StackingController, public: |
38 | 30 |
39 StackingController::StackingController() { | 31 StackingController::StackingController() { |
40 aura::RootWindow::GetInstance()->SetStackingClient(this); | 32 aura::RootWindow::GetInstance()->SetStackingClient(this); |
41 } | 33 } |
42 | 34 |
43 StackingController::~StackingController() { | 35 StackingController::~StackingController() { |
44 } | 36 } |
45 | 37 |
46 void StackingController::Init() { | 38 void StackingController::Init() { |
47 always_on_top_controller_.reset(new internal::AlwaysOnTopController); | 39 always_on_top_controller_.reset(new internal::AlwaysOnTopController); |
48 always_on_top_controller_->SetContainers( | 40 always_on_top_controller_->SetContainers( |
49 GetContainer(internal::kShellWindowId_DefaultContainer), | 41 GetContainer(internal::kShellWindowId_DefaultContainer), |
50 GetContainer(internal::kShellWindowId_AlwaysOnTopContainer)); | 42 GetContainer(internal::kShellWindowId_AlwaysOnTopContainer)); |
51 } | 43 } |
52 | 44 |
53 // static | |
54 aura::Window* StackingController::GetActivatableWindow(aura::Window* window) { | |
55 aura::Window* parent = window->parent(); | |
56 aura::Window* child = window; | |
57 while (parent) { | |
58 if (SupportsChildActivation(parent)) | |
59 return child; | |
60 // If |child| isn't activatable, but has transient parent, trace | |
61 // that path instead. | |
62 if (child->transient_parent()) | |
63 return GetActivatableWindow(child->transient_parent()); | |
64 parent = parent->parent(); | |
65 child = child->parent(); | |
66 } | |
67 return NULL; | |
68 } | |
69 | |
70 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
71 // StackingController, aura::StackingClient implementation: | 46 // StackingController, aura::StackingClient implementation: |
72 | 47 |
73 void StackingController::AddChildToDefaultParent(aura::Window* window) { | 48 void StackingController::AddChildToDefaultParent(aura::Window* window) { |
74 aura::Window* parent = NULL; | 49 aura::Window* parent = NULL; |
75 switch (window->type()) { | 50 switch (window->type()) { |
76 case aura::WINDOW_TYPE_NORMAL: | 51 case aura::WINDOW_TYPE_NORMAL: |
77 case aura::WINDOW_TYPE_POPUP: | 52 case aura::WINDOW_TYPE_POPUP: |
78 if (IsWindowModal(window)) { | 53 if (IsWindowModal(window)) { |
79 parent = GetModalContainer(window); | 54 parent = GetModalContainer(window); |
80 break; | 55 break; |
81 } | 56 } |
82 parent = always_on_top_controller_->GetContainer(window); | 57 parent = always_on_top_controller_->GetContainer(window); |
83 break; | 58 break; |
84 case aura::WINDOW_TYPE_MENU: | 59 case aura::WINDOW_TYPE_MENU: |
85 case aura::WINDOW_TYPE_TOOLTIP: | 60 case aura::WINDOW_TYPE_TOOLTIP: |
86 parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); | 61 parent = GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); |
87 break; | 62 break; |
88 default: | 63 default: |
89 NOTREACHED() << "Window " << window->id() | 64 NOTREACHED() << "Window " << window->id() |
90 << " has unhandled type " << window->type(); | 65 << " has unhandled type " << window->type(); |
91 break; | 66 break; |
92 } | 67 } |
93 parent->AddChild(window); | 68 parent->AddChild(window); |
94 } | 69 } |
95 | 70 |
96 bool StackingController::CanActivateWindow(aura::Window* window) const { | |
97 return window && SupportsChildActivation(window->parent()); | |
98 } | |
99 | |
100 aura::Window* StackingController::GetTopmostWindowToActivate( | |
101 aura::Window* ignore) const { | |
102 const aura::Window* container = GetContainer(kShellWindowId_DefaultContainer); | |
103 for (aura::Window::Windows::const_reverse_iterator i = | |
104 container->children().rbegin(); | |
105 i != container->children().rend(); | |
106 ++i) { | |
107 if (*i != ignore && (*i)->CanActivate()) | |
108 return *i; | |
109 } | |
110 return NULL; | |
111 } | |
112 | |
113 | |
114 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
115 // StackingController, private: | 72 // StackingController, private: |
116 | 73 |
117 aura::Window* StackingController::GetModalContainer( | 74 aura::Window* StackingController::GetModalContainer( |
118 aura::Window* window) const { | 75 aura::Window* window) const { |
119 if (!IsWindowModal(window)) | 76 if (!IsWindowModal(window)) |
120 return NULL; | 77 return NULL; |
121 | 78 |
122 // If screen lock is not active, all modal windows are placed into the | 79 // If screen lock is not active, all modal windows are placed into the |
123 // normal modal container. | 80 // normal modal container. |
(...skipping 11 matching lines...) Expand all Loading... |
135 if (window_container_id < lock_container_id) | 92 if (window_container_id < lock_container_id) |
136 container = GetContainer(internal::kShellWindowId_ModalContainer); | 93 container = GetContainer(internal::kShellWindowId_ModalContainer); |
137 else | 94 else |
138 container = GetContainer(internal::kShellWindowId_LockModalContainer); | 95 container = GetContainer(internal::kShellWindowId_LockModalContainer); |
139 | 96 |
140 return container; | 97 return container; |
141 } | 98 } |
142 | 99 |
143 } // namespace internal | 100 } // namespace internal |
144 } // namespace aura_shell | 101 } // namespace aura_shell |
OLD | NEW |