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

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: Updated all the namespaces in mus 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
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 if ((event->key_data && 383 if ((event->key_data &&
386 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_DOWN) || 384 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_DOWN) ||
387 (event->pointer_data && event->pointer_data->vertical_wheel < 0)) { 385 (event->pointer_data && event->pointer_data->vertical_wheel < 0)) {
388 if (current_page_ < (page_count_ - 1)) { 386 if (current_page_ < (page_count_ - 1)) {
389 current_page_++; 387 current_page_++;
390 DrawBitmap(embedder_for_roots_[view]); 388 DrawBitmap(embedder_for_roots_[view]);
391 } 389 }
392 } else if ((event->key_data && 390 } else if ((event->key_data &&
393 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_UP) || 391 event->key_data->windows_key_code == mojo::KEYBOARD_CODE_UP) ||
394 (event->pointer_data && 392 (event->pointer_data &&
395 event->pointer_data->vertical_wheel > 0)) { 393 event->pointer_data->vertical_wheel > 0)) {
396 if (current_page_ > 0) { 394 if (current_page_ > 0) {
397 current_page_--; 395 current_page_--;
398 DrawBitmap(embedder_for_roots_[view]); 396 DrawBitmap(embedder_for_roots_[view]);
399 } 397 }
400 } 398 }
401 } 399 }
402 400
403 void OnViewDestroyed(mojo::View* view) override { 401 void OnViewDestroyed(mus::View* view) override {
404 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end()); 402 DCHECK(embedder_for_roots_.find(view) != embedder_for_roots_.end());
405 const auto& it = embedder_for_roots_.find(view); 403 const auto& it = embedder_for_roots_.find(view);
406 DCHECK(it != embedder_for_roots_.end()); 404 DCHECK(it != embedder_for_roots_.end());
407 delete it->second; 405 delete it->second;
408 embedder_for_roots_.erase(it); 406 embedder_for_roots_.erase(it);
409 if (embedder_for_roots_.size() == 0) 407 if (embedder_for_roots_.size() == 0)
410 app_.Quit(); 408 app_.Quit();
411 } 409 }
412 410
413 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: 411 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>:
414 void Create( 412 void Create(
415 mojo::ApplicationConnection* connection, 413 mojo::ApplicationConnection* connection,
416 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { 414 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override {
417 mojo::ViewTreeConnection::Create(this, request.Pass()); 415 mus::ViewTreeConnection::Create(this, request.Pass());
418 } 416 }
419 417
420 void DrawBitmap(EmbedderData* embedder_data) { 418 void DrawBitmap(EmbedderData* embedder_data) {
421 if (!doc_) 419 if (!doc_)
422 return; 420 return;
423 421
424 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_); 422 FPDF_PAGE page = FPDF_LoadPage(doc_, current_page_);
425 int width = static_cast<int>(FPDF_GetPageWidth(page)); 423 int width = static_cast<int>(FPDF_GetPageWidth(page));
426 int height = static_cast<int>(FPDF_GetPageHeight(page)); 424 int height = static_cast<int>(FPDF_GetPageHeight(page));
427 425
(...skipping 28 matching lines...) Expand all
456 // when we quit (the messageloop is shared among multiple PDFViews). 454 // when we quit (the messageloop is shared among multiple PDFViews).
457 void OnTerminate() { 455 void OnTerminate() {
458 delete this; 456 delete this;
459 } 457 }
460 458
461 mojo::ApplicationImpl app_; 459 mojo::ApplicationImpl app_;
462 std::string data_; 460 std::string data_;
463 int current_page_; 461 int current_page_;
464 int page_count_; 462 int page_count_;
465 FPDF_DOCUMENT doc_; 463 FPDF_DOCUMENT doc_;
466 std::map<mojo::View*, EmbedderData*> embedder_for_roots_; 464 std::map<mus::View*, EmbedderData*> embedder_for_roots_;
467 465
468 DISALLOW_COPY_AND_ASSIGN(PDFView); 466 DISALLOW_COPY_AND_ASSIGN(PDFView);
469 }; 467 };
470 468
471 class ContentHandlerImpl : public mojo::ContentHandler { 469 class ContentHandlerImpl : public mojo::ContentHandler {
472 public: 470 public:
473 ContentHandlerImpl(mojo::InterfaceRequest<ContentHandler> request) 471 ContentHandlerImpl(mojo::InterfaceRequest<ContentHandler> request)
474 : binding_(this, request.Pass()) {} 472 : binding_(this, request.Pass()) {}
475 ~ContentHandlerImpl() override {} 473 ~ContentHandlerImpl() override {}
476 474
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 DISALLOW_COPY_AND_ASSIGN(PDFViewer); 513 DISALLOW_COPY_AND_ASSIGN(PDFViewer);
516 }; 514 };
517 515
518 } // namespace 516 } // namespace
519 } // namespace pdf_viewer 517 } // namespace pdf_viewer
520 518
521 MojoResult MojoMain(MojoHandle application_request) { 519 MojoResult MojoMain(MojoHandle application_request) {
522 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer()); 520 mojo::ApplicationRunner runner(new pdf_viewer::PDFViewer());
523 return runner.Run(application_request); 521 return runner.Run(application_request);
524 } 522 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698