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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 }; | 204 }; |
205 | 205 |
206 class MediaViewer | 206 class MediaViewer |
207 : public ApplicationDelegate, | 207 : public ApplicationDelegate, |
208 public ViewManagerDelegate, | 208 public ViewManagerDelegate, |
209 public ControlPanel::Delegate, | 209 public ControlPanel::Delegate, |
210 public ViewObserver { | 210 public ViewObserver { |
211 public: | 211 public: |
212 MediaViewer() | 212 MediaViewer() |
213 : navigator_factory_(this), | 213 : navigator_factory_(this), |
214 view_manager_client_factory_(this), | |
215 app_(NULL), | 214 app_(NULL), |
216 view_manager_(NULL), | 215 view_manager_(NULL), |
217 root_view_(NULL), | 216 root_view_(NULL), |
218 control_view_(NULL), | 217 control_view_(NULL), |
219 content_view_(NULL), | 218 content_view_(NULL), |
220 control_panel_(this) { | 219 control_panel_(this) { |
221 handler_map_["image/png"] = "mojo:mojo_png_viewer"; | 220 handler_map_["image/png"] = "mojo:mojo_png_viewer"; |
222 } | 221 } |
223 | 222 |
224 virtual ~MediaViewer() { | 223 virtual ~MediaViewer() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 263 |
265 struct PendingNavigateRequest { | 264 struct PendingNavigateRequest { |
266 uint32_t view_id; | 265 uint32_t view_id; |
267 NavigationDetailsPtr navigation_details; | 266 NavigationDetailsPtr navigation_details; |
268 ResponseDetailsPtr response_details; | 267 ResponseDetailsPtr response_details; |
269 }; | 268 }; |
270 | 269 |
271 | 270 |
272 // Overridden from ApplicationDelegate: | 271 // Overridden from ApplicationDelegate: |
273 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 272 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
| 273 view_manager_client_factory_.reset( |
| 274 new ViewManagerClientFactory(app->shell(), this)); |
274 app_ = app; | 275 app_ = app; |
275 views_init_.reset(new ViewsInit); | 276 views_init_.reset(new ViewsInit); |
276 } | 277 } |
277 | 278 |
278 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 279 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
279 OVERRIDE { | 280 OVERRIDE { |
280 connection->AddService(&navigator_factory_); | 281 connection->AddService(&navigator_factory_); |
281 connection->AddService(&view_manager_client_factory_); | 282 connection->AddService(view_manager_client_factory_.get()); |
282 return true; | 283 return true; |
283 } | 284 } |
284 | 285 |
285 void LayoutViews() { | 286 void LayoutViews() { |
286 View* root = content_view_->parent(); | 287 View* root = content_view_->parent(); |
287 gfx::Rect control_bounds(root->bounds().width(), 28); | 288 gfx::Rect control_bounds(root->bounds().width(), 28); |
288 control_view_->SetBounds(control_bounds); | 289 control_view_->SetBounds(control_bounds); |
289 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), | 290 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
290 root->bounds().height() - control_bounds.height()); | 291 root->bounds().height() - control_bounds.height()); |
291 content_view_->SetBounds(content_bounds); | 292 content_view_->SetBounds(content_bounds); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 root_view_ = NULL; | 355 root_view_ = NULL; |
355 } | 356 } |
356 | 357 |
357 std::string GetHandlerForContentType(const std::string& content_type) { | 358 std::string GetHandlerForContentType(const std::string& content_type) { |
358 HandlerMap::const_iterator it = handler_map_.find(content_type); | 359 HandlerMap::const_iterator it = handler_map_.find(content_type); |
359 return it != handler_map_.end() ? it->second : std::string(); | 360 return it != handler_map_.end() ? it->second : std::string(); |
360 } | 361 } |
361 | 362 |
362 InterfaceFactoryImplWithContext<NavigatorImpl, MediaViewer> | 363 InterfaceFactoryImplWithContext<NavigatorImpl, MediaViewer> |
363 navigator_factory_; | 364 navigator_factory_; |
364 ViewManagerClientFactory view_manager_client_factory_; | 365 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
365 | 366 |
366 ApplicationImpl* app_; | 367 ApplicationImpl* app_; |
367 scoped_ptr<ViewsInit> views_init_; | 368 scoped_ptr<ViewsInit> views_init_; |
368 ViewManager* view_manager_; | 369 ViewManager* view_manager_; |
369 View* root_view_; | 370 View* root_view_; |
370 View* control_view_; | 371 View* control_view_; |
371 View* content_view_; | 372 View* content_view_; |
372 ControlPanel control_panel_; | 373 ControlPanel control_panel_; |
373 ZoomableMediaPtr zoomable_media_; | 374 ZoomableMediaPtr zoomable_media_; |
374 HandlerMap handler_map_; | 375 HandlerMap handler_map_; |
(...skipping 10 matching lines...) Expand all Loading... |
385 response_details.Pass()); | 386 response_details.Pass()); |
386 } | 387 } |
387 | 388 |
388 } // namespace examples | 389 } // namespace examples |
389 } // namespace mojo | 390 } // namespace mojo |
390 | 391 |
391 MojoResult MojoMain(MojoHandle shell_handle) { | 392 MojoResult MojoMain(MojoHandle shell_handle) { |
392 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); | 393 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); |
393 return runner.Run(shell_handle); | 394 return runner.Run(shell_handle); |
394 } | 395 } |
OLD | NEW |