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

Side by Side Diff: mash/wm/window_manager_application.cc

Issue 1656123002: Moves accelerator registration to WindowManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix mandoline Created 4 years, 10 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 | « mash/wm/window_manager_application.h ('k') | no next file » | 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 "mash/wm/window_manager_application.h" 5 #include "mash/wm/window_manager_application.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "components/mus/public/cpp/event_matcher.h" 10 #include "components/mus/public/cpp/event_matcher.h"
11 #include "components/mus/public/cpp/window.h" 11 #include "components/mus/public/cpp/window.h"
12 #include "components/mus/public/interfaces/window_manager_factory.mojom.h" 12 #include "components/mus/public/interfaces/window_manager_factory.mojom.h"
13 #include "mash/wm/accelerator_registrar_impl.h" 13 #include "mash/wm/accelerator_registrar_impl.h"
14 #include "mash/wm/root_window_controller.h" 14 #include "mash/wm/root_window_controller.h"
15 #include "mash/wm/root_windows_observer.h"
15 #include "mash/wm/user_window_controller_impl.h" 16 #include "mash/wm/user_window_controller_impl.h"
16 #include "mojo/services/tracing/public/cpp/tracing_impl.h" 17 #include "mojo/services/tracing/public/cpp/tracing_impl.h"
17 #include "mojo/shell/public/cpp/application_connection.h" 18 #include "mojo/shell/public/cpp/application_connection.h"
18 #include "mojo/shell/public/cpp/application_impl.h" 19 #include "mojo/shell/public/cpp/application_impl.h"
19 #include "ui/mojo/init/ui_init.h" 20 #include "ui/mojo/init/ui_init.h"
20 #include "ui/views/mus/aura_init.h" 21 #include "ui/views/mus/aura_init.h"
21 #include "ui/views/mus/display_converter.h" 22 #include "ui/views/mus/display_converter.h"
22 23
23 namespace mash { 24 namespace mash {
24 namespace wm { 25 namespace wm {
25 26
26 WindowManagerApplication::WindowManagerApplication() 27 WindowManagerApplication::WindowManagerApplication()
27 : app_(nullptr), window_manager_factory_binding_(this) {} 28 : app_(nullptr), window_manager_factory_binding_(this) {}
28 29
29 WindowManagerApplication::~WindowManagerApplication() { 30 WindowManagerApplication::~WindowManagerApplication() {
31 // AcceleratorRegistrarImpl removes an observer in its destructor. Destroy
32 // it early on.
33 std::set<AcceleratorRegistrarImpl*> accelerator_registrars(
34 accelerator_registrars_);
35 for (AcceleratorRegistrarImpl* registrar : accelerator_registrars)
36 registrar->Destroy();
37
30 std::set<RootWindowController*> controllers(root_controllers_); 38 std::set<RootWindowController*> controllers(root_controllers_);
31 std::for_each( 39 for (RootWindowController* controller : controllers)
32 controllers.begin(), controllers.end(), 40 controller->Destroy();
33 [](RootWindowController* controller) { controller->Destroy(); }); 41 }
42
43 std::set<RootWindowController*> WindowManagerApplication::GetRootControllers() {
44 std::set<RootWindowController*> root_controllers;
45 for (RootWindowController* controller : root_controllers_) {
46 if (controller->root())
47 root_controllers.insert(controller);
48 }
49 return root_controllers;
34 } 50 }
35 51
36 void WindowManagerApplication::OnRootWindowControllerGotRoot( 52 void WindowManagerApplication::OnRootWindowControllerGotRoot(
37 RootWindowController* root_controller) { 53 RootWindowController* root_controller) {
38 if (ui_init_.get()) 54 if (ui_init_.get())
39 return; 55 return;
40 56
41 ui_init_.reset(new ui::mojo::UIInit( 57 ui_init_.reset(new ui::mojo::UIInit(
42 views::GetDisplaysFromWindow(root_controller->root()))); 58 views::GetDisplaysFromWindow(root_controller->root())));
43 aura_init_.reset(new views::AuraInit(app_, "mash_wm_resources.pak")); 59 aura_init_.reset(new views::AuraInit(app_, "mash_wm_resources.pak"));
44 } 60 }
45 61
46 void WindowManagerApplication::OnRootWindowControllerDoneInit( 62 void WindowManagerApplication::OnRootWindowControllerDoneInit(
47 RootWindowController* root_controller) { 63 RootWindowController* root_controller) {
48 // TODO(msw): figure out if this should be per display, or global. 64 // TODO(msw): figure out if this should be per display, or global.
49 user_window_controller_->Initialize(root_controller); 65 user_window_controller_->Initialize(root_controller);
50 for (auto& request : user_window_controller_requests_) 66 for (auto& request : user_window_controller_requests_)
51 user_window_controller_binding_.AddBinding(user_window_controller_.get(), 67 user_window_controller_binding_.AddBinding(user_window_controller_.get(),
52 std::move(*request)); 68 std::move(*request));
53 user_window_controller_requests_.clear(); 69 user_window_controller_requests_.clear();
70
71 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
72 OnRootWindowControllerAdded(root_controller));
54 } 73 }
55 74
56 void WindowManagerApplication::OnRootWindowDestroyed( 75 void WindowManagerApplication::OnRootWindowDestroyed(
57 RootWindowController* root_controller) { 76 RootWindowController* root_controller) {
58 root_controllers_.erase(root_controller); 77 root_controllers_.erase(root_controller);
59 user_window_controller_.reset(nullptr); 78 user_window_controller_.reset(nullptr);
60 } 79 }
61 80
62 void WindowManagerApplication::OnAccelerator(uint32_t id, 81 void WindowManagerApplication::OnAccelerator(uint32_t id,
63 mus::mojom::EventPtr event) { 82 mus::mojom::EventPtr event) {
64 for (auto* registrar : accelerator_registrars_) { 83 for (auto* registrar : accelerator_registrars_) {
65 if (registrar->OwnsAccelerator(id)) { 84 if (registrar->OwnsAccelerator(id)) {
66 registrar->ProcessAccelerator(id, std::move(event)); 85 registrar->ProcessAccelerator(id, std::move(event));
67 break; 86 break;
68 } 87 }
69 } 88 }
70 } 89 }
71 90
91 void WindowManagerApplication::AddRootWindowsObserver(
92 RootWindowsObserver* observer) {
93 root_windows_observers_.AddObserver(observer);
94 }
95
96 void WindowManagerApplication::RemoveRootWindowsObserver(
97 RootWindowsObserver* observer) {
98 root_windows_observers_.RemoveObserver(observer);
99 }
100
72 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed( 101 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed(
73 AcceleratorRegistrarImpl* registrar) { 102 AcceleratorRegistrarImpl* registrar) {
74 accelerator_registrars_.erase(registrar); 103 accelerator_registrars_.erase(registrar);
75 } 104 }
76 105
77 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { 106 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) {
78 app_ = app; 107 app_ = app;
79 tracing_.Initialize(app); 108 tracing_.Initialize(app);
80 109
81 mus::mojom::WindowManagerFactoryServicePtr wm_factory_service; 110 mus::mojom::WindowManagerFactoryServicePtr wm_factory_service;
(...skipping 23 matching lines...) Expand all
105 } else { 134 } else {
106 user_window_controller_requests_.push_back(make_scoped_ptr( 135 user_window_controller_requests_.push_back(make_scoped_ptr(
107 new mojo::InterfaceRequest<mash::wm::mojom::UserWindowController>( 136 new mojo::InterfaceRequest<mash::wm::mojom::UserWindowController>(
108 std::move(request)))); 137 std::move(request))));
109 } 138 }
110 } 139 }
111 140
112 void WindowManagerApplication::Create( 141 void WindowManagerApplication::Create(
113 mojo::ApplicationConnection* connection, 142 mojo::ApplicationConnection* connection,
114 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) { 143 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) {
115 // TODO(sky): figure out the right place for this code. Should it
116 // automatically register for all displays?
117 static int accelerator_registrar_count = 0; 144 static int accelerator_registrar_count = 0;
118 if (accelerator_registrar_count == std::numeric_limits<int>::max()) { 145 if (accelerator_registrar_count == std::numeric_limits<int>::max()) {
119 // Restart from zero if we have reached the limit. It is technically 146 // Restart from zero if we have reached the limit. It is technically
120 // possible to end up with multiple active registrars with the same 147 // possible to end up with multiple active registrars with the same
121 // namespace, but it is highly unlikely. In the event that multiple 148 // namespace, but it is highly unlikely. In the event that multiple
122 // registrars have the same namespace, this new registrar will be unable to 149 // registrars have the same namespace, this new registrar will be unable to
123 // install accelerators. 150 // install accelerators.
124 accelerator_registrar_count = 0; 151 accelerator_registrar_count = 0;
125 } 152 }
126 // TODO(sky): make global.
127 RootWindowController* root_controller = *root_controllers_.begin();
128 accelerator_registrars_.insert(new AcceleratorRegistrarImpl( 153 accelerator_registrars_.insert(new AcceleratorRegistrarImpl(
129 root_controller->window_tree_host(), ++accelerator_registrar_count, 154 this, ++accelerator_registrar_count, std::move(request),
130 std::move(request),
131 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed, 155 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed,
132 base::Unretained(this)))); 156 base::Unretained(this))));
133 } 157 }
134 158
135 void WindowManagerApplication::CreateWindowManager( 159 void WindowManagerApplication::CreateWindowManager(
136 mus::mojom::DisplayPtr display, 160 mus::mojom::DisplayPtr display,
137 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> client_request) { 161 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> client_request) {
138 root_controllers_.insert(RootWindowController::CreateFromDisplay( 162 root_controllers_.insert(RootWindowController::CreateFromDisplay(
139 this, std::move(display), std::move(client_request))); 163 this, std::move(display), std::move(client_request)));
140 } 164 }
141 165
142 } // namespace wm 166 } // namespace wm
143 } // namespace mash 167 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/window_manager_application.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698