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

Side by Side Diff: components/pdf_viewer/pdf_viewer.cc

Issue 1340983002: Mandoline UI Process: Update namespaces and file names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 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 | « components/mus/window_manager_access_policy.cc ('k') | components/web_view/frame.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "components/mus/public/cpp/types.h" 9 #include "components/mus/public/cpp/types.h"
10 #include "components/mus/public/cpp/view.h" 10 #include "components/mus/public/cpp/view.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 void LostContext(void*) { 52 void LostContext(void*) {
53 DCHECK(false); 53 DCHECK(false);
54 } 54 }
55 55
56 void OnGotContentHandlerID(uint32_t content_handler_id) {} 56 void OnGotContentHandlerID(uint32_t content_handler_id) {}
57 57
58 // BitmapUploader is useful if you want to draw a bitmap or color in a View. 58 // BitmapUploader is useful if you want to draw a bitmap or color in a View.
59 class BitmapUploader : public mojo::SurfaceClient { 59 class BitmapUploader : public mojo::SurfaceClient {
60 public: 60 public:
61 explicit BitmapUploader(mojo::View* view) 61 explicit BitmapUploader(mus::View* view)
62 : view_(view), 62 : view_(view),
63 color_(g_transparent_color), 63 color_(g_transparent_color),
64 width_(0), 64 width_(0),
65 height_(0), 65 height_(0),
66 format_(BGRA), 66 format_(BGRA),
67 next_resource_id_(1u), 67 next_resource_id_(1u),
68 id_namespace_(0u), 68 id_namespace_(0u),
69 local_id_(0u), 69 local_id_(0u),
70 returner_binding_(this) { 70 returner_binding_(this) {}
71 }
72 ~BitmapUploader() override { 71 ~BitmapUploader() override {
73 MojoGLES2DestroyContext(gles2_context_); 72 MojoGLES2DestroyContext(gles2_context_);
74 } 73 }
75 74
76 void Init(mojo::Shell* shell) { 75 void Init(mojo::Shell* shell) {
77 surface_ = view_->RequestSurface(); 76 surface_ = view_->RequestSurface();
78 surface_->BindToThread(); 77 surface_->BindToThread();
79 78
80 mojo::ServiceProviderPtr gpu_service_provider; 79 mojo::ServiceProviderPtr gpu_service_provider;
81 mojo::URLRequestPtr request2(mojo::URLRequest::New()); 80 mojo::URLRequestPtr request2(mojo::URLRequest::New());
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 mojo::ReturnedResourcePtr resource = resources[i].Pass(); 281 mojo::ReturnedResourcePtr resource = resources[i].Pass();
283 DCHECK_EQ(1, resource->count); 282 DCHECK_EQ(1, resource->count);
284 glWaitSyncPointCHROMIUM(resource->sync_point); 283 glWaitSyncPointCHROMIUM(resource->sync_point);
285 uint32_t texture_id = resource_to_texture_id_map_[resource->id]; 284 uint32_t texture_id = resource_to_texture_id_map_[resource->id];
286 DCHECK_NE(0u, texture_id); 285 DCHECK_NE(0u, texture_id);
287 resource_to_texture_id_map_.erase(resource->id); 286 resource_to_texture_id_map_.erase(resource->id);
288 glDeleteTextures(1, &texture_id); 287 glDeleteTextures(1, &texture_id);
289 } 288 }
290 } 289 }
291 290
292 mojo::View* view_; 291 mus::View* view_;
293 mojo::GpuPtr gpu_service_; 292 mojo::GpuPtr gpu_service_;
294 scoped_ptr<mojo::ViewSurface> surface_; 293 scoped_ptr<mus::ViewSurface> surface_;
295 MojoGLES2Context gles2_context_; 294 MojoGLES2Context gles2_context_;
296 295
297 mojo::Size size_; 296 mojo::Size size_;
298 uint32_t color_; 297 uint32_t color_;
299 int width_; 298 int width_;
300 int height_; 299 int height_;
301 Format format_; 300 Format format_;
302 scoped_ptr<std::vector<unsigned char>> bitmap_; 301 scoped_ptr<std::vector<unsigned char>> bitmap_;
303 uint32_t next_resource_id_; 302 uint32_t next_resource_id_;
304 uint32_t id_namespace_; 303 uint32_t id_namespace_;
305 uint32_t local_id_; 304 uint32_t local_id_;
306 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_; 305 base::hash_map<uint32_t, uint32_t> resource_to_texture_id_map_;
307 mojo::Binding<mojo::SurfaceClient> returner_binding_; 306 mojo::Binding<mojo::SurfaceClient> returner_binding_;
308 307
309 DISALLOW_COPY_AND_ASSIGN(BitmapUploader); 308 DISALLOW_COPY_AND_ASSIGN(BitmapUploader);
310 }; 309 };
311 310
312 class EmbedderData { 311 class EmbedderData {
313 public: 312 public:
314 EmbedderData(mojo::Shell* shell, mojo::View* root) : bitmap_uploader_(root) { 313 EmbedderData(mojo::Shell* shell, mus::View* root) : bitmap_uploader_(root) {
315 bitmap_uploader_.Init(shell); 314 bitmap_uploader_.Init(shell);
316 bitmap_uploader_.SetColor(g_background_color); 315 bitmap_uploader_.SetColor(g_background_color);
317 } 316 }
318 317
319 BitmapUploader& bitmap_uploader() { return bitmap_uploader_; } 318 BitmapUploader& bitmap_uploader() { return bitmap_uploader_; }
320 319
321 private: 320 private:
322 BitmapUploader bitmap_uploader_; 321 BitmapUploader bitmap_uploader_;
323 322
324 DISALLOW_COPY_AND_ASSIGN(EmbedderData); 323 DISALLOW_COPY_AND_ASSIGN(EmbedderData);
325 }; 324 };
326 325
327 class PDFView : public mojo::ApplicationDelegate, 326 class PDFView : public mojo::ApplicationDelegate,
328 public mojo::ViewTreeDelegate, 327 public mus::ViewTreeDelegate,
329 public mojo::ViewObserver, 328 public mus::ViewObserver,
330 public mojo::InterfaceFactory<mojo::ViewTreeClient> { 329 public mojo::InterfaceFactory<mojo::ViewTreeClient> {
331 public: 330 public:
332 PDFView(mojo::InterfaceRequest<mojo::Application> request, 331 PDFView(mojo::InterfaceRequest<mojo::Application> request,
333 mojo::URLResponsePtr response) 332 mojo::URLResponsePtr response)
334 : app_(this, request.Pass(), base::Bind(&PDFView::OnTerminate, 333 : app_(this, request.Pass(), base::Bind(&PDFView::OnTerminate,
335 base::Unretained(this))), 334 base::Unretained(this))),
336 current_page_(0), page_count_(0), doc_(nullptr) { 335 current_page_(0), page_count_(0), doc_(nullptr) {
337 FetchPDF(response.Pass()); 336 FetchPDF(response.Pass());
338 } 337 }
339 338
340 ~PDFView() override { 339 ~PDFView() override {
341 if (doc_) 340 if (doc_)
342 FPDF_CloseDocument(doc_); 341 FPDF_CloseDocument(doc_);
343 for (auto& roots : embedder_for_roots_) { 342 for (auto& roots : embedder_for_roots_) {
344 roots.first->RemoveObserver(this); 343 roots.first->RemoveObserver(this);
345 delete roots.second; 344 delete roots.second;
346 } 345 }
347 } 346 }
348 347
349 private: 348 private:
350 // Overridden from ApplicationDelegate: 349 // Overridden from ApplicationDelegate:
351 bool ConfigureIncomingConnection( 350 bool ConfigureIncomingConnection(
352 mojo::ApplicationConnection* connection) override { 351 mojo::ApplicationConnection* connection) override {
353 connection->AddService<mojo::ViewTreeClient>(this); 352 connection->AddService<mojo::ViewTreeClient>(this);
354 return true; 353 return true;
355 } 354 }
356 355
357 // Overridden from ViewTreeDelegate: 356 // Overridden from ViewTreeDelegate:
358 void OnEmbed(mojo::View* root) override { 357 void OnEmbed(mus::View* root) override {
359 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end()); 358 DCHECK(embedder_for_roots_.find(root) == embedder_for_roots_.end());
360 root->AddObserver(this); 359 root->AddObserver(this);
361 EmbedderData* embedder_data = new EmbedderData(app_.shell(), root); 360 EmbedderData* embedder_data = new EmbedderData(app_.shell(), root);
362 embedder_for_roots_[root] = embedder_data; 361 embedder_for_roots_[root] = embedder_data;
363 DrawBitmap(embedder_data); 362 DrawBitmap(embedder_data);
364 } 363 }
365 364
366 void OnConnectionLost(mojo::ViewTreeConnection* connection) override {} 365 void OnConnectionLost(mus::ViewTreeConnection* connection) override {}
367 366
368 // Overridden from ViewObserver: 367 // Overridden from ViewObserver:
369 void OnViewBoundsChanged(mojo::View* view, 368 void OnViewBoundsChanged(mus::View* view,
370 const mojo::Rect& old_bounds, 369 const mojo::Rect& old_bounds,
371 const mojo::Rect& new_bounds) override { 370 const mojo::Rect& new_bounds) override {
372 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 371 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
373 DrawBitmap(embedder_for_roots_[view]); 372 DrawBitmap(embedder_for_roots_[view]);
374 } 373 }
375 374
376 void OnViewInputEvent(mojo::View* view, 375 void OnViewInputEvent(mus::View* view, const mojo::EventPtr& event) override {
377 const mojo::EventPtr& event) override {
378 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 376 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
379 if (event->key_data && 377 if (event->key_data &&
380 (event->action != mojo::EVENT_TYPE_KEY_PRESSED || 378 (event->action != mojo::EVENT_TYPE_KEY_PRESSED ||
381 event->key_data->is_char)) { 379 event->key_data->is_char)) {
382 return; 380 return;
383 } 381 }
384 382
385 // TODO(rjkroege): Make panning and scrolling more performant and 383 // TODO(rjkroege): Make panning and scrolling more performant and
386 // responsive to gesture events. 384 // responsive to gesture events.
387 if ((event->key_data && 385 if ((event->key_data &&
388 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_DOWN) || 386 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_DOWN) ||
389 (event->wheel_data && event->wheel_data && 387 (event->wheel_data && event->wheel_data &&
390 event->wheel_data->delta_y < 0)) { 388 event->wheel_data->delta_y < 0)) {
391 if (current_page_ < (page_count_ - 1)) { 389 if (current_page_ < (page_count_ - 1)) {
392 current_page_++; 390 current_page_++;
393 DrawBitmap(embedder_for_roots_[view]); 391 DrawBitmap(embedder_for_roots_[view]);
394 } 392 }
395 } else if ((event->key_data && 393 } else if ((event->key_data &&
396 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_UP) || 394 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_UP) ||
397 (event->pointer_data && event->wheel_data && 395 (event->pointer_data && event->wheel_data &&
398 event->wheel_data->delta_y > 0)) { 396 event->wheel_data->delta_y > 0)) {
399 if (current_page_ > 0) { 397 if (current_page_ > 0) {
400 current_page_--; 398 current_page_--;
401 DrawBitmap(embedder_for_roots_[view]); 399 DrawBitmap(embedder_for_roots_[view]);
402 } 400 }
403 } 401 }
404 } 402 }
405 403
406 void OnViewDestroyed(mojo::View* view) override { 404 void OnViewDestroyed(mus::View* view) override {
407 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 405 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
408 const auto& it = embedder_for_roots_.find(view); 406 const auto& it = embedder_for_roots_.find(view);
409 DCHECK(it != embedder_for_roots_.end()); 407 DCHECK(it != embedder_for_roots_.end());
410 delete it->second; 408 delete it->second;
411 embedder_for_roots_.erase(it); 409 embedder_for_roots_.erase(it);
412 if (embedder_for_roots_.size() == 0) 410 if (embedder_for_roots_.size() == 0)
413 app_.Quit(); 411 app_.Quit();
414 } 412 }
415 413
416 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: 414 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>:
417 void Create( 415 void Create(
418 mojo::ApplicationConnection* connection, 416 mojo::ApplicationConnection* connection,
419 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { 417 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override {
420 mojo::ViewTreeConnection::Create(this, request.Pass()); 418 mus::ViewTreeConnection::Create(this, request.Pass());
421 } 419 }
422 420
423 void DrawBitmap(EmbedderData* embedder_data) { 421 void DrawBitmap(EmbedderData* embedder_data) {
424 if (!doc_) 422 if (!doc_)
425 return; 423 return;
426 424
427 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_); 425 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_);
428 int width = static_cast<int>(FPDF_GetPageWidth(page)); 426 int width = static_cast<int>(FPDF_GetPageWidth(page));
429 int height = static_cast<int>(FPDF_GetPageHeight(page)); 427 int height = static_cast<int>(FPDF_GetPageHeight(page));
430 428
(...skipping 28 matching lines...) Expand all
459 // when we quit (the messageloop is shared among multiple PDFViews). 457 // when we quit (the messageloop is shared among multiple PDFViews).
460 void OnTerminate() { 458 void OnTerminate() {
461 delete this; 459 delete this;
462 } 460 }
463 461
464 mojo::ApplicationImpl app_; 462 mojo::ApplicationImpl app_;
465 std::string data_; 463 std::string data_;
466 int current_page_; 464 int current_page_;
467 int page_count_; 465 int page_count_;
468 FPDF_DOCUMENT doc_; 466 FPDF_DOCUMENT doc_;
469 std::map<mojo::View*, EmbedderData*> embedder_for_roots_; 467 std::map<mus::View*, EmbedderData*> embedder_for_roots_;
470 468
471 DISALLOW_COPY_AND_ASSIGN(PDFView); 469 DISALLOW_COPY_AND_ASSIGN(PDFView);
472 }; 470 };
473 471
474 class ContentHandlerImpl : public mojo::ContentHandler { 472 class ContentHandlerImpl : public mojo::ContentHandler {
475 public: 473 public:
476 ContentHandlerImpl(mojo::InterfaceRequest<ContentHandler> request) 474 ContentHandlerImpl(mojo::InterfaceRequest<ContentHandler> request)
477 : binding_(this, request.Pass()) {} 475 : binding_(this, request.Pass()) {}
478 ~ContentHandlerImpl() override {} 476 ~ContentHandlerImpl() override {}
479 477
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 DISALLOW_COPY_AND_ASSIGN(PDFViewer); 516 DISALLOW_COPY_AND_ASSIGN(PDFViewer);
519 }; 517 };
520 518
521 } // namespace 519 } // namespace
522 } // namespace pdf_viewer 520 } // namespace pdf_viewer
523 521
524 MojoResult MojoMain(MojoHandle application_request) { 522 MojoResult MojoMain(MojoHandle application_request) {
525 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); 523 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer());
526 return runner.Run(application_request); 524 return runner.Run(application_request);
527 } 525 }
OLDNEW
« no previous file with comments | « components/mus/window_manager_access_policy.cc ('k') | components/web_view/frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698