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

Side by Side Diff: ash/wm/common/container_finder.cc

Issue 1954523002: Refactors StackingController::GetDefaultParent to ash/wm/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge to trunk Created 4 years, 7 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/wm/common/container_finder.h"
6
7 #include "ash/wm/common/always_on_top_controller.h"
8 #include "ash/wm/common/root_window_finder.h"
9 #include "ash/wm/common/window_state.h"
10 #include "ash/wm/common/wm_globals.h"
11 #include "ash/wm/common/wm_root_window_controller.h"
12 #include "ash/wm/common/wm_shell_window_ids.h"
13 #include "ash/wm/common/wm_window.h"
14
15 namespace ash {
16 namespace wm {
17 namespace {
18
19 WmWindow* FindContainerRoot(WmGlobals* globals, const gfx::Rect& bounds) {
20 if (bounds == gfx::Rect())
James Cook 2016/05/05 02:11:39 nit: #include "ui/gfx/geometry/rect.h"
sky 2016/05/05 15:33:17 Done.
21 return globals->GetRootWindowForNewWindows();
22 return GetRootWindowMatching(bounds);
23 }
24
25 bool HasTransientParentWindow(const WmWindow* window) {
26 return window->GetTransientParent() &&
27 window->GetTransientParent()->GetType() != ui::wm::WINDOW_TYPE_UNKNOWN;
28 }
29
30 WmWindow* GetSystemModalContainer(WmWindow* root, WmWindow* window) {
31 DCHECK(window->IsSystemModal());
32
33 // If screen lock is not active and user session is active,
34 // all modal windows are placed into the normal modal container.
35 // In case of missing transient parent (it could happen for alerts from
36 // background pages) assume that the window belongs to user session.
37 if (!window->GetGlobals()->IsUserSessionBlocked() ||
38 !window->GetTransientParent()) {
39 return root->GetChildByShellWindowId(kShellWindowId_SystemModalContainer);
40 }
41
42 // Otherwise those that originate from LockScreen container and above are
43 // placed in the screen lock modal container.
44 int window_container_id =
45 window->GetTransientParent()->GetParent()->GetShellWindowId();
46 if (window_container_id < kShellWindowId_LockScreenContainer)
47 return root->GetChildByShellWindowId(kShellWindowId_SystemModalContainer);
48 return root->GetChildByShellWindowId(kShellWindowId_LockSystemModalContainer);
49 }
50
51 WmWindow* GetContainerFromAlwaysOnTopController(WmWindow* root,
52 WmWindow* window) {
53 return root->GetRootWindowController()
54 ->GetAlwaysOnTopController()
55 ->GetContainer(window);
56 }
57
58 } // namespace
59
60 WmWindow* GetContainerForWindow(WmWindow* window) {
61 WmWindow* container = window->GetParent();
62 while (container && container->GetType() != ui::wm::WINDOW_TYPE_UNKNOWN)
63 container = container->GetParent();
64 return container;
65 }
66
67 WmWindow* GetDefaultParent(WmWindow* context,
68 WmWindow* window,
69 const gfx::Rect& bounds) {
70 WmWindow* target_root = nullptr;
71 WmWindow* transient_parent = window->GetTransientParent();
72 if (transient_parent) {
73 // Transient window should use the same root as its transient parent.
74 target_root = transient_parent->GetRootWindow();
75 } else {
76 target_root = FindContainerRoot(context->GetGlobals(), bounds);
77 }
78
79 switch (window->GetType()) {
80 case ui::wm::WINDOW_TYPE_NORMAL:
81 case ui::wm::WINDOW_TYPE_POPUP:
82 if (window->IsSystemModal())
83 return GetSystemModalContainer(target_root, window);
84 if (HasTransientParentWindow(window))
85 return GetContainerForWindow(window->GetTransientParent());
86 return GetContainerFromAlwaysOnTopController(target_root, window);
87 case ui::wm::WINDOW_TYPE_CONTROL:
88 return target_root->GetChildByShellWindowId(
89 kShellWindowId_UnparentedControlContainer);
90 case ui::wm::WINDOW_TYPE_PANEL:
91 if (window->GetWindowState()->panel_attached())
92 return target_root->GetChildByShellWindowId(
93 kShellWindowId_PanelContainer);
94 return GetContainerFromAlwaysOnTopController(target_root, window);
95 case ui::wm::WINDOW_TYPE_MENU:
96 return target_root->GetChildByShellWindowId(kShellWindowId_MenuContainer);
97 case ui::wm::WINDOW_TYPE_TOOLTIP:
98 return target_root->GetChildByShellWindowId(
99 kShellWindowId_DragImageAndTooltipContainer);
100 default:
101 NOTREACHED() << "Window " << window->GetShellWindowId()
102 << " has unhandled type " << window->GetType();
103 break;
104 }
105 return nullptr;
106 }
107
108 } // namespace wm
109 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698