Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: athena/screen/screen_manager_impl.cc

Issue 662763002: Support modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: fix leaks Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/screen/screen_manager_impl.h ('k') | athena/screen/screen_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "athena/screen/public/screen_manager.h" 5 #include "athena/screen/screen_manager_impl.h"
6 6
7 #include "athena/input/public/accelerator_manager.h" 7 #include "athena/input/public/accelerator_manager.h"
8 #include "athena/screen/modal_window_controller.h"
8 #include "athena/screen/screen_accelerator_handler.h" 9 #include "athena/screen/screen_accelerator_handler.h"
9 #include "athena/util/container_priorities.h" 10 #include "athena/util/container_priorities.h"
10 #include "athena/util/fill_layout_manager.h" 11 #include "athena/util/fill_layout_manager.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/client/screen_position_client.h" 15 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/client/window_tree_client.h"
15 #include "ui/aura/layout_manager.h"
16 #include "ui/aura/test/test_screen.h" 16 #include "ui/aura/test/test_screen.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_property.h" 18 #include "ui/aura/window_property.h"
19 #include "ui/aura/window_targeter.h" 19 #include "ui/aura/window_targeter.h"
20 #include "ui/aura/window_tree_host.h" 20 #include "ui/aura/window_tree_host.h"
21 #include "ui/compositor/layer.h"
22 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
23 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
24 #include "ui/wm/core/base_focus_rules.h" 23 #include "ui/wm/core/base_focus_rules.h"
25 #include "ui/wm/core/capture_controller.h" 24 #include "ui/wm/core/capture_controller.h"
26 #include "ui/wm/core/focus_controller.h" 25 #include "ui/wm/core/focus_controller.h"
27 #include "ui/wm/core/window_util.h" 26 #include "ui/wm/core/window_util.h"
28 27
28 // This is to avoid creating type definitoin for kAlwaysOnTopKey.
29 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ATHENA_EXPORT, bool);
30
29 namespace athena { 31 namespace athena {
30 namespace { 32 namespace {
31 33
32 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, 34 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams,
33 kContainerParamsKey, 35 kContainerParamsKey,
34 NULL); 36 NULL);
35 37
36 ScreenManager* instance = NULL; 38 ScreenManagerImpl* instance = NULL;
37 39
38 bool GrabsInput(aura::Window* container) { 40 // A functor to find a container that has the higher priority.
41 struct HigherPriorityFinder {
42 HigherPriorityFinder(int p) : priority(p) {}
43 bool operator()(aura::Window* window) {
44 return window->GetProperty(kContainerParamsKey)->z_order_priority >
45 priority;
46 }
47 int priority;
48 };
49
50 bool BlockEvents(aura::Window* container) {
39 ScreenManager::ContainerParams* params = 51 ScreenManager::ContainerParams* params =
40 container->GetProperty(kContainerParamsKey); 52 container->GetProperty(kContainerParamsKey);
41 return params && params->grab_inputs; 53 return params && params->block_events;
54 }
55
56 bool DefaultContainer(aura::Window* container) {
57 ScreenManager::ContainerParams* params =
58 container->GetProperty(kContainerParamsKey);
59 return params && params->default_parent;
60 }
61
62 bool HasModalContainerPriority(aura::Window* container) {
63 ScreenManager::ContainerParams* params =
64 container->GetProperty(kContainerParamsKey);
65 return params && params->modal_container_priority != -1;
66 }
67
68 bool IsSystemModal(aura::Window* window) {
69 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM;
42 } 70 }
43 71
44 // Returns the container which contains |window|. 72 // Returns the container which contains |window|.
45 aura::Window* GetContainer(aura::Window* window) { 73 aura::Window* GetContainer(aura::Window* window) {
46 aura::Window* container = window; 74 aura::Window* container = window;
47 while (container && !container->GetProperty(kContainerParamsKey)) 75 while (container && !container->GetProperty(kContainerParamsKey))
48 container = container->parent(); 76 container = container->parent();
49 return container; 77 return container;
50 } 78 }
51 79
52 class AthenaFocusRules : public wm::BaseFocusRules { 80 class AthenaFocusRules : public wm::BaseFocusRules {
53 public: 81 public:
54 AthenaFocusRules() {} 82 AthenaFocusRules() {}
55 virtual ~AthenaFocusRules() {} 83 virtual ~AthenaFocusRules() {}
56 84
57 // wm::BaseFocusRules: 85 // wm::BaseFocusRules:
58 virtual bool SupportsChildActivation(aura::Window* window) const override { 86 virtual bool SupportsChildActivation(aura::Window* window) const override {
59 ScreenManager::ContainerParams* params = 87 ScreenManager::ContainerParams* params =
60 window->GetProperty(kContainerParamsKey); 88 window->GetProperty(kContainerParamsKey);
61 return params && params->can_activate_children; 89 return params && params->can_activate_children;
62 } 90 }
63 virtual bool CanActivateWindow(aura::Window* window) const override { 91 virtual bool CanActivateWindow(aura::Window* window) const override {
64 // Check if containers of higher z-order than |window| have 'grab_inputs' 92 if (!window)
93 return true;
94
95 // Check if containers of higher z-order than |window| have 'block_events'
65 // fields. 96 // fields.
66 if (window) { 97 if (window->GetRootWindow()) {
67 const aura::Window::Windows& containers = 98 const aura::Window::Windows& containers =
68 window->GetRootWindow()->children(); 99 window->GetRootWindow()->children();
69 aura::Window::Windows::const_iterator iter = 100 aura::Window::Windows::const_iterator iter =
70 std::find(containers.begin(), containers.end(), GetContainer(window)); 101 std::find(containers.begin(), containers.end(), GetContainer(window));
71 DCHECK(iter != containers.end()); 102 DCHECK(iter != containers.end());
72 for (++iter; iter != containers.end(); ++iter) { 103 for (++iter; iter != containers.end(); ++iter) {
73 if (GrabsInput(*iter)) 104 if (BlockEvents(*iter))
74 return false; 105 return false;
75 } 106 }
76 } 107 }
77 return BaseFocusRules::CanActivateWindow(window); 108 return BaseFocusRules::CanActivateWindow(window);
78 } 109 }
79 110
111 virtual aura::Window* GetNextActivatableWindow(
112 aura::Window* ignore) const override {
113 aura::Window* next = wm::BaseFocusRules::GetNextActivatableWindow(ignore);
114 // TODO(oshima): Search from activatable containers if |next| is NULL.
115 return next;
116 }
117
80 private: 118 private:
81 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); 119 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules);
82 }; 120 };
83 121
84 class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
85 public:
86 explicit AthenaWindowTreeClient(aura::Window* container)
87 : container_(container) {}
88
89 private:
90 virtual ~AthenaWindowTreeClient() {}
91
92 // aura::client::WindowTreeClient:
93 virtual aura::Window* GetDefaultParent(aura::Window* context,
94 aura::Window* window,
95 const gfx::Rect& bounds) override {
96 aura::Window* transient_parent = wm::GetTransientParent(window);
97 if (transient_parent)
98 return GetContainer(transient_parent);
99 return container_;
100 }
101
102 aura::Window* container_;
103
104 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient);
105 };
106
107 class AthenaScreenPositionClient : public aura::client::ScreenPositionClient { 122 class AthenaScreenPositionClient : public aura::client::ScreenPositionClient {
108 public: 123 public:
109 AthenaScreenPositionClient() { 124 AthenaScreenPositionClient() {
110 } 125 }
111 virtual ~AthenaScreenPositionClient() { 126 virtual ~AthenaScreenPositionClient() {
112 } 127 }
113 128
114 private: 129 private:
115 // aura::client::ScreenPositionClient: 130 // aura::client::ScreenPositionClient:
116 virtual void ConvertPointToScreen(const aura::Window* window, 131 virtual void ConvertPointToScreen(const aura::Window* window,
(...skipping 16 matching lines...) Expand all
133 148
134 virtual void SetBounds(aura::Window* window, 149 virtual void SetBounds(aura::Window* window,
135 const gfx::Rect& bounds, 150 const gfx::Rect& bounds,
136 const gfx::Display& display) override { 151 const gfx::Display& display) override {
137 window->SetBounds(bounds); 152 window->SetBounds(bounds);
138 } 153 }
139 154
140 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); 155 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient);
141 }; 156 };
142 157
143 class AthenaEventTargeter : public aura::WindowTargeter, 158 class AthenaWindowTargeter : public aura::WindowTargeter {
144 public aura::WindowObserver {
145 public: 159 public:
146 explicit AthenaEventTargeter(aura::Window* container) 160 explicit AthenaWindowTargeter(aura::Window* root_window)
147 : container_(container) { 161 : root_window_(root_window) {}
148 container_->AddObserver(this);
149 }
150 162
151 virtual ~AthenaEventTargeter() { 163 virtual ~AthenaWindowTargeter() {}
152 // Removed before the container is removed.
153 if (container_)
154 container_->RemoveObserver(this);
155 }
156
157 void SetPreviousEventTargeter(scoped_ptr<ui::EventTargeter> targeter) {
158 previous_root_event_targeter_ = targeter.Pass();
159 }
160 164
161 private: 165 private:
162 // aura::WindowTargeter: 166 // aura::WindowTargeter:
163 virtual bool SubtreeCanAcceptEvent( 167 virtual bool SubtreeCanAcceptEvent(
164 ui::EventTarget* target, 168 ui::EventTarget* target,
165 const ui::LocatedEvent& event) const override { 169 const ui::LocatedEvent& event) const override {
170 const aura::Window::Windows& containers = root_window_->children();
171 auto r_iter =
172 std::find_if(containers.rbegin(), containers.rend(), &BlockEvents);
173 if (r_iter == containers.rend())
174 return aura::WindowTargeter::SubtreeCanAcceptEvent(target, event);
175
166 aura::Window* window = static_cast<aura::Window*>(target); 176 aura::Window* window = static_cast<aura::Window*>(target);
167 const aura::Window::Windows& containers = 177 for (;; --r_iter) {
168 container_->GetRootWindow()->children(); 178 if ((*r_iter)->Contains(window))
169 aura::Window::Windows::const_iterator iter = 179 return aura::WindowTargeter::SubtreeCanAcceptEvent(target, event);
170 std::find(containers.begin(), containers.end(), container_); 180 if (r_iter == containers.rbegin())
171 DCHECK(iter != containers.end()); 181 break;
172 for (; iter != containers.end(); ++iter) {
173 if ((*iter)->Contains(window))
174 return true;
175 } 182 }
176 return false; 183 return false;
177 } 184 }
178 185
179 // aura::WindowObserver: 186 virtual ui::EventTarget* FindTargetForLocatedEvent(
180 virtual void OnWindowDestroying(aura::Window* window) override { 187 ui::EventTarget* root,
181 aura::Window* root_window = container_->GetRootWindow(); 188 ui::LocatedEvent* event) override {
182 DCHECK_EQ(window, container_); 189 ui::EventTarget* target =
183 DCHECK_EQ( 190 aura::WindowTargeter::FindTargetForLocatedEvent(root, event);
184 this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter()); 191 if (target)
185 192 return target;
186 container_->RemoveObserver(this); 193 // If the root target is blocking the event, return the container even if
187 container_ = NULL; 194 // there is no target found so that windows behind it will not be searched.
188 195 const ScreenManager::ContainerParams* params =
189 // This will remove myself. 196 static_cast<aura::Window*>(root)->GetProperty(kContainerParamsKey);
190 root_window->SetEventTargeter(previous_root_event_targeter_.Pass()); 197 return (params && params->block_events) ? root : NULL;
191 } 198 }
192 199
193 aura::Window* container_;
194 scoped_ptr<ui::EventTargeter> previous_root_event_targeter_;
195
196 DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter);
197 };
198
199 class ScreenManagerImpl : public ScreenManager {
200 public:
201 explicit ScreenManagerImpl(aura::Window* root_window);
202 virtual ~ScreenManagerImpl();
203
204 void Init();
205
206 private:
207 // ScreenManager:
208 virtual aura::Window* CreateDefaultContainer(
209 const ContainerParams& params) override;
210 virtual aura::Window* CreateContainer(const ContainerParams& params) override;
211 virtual aura::Window* GetContext() override { return root_window_; }
212 virtual void SetRotation(gfx::Display::Rotation rotation) override;
213 virtual void SetRotationLocked(bool rotation_locked) override;
214
215 // Not owned. 200 // Not owned.
216 aura::Window* root_window_; 201 aura::Window* root_window_;
217 202
218 scoped_ptr<aura::client::FocusClient> focus_client_; 203 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTargeter);
219 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; 204 };
220 scoped_ptr<AcceleratorHandler> accelerator_handler_;
221 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_;
222 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_;
223 205
224 gfx::Display::Rotation last_requested_rotation_; 206 } // namespace
225 bool rotation_locked_;
226
227 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
228 };
229 207
230 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) 208 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
231 : root_window_(root_window), 209 : root_window_(root_window),
232 last_requested_rotation_(gfx::Display::ROTATE_0), 210 last_requested_rotation_(gfx::Display::ROTATE_0),
233 rotation_locked_(false) { 211 rotation_locked_(false) {
234 DCHECK(root_window_); 212 DCHECK(root_window_);
235 DCHECK(!instance); 213 DCHECK(!instance);
236 instance = this; 214 instance = this;
237 } 215 }
238 216
(...skipping 20 matching lines...) Expand all
259 new wm::FocusController(new AthenaFocusRules()); 237 new wm::FocusController(new AthenaFocusRules());
260 238
261 aura::client::SetFocusClient(root_window_, focus_controller); 239 aura::client::SetFocusClient(root_window_, focus_controller);
262 root_window_->AddPreTargetHandler(focus_controller); 240 root_window_->AddPreTargetHandler(focus_controller);
263 aura::client::SetActivationClient(root_window_, focus_controller); 241 aura::client::SetActivationClient(root_window_, focus_controller);
264 focus_client_.reset(focus_controller); 242 focus_client_.reset(focus_controller);
265 243
266 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); 244 root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
267 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); 245 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_));
268 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); 246 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_));
269 }
270 247
271 aura::Window* ScreenManagerImpl::CreateDefaultContainer( 248 aura::client::SetWindowTreeClient(root_window_, this);
272 const ContainerParams& params) {
273 aura::Window* container = CreateContainer(params);
274 window_tree_client_.reset(new AthenaWindowTreeClient(container));
275 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get());
276 249
277 screen_position_client_.reset(new AthenaScreenPositionClient()); 250 screen_position_client_.reset(new AthenaScreenPositionClient());
278 aura::client::SetScreenPositionClient(root_window_, 251 aura::client::SetScreenPositionClient(root_window_,
279 screen_position_client_.get()); 252 screen_position_client_.get());
280 253 root_window_->SetEventTargeter(
281 return container; 254 make_scoped_ptr(new AthenaWindowTargeter(root_window_)));
282 } 255 }
283 256
284 // A functor to find a container that has the higher priority. 257 aura::Window* ScreenManagerImpl::FindContainerByPriority(int priority) {
285 struct HigherPriorityFinder { 258 for (aura::Window* window : root_window_->children()) {
286 HigherPriorityFinder(int p) : priority(p) {} 259 if (window->GetProperty(kContainerParamsKey)->z_order_priority == priority)
287 bool operator()(aura::Window* window) { 260 return window;
288 return window->GetProperty(kContainerParamsKey)->z_order_priority >
289 priority;
290 } 261 }
291 int priority; 262 return NULL;
292 }; 263 }
293
294 #if !defined(NDEBUG)
295 struct PriorityMatcher {
296 PriorityMatcher(int p) : priority(p) {}
297 bool operator()(aura::Window* window) {
298 return window->GetProperty(kContainerParamsKey)->z_order_priority ==
299 priority;
300 }
301 int priority;
302 };
303 #endif
304 264
305 aura::Window* ScreenManagerImpl::CreateContainer( 265 aura::Window* ScreenManagerImpl::CreateContainer(
306 const ContainerParams& params) { 266 const ContainerParams& params) {
267 const aura::Window::Windows& children = root_window_->children();
268
269 if (params.default_parent) {
270 CHECK(std::find_if(children.begin(), children.end(), &DefaultContainer) ==
271 children.end());
272 }
273 // mmodal container's priority must be higher than the container's priority.
274 DCHECK(params.modal_container_priority == -1 ||
275 params.modal_container_priority > params.z_order_priority);
276 // Default parent must specify modal_container_priority.
277 DCHECK(!params.default_parent || params.modal_container_priority != -1);
278
307 aura::Window* container = new aura::Window(NULL); 279 aura::Window* container = new aura::Window(NULL);
308 CHECK_GE(params.z_order_priority, 0); 280 CHECK_GE(params.z_order_priority, 0);
309 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); 281 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
310 container->SetName(params.name); 282 container->SetName(params.name);
311 283
312 const aura::Window::Windows& children = root_window_->children(); 284 DCHECK(!FindContainerByPriority(params.z_order_priority))
313 285 << "The container with the priority " << params.z_order_priority
314 #if !defined(NDEBUG) 286 << " already exists.";
315 DCHECK(std::find_if(children.begin(),
316 children.end(),
317 PriorityMatcher(params.z_order_priority))
318 == children.end())
319 << "The container with the priority "
320 << params.z_order_priority << " already exists.";
321 #endif
322 287
323 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); 288 container->SetProperty(kContainerParamsKey, new ContainerParams(params));
324 289
325 // If another container is already grabbing the input, SetEventTargeter
326 // implicitly release the grabbing and remove the EventTargeter instance.
327 // TODO(mukai|oshima): think about the ideal behavior of multiple grabbing
328 // and implement it.
329 if (params.grab_inputs) {
330 DCHECK(std::find_if(children.begin(), children.end(), &GrabsInput)
331 == children.end())
332 << "input has already been grabbed by another container";
333 AthenaEventTargeter* athena_event_targeter =
334 new AthenaEventTargeter(container);
335 athena_event_targeter->SetPreviousEventTargeter(
336 root_window_->SetEventTargeter(
337 scoped_ptr<ui::EventTargeter>(athena_event_targeter)));
338 }
339
340 root_window_->AddChild(container); 290 root_window_->AddChild(container);
341 291
342 aura::Window::Windows::const_iterator iter = 292 aura::Window::Windows::const_iterator iter =
343 std::find_if(children.begin(), 293 std::find_if(children.begin(),
344 children.end(), 294 children.end(),
345 HigherPriorityFinder(params.z_order_priority)); 295 HigherPriorityFinder(params.z_order_priority));
346 if (iter != children.end()) 296 if (iter != children.end())
347 root_window_->StackChildBelow(container, *iter); 297 root_window_->StackChildBelow(container, *iter);
348 298
349 container->Show(); 299 container->Show();
350 return container; 300 return container;
351 } 301 }
352 302
303 aura::Window* ScreenManagerImpl::GetContext() {
304 return root_window_;
305 }
306
353 void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) { 307 void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) {
354 last_requested_rotation_ = rotation; 308 last_requested_rotation_ = rotation;
355 if (rotation_locked_ || rotation == 309 if (rotation_locked_ || rotation ==
356 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()) { 310 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()) {
357 return; 311 return;
358 } 312 }
359 313
360 // TODO(flackr): Use display manager to update display rotation: 314 // TODO(flackr): Use display manager to update display rotation:
361 // http://crbug.com/401044. 315 // http://crbug.com/401044.
362 static_cast<aura::TestScreen*>(gfx::Screen::GetNativeScreen())-> 316 static_cast<aura::TestScreen*>(gfx::Screen::GetNativeScreen())->
363 SetDisplayRotation(rotation); 317 SetDisplayRotation(rotation);
364 } 318 }
365 319
366 void ScreenManagerImpl::SetRotationLocked(bool rotation_locked) { 320 void ScreenManagerImpl::SetRotationLocked(bool rotation_locked) {
367 rotation_locked_ = rotation_locked; 321 rotation_locked_ = rotation_locked;
368 if (!rotation_locked_) 322 if (!rotation_locked_)
369 SetRotation(last_requested_rotation_); 323 SetRotation(last_requested_rotation_);
370 } 324 }
371 325
372 } // namespace 326 int ScreenManagerImpl::GetModalContainerPriority(aura::Window* window,
327 aura::Window* parent) {
328 const aura::Window::Windows& children = root_window_->children();
329 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) {
330 // Use top most modal container.
331 auto iter = std::find_if(
332 children.rbegin(), children.rend(), &HasModalContainerPriority);
333 DCHECK(iter != children.rend());
334 return (*iter)->GetProperty(kContainerParamsKey)->modal_container_priority;
335 } else {
336 // use the container closest to the parent which has modal
337 // container priority.
338 auto iter = std::find(children.rbegin(), children.rend(), parent);
339 DCHECK(iter != children.rend());
340 iter = std::find_if(iter, children.rend(), &HasModalContainerPriority);
341 DCHECK(iter != children.rend());
342 return (*iter)->GetProperty(kContainerParamsKey)->modal_container_priority;
343 }
344 }
345
346 aura::Window* ScreenManagerImpl::GetDefaultParent(aura::Window* context,
347 aura::Window* window,
348 const gfx::Rect& bounds) {
349 aura::Window* parent = wm::GetTransientParent(window);
350 if (parent)
351 parent = GetContainer(parent);
352 else
353 parent = GetDefaultContainer();
354
355 if (IsSystemModal(window)) {
356 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL ||
357 window->type() == ui::wm::WINDOW_TYPE_POPUP);
358 int priority = GetModalContainerPriority(window, parent);
359
360 parent = FindContainerByPriority(priority);
361 if (!parent) {
362 ModalWindowController* controller = new ModalWindowController(priority);
363 parent = controller->modal_container();
364 }
365 }
366 return parent;
367 }
368
369 aura::Window* ScreenManagerImpl::GetDefaultContainer() {
370 const aura::Window::Windows& children = root_window_->children();
371 return *(std::find_if(children.begin(), children.end(), &DefaultContainer));
372 }
373 373
374 ScreenManager::ContainerParams::ContainerParams(const std::string& n, 374 ScreenManager::ContainerParams::ContainerParams(const std::string& n,
375 int priority) 375 int priority)
376 : name(n), 376 : name(n),
377 can_activate_children(false), 377 can_activate_children(false),
378 grab_inputs(false), 378 block_events(false),
379 z_order_priority(priority) { 379 z_order_priority(priority),
380 default_parent(false),
381 modal_container_priority(-1) {
380 } 382 }
381 383
382 // static 384 // static
383 ScreenManager* ScreenManager::Create(aura::Window* root_window) { 385 ScreenManager* ScreenManager::Create(aura::Window* root_window) {
384 (new ScreenManagerImpl(root_window))->Init(); 386 (new ScreenManagerImpl(root_window))->Init();
385 DCHECK(instance); 387 DCHECK(instance);
386 return instance; 388 return instance;
387 } 389 }
388 390
389 // static 391 // static
390 ScreenManager* ScreenManager::Get() { 392 ScreenManager* ScreenManager::Get() {
391 DCHECK(instance); 393 DCHECK(instance);
392 return instance; 394 return instance;
393 } 395 }
394 396
395 // static 397 // static
396 void ScreenManager::Shutdown() { 398 void ScreenManager::Shutdown() {
397 DCHECK(instance); 399 DCHECK(instance);
398 delete instance; 400 delete instance;
399 DCHECK(!instance); 401 DCHECK(!instance);
400 } 402 }
401 403
402 } // namespace athena 404 } // namespace athena
OLDNEW
« no previous file with comments | « athena/screen/screen_manager_impl.h ('k') | athena/screen/screen_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698