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

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

Issue 2072343002: Changes how window manager obtains WindowTree from mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include Created 4 years, 6 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/window_manager.h ('k') | ash/mus/window_manager_application.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ash/mus/window_manager.h" 5 #include "ash/mus/window_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
12 #include "ash/common/wm/container_finder.h" 12 #include "ash/mus/bridge/wm_lookup_mus.h"
13 #include "ash/mus/bridge/wm_shell_mus.h"
13 #include "ash/mus/bridge/wm_window_mus.h" 14 #include "ash/mus/bridge/wm_window_mus.h"
14 #include "ash/mus/non_client_frame_controller.h" 15 #include "ash/mus/non_client_frame_controller.h"
15 #include "ash/mus/property_util.h" 16 #include "ash/mus/property_util.h"
16 #include "ash/mus/root_window_controller.h" 17 #include "ash/mus/root_window_controller.h"
18 #include "ash/mus/root_windows_observer.h"
19 #include "ash/mus/shadow_controller.h"
20 #include "ash/mus/window_manager_application.h"
17 #include "ash/public/interfaces/container.mojom.h" 21 #include "ash/public/interfaces/container.mojom.h"
22 #include "components/mus/common/event_matcher_util.h"
18 #include "components/mus/common/types.h" 23 #include "components/mus/common/types.h"
19 #include "components/mus/public/cpp/property_type_converters.h" 24 #include "components/mus/public/cpp/property_type_converters.h"
20 #include "components/mus/public/cpp/window.h" 25 #include "components/mus/public/cpp/window.h"
21 #include "components/mus/public/cpp/window_property.h" 26 #include "components/mus/public/cpp/window_property.h"
22 #include "components/mus/public/cpp/window_tree_client.h" 27 #include "components/mus/public/cpp/window_tree_client.h"
23 #include "components/mus/public/interfaces/mus_constants.mojom.h" 28 #include "components/mus/public/interfaces/mus_constants.mojom.h"
24 #include "components/mus/public/interfaces/window_manager.mojom.h" 29 #include "components/mus/public/interfaces/window_manager.mojom.h"
25 #include "ui/events/mojo/event.mojom.h" 30 #include "ui/events/mojo/event.mojom.h"
31 #include "ui/views/mus/screen_mus.h"
26 32
27 namespace ash { 33 namespace ash {
28 namespace mus { 34 namespace mus {
29 35
30 WindowManager::WindowManager() 36 const uint32_t kWindowSwitchAccelerator = 1;
31 : root_controller_(nullptr),
32 window_manager_client_(nullptr),
33 binding_(this) {}
34 37
35 WindowManager::~WindowManager() {} 38 void AssertTrue(bool success) {
39 DCHECK(success);
40 }
36 41
37 void WindowManager::Initialize(RootWindowController* root_controller, 42 WindowManager::WindowManager(WindowManagerApplication* window_manager_app,
38 mash::session::mojom::Session* session) { 43 shell::Connector* connector)
39 DCHECK(root_controller); 44 : window_manager_app_(window_manager_app), connector_(connector) {}
40 DCHECK(!root_controller_);
41 root_controller_ = root_controller;
42 45
43 // Observe all the containers so that windows can be added to/removed from the 46 WindowManager::~WindowManager() {
44 // |disconnected_app_handler_|. 47 // NOTE: |window_tree_client_| may already be null.
45 WmWindowMus* root = WmWindowMus::Get(root_controller_->root()); 48 delete window_tree_client_;
46 for (int shell_window_id = kShellWindowId_Min; 49 }
47 shell_window_id < kShellWindowId_Max; ++shell_window_id) {
48 // kShellWindowId_VirtualKeyboardContainer is lazily created.
49 // TODO(sky): http://crbug.com/616909 .
50 // kShellWindowId_PhantomWindow is not a container, but a window.
51 if (shell_window_id == kShellWindowId_VirtualKeyboardContainer ||
52 shell_window_id == kShellWindowId_PhantomWindow)
53 continue;
54 50
55 // kShellWindowId_MouseCursorContainer is chromeos specific. 51 void WindowManager::Init(::mus::WindowTreeClient* window_tree_client) {
56 #if !defined(OS_CHROMEOS) 52 DCHECK(!window_tree_client_);
57 if (shell_window_id == kShellWindowId_MouseCursorContainer) 53 window_tree_client_ = window_tree_client;
58 continue;
59 #endif
60 54
61 WmWindowMus* container = WmWindowMus::AsWmWindowMus( 55 shadow_controller_.reset(new ShadowController(window_tree_client));
62 root->GetChildByShellWindowId(shell_window_id));
63 Add(container->mus_window());
64 56
65 // Add any pre-existing windows in the container to 57 AddAccelerators();
66 // |disconnected_app_handler_|.
67 for (::mus::Window* child : container->mus_window()->children()) {
68 if (!root_controller_->WindowIsContainer(child))
69 disconnected_app_handler_.Add(child);
70 }
71 }
72 58
73 // The insets are roughly what is needed by CustomFrameView. The expectation 59 // The insets are roughly what is needed by CustomFrameView. The expectation
74 // is at some point we'll write our own NonClientFrameView and get the insets 60 // is at some point we'll write our own NonClientFrameView and get the insets
75 // from it. 61 // from it.
76 ::mus::mojom::FrameDecorationValuesPtr frame_decoration_values = 62 ::mus::mojom::FrameDecorationValuesPtr frame_decoration_values =
77 ::mus::mojom::FrameDecorationValues::New(); 63 ::mus::mojom::FrameDecorationValues::New();
78 const gfx::Insets client_area_insets = 64 const gfx::Insets client_area_insets =
79 NonClientFrameController::GetPreferredClientAreaInsets(); 65 NonClientFrameController::GetPreferredClientAreaInsets();
80 frame_decoration_values->normal_client_area_insets = client_area_insets; 66 frame_decoration_values->normal_client_area_insets = client_area_insets;
81 frame_decoration_values->maximized_client_area_insets = client_area_insets; 67 frame_decoration_values->maximized_client_area_insets = client_area_insets;
82 frame_decoration_values->max_title_bar_button_width = 68 frame_decoration_values->max_title_bar_button_width =
83 NonClientFrameController::GetMaxTitleBarButtonWidth(); 69 NonClientFrameController::GetMaxTitleBarButtonWidth();
84 window_manager_client_->SetFrameDecorationValues( 70 window_manager_client_->SetFrameDecorationValues(
85 std::move(frame_decoration_values)); 71 std::move(frame_decoration_values));
86 72
87 if (session) 73 shell_.reset(new WmShellMus(window_tree_client_));
88 session->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind()); 74 lookup_.reset(new WmLookupMus);
75 }
76
77 void WindowManager::SetScreenLocked(bool is_locked) {
78 // TODO: screen locked state needs to be persisted for newly added displays.
79 for (auto& root_window_controller : root_window_controllers_) {
80 WmWindowMus* non_lock_screen_containers_container =
81 root_window_controller->GetWindowByShellWindowId(
82 kShellWindowId_NonLockScreenContainersContainer);
83 non_lock_screen_containers_container->mus_window()->SetVisible(!is_locked);
84 }
89 } 85 }
90 86
91 ::mus::Window* WindowManager::NewTopLevelWindow( 87 ::mus::Window* WindowManager::NewTopLevelWindow(
92 std::map<std::string, std::vector<uint8_t>>* properties) { 88 std::map<std::string, std::vector<uint8_t>>* properties) {
93 DCHECK(root_controller_); 89 // TODO(sky): need to maintain active as well as allowing specifying display.
94 ::mus::Window* root = root_controller_->root(); 90 RootWindowController* root_window_controller =
95 DCHECK(root); 91 root_window_controllers_.begin()->get();
92 return root_window_controller->NewTopLevelWindow(properties);
93 }
96 94
97 // TODO(sky): panels need a different frame, http:://crbug.com/614362. 95 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() {
98 const bool provide_non_client_frame = 96 std::set<RootWindowController*> result;
99 GetWindowType(*properties) == ::mus::mojom::WindowType::WINDOW || 97 for (auto& root_window_controller : root_window_controllers_)
100 GetWindowType(*properties) == ::mus::mojom::WindowType::PANEL; 98 result.insert(root_window_controller.get());
101 if (provide_non_client_frame) 99 return result;
102 (*properties)[::mus::mojom::kWaitForUnderlay_Property].clear(); 100 }
103 101
104 // TODO(sky): constrain and validate properties before passing to server. 102 void WindowManager::AddRootWindowsObserver(RootWindowsObserver* observer) {
105 ::mus::Window* window = root->window_tree()->NewWindow(properties); 103 root_windows_observers_.AddObserver(observer);
106 window->SetBounds(CalculateDefaultBounds(window)); 104 }
107 105
108 ::mus::Window* container_window = nullptr; 106 void WindowManager::RemoveRootWindowsObserver(RootWindowsObserver* observer) {
109 mojom::Container container; 107 root_windows_observers_.RemoveObserver(observer);
110 if (GetRequestedContainer(window, &container)) { 108 }
111 container_window = root_controller_->GetWindowForContainer(container);
112 } else {
113 // TODO(sky): window->bounds() isn't quite right.
114 container_window = WmWindowMus::GetMusWindow(
115 wm::GetDefaultParent(WmWindowMus::Get(root_controller_->root()),
116 WmWindowMus::Get(window), window->bounds()));
117 }
118 DCHECK(root_controller_->WindowIsContainer(container_window));
119 109
120 if (provide_non_client_frame) { 110 void WindowManager::AddAccelerators() {
121 NonClientFrameController::Create(root_controller_->GetConnector(), 111 // TODO(sky): this is broke for multi-display case. Need to fix mus to
122 container_window, window, 112 // deal correctly.
123 root_controller_->window_manager_client()); 113 window_manager_client_->AddAccelerator(
124 } else { 114 kWindowSwitchAccelerator,
125 container_window->AddChild(window); 115 ::mus::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB,
116 ui::mojom::kEventFlagControlDown),
117 base::Bind(&AssertTrue));
118 }
119
120 RootWindowController* WindowManager::CreateRootWindowController(
121 ::mus::Window* window,
122 const display::Display& display) {
123 // TODO(sky): there is timing issues with using ScreenMus.
124 if (!screen_) {
125 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr));
126 screen->Init(connector_);
127 screen_ = std::move(screen);
126 } 128 }
127 129
128 root_controller_->IncrementWindowCount(); 130 std::unique_ptr<RootWindowController> root_window_controller_ptr(
131 new RootWindowController(this, window, display));
132 RootWindowController* root_window_controller =
133 root_window_controller_ptr.get();
134 root_window_controllers_.insert(std::move(root_window_controller_ptr));
135 window->AddObserver(this);
129 136
130 return window; 137 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
138 OnRootWindowControllerAdded(root_window_controller));
139 return root_window_controller;
131 } 140 }
132 141
133 gfx::Rect WindowManager::CalculateDefaultBounds(::mus::Window* window) const { 142 void WindowManager::OnWindowDestroying(::mus::Window* window) {
134 if (window->HasSharedProperty( 143 for (auto it = root_window_controllers_.begin();
135 ::mus::mojom::WindowManager::kInitialBounds_Property)) { 144 it != root_window_controllers_.end(); ++it) {
136 return window->GetSharedProperty<gfx::Rect>( 145 if ((*it)->root() == window) {
137 ::mus::mojom::WindowManager::kInitialBounds_Property); 146 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
147 OnWillDestroyRootWindowController((*it).get()));
148 return;
149 }
138 } 150 }
139 151 NOTREACHED();
140 DCHECK(root_controller_);
141 int width, height;
142 const gfx::Size pref = GetWindowPreferredSize(window);
143 const ::mus::Window* root = root_controller_->root();
144 if (pref.IsEmpty()) {
145 width = root->bounds().width() - 240;
146 height = root->bounds().height() - 240;
147 } else {
148 // TODO(sky): likely want to constrain more than root size.
149 const gfx::Size max_size = GetMaximizedWindowBounds().size();
150 width = std::max(0, std::min(max_size.width(), pref.width()));
151 height = std::max(0, std::min(max_size.height(), pref.height()));
152 }
153 return gfx::Rect(40 + (root_controller_->window_count() % 4) * 40,
154 40 + (root_controller_->window_count() % 4) * 40, width,
155 height);
156 } 152 }
157 153
158 gfx::Rect WindowManager::GetMaximizedWindowBounds() const { 154 void WindowManager::OnWindowDestroyed(::mus::Window* window) {
159 DCHECK(root_controller_); 155 window->RemoveObserver(this);
160 return gfx::Rect(root_controller_->root()->bounds().size()); 156 for (auto it = root_window_controllers_.begin();
157 it != root_window_controllers_.end(); ++it) {
158 if ((*it)->root() == window) {
159 root_window_controllers_.erase(it);
160 return;
161 }
162 }
163 NOTREACHED();
161 } 164 }
162 165
163 void WindowManager::OnTreeChanging(const TreeChangeParams& params) { 166 void WindowManager::OnEmbed(::mus::Window* root) {
164 DCHECK(root_controller_); 167 // WindowManager should never see this, instead OnWmNewDisplay() is called.
165 if (params.old_parent == params.receiver && 168 NOTREACHED();
166 root_controller_->WindowIsContainer(params.old_parent)) 169 }
167 disconnected_app_handler_.Remove(params.target);
168 170
169 if (params.new_parent == params.receiver && 171 void WindowManager::OnWindowTreeClientDestroyed(
170 root_controller_->WindowIsContainer(params.new_parent)) 172 ::mus::WindowTreeClient* client) {
171 disconnected_app_handler_.Add(params.target); 173 // Destroying the roots should result in removal from
174 // |root_window_controllers_|.
175 DCHECK(root_window_controllers_.empty());
172 176
173 ::mus::WindowTracker::OnTreeChanging(params); 177 lookup_.reset();
178 shell_.reset();
179 shadow_controller_.reset();
180
181 window_tree_client_ = nullptr;
182 // TODO(sky): this should likely shutdown.
183 }
184
185 void WindowManager::OnEventObserved(const ui::Event& event,
186 ::mus::Window* target) {
187 // Does not use EventObservers.
174 } 188 }
175 189
176 void WindowManager::SetWindowManagerClient(::mus::WindowManagerClient* client) { 190 void WindowManager::SetWindowManagerClient(::mus::WindowManagerClient* client) {
177 window_manager_client_ = client; 191 window_manager_client_ = client;
178 } 192 }
179 193
180 bool WindowManager::OnWmSetBounds(::mus::Window* window, gfx::Rect* bounds) { 194 bool WindowManager::OnWmSetBounds(::mus::Window* window, gfx::Rect* bounds) {
181 // TODO(sky): this indirectly sets bounds, which is against what 195 // TODO(sky): this indirectly sets bounds, which is against what
182 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. 196 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this.
183 WmWindowMus::Get(window)->SetBounds(*bounds); 197 WmWindowMus::Get(window)->SetBounds(*bounds);
(...skipping 19 matching lines...) Expand all
203 return NewTopLevelWindow(properties); 217 return NewTopLevelWindow(properties);
204 } 218 }
205 219
206 void WindowManager::OnWmClientJankinessChanged( 220 void WindowManager::OnWmClientJankinessChanged(
207 const std::set<::mus::Window*>& client_windows, 221 const std::set<::mus::Window*>& client_windows,
208 bool janky) { 222 bool janky) {
209 for (auto window : client_windows) 223 for (auto window : client_windows)
210 SetWindowIsJanky(window, janky); 224 SetWindowIsJanky(window, janky);
211 } 225 }
212 226
213 void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) { 227 void WindowManager::OnWmNewDisplay(::mus::Window* window,
214 root_controller_->OnAccelerator(id, std::move(event)); 228 const display::Display& display) {
229 CreateRootWindowController(window, display);
215 } 230 }
216 231
217 void WindowManager::ScreenlockStateChanged(bool locked) { 232 void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) {
218 WmWindowMus* non_lock_screen_containers_container = 233 switch (id) {
219 root_controller_->GetWindowByShellWindowId( 234 case kWindowSwitchAccelerator:
220 kShellWindowId_NonLockScreenContainersContainer); 235 window_manager_client()->ActivateNextWindow();
221 non_lock_screen_containers_container->mus_window()->SetVisible(!locked); 236 break;
237 default:
238 window_manager_app_->OnAccelerator(id, event);
239 break;
240 }
222 } 241 }
223 242
224 } // namespace mus 243 } // namespace mus
225 } // namespace ash 244 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/window_manager.h ('k') | ash/mus/window_manager_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698