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

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

Issue 665803003: Revert of 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
« 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/screen_manager_impl.h" 5 #include "athena/screen/public/screen_manager.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"
9 #include "athena/screen/screen_accelerator_handler.h" 8 #include "athena/screen/screen_accelerator_handler.h"
10 #include "athena/util/container_priorities.h" 9 #include "athena/util/container_priorities.h"
11 #include "athena/util/fill_layout_manager.h" 10 #include "athena/util/fill_layout_manager.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/client/screen_position_client.h" 13 #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"
21 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
22 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
23 #include "ui/wm/core/base_focus_rules.h" 24 #include "ui/wm/core/base_focus_rules.h"
24 #include "ui/wm/core/capture_controller.h" 25 #include "ui/wm/core/capture_controller.h"
25 #include "ui/wm/core/focus_controller.h" 26 #include "ui/wm/core/focus_controller.h"
26 #include "ui/wm/core/window_util.h" 27 #include "ui/wm/core/window_util.h"
27 28
28 // This is to avoid creating type definitoin for kAlwaysOnTopKey.
29 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ATHENA_EXPORT, bool);
30
31 namespace athena { 29 namespace athena {
32 namespace { 30 namespace {
33 31
34 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, 32 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams,
35 kContainerParamsKey, 33 kContainerParamsKey,
36 NULL); 34 NULL);
37 35
38 ScreenManagerImpl* instance = NULL; 36 ScreenManager* instance = NULL;
39 37
40 // A functor to find a container that has the higher priority. 38 bool GrabsInput(aura::Window* container) {
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) {
51 ScreenManager::ContainerParams* params = 39 ScreenManager::ContainerParams* params =
52 container->GetProperty(kContainerParamsKey); 40 container->GetProperty(kContainerParamsKey);
53 return params && params->block_events; 41 return params && params->grab_inputs;
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;
70 } 42 }
71 43
72 // Returns the container which contains |window|. 44 // Returns the container which contains |window|.
73 aura::Window* GetContainer(aura::Window* window) { 45 aura::Window* GetContainer(aura::Window* window) {
74 aura::Window* container = window; 46 aura::Window* container = window;
75 while (container && !container->GetProperty(kContainerParamsKey)) 47 while (container && !container->GetProperty(kContainerParamsKey))
76 container = container->parent(); 48 container = container->parent();
77 return container; 49 return container;
78 } 50 }
79 51
80 class AthenaFocusRules : public wm::BaseFocusRules { 52 class AthenaFocusRules : public wm::BaseFocusRules {
81 public: 53 public:
82 AthenaFocusRules() {} 54 AthenaFocusRules() {}
83 virtual ~AthenaFocusRules() {} 55 virtual ~AthenaFocusRules() {}
84 56
85 // wm::BaseFocusRules: 57 // wm::BaseFocusRules:
86 virtual bool SupportsChildActivation(aura::Window* window) const override { 58 virtual bool SupportsChildActivation(aura::Window* window) const override {
87 ScreenManager::ContainerParams* params = 59 ScreenManager::ContainerParams* params =
88 window->GetProperty(kContainerParamsKey); 60 window->GetProperty(kContainerParamsKey);
89 return params && params->can_activate_children; 61 return params && params->can_activate_children;
90 } 62 }
91 virtual bool CanActivateWindow(aura::Window* window) const override { 63 virtual bool CanActivateWindow(aura::Window* window) const override {
92 if (!window) 64 // Check if containers of higher z-order than |window| have 'grab_inputs'
93 return true;
94
95 // Check if containers of higher z-order than |window| have 'block_events'
96 // fields. 65 // fields.
97 if (window->GetRootWindow()) { 66 if (window) {
98 const aura::Window::Windows& containers = 67 const aura::Window::Windows& containers =
99 window->GetRootWindow()->children(); 68 window->GetRootWindow()->children();
100 aura::Window::Windows::const_iterator iter = 69 aura::Window::Windows::const_iterator iter =
101 std::find(containers.begin(), containers.end(), GetContainer(window)); 70 std::find(containers.begin(), containers.end(), GetContainer(window));
102 DCHECK(iter != containers.end()); 71 DCHECK(iter != containers.end());
103 for (++iter; iter != containers.end(); ++iter) { 72 for (++iter; iter != containers.end(); ++iter) {
104 if (BlockEvents(*iter)) 73 if (GrabsInput(*iter))
105 return false; 74 return false;
106 } 75 }
107 } 76 }
108 return BaseFocusRules::CanActivateWindow(window); 77 return BaseFocusRules::CanActivateWindow(window);
109 } 78 }
110 79
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
118 private: 80 private:
119 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); 81 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules);
120 }; 82 };
121 83
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
122 class AthenaScreenPositionClient : public aura::client::ScreenPositionClient { 107 class AthenaScreenPositionClient : public aura::client::ScreenPositionClient {
123 public: 108 public:
124 AthenaScreenPositionClient() { 109 AthenaScreenPositionClient() {
125 } 110 }
126 virtual ~AthenaScreenPositionClient() { 111 virtual ~AthenaScreenPositionClient() {
127 } 112 }
128 113
129 private: 114 private:
130 // aura::client::ScreenPositionClient: 115 // aura::client::ScreenPositionClient:
131 virtual void ConvertPointToScreen(const aura::Window* window, 116 virtual void ConvertPointToScreen(const aura::Window* window,
(...skipping 16 matching lines...) Expand all
148 133
149 virtual void SetBounds(aura::Window* window, 134 virtual void SetBounds(aura::Window* window,
150 const gfx::Rect& bounds, 135 const gfx::Rect& bounds,
151 const gfx::Display& display) override { 136 const gfx::Display& display) override {
152 window->SetBounds(bounds); 137 window->SetBounds(bounds);
153 } 138 }
154 139
155 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); 140 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient);
156 }; 141 };
157 142
158 class AthenaWindowTargeter : public aura::WindowTargeter { 143 class AthenaEventTargeter : public aura::WindowTargeter,
144 public aura::WindowObserver {
159 public: 145 public:
160 explicit AthenaWindowTargeter(aura::Window* root_window) 146 explicit AthenaEventTargeter(aura::Window* container)
161 : root_window_(root_window) {} 147 : container_(container) {
148 container_->AddObserver(this);
149 }
162 150
163 virtual ~AthenaWindowTargeter() {} 151 virtual ~AthenaEventTargeter() {
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 }
164 160
165 private: 161 private:
166 // aura::WindowTargeter: 162 // aura::WindowTargeter:
167 virtual bool SubtreeCanAcceptEvent( 163 virtual bool SubtreeCanAcceptEvent(
168 ui::EventTarget* target, 164 ui::EventTarget* target,
169 const ui::LocatedEvent& event) const override { 165 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
176 aura::Window* window = static_cast<aura::Window*>(target); 166 aura::Window* window = static_cast<aura::Window*>(target);
177 for (;; --r_iter) { 167 const aura::Window::Windows& containers =
178 if ((*r_iter)->Contains(window)) 168 container_->GetRootWindow()->children();
179 return aura::WindowTargeter::SubtreeCanAcceptEvent(target, event); 169 aura::Window::Windows::const_iterator iter =
180 if (r_iter == containers.rbegin()) 170 std::find(containers.begin(), containers.end(), container_);
181 break; 171 DCHECK(iter != containers.end());
172 for (; iter != containers.end(); ++iter) {
173 if ((*iter)->Contains(window))
174 return true;
182 } 175 }
183 return false; 176 return false;
184 } 177 }
185 178
186 virtual ui::EventTarget* FindTargetForLocatedEvent( 179 // aura::WindowObserver:
187 ui::EventTarget* root, 180 virtual void OnWindowDestroying(aura::Window* window) override {
188 ui::LocatedEvent* event) override { 181 aura::Window* root_window = container_->GetRootWindow();
189 ui::EventTarget* target = 182 DCHECK_EQ(window, container_);
190 aura::WindowTargeter::FindTargetForLocatedEvent(root, event); 183 DCHECK_EQ(
191 if (target) 184 this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter());
192 return target; 185
193 // If the root target is blocking the event, return the container even if 186 container_->RemoveObserver(this);
194 // there is no target found so that windows behind it will not be searched. 187 container_ = NULL;
195 const ScreenManager::ContainerParams* params = 188
196 static_cast<aura::Window*>(root)->GetProperty(kContainerParamsKey); 189 // This will remove myself.
197 return (params && params->block_events) ? root : NULL; 190 root_window->SetEventTargeter(previous_root_event_targeter_.Pass());
198 } 191 }
199 192
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
200 // Not owned. 215 // Not owned.
201 aura::Window* root_window_; 216 aura::Window* root_window_;
202 217
203 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTargeter); 218 scoped_ptr<aura::client::FocusClient> focus_client_;
219 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
220 scoped_ptr<AcceleratorHandler> accelerator_handler_;
221 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_;
222 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_;
223
224 gfx::Display::Rotation last_requested_rotation_;
225 bool rotation_locked_;
226
227 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl);
204 }; 228 };
205 229
206 } // namespace
207
208 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) 230 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
209 : root_window_(root_window), 231 : root_window_(root_window),
210 last_requested_rotation_(gfx::Display::ROTATE_0), 232 last_requested_rotation_(gfx::Display::ROTATE_0),
211 rotation_locked_(false) { 233 rotation_locked_(false) {
212 DCHECK(root_window_); 234 DCHECK(root_window_);
213 DCHECK(!instance); 235 DCHECK(!instance);
214 instance = this; 236 instance = this;
215 } 237 }
216 238
217 ScreenManagerImpl::~ScreenManagerImpl() { 239 ScreenManagerImpl::~ScreenManagerImpl() {
(...skipping 19 matching lines...) Expand all
237 new wm::FocusController(new AthenaFocusRules()); 259 new wm::FocusController(new AthenaFocusRules());
238 260
239 aura::client::SetFocusClient(root_window_, focus_controller); 261 aura::client::SetFocusClient(root_window_, focus_controller);
240 root_window_->AddPreTargetHandler(focus_controller); 262 root_window_->AddPreTargetHandler(focus_controller);
241 aura::client::SetActivationClient(root_window_, focus_controller); 263 aura::client::SetActivationClient(root_window_, focus_controller);
242 focus_client_.reset(focus_controller); 264 focus_client_.reset(focus_controller);
243 265
244 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); 266 root_window_->SetLayoutManager(new FillLayoutManager(root_window_));
245 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); 267 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_));
246 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); 268 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_));
269 }
247 270
248 aura::client::SetWindowTreeClient(root_window_, this); 271 aura::Window* ScreenManagerImpl::CreateDefaultContainer(
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());
249 276
250 screen_position_client_.reset(new AthenaScreenPositionClient()); 277 screen_position_client_.reset(new AthenaScreenPositionClient());
251 aura::client::SetScreenPositionClient(root_window_, 278 aura::client::SetScreenPositionClient(root_window_,
252 screen_position_client_.get()); 279 screen_position_client_.get());
253 root_window_->SetEventTargeter( 280
254 make_scoped_ptr(new AthenaWindowTargeter(root_window_))); 281 return container;
255 } 282 }
256 283
257 aura::Window* ScreenManagerImpl::FindContainerByPriority(int priority) { 284 // A functor to find a container that has the higher priority.
258 for (aura::Window* window : root_window_->children()) { 285 struct HigherPriorityFinder {
259 if (window->GetProperty(kContainerParamsKey)->z_order_priority == priority) 286 HigherPriorityFinder(int p) : priority(p) {}
260 return window; 287 bool operator()(aura::Window* window) {
288 return window->GetProperty(kContainerParamsKey)->z_order_priority >
289 priority;
261 } 290 }
262 return NULL; 291 int priority;
263 } 292 };
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
264 304
265 aura::Window* ScreenManagerImpl::CreateContainer( 305 aura::Window* ScreenManagerImpl::CreateContainer(
266 const ContainerParams& params) { 306 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
279 aura::Window* container = new aura::Window(NULL); 307 aura::Window* container = new aura::Window(NULL);
280 CHECK_GE(params.z_order_priority, 0); 308 CHECK_GE(params.z_order_priority, 0);
281 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); 309 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
282 container->SetName(params.name); 310 container->SetName(params.name);
283 311
284 DCHECK(!FindContainerByPriority(params.z_order_priority)) 312 const aura::Window::Windows& children = root_window_->children();
285 << "The container with the priority " << params.z_order_priority 313
286 << " already exists."; 314 #if !defined(NDEBUG)
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
287 322
288 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); 323 container->SetProperty(kContainerParamsKey, new ContainerParams(params));
289 324
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
290 root_window_->AddChild(container); 340 root_window_->AddChild(container);
291 341
292 aura::Window::Windows::const_iterator iter = 342 aura::Window::Windows::const_iterator iter =
293 std::find_if(children.begin(), 343 std::find_if(children.begin(),
294 children.end(), 344 children.end(),
295 HigherPriorityFinder(params.z_order_priority)); 345 HigherPriorityFinder(params.z_order_priority));
296 if (iter != children.end()) 346 if (iter != children.end())
297 root_window_->StackChildBelow(container, *iter); 347 root_window_->StackChildBelow(container, *iter);
298 348
299 container->Show(); 349 container->Show();
300 return container; 350 return container;
301 } 351 }
302 352
303 aura::Window* ScreenManagerImpl::GetContext() {
304 return root_window_;
305 }
306
307 void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) { 353 void ScreenManagerImpl::SetRotation(gfx::Display::Rotation rotation) {
308 last_requested_rotation_ = rotation; 354 last_requested_rotation_ = rotation;
309 if (rotation_locked_ || rotation == 355 if (rotation_locked_ || rotation ==
310 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()) { 356 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation()) {
311 return; 357 return;
312 } 358 }
313 359
314 // TODO(flackr): Use display manager to update display rotation: 360 // TODO(flackr): Use display manager to update display rotation:
315 // http://crbug.com/401044. 361 // http://crbug.com/401044.
316 static_cast<aura::TestScreen*>(gfx::Screen::GetNativeScreen())-> 362 static_cast<aura::TestScreen*>(gfx::Screen::GetNativeScreen())->
317 SetDisplayRotation(rotation); 363 SetDisplayRotation(rotation);
318 } 364 }
319 365
320 void ScreenManagerImpl::SetRotationLocked(bool rotation_locked) { 366 void ScreenManagerImpl::SetRotationLocked(bool rotation_locked) {
321 rotation_locked_ = rotation_locked; 367 rotation_locked_ = rotation_locked;
322 if (!rotation_locked_) 368 if (!rotation_locked_)
323 SetRotation(last_requested_rotation_); 369 SetRotation(last_requested_rotation_);
324 } 370 }
325 371
326 int ScreenManagerImpl::GetModalContainerPriority(aura::Window* window, 372 } // namespace
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 block_events(false), 378 grab_inputs(false),
379 z_order_priority(priority), 379 z_order_priority(priority) {
380 default_parent(false),
381 modal_container_priority(-1) {
382 } 380 }
383 381
384 // static 382 // static
385 ScreenManager* ScreenManager::Create(aura::Window* root_window) { 383 ScreenManager* ScreenManager::Create(aura::Window* root_window) {
386 (new ScreenManagerImpl(root_window))->Init(); 384 (new ScreenManagerImpl(root_window))->Init();
387 DCHECK(instance); 385 DCHECK(instance);
388 return instance; 386 return instance;
389 } 387 }
390 388
391 // static 389 // static
392 ScreenManager* ScreenManager::Get() { 390 ScreenManager* ScreenManager::Get() {
393 DCHECK(instance); 391 DCHECK(instance);
394 return instance; 392 return instance;
395 } 393 }
396 394
397 // static 395 // static
398 void ScreenManager::Shutdown() { 396 void ScreenManager::Shutdown() {
399 DCHECK(instance); 397 DCHECK(instance);
400 delete instance; 398 delete instance;
401 DCHECK(!instance); 399 DCHECK(!instance);
402 } 400 }
403 401
404 } // namespace athena 402 } // 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