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

Side by Side Diff: examples/pdf_viewer/pdf_viewer.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/nesting_app/nesting_app.cc ('k') | examples/png_viewer/png_viewer.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 "base/strings/string_tokenizer.h" 5 #include "base/strings/string_tokenizer.h"
6 #include "examples/bitmap_uploader/bitmap_uploader.h" 6 #include "examples/bitmap_uploader/bitmap_uploader.h"
7 #include "mojo/application/application_runner_chromium.h" 7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/application/content_handler_factory.h" 8 #include "mojo/application/content_handler_factory.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 class PDFView : public ApplicationDelegate, 52 class PDFView : public ApplicationDelegate,
53 public ViewManagerDelegate, 53 public ViewManagerDelegate,
54 public ViewObserver { 54 public ViewObserver {
55 public: 55 public:
56 PDFView(URLResponsePtr response) 56 PDFView(URLResponsePtr response)
57 : current_page_(0), page_count_(0), doc_(NULL), app_(nullptr) { 57 : current_page_(0), page_count_(0), doc_(NULL), app_(nullptr) {
58 FetchPDF(response.Pass()); 58 FetchPDF(response.Pass());
59 } 59 }
60 60
61 virtual ~PDFView() { 61 ~PDFView() override {
62 if (doc_) 62 if (doc_)
63 FPDF_CloseDocument(doc_); 63 FPDF_CloseDocument(doc_);
64 for (auto& roots : embedder_for_roots_) { 64 for (auto& roots : embedder_for_roots_) {
65 roots.first->RemoveObserver(this); 65 roots.first->RemoveObserver(this);
66 delete roots.second; 66 delete roots.second;
67 } 67 }
68 } 68 }
69 69
70 private: 70 private:
71 // Overridden from ApplicationDelegate: 71 // Overridden from ApplicationDelegate:
72 virtual void Initialize(ApplicationImpl* app) override { 72 void Initialize(ApplicationImpl* app) override {
73 app_ = app; 73 app_ = app;
74 view_manager_client_factory_.reset( 74 view_manager_client_factory_.reset(
75 new ViewManagerClientFactory(app->shell(), this)); 75 new ViewManagerClientFactory(app->shell(), this));
76 } 76 }
77 77
78 virtual bool ConfigureIncomingConnection( 78 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
79 ApplicationConnection* connection) override {
80 connection->AddService(view_manager_client_factory_.get()); 79 connection->AddService(view_manager_client_factory_.get());
81 return true; 80 return true;
82 } 81 }
83 82
84 // Overridden from ViewManagerDelegate: 83 // Overridden from ViewManagerDelegate:
85 virtual void OnEmbed(View* root, 84 void OnEmbed(View* root,
86 InterfaceRequest<ServiceProvider> services, 85 InterfaceRequest<ServiceProvider> services,
87 ServiceProviderPtr exposed_services) override { 86 ServiceProviderPtr exposed_services) override {
88 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); 87 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end());
89 root->AddObserver(this); 88 root->AddObserver(this);
90 EmbedderData* embedder_data = new EmbedderData(app_->shell(), root); 89 EmbedderData* embedder_data = new EmbedderData(app_->shell(), root);
91 embedder_for_roots_[root] = embedder_data; 90 embedder_for_roots_[root] = embedder_data;
92 DrawBitmap(embedder_data); 91 DrawBitmap(embedder_data);
93 } 92 }
94 93
95 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {} 94 void OnViewManagerDisconnected(ViewManager* view_manager) override {}
96 95
97 // Overridden from ViewObserver: 96 // Overridden from ViewObserver:
98 virtual void OnViewBoundsChanged(View* view, 97 void OnViewBoundsChanged(View* view,
99 const Rect& old_bounds, 98 const Rect& old_bounds,
100 const Rect& new_bounds) override { 99 const Rect& new_bounds) override {
101 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 100 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
102 DrawBitmap(embedder_for_roots_[view]); 101 DrawBitmap(embedder_for_roots_[view]);
103 } 102 }
104 103
105 virtual void OnViewInputEvent(View* view, const EventPtr& event) override { 104 void OnViewInputEvent(View* view, const EventPtr& event) override {
106 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 105 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
107 if (event->key_data && 106 if (event->key_data &&
108 (event->action != EVENT_TYPE_KEY_PRESSED || event->key_data->is_char)) { 107 (event->action != EVENT_TYPE_KEY_PRESSED || event->key_data->is_char)) {
109 return; 108 return;
110 } 109 }
111 if ((event->key_data && 110 if ((event->key_data &&
112 event->key_data->windows_key_code == KEYBOARD_CODE_DOWN) || 111 event->key_data->windows_key_code == KEYBOARD_CODE_DOWN) ||
113 (event->wheel_data && event->wheel_data->y_offset < 0)) { 112 (event->wheel_data && event->wheel_data->y_offset < 0)) {
114 if (current_page_ < (page_count_ - 1)) { 113 if (current_page_ < (page_count_ - 1)) {
115 current_page_++; 114 current_page_++;
116 DrawBitmap(embedder_for_roots_[view]); 115 DrawBitmap(embedder_for_roots_[view]);
117 } 116 }
118 } else if ((event->key_data && 117 } else if ((event->key_data &&
119 event->key_data->windows_key_code == KEYBOARD_CODE_UP) || 118 event->key_data->windows_key_code == KEYBOARD_CODE_UP) ||
120 (event->wheel_data && event->wheel_data->y_offset > 0)) { 119 (event->wheel_data && event->wheel_data->y_offset > 0)) {
121 if (current_page_ > 0) { 120 if (current_page_ > 0) {
122 current_page_--; 121 current_page_--;
123 DrawBitmap(embedder_for_roots_[view]); 122 DrawBitmap(embedder_for_roots_[view]);
124 } 123 }
125 } 124 }
126 } 125 }
127 126
128 virtual void OnViewDestroyed(View* view) override { 127 void OnViewDestroyed(View* view) override {
129 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 128 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
130 const auto& it = embedder_for_roots_.find(view); 129 const auto& it = embedder_for_roots_.find(view);
131 DCHECK(it != embedder_for_roots_.end()); 130 DCHECK(it != embedder_for_roots_.end());
132 delete it->second; 131 delete it->second;
133 embedder_for_roots_.erase(it); 132 embedder_for_roots_.erase(it);
134 if (embedder_for_roots_.size() == 0) 133 if (embedder_for_roots_.size() == 0)
135 ApplicationImpl::Terminate(); 134 ApplicationImpl::Terminate();
136 } 135 }
137 136
138 void DrawBitmap(EmbedderData* embedder_data) { 137 void DrawBitmap(EmbedderData* embedder_data) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }; 210 };
212 211
213 class PDFViewer : public ApplicationDelegate, 212 class PDFViewer : public ApplicationDelegate,
214 public ContentHandlerFactory::ManagedDelegate { 213 public ContentHandlerFactory::ManagedDelegate {
215 public: 214 public:
216 PDFViewer() : content_handler_factory_(this) { 215 PDFViewer() : content_handler_factory_(this) {
217 v8::V8::InitializeICU(); 216 v8::V8::InitializeICU();
218 FPDF_InitLibrary(); 217 FPDF_InitLibrary();
219 } 218 }
220 219
221 virtual ~PDFViewer() { FPDF_DestroyLibrary(); } 220 ~PDFViewer() override { FPDF_DestroyLibrary(); }
222 221
223 private: 222 private:
224 // Overridden from ApplicationDelegate: 223 // Overridden from ApplicationDelegate:
225 virtual bool ConfigureIncomingConnection( 224 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
226 ApplicationConnection* connection) override {
227 connection->AddService(&content_handler_factory_); 225 connection->AddService(&content_handler_factory_);
228 return true; 226 return true;
229 } 227 }
230 228
231 // Overridden from ContentHandlerFactory::ManagedDelegate: 229 // Overridden from ContentHandlerFactory::ManagedDelegate:
232 virtual scoped_ptr<ContentHandlerFactory::HandledApplicationHolder> 230 scoped_ptr<ContentHandlerFactory::HandledApplicationHolder>
233 CreateApplication(InterfaceRequest<Application> application_request, 231 CreateApplication(InterfaceRequest<Application> application_request,
234 URLResponsePtr response) override { 232 URLResponsePtr response) override {
235 return make_handled_factory_holder(new mojo::ApplicationImpl( 233 return make_handled_factory_holder(new mojo::ApplicationImpl(
236 new PDFView(response.Pass()), application_request.Pass())); 234 new PDFView(response.Pass()), application_request.Pass()));
237 } 235 }
238 236
239 ContentHandlerFactory content_handler_factory_; 237 ContentHandlerFactory content_handler_factory_;
240 238
241 DISALLOW_COPY_AND_ASSIGN(PDFViewer); 239 DISALLOW_COPY_AND_ASSIGN(PDFViewer);
242 }; 240 };
243 241
244 } // namespace examples 242 } // namespace examples
245 } // namespace mojo 243 } // namespace mojo
246 244
247 MojoResult MojoMain(MojoHandle shell_handle) { 245 MojoResult MojoMain(MojoHandle shell_handle) {
248 mojo::ApplicationRunnerChromium runner(new mojo::examples::PDFViewer()); 246 mojo::ApplicationRunnerChromium runner(new mojo::examples::PDFViewer());
249 return runner.Run(shell_handle); 247 return runner.Run(shell_handle);
250 } 248 }
OLDNEW
« no previous file with comments | « examples/nesting_app/nesting_app.cc ('k') | examples/png_viewer/png_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698