| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 first_paint_(true), | 264 first_paint_(true), |
| 265 document_load_state_(LOAD_STATE_LOADING), | 265 document_load_state_(LOAD_STATE_LOADING), |
| 266 preview_document_load_state_(LOAD_STATE_COMPLETE), | 266 preview_document_load_state_(LOAD_STATE_COMPLETE), |
| 267 uma_(this), | 267 uma_(this), |
| 268 told_browser_about_unsupported_feature_(false), | 268 told_browser_about_unsupported_feature_(false), |
| 269 print_preview_page_count_(0), | 269 print_preview_page_count_(0), |
| 270 last_progress_sent_(0), | 270 last_progress_sent_(0), |
| 271 recently_sent_find_update_(false), | 271 recently_sent_find_update_(false), |
| 272 received_viewport_message_(false), | 272 received_viewport_message_(false), |
| 273 did_call_start_loading_(false), | 273 did_call_start_loading_(false), |
| 274 stop_scrolling_(false) { | 274 stop_scrolling_(false), |
| 275 background_color_(kBackgroundColor) { |
| 275 loader_factory_.Initialize(this); | 276 loader_factory_.Initialize(this); |
| 276 timer_factory_.Initialize(this); | 277 timer_factory_.Initialize(this); |
| 277 form_factory_.Initialize(this); | 278 form_factory_.Initialize(this); |
| 278 print_callback_factory_.Initialize(this); | 279 print_callback_factory_.Initialize(this); |
| 279 engine_.reset(PDFEngine::Create(this)); | 280 engine_.reset(PDFEngine::Create(this)); |
| 280 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); | 281 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); |
| 281 AddPerInstanceObject(kPPPPdfInterface, this); | 282 AddPerInstanceObject(kPPPPdfInterface, this); |
| 282 | 283 |
| 283 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 284 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
| 284 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 285 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 original_url = argv[i]; | 342 original_url = argv[i]; |
| 342 else if (strcmp(argn[i], "stream-url") == 0) | 343 else if (strcmp(argn[i], "stream-url") == 0) |
| 343 stream_url = argv[i]; | 344 stream_url = argv[i]; |
| 344 else if (strcmp(argn[i], "headers") == 0) | 345 else if (strcmp(argn[i], "headers") == 0) |
| 345 headers = argv[i]; | 346 headers = argv[i]; |
| 346 else if (strcmp(argn[i], "is-material") == 0) | 347 else if (strcmp(argn[i], "is-material") == 0) |
| 347 is_material = true; | 348 is_material = true; |
| 348 } | 349 } |
| 349 | 350 |
| 350 if (is_material) | 351 if (is_material) |
| 351 engine_->SetBackgroundColor(kBackgroundColorMaterial); | 352 background_color_ = kBackgroundColorMaterial; |
| 352 else | 353 else |
| 353 engine_->SetBackgroundColor(kBackgroundColor); | 354 background_color_ = kBackgroundColor; |
| 354 | |
| 355 | 355 |
| 356 // 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 |
| 357 // 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 |
| 358 // can fix the document loader properly and remove this hack. | 358 // can fix the document loader properly and remove this hack. |
| 359 if (!headers || strcmp(headers, "") == 0) | 359 if (!headers || strcmp(headers, "") == 0) |
| 360 headers = "content-type: application/pdf"; | 360 headers = "content-type: application/pdf"; |
| 361 | 361 |
| 362 if (!original_url) | 362 if (!original_url) |
| 363 return false; | 363 return false; |
| 364 | 364 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 const std::vector<pp::Rect>& paint_rects, | 668 const std::vector<pp::Rect>& paint_rects, |
| 669 std::vector<PaintManager::ReadyRect>* ready, | 669 std::vector<PaintManager::ReadyRect>* ready, |
| 670 std::vector<pp::Rect>* pending) { | 670 std::vector<pp::Rect>* pending) { |
| 671 if (image_data_.is_null()) { | 671 if (image_data_.is_null()) { |
| 672 DCHECK(plugin_size_.IsEmpty()); | 672 DCHECK(plugin_size_.IsEmpty()); |
| 673 return; | 673 return; |
| 674 } | 674 } |
| 675 if (first_paint_) { | 675 if (first_paint_) { |
| 676 first_paint_ = false; | 676 first_paint_ = false; |
| 677 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); | 677 pp::Rect rect = pp::Rect(pp::Point(), image_data_.size()); |
| 678 FillRect(rect, engine_->GetBackgroundColor()); | 678 FillRect(rect, background_color_); |
| 679 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); | 679 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); |
| 680 } | 680 } |
| 681 | 681 |
| 682 if (!received_viewport_message_) | 682 if (!received_viewport_message_) |
| 683 return; | 683 return; |
| 684 | 684 |
| 685 engine_->PrePaint(); | 685 engine_->PrePaint(); |
| 686 | 686 |
| 687 for (size_t i = 0; i < paint_rects.size(); i++) { | 687 for (size_t i = 0; i < paint_rects.size(); i++) { |
| 688 // 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... |
| 761 background_parts_.clear(); | 761 background_parts_.clear(); |
| 762 int left_width = available_area_.x(); | 762 int left_width = available_area_.x(); |
| 763 int right_start = available_area_.right(); | 763 int right_start = available_area_.right(); |
| 764 int right_width = abs(plugin_size_.width() - available_area_.right()); | 764 int right_width = abs(plugin_size_.width() - available_area_.right()); |
| 765 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); | 765 int bottom = std::min(available_area_.bottom(), plugin_size_.height()); |
| 766 | 766 |
| 767 // Add the left, right, and bottom rectangles. Note: we assume only | 767 // Add the left, right, and bottom rectangles. Note: we assume only |
| 768 // horizontal centering. | 768 // horizontal centering. |
| 769 BackgroundPart part = { | 769 BackgroundPart part = { |
| 770 pp::Rect(0, 0, left_width, bottom), | 770 pp::Rect(0, 0, left_width, bottom), |
| 771 engine_->GetBackgroundColor() | 771 background_color_ |
| 772 }; | 772 }; |
| 773 if (!part.location.IsEmpty()) | 773 if (!part.location.IsEmpty()) |
| 774 background_parts_.push_back(part); | 774 background_parts_.push_back(part); |
| 775 part.location = pp::Rect(right_start, 0, right_width, bottom); | 775 part.location = pp::Rect(right_start, 0, right_width, bottom); |
| 776 if (!part.location.IsEmpty()) | 776 if (!part.location.IsEmpty()) |
| 777 background_parts_.push_back(part); | 777 background_parts_.push_back(part); |
| 778 part.location = pp::Rect( | 778 part.location = pp::Rect( |
| 779 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); | 779 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom); |
| 780 if (!part.location.IsEmpty()) | 780 if (!part.location.IsEmpty()) |
| 781 background_parts_.push_back(part); | 781 background_parts_.push_back(part); |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 return; | 1340 return; |
| 1341 engine_->AppendBlankPages(print_preview_page_count_); | 1341 engine_->AppendBlankPages(print_preview_page_count_); |
| 1342 if (preview_pages_info_.size() > 0) | 1342 if (preview_pages_info_.size() > 0) |
| 1343 LoadAvailablePreviewPage(); | 1343 LoadAvailablePreviewPage(); |
| 1344 } | 1344 } |
| 1345 | 1345 |
| 1346 bool OutOfProcessInstance::IsPrintPreview() { | 1346 bool OutOfProcessInstance::IsPrintPreview() { |
| 1347 return IsPrintPreviewUrl(url_); | 1347 return IsPrintPreviewUrl(url_); |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 uint32 OutOfProcessInstance::GetBackgroundColor() { |
| 1351 return background_color_; |
| 1352 } |
| 1353 |
| 1350 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, | 1354 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, |
| 1351 int dst_page_index) { | 1355 int dst_page_index) { |
| 1352 if (!IsPrintPreview()) | 1356 if (!IsPrintPreview()) |
| 1353 return; | 1357 return; |
| 1354 | 1358 |
| 1355 int src_page_index = ExtractPrintPreviewPageIndex(url); | 1359 int src_page_index = ExtractPrintPreviewPageIndex(url); |
| 1356 if (src_page_index < 1) | 1360 if (src_page_index < 1) |
| 1357 return; | 1361 return; |
| 1358 | 1362 |
| 1359 preview_pages_info_.push(std::make_pair(url, dst_page_index)); | 1363 preview_pages_info_.push(std::make_pair(url, dst_page_index)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1388 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1392 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1389 const pp::FloatPoint& scroll_offset) { | 1393 const pp::FloatPoint& scroll_offset) { |
| 1390 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1394 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); | 1395 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(); | 1396 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); | 1397 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
| 1394 return pp::FloatPoint(x, y); | 1398 return pp::FloatPoint(x, y); |
| 1395 } | 1399 } |
| 1396 | 1400 |
| 1397 } // namespace chrome_pdf | 1401 } // namespace chrome_pdf |
| OLD | NEW |