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

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
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(this)); 64 window_manager_.reset(new WindowManagerImpl(this));
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 15 matching lines...) Expand all
108 } 121 }
109 122
110 void WindowManagerApplication::OnConnectionLost( 123 void WindowManagerApplication::OnConnectionLost(
111 mus::WindowTreeConnection* connection) { 124 mus::WindowTreeConnection* connection) {
112 // TODO(sky): shutdown. 125 // TODO(sky): shutdown.
113 NOTIMPLEMENTED(); 126 NOTIMPLEMENTED();
114 } 127 }
115 128
116 void WindowManagerApplication::Create( 129 void WindowManagerApplication::Create(
117 mojo::ApplicationConnection* connection, 130 mojo::ApplicationConnection* connection,
131 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) {
132 static int accelerator_registrar_count = 0;
133 accelerator_registrars_.insert(new AcceleratorRegistrarImpl(
134 window_tree_host_.get(), ++accelerator_registrar_count, request.Pass(),
135 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed,
136 base::Unretained(this))));
137 }
138
139 void WindowManagerApplication::Create(
140 mojo::ApplicationConnection* connection,
118 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { 141 mojo::InterfaceRequest<mus::mojom::WindowManager> request) {
119 if (root_) { 142 if (root_) {
120 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); 143 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass());
121 } else { 144 } else {
122 requests_.push_back( 145 requests_.push_back(
123 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass())); 146 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass()));
124 } 147 }
125 } 148 }
126 149
127 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { 150 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) {
(...skipping 13 matching lines...) Expand all
141 DCHECK_EQ(mus::LoWord(window->id()), container) 164 DCHECK_EQ(mus::LoWord(window->id()), container)
142 << "Containers must be created before other windows!"; 165 << "Containers must be created before other windows!";
143 window->SetBounds(root_->bounds()); 166 window->SetBounds(root_->bounds());
144 window->SetVisible(true); 167 window->SetVisible(true);
145 root_->AddChild(window); 168 root_->AddChild(window);
146 } 169 }
147 } 170 }
148 171
149 } // namespace wm 172 } // namespace wm
150 } // namespace mash 173 } // namespace mash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698