| 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/bridge/wm_lookup_mus.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_shell_mus.h" |
| 14 #include "ash/mus/bridge/wm_window_mus.h" | 14 #include "ash/mus/bridge/wm_window_mus.h" |
| 15 #include "ash/mus/non_client_frame_controller.h" | 15 #include "ash/mus/non_client_frame_controller.h" |
| 16 #include "ash/mus/property_util.h" | 16 #include "ash/mus/property_util.h" |
| 17 #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" | 18 #include "ash/mus/shadow_controller.h" |
| 20 #include "ash/mus/window_manager_application.h" | 19 #include "ash/mus/window_manager_observer.h" |
| 21 #include "ash/public/interfaces/container.mojom.h" | 20 #include "ash/public/interfaces/container.mojom.h" |
| 22 #include "components/mus/common/event_matcher_util.h" | 21 #include "components/mus/common/event_matcher_util.h" |
| 23 #include "components/mus/common/types.h" | 22 #include "components/mus/common/types.h" |
| 24 #include "components/mus/public/cpp/property_type_converters.h" | 23 #include "components/mus/public/cpp/property_type_converters.h" |
| 25 #include "components/mus/public/cpp/window.h" | 24 #include "components/mus/public/cpp/window.h" |
| 26 #include "components/mus/public/cpp/window_property.h" | 25 #include "components/mus/public/cpp/window_property.h" |
| 27 #include "components/mus/public/cpp/window_tree_client.h" | 26 #include "components/mus/public/cpp/window_tree_client.h" |
| 28 #include "components/mus/public/interfaces/mus_constants.mojom.h" | 27 #include "components/mus/public/interfaces/mus_constants.mojom.h" |
| 29 #include "components/mus/public/interfaces/window_manager.mojom.h" | 28 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 30 #include "ui/events/mojo/event.mojom.h" | 29 #include "ui/events/mojo/event.mojom.h" |
| 31 #include "ui/views/mus/screen_mus.h" | 30 #include "ui/views/mus/screen_mus.h" |
| 32 | 31 |
| 33 namespace ash { | 32 namespace ash { |
| 34 namespace mus { | 33 namespace mus { |
| 35 | 34 |
| 36 const uint32_t kWindowSwitchAccelerator = 1; | 35 const uint32_t kWindowSwitchAccelerator = 1; |
| 37 | 36 |
| 38 void AssertTrue(bool success) { | 37 void AssertTrue(bool success) { |
| 39 DCHECK(success); | 38 DCHECK(success); |
| 40 } | 39 } |
| 41 | 40 |
| 42 WindowManager::WindowManager(WindowManagerApplication* window_manager_app, | 41 WindowManager::WindowManager(shell::Connector* connector) |
| 43 shell::Connector* connector) | 42 : connector_(connector) {} |
| 44 : window_manager_app_(window_manager_app), connector_(connector) {} | |
| 45 | 43 |
| 46 WindowManager::~WindowManager() { | 44 WindowManager::~WindowManager() { |
| 47 // NOTE: |window_tree_client_| may already be null. | 45 // NOTE: |window_tree_client_| may already be null. |
| 48 delete window_tree_client_; | 46 delete window_tree_client_; |
| 49 } | 47 } |
| 50 | 48 |
| 51 void WindowManager::Init(::mus::WindowTreeClient* window_tree_client) { | 49 void WindowManager::Init(::mus::WindowTreeClient* window_tree_client) { |
| 52 DCHECK(!window_tree_client_); | 50 DCHECK(!window_tree_client_); |
| 53 window_tree_client_ = window_tree_client; | 51 window_tree_client_ = window_tree_client; |
| 54 | 52 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return root_window_controller->NewTopLevelWindow(properties); | 90 return root_window_controller->NewTopLevelWindow(properties); |
| 93 } | 91 } |
| 94 | 92 |
| 95 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { | 93 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { |
| 96 std::set<RootWindowController*> result; | 94 std::set<RootWindowController*> result; |
| 97 for (auto& root_window_controller : root_window_controllers_) | 95 for (auto& root_window_controller : root_window_controllers_) |
| 98 result.insert(root_window_controller.get()); | 96 result.insert(root_window_controller.get()); |
| 99 return result; | 97 return result; |
| 100 } | 98 } |
| 101 | 99 |
| 102 void WindowManager::AddRootWindowsObserver(RootWindowsObserver* observer) { | 100 void WindowManager::AddObserver(WindowManagerObserver* observer) { |
| 103 root_windows_observers_.AddObserver(observer); | 101 observers_.AddObserver(observer); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void WindowManager::RemoveRootWindowsObserver(RootWindowsObserver* observer) { | 104 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 107 root_windows_observers_.RemoveObserver(observer); | 105 observers_.RemoveObserver(observer); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void WindowManager::AddAccelerators() { | 108 void WindowManager::AddAccelerators() { |
| 111 // TODO(sky): this is broke for multi-display case. Need to fix mus to | 109 // TODO(sky): this is broke for multi-display case. Need to fix mus to |
| 112 // deal correctly. | 110 // deal correctly. |
| 113 window_manager_client_->AddAccelerator( | 111 window_manager_client_->AddAccelerator( |
| 114 kWindowSwitchAccelerator, | 112 kWindowSwitchAccelerator, |
| 115 ::mus::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB, | 113 ::mus::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB, |
| 116 ui::mojom::kEventFlagControlDown), | 114 ui::mojom::kEventFlagControlDown), |
| 117 base::Bind(&AssertTrue)); | 115 base::Bind(&AssertTrue)); |
| 118 } | 116 } |
| 119 | 117 |
| 120 RootWindowController* WindowManager::CreateRootWindowController( | 118 RootWindowController* WindowManager::CreateRootWindowController( |
| 121 ::mus::Window* window, | 119 ::mus::Window* window, |
| 122 const display::Display& display) { | 120 const display::Display& display) { |
| 123 // TODO(sky): there is timing issues with using ScreenMus. | 121 // TODO(sky): there is timing issues with using ScreenMus. |
| 124 if (!screen_) { | 122 if (!screen_) { |
| 125 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr)); | 123 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr)); |
| 126 screen->Init(connector_); | 124 screen->Init(connector_); |
| 127 screen_ = std::move(screen); | 125 screen_ = std::move(screen); |
| 128 } | 126 } |
| 129 | 127 |
| 130 std::unique_ptr<RootWindowController> root_window_controller_ptr( | 128 std::unique_ptr<RootWindowController> root_window_controller_ptr( |
| 131 new RootWindowController(this, window, display)); | 129 new RootWindowController(this, window, display)); |
| 132 RootWindowController* root_window_controller = | 130 RootWindowController* root_window_controller = |
| 133 root_window_controller_ptr.get(); | 131 root_window_controller_ptr.get(); |
| 134 root_window_controllers_.insert(std::move(root_window_controller_ptr)); | 132 root_window_controllers_.insert(std::move(root_window_controller_ptr)); |
| 135 window->AddObserver(this); | 133 window->AddObserver(this); |
| 136 | 134 |
| 137 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_, | 135 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 138 OnRootWindowControllerAdded(root_window_controller)); | 136 OnRootWindowControllerAdded(root_window_controller)); |
| 139 return root_window_controller; | 137 return root_window_controller; |
| 140 } | 138 } |
| 141 | 139 |
| 142 void WindowManager::OnWindowDestroying(::mus::Window* window) { | 140 void WindowManager::OnWindowDestroying(::mus::Window* window) { |
| 143 for (auto it = root_window_controllers_.begin(); | 141 for (auto it = root_window_controllers_.begin(); |
| 144 it != root_window_controllers_.end(); ++it) { | 142 it != root_window_controllers_.end(); ++it) { |
| 145 if ((*it)->root() == window) { | 143 if ((*it)->root() == window) { |
| 146 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_, | 144 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 147 OnWillDestroyRootWindowController((*it).get())); | 145 OnWillDestroyRootWindowController((*it).get())); |
| 148 return; | 146 return; |
| 149 } | 147 } |
| 150 } | 148 } |
| 151 NOTREACHED(); | 149 NOTREACHED(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 void WindowManager::OnWindowDestroyed(::mus::Window* window) { | 152 void WindowManager::OnWindowDestroyed(::mus::Window* window) { |
| 155 window->RemoveObserver(this); | 153 window->RemoveObserver(this); |
| 156 for (auto it = root_window_controllers_.begin(); | 154 for (auto it = root_window_controllers_.begin(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 171 void WindowManager::OnWindowTreeClientDestroyed( | 169 void WindowManager::OnWindowTreeClientDestroyed( |
| 172 ::mus::WindowTreeClient* client) { | 170 ::mus::WindowTreeClient* client) { |
| 173 // Destroying the roots should result in removal from | 171 // Destroying the roots should result in removal from |
| 174 // |root_window_controllers_|. | 172 // |root_window_controllers_|. |
| 175 DCHECK(root_window_controllers_.empty()); | 173 DCHECK(root_window_controllers_.empty()); |
| 176 | 174 |
| 177 lookup_.reset(); | 175 lookup_.reset(); |
| 178 shell_.reset(); | 176 shell_.reset(); |
| 179 shadow_controller_.reset(); | 177 shadow_controller_.reset(); |
| 180 | 178 |
| 179 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 180 OnWindowTreeClientDestroyed()); |
| 181 |
| 181 window_tree_client_ = nullptr; | 182 window_tree_client_ = nullptr; |
| 182 // TODO(sky): this should likely shutdown. | 183 window_manager_client_ = nullptr; |
| 183 } | 184 } |
| 184 | 185 |
| 185 void WindowManager::OnEventObserved(const ui::Event& event, | 186 void WindowManager::OnEventObserved(const ui::Event& event, |
| 186 ::mus::Window* target) { | 187 ::mus::Window* target) { |
| 187 // Does not use EventObservers. | 188 // Does not use EventObservers. |
| 188 } | 189 } |
| 189 | 190 |
| 190 void WindowManager::SetWindowManagerClient(::mus::WindowManagerClient* client) { | 191 void WindowManager::SetWindowManagerClient(::mus::WindowManagerClient* client) { |
| 191 window_manager_client_ = client; | 192 window_manager_client_ = client; |
| 192 } | 193 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 const display::Display& display) { | 229 const display::Display& display) { |
| 229 CreateRootWindowController(window, display); | 230 CreateRootWindowController(window, display); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) { | 233 void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) { |
| 233 switch (id) { | 234 switch (id) { |
| 234 case kWindowSwitchAccelerator: | 235 case kWindowSwitchAccelerator: |
| 235 window_manager_client()->ActivateNextWindow(); | 236 window_manager_client()->ActivateNextWindow(); |
| 236 break; | 237 break; |
| 237 default: | 238 default: |
| 238 window_manager_app_->OnAccelerator(id, event); | 239 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 240 OnAccelerator(id, event)); |
| 239 break; | 241 break; |
| 240 } | 242 } |
| 241 } | 243 } |
| 242 | 244 |
| 243 } // namespace mus | 245 } // namespace mus |
| 244 } // namespace ash | 246 } // namespace ash |
| OLD | NEW |