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

Side by Side Diff: examples/wm_flow/app/app.cc

Issue 988693005: Chromium roll (https://codereview.chromium.org/976353002) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fixed bad android build patch Created 5 years, 9 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 | « examples/window_manager/window_manager.cc ('k') | examples/wm_flow/embedded/embedded.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 <map> 5 #include <map>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "examples/bitmap_uploader/bitmap_uploader.h" 10 #include "examples/bitmap_uploader/bitmap_uploader.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // This app starts its life via Connect() rather than by being embed, so it does 79 // This app starts its life via Connect() rather than by being embed, so it does
80 // not start with a connection to the ViewManager service. It has to obtain a 80 // not start with a connection to the ViewManager service. It has to obtain a
81 // connection by connecting to the ViewManagerInit service and asking to be 81 // connection by connecting to the ViewManagerInit service and asking to be
82 // embed without a view context. 82 // embed without a view context.
83 class WMFlowApp : public mojo::ApplicationDelegate, 83 class WMFlowApp : public mojo::ApplicationDelegate,
84 public mojo::ViewManagerDelegate, 84 public mojo::ViewManagerDelegate,
85 public mojo::ViewObserver { 85 public mojo::ViewObserver {
86 public: 86 public:
87 WMFlowApp() : shell_(nullptr), embed_count_(0) {} 87 WMFlowApp() : shell_(nullptr), embed_count_(0) {}
88 virtual ~WMFlowApp() { STLDeleteValues(&uploaders_); } 88 ~WMFlowApp() override { STLDeleteValues(&uploaders_); }
89 89
90 private: 90 private:
91 typedef std::map<mojo::View*, mojo::BitmapUploader*> ViewToUploader; 91 typedef std::map<mojo::View*, mojo::BitmapUploader*> ViewToUploader;
92 92
93 // Overridden from ApplicationDelegate: 93 // Overridden from ApplicationDelegate:
94 virtual void Initialize(mojo::ApplicationImpl* app) override { 94 void Initialize(mojo::ApplicationImpl* app) override {
95 shell_ = app->shell(); 95 shell_ = app->shell();
96 view_manager_client_factory_.reset( 96 view_manager_client_factory_.reset(
97 new mojo::ViewManagerClientFactory(app->shell(), this)); 97 new mojo::ViewManagerClientFactory(app->shell(), this));
98 view_manager_context_.reset(new mojo::ViewManagerContext(app)); 98 view_manager_context_.reset(new mojo::ViewManagerContext(app));
99 // FIXME: Mojo applications don't know their URLs yet: 99 // FIXME: Mojo applications don't know their URLs yet:
100 // https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmne yXJnke-MnYYL4Gz1AKDos 100 // https://docs.google.com/a/chromium.org/document/d/1AQ2y6ekzvbdaMF5WrUQmne yXJnke-MnYYL4Gz1AKDos
101 url_ = GURL(app->args()[1]); 101 url_ = GURL(app->args()[1]);
102 OpenNewWindow(); 102 OpenNewWindow();
103 OpenNewWindow(); 103 OpenNewWindow();
104 OpenNewWindow(); 104 OpenNewWindow();
105 } 105 }
106 virtual bool ConfigureIncomingConnection( 106 bool ConfigureIncomingConnection(
107 mojo::ApplicationConnection* connection) override { 107 mojo::ApplicationConnection* connection) override {
108 connection->AddService(view_manager_client_factory_.get()); 108 connection->AddService(view_manager_client_factory_.get());
109 return true; 109 return true;
110 } 110 }
111 111
112 // Overridden from mojo::ViewManagerDelegate: 112 // Overridden from mojo::ViewManagerDelegate:
113 virtual void OnEmbed(mojo::View* root, 113 void OnEmbed(mojo::View* root,
114 mojo::InterfaceRequest<mojo::ServiceProvider> services, 114 mojo::InterfaceRequest<mojo::ServiceProvider> services,
115 mojo::ServiceProviderPtr exposed_services) override { 115 mojo::ServiceProviderPtr exposed_services) override {
116 root->AddObserver(this); 116 root->AddObserver(this);
117 mojo::BitmapUploader* uploader = new mojo::BitmapUploader(root); 117 mojo::BitmapUploader* uploader = new mojo::BitmapUploader(root);
118 uploaders_[root] = uploader; 118 uploaders_[root] = uploader;
119 uploader->Init(shell_); 119 uploader->Init(shell_);
120 // BitmapUploader does not track view size changes, we would 120 // BitmapUploader does not track view size changes, we would
121 // need to subscribe to OnViewBoundsChanged and tell the bitmap uploader 121 // need to subscribe to OnViewBoundsChanged and tell the bitmap uploader
122 // to invalidate itself. This is better done once if had a per-view 122 // to invalidate itself. This is better done once if had a per-view
123 // object instead of holding per-view state on the ApplicationDelegate. 123 // object instead of holding per-view state on the ApplicationDelegate.
124 uploader->SetColor(kColors[embed_count_++ % arraysize(kColors)]); 124 uploader->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
125 125
(...skipping 15 matching lines...) Expand all
141 embedee_exposed_services.Pass()); 141 embedee_exposed_services.Pass());
142 // FIXME: This is wrong. We're storing per-view state on this per-app 142 // FIXME: This is wrong. We're storing per-view state on this per-app
143 // delegate. Every time a new view is created embedee_ is replaced 143 // delegate. Every time a new view is created embedee_ is replaced
144 // causing the previous one to shut down. This class should not 144 // causing the previous one to shut down. This class should not
145 // be a ViewManagerDelegate, but rather a separate object should be 145 // be a ViewManagerDelegate, but rather a separate object should be
146 // created for each embedding. 146 // created for each embedding.
147 mojo::ConnectToService(imported.get(), &embeddee_); 147 mojo::ConnectToService(imported.get(), &embeddee_);
148 embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck, 148 embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck,
149 base::Unretained(this))); 149 base::Unretained(this)));
150 } 150 }
151 virtual void OnViewManagerDisconnected( 151 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override {
152 mojo::ViewManager* view_manager) override {
153 STLDeleteValues(&uploaders_); 152 STLDeleteValues(&uploaders_);
154 } 153 }
155 154
156 // Overridden from mojo::ViewObserver: 155 // Overridden from mojo::ViewObserver:
157 virtual void OnViewInputEvent(mojo::View* view, 156 void OnViewInputEvent(mojo::View* view,
158 const mojo::EventPtr& event) override { 157 const mojo::EventPtr& event) override {
159 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED && 158 if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED &&
160 event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) { 159 event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) {
161 OpenNewWindow(); 160 OpenNewWindow();
162 } 161 }
163 } 162 }
164 virtual void OnViewDestroyed(mojo::View* view) override { 163 void OnViewDestroyed(mojo::View* view) override {
165 if (uploaders_.find(view) != uploaders_.end()) { 164 if (uploaders_.find(view) != uploaders_.end()) {
166 delete uploaders_[view]; 165 delete uploaders_[view];
167 uploaders_.erase(view); 166 uploaders_.erase(view);
168 } 167 }
169 --embed_count_; 168 --embed_count_;
170 view->RemoveObserver(this); 169 view->RemoveObserver(this);
171 } 170 }
172 171
173 void HelloBackAck() { 172 void HelloBackAck() {
174 printf("HelloBack() ack'ed\n"); 173 printf("HelloBack() ack'ed\n");
(...skipping 12 matching lines...) Expand all
187 186
188 DISALLOW_COPY_AND_ASSIGN(WMFlowApp); 187 DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
189 }; 188 };
190 189
191 } // namespace examples 190 } // namespace examples
192 191
193 MojoResult MojoMain(MojoHandle shell_handle) { 192 MojoResult MojoMain(MojoHandle shell_handle) {
194 mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp); 193 mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp);
195 return runner.Run(shell_handle); 194 return runner.Run(shell_handle);
196 } 195 }
OLDNEW
« no previous file with comments | « examples/window_manager/window_manager.cc ('k') | examples/wm_flow/embedded/embedded.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698