Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/mus/accelerators/accelerator_handler.h" | 12 #include "ash/mus/accelerators/accelerator_handler.h" |
| 13 #include "ash/mus/accelerators/accelerator_ids.h" | 13 #include "ash/mus/accelerators/accelerator_ids.h" |
| 14 #include "ash/mus/bridge/wm_lookup_mus.h" | 14 #include "ash/mus/bridge/wm_lookup_mus.h" |
| 15 #include "ash/mus/bridge/wm_shell_mus.h" | 15 #include "ash/mus/bridge/wm_shell_mus.h" |
| 16 #include "ash/mus/bridge/wm_window_mus.h" | 16 #include "ash/mus/bridge/wm_window_mus.h" |
| 17 #include "ash/mus/move_event_handler.h" | 17 #include "ash/mus/move_event_handler.h" |
| 18 #include "ash/mus/non_client_frame_controller.h" | 18 #include "ash/mus/non_client_frame_controller.h" |
| 19 #include "ash/mus/property_util.h" | 19 #include "ash/mus/property_util.h" |
| 20 #include "ash/mus/root_window_controller.h" | 20 #include "ash/mus/root_window_controller.h" |
| 21 #include "ash/mus/shadow_controller.h" | 21 #include "ash/mus/shadow_controller.h" |
| 22 #include "ash/mus/shell_delegate_mus.h" | 22 #include "ash/mus/shell_delegate_mus.h" |
| 23 #include "ash/mus/window_manager_observer.h" | 23 #include "ash/mus/window_manager_observer.h" |
| 24 #include "ash/public/interfaces/container.mojom.h" | 24 #include "ash/public/interfaces/container.mojom.h" |
| 25 #include "services/shell/public/cpp/connector.h" | |
| 25 #include "services/ui/common/event_matcher_util.h" | 26 #include "services/ui/common/event_matcher_util.h" |
| 26 #include "services/ui/common/types.h" | 27 #include "services/ui/common/types.h" |
| 27 #include "services/ui/public/cpp/property_type_converters.h" | 28 #include "services/ui/public/cpp/property_type_converters.h" |
| 28 #include "services/ui/public/cpp/window.h" | 29 #include "services/ui/public/cpp/window.h" |
| 29 #include "services/ui/public/cpp/window_property.h" | 30 #include "services/ui/public/cpp/window_property.h" |
| 30 #include "services/ui/public/cpp/window_tree_client.h" | 31 #include "services/ui/public/cpp/window_tree_client.h" |
| 31 #include "services/ui/public/interfaces/mus_constants.mojom.h" | 32 #include "services/ui/public/interfaces/mus_constants.mojom.h" |
| 32 #include "services/ui/public/interfaces/window_manager.mojom.h" | 33 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 33 #include "ui/app_list/presenter/app_list_presenter.h" | 34 #include "ui/app_list/presenter/app_list_presenter.h" |
| 34 #include "ui/base/hit_test.h" | 35 #include "ui/base/hit_test.h" |
| 36 #include "ui/display/screen_base.h" | |
| 35 #include "ui/events/mojo/event.mojom.h" | 37 #include "ui/events/mojo/event.mojom.h" |
| 36 #include "ui/views/mus/pointer_watcher_event_router.h" | 38 #include "ui/views/mus/pointer_watcher_event_router.h" |
| 37 #include "ui/views/mus/screen_mus.h" | 39 #include "ui/views/mus/window_manager_frame_values.h" |
| 38 | 40 |
| 39 namespace ash { | 41 namespace mojo { |
| 40 namespace mus { | |
| 41 | 42 |
| 42 void AssertTrue(bool success) { | 43 template <> |
| 43 DCHECK(success); | 44 struct TypeConverter<views::WindowManagerFrameValues, |
| 44 } | 45 ui::mojom::FrameDecorationValuesPtr> { |
| 46 static views::WindowManagerFrameValues Convert( | |
| 47 const ui::mojom::FrameDecorationValuesPtr& input) { | |
| 48 views::WindowManagerFrameValues result; | |
| 49 result.normal_insets = input->normal_client_area_insets; | |
| 50 result.maximized_insets = input->maximized_client_area_insets; | |
| 51 result.max_title_bar_button_width = input->max_title_bar_button_width; | |
| 52 return result; | |
| 53 } | |
| 54 }; | |
| 55 | |
| 56 } // namespace mojo | |
| 57 | |
| 58 namespace { | |
| 45 | 59 |
| 46 // TODO(jamescook): Port ash::sysui::AppListPresenterMus and eliminate this. | 60 // TODO(jamescook): Port ash::sysui::AppListPresenterMus and eliminate this. |
| 47 class AppListPresenterStub : public app_list::AppListPresenter { | 61 class AppListPresenterStub : public app_list::AppListPresenter { |
| 48 public: | 62 public: |
| 49 AppListPresenterStub() {} | 63 AppListPresenterStub() {} |
| 50 ~AppListPresenterStub() override {} | 64 ~AppListPresenterStub() override {} |
| 51 | 65 |
| 52 // app_list::AppListPresenter: | 66 // app_list::AppListPresenter: |
| 53 void Show(int64_t display_id) override { NOTIMPLEMENTED(); } | 67 void Show(int64_t display_id) override { NOTIMPLEMENTED(); } |
| 54 void Dismiss() override { NOTIMPLEMENTED(); } | 68 void Dismiss() override { NOTIMPLEMENTED(); } |
| 55 void ToggleAppList(int64_t display_id) override { NOTIMPLEMENTED(); } | 69 void ToggleAppList(int64_t display_id) override { NOTIMPLEMENTED(); } |
| 56 bool IsVisible() const override { | 70 bool IsVisible() const override { |
| 57 NOTIMPLEMENTED(); | 71 NOTIMPLEMENTED(); |
| 58 return false; | 72 return false; |
| 59 } | 73 } |
| 60 bool GetTargetVisibility() const override { | 74 bool GetTargetVisibility() const override { |
| 61 NOTIMPLEMENTED(); | 75 NOTIMPLEMENTED(); |
| 62 return false; | 76 return false; |
| 63 } | 77 } |
| 64 | 78 |
| 65 private: | 79 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(AppListPresenterStub); | 80 DISALLOW_COPY_AND_ASSIGN(AppListPresenterStub); |
| 67 }; | 81 }; |
| 68 | 82 |
| 83 } // namespace | |
| 84 | |
| 85 namespace ash { | |
| 86 namespace mus { | |
| 87 | |
| 69 WindowManager::WindowManager(shell::Connector* connector) | 88 WindowManager::WindowManager(shell::Connector* connector) |
| 70 : connector_(connector) {} | 89 : connector_(connector), display_manager_observer_binding_(this) {} |
| 71 | 90 |
| 72 WindowManager::~WindowManager() { | 91 WindowManager::~WindowManager() { |
| 73 // NOTE: |window_tree_client_| may already be null. | 92 // NOTE: |window_tree_client_| may already be null. |
| 74 delete window_tree_client_; | 93 delete window_tree_client_; |
| 75 } | 94 } |
| 76 | 95 |
| 77 void WindowManager::Init(ui::WindowTreeClient* window_tree_client) { | 96 void WindowManager::Init(ui::WindowTreeClient* window_tree_client) { |
| 78 DCHECK(!window_tree_client_); | 97 DCHECK(!window_tree_client_); |
| 79 window_tree_client_ = window_tree_client; | 98 window_tree_client_ = window_tree_client; |
| 80 | 99 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 observers_.AddObserver(observer); | 173 observers_.AddObserver(observer); |
| 155 } | 174 } |
| 156 | 175 |
| 157 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { | 176 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 158 observers_.RemoveObserver(observer); | 177 observers_.RemoveObserver(observer); |
| 159 } | 178 } |
| 160 | 179 |
| 161 RootWindowController* WindowManager::CreateRootWindowController( | 180 RootWindowController* WindowManager::CreateRootWindowController( |
| 162 ui::Window* window, | 181 ui::Window* window, |
| 163 const display::Display& display) { | 182 const display::Display& display) { |
| 164 // TODO(sky): there is timing issues with using ScreenMus. | 183 // TODO(sky): There are timing issues with using ScreenBase. |
| 165 if (!screen_) { | 184 if (!screen_) { |
| 166 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr)); | 185 screen_.reset(new display::ScreenBase()); |
| 167 screen->Init(connector_); | 186 |
| 168 screen_ = std::move(screen); | 187 ui::mojom::DisplayManagerPtr display_manager; |
| 188 connector_->ConnectToInterface("mojo:ui", &display_manager); | |
|
sky
2016/09/01 23:51:17
The windowmanager shouldn't need to connect to dis
| |
| 189 display_manager->AddObserver( | |
| 190 display_manager_observer_binding_.CreateInterfacePtrAndBind()); | |
| 191 | |
| 192 // We need the set of displays before we can continue. Wait for it. | |
| 193 // | |
| 194 // TODO(rockot): Do something better here. This should not have to block | |
| 195 // tasks from running on the calling thread. http://crbug.com/594852. | |
| 196 bool success = | |
| 197 display_manager_observer_binding_.WaitForIncomingMethodCall(); | |
| 198 | |
| 199 // The WaitForIncomingMethodCall() should have supplied the set of Displays, | |
| 200 // unless mus is going down, in which case encountered_error() is true, or | |
| 201 // the call to WaitForIncomingMethodCall() failed. | |
| 202 if (screen_->display_list()->displays().empty()) { | |
| 203 DCHECK(display_manager.encountered_error() || !success); | |
| 204 // In this case we install a default display and assume the process is | |
| 205 // going to exit shortly so that the real value doesn't matter. | |
| 206 screen_->display_list()->AddDisplay( | |
| 207 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)), | |
| 208 display::DisplayList::Type::PRIMARY); | |
| 209 } | |
| 169 } | 210 } |
| 170 | 211 |
| 171 std::unique_ptr<RootWindowController> root_window_controller_ptr( | 212 std::unique_ptr<RootWindowController> root_window_controller_ptr( |
| 172 new RootWindowController(this, window, display)); | 213 new RootWindowController(this, window, display)); |
| 173 RootWindowController* root_window_controller = | 214 RootWindowController* root_window_controller = |
| 174 root_window_controller_ptr.get(); | 215 root_window_controller_ptr.get(); |
| 175 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 216 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 176 window->AddObserver(this); | 217 window->AddObserver(this); |
| 177 | 218 |
| 178 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 219 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. | 285 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. |
| 245 WmWindowMus::Get(window)->SetBounds(*bounds); | 286 WmWindowMus::Get(window)->SetBounds(*bounds); |
| 246 *bounds = window->bounds(); | 287 *bounds = window->bounds(); |
| 247 return true; | 288 return true; |
| 248 } | 289 } |
| 249 | 290 |
| 250 bool WindowManager::OnWmSetProperty( | 291 bool WindowManager::OnWmSetProperty( |
| 251 ui::Window* window, | 292 ui::Window* window, |
| 252 const std::string& name, | 293 const std::string& name, |
| 253 std::unique_ptr<std::vector<uint8_t>>* new_data) { | 294 std::unique_ptr<std::vector<uint8_t>>* new_data) { |
| 254 // TODO(sky): constrain this to set of keys we know about, and allowed | 295 // TODO(sky): constrain this to set of keys we know about, and allowed values. |
| 255 // values. | |
| 256 return name == ui::mojom::WindowManager::kShowState_Property || | 296 return name == ui::mojom::WindowManager::kShowState_Property || |
| 257 name == ui::mojom::WindowManager::kPreferredSize_Property || | 297 name == ui::mojom::WindowManager::kPreferredSize_Property || |
| 258 name == ui::mojom::WindowManager::kResizeBehavior_Property || | 298 name == ui::mojom::WindowManager::kResizeBehavior_Property || |
| 259 name == ui::mojom::WindowManager::kWindowAppIcon_Property || | 299 name == ui::mojom::WindowManager::kWindowAppIcon_Property || |
| 260 name == ui::mojom::WindowManager::kWindowTitle_Property; | 300 name == ui::mojom::WindowManager::kWindowTitle_Property; |
| 261 } | 301 } |
| 262 | 302 |
| 263 ui::Window* WindowManager::OnWmCreateTopLevelWindow( | 303 ui::Window* WindowManager::OnWmCreateTopLevelWindow( |
| 264 std::map<std::string, std::vector<uint8_t>>* properties) { | 304 std::map<std::string, std::vector<uint8_t>>* properties) { |
| 265 return NewTopLevelWindow(properties); | 305 return NewTopLevelWindow(properties); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 346 |
| 307 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, | 347 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, |
| 308 const ui::Event& event) { | 348 const ui::Event& event) { |
| 309 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); | 349 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 310 if (iter == accelerator_handlers_.end()) | 350 if (iter == accelerator_handlers_.end()) |
| 311 return ui::mojom::EventResult::HANDLED; | 351 return ui::mojom::EventResult::HANDLED; |
| 312 | 352 |
| 313 return iter->second->OnAccelerator(id, event); | 353 return iter->second->OnAccelerator(id, event); |
| 314 } | 354 } |
| 315 | 355 |
| 356 void WindowManager::OnDisplays( | |
| 357 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | |
| 358 // This should only be called once from Init() before any observers have been | |
| 359 // added. | |
| 360 DCHECK(screen_->display_list()->displays().empty()); | |
| 361 for (size_t i = 0; i < ws_displays.size(); ++i) { | |
| 362 const bool is_primary = ws_displays[i]->is_primary; | |
| 363 screen_->display_list()->AddDisplay( | |
| 364 ws_displays[i]->display, is_primary | |
| 365 ? display::DisplayList::Type::PRIMARY | |
| 366 : display::DisplayList::Type::NOT_PRIMARY); | |
| 367 if (is_primary) { | |
| 368 // TODO(sky): Make views::WindowManagerFrameValues per display. | |
| 369 views::WindowManagerFrameValues frame_values = | |
| 370 ws_displays[i] | |
| 371 ->frame_decoration_values.To<views::WindowManagerFrameValues>(); | |
| 372 views::WindowManagerFrameValues::SetInstance(frame_values); | |
| 373 } | |
| 374 } | |
| 375 DCHECK(!screen_->display_list()->displays().empty()); | |
| 376 } | |
| 377 | |
| 378 void WindowManager::OnDisplaysChanged( | |
| 379 mojo::Array<ui::mojom::WsDisplayPtr> ws_displays) { | |
| 380 for (size_t i = 0; i < ws_displays.size(); ++i) { | |
| 381 const bool is_primary = ws_displays[i]->is_primary; | |
| 382 screen_->ProcessDisplayChanged(ws_displays[i]->display, is_primary); | |
| 383 if (is_primary) { | |
| 384 views::WindowManagerFrameValues frame_values = | |
| 385 ws_displays[i] | |
| 386 ->frame_decoration_values.To<views::WindowManagerFrameValues>(); | |
| 387 views::WindowManagerFrameValues::SetInstance(frame_values); | |
| 388 } | |
| 389 } | |
| 390 } | |
| 391 | |
| 392 void WindowManager::OnDisplayRemoved(int64_t id) { | |
| 393 // Shutdown the root window controller before removing the display. | |
| 394 for (auto& root_window_controller : root_window_controllers_) { | |
| 395 if (root_window_controller->display().id() == id) { | |
| 396 root_window_controller->Shutdown(); | |
| 397 break; | |
| 398 } | |
| 399 } | |
| 400 screen_->display_list()->RemoveDisplay(id); | |
| 401 } | |
| 402 | |
| 316 } // namespace mus | 403 } // namespace mus |
| 317 } // namespace ash | 404 } // namespace ash |
| OLD | NEW |