| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: | 159 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: |
| 160 obj_instance->RotateClockwise(); | 160 obj_instance->RotateClockwise(); |
| 161 break; | 161 break; |
| 162 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: | 162 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: |
| 163 obj_instance->RotateCounterclockwise(); | 163 obj_instance->RotateCounterclockwise(); |
| 164 break; | 164 break; |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 PP_Bool GetPrintPresetOptionsFromDocument( |
| 170 PP_Instance instance, |
| 171 PP_PdfPrintPresetOptions_Dev* options) { |
| 172 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
| 173 if (object) { |
| 174 OutOfProcessInstance* obj_instance = |
| 175 static_cast<OutOfProcessInstance*>(object); |
| 176 obj_instance->GetPrintPresetOptionsFromDocument(options); |
| 177 } |
| 178 return PP_TRUE; |
| 179 } |
| 180 |
| 169 const PPP_Pdf ppp_private = { | 181 const PPP_Pdf ppp_private = { |
| 170 &GetLinkAtPosition, | 182 &GetLinkAtPosition, |
| 171 &Transform | 183 &Transform, |
| 184 &GetPrintPresetOptionsFromDocument |
| 172 }; | 185 }; |
| 173 | 186 |
| 174 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 187 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
| 175 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 188 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
| 176 std::vector<std::string> url_substr; | 189 std::vector<std::string> url_substr; |
| 177 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); | 190 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); |
| 178 if (url_substr.size() != 3) | 191 if (url_substr.size() != 3) |
| 179 return -1; | 192 return -1; |
| 180 | 193 |
| 181 if (url_substr[2] != "print.pdf") | 194 if (url_substr[2] != "print.pdf") |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (!stop_scrolling_) { | 557 if (!stop_scrolling_) { |
| 545 pp::Point scroll_offset(view.GetScrollOffset()); | 558 pp::Point scroll_offset(view.GetScrollOffset()); |
| 546 pp::FloatPoint scroll_offset_float(scroll_offset.x(), | 559 pp::FloatPoint scroll_offset_float(scroll_offset.x(), |
| 547 scroll_offset.y()); | 560 scroll_offset.y()); |
| 548 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); | 561 scroll_offset_float = BoundScrollOffsetToDocument(scroll_offset_float); |
| 549 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); | 562 engine_->ScrolledToXPosition(scroll_offset_float.x() * device_scale_); |
| 550 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); | 563 engine_->ScrolledToYPosition(scroll_offset_float.y() * device_scale_); |
| 551 } | 564 } |
| 552 } | 565 } |
| 553 | 566 |
| 567 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( |
| 568 PP_PdfPrintPresetOptions_Dev* options) { |
| 569 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 570 options->copies = engine_->GetCopiesToPrint(); |
| 571 } |
| 572 |
| 554 pp::Var OutOfProcessInstance::GetLinkAtPosition( | 573 pp::Var OutOfProcessInstance::GetLinkAtPosition( |
| 555 const pp::Point& point) { | 574 const pp::Point& point) { |
| 556 pp::Point offset_point(point); | 575 pp::Point offset_point(point); |
| 557 ScalePoint(device_scale_, &offset_point); | 576 ScalePoint(device_scale_, &offset_point); |
| 558 offset_point.set_x(offset_point.x() - available_area_.x()); | 577 offset_point.set_x(offset_point.x() - available_area_.x()); |
| 559 return engine_->GetLinkAtPosition(offset_point); | 578 return engine_->GetLinkAtPosition(offset_point); |
| 560 } | 579 } |
| 561 | 580 |
| 562 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { | 581 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { |
| 563 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 582 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1375 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( | 1394 pp::FloatPoint OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1376 const pp::FloatPoint& scroll_offset) { | 1395 const pp::FloatPoint& scroll_offset) { |
| 1377 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1396 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); | 1397 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(); | 1398 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); | 1399 float y = std::max(std::min(scroll_offset.y(), max_y), 0.0f); |
| 1381 return pp::FloatPoint(x, y); | 1400 return pp::FloatPoint(x, y); |
| 1382 } | 1401 } |
| 1383 | 1402 |
| 1384 } // namespace chrome_pdf | 1403 } // namespace chrome_pdf |
| OLD | NEW |