Chromium Code Reviews| 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 document_load_state_(LOAD_STATE_LOADING), | 271 document_load_state_(LOAD_STATE_LOADING), |
| 272 preview_document_load_state_(LOAD_STATE_COMPLETE), | 272 preview_document_load_state_(LOAD_STATE_COMPLETE), |
| 273 uma_(this), | 273 uma_(this), |
| 274 told_browser_about_unsupported_feature_(false), | 274 told_browser_about_unsupported_feature_(false), |
| 275 print_preview_page_count_(0), | 275 print_preview_page_count_(0), |
| 276 last_progress_sent_(0), | 276 last_progress_sent_(0), |
| 277 recently_sent_find_update_(false), | 277 recently_sent_find_update_(false), |
| 278 received_viewport_message_(false), | 278 received_viewport_message_(false), |
| 279 did_call_start_loading_(false), | 279 did_call_start_loading_(false), |
| 280 stop_scrolling_(false), | 280 stop_scrolling_(false), |
| 281 background_color_(kBackgroundColor) { | 281 background_color_(kBackgroundColor), |
| 282 top_toolbar_height_(0) { | |
| 282 loader_factory_.Initialize(this); | 283 loader_factory_.Initialize(this); |
| 283 timer_factory_.Initialize(this); | 284 timer_factory_.Initialize(this); |
| 284 form_factory_.Initialize(this); | 285 form_factory_.Initialize(this); |
| 285 print_callback_factory_.Initialize(this); | 286 print_callback_factory_.Initialize(this); |
| 286 engine_.reset(PDFEngine::Create(this)); | 287 engine_.reset(PDFEngine::Create(this)); |
| 287 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); | 288 pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private); |
| 288 AddPerInstanceObject(kPPPPdfInterface, this); | 289 AddPerInstanceObject(kPPPPdfInterface, this); |
| 289 | 290 |
| 290 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | 291 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
| 291 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 292 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 bool is_material = false; | 349 bool is_material = false; |
| 349 for (uint32_t i = 0; i < argc; ++i) { | 350 for (uint32_t i = 0; i < argc; ++i) { |
| 350 if (strcmp(argn[i], "src") == 0) | 351 if (strcmp(argn[i], "src") == 0) |
| 351 original_url = argv[i]; | 352 original_url = argv[i]; |
| 352 else if (strcmp(argn[i], "stream-url") == 0) | 353 else if (strcmp(argn[i], "stream-url") == 0) |
| 353 stream_url = argv[i]; | 354 stream_url = argv[i]; |
| 354 else if (strcmp(argn[i], "headers") == 0) | 355 else if (strcmp(argn[i], "headers") == 0) |
| 355 headers = argv[i]; | 356 headers = argv[i]; |
| 356 else if (strcmp(argn[i], "is-material") == 0) | 357 else if (strcmp(argn[i], "is-material") == 0) |
| 357 is_material = true; | 358 is_material = true; |
| 359 else if (strcmp(argn[i], "top-toolbar-height") == 0) | |
| 360 base::StringToInt(argv[i], &top_toolbar_height_); | |
| 358 } | 361 } |
| 359 | 362 |
| 360 if (is_material) | 363 if (is_material) |
| 361 background_color_ = kBackgroundColorMaterial; | 364 background_color_ = kBackgroundColorMaterial; |
| 362 else | 365 else |
| 363 background_color_ = kBackgroundColor; | 366 background_color_ = kBackgroundColor; |
| 364 | 367 |
| 365 if (!original_url) | 368 if (!original_url) |
| 366 return false; | 369 return false; |
| 367 | 370 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 if (image_data_.is_null()) { | 588 if (image_data_.is_null()) { |
| 586 DCHECK(plugin_size_.IsEmpty()); | 589 DCHECK(plugin_size_.IsEmpty()); |
| 587 return; | 590 return; |
| 588 } | 591 } |
| 589 | 592 |
| 590 OnGeometryChanged(zoom_, old_device_scale); | 593 OnGeometryChanged(zoom_, old_device_scale); |
| 591 } | 594 } |
| 592 | 595 |
| 593 if (!stop_scrolling_) { | 596 if (!stop_scrolling_) { |
| 594 pp::Point scroll_offset(view.GetScrollOffset()); | 597 pp::Point scroll_offset(view.GetScrollOffset()); |
| 598 // Because view messages come from the DOM, the coordinates of the viewport | |
| 599 // are 0-based (i.e. they do not correspond to the viewport's coordinates in | |
| 600 // JS), so we need to subtract the toolbar height to convert thme into | |
|
Sam McNally
2015/08/04 00:48:55
them
raymes
2015/08/04 01:00:20
Done.
| |
| 601 // viewport coordinates. | |
| 595 pp::FloatPoint scroll_offset_float(scroll_offset.x(), | 602 pp::FloatPoint scroll_offset_float(scroll_offset.x(), |
| 596 scroll_offset.y()); | 603 scroll_offset.y() - top_toolbar_height_); |
| 597 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); | 604 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); |
| 598 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); | 605 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); |
| 599 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); | 606 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); |
| 600 } | 607 } |
| 601 } | 608 } |
| 602 | 609 |
| 603 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( | 610 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( |
| 604 PP_PdfPrintPresetOptions_Dev* options) { | 611 PP_PdfPrintPresetOptions_Dev* options) { |
| 605 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | 612 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 606 options->duplex = | 613 options->duplex = |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 pdf_ready[j].Offset(available_area_.point()); | 726 pdf_ready[j].Offset(available_area_.point()); |
| 720 ready->push_back( | 727 ready->push_back( |
| 721 PaintManager::ReadyRect(pdf_ready[j], image_data_, false)); | 728 PaintManager::ReadyRect(pdf_ready[j], image_data_, false)); |
| 722 } | 729 } |
| 723 for (size_t j = 0; j < pdf_pending.size(); ++j) { | 730 for (size_t j = 0; j < pdf_pending.size(); ++j) { |
| 724 pdf_pending[j].Offset(available_area_.point()); | 731 pdf_pending[j].Offset(available_area_.point()); |
| 725 pending->push_back(pdf_pending[j]); | 732 pending->push_back(pdf_pending[j]); |
| 726 } | 733 } |
| 727 } | 734 } |
| 728 | 735 |
| 736 // Ensure the region above the first page (if any) is filled; | |
| 737 int32_t first_page_ypos = engine_->GetPageScreenRect(0).y(); | |
| 738 if (rect.y() < first_page_ypos) { | |
| 739 pp::Rect region = rect.Intersect(pp::Rect( | |
| 740 pp::Point(), pp::Size(plugin_size_.width(), first_page_ypos))); | |
| 741 ready->push_back(PaintManager::ReadyRect(region, image_data_, false)); | |
| 742 FillRect(region, background_color_); | |
| 743 } | |
| 744 | |
| 729 for (size_t j = 0; j < background_parts_.size(); ++j) { | 745 for (size_t j = 0; j < background_parts_.size(); ++j) { |
| 730 pp::Rect intersection = background_parts_[j].location.Intersect(rect); | 746 pp::Rect intersection = background_parts_[j].location.Intersect(rect); |
| 731 if (!intersection.IsEmpty()) { | 747 if (!intersection.IsEmpty()) { |
| 732 FillRect(intersection, background_parts_[j].color); | 748 FillRect(intersection, background_parts_[j].color); |
| 733 ready->push_back( | 749 ready->push_back( |
| 734 PaintManager::ReadyRect(intersection, image_data_, false)); | 750 PaintManager::ReadyRect(intersection, image_data_, false)); |
| 735 } | 751 } |
| 736 } | 752 } |
| 737 } | 753 } |
| 738 | 754 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1125 did_call_start_loading_ = false; | 1141 did_call_start_loading_ = false; |
| 1126 } | 1142 } |
| 1127 | 1143 |
| 1128 int content_restrictions = | 1144 int content_restrictions = |
| 1129 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; | 1145 CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE; |
| 1130 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 1146 if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
| 1131 content_restrictions |= CONTENT_RESTRICTION_COPY; | 1147 content_restrictions |= CONTENT_RESTRICTION_COPY; |
| 1132 | 1148 |
| 1133 pp::PDF::SetContentRestriction(this, content_restrictions); | 1149 pp::PDF::SetContentRestriction(this, content_restrictions); |
| 1134 | 1150 |
| 1135 uma_.HistogramCustomCounts("PDF.PageCount", page_count, | 1151 uma_.HistogramCustomCounts("PDF.PageCount", page_count, 1, 1000000, 50); |
| 1136 1, 1000000, 50); | |
| 1137 } | 1152 } |
| 1138 | 1153 |
| 1139 void OutOfProcessInstance::RotateClockwise() { | 1154 void OutOfProcessInstance::RotateClockwise() { |
| 1140 engine_->RotateClockwise(); | 1155 engine_->RotateClockwise(); |
| 1141 } | 1156 } |
| 1142 | 1157 |
| 1143 void OutOfProcessInstance::RotateCounterclockwise() { | 1158 void OutOfProcessInstance::RotateCounterclockwise() { |
| 1144 engine_->RotateCounterclockwise(); | 1159 engine_->RotateCounterclockwise(); |
| 1145 } | 1160 } |
| 1146 | 1161 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1272 float old_device_scale) { | 1287 float old_device_scale) { |
| 1273 if (zoom_ != old_zoom || device_scale_ != old_device_scale) | 1288 if (zoom_ != old_zoom || device_scale_ != old_device_scale) |
| 1274 engine_->ZoomUpdated(zoom_ * device_scale_); | 1289 engine_->ZoomUpdated(zoom_ * device_scale_); |
| 1275 | 1290 |
| 1276 available_area_ = pp::Rect(plugin_size_); | 1291 available_area_ = pp::Rect(plugin_size_); |
| 1277 int doc_width = GetDocumentPixelWidth(); | 1292 int doc_width = GetDocumentPixelWidth(); |
| 1278 if (doc_width < available_area_.width()) { | 1293 if (doc_width < available_area_.width()) { |
| 1279 available_area_.Offset((available_area_.width() - doc_width) / 2, 0); | 1294 available_area_.Offset((available_area_.width() - doc_width) / 2, 0); |
| 1280 available_area_.set_width(doc_width); | 1295 available_area_.set_width(doc_width); |
| 1281 } | 1296 } |
| 1282 int doc_height = GetDocumentPixelHeight(); | 1297 int bottom_of_document = |
| 1283 if (doc_height < available_area_.height()) { | 1298 GetDocumentPixelHeight() + (top_toolbar_height_ * device_scale_); |
| 1284 available_area_.set_height(doc_height); | 1299 if (bottom_of_document < available_area_.height()) |
| 1285 } | 1300 available_area_.set_height(bottom_of_document); |
| 1286 | 1301 |
| 1287 CalculateBackgroundParts(); | 1302 CalculateBackgroundParts(); |
| 1288 engine_->PageOffsetUpdated(available_area_.point()); | 1303 engine_->PageOffsetUpdated(available_area_.point()); |
| 1289 engine_->PluginSizeUpdated(available_area_.size()); | 1304 engine_->PluginSizeUpdated(available_area_.size()); |
| 1290 | 1305 |
| 1291 if (!document_size_.GetArea()) | 1306 if (!document_size_.GetArea()) |
| 1292 return; | 1307 return; |
| 1293 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); | 1308 paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_)); |
| 1294 } | 1309 } |
| 1295 | 1310 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1401 void OutOfProcessInstance::UserMetricsRecordAction( | 1416 void OutOfProcessInstance::UserMetricsRecordAction( |
| 1402 const std::string& action) { | 1417 const std::string& action) { |
| 1403 // TODO(raymes): Move this function to PPB_UMA_Private. | 1418 // TODO(raymes): Move this function to PPB_UMA_Private. |
| 1404 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); | 1419 pp::PDF::UserMetricsRecordAction(this, pp::Var(action)); |
| 1405 } | 1420 } |
| 1406 | 1421 |
| 1407 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1422 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1408 const pp::FloatPoint& scroll_offset) { | 1423 const pp::FloatPoint& scroll_offset) { |
| 1409 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1424 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1410 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1425 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
| 1426 float min_y = -top_toolbar_height_; | |
| 1411 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1427 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1412 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); | 1428 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
| 1413 return pp::FloatPoint(x, y); | 1429 return pp::FloatPoint(x, y); |
| 1414 } | 1430 } |
| 1415 | 1431 |
| 1416 } // namespace chrome_pdf | 1432 } // namespace chrome_pdf |
| OLD | NEW |