| 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/instance.h" | 5 #include "pdf/instance.h" |
| 6 | 6 |
| 7 #include <algorithm> // for min() | 7 #include <algorithm> // for min() |
| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: | 209 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: |
| 210 obj_instance->RotateClockwise(); | 210 obj_instance->RotateClockwise(); |
| 211 break; | 211 break; |
| 212 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: | 212 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: |
| 213 obj_instance->RotateCounterclockwise(); | 213 obj_instance->RotateCounterclockwise(); |
| 214 break; | 214 break; |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 PP_Bool GetPrintPresetOptionsFromDocument( |
| 220 PP_Instance instance, |
| 221 PP_PdfPrintPresetOptions_Dev* options) { |
| 222 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
| 223 if (object) { |
| 224 Instance* obj_instance = static_cast<Instance*>(object); |
| 225 obj_instance->GetPrintPresetOptionsFromDocument(options); |
| 226 } |
| 227 return PP_TRUE; |
| 228 } |
| 229 |
| 219 const PPP_Pdf ppp_private = { | 230 const PPP_Pdf ppp_private = { |
| 220 &GetLinkAtPosition, | 231 &GetLinkAtPosition, |
| 221 &Transform | 232 &Transform, |
| 233 &GetPrintPresetOptionsFromDocument |
| 222 }; | 234 }; |
| 223 | 235 |
| 224 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 236 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
| 225 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 237 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
| 226 std::vector<std::string> url_substr; | 238 std::vector<std::string> url_substr; |
| 227 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); | 239 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); |
| 228 if (url_substr.size() != 3) | 240 if (url_substr.size() != 3) |
| 229 return -1; | 241 return -1; |
| 230 | 242 |
| 231 if (url_substr[2] != "print.pdf") | 243 if (url_substr[2] != "print.pdf") |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 pp::Var Instance::GetInstanceObject() { | 663 pp::Var Instance::GetInstanceObject() { |
| 652 if (instance_object_.is_undefined()) { | 664 if (instance_object_.is_undefined()) { |
| 653 PDFScriptableObject* object = new PDFScriptableObject(this); | 665 PDFScriptableObject* object = new PDFScriptableObject(this); |
| 654 // The pp::Var takes ownership of object here. | 666 // The pp::Var takes ownership of object here. |
| 655 instance_object_ = pp::VarPrivate(this, object); | 667 instance_object_ = pp::VarPrivate(this, object); |
| 656 } | 668 } |
| 657 | 669 |
| 658 return instance_object_; | 670 return instance_object_; |
| 659 } | 671 } |
| 660 | 672 |
| 673 void Instance::GetPrintPresetOptionsFromDocument( |
| 674 PP_PdfPrintPresetOptions_Dev* options) { |
| 675 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 676 options->copies = engine_->GetCopiesToPrint(); |
| 677 } |
| 678 |
| 661 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { | 679 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { |
| 662 pp::Point offset_point(point); | 680 pp::Point offset_point(point); |
| 663 ScalePoint(device_scale_, &offset_point); | 681 ScalePoint(device_scale_, &offset_point); |
| 664 offset_point.set_x(offset_point.x() - available_area_.x()); | 682 offset_point.set_x(offset_point.x() - available_area_.x()); |
| 665 return engine_->GetLinkAtPosition(offset_point); | 683 return engine_->GetLinkAtPosition(offset_point); |
| 666 } | 684 } |
| 667 | 685 |
| 668 pp::Var Instance::GetSelectedText(bool html) { | 686 pp::Var Instance::GetSelectedText(bool html) { |
| 669 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 687 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
| 670 return pp::Var(); | 688 return pp::Var(); |
| (...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2761 return instance_->HasScriptableMethod(name, exception); | 2779 return instance_->HasScriptableMethod(name, exception); |
| 2762 } | 2780 } |
| 2763 | 2781 |
| 2764 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2782 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
| 2765 const std::vector<pp::Var>& args, | 2783 const std::vector<pp::Var>& args, |
| 2766 pp::Var* exception) { | 2784 pp::Var* exception) { |
| 2767 return instance_->CallScriptableMethod(method, args, exception); | 2785 return instance_->CallScriptableMethod(method, args, exception); |
| 2768 } | 2786 } |
| 2769 | 2787 |
| 2770 } // namespace chrome_pdf | 2788 } // namespace chrome_pdf |
| OLD | NEW |