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

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: 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
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 { 159 public aura::WindowObserver {
Jun Mukai 2014/10/17 17:29:54 It doesn't have to be WindowObserver anymore?
oshima 2014/10/17 18:20:04 Good catch. Done.
145 public: 160 public:
146 explicit AthenaEventTargeter(aura::Window* container) 161 explicit AthenaWindowTargeter(aura::Window* root_window)
147 : container_(container) { 162 : root_window_(root_window) {}
148 container_->AddObserver(this);
149 }
150 163
151 virtual ~AthenaEventTargeter() { 164 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 165
161 private: 166 private:
162 // aura::WindowTargeter: 167 // aura::WindowTargeter:
163 virtual bool SubtreeCanAcceptEvent( 168 virtual bool SubtreeCanAcceptEvent(
164 ui::EventTarget* target, 169 ui::EventTarget* target,
165 const ui::LocatedEvent& event) const override { 170 const ui::LocatedEvent& event) const override {
171 const aura::Window::Windows& containers = root_window_->children();
172 auto r_iter =
173 std::find_if(containers.rbegin(), containers.rend(), &BlockEvents);
174 if (r_iter == containers.rend())
175 return aura::WindowTargeter::SubtreeCanAcceptEvent(target, event);
176
166 aura::Window* window = static_cast<aura::Window*>(target); 177 aura::Window* window = static_cast<aura::Window*>(target);
167 const aura::Window::Windows& containers = 178 auto iter = std::find(containers.begin(), containers.end(), *r_iter);
168 container_->GetRootWindow()->children();
169 aura::Window::Windows::const_iterator iter =
170 std::find(containers.begin(), containers.end(), container_);
171 DCHECK(iter != containers.end()); 179 DCHECK(iter != containers.end());
172 for (; iter != containers.end(); ++iter) { 180 for (; iter != containers.end(); ++iter) {
Jun Mukai 2014/10/17 17:29:54 You can simply using r_iter (but --r_iter) right?
oshima 2014/10/17 18:20:06 You're right. done.
173 if ((*iter)->Contains(window)) 181 if ((*iter)->Contains(window))
174 return true; 182 return aura::WindowTargeter::SubtreeCanAcceptEvent(target, event);
175 } 183 }
176 return false; 184 return false;
177 } 185 }
178 186
179 // aura::WindowObserver: 187 virtual ui::EventTarget* FindTargetForLocatedEvent(
180 virtual void OnWindowDestroying(aura::Window* window) override { 188 ui::EventTarget* root,
181 aura::Window* root_window = container_->GetRootWindow(); 189 ui::LocatedEvent* event) override {
182 DCHECK_EQ(window, container_); 190 ui::EventTarget* target =
183 DCHECK_EQ( 191 aura::WindowTargeter::FindTargetForLocatedEvent(root, event);
184 this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter()); 192 if (target)
185 193 return target;
186 container_->RemoveObserver(this); 194 // If the root target is blocking the event, return the container even if
187 container_ = NULL; 195 // there is no target found so that windows behind it will not be searched.
188 196 const ScreenManager::ContainerParams* params =
189 // This will remove myself. 197 static_cast<aura::Window*>(root)->GetProperty(kContainerParamsKey);
190 root_window->SetEventTargeter(previous_root_event_targeter_.Pass()); 198 return (params && params->block_events) ? root : NULL;
191 } 199 }
192 200
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. 201 // Not owned.
216 aura::Window* root_window_; 202 aura::Window* root_window_;
217 203
218 scoped_ptr<aura::client::FocusClient> focus_client_; 204 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTargeter);
219 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; 205 };
220 scoped_ptr<AcceleratorHandler> accelerator_handler_;
221 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_;
222 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_;
223 206
224 gfx::Display::Rotation last_requested_rotation_; 207 } // namespace
225 bool rotation_locked_;
226
227 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
228 };
229 208
230 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) 209 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
231 : root_window_(root_window), 210 : root_window_(root_window),
232 last_requested_rotation_(gfx::Display::ROTATE_0), 211 last_requested_rotation_(gfx::Display::ROTATE_0),
233 rotation_locked_(false) { 212 rotation_locked_(false) {
234 DCHECK(root_window_); 213 DCHECK(root_window_);
235 DCHECK(!instance); 214 DCHECK(!instance);
236 instance = this; 215 instance = this;
237 } 216 }
238 217
(...skipping 20 matching lines...) Expand all
259 new wm::FocusController(new AthenaFocusRules()); 238 new wm::FocusController(new AthenaFocusRules());
260 239
261 aura::client::SetFocusClient(root_window_, focus_controller); 240 aura::client::SetFocusClient(root_window_, focus_controller);
262 root_window_->AddPreTargetHandler(focus_controller); 241 root_window_->AddPreTargetHandler(focus_controller);
263 aura::client::SetActivationClient(root_window_, focus_controller); 242 aura::client::SetActivationClient(root_window_, focus_controller);
264 focus_client_.reset(focus_controller); 243 focus_client_.reset(focus_controller);
265 244
266 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); 245 root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
267 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); 246 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_));
268 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); 247 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_));
269 }
270 248
271 aura::Window* ScreenManagerImpl::CreateDefaultContainer( 249 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 250
277 screen_position_client_.reset(new AthenaScreenPositionClient()); 251 screen_position_client_.reset(new AthenaScreenPositionClient());
278 aura::client::SetScreenPositionClient(root_window_, 252 aura::client::SetScreenPositionClient(root_window_,
279 screen_position_client_.get()); 253 screen_position_client_.get());
280 254 root_window_->SetEventTargeter(
281 return container; 255 scoped_ptr<ui::EventTargeter>(new AthenaWindowTargeter(root_window_)));
Jun Mukai 2014/10/17 17:29:54 make_scoped_ptr(...) is more concise
oshima 2014/10/17 18:20:04 Done.
282 } 256 }
283 257
284 // A functor to find a container that has the higher priority. 258 aura::Window* ScreenManagerImpl::FindContainerByPriority(int priority) {
285 struct HigherPriorityFinder { 259 for (aura::Window* window : root_window_->children()) {
286 HigherPriorityFinder(int p) : priority(p) {} 260 if (window->GetProperty(kContainerParamsKey)->z_order_priority == priority)
287 bool operator()(aura::Window* window) { 261 return window;
288 return window->GetProperty(kContainerParamsKey)->z_order_priority >
289 priority;
290 } 262 }
291 int priority; 263 return NULL;
292 }; 264 }
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 265
305 aura::Window* ScreenManagerImpl::CreateContainer( 266 aura::Window* ScreenManagerImpl::CreateContainer(
306 const ContainerParams& params) { 267 const ContainerParams& params) {
268 const aura::Window::Windows& children = root_window_->children();
269
270 if (params.default_parent) {
271 CHECK(std::find_if(children.begin(), children.end(), &DefaultContainer) ==
272 children.end());
273 }
274 // mmodal container's priority must be higher than the container's priority.
275 DCHECK(params.modal_container_priority == -1 ||
276 params.modal_container_priority > params.z_order_priority);
277 // Default parent must specify modal_container_priority.
278 DCHECK(!params.default_parent || params.modal_container_priority != -1);
279
307 aura::Window* container = new aura::Window(NULL); 280 aura::Window* container = new aura::Window(NULL);
308 CHECK_GE(params.z_order_priority, 0); 281 CHECK_GE(params.z_order_priority, 0);
309 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); 282 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
310 container->SetName(params.name); 283 container->SetName(params.name);
311 284
312 const aura::Window::Windows& children = root_window_->children();
313
314 #if !defined(NDEBUG) 285 #if !defined(NDEBUG)
Jun Mukai 2014/10/17 17:29:54 It's not related to this, but why it's enclosed by
oshima 2014/10/17 18:20:06 Done.
315 DCHECK(std::find_if(children.begin(), 286 DCHECK(!FindContainerByPriority(params.z_order_priority))
316 children.end(), 287 << "The container with the priority " << params.z_order_priority
317 PriorityMatcher(params.z_order_priority)) 288 << " already exists.";
318 == children.end())
319 << "The container with the priority "
320 << params.z_order_priority << " already exists.";
321 #endif 289 #endif
322
323 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); 290 container->SetProperty(kContainerParamsKey, new ContainerParams(params));
324 291
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); 292 root_window_->AddChild(container);
341 293
342 aura::Window::Windows::const_iterator iter = 294 aura::Window::Windows::const_iterator iter =
343 std::find_if(children.begin(), 295 std::find_if(children.begin(),
344 children.end(), 296 children.end(),
345 HigherPriorityFinder(params.z_order_priority)); 297 HigherPriorityFinder(params.z_order_priority));
346 if (iter != children.end()) 298 if (iter != children.end())
347 root_window_->StackChildBelow(container, *iter); 299 root_window_->StackChildBelow(container, *iter);
348 300
349 container->Show(); 301 container->Show();
350 return container; 302 return container;
351 } 303 }
352 304
305 aura::Window* ScreenManagerImpl::GetContext() {
306 return root_window_;
307 }
308
353 void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) { 309 void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) {
354 last_requested_rotation_ = rotation; 310 last_requested_rotation_ = rotation;
355 if (rotation_locked_ || rotation == 311 if (rotation_locked_ || rotation ==
356 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()) { 312 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()) {
357 return; 313 return;
358 } 314 }
359 315
360 // TODO(flackr): Use display manager to update display rotation: 316 // TODO(flackr): Use display manager to update display rotation:
361 // http://crbug.com/401044. 317 // http://crbug.com/401044.
362 static_cast<aura::TestScreen*>(gfx::Screen::GetNativeScreen())-> 318 static_cast<aura::TestScreen*>(gfx::Screen::GetNativeScreen())->
363 SetDisplayRotation(rotation); 319 SetDisplayRotation(rotation);
364 } 320 }
365 321
366 void ScreenManagerImpl::SetRotationLocked(bool rotation_locked) { 322 void ScreenManagerImpl::SetRotationLocked(bool rotation_locked) {
367 rotation_locked_ = rotation_locked; 323 rotation_locked_ = rotation_locked;
368 if (!rotation_locked_) 324 if (!rotation_locked_)
369 SetRotation(last_requested_rotation_); 325 SetRotation(last_requested_rotation_);
370 } 326 }
371 327
372 } // namespace 328 int ScreenManagerImpl::GetModalContainerPriority(aura::Window* window,
329 aura::Window* parent) {
330 const aura::Window::Windows& children = root_window_->children();
331 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) {
332 // Use top most modal container.
333 auto iter = std::find_if(
334 children.rbegin(), children.rend(), &HasModalContainerPriority);
335 DCHECK(iter != children.rend());
336 return (*iter)->GetProperty(kContainerParamsKey)->modal_container_priority;
337 } else {
338 // use the container closest to the parent which has modal
339 // container priority.
340 auto iter = std::find(children.rbegin(), children.rend(), parent);
341 DCHECK(iter != children.rend());
342 iter = std::find_if(iter, children.rend(), &HasModalContainerPriority);
343 DCHECK(iter != children.rend());
344 return (*iter)->GetProperty(kContainerParamsKey)->modal_container_priority;
345 }
346 }
347
348 aura::Window* ScreenManagerImpl::GetDefaultParent(aura::Window* context,
349 aura::Window* window,
350 const gfx::Rect& bounds) {
351 aura::Window* parent = wm::GetTransientParent(window);
352 if (parent)
353 parent = GetContainer(parent);
354 else
355 parent = GetDefaultContainer();
356
357 if (IsSystemModal(window)) {
358 DCHECK(window->type() == ui::wm::WINDOW_TYPE_NORMAL ||
359 window->type() == ui::wm::WINDOW_TYPE_POPUP);
360 int priority = GetModalContainerPriority(window, parent);
361
362 parent = FindContainerByPriority(priority);
363 if (!parent) {
364 ModalWindowController* controller = new ModalWindowController(priority);
365 parent = controller->modal_container();
366 }
367 }
368 return parent;
369 }
370
371 aura::Window* ScreenManagerImpl::GetDefaultContainer() {
372 const aura::Window::Windows& children = root_window_->children();
373 return *(std::find_if(children.begin(), children.end(), &DefaultContainer));
374 }
373 375
374 ScreenManager::ContainerParams::ContainerParams(const std::string& n, 376 ScreenManager::ContainerParams::ContainerParams(const std::string& n,
375 int priority) 377 int priority)
376 : name(n), 378 : name(n),
377 can_activate_children(false), 379 can_activate_children(false),
378 grab_inputs(false), 380 block_events(false),
379 z_order_priority(priority) { 381 z_order_priority(priority),
382 default_parent(false),
383 modal_container_priority(-1) {
380 } 384 }
381 385
382 // static 386 // static
383 ScreenManager* ScreenManager::Create(aura::Window* root_window) { 387 ScreenManager* ScreenManager::Create(aura::Window* root_window) {
384 (new ScreenManagerImpl(root_window))->Init(); 388 (new ScreenManagerImpl(root_window))->Init();
385 DCHECK(instance); 389 DCHECK(instance);
386 return instance; 390 return instance;
387 } 391 }
388 392
389 // static 393 // static
390 ScreenManager* ScreenManager::Get() { 394 ScreenManager* ScreenManager::Get() {
391 DCHECK(instance); 395 DCHECK(instance);
392 return instance; 396 return instance;
393 } 397 }
394 398
395 // static 399 // static
396 void ScreenManager::Shutdown() { 400 void ScreenManager::Shutdown() {
397 DCHECK(instance); 401 DCHECK(instance);
398 delete instance; 402 delete instance;
399 DCHECK(!instance); 403 DCHECK(!instance);
400 } 404 }
401 405
402 } // namespace athena 406 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698