OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_ptr.h" | |
6 #include "mojo/application/application_runner_chromium.h" | |
7 #include "mojo/common/tracing_impl.h" | |
8 #include "mojo/public/c/system/main.h" | |
9 #include "mojo/public/cpp/application/application_delegate.h" | |
10 #include "mojo/public/cpp/application/service_provider_impl.h" | |
11 #include "mojo/services/view_manager/cpp/view_manager.h" | |
12 #include "mojo/services/view_manager/cpp/view_manager_delegate.h" | |
13 #include "services/window_manager/basic_focus_rules.h" | |
14 #include "services/window_manager/window_manager_app.h" | |
15 #include "services/window_manager/window_manager_delegate.h" | |
16 #include "services/window_manager/window_manager_root.h" | |
17 | |
18 // ApplicationDelegate implementation file for WindowManager users (e.g. | |
19 // core window manager tests) that do not want to provide their own | |
20 // ApplicationDelegate::Create(). | |
21 | |
22 using mojo::View; | |
23 using mojo::ViewManager; | |
24 | |
25 namespace window_manager { | |
26 | |
27 class DefaultWindowManagerController : public WindowManagerController { | |
28 public: | |
29 DefaultWindowManagerController(WindowManagerRoot* wm_root) | |
30 : window_manager_root_(wm_root), root_(nullptr), window_offset_(10) {} | |
31 | |
32 ~DefaultWindowManagerController() override {} | |
33 | |
34 private: | |
35 // Overridden from ViewManagerDelegate: | |
36 void OnEmbed(View* root, | |
37 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
38 mojo::ServiceProviderPtr exposed_services) override { | |
39 root_ = root; | |
40 window_manager_root_->InitFocus( | |
41 make_scoped_ptr(new window_manager::BasicFocusRules(root_))); | |
42 } | |
43 | |
44 void OnViewManagerDisconnected(ViewManager* view_manager) override {} | |
45 | |
46 // Overridden from WindowManagerDelegate: | |
47 void Embed(const mojo::String& url, | |
48 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
49 mojo::ServiceProviderPtr exposed_services) override { | |
50 DCHECK(root_); | |
51 View* view = root_->view_manager()->CreateView(); | |
52 root_->AddChild(view); | |
53 | |
54 mojo::Rect rect; | |
55 rect.x = rect.y = window_offset_; | |
56 rect.width = rect.height = 100; | |
57 view->SetBounds(rect); | |
58 window_offset_ += 10; | |
59 | |
60 view->SetVisible(true); | |
61 view->Embed(url, services.Pass(), exposed_services.Pass()); | |
62 } | |
63 | |
64 WindowManagerRoot* window_manager_root_; | |
65 | |
66 View* root_; | |
67 int window_offset_; | |
68 | |
69 MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManagerController); | |
70 }; | |
71 | |
72 class DefaultWindowManager : public mojo::ApplicationDelegate, | |
73 public WindowManagerControllerFactory { | |
74 public: | |
75 DefaultWindowManager() : window_manager_app_(new WindowManagerApp(this)) {} | |
76 | |
77 // Overridden from mojo::ApplicationDelegate: | |
78 void Initialize(mojo::ApplicationImpl* impl) override { | |
79 tracing_.Initialize(impl); | |
80 window_manager_app_->Initialize(impl); | |
81 } | |
82 | |
83 bool ConfigureIncomingConnection( | |
84 mojo::ApplicationConnection* connection) override { | |
85 window_manager_app_->ConfigureIncomingConnection(connection); | |
86 return true; | |
87 } | |
88 | |
89 scoped_ptr<WindowManagerController> CreateWindowManagerController( | |
90 mojo::ApplicationConnection* connection, | |
91 window_manager::WindowManagerRoot* wm_root) override { | |
92 return scoped_ptr<WindowManagerController>( | |
93 new DefaultWindowManagerController(wm_root)); | |
94 } | |
95 | |
96 private: | |
97 scoped_ptr<WindowManagerApp> window_manager_app_; | |
98 mojo::TracingImpl tracing_; | |
99 MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManager); | |
100 }; | |
101 | |
102 } // namespace window_manager | |
103 | |
104 MojoResult MojoMain(MojoHandle application_request) { | |
105 mojo::ApplicationRunnerChromium runner( | |
106 new window_manager::DefaultWindowManager); | |
107 return runner.Run(application_request); | |
108 } | |
OLD | NEW |