| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 class MediaViewer | 192 class MediaViewer |
| 193 : public ApplicationDelegate, | 193 : public ApplicationDelegate, |
| 194 public ViewManagerDelegate, | 194 public ViewManagerDelegate, |
| 195 public ControlPanel::Delegate, | 195 public ControlPanel::Delegate, |
| 196 public ViewObserver { | 196 public ViewObserver { |
| 197 public: | 197 public: |
| 198 MediaViewer() | 198 MediaViewer() |
| 199 : shell_(nullptr), | 199 : shell_(nullptr), |
| 200 app_(NULL), | 200 app_(NULL), |
| 201 view_manager_(NULL), | |
| 202 root_view_(NULL), | 201 root_view_(NULL), |
| 203 control_view_(NULL), | 202 control_view_(NULL), |
| 204 content_view_(NULL), | 203 content_view_(NULL), |
| 205 control_panel_(this) { | 204 control_panel_(this) { |
| 206 handler_map_["image/png"] = "mojo:png_viewer"; | 205 handler_map_["image/png"] = "mojo:png_viewer"; |
| 207 } | 206 } |
| 208 | 207 |
| 209 virtual ~MediaViewer() { | 208 virtual ~MediaViewer() { |
| 210 if (root_view_) | 209 if (root_view_) |
| 211 root_view_->RemoveObserver(this); | 210 root_view_->RemoveObserver(this); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 237 control_bounds.height = 28; | 236 control_bounds.height = 28; |
| 238 control_view_->SetBounds(control_bounds); | 237 control_view_->SetBounds(control_bounds); |
| 239 Rect content_bounds; | 238 Rect content_bounds; |
| 240 content_bounds.y = control_bounds.height; | 239 content_bounds.y = control_bounds.height; |
| 241 content_bounds.width = root->bounds().width; | 240 content_bounds.width = root->bounds().width; |
| 242 content_bounds.height = root->bounds().height - control_bounds.height; | 241 content_bounds.height = root->bounds().height - control_bounds.height; |
| 243 content_view_->SetBounds(content_bounds); | 242 content_view_->SetBounds(content_bounds); |
| 244 } | 243 } |
| 245 | 244 |
| 246 // Overridden from ViewManagerDelegate: | 245 // Overridden from ViewManagerDelegate: |
| 247 virtual void OnEmbed(ViewManager* view_manager, | 246 virtual void OnEmbed(View* root, |
| 248 View* root, | |
| 249 ServiceProviderImpl* exported_services, | 247 ServiceProviderImpl* exported_services, |
| 250 scoped_ptr<ServiceProvider> imported_services) override { | 248 scoped_ptr<ServiceProvider> imported_services) override { |
| 251 root_view_ = root; | 249 root_view_ = root; |
| 252 view_manager_ = view_manager; | |
| 253 | 250 |
| 254 control_view_ = View::Create(view_manager_); | 251 control_view_ = View::Create(root->view_manager()); |
| 255 control_view_->SetVisible(true); | 252 control_view_->SetVisible(true); |
| 256 root_view_->AddChild(control_view_); | 253 root_view_->AddChild(control_view_); |
| 257 | 254 |
| 258 content_view_ = View::Create(view_manager_); | 255 content_view_ = View::Create(root->view_manager()); |
| 259 content_view_->SetVisible(true); | 256 content_view_->SetVisible(true); |
| 260 root_view_->AddChild(content_view_); | 257 root_view_->AddChild(content_view_); |
| 261 | 258 |
| 262 control_panel_.Initialize(control_view_, shell_); | 259 control_panel_.Initialize(control_view_, shell_); |
| 263 | 260 |
| 264 LayoutViews(); | 261 LayoutViews(); |
| 265 root_view_->AddObserver(this); | 262 root_view_->AddObserver(this); |
| 266 | 263 |
| 267 content_view_->Embed("TODO"); | 264 content_view_->Embed("TODO"); |
| 268 } | 265 } |
| 269 | 266 |
| 270 virtual void OnViewManagerDisconnected( | 267 virtual void OnViewManagerDisconnected( |
| 271 ViewManager* view_manager) override { | 268 ViewManager* view_manager) override { |
| 272 DCHECK_EQ(view_manager_, view_manager); | |
| 273 view_manager_ = NULL; | |
| 274 base::MessageLoop::current()->Quit(); | 269 base::MessageLoop::current()->Quit(); |
| 275 } | 270 } |
| 276 | 271 |
| 277 // Overridden from ControlPanel::Delegate: | 272 // Overridden from ControlPanel::Delegate: |
| 278 virtual void ButtonPressed(ControlPanel::ControlType type) override { | 273 virtual void ButtonPressed(ControlPanel::ControlType type) override { |
| 279 switch (type) { | 274 switch (type) { |
| 280 case ControlPanel::CONTROL_ZOOM_IN: | 275 case ControlPanel::CONTROL_ZOOM_IN: |
| 281 zoomable_media_->ZoomIn(); | 276 zoomable_media_->ZoomIn(); |
| 282 break; | 277 break; |
| 283 case ControlPanel::CONTROL_ACTUAL_SIZE: | 278 case ControlPanel::CONTROL_ACTUAL_SIZE: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 307 HandlerMap::const_iterator it = handler_map_.find(content_type); | 302 HandlerMap::const_iterator it = handler_map_.find(content_type); |
| 308 return it != handler_map_.end() ? it->second : std::string(); | 303 return it != handler_map_.end() ? it->second : std::string(); |
| 309 } | 304 } |
| 310 | 305 |
| 311 Shell* shell_; | 306 Shell* shell_; |
| 312 | 307 |
| 313 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 308 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
| 314 | 309 |
| 315 ApplicationImpl* app_; | 310 ApplicationImpl* app_; |
| 316 scoped_ptr<ViewsInit> views_init_; | 311 scoped_ptr<ViewsInit> views_init_; |
| 317 ViewManager* view_manager_; | |
| 318 View* root_view_; | 312 View* root_view_; |
| 319 View* control_view_; | 313 View* control_view_; |
| 320 View* content_view_; | 314 View* content_view_; |
| 321 ControlPanel control_panel_; | 315 ControlPanel control_panel_; |
| 322 ZoomableMediaPtr zoomable_media_; | 316 ZoomableMediaPtr zoomable_media_; |
| 323 HandlerMap handler_map_; | 317 HandlerMap handler_map_; |
| 324 | 318 |
| 325 DISALLOW_COPY_AND_ASSIGN(MediaViewer); | 319 DISALLOW_COPY_AND_ASSIGN(MediaViewer); |
| 326 }; | 320 }; |
| 327 | 321 |
| 328 } // namespace examples | 322 } // namespace examples |
| 329 } // namespace mojo | 323 } // namespace mojo |
| 330 | 324 |
| 331 MojoResult MojoMain(MojoHandle shell_handle) { | 325 MojoResult MojoMain(MojoHandle shell_handle) { |
| 332 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); | 326 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); |
| 333 return runner.Run(shell_handle); | 327 return runner.Run(shell_handle); |
| 334 } | 328 } |
| OLD | NEW |