| 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" |
| 13 #include "ash/mus/accelerators/accelerator_ids.h" |
| 12 #include "ash/mus/bridge/wm_lookup_mus.h" | 14 #include "ash/mus/bridge/wm_lookup_mus.h" |
| 13 #include "ash/mus/bridge/wm_shell_mus.h" | 15 #include "ash/mus/bridge/wm_shell_mus.h" |
| 14 #include "ash/mus/bridge/wm_window_mus.h" | 16 #include "ash/mus/bridge/wm_window_mus.h" |
| 15 #include "ash/mus/frame/move_event_handler.h" | 17 #include "ash/mus/frame/move_event_handler.h" |
| 16 #include "ash/mus/non_client_frame_controller.h" | 18 #include "ash/mus/non_client_frame_controller.h" |
| 17 #include "ash/mus/property_util.h" | 19 #include "ash/mus/property_util.h" |
| 18 #include "ash/mus/root_window_controller.h" | 20 #include "ash/mus/root_window_controller.h" |
| 19 #include "ash/mus/shadow_controller.h" | 21 #include "ash/mus/shadow_controller.h" |
| 20 #include "ash/mus/shell_delegate_mus.h" | 22 #include "ash/mus/shell_delegate_mus.h" |
| 21 #include "ash/mus/window_manager_observer.h" | 23 #include "ash/mus/window_manager_observer.h" |
| 22 #include "ash/public/interfaces/container.mojom.h" | 24 #include "ash/public/interfaces/container.mojom.h" |
| 23 #include "services/ui/common/event_matcher_util.h" | 25 #include "services/ui/common/event_matcher_util.h" |
| 24 #include "services/ui/common/types.h" | 26 #include "services/ui/common/types.h" |
| 25 #include "services/ui/public/cpp/property_type_converters.h" | 27 #include "services/ui/public/cpp/property_type_converters.h" |
| 26 #include "services/ui/public/cpp/window.h" | 28 #include "services/ui/public/cpp/window.h" |
| 27 #include "services/ui/public/cpp/window_property.h" | 29 #include "services/ui/public/cpp/window_property.h" |
| 28 #include "services/ui/public/cpp/window_tree_client.h" | 30 #include "services/ui/public/cpp/window_tree_client.h" |
| 29 #include "services/ui/public/interfaces/mus_constants.mojom.h" | 31 #include "services/ui/public/interfaces/mus_constants.mojom.h" |
| 30 #include "services/ui/public/interfaces/window_manager.mojom.h" | 32 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 31 #include "ui/app_list/presenter/app_list_presenter.h" | 33 #include "ui/app_list/presenter/app_list_presenter.h" |
| 32 #include "ui/base/hit_test.h" | 34 #include "ui/base/hit_test.h" |
| 33 #include "ui/events/mojo/event.mojom.h" | 35 #include "ui/events/mojo/event.mojom.h" |
| 34 #include "ui/views/mus/screen_mus.h" | 36 #include "ui/views/mus/screen_mus.h" |
| 35 | 37 |
| 36 namespace ash { | 38 namespace ash { |
| 37 namespace mus { | 39 namespace mus { |
| 38 | 40 |
| 39 const uint32_t kWindowSwitchAccelerator = 1; | |
| 40 | |
| 41 void AssertTrue(bool success) { | 41 void AssertTrue(bool success) { |
| 42 DCHECK(success); | 42 DCHECK(success); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // TODO(jamescook): Port ash::sysui::AppListPresenterMus and eliminate this. | 45 // TODO(jamescook): Port ash::sysui::AppListPresenterMus and eliminate this. |
| 46 class AppListPresenterStub : public app_list::AppListPresenter { | 46 class AppListPresenterStub : public app_list::AppListPresenter { |
| 47 public: | 47 public: |
| 48 AppListPresenterStub() {} | 48 AppListPresenterStub() {} |
| 49 ~AppListPresenterStub() override {} | 49 ~AppListPresenterStub() override {} |
| 50 | 50 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 72 // NOTE: |window_tree_client_| may already be null. | 72 // NOTE: |window_tree_client_| may already be null. |
| 73 delete window_tree_client_; | 73 delete window_tree_client_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void WindowManager::Init(::ui::WindowTreeClient* window_tree_client) { | 76 void WindowManager::Init(::ui::WindowTreeClient* window_tree_client) { |
| 77 DCHECK(!window_tree_client_); | 77 DCHECK(!window_tree_client_); |
| 78 window_tree_client_ = window_tree_client; | 78 window_tree_client_ = window_tree_client; |
| 79 | 79 |
| 80 shadow_controller_.reset(new ShadowController(window_tree_client)); | 80 shadow_controller_.reset(new ShadowController(window_tree_client)); |
| 81 | 81 |
| 82 AddAccelerators(); | |
| 83 | |
| 84 // The insets are roughly what is needed by CustomFrameView. The expectation | 82 // The insets are roughly what is needed by CustomFrameView. The expectation |
| 85 // is at some point we'll write our own NonClientFrameView and get the insets | 83 // is at some point we'll write our own NonClientFrameView and get the insets |
| 86 // from it. | 84 // from it. |
| 87 ::ui::mojom::FrameDecorationValuesPtr frame_decoration_values = | 85 ::ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 88 ::ui::mojom::FrameDecorationValues::New(); | 86 ::ui::mojom::FrameDecorationValues::New(); |
| 89 const gfx::Insets client_area_insets = | 87 const gfx::Insets client_area_insets = |
| 90 NonClientFrameController::GetPreferredClientAreaInsets(); | 88 NonClientFrameController::GetPreferredClientAreaInsets(); |
| 91 frame_decoration_values->normal_client_area_insets = client_area_insets; | 89 frame_decoration_values->normal_client_area_insets = client_area_insets; |
| 92 frame_decoration_values->maximized_client_area_insets = client_area_insets; | 90 frame_decoration_values->maximized_client_area_insets = client_area_insets; |
| 93 frame_decoration_values->max_title_bar_button_width = | 91 frame_decoration_values->max_title_bar_button_width = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 120 return root_window_controller->NewTopLevelWindow(properties); | 118 return root_window_controller->NewTopLevelWindow(properties); |
| 121 } | 119 } |
| 122 | 120 |
| 123 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { | 121 std::set<RootWindowController*> WindowManager::GetRootWindowControllers() { |
| 124 std::set<RootWindowController*> result; | 122 std::set<RootWindowController*> result; |
| 125 for (auto& root_window_controller : root_window_controllers_) | 123 for (auto& root_window_controller : root_window_controllers_) |
| 126 result.insert(root_window_controller.get()); | 124 result.insert(root_window_controller.get()); |
| 127 return result; | 125 return result; |
| 128 } | 126 } |
| 129 | 127 |
| 128 bool WindowManager::GetNextAcceleratorNamespaceId(uint16_t* id) { |
| 129 if (accelerator_handlers_.size() == std::numeric_limits<uint16_t>::max()) |
| 130 return false; |
| 131 while (accelerator_handlers_.count(next_accelerator_namespace_id_) > 0) |
| 132 ++next_accelerator_namespace_id_; |
| 133 *id = next_accelerator_namespace_id_; |
| 134 ++next_accelerator_namespace_id_; |
| 135 return true; |
| 136 } |
| 137 |
| 138 void WindowManager::AddAcceleratorHandler(uint16_t id_namespace, |
| 139 AcceleratorHandler* handler) { |
| 140 DCHECK_EQ(0u, accelerator_handlers_.count(id_namespace)); |
| 141 accelerator_handlers_[id_namespace] = handler; |
| 142 } |
| 143 |
| 144 void WindowManager::RemoveAcceleratorHandler(uint16_t id_namespace) { |
| 145 accelerator_handlers_.erase(id_namespace); |
| 146 } |
| 147 |
| 130 void WindowManager::AddObserver(WindowManagerObserver* observer) { | 148 void WindowManager::AddObserver(WindowManagerObserver* observer) { |
| 131 observers_.AddObserver(observer); | 149 observers_.AddObserver(observer); |
| 132 } | 150 } |
| 133 | 151 |
| 134 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { | 152 void WindowManager::RemoveObserver(WindowManagerObserver* observer) { |
| 135 observers_.RemoveObserver(observer); | 153 observers_.RemoveObserver(observer); |
| 136 } | 154 } |
| 137 | 155 |
| 138 void WindowManager::AddAccelerators() { | |
| 139 // TODO(sky): this is broke for multi-display case. Need to fix mus to | |
| 140 // deal correctly. | |
| 141 window_manager_client_->AddAccelerator( | |
| 142 kWindowSwitchAccelerator, | |
| 143 ::ui::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB, | |
| 144 ui::mojom::kEventFlagControlDown), | |
| 145 base::Bind(&AssertTrue)); | |
| 146 } | |
| 147 | |
| 148 RootWindowController* WindowManager::CreateRootWindowController( | 156 RootWindowController* WindowManager::CreateRootWindowController( |
| 149 ::ui::Window* window, | 157 ::ui::Window* window, |
| 150 const display::Display& display) { | 158 const display::Display& display) { |
| 151 // TODO(sky): there is timing issues with using ScreenMus. | 159 // TODO(sky): there is timing issues with using ScreenMus. |
| 152 if (!screen_) { | 160 if (!screen_) { |
| 153 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr)); | 161 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr)); |
| 154 screen->Init(connector_); | 162 screen->Init(connector_); |
| 155 screen_ = std::move(screen); | 163 screen_ = std::move(screen); |
| 156 } | 164 } |
| 157 | 165 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 289 |
| 282 void WindowManager::OnWmCancelMoveLoop(::ui::Window* window) { | 290 void WindowManager::OnWmCancelMoveLoop(::ui::Window* window) { |
| 283 WmWindowMus* child_window = WmWindowMus::Get(window); | 291 WmWindowMus* child_window = WmWindowMus::Get(window); |
| 284 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); | 292 MoveEventHandler* handler = MoveEventHandler::GetForWindow(child_window); |
| 285 if (handler) | 293 if (handler) |
| 286 handler->RevertDrag(); | 294 handler->RevertDrag(); |
| 287 } | 295 } |
| 288 | 296 |
| 289 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, | 297 ui::mojom::EventResult WindowManager::OnAccelerator(uint32_t id, |
| 290 const ui::Event& event) { | 298 const ui::Event& event) { |
| 291 switch (id) { | 299 auto iter = accelerator_handlers_.find(GetAcceleratorNamespaceId(id)); |
| 292 case kWindowSwitchAccelerator: | 300 if (iter == accelerator_handlers_.end()) |
| 293 window_manager_client()->ActivateNextWindow(); | 301 return ui::mojom::EventResult::HANDLED; |
| 294 break; | |
| 295 default: | |
| 296 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | |
| 297 OnAccelerator(id, event)); | |
| 298 break; | |
| 299 } | |
| 300 | 302 |
| 301 return ui::mojom::EventResult::HANDLED; | 303 return iter->second->OnAccelerator(id, event); |
| 302 } | 304 } |
| 303 | 305 |
| 304 } // namespace mus | 306 } // namespace mus |
| 305 } // namespace ash | 307 } // namespace ash |
| OLD | NEW |