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

Side by Side Diff: ash/mus/top_level_window_factory.cc

Issue 2642003002: Removes ash::mus::RootWindowController (Closed)
Patch Set: feedback Created 3 years, 11 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 | « ash/mus/top_level_window_factory.h ('k') | ash/mus/top_level_window_factory_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
(Empty)
1 // Copyright 2017 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/mus/top_level_window_factory.h"
6
7 #include "ash/common/wm/container_finder.h"
8 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h"
11 #include "ash/mus/disconnected_app_handler.h"
12 #include "ash/mus/non_client_frame_controller.h"
13 #include "ash/mus/property_util.h"
14 #include "ash/mus/window_manager.h"
15 #include "ash/public/cpp/shell_window_ids.h"
16 #include "ash/root_window_controller.h"
17 #include "ash/root_window_settings.h"
18 #include "mojo/public/cpp/bindings/type_converter.h"
19 #include "services/ui/public/cpp/property_type_converters.h"
20 #include "services/ui/public/interfaces/window_manager.mojom.h"
21 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
22 #include "ui/aura/mus/property_converter.h"
23 #include "ui/aura/mus/property_utils.h"
24 #include "ui/aura/window.h"
25 #include "ui/display/display.h"
26
27 namespace ash {
28 namespace mus {
29 namespace {
30
31 // Returns true if a fullscreen window was requested.
32 bool IsFullscreen(aura::PropertyConverter* property_converter,
33 const std::vector<uint8_t>& transport_data) {
34 using ui::mojom::WindowManager;
35 aura::PropertyConverter::PrimitiveType show_state = 0;
36 return property_converter->GetPropertyValueFromTransportValue(
37 WindowManager::kShowState_Property, transport_data, &show_state) &&
38 (static_cast<ui::WindowShowState>(show_state) ==
39 ui::SHOW_STATE_FULLSCREEN);
40 }
41
42 // Returns the RootWindowController where new top levels are created.
43 // |properties| is the properties supplied during window creation.
44 RootWindowController* GetRootWindowControllerForNewTopLevelWindow(
45 std::map<std::string, std::vector<uint8_t>>* properties) {
46 // If a specific display was requested, use it.
47 const int64_t display_id = GetInitialDisplayId(*properties);
48 if (display_id != display::kInvalidDisplayId) {
49 for (RootWindowController* root_window_controller :
50 RootWindowController::root_window_controllers()) {
51 if (GetRootWindowSettings(root_window_controller->GetRootWindow())
52 ->display_id == display_id) {
53 return root_window_controller;
54 }
55 }
56 }
57 return RootWindowController::ForWindow(
58 WmShell::Get()->GetRootWindowForNewWindows()->aura_window());
59 }
60
61 // Returns the bounds for the new window.
62 gfx::Rect CalculateDefaultBounds(
63 WindowManager* window_manager,
64 RootWindowController* root_window_controller,
65 aura::Window* container_window,
66 const std::map<std::string, std::vector<uint8_t>>* properties) {
67 gfx::Rect requested_bounds;
68 if (GetInitialBounds(*properties, &requested_bounds))
69 return requested_bounds;
70
71 const gfx::Size root_size =
72 root_window_controller->GetRootWindow()->bounds().size();
73 auto show_state_iter =
74 properties->find(ui::mojom::WindowManager::kShowState_Property);
75 if (show_state_iter != properties->end()) {
76 if (IsFullscreen(window_manager->property_converter(),
77 show_state_iter->second)) {
78 gfx::Rect bounds(root_size);
79 if (!container_window) {
80 const display::Display display =
81 root_window_controller->GetWindow()->GetDisplayNearestWindow();
82 bounds.Offset(display.bounds().OffsetFromOrigin());
83 }
84 return bounds;
85 }
86 }
87
88 gfx::Size window_size;
89 if (GetWindowPreferredSize(*properties, &window_size) &&
90 !window_size.IsEmpty()) {
91 // TODO(sky): likely want to constrain more than root size.
92 window_size.SetToMin(root_size);
msw 2017/01/19 01:20:33 nit: also do SetToMax(gfx::Size()) to also ensure
sky 2017/01/19 15:50:45 gfx::Size forces width/height to be >= 0.
93 } else {
94 static constexpr int kRootSizeDelta = 240;
95 window_size.SetSize(root_size.width() - kRootSizeDelta,
96 root_size.height() - kRootSizeDelta);
97 }
98 // TODO(sky): this should use code in chrome/browser/ui/window_sizer.
99 static constexpr int kOriginOffset = 40;
100 return gfx::Rect(gfx::Point(kOriginOffset, kOriginOffset), window_size);
101 }
102
103 // Does the real work of CreateAndParentTopLevelWindow() once the appropriate
104 // RootWindowController was found.
105 aura::Window* CreateAndParentTopLevelWindowInRoot(
106 WindowManager* window_manager,
107 RootWindowController* root_window_controller,
108 ui::mojom::WindowType window_type,
109 std::map<std::string, std::vector<uint8_t>>* properties) {
110 // TODO(sky): constrain and validate properties.
111
112 int32_t container_id = kShellWindowId_Invalid;
113 aura::Window* context = nullptr;
114 aura::Window* container_window = nullptr;
115 if (GetInitialContainerId(*properties, &container_id)) {
116 container_window = root_window_controller->GetWindow()
117 ->GetChildByShellWindowId(container_id)
118 ->aura_window();
119 } else {
120 context = root_window_controller->GetRootWindow();
121 }
122
123 gfx::Rect bounds = CalculateDefaultBounds(
124 window_manager, root_window_controller, container_window, properties);
125
126 const bool provide_non_client_frame =
127 window_type == ui::mojom::WindowType::WINDOW ||
128 window_type == ui::mojom::WindowType::PANEL;
129 if (provide_non_client_frame) {
130 // See NonClientFrameController for details on lifetime.
131 NonClientFrameController* non_client_frame_controller =
132 new NonClientFrameController(container_window, context, bounds,
133 window_type, properties, window_manager);
134 return non_client_frame_controller->window();
135 }
136
137 aura::Window* window = new aura::Window(nullptr);
138 aura::SetWindowType(window, window_type);
139 // Apply properties before Init(), that way they are sent to the server at
140 // the time the window is created.
141 aura::PropertyConverter* property_converter =
142 window_manager->property_converter();
143 for (auto& property_pair : *properties) {
144 property_converter->SetPropertyFromTransportValue(
145 window, property_pair.first, &property_pair.second);
146 }
147 window->Init(ui::LAYER_TEXTURED);
148 window->SetBounds(bounds);
149
150 if (container_window) {
151 container_window->AddChild(window);
152 } else {
153 WmWindow* root = root_window_controller->GetWindow();
154 gfx::Point origin =
155 root->ConvertPointToTarget(root->GetRootWindow(), gfx::Point());
156 origin += root_window_controller->GetWindow()
157 ->GetDisplayNearestWindow()
158 .bounds()
159 .OffsetFromOrigin();
160 gfx::Rect bounds_in_screen(origin, bounds.size());
161 ash::wm::GetDefaultParent(WmWindow::Get(context), WmWindow::Get(window),
162 bounds_in_screen)
163 ->aura_window()
164 ->AddChild(window);
165 }
166 return window;
167 }
168
169 } // namespace
170
171 aura::Window* CreateAndParentTopLevelWindow(
172 WindowManager* window_manager,
173 ui::mojom::WindowType window_type,
174 std::map<std::string, std::vector<uint8_t>>* properties) {
175 RootWindowController* root_window_controller =
176 GetRootWindowControllerForNewTopLevelWindow(properties);
177 aura::Window* window = CreateAndParentTopLevelWindowInRoot(
178 window_manager, root_window_controller, window_type, properties);
179 DisconnectedAppHandler::Create(window);
180 if (properties->count(
181 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property)) {
182 wm::WindowState* window_state = WmWindow::Get(window)->GetWindowState();
183 window_state->set_ignored_by_shelf(mojo::ConvertTo<bool>(
184 (*properties)
185 [ui::mojom::WindowManager::kWindowIgnoredByShelf_Property]));
186 // No need to persist this value.
187 properties->erase(ui::mojom::WindowManager::kWindowIgnoredByShelf_Property);
188 }
189 return window;
190 }
191
192 } // namespace mus
193 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/top_level_window_factory.h ('k') | ash/mus/top_level_window_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698