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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: | 210 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: |
211 obj_instance->RotateClockwise(); | 211 obj_instance->RotateClockwise(); |
212 break; | 212 break; |
213 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: | 213 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: |
214 obj_instance->RotateCounterclockwise(); | 214 obj_instance->RotateCounterclockwise(); |
215 break; | 215 break; |
216 } | 216 } |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
| 220 PP_Bool GetPrintPresetOptionsFromDocument( |
| 221 PP_Instance instance, |
| 222 PP_PdfPrintPresetOptions_Dev* options) { |
| 223 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
| 224 if (object) { |
| 225 Instance* obj_instance = static_cast<Instance*>(object); |
| 226 obj_instance->GetPrintPresetOptionsFromDocument(options); |
| 227 } |
| 228 return PP_TRUE; |
| 229 } |
| 230 |
220 const PPP_Pdf ppp_private = { | 231 const PPP_Pdf ppp_private = { |
221 &GetLinkAtPosition, | 232 &GetLinkAtPosition, |
222 &Transform | 233 &Transform, |
| 234 &GetPrintPresetOptionsFromDocument |
223 }; | 235 }; |
224 | 236 |
225 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 237 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
226 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 238 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
227 std::vector<std::string> url_substr; | 239 std::vector<std::string> url_substr; |
228 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); | 240 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); |
229 if (url_substr.size() != 3) | 241 if (url_substr.size() != 3) |
230 return -1; | 242 return -1; |
231 | 243 |
232 if (url_substr[2] != "print.pdf") | 244 if (url_substr[2] != "print.pdf") |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 pp::Var Instance::GetInstanceObject() { | 676 pp::Var Instance::GetInstanceObject() { |
665 if (instance_object_.is_undefined()) { | 677 if (instance_object_.is_undefined()) { |
666 PDFScriptableObject* object = new PDFScriptableObject(this); | 678 PDFScriptableObject* object = new PDFScriptableObject(this); |
667 // The pp::Var takes ownership of object here. | 679 // The pp::Var takes ownership of object here. |
668 instance_object_ = pp::VarPrivate(this, object); | 680 instance_object_ = pp::VarPrivate(this, object); |
669 } | 681 } |
670 | 682 |
671 return instance_object_; | 683 return instance_object_; |
672 } | 684 } |
673 | 685 |
| 686 void Instance::GetPrintPresetOptionsFromDocument( |
| 687 PP_PdfPrintPresetOptions_Dev* options) { |
| 688 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 689 options->copies = engine_->GetCopiesToPrint(); |
| 690 } |
| 691 |
674 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { | 692 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { |
675 pp::Point offset_point(point); | 693 pp::Point offset_point(point); |
676 ScalePoint(device_scale_, &offset_point); | 694 ScalePoint(device_scale_, &offset_point); |
677 offset_point.set_x(offset_point.x() - available_area_.x()); | 695 offset_point.set_x(offset_point.x() - available_area_.x()); |
678 return engine_->GetLinkAtPosition(offset_point); | 696 return engine_->GetLinkAtPosition(offset_point); |
679 } | 697 } |
680 | 698 |
681 pp::Var Instance::GetSelectedText(bool html) { | 699 pp::Var Instance::GetSelectedText(bool html) { |
682 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 700 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
683 return pp::Var(); | 701 return pp::Var(); |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2783 return instance_->HasScriptableMethod(name, exception); | 2801 return instance_->HasScriptableMethod(name, exception); |
2784 } | 2802 } |
2785 | 2803 |
2786 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2804 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
2787 const std::vector<pp::Var>& args, | 2805 const std::vector<pp::Var>& args, |
2788 pp::Var* exception) { | 2806 pp::Var* exception) { |
2789 return instance_->CallScriptableMethod(method, args, exception); | 2807 return instance_->CallScriptableMethod(method, args, exception); |
2790 } | 2808 } |
2791 | 2809 |
2792 } // namespace chrome_pdf | 2810 } // namespace chrome_pdf |
OLD | NEW |