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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 { kZoomOutButtonId, Button::BUTTON_CLICKABLE, | 181 { kZoomOutButtonId, Button::BUTTON_CLICKABLE, |
182 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT, | 182 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT, |
183 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER, | 183 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER, |
184 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED }, | 184 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED }, |
185 { kZoomInButtonId, Button::BUTTON_CLICKABLE, | 185 { kZoomInButtonId, Button::BUTTON_CLICKABLE, |
186 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END, | 186 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END, |
187 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_HOVER, | 187 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_HOVER, |
188 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_PRESSED }, | 188 PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_PRESSED }, |
189 }; | 189 }; |
190 | 190 |
191 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; | 191 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_2; |
192 | 192 |
193 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { | 193 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { |
194 pp::Var var; | 194 pp::Var var; |
195 void* object = | 195 void* object = |
196 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); | 196 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
197 if (object) | 197 if (object) |
198 var = static_cast<Instance*>(object)->GetLinkAtPosition(pp::Point(point)); | 198 var = static_cast<Instance*>(object)->GetLinkAtPosition(pp::Point(point)); |
199 return var.Detach(); | 199 return var.Detach(); |
200 } | 200 } |
201 | 201 |
202 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) { | 202 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) { |
203 void* object = | 203 void* object = |
204 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); | 204 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
205 if (object) { | 205 if (object) { |
206 Instance* obj_instance = static_cast<Instance*>(object); | 206 Instance* obj_instance = static_cast<Instance*>(object); |
207 switch (type) { | 207 switch (type) { |
208 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: | 208 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: |
209 obj_instance->RotateClockwise(); | 209 obj_instance->RotateClockwise(); |
210 break; | 210 break; |
211 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: | 211 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: |
212 obj_instance->RotateCounterclockwise(); | 212 obj_instance->RotateCounterclockwise(); |
213 break; | 213 break; |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 PP_Bool GetPrintPresetOptionsFromDocument(PP_Instance instance, | |
219 PP_PrintPresetOptions_Dev& options) { | |
220 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); | |
221 PP_Bool ret = PP_FALSE; | |
222 if (object) | |
223 ret = static_cast<Instance*>(object) | |
224 ->GetPrintPresetOptionsFromDocument(options); | |
dmichael (off chromium)
2014/09/22 18:11:51
The style here looks funny. I think normally we'd
Nikhil
2014/09/23 10:32:28
The style here was a result of "git cl format". I'
| |
225 return ret; | |
226 } | |
227 | |
218 const PPP_Pdf ppp_private = { | 228 const PPP_Pdf ppp_private = { |
219 &GetLinkAtPosition, | 229 &GetLinkAtPosition, |
220 &Transform | 230 &Transform, |
231 &GetPrintPresetOptionsFromDocument | |
221 }; | 232 }; |
222 | 233 |
223 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 234 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
224 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 235 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
225 std::vector<std::string> url_substr; | 236 std::vector<std::string> url_substr; |
226 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); | 237 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); |
227 if (url_substr.size() != 3) | 238 if (url_substr.size() != 3) |
228 return -1; | 239 return -1; |
229 | 240 |
230 if (url_substr[2] != "print.pdf") | 241 if (url_substr[2] != "print.pdf") |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 pp::Var Instance::GetInstanceObject() { | 656 pp::Var Instance::GetInstanceObject() { |
646 if (instance_object_.is_undefined()) { | 657 if (instance_object_.is_undefined()) { |
647 PDFScriptableObject* object = new PDFScriptableObject(this); | 658 PDFScriptableObject* object = new PDFScriptableObject(this); |
648 // The pp::Var takes ownership of object here. | 659 // The pp::Var takes ownership of object here. |
649 instance_object_ = pp::VarPrivate(this, object); | 660 instance_object_ = pp::VarPrivate(this, object); |
650 } | 661 } |
651 | 662 |
652 return instance_object_; | 663 return instance_object_; |
653 } | 664 } |
654 | 665 |
666 PP_Bool Instance::GetPrintPresetOptionsFromDocument( | |
667 PP_PrintPresetOptions_Dev& options) { | |
668 options.is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | |
669 options.copies = engine_->GetCopiesToPrint(); | |
670 | |
671 return PP_TRUE; | |
672 } | |
673 | |
655 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { | 674 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { |
656 pp::Point offset_point(point); | 675 pp::Point offset_point(point); |
657 ScalePoint(device_scale_, &offset_point); | 676 ScalePoint(device_scale_, &offset_point); |
658 offset_point.set_x(offset_point.x() - available_area_.x()); | 677 offset_point.set_x(offset_point.x() - available_area_.x()); |
659 return engine_->GetLinkAtPosition(offset_point); | 678 return engine_->GetLinkAtPosition(offset_point); |
660 } | 679 } |
661 | 680 |
662 pp::Var Instance::GetSelectedText(bool html) { | 681 pp::Var Instance::GetSelectedText(bool html) { |
663 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 682 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
664 return pp::Var(); | 683 return pp::Var(); |
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2751 return instance_->HasScriptableMethod(name, exception); | 2770 return instance_->HasScriptableMethod(name, exception); |
2752 } | 2771 } |
2753 | 2772 |
2754 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2773 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
2755 const std::vector<pp::Var>& args, | 2774 const std::vector<pp::Var>& args, |
2756 pp::Var* exception) { | 2775 pp::Var* exception) { |
2757 return instance_->CallScriptableMethod(method, args, exception); | 2776 return instance_->CallScriptableMethod(method, args, exception); |
2758 } | 2777 } |
2759 | 2778 |
2760 } // namespace chrome_pdf | 2779 } // namespace chrome_pdf |
OLD | NEW |