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 "mash/wm/window_manager_application.h" | 5 #include "mash/wm/window_manager_application.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/mus/common/util.h" | 8 #include "components/mus/common/util.h" |
9 #include "components/mus/public/cpp/event_matcher.h" | 9 #include "components/mus/public/cpp/event_matcher.h" |
10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
11 #include "components/mus/public/cpp/window_tree_connection.h" | 11 #include "components/mus/public/cpp/window_tree_connection.h" |
12 #include "components/mus/public/cpp/window_tree_host_factory.h" | 12 #include "components/mus/public/cpp/window_tree_host_factory.h" |
| 13 #include "mash/wm/accelerator_registrar_impl.h" |
13 #include "mash/wm/background_layout.h" | 14 #include "mash/wm/background_layout.h" |
14 #include "mash/wm/shelf_layout.h" | 15 #include "mash/wm/shelf_layout.h" |
15 #include "mash/wm/window_layout.h" | 16 #include "mash/wm/window_layout.h" |
16 #include "mash/wm/window_manager_impl.h" | 17 #include "mash/wm/window_manager_impl.h" |
17 #include "mojo/application/public/cpp/application_connection.h" | 18 #include "mojo/application/public/cpp/application_connection.h" |
18 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 19 #include "mojo/services/tracing/public/cpp/tracing_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 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 57 } |
57 | 58 |
58 void WindowManagerApplication::AddAccelerators() { | 59 void WindowManagerApplication::AddAccelerators() { |
59 window_tree_host_->AddAccelerator( | 60 window_tree_host_->AddAccelerator( |
60 kWindowSwitchCmd, | 61 kWindowSwitchCmd, |
61 mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_TAB, | 62 mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_TAB, |
62 mus::mojom::EVENT_FLAGS_CONTROL_DOWN), | 63 mus::mojom::EVENT_FLAGS_CONTROL_DOWN), |
63 base::Bind(&AssertTrue)); | 64 base::Bind(&AssertTrue)); |
64 } | 65 } |
65 | 66 |
| 67 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed( |
| 68 AcceleratorRegistrarImpl* registrar) { |
| 69 accelerator_registrars_.erase(registrar); |
| 70 } |
| 71 |
66 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { | 72 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { |
67 app_ = app; | 73 app_ = app; |
68 tracing_.Initialize(app); | 74 tracing_.Initialize(app); |
69 window_manager_.reset(new WindowManagerImpl()); | 75 window_manager_.reset(new WindowManagerImpl()); |
70 // Don't bind to the WindowManager immediately. Wait for OnEmbed() first. | 76 // Don't bind to the WindowManager immediately. Wait for OnEmbed() first. |
71 mus::mojom::WindowManagerPtr window_manager; | 77 mus::mojom::WindowManagerPtr window_manager; |
72 requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>( | 78 requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>( |
73 mojo::GetProxy(&window_manager))); | 79 mojo::GetProxy(&window_manager))); |
74 mus::mojom::WindowTreeHostClientPtr host_client; | 80 mus::mojom::WindowTreeHostClientPtr host_client; |
75 host_client_binding_.Bind(GetProxy(&host_client)); | 81 host_client_binding_.Bind(GetProxy(&host_client)); |
76 mus::CreateSingleWindowTreeHost(app, host_client.Pass(), this, | 82 mus::CreateSingleWindowTreeHost(app, host_client.Pass(), this, |
77 &window_tree_host_, window_manager.Pass(), | 83 &window_tree_host_, window_manager.Pass(), |
78 window_manager_.get()); | 84 window_manager_.get()); |
79 } | 85 } |
80 | 86 |
81 bool WindowManagerApplication::ConfigureIncomingConnection( | 87 bool WindowManagerApplication::ConfigureIncomingConnection( |
82 mojo::ApplicationConnection* connection) { | 88 mojo::ApplicationConnection* connection) { |
83 connection->AddService(this); | 89 connection->AddService<mus::mojom::AcceleratorRegistrar>(this); |
| 90 connection->AddService<mus::mojom::WindowManager>(this); |
84 return true; | 91 return true; |
85 } | 92 } |
86 | 93 |
87 void WindowManagerApplication::OnAccelerator(uint32_t id, | 94 void WindowManagerApplication::OnAccelerator(uint32_t id, |
88 mus::mojom::EventPtr event) { | 95 mus::mojom::EventPtr event) { |
89 switch (id) { | 96 switch (id) { |
90 case kWindowSwitchCmd: | 97 case kWindowSwitchCmd: |
91 window_tree_host_->ActivateNextWindow(); | 98 window_tree_host_->ActivateNextWindow(); |
92 break; | 99 break; |
93 default: | 100 default: |
94 NOTREACHED() << "Unknown accelerator command: " << id; | 101 for (auto* registrar : accelerator_registrars_) { |
| 102 if (registrar->OwnsAccelerator(id)) { |
| 103 registrar->ProcessAccelerator(id, event.Pass()); |
| 104 break; |
| 105 } |
| 106 } |
95 } | 107 } |
96 } | 108 } |
97 | 109 |
98 void WindowManagerApplication::OnEmbed(mus::Window* root) { | 110 void WindowManagerApplication::OnEmbed(mus::Window* root) { |
99 root_ = root; | 111 root_ = root; |
100 root_->AddObserver(this); | 112 root_->AddObserver(this); |
101 CreateContainers(); | 113 CreateContainers(); |
102 background_layout_.reset(new BackgroundLayout( | 114 background_layout_.reset(new BackgroundLayout( |
103 GetWindowForContainer(mojom::CONTAINER_USER_BACKGROUND))); | 115 GetWindowForContainer(mojom::CONTAINER_USER_BACKGROUND))); |
104 shelf_layout_.reset( | 116 shelf_layout_.reset( |
(...skipping 16 matching lines...) Expand all Loading... |
121 } | 133 } |
122 | 134 |
123 void WindowManagerApplication::OnConnectionLost( | 135 void WindowManagerApplication::OnConnectionLost( |
124 mus::WindowTreeConnection* connection) { | 136 mus::WindowTreeConnection* connection) { |
125 // TODO(sky): shutdown. | 137 // TODO(sky): shutdown. |
126 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
127 } | 139 } |
128 | 140 |
129 void WindowManagerApplication::Create( | 141 void WindowManagerApplication::Create( |
130 mojo::ApplicationConnection* connection, | 142 mojo::ApplicationConnection* connection, |
| 143 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) { |
| 144 static int accelerator_registrar_count = 0; |
| 145 if (accelerator_registrar_count == std::numeric_limits<int>::max()) { |
| 146 // Restart from zero if we have reached the limit. It is technically |
| 147 // possible to end up with multiple active registrars with the same |
| 148 // namespace, but it is highly unlikely. In the event that multiple |
| 149 // registrars have the same namespace, this new registrar will be unable to |
| 150 // install accelerators. |
| 151 accelerator_registrar_count = 0; |
| 152 } |
| 153 accelerator_registrars_.insert(new AcceleratorRegistrarImpl( |
| 154 window_tree_host_.get(), ++accelerator_registrar_count, request.Pass(), |
| 155 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed, |
| 156 base::Unretained(this)))); |
| 157 } |
| 158 |
| 159 void WindowManagerApplication::Create( |
| 160 mojo::ApplicationConnection* connection, |
131 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { | 161 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { |
132 if (root_) { | 162 if (root_) { |
133 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); | 163 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); |
134 } else { | 164 } else { |
135 requests_.push_back( | 165 requests_.push_back( |
136 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass())); | 166 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass())); |
137 } | 167 } |
138 } | 168 } |
139 | 169 |
140 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { | 170 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { |
(...skipping 13 matching lines...) Expand all Loading... |
154 DCHECK_EQ(mus::LoWord(window->id()), container) | 184 DCHECK_EQ(mus::LoWord(window->id()), container) |
155 << "Containers must be created before other windows!"; | 185 << "Containers must be created before other windows!"; |
156 window->SetBounds(root_->bounds()); | 186 window->SetBounds(root_->bounds()); |
157 window->SetVisible(true); | 187 window->SetVisible(true); |
158 root_->AddChild(window); | 188 root_->AddChild(window); |
159 } | 189 } |
160 } | 190 } |
161 | 191 |
162 } // namespace wm | 192 } // namespace wm |
163 } // namespace mash | 193 } // namespace mash |
OLD | NEW |