OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "pdf/out_of_process_instance.h" | 5 #include "pdf/out_of_process_instance.h" |
6 | 6 |
7 #include <algorithm> // for min/max() | 7 #include <algorithm> // for min/max() |
8 #define _USE_MATH_DEFINES // for M_PI | 8 #define _USE_MATH_DEFINES // for M_PI |
9 #include <cmath> // for log() and pow() | 9 #include <cmath> // for log() and pow() |
10 #include <math.h> | 10 #include <math.h> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 const char kChromePrint[] = "chrome://print/"; | 46 const char kChromePrint[] = "chrome://print/"; |
47 const char kChromeExtension[] = | 47 const char kChromeExtension[] = |
48 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; | 48 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai"; |
49 | 49 |
50 // Dictionary Value key names for the document accessibility info | 50 // Dictionary Value key names for the document accessibility info |
51 const char kAccessibleNumberOfPages[] = "numberOfPages"; | 51 const char kAccessibleNumberOfPages[] = "numberOfPages"; |
52 const char kAccessibleLoaded[] = "loaded"; | 52 const char kAccessibleLoaded[] = "loaded"; |
53 const char kAccessibleCopyable[] = "copyable"; | 53 const char kAccessibleCopyable[] = "copyable"; |
54 | 54 |
| 55 // PDF background colors |
| 56 const uint32 kBackgroundColor = 0xFFCCCCCC; |
| 57 const uint32 kBackgroundColorMaterial = 0xFFEEEEEE; |
| 58 |
55 // Constants used in handling postMessage() messages. | 59 // Constants used in handling postMessage() messages. |
56 const char kType[] = "type"; | 60 const char kType[] = "type"; |
57 // Viewport message arguments. (Page -> Plugin). | 61 // Viewport message arguments. (Page -> Plugin). |
58 const char kJSViewportType[] = "viewport"; | 62 const char kJSViewportType[] = "viewport"; |
59 const char kJSXOffset[] = "xOffset"; | 63 const char kJSXOffset[] = "xOffset"; |
60 const char kJSYOffset[] = "yOffset"; | 64 const char kJSYOffset[] = "yOffset"; |
61 const char kJSZoom[] = "zoom"; | 65 const char kJSZoom[] = "zoom"; |
62 // Stop scrolling message (Page -> Plugin) | 66 // Stop scrolling message (Page -> Plugin) |
63 const char kJSStopScrollingType[] = "stopScrolling"; | 67 const char kJSStopScrollingType[] = "stopScrolling"; |
64 // Document dimension arguments (Plugin -> Page). | 68 // Document dimension arguments (Plugin -> Page). |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 GetLocalizedString(PP_RESOURCESTRING_PDFLOADING)); | 328 GetLocalizedString(PP_RESOURCESTRING_PDFLOADING)); |
325 translated_strings.Set(kJSLoadFailedString, | 329 translated_strings.Set(kJSLoadFailedString, |
326 GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED)); | 330 GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED)); |
327 PostMessage(translated_strings); | 331 PostMessage(translated_strings); |
328 | 332 |
329 text_input_.reset(new pp::TextInput_Dev(this)); | 333 text_input_.reset(new pp::TextInput_Dev(this)); |
330 | 334 |
331 const char* stream_url = NULL; | 335 const char* stream_url = NULL; |
332 const char* original_url = NULL; | 336 const char* original_url = NULL; |
333 const char* headers = NULL; | 337 const char* headers = NULL; |
| 338 const char* isMaterial = NULL; |
334 for (uint32_t i = 0; i < argc; ++i) { | 339 for (uint32_t i = 0; i < argc; ++i) { |
335 if (strcmp(argn[i], "src") == 0) | 340 if (strcmp(argn[i], "src") == 0) |
336 original_url = argv[i]; | 341 original_url = argv[i]; |
337 else if (strcmp(argn[i], "stream-url") == 0) | 342 else if (strcmp(argn[i], "stream-url") == 0) |
338 stream_url = argv[i]; | 343 stream_url = argv[i]; |
339 else if (strcmp(argn[i], "headers") == 0) | 344 else if (strcmp(argn[i], "headers") == 0) |
340 headers = argv[i]; | 345 headers = argv[i]; |
| 346 else if (strcmp(argn[i], "is-material") == 0) |
| 347 isMaterial = argv[i]; |
341 } | 348 } |
342 | 349 |
| 350 if (strcmp(isMaterial, "true") == 0) |
| 351 engine_->SetBackgroundColor(kBackgroundColorMaterial); |
| 352 else |
| 353 engine_->SetBackgroundColor(kBackgroundColor); |
| 354 |
| 355 |
343 // TODO(raymes): This is a hack to ensure that if no headers are passed in | 356 // TODO(raymes): This is a hack to ensure that if no headers are passed in |
344 // then we get the right MIME type. When the in process plugin is removed we | 357 // then we get the right MIME type. When the in process plugin is removed we |
345 // can fix the document loader properly and remove this hack. | 358 // can fix the document loader properly and remove this hack. |
346 if (!headers || strcmp(headers, "") == 0) | 359 if (!headers || strcmp(headers, "") == 0) |
347 headers = "content-type: application/pdf"; | 360 headers = "content-type: application/pdf"; |
348 | 361 |
349 if (!original_url) | 362 if (!original_url) |
350 return false; | 363 return false; |
351 | 364 |
352 if (!stream_url) | 365 if (!stream_url) |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 const std::vector<pp::Rect>& paint_rects, | 668 const std::vector<pp::Rect>& paint_rects, |
656 std::vector<PaintManager::ReadyRect>* ready, | 669 std::vector<PaintManager::ReadyRect>* ready, |
657 std::vector<pp::Rect>* pending) { | 670 std::vector<pp::Rect>* pending) { |
658 if (image_data_.is_null()) { | 671 if (image_data_.is_null()) { |
659 DCHECK(plugin_size_.IsEmpty()); | 672 DCHECK(plugin_size_.IsEmpty()); |
660 return; | 673 return; |
661 } | 674 } |
662 if (first_paint_) { | 675 if (first_paint_) { |
663 first_paint_ = false; | 676 first_paint_ = false; |
664 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); | 677 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); |
665 FillRect(rect, kBackgroundColor); | 678 FillRect(rect, engine_->GetBackgroundColor()); |
666 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); | 679 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); |
667 } | 680 } |
668 | 681 |
669 if (!received_viewport_message_) | 682 if (!received_viewport_message_) |
670 return; | 683 return; |
671 | 684 |
672 engine_->PrePaint(); | 685 engine_->PrePaint(); |
673 | 686 |
674 for (size_t i = 0; i < paint_rects.size(); i++) { | 687 for (size_t i = 0; i < paint_rects.size(); i++) { |
675 // Intersect with plugin area since there could be pending invalidates from | 688 // Intersect with plugin area since there could be pending invalidates from |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 background_parts_.clear(); | 761 background_parts_.clear(); |
749 int left_width = available_area_.x(); | 762 int left_width = available_area_.x(); |
750 int right_start = available_area_.right(); | 763 int right_start = available_area_.right(); |
751 int right_width = abs(plugin_size_.width() - available_area_.right()); | 764 int right_width = abs(plugin_size_.width() - available_area_.right()); |
752 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); | 765 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); |
753 | 766 |
754 // Add the left, right, and bottom rectangles. Note: we assume only | 767 // Add the left, right, and bottom rectangles. Note: we assume only |
755 // horizontal centering. | 768 // horizontal centering. |
756 BackgroundPart part = { | 769 BackgroundPart part = { |
757 pp::Rect(0, 0, left_width, bottom), | 770 pp::Rect(0, 0, left_width, bottom), |
758 kBackgroundColor | 771 engine_->GetBackgroundColor() |
759 }; | 772 }; |
760 if (!part.location.IsEmpty()) | 773 if (!part.location.IsEmpty()) |
761 background_parts_.push_back(part); | 774 background_parts_.push_back(part); |
762 part.location = pp::Rect(right_start, 0, right_width, bottom); | 775 part.location = pp::Rect(right_start, 0, right_width, bottom); |
763 if (!part.location.IsEmpty()) | 776 if (!part.location.IsEmpty()) |
764 background_parts_.push_back(part); | 777 background_parts_.push_back(part); |
765 part.location = pp::Rect( | 778 part.location = pp::Rect( |
766 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); | 779 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); |
767 if (!part.location.IsEmpty()) | 780 if (!part.location.IsEmpty()) |
768 background_parts_.push_back(part); | 781 background_parts_.push_back(part); |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1388 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1376 const pp::FloatPoint& scroll_offset) { | 1389 const pp::FloatPoint& scroll_offset) { |
1377 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1390 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1378 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1391 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1379 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1392 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1380 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1393 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1381 return pp::FloatPoint(x, y); | 1394 return pp::FloatPoint(x, y); |
1382 } | 1395 } |
1383 | 1396 |
1384 } // namespace chrome_pdf | 1397 } // namespace chrome_pdf |
OLD | NEW |