Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/screen_mus.h" | |
|
msw
2017/01/18 23:31:27
nit: needed?
sky
2017/01/19 01:02:19
Indeed it isn't. Removed.
| |
| 15 #include "ash/mus/window_manager.h" | |
| 16 #include "ash/public/cpp/shell_window_ids.h" | |
| 17 #include "ash/root_window_controller.h" | |
| 18 #include "ash/root_window_settings.h" | |
| 19 #include "mojo/public/cpp/bindings/type_converter.h" | |
| 20 #include "services/ui/public/cpp/property_type_converters.h" | |
| 21 #include "services/ui/public/interfaces/window_manager.mojom.h" | |
| 22 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | |
| 23 #include "ui/aura/mus/property_converter.h" | |
| 24 #include "ui/aura/mus/property_utils.h" | |
| 25 #include "ui/aura/window.h" | |
| 26 #include "ui/display/display.h" | |
| 27 | |
| 28 namespace ash { | |
| 29 namespace mus { | |
| 30 namespace { | |
| 31 | |
| 32 // Returns true if a fullscreen window was requested. | |
| 33 bool IsFullscreen(aura::PropertyConverter* property_converter, | |
| 34 const std::vector<uint8_t>& transport_data) { | |
| 35 using ui::mojom::WindowManager; | |
| 36 aura::PropertyConverter::PrimitiveType show_state = 0; | |
| 37 return property_converter->GetPropertyValueFromTransportValue( | |
| 38 WindowManager::kShowState_Property, transport_data, &show_state) && | |
| 39 (static_cast<ui::WindowShowState>(show_state) == | |
| 40 ui::SHOW_STATE_FULLSCREEN); | |
| 41 } | |
| 42 | |
| 43 // Returns the RootWindowController where new top levels are created. | |
| 44 // |properties| is the properties supplied during window creation. | |
| 45 RootWindowController* GetRootWindowControllerForNewTopLevelWindow( | |
| 46 std::map<std::string, std::vector<uint8_t>>* properties) { | |
| 47 // If a specific display was requested, use it. | |
| 48 const int64_t display_id = GetInitialDisplayId(*properties); | |
|
msw
2017/01/18 23:31:27
nit: skip the loop for display::kInvalidDisplayId?
sky
2017/01/19 01:02:20
Done.
| |
| 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 return RootWindowController::ForWindow( | |
| 57 WmShell::Get()->GetRootWindowForNewWindows()->aura_window()); | |
| 58 } | |
| 59 | |
| 60 // Returns the bounds for the new window. | |
| 61 gfx::Rect CalculateDefaultBounds( | |
| 62 WindowManager* window_manager, | |
| 63 RootWindowController* root_window_controller, | |
| 64 aura::Window* container_window, | |
| 65 const std::map<std::string, std::vector<uint8_t>>* properties) { | |
| 66 gfx::Rect requested_bounds; | |
| 67 if (GetInitialBounds(*properties, &requested_bounds)) | |
| 68 return requested_bounds; | |
| 69 | |
| 70 const gfx::Size root_size = | |
| 71 root_window_controller->GetRootWindow()->bounds().size(); | |
| 72 auto show_state_iter = | |
| 73 properties->find(ui::mojom::WindowManager::kShowState_Property); | |
| 74 if (show_state_iter != properties->end()) { | |
| 75 if (IsFullscreen(window_manager->property_converter(), | |
| 76 show_state_iter->second)) { | |
| 77 gfx::Rect bounds(0, 0, root_size.width(), root_size.height()); | |
|
msw
2017/01/18 23:31:27
nit: use Rect(const Size& size) ctor
sky
2017/01/19 01:02:19
Done.
| |
| 78 if (!container_window) { | |
| 79 const display::Display display = | |
| 80 root_window_controller->GetWindow()->GetDisplayNearestWindow(); | |
|
msw
2017/01/18 23:31:27
ditto q: GetWindow/GetRootWindow, optionally cache
sky
2017/01/19 01:02:20
See earlier comment.
| |
| 81 bounds.Offset(display.bounds().origin().x(), | |
|
msw
2017/01/18 23:31:27
nit: bounds.Offset(display.bounds()OffsetFromOrigi
sky
2017/01/19 01:02:19
Done.
| |
| 82 display.bounds().origin().y()); | |
| 83 } | |
| 84 return bounds; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 int width, height; | |
|
msw
2017/01/18 23:31:27
nit: explicit 0 init
sky
2017/01/19 01:02:19
Done.
| |
| 89 gfx::Size pref; | |
| 90 if (GetWindowPreferredSize(*properties, &pref) && !pref.IsEmpty()) { | |
| 91 // TODO(sky): likely want to constrain more than root size. | |
| 92 const gfx::Size max_size = root_size; | |
| 93 width = std::max(0, std::min(max_size.width(), pref.width())); | |
|
msw
2017/01/18 23:31:27
optional nit: re-use |pref| with Size::SetToMax an
sky
2017/01/19 01:02:19
I think you mean SetToMin.
| |
| 94 height = std::max(0, std::min(max_size.height(), pref.height())); | |
| 95 } else { | |
| 96 width = root_size.width() - 240; | |
|
msw
2017/01/18 23:31:27
optional nit: use a const for this magic number, d
sky
2017/01/19 01:02:19
Done.
| |
| 97 height = root_size.height() - 240; | |
| 98 } | |
| 99 // TODO(sky): decide if we really want to support window_count. If so, set as | |
| 100 // a property on the root. | |
| 101 const int window_count = 0; | |
|
msw
2017/01/18 23:31:27
q: I realize this has a TODO, but did you mean to
sky
2017/01/19 01:02:19
I changed to static, and I removed a bunch of this
| |
| 102 return gfx::Rect(40 + (window_count % 4) * 40, 40 + (window_count % 4) * 40, | |
|
msw
2017/01/18 23:31:27
optional nit: cache |40 + (window_count % 4) * 40|
sky
2017/01/19 01:02:20
No longer applicable.
| |
| 103 width, height); | |
| 104 } | |
| 105 | |
| 106 // Does the real work of CreateAndParentTopLevelWindow() once the appropriate | |
| 107 // RootWindowController was found. | |
| 108 aura::Window* CreateAndParentTopLevelWindowInRoot( | |
| 109 WindowManager* window_manager, | |
| 110 RootWindowController* root_window_controller, | |
| 111 ui::mojom::WindowType window_type, | |
| 112 std::map<std::string, std::vector<uint8_t>>* properties) { | |
| 113 // TODO(sky): constrain and validate properties. | |
| 114 | |
| 115 int32_t container_id = kShellWindowId_Invalid; | |
| 116 aura::Window* context = nullptr; | |
| 117 aura::Window* container_window = nullptr; | |
| 118 if (GetInitialContainerId(*properties, &container_id)) { | |
| 119 container_window = root_window_controller->GetWindow() | |
|
msw
2017/01/18 23:31:27
aside: GetWindow==GetRootWindow is bugging me, try
sky
2017/01/19 01:02:19
Sorry. Some operations are easier on WmWindow at t
| |
| 120 ->GetChildByShellWindowId(container_id) | |
| 121 ->aura_window(); | |
| 122 } else { | |
| 123 context = root_window_controller->GetRootWindow(); | |
|
msw
2017/01/18 23:31:27
aside: it might be nice to avoid context and pick
sky
2017/01/19 01:02:19
We should probably try to make ash::wm::GetDefault
| |
| 124 } | |
| 125 | |
| 126 gfx::Rect bounds = CalculateDefaultBounds( | |
| 127 window_manager, root_window_controller, container_window, properties); | |
| 128 | |
| 129 const bool provide_non_client_frame = | |
|
msw
2017/01/18 23:31:27
optional nit: inline
sky
2017/01/19 01:02:20
I went with this as it better documents the condit
| |
| 130 window_type == ui::mojom::WindowType::WINDOW || | |
| 131 window_type == ui::mojom::WindowType::PANEL; | |
| 132 if (provide_non_client_frame) { | |
| 133 // See NonClientFrameController for details on lifetime. | |
| 134 NonClientFrameController* non_client_frame_controller = | |
| 135 new NonClientFrameController(container_window, context, bounds, | |
| 136 window_type, properties, window_manager); | |
| 137 return non_client_frame_controller->window(); | |
| 138 } | |
| 139 | |
| 140 aura::Window* window = new aura::Window(nullptr); | |
| 141 aura::SetWindowType(window, window_type); | |
| 142 // Apply properties before Init(), that way they are sent to the server at | |
| 143 // the time the window is created. | |
| 144 aura::PropertyConverter* property_converter = | |
| 145 window_manager->property_converter(); | |
| 146 for (auto& property_pair : *properties) { | |
| 147 property_converter->SetPropertyFromTransportValue( | |
| 148 window, property_pair.first, &property_pair.second); | |
| 149 } | |
| 150 window->Init(ui::LAYER_TEXTURED); | |
| 151 window->SetBounds(bounds); | |
| 152 | |
| 153 if (container_window) { | |
| 154 container_window->AddChild(window); | |
| 155 } else { | |
| 156 WmWindow* root = root_window_controller->GetWindow(); | |
| 157 gfx::Point origin = | |
| 158 root->ConvertPointToTarget(root->GetRootWindow(), gfx::Point()); | |
| 159 origin += root_window_controller->GetWindow() | |
| 160 ->GetDisplayNearestWindow() | |
| 161 .bounds() | |
| 162 .OffsetFromOrigin(); | |
| 163 gfx::Rect bounds_in_screen(origin, bounds.size()); | |
| 164 ash::wm::GetDefaultParent(WmWindow::Get(context), WmWindow::Get(window), | |
| 165 bounds_in_screen) | |
| 166 ->aura_window() | |
| 167 ->AddChild(window); | |
| 168 } | |
| 169 return window; | |
| 170 } | |
| 171 | |
| 172 } // namespace | |
| 173 | |
| 174 aura::Window* CreateAndParentTopLevelWindow( | |
| 175 WindowManager* window_manager, | |
| 176 ui::mojom::WindowType window_type, | |
| 177 std::map<std::string, std::vector<uint8_t>>* properties) { | |
| 178 RootWindowController* root_window_controller = | |
| 179 GetRootWindowControllerForNewTopLevelWindow(properties); | |
| 180 aura::Window* window = CreateAndParentTopLevelWindowInRoot( | |
| 181 window_manager, root_window_controller, window_type, properties); | |
| 182 DisconnectedAppHandler::Create(window); | |
| 183 if (properties->count( | |
| 184 ui::mojom::WindowManager::kWindowIgnoredByShelf_Property)) { | |
|
msw
2017/01/18 23:31:27
aside: itd be nice if this were an aura window pro
sky
2017/01/19 01:02:19
Agreed. I filed 671729 a while back on it.
| |
| 185 wm::WindowState* window_state = WmWindow::Get(window)->GetWindowState(); | |
| 186 window_state->set_ignored_by_shelf(mojo::ConvertTo<bool>( | |
| 187 (*properties) | |
| 188 [ui::mojom::WindowManager::kWindowIgnoredByShelf_Property])); | |
| 189 // No need to persist this value. | |
| 190 properties->erase(ui::mojom::WindowManager::kWindowIgnoredByShelf_Property); | |
| 191 } | |
| 192 return window; | |
| 193 } | |
| 194 | |
| 195 } // namespace mus | |
| 196 } // namespace ash | |
| OLD | NEW |