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

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

Issue 1488713002: mus: Introduce AcceleratorRegistrar and AcceleratorHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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 "base/bind.h"
7 #include "components/mus/common/util.h" 8 #include "components/mus/common/util.h"
8 #include "components/mus/public/cpp/event_matcher.h" 9 #include "components/mus/public/cpp/event_matcher.h"
9 #include "components/mus/public/cpp/window.h" 10 #include "components/mus/public/cpp/window.h"
10 #include "components/mus/public/cpp/window_tree_connection.h" 11 #include "components/mus/public/cpp/window_tree_connection.h"
11 #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"
12 #include "mash/wm/background_layout.h" 14 #include "mash/wm/background_layout.h"
13 #include "mash/wm/shelf_layout.h" 15 #include "mash/wm/shelf_layout.h"
14 #include "mash/wm/window_layout.h" 16 #include "mash/wm/window_layout.h"
15 #include "mash/wm/window_manager_impl.h" 17 #include "mash/wm/window_manager_impl.h"
16 #include "mojo/application/public/cpp/application_connection.h" 18 #include "mojo/application/public/cpp/application_connection.h"
17 #include "mojo/services/tracing/public/cpp/tracing_impl.h" 19 #include "mojo/services/tracing/public/cpp/tracing_impl.h"
18 #include "ui/mojo/init/ui_init.h" 20 #include "ui/mojo/init/ui_init.h"
19 #include "ui/views/mus/aura_init.h" 21 #include "ui/views/mus/aura_init.h"
20 #include "ui/views/mus/display_converter.h" 22 #include "ui/views/mus/display_converter.h"
21 23
(...skipping 22 matching lines...) Expand all
44 return root_->GetChildById(id); 46 return root_->GetChildById(id);
45 } 47 }
46 48
47 void WindowManagerApplication::AddAccelerators() { 49 void WindowManagerApplication::AddAccelerators() {
48 window_tree_host_->AddAccelerator( 50 window_tree_host_->AddAccelerator(
49 kWindowSwitchCmd, 51 kWindowSwitchCmd,
50 mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_TAB, 52 mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_TAB,
51 mus::mojom::EVENT_FLAGS_CONTROL_DOWN)); 53 mus::mojom::EVENT_FLAGS_CONTROL_DOWN));
52 } 54 }
53 55
56 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed(
57 AcceleratorRegistrarImpl* registrar) {
58 accelerator_registrars_.erase(registrar);
59 }
60
54 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { 61 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) {
55 app_ = app; 62 app_ = app;
56 tracing_.Initialize(app); 63 tracing_.Initialize(app);
57 window_manager_.reset(new WindowManagerImpl()); 64 window_manager_.reset(new WindowManagerImpl());
58 // Don't bind to the WindowManager immediately. Wait for OnEmbed() first. 65 // Don't bind to the WindowManager immediately. Wait for OnEmbed() first.
59 mus::mojom::WindowManagerPtr window_manager; 66 mus::mojom::WindowManagerPtr window_manager;
60 requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>( 67 requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>(
61 mojo::GetProxy(&window_manager))); 68 mojo::GetProxy(&window_manager)));
62 mus::mojom::WindowTreeHostClientPtr host_client; 69 mus::mojom::WindowTreeHostClientPtr host_client;
63 host_client_binding_.Bind(GetProxy(&host_client)); 70 host_client_binding_.Bind(GetProxy(&host_client));
64 mus::CreateSingleWindowTreeHost(app, host_client.Pass(), this, 71 mus::CreateSingleWindowTreeHost(app, host_client.Pass(), this,
65 &window_tree_host_, window_manager.Pass(), 72 &window_tree_host_, window_manager.Pass(),
66 window_manager_.get()); 73 window_manager_.get());
67 } 74 }
68 75
69 bool WindowManagerApplication::ConfigureIncomingConnection( 76 bool WindowManagerApplication::ConfigureIncomingConnection(
70 mojo::ApplicationConnection* connection) { 77 mojo::ApplicationConnection* connection) {
71 connection->AddService(this); 78 connection->AddService<mus::mojom::AcceleratorRegistrar>(this);
79 connection->AddService<mus::mojom::WindowManager>(this);
72 return true; 80 return true;
73 } 81 }
74 82
75 void WindowManagerApplication::OnAccelerator(uint32_t id, 83 void WindowManagerApplication::OnAccelerator(uint32_t id,
76 mus::mojom::EventPtr event) { 84 mus::mojom::EventPtr event) {
77 switch (id) { 85 switch (id) {
78 case kWindowSwitchCmd: 86 case kWindowSwitchCmd:
79 window_tree_host_->ActivateNextWindow(); 87 window_tree_host_->ActivateNextWindow();
80 break; 88 break;
81 default: 89 default:
82 NOTREACHED() << "Unknown accelerator command: " << id; 90 for (auto* registrar : accelerator_registrars_) {
91 if (registrar->OwnsAccelerator(id)) {
92 registrar->ProcessAccelerator(id, event.Pass());
93 break;
94 }
95 }
83 } 96 }
84 } 97 }
85 98
86 void WindowManagerApplication::OnEmbed(mus::Window* root) { 99 void WindowManagerApplication::OnEmbed(mus::Window* root) {
87 root_ = root; 100 root_ = root;
88 root_->AddObserver(this); 101 root_->AddObserver(this);
89 CreateContainers(); 102 CreateContainers();
90 background_layout_.reset(new BackgroundLayout( 103 background_layout_.reset(new BackgroundLayout(
91 GetWindowForContainer(mojom::CONTAINER_USER_BACKGROUND))); 104 GetWindowForContainer(mojom::CONTAINER_USER_BACKGROUND)));
92 shelf_layout_.reset( 105 shelf_layout_.reset(
(...skipping 16 matching lines...) Expand all
109 } 122 }
110 123
111 void WindowManagerApplication::OnConnectionLost( 124 void WindowManagerApplication::OnConnectionLost(
112 mus::WindowTreeConnection* connection) { 125 mus::WindowTreeConnection* connection) {
113 // TODO(sky): shutdown. 126 // TODO(sky): shutdown.
114 NOTIMPLEMENTED(); 127 NOTIMPLEMENTED();
115 } 128 }
116 129
117 void WindowManagerApplication::Create( 130 void WindowManagerApplication::Create(
118 mojo::ApplicationConnection* connection, 131 mojo::ApplicationConnection* connection,
132 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) {
133 static int accelerator_registrar_count = 0;
134 if (accelerator_registrar_count == std::numeric_limits<int>::max()) {
135 // Restart from zero if we have reached the limit. It is technically
136 // possible to end up with multiple active registrars with the same
137 // namespace, but it is highly unlikely. In the event that multiple
138 // registrars have the same namespace, this new registrar will be unable to
139 // install accelerators.
Ben Goodger (Google) 2015/12/02 00:59:45 how is this enforced? you don't seem to prevent re
sadrul 2015/12/02 19:14:25 Ah, you are right. We do not actually do the right
140 accelerator_registrar_count = 0;
141 }
142 accelerator_registrars_.insert(new AcceleratorRegistrarImpl(
143 window_tree_host_.get(), ++accelerator_registrar_count, request.Pass(),
144 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed,
145 base::Unretained(this))));
146 }
147
148 void WindowManagerApplication::Create(
149 mojo::ApplicationConnection* connection,
119 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { 150 mojo::InterfaceRequest<mus::mojom::WindowManager> request) {
120 if (root_) { 151 if (root_) {
121 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); 152 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass());
122 } else { 153 } else {
123 requests_.push_back( 154 requests_.push_back(
124 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass())); 155 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass()));
125 } 156 }
126 } 157 }
127 158
128 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { 159 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) {
(...skipping 13 matching lines...) Expand all
142 DCHECK_EQ(mus::LoWord(window->id()), container) 173 DCHECK_EQ(mus::LoWord(window->id()), container)
143 << "Containers must be created before other windows!"; 174 << "Containers must be created before other windows!";
144 window->SetBounds(root_->bounds()); 175 window->SetBounds(root_->bounds());
145 window->SetVisible(true); 176 window->SetVisible(true);
146 root_->AddChild(window); 177 root_->AddChild(window);
147 } 178 }
148 } 179 }
149 180
150 } // namespace wm 181 } // namespace wm
151 } // namespace mash 182 } // 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