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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 original_url = argv[i]; | 341 original_url = argv[i]; |
342 else if (strcmp(argn[i], "stream-url") == 0) | 342 else if (strcmp(argn[i], "stream-url") == 0) |
343 stream_url = argv[i]; | 343 stream_url = argv[i]; |
344 else if (strcmp(argn[i], "headers") == 0) | 344 else if (strcmp(argn[i], "headers") == 0) |
345 headers = argv[i]; | 345 headers = argv[i]; |
346 else if (strcmp(argn[i], "is-material") == 0) | 346 else if (strcmp(argn[i], "is-material") == 0) |
347 is_material = true; | 347 is_material = true; |
348 } | 348 } |
349 | 349 |
350 if (is_material) | 350 if (is_material) |
351 engine_->SetBackgroundColor(kBackgroundColorMaterial); | 351 background_color_ = kBackgroundColorMaterial; |
352 else | 352 else |
353 engine_->SetBackgroundColor(kBackgroundColor); | 353 background_color_ = kBackgroundColor; |
Sam McNally
2015/02/09 01:35:47
Initialize background_color_ to kBackgroundColor.
raymes
2015/02/09 01:45:57
Done.
| |
354 | |
355 | 354 |
356 // TODO(raymes): This is a hack to ensure that if no headers are passed in | 355 // TODO(raymes): This is a hack to ensure that if no headers are passed in |
357 // then we get the right MIME type. When the in process plugin is removed we | 356 // then we get the right MIME type. When the in process plugin is removed we |
358 // can fix the document loader properly and remove this hack. | 357 // can fix the document loader properly and remove this hack. |
359 if (!headers || strcmp(headers, "") == 0) | 358 if (!headers || strcmp(headers, "") == 0) |
360 headers = "content-type: application/pdf"; | 359 headers = "content-type: application/pdf"; |
361 | 360 |
362 if (!original_url) | 361 if (!original_url) |
363 return false; | 362 return false; |
364 | 363 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 const std::vector<pp::Rect>& paint_rects, | 667 const std::vector<pp::Rect>& paint_rects, |
669 std::vector<PaintManager::ReadyRect>* ready, | 668 std::vector<PaintManager::ReadyRect>* ready, |
670 std::vector<pp::Rect>* pending) { | 669 std::vector<pp::Rect>* pending) { |
671 if (image_data_.is_null()) { | 670 if (image_data_.is_null()) { |
672 DCHECK(plugin_size_.IsEmpty()); | 671 DCHECK(plugin_size_.IsEmpty()); |
673 return; | 672 return; |
674 } | 673 } |
675 if (first_paint_) { | 674 if (first_paint_) { |
676 first_paint_ = false; | 675 first_paint_ = false; |
677 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); | 676 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); |
678 FillRect(rect, engine_->GetBackgroundColor()); | 677 FillRect(rect, background_color_); |
679 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); | 678 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); |
680 } | 679 } |
681 | 680 |
682 if (!received_viewport_message_) | 681 if (!received_viewport_message_) |
683 return; | 682 return; |
684 | 683 |
685 engine_->PrePaint(); | 684 engine_->PrePaint(); |
686 | 685 |
687 for (size_t i = 0; i < paint_rects.size(); i++) { | 686 for (size_t i = 0; i < paint_rects.size(); i++) { |
688 // Intersect with plugin area since there could be pending invalidates from | 687 // Intersect with plugin area since there could be pending invalidates from |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 background_parts_.clear(); | 760 background_parts_.clear(); |
762 int left_width = available_area_.x(); | 761 int left_width = available_area_.x(); |
763 int right_start = available_area_.right(); | 762 int right_start = available_area_.right(); |
764 int right_width = abs(plugin_size_.width() - available_area_.right()); | 763 int right_width = abs(plugin_size_.width() - available_area_.right()); |
765 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); | 764 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); |
766 | 765 |
767 // Add the left, right, and bottom rectangles. Note: we assume only | 766 // Add the left, right, and bottom rectangles. Note: we assume only |
768 // horizontal centering. | 767 // horizontal centering. |
769 BackgroundPart part = { | 768 BackgroundPart part = { |
770 pp::Rect(0, 0, left_width, bottom), | 769 pp::Rect(0, 0, left_width, bottom), |
771 engine_->GetBackgroundColor() | 770 background_color_ |
772 }; | 771 }; |
773 if (!part.location.IsEmpty()) | 772 if (!part.location.IsEmpty()) |
774 background_parts_.push_back(part); | 773 background_parts_.push_back(part); |
775 part.location = pp::Rect(right_start, 0, right_width, bottom); | 774 part.location = pp::Rect(right_start, 0, right_width, bottom); |
776 if (!part.location.IsEmpty()) | 775 if (!part.location.IsEmpty()) |
777 background_parts_.push_back(part); | 776 background_parts_.push_back(part); |
778 part.location = pp::Rect( | 777 part.location = pp::Rect( |
779 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); | 778 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); |
780 if (!part.location.IsEmpty()) | 779 if (!part.location.IsEmpty()) |
781 background_parts_.push_back(part); | 780 background_parts_.push_back(part); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 return; | 1339 return; |
1341 engine_->AppendBlankPages(print_preview_page_count_); | 1340 engine_->AppendBlankPages(print_preview_page_count_); |
1342 if (preview_pages_info_.size() > 0) | 1341 if (preview_pages_info_.size() > 0) |
1343 LoadAvailablePreviewPage(); | 1342 LoadAvailablePreviewPage(); |
1344 } | 1343 } |
1345 | 1344 |
1346 bool OutOfProcessInstance::IsPrintPreview() { | 1345 bool OutOfProcessInstance::IsPrintPreview() { |
1347 return IsPrintPreviewUrl(url_); | 1346 return IsPrintPreviewUrl(url_); |
1348 } | 1347 } |
1349 | 1348 |
1349 uint32 OutOfProcessInstance::GetBackgroundColor() { | |
1350 return background_color_; | |
1351 } | |
1352 | |
1350 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, | 1353 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, |
1351 int dst_page_index) { | 1354 int dst_page_index) { |
1352 if (!IsPrintPreview()) | 1355 if (!IsPrintPreview()) |
1353 return; | 1356 return; |
1354 | 1357 |
1355 int src_page_index = ExtractPrintPreviewPageIndex(url); | 1358 int src_page_index = ExtractPrintPreviewPageIndex(url); |
1356 if (src_page_index < 1) | 1359 if (src_page_index < 1) |
1357 return; | 1360 return; |
1358 | 1361 |
1359 preview_pages_info_.push(std::make_pair(url, dst_page_index)); | 1362 preview_pages_info_.push(std::make_pair(url, dst_page_index)); |
(...skipping 28 matching lines...) Expand all Loading... | |
1388 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1391 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
1389 const pp::FloatPoint& scroll_offset) { | 1392 const pp::FloatPoint& scroll_offset) { |
1390 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1393 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1391 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1394 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
1392 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1395 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1393 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1396 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
1394 return pp::FloatPoint(x, y); | 1397 return pp::FloatPoint(x, y); |
1395 } | 1398 } |
1396 | 1399 |
1397 } // namespace chrome_pdf | 1400 } // namespace chrome_pdf |
OLD | NEW |