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

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

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « mojo/examples/surfaces_app/child_impl.cc ('k') | mojo/gles2/command_buffer_client_impl.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" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "mojo/examples/keyboard/keyboard.mojom.h" 7 #include "mojo/examples/keyboard/keyboard.mojom.h"
8 #include "mojo/examples/window_manager/debug_panel.h" 8 #include "mojo/examples/window_manager/debug_panel.h"
9 #include "mojo/examples/window_manager/window_manager.mojom.h" 9 #include "mojo/examples/window_manager/window_manager.mojom.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h" 12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/interface_factory_with_context.h"
13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
14 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" 15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
15 #include "mojo/services/public/cpp/view_manager/node.h" 16 #include "mojo/services/public/cpp/view_manager/node.h"
16 #include "mojo/services/public/cpp/view_manager/node_observer.h" 17 #include "mojo/services/public/cpp/view_manager/node_observer.h"
17 #include "mojo/services/public/cpp/view_manager/view.h" 18 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager.h"
20 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" 22 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" 23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" 24 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 25 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
24 #include "mojo/views/views_init.h" 26 #include "mojo/views/views_init.h"
25 #include "ui/events/event.h" 27 #include "ui/events/event.h"
26 #include "ui/events/event_constants.h" 28 #include "ui/events/event_constants.h"
27 #include "ui/gfx/geometry/size_conversions.h" 29 #include "ui/gfx/geometry/size_conversions.h"
28 30
29 #if defined CreateWindow 31 #if defined CreateWindow
30 #undef CreateWindow 32 #undef CreateWindow
31 #endif 33 #endif
32 34
33 using mojo::view_manager::Id; 35 using mojo::view_manager::Id;
34 using mojo::view_manager::Node; 36 using mojo::view_manager::Node;
35 using mojo::view_manager::NodeObserver; 37 using mojo::view_manager::NodeObserver;
36 using mojo::view_manager::View; 38 using mojo::view_manager::View;
37 using mojo::view_manager::ViewManager; 39 using mojo::view_manager::ViewManager;
40 using mojo::view_manager::ViewManagerClientFactory;
38 using mojo::view_manager::ViewManagerDelegate; 41 using mojo::view_manager::ViewManagerDelegate;
39 using mojo::view_manager::ViewObserver; 42 using mojo::view_manager::ViewObserver;
40 using mojo::view_manager::WindowManagerDelegate; 43 using mojo::view_manager::WindowManagerDelegate;
41 44
42 namespace mojo { 45 namespace mojo {
43 namespace examples { 46 namespace examples {
44 47
45 class WindowManager; 48 class WindowManager;
46 49
47 namespace { 50 namespace {
48 51
49 const int kBorderInset = 25; 52 const int kBorderInset = 25;
50 const int kControlPanelWidth = 200; 53 const int kControlPanelWidth = 200;
51 const int kTextfieldHeight = 25; 54 const int kTextfieldHeight = 25;
52 55
53 } // namespace 56 } // namespace
54 57
55 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { 58 class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
56 public: 59 public:
57 explicit WindowManagerConnection(ApplicationConnection* connection, 60 explicit WindowManagerConnection(WindowManager* window_manager)
58 WindowManager* window_manager)
59 : window_manager_(window_manager) {} 61 : window_manager_(window_manager) {}
60 virtual ~WindowManagerConnection() {} 62 virtual ~WindowManagerConnection() {}
61 63
62 private: 64 private:
63 // Overridden from IWindowManager: 65 // Overridden from IWindowManager:
64 virtual void CloseWindow(Id node_id) OVERRIDE; 66 virtual void CloseWindow(Id node_id) OVERRIDE;
65 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; 67 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE;
66 virtual void HideKeyboard(Id view_id) OVERRIDE; 68 virtual void HideKeyboard(Id view_id) OVERRIDE;
67 69
68 WindowManager* window_manager_; 70 WindowManager* window_manager_;
69 71
70 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); 72 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection);
71 }; 73 };
72 74
73 class NavigatorHost : public InterfaceImpl<navigation::NavigatorHost> { 75 class NavigatorHost : public InterfaceImpl<navigation::NavigatorHost> {
74 public: 76 public:
75 explicit NavigatorHost(ApplicationConnection* connection, 77 explicit NavigatorHost(WindowManager* window_manager)
76 WindowManager* window_manager) 78 : window_manager_(window_manager) {}
77 : window_manager_(window_manager) {
78 }
79 virtual ~NavigatorHost() { 79 virtual ~NavigatorHost() {
80 } 80 }
81 81
82 private: 82 private:
83 virtual void DidNavigateLocally(uint32 source_node_id, 83 virtual void DidNavigateLocally(uint32 source_node_id,
84 const mojo::String& url) OVERRIDE; 84 const mojo::String& url) OVERRIDE;
85 virtual void RequestNavigate( 85 virtual void RequestNavigate(
86 uint32 source_node_id, 86 uint32 source_node_id,
87 navigation::Target target, 87 navigation::Target target,
88 navigation::NavigationDetailsPtr nav_details) OVERRIDE; 88 navigation::NavigationDetailsPtr nav_details) OVERRIDE;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 Node* root_; 243 Node* root_;
244 ViewManager* view_manager_; 244 ViewManager* view_manager_;
245 const Id content_node_id_; 245 const Id content_node_id_;
246 const Id launcher_ui_node_id_; 246 const Id launcher_ui_node_id_;
247 const Id control_panel_node_id_; 247 const Id control_panel_node_id_;
248 248
249 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); 249 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
250 }; 250 };
251 251
252 class WindowManager : public ApplicationDelegate, 252 class WindowManager
253 public DebugPanel::Delegate, 253 : public ApplicationDelegate,
254 public ViewManagerDelegate, 254 public DebugPanel::Delegate,
255 public WindowManagerDelegate { 255 public ViewManagerDelegate,
256 public WindowManagerDelegate,
257 public InterfaceFactoryWithContext<WindowManagerConnection,
258 WindowManager>,
259 public InterfaceFactoryWithContext<NavigatorHost, WindowManager> {
256 public: 260 public:
257 WindowManager() 261 WindowManager()
258 : launcher_ui_(NULL), 262 : InterfaceFactoryWithContext<WindowManagerConnection, WindowManager>(
263 this),
264 InterfaceFactoryWithContext<NavigatorHost, WindowManager>(this),
265 launcher_ui_(NULL),
259 view_manager_(NULL), 266 view_manager_(NULL),
260 app_(NULL) { 267 view_manager_client_factory_(this),
261 } 268 app_(NULL) {}
262 269
263 virtual ~WindowManager() {} 270 virtual ~WindowManager() {}
264 271
265 void CloseWindow(Id node_id) { 272 void CloseWindow(Id node_id) {
266 Node* node = view_manager_->GetNodeById(node_id); 273 Node* node = view_manager_->GetNodeById(node_id);
267 DCHECK(node); 274 DCHECK(node);
268 std::vector<Node*>::iterator iter = 275 std::vector<Node*>::iterator iter =
269 std::find(windows_.begin(), windows_.end(), node); 276 std::find(windows_.begin(), windows_.end(), node);
270 DCHECK(iter != windows_.end()); 277 DCHECK(iter != windows_.end());
271 windows_.erase(iter); 278 windows_.erase(iter);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 private: 329 private:
323 // Overridden from ApplicationDelegate: 330 // Overridden from ApplicationDelegate:
324 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { 331 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
325 app_ = app; 332 app_ = app;
326 app->ConnectToService("mojo:mojo_launcher", &launcher_); 333 app->ConnectToService("mojo:mojo_launcher", &launcher_);
327 views_init_.reset(new ViewsInit); 334 views_init_.reset(new ViewsInit);
328 } 335 }
329 336
330 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 337 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
331 MOJO_OVERRIDE { 338 MOJO_OVERRIDE {
332 connection->AddService<WindowManagerConnection>(this); 339 connection->AddService<IWindowManager>(this);
333 connection->AddService<NavigatorHost>(this); 340 connection->AddService<navigation::NavigatorHost>(this);
334 ViewManager::ConfigureIncomingConnection(connection, this); 341 connection->AddService(&view_manager_client_factory_);
335 return true; 342 return true;
336 } 343 }
337 344
338 // Overridden from ViewManagerDelegate: 345 // Overridden from ViewManagerDelegate:
339 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { 346 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
340 DCHECK(!view_manager_); 347 DCHECK(!view_manager_);
341 view_manager_ = view_manager; 348 view_manager_ = view_manager;
342 view_manager_->SetWindowManagerDelegate(this); 349 view_manager_->SetWindowManagerDelegate(this);
343 350
344 Node* node = Node::Create(view_manager_); 351 Node* node = Node::Create(view_manager_);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 debug_panel_ = new DebugPanel(this, node); 505 debug_panel_ = new DebugPanel(this, node);
499 return node->id(); 506 return node->id();
500 } 507 }
501 508
502 scoped_ptr<ViewsInit> views_init_; 509 scoped_ptr<ViewsInit> views_init_;
503 DebugPanel* debug_panel_; 510 DebugPanel* debug_panel_;
504 launcher::LauncherPtr launcher_; 511 launcher::LauncherPtr launcher_;
505 Node* launcher_ui_; 512 Node* launcher_ui_;
506 std::vector<Node*> windows_; 513 std::vector<Node*> windows_;
507 ViewManager* view_manager_; 514 ViewManager* view_manager_;
515 ViewManagerClientFactory view_manager_client_factory_;
508 scoped_ptr<RootLayoutManager> root_layout_manager_; 516 scoped_ptr<RootLayoutManager> root_layout_manager_;
509 517
510 // Id of the node most content is added to. The keyboard is NOT added here. 518 // Id of the node most content is added to. The keyboard is NOT added here.
511 Id content_node_id_; 519 Id content_node_id_;
512 520
513 scoped_ptr<KeyboardManager> keyboard_manager_; 521 scoped_ptr<KeyboardManager> keyboard_manager_;
514 ApplicationImpl* app_; 522 ApplicationImpl* app_;
515 523
516 DISALLOW_COPY_AND_ASSIGN(WindowManager); 524 DISALLOW_COPY_AND_ASSIGN(WindowManager);
517 }; 525 };
(...skipping 23 matching lines...) Expand all
541 } 549 }
542 550
543 } // namespace examples 551 } // namespace examples
544 552
545 // static 553 // static
546 ApplicationDelegate* ApplicationDelegate::Create() { 554 ApplicationDelegate* ApplicationDelegate::Create() {
547 return new examples::WindowManager; 555 return new examples::WindowManager;
548 } 556 }
549 557
550 } // namespace mojo 558 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/surfaces_app/child_impl.cc ('k') | mojo/gles2/command_buffer_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698