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

Side by Side Diff: mojo/examples/window_manager/window_manager.cc

Issue 623573002: Mojo: Convert the remaining OVERRIDEs to override in mojo/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « mojo/examples/window_manager/debug_panel.h ('k') | mojo/examples/wm_flow/app/app.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/basictypes.h"
6 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h"
7 #include "mojo/application/application_runner_chromium.h" 7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/examples/keyboard/keyboard.mojom.h" 8 #include "mojo/examples/keyboard/keyboard.mojom.h"
9 #include "mojo/examples/window_manager/debug_panel.h" 9 #include "mojo/examples/window_manager/debug_panel.h"
10 #include "mojo/examples/window_manager/window_manager.mojom.h" 10 #include "mojo/examples/window_manager/window_manager.mojom.h"
11 #include "mojo/public/c/system/main.h" 11 #include "mojo/public/c/system/main.h"
12 #include "mojo/public/cpp/application/application_connection.h" 12 #include "mojo/public/cpp/application/application_connection.h"
13 #include "mojo/public/cpp/application/application_delegate.h" 13 #include "mojo/public/cpp/application/application_delegate.h"
14 #include "mojo/public/cpp/application/application_impl.h" 14 #include "mojo/public/cpp/application/application_impl.h"
15 #include "mojo/public/cpp/application/interface_factory_impl.h" 15 #include "mojo/public/cpp/application/interface_factory_impl.h"
16 #include "mojo/public/cpp/application/service_provider_impl.h" 16 #include "mojo/public/cpp/application/service_provider_impl.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } // namespace 107 } // namespace
108 108
109 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { 109 class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
110 public: 110 public:
111 explicit WindowManagerConnection(WindowManager* window_manager) 111 explicit WindowManagerConnection(WindowManager* window_manager)
112 : window_manager_(window_manager) {} 112 : window_manager_(window_manager) {}
113 virtual ~WindowManagerConnection() {} 113 virtual ~WindowManagerConnection() {}
114 114
115 private: 115 private:
116 // Overridden from IWindowManager: 116 // Overridden from IWindowManager:
117 virtual void CloseWindow(Id view_id) OVERRIDE; 117 virtual void CloseWindow(Id view_id) override;
118 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; 118 virtual void ShowKeyboard(Id view_id, RectPtr bounds) override;
119 virtual void HideKeyboard(Id view_id) OVERRIDE; 119 virtual void HideKeyboard(Id view_id) override;
120 120
121 WindowManager* window_manager_; 121 WindowManager* window_manager_;
122 122
123 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); 123 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection);
124 }; 124 };
125 125
126 class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> { 126 class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> {
127 public: 127 public:
128 explicit NavigatorHostImpl(WindowManager* window_manager, Id view_id) 128 explicit NavigatorHostImpl(WindowManager* window_manager, Id view_id)
129 : window_manager_(window_manager), view_id_(view_id) {} 129 : window_manager_(window_manager), view_id_(view_id) {}
130 virtual ~NavigatorHostImpl() { 130 virtual ~NavigatorHostImpl() {
131 } 131 }
132 132
133 private: 133 private:
134 virtual void DidNavigateLocally(const mojo::String& url) OVERRIDE; 134 virtual void DidNavigateLocally(const mojo::String& url) override;
135 virtual void RequestNavigate(Target target, URLRequestPtr request) OVERRIDE; 135 virtual void RequestNavigate(Target target, URLRequestPtr request) override;
136 136
137 WindowManager* window_manager_; 137 WindowManager* window_manager_;
138 Id view_id_; 138 Id view_id_;
139 139
140 DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl); 140 DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl);
141 }; 141 };
142 142
143 class KeyboardManager : public KeyboardClient, 143 class KeyboardManager : public KeyboardClient,
144 public ViewObserver { 144 public ViewObserver {
145 public: 145 public:
(...skipping 27 matching lines...) Expand all
173 173
174 void Hide(Id view_id) { 174 void Hide(Id view_id) {
175 keyboard_service_->SetTarget(0); 175 keyboard_service_->SetTarget(0);
176 view_->SetVisible(false); 176 view_->SetVisible(false);
177 } 177 }
178 178
179 private: 179 private:
180 // KeyboardClient: 180 // KeyboardClient:
181 virtual void OnKeyboardEvent(Id view_id, 181 virtual void OnKeyboardEvent(Id view_id,
182 int32_t code, 182 int32_t code,
183 int32_t flags) OVERRIDE { 183 int32_t flags) override {
184 View* view = view_manager_->GetViewById(view_id); 184 View* view = view_manager_->GetViewById(view_id);
185 if (!view) 185 if (!view)
186 return; 186 return;
187 #if defined(OS_WIN) 187 #if defined(OS_WIN)
188 const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN; 188 const bool is_char = code != ui::VKEY_BACK && code != ui::VKEY_RETURN;
189 #else 189 #else
190 const bool is_char = false; 190 const bool is_char = false;
191 #endif 191 #endif
192 if (is_char) { 192 if (is_char) {
193 view_manager_->DispatchEvent( 193 view_manager_->DispatchEvent(
(...skipping 11 matching lines...) Expand all
205 view_manager_->DispatchEvent( 205 view_manager_->DispatchEvent(
206 view, 206 view,
207 Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED, 207 Event::From(ui::KeyEvent(ui::ET_KEY_RELEASED,
208 static_cast<ui::KeyboardCode>(code), 208 static_cast<ui::KeyboardCode>(code),
209 flags))); 209 flags)));
210 } 210 }
211 211
212 // Overridden from ViewObserver: 212 // Overridden from ViewObserver:
213 virtual void OnViewBoundsChanged(View* parent, 213 virtual void OnViewBoundsChanged(View* parent,
214 const gfx::Rect& old_bounds, 214 const gfx::Rect& old_bounds,
215 const gfx::Rect& new_bounds) OVERRIDE { 215 const gfx::Rect& new_bounds) override {
216 gfx::Rect keyboard_bounds(view_->bounds()); 216 gfx::Rect keyboard_bounds(view_->bounds());
217 keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height()); 217 keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height());
218 keyboard_bounds.set_width(keyboard_bounds.width() + 218 keyboard_bounds.set_width(keyboard_bounds.width() +
219 new_bounds.width() - old_bounds.width()); 219 new_bounds.width() - old_bounds.width());
220 view_->SetBounds(keyboard_bounds); 220 view_->SetBounds(keyboard_bounds);
221 } 221 }
222 virtual void OnViewDestroyed(View* parent) OVERRIDE { 222 virtual void OnViewDestroyed(View* parent) override {
223 DCHECK_EQ(parent, view_->parent()); 223 DCHECK_EQ(parent, view_->parent());
224 parent->RemoveObserver(this); 224 parent->RemoveObserver(this);
225 view_ = NULL; 225 view_ = NULL;
226 } 226 }
227 227
228 KeyboardServicePtr keyboard_service_; 228 KeyboardServicePtr keyboard_service_;
229 ViewManager* view_manager_; 229 ViewManager* view_manager_;
230 230
231 // View the keyboard is attached to. 231 // View the keyboard is attached to.
232 View* view_; 232 View* view_;
(...skipping 15 matching lines...) Expand all
248 control_panel_view_id_(control_panel_view_id) {} 248 control_panel_view_id_(control_panel_view_id) {}
249 virtual ~RootLayoutManager() { 249 virtual ~RootLayoutManager() {
250 if (root_) 250 if (root_)
251 root_->RemoveObserver(this); 251 root_->RemoveObserver(this);
252 } 252 }
253 253
254 private: 254 private:
255 // Overridden from ViewObserver: 255 // Overridden from ViewObserver:
256 virtual void OnViewBoundsChanged(View* view, 256 virtual void OnViewBoundsChanged(View* view,
257 const gfx::Rect& old_bounds, 257 const gfx::Rect& old_bounds,
258 const gfx::Rect& new_bounds) OVERRIDE { 258 const gfx::Rect& new_bounds) override {
259 DCHECK_EQ(view, root_); 259 DCHECK_EQ(view, root_);
260 260
261 View* content_view = view_manager_->GetViewById(content_view_id_); 261 View* content_view = view_manager_->GetViewById(content_view_id_);
262 content_view->SetBounds(new_bounds); 262 content_view->SetBounds(new_bounds);
263 263
264 int delta_width = new_bounds.width() - old_bounds.width(); 264 int delta_width = new_bounds.width() - old_bounds.width();
265 int delta_height = new_bounds.height() - old_bounds.height(); 265 int delta_height = new_bounds.height() - old_bounds.height();
266 266
267 View* launcher_ui_view = 267 View* launcher_ui_view =
268 view_manager_->GetViewById(launcher_ui_view_id_); 268 view_manager_->GetViewById(launcher_ui_view_id_);
(...skipping 13 matching lines...) Expand all
282 View* view = *iter; 282 View* view = *iter;
283 if (view->id() == control_panel_view->id() || 283 if (view->id() == control_panel_view->id() ||
284 view->id() == launcher_ui_view->id()) 284 view->id() == launcher_ui_view->id())
285 continue; 285 continue;
286 gfx::Rect view_bounds(view->bounds()); 286 gfx::Rect view_bounds(view->bounds());
287 view_bounds.set_width(view_bounds.width() + delta_width); 287 view_bounds.set_width(view_bounds.width() + delta_width);
288 view_bounds.set_height(view_bounds.height() + delta_height); 288 view_bounds.set_height(view_bounds.height() + delta_height);
289 view->SetBounds(view_bounds); 289 view->SetBounds(view_bounds);
290 } 290 }
291 } 291 }
292 virtual void OnViewDestroyed(View* view) OVERRIDE { 292 virtual void OnViewDestroyed(View* view) override {
293 DCHECK_EQ(view, root_); 293 DCHECK_EQ(view, root_);
294 root_->RemoveObserver(this); 294 root_->RemoveObserver(this);
295 root_ = NULL; 295 root_ = NULL;
296 } 296 }
297 297
298 View* root_; 298 View* root_;
299 ViewManager* view_manager_; 299 ViewManager* view_manager_;
300 const Id content_view_id_; 300 const Id content_view_id_;
301 const Id launcher_ui_view_id_; 301 const Id launcher_ui_view_id_;
302 const Id control_panel_view_id_; 302 const Id control_panel_view_id_;
(...skipping 13 matching lines...) Expand all
316 void Embed(const std::string& url) { 316 void Embed(const std::string& url) {
317 scoped_ptr<ServiceProviderImpl> service_provider_impl( 317 scoped_ptr<ServiceProviderImpl> service_provider_impl(
318 new ServiceProviderImpl()); 318 new ServiceProviderImpl());
319 service_provider_impl->AddService<NavigatorHost>(this); 319 service_provider_impl->AddService<NavigatorHost>(this);
320 view_->Embed(url, service_provider_impl.Pass()); 320 view_->Embed(url, service_provider_impl.Pass());
321 } 321 }
322 322
323 private: 323 private:
324 // InterfaceFactory<NavigatorHost> 324 // InterfaceFactory<NavigatorHost>
325 virtual void Create(ApplicationConnection* connection, 325 virtual void Create(ApplicationConnection* connection,
326 InterfaceRequest<NavigatorHost> request) OVERRIDE { 326 InterfaceRequest<NavigatorHost> request) override {
327 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()), 327 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()),
328 &request); 328 &request);
329 } 329 }
330 330
331 WindowManager* window_manager_; 331 WindowManager* window_manager_;
332 View* view_; 332 View* view_;
333 }; 333 };
334 334
335 class WindowManager 335 class WindowManager
336 : public ApplicationDelegate, 336 : public ApplicationDelegate,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (keyboard_manager_) 385 if (keyboard_manager_)
386 keyboard_manager_->Hide(view_id); 386 keyboard_manager_->Hide(view_id);
387 } 387 }
388 388
389 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) { 389 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) {
390 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id 390 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id
391 << " url: " << url.To<std::string>(); 391 << " url: " << url.To<std::string>();
392 } 392 }
393 393
394 // Overridden from DebugPanel::Delegate: 394 // Overridden from DebugPanel::Delegate:
395 virtual void CloseTopWindow() OVERRIDE { 395 virtual void CloseTopWindow() override {
396 if (!windows_.empty()) 396 if (!windows_.empty())
397 CloseWindow(windows_.back()->view()->id()); 397 CloseWindow(windows_.back()->view()->id());
398 } 398 }
399 399
400 virtual void RequestNavigate(uint32 source_view_id, 400 virtual void RequestNavigate(uint32 source_view_id,
401 Target target, 401 Target target,
402 URLRequestPtr request) OVERRIDE { 402 URLRequestPtr request) override {
403 OnLaunch(source_view_id, target, request->url); 403 OnLaunch(source_view_id, target, request->url);
404 } 404 }
405 405
406 private: 406 private:
407 typedef std::vector<Window*> WindowVector; 407 typedef std::vector<Window*> WindowVector;
408 408
409 // Overridden from ApplicationDelegate: 409 // Overridden from ApplicationDelegate:
410 virtual void Initialize(ApplicationImpl* app) override { 410 virtual void Initialize(ApplicationImpl* app) override {
411 app_ = app; 411 app_ = app;
412 views_init_.reset(new ViewsInit); 412 views_init_.reset(new ViewsInit);
413 window_manager_app_->Initialize(app); 413 window_manager_app_->Initialize(app);
414 } 414 }
415 415
416 virtual bool ConfigureIncomingConnection( 416 virtual bool ConfigureIncomingConnection(
417 ApplicationConnection* connection) override { 417 ApplicationConnection* connection) override {
418 connection->AddService(&window_manager_factory_); 418 connection->AddService(&window_manager_factory_);
419 window_manager_app_->ConfigureIncomingConnection(connection); 419 window_manager_app_->ConfigureIncomingConnection(connection);
420 return true; 420 return true;
421 } 421 }
422 422
423 // Overridden from ViewManagerDelegate: 423 // Overridden from ViewManagerDelegate:
424 virtual void OnEmbed(ViewManager* view_manager, 424 virtual void OnEmbed(ViewManager* view_manager,
425 View* root, 425 View* root,
426 ServiceProviderImpl* exported_services, 426 ServiceProviderImpl* exported_services,
427 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { 427 scoped_ptr<ServiceProvider> imported_services) override {
428 DCHECK(!view_manager_); 428 DCHECK(!view_manager_);
429 view_manager_ = view_manager; 429 view_manager_ = view_manager;
430 430
431 View* view = View::Create(view_manager_); 431 View* view = View::Create(view_manager_);
432 root->AddChild(view); 432 root->AddChild(view);
433 view->SetBounds(gfx::Rect(root->bounds().size())); 433 view->SetBounds(gfx::Rect(root->bounds().size()));
434 content_view_id_ = view->id(); 434 content_view_id_ = view->id();
435 435
436 Id launcher_ui_id = CreateLauncherUI(); 436 Id launcher_ui_id = CreateLauncherUI();
437 Id control_panel_id = CreateControlPanel(view); 437 Id control_panel_id = CreateControlPanel(view);
438 438
439 root_layout_manager_.reset( 439 root_layout_manager_.reset(
440 new RootLayoutManager(view_manager, root, 440 new RootLayoutManager(view_manager, root,
441 content_view_id_, 441 content_view_id_,
442 launcher_ui_id, 442 launcher_ui_id,
443 control_panel_id)); 443 control_panel_id));
444 root->AddObserver(root_layout_manager_.get()); 444 root->AddObserver(root_layout_manager_.get());
445 445
446 window_manager_app_->host()->window()->AddPreTargetHandler(this); 446 window_manager_app_->host()->window()->AddPreTargetHandler(this);
447 447
448 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(), 448 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
449 view)); 449 view));
450 } 450 }
451 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { 451 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
452 DCHECK_EQ(view_manager_, view_manager); 452 DCHECK_EQ(view_manager_, view_manager);
453 view_manager_ = NULL; 453 view_manager_ = NULL;
454 base::MessageLoop::current()->Quit(); 454 base::MessageLoop::current()->Quit();
455 } 455 }
456 456
457 // Overridden from WindowManagerDelegate: 457 // Overridden from WindowManagerDelegate:
458 virtual void Embed( 458 virtual void Embed(
459 const String& url, 459 const String& url,
460 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { 460 InterfaceRequest<ServiceProvider> service_provider) override {
461 const Id kInvalidSourceViewId = 0; 461 const Id kInvalidSourceViewId = 0;
462 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); 462 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url);
463 } 463 }
464 virtual void DispatchEvent(EventPtr event) override {} 464 virtual void DispatchEvent(EventPtr event) override {}
465 465
466 // Overridden from ui::EventHandler: 466 // Overridden from ui::EventHandler:
467 virtual void OnEvent(ui::Event* event) OVERRIDE { 467 virtual void OnEvent(ui::Event* event) override {
468 View* view = WindowManagerApp::GetViewForWindow( 468 View* view = WindowManagerApp::GetViewForWindow(
469 static_cast<aura::Window*>(event->target())); 469 static_cast<aura::Window*>(event->target()));
470 if (event->type() == ui::ET_MOUSE_PRESSED && 470 if (event->type() == ui::ET_MOUSE_PRESSED &&
471 !IsDescendantOfKeyboard(view)) { 471 !IsDescendantOfKeyboard(view)) {
472 view->SetFocus(); 472 view->SetFocus();
473 } 473 }
474 } 474 }
475 475
476 void OnLaunch(uint32 source_view_id, 476 void OnLaunch(uint32 source_view_id,
477 Target requested_target, 477 Target requested_target,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 window_manager_->RequestNavigate(view_id_, target, request.Pass()); 614 window_manager_->RequestNavigate(view_id_, target, request.Pass());
615 } 615 }
616 616
617 } // namespace examples 617 } // namespace examples
618 } // namespace mojo 618 } // namespace mojo
619 619
620 MojoResult MojoMain(MojoHandle shell_handle) { 620 MojoResult MojoMain(MojoHandle shell_handle) {
621 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); 621 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager);
622 return runner.Run(shell_handle); 622 return runner.Run(shell_handle);
623 } 623 }
OLDNEW
« no previous file with comments | « mojo/examples/window_manager/debug_panel.h ('k') | mojo/examples/wm_flow/app/app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698