| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 public ViewObserver { | 55 public ViewObserver { |
| 56 public: | 56 public: |
| 57 PNGView(URLResponsePtr response) | 57 PNGView(URLResponsePtr response) |
| 58 : width_(0), | 58 : width_(0), |
| 59 height_(0), | 59 height_(0), |
| 60 app_(nullptr), | 60 app_(nullptr), |
| 61 zoom_percentage_(kDefaultZoomPercentage) { | 61 zoom_percentage_(kDefaultZoomPercentage) { |
| 62 DecodePNG(response.Pass()); | 62 DecodePNG(response.Pass()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual ~PNGView() { | 65 ~PNGView() override { |
| 66 for (auto& roots : embedder_for_roots_) { | 66 for (auto& roots : embedder_for_roots_) { |
| 67 roots.first->RemoveObserver(this); | 67 roots.first->RemoveObserver(this); |
| 68 delete roots.second; | 68 delete roots.second; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 static const uint16_t kMaxZoomPercentage = 400; | 73 static const uint16_t kMaxZoomPercentage = 400; |
| 74 static const uint16_t kMinZoomPercentage = 20; | 74 static const uint16_t kMinZoomPercentage = 20; |
| 75 static const uint16_t kDefaultZoomPercentage = 100; | 75 static const uint16_t kDefaultZoomPercentage = 100; |
| 76 static const uint16_t kZoomStep = 20; | 76 static const uint16_t kZoomStep = 20; |
| 77 | 77 |
| 78 // Overridden from ApplicationDelegate: | 78 // Overridden from ApplicationDelegate: |
| 79 virtual void Initialize(ApplicationImpl* app) override { | 79 void Initialize(ApplicationImpl* app) override { |
| 80 app_ = app; | 80 app_ = app; |
| 81 view_manager_client_factory_.reset( | 81 view_manager_client_factory_.reset( |
| 82 new ViewManagerClientFactory(app->shell(), this)); | 82 new ViewManagerClientFactory(app->shell(), this)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Overridden from ApplicationDelegate: | 85 // Overridden from ApplicationDelegate: |
| 86 virtual bool ConfigureIncomingConnection( | 86 bool ConfigureIncomingConnection( |
| 87 ApplicationConnection* connection) override { | 87 ApplicationConnection* connection) override { |
| 88 connection->AddService(view_manager_client_factory_.get()); | 88 connection->AddService(view_manager_client_factory_.get()); |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Overridden from ViewManagerDelegate: | 92 // Overridden from ViewManagerDelegate: |
| 93 virtual void OnEmbed(View* root, | 93 void OnEmbed(View* root, |
| 94 InterfaceRequest<ServiceProvider> services, | 94 InterfaceRequest<ServiceProvider> services, |
| 95 ServiceProviderPtr exposed_services) override { | 95 ServiceProviderPtr exposed_services) override { |
| 96 // TODO(qsr): The same view should be embeddable on multiple views. | 96 // TODO(qsr): The same view should be embeddable on multiple views. |
| 97 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); | 97 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); |
| 98 root->AddObserver(this); | 98 root->AddObserver(this); |
| 99 EmbedderData* embedder_data = new EmbedderData(app_->shell(), root); | 99 EmbedderData* embedder_data = new EmbedderData(app_->shell(), root); |
| 100 embedder_for_roots_[root] = embedder_data; | 100 embedder_for_roots_[root] = embedder_data; |
| 101 embedder_data->bitmap_uploader().SetBitmap( | 101 embedder_data->bitmap_uploader().SetBitmap( |
| 102 width_, height_, | 102 width_, height_, |
| 103 make_scoped_ptr(new std::vector<unsigned char>(*bitmap_)), | 103 make_scoped_ptr(new std::vector<unsigned char>(*bitmap_)), |
| 104 BitmapUploader::BGRA); | 104 BitmapUploader::BGRA); |
| 105 } | 105 } |
| 106 | 106 |
| 107 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { | 107 void OnViewManagerDisconnected(ViewManager* view_manager) override { |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Overridden from ViewObserver: | 110 // Overridden from ViewObserver: |
| 111 virtual void OnViewBoundsChanged(View* view, | 111 void OnViewBoundsChanged(View* view, |
| 112 const Rect& old_bounds, | 112 const Rect& old_bounds, |
| 113 const Rect& new_bounds) override { | 113 const Rect& new_bounds) override { |
| 114 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); | 114 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 virtual void OnViewDestroyed(View* view) override { | 117 void OnViewDestroyed(View* view) override { |
| 118 // TODO(aa): Need to figure out how shutdown works. | 118 // TODO(aa): Need to figure out how shutdown works. |
| 119 const auto& it = embedder_for_roots_.find(view); | 119 const auto& it = embedder_for_roots_.find(view); |
| 120 DCHECK(it != embedder_for_roots_.end()); | 120 DCHECK(it != embedder_for_roots_.end()); |
| 121 delete it->second; | 121 delete it->second; |
| 122 embedder_for_roots_.erase(it); | 122 embedder_for_roots_.erase(it); |
| 123 if (embedder_for_roots_.size() == 0) | 123 if (embedder_for_roots_.size() == 0) |
| 124 ApplicationImpl::Terminate(); | 124 ApplicationImpl::Terminate(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void ZoomIn() { | 127 void ZoomIn() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 DISALLOW_COPY_AND_ASSIGN(PNGView); | 195 DISALLOW_COPY_AND_ASSIGN(PNGView); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 class PNGViewer : public ApplicationDelegate, | 198 class PNGViewer : public ApplicationDelegate, |
| 199 public ContentHandlerFactory::ManagedDelegate { | 199 public ContentHandlerFactory::ManagedDelegate { |
| 200 public: | 200 public: |
| 201 PNGViewer() : content_handler_factory_(this) {} | 201 PNGViewer() : content_handler_factory_(this) {} |
| 202 | 202 |
| 203 private: | 203 private: |
| 204 // Overridden from ApplicationDelegate: | 204 // Overridden from ApplicationDelegate: |
| 205 virtual bool ConfigureIncomingConnection( | 205 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| 206 ApplicationConnection* connection) override { | |
| 207 connection->AddService(&content_handler_factory_); | 206 connection->AddService(&content_handler_factory_); |
| 208 return true; | 207 return true; |
| 209 } | 208 } |
| 210 | 209 |
| 211 // Overridden from ContentHandlerFactory::ManagedDelegate: | 210 // Overridden from ContentHandlerFactory::ManagedDelegate: |
| 212 virtual scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> | 211 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> |
| 213 CreateApplication(InterfaceRequest<Application> application_request, | 212 CreateApplication(InterfaceRequest<Application> application_request, |
| 214 URLResponsePtr response) override { | 213 URLResponsePtr response) override { |
| 215 return make_handled_factory_holder(new mojo::ApplicationImpl( | 214 return make_handled_factory_holder(new mojo::ApplicationImpl( |
| 216 new PNGView(response.Pass()), application_request.Pass())); | 215 new PNGView(response.Pass()), application_request.Pass())); |
| 217 } | 216 } |
| 218 | 217 |
| 219 ContentHandlerFactory content_handler_factory_; | 218 ContentHandlerFactory content_handler_factory_; |
| 220 | 219 |
| 221 DISALLOW_COPY_AND_ASSIGN(PNGViewer); | 220 DISALLOW_COPY_AND_ASSIGN(PNGViewer); |
| 222 }; | 221 }; |
| 223 | 222 |
| 224 } // namespace examples | 223 } // namespace examples |
| 225 } // namespace mojo | 224 } // namespace mojo |
| 226 | 225 |
| 227 MojoResult MojoMain(MojoHandle shell_handle) { | 226 MojoResult MojoMain(MojoHandle shell_handle) { |
| 228 mojo::ApplicationRunnerChromium runner(new mojo::examples::PNGViewer()); | 227 mojo::ApplicationRunnerChromium runner(new mojo::examples::PNGViewer()); |
| 229 return runner.Run(shell_handle); | 228 return runner.Run(shell_handle); |
| 230 } | 229 } |
| OLD | NEW |