OLD | NEW |
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/bind.h" | 5 #include "base/bind.h" |
6 #include "mojo/application/application_runner_chromium.h" | 6 #include "mojo/application/application_runner_chromium.h" |
7 #include "mojo/examples/wm_flow/app/embedder.mojom.h" | 7 #include "mojo/examples/wm_flow/app/embedder.mojom.h" |
8 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h" | 8 #include "mojo/examples/wm_flow/embedded/embeddee.mojom.h" |
9 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // embed without a view context. | 48 // embed without a view context. |
49 class WMFlowApp : public mojo::ApplicationDelegate, | 49 class WMFlowApp : public mojo::ApplicationDelegate, |
50 public mojo::ViewManagerDelegate, | 50 public mojo::ViewManagerDelegate, |
51 public mojo::ViewObserver { | 51 public mojo::ViewObserver { |
52 public: | 52 public: |
53 WMFlowApp() : embed_count_(0) {} | 53 WMFlowApp() : embed_count_(0) {} |
54 virtual ~WMFlowApp() {} | 54 virtual ~WMFlowApp() {} |
55 | 55 |
56 private: | 56 private: |
57 // Overridden from Application: | 57 // Overridden from Application: |
58 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 58 virtual void Initialize(mojo::ApplicationImpl* app) override { |
59 view_manager_client_factory_.reset( | 59 view_manager_client_factory_.reset( |
60 new mojo::ViewManagerClientFactory(app->shell(), this)); | 60 new mojo::ViewManagerClientFactory(app->shell(), this)); |
61 view_manager_context_.reset(new mojo::ViewManagerContext(app)); | 61 view_manager_context_.reset(new mojo::ViewManagerContext(app)); |
62 OpenNewWindow(); | 62 OpenNewWindow(); |
63 OpenNewWindow(); | 63 OpenNewWindow(); |
64 OpenNewWindow(); | 64 OpenNewWindow(); |
65 } | 65 } |
66 virtual bool ConfigureIncomingConnection( | 66 virtual bool ConfigureIncomingConnection( |
67 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 67 mojo::ApplicationConnection* connection) override { |
68 connection->AddService(view_manager_client_factory_.get()); | 68 connection->AddService(view_manager_client_factory_.get()); |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 void OnConnect(bool success) {} | 72 void OnConnect(bool success) {} |
73 | 73 |
74 // Overridden from mojo::ViewManagerDelegate: | 74 // Overridden from mojo::ViewManagerDelegate: |
75 virtual void OnEmbed( | 75 virtual void OnEmbed( |
76 mojo::ViewManager* view_manager, | 76 mojo::ViewManager* view_manager, |
77 mojo::View* root, | 77 mojo::View* root, |
78 mojo::ServiceProviderImpl* exported_services, | 78 mojo::ServiceProviderImpl* exported_services, |
79 scoped_ptr<mojo::ServiceProvider> imported_services) MOJO_OVERRIDE { | 79 scoped_ptr<mojo::ServiceProvider> imported_services) override { |
80 root->AddObserver(this); | 80 root->AddObserver(this); |
81 root->SetColor(kColors[embed_count_++ % arraysize(kColors)]); | 81 root->SetColor(kColors[embed_count_++ % arraysize(kColors)]); |
82 | 82 |
83 mojo::View* embed = mojo::View::Create(view_manager); | 83 mojo::View* embed = mojo::View::Create(view_manager); |
84 root->AddChild(embed); | 84 root->AddChild(embed); |
85 gfx::Rect bounds = gfx::Rect(root->bounds().size()); | 85 gfx::Rect bounds = gfx::Rect(root->bounds().size()); |
86 bounds.Inset(25, 25); | 86 bounds.Inset(25, 25); |
87 embed->SetBounds(bounds); | 87 embed->SetBounds(bounds); |
88 | 88 |
89 scoped_ptr<mojo::ServiceProviderImpl> registry( | 89 scoped_ptr<mojo::ServiceProviderImpl> registry( |
90 new mojo::ServiceProviderImpl); | 90 new mojo::ServiceProviderImpl); |
91 // Expose some services to the embeddee... | 91 // Expose some services to the embeddee... |
92 registry->AddService(&embedder_factory_); | 92 registry->AddService(&embedder_factory_); |
93 scoped_ptr<mojo::ServiceProvider> imported = | 93 scoped_ptr<mojo::ServiceProvider> imported = |
94 embed->Embed("mojo:mojo_wm_flow_embedded", registry.Pass()); | 94 embed->Embed("mojo:mojo_wm_flow_embedded", registry.Pass()); |
95 mojo::ConnectToService(imported.get(), &embeddee_); | 95 mojo::ConnectToService(imported.get(), &embeddee_); |
96 embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck, | 96 embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck, |
97 base::Unretained(this))); | 97 base::Unretained(this))); |
98 } | 98 } |
99 virtual void OnViewManagerDisconnected( | 99 virtual void OnViewManagerDisconnected( |
100 mojo::ViewManager* view_manager) MOJO_OVERRIDE {} | 100 mojo::ViewManager* view_manager) override {} |
101 | 101 |
102 // Overridden from mojo::ViewObserver: | 102 // Overridden from mojo::ViewObserver: |
103 virtual void OnViewInputEvent(mojo::View* view, | 103 virtual void OnViewInputEvent(mojo::View* view, |
104 const mojo::EventPtr& event) MOJO_OVERRIDE { | 104 const mojo::EventPtr& event) override { |
105 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED && | 105 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED && |
106 event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) { | 106 event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) { |
107 OpenNewWindow(); | 107 OpenNewWindow(); |
108 } | 108 } |
109 } | 109 } |
110 virtual void OnViewDestroyed(mojo::View* view) MOJO_OVERRIDE { | 110 virtual void OnViewDestroyed(mojo::View* view) override { |
111 --embed_count_; | 111 --embed_count_; |
112 view->RemoveObserver(this); | 112 view->RemoveObserver(this); |
113 } | 113 } |
114 | 114 |
115 void HelloBackAck() { | 115 void HelloBackAck() { |
116 printf("HelloBack() ack'ed\n"); | 116 printf("HelloBack() ack'ed\n"); |
117 } | 117 } |
118 | 118 |
119 void OpenNewWindow() { | 119 void OpenNewWindow() { |
120 view_manager_context_->Embed("mojo:mojo_wm_flow_app"); | 120 view_manager_context_->Embed("mojo:mojo_wm_flow_app"); |
121 } | 121 } |
122 | 122 |
123 int embed_count_; | 123 int embed_count_; |
124 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; | 124 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; |
125 mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_; | 125 mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_; |
126 scoped_ptr<mojo::ViewManagerContext> view_manager_context_; | 126 scoped_ptr<mojo::ViewManagerContext> view_manager_context_; |
127 EmbeddeePtr embeddee_; | 127 EmbeddeePtr embeddee_; |
128 | 128 |
129 DISALLOW_COPY_AND_ASSIGN(WMFlowApp); | 129 DISALLOW_COPY_AND_ASSIGN(WMFlowApp); |
130 }; | 130 }; |
131 | 131 |
132 } // namespace examples | 132 } // namespace examples |
133 | 133 |
134 MojoResult MojoMain(MojoHandle shell_handle) { | 134 MojoResult MojoMain(MojoHandle shell_handle) { |
135 mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp); | 135 mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp); |
136 return runner.Run(shell_handle); | 136 return runner.Run(shell_handle); |
137 } | 137 } |
OLD | NEW |