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/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_1_1; |
| 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 Instance* obj_instance = static_cast<Instance*>(object); | |
| 224 ret = obj_instance->GetPrintPresetOptionsFromDocument(options); | |
| 225 } | |
| 226 return ret; | |
| 227 } | |
| 228 | |
| 218 const PPP_Pdf ppp_private = { | 229 const PPP_Pdf ppp_private = { |
| 219 &GetLinkAtPosition, | 230 &GetLinkAtPosition, |
| 220 &Transform | 231 &Transform, |
| 232 &GetPrintPresetOptionsFromDocument | |
| 221 }; | 233 }; |
| 222 | 234 |
| 223 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 235 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
| 224 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 236 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
| 225 std::vector<std::string> url_substr; | 237 std::vector<std::string> url_substr; |
| 226 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); | 238 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); |
| 227 if (url_substr.size() != 3) | 239 if (url_substr.size() != 3) |
| 228 return -1; | 240 return -1; |
| 229 | 241 |
| 230 if (url_substr[2] != "print.pdf") | 242 if (url_substr[2] != "print.pdf") |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 pp::Var Instance::GetInstanceObject() { | 657 pp::Var Instance::GetInstanceObject() { |
| 646 if (instance_object_.is_undefined()) { | 658 if (instance_object_.is_undefined()) { |
| 647 PDFScriptableObject* object = new PDFScriptableObject(this); | 659 PDFScriptableObject* object = new PDFScriptableObject(this); |
| 648 // The pp::Var takes ownership of object here. | 660 // The pp::Var takes ownership of object here. |
| 649 instance_object_ = pp::VarPrivate(this, object); | 661 instance_object_ = pp::VarPrivate(this, object); |
| 650 } | 662 } |
| 651 | 663 |
| 652 return instance_object_; | 664 return instance_object_; |
| 653 } | 665 } |
| 654 | 666 |
| 667 PP_Bool Instance::GetPrintPresetOptionsFromDocument( | |
| 668 PP_PrintPresetOptions_Dev* options) { | |
| 669 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | |
| 670 options->copies = engine_->GetCopiesToPrint(); | |
| 671 | |
| 672 return PP_TRUE; | |
|
raymes
2014/09/24 04:54:39
If the return value is always PP_TRUE, we might as
Nikhil
2014/09/29 11:15:30
I think it can be removed. I'm not sure about beha
raymes
2014/10/01 17:26:23
If you want to keep the PP_Bool in the API, that's
Nikhil
2014/10/07 09:53:37
Done.
| |
| 673 } | |
| 674 | |
| 655 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { | 675 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { |
| 656 pp::Point offset_point(point); | 676 pp::Point offset_point(point); |
| 657 ScalePoint(device_scale_, &offset_point); | 677 ScalePoint(device_scale_, &offset_point); |
| 658 offset_point.set_x(offset_point.x() - available_area_.x()); | 678 offset_point.set_x(offset_point.x() - available_area_.x()); |
| 659 return engine_->GetLinkAtPosition(offset_point); | 679 return engine_->GetLinkAtPosition(offset_point); |
| 660 } | 680 } |
| 661 | 681 |
| 662 pp::Var Instance::GetSelectedText(bool html) { | 682 pp::Var Instance::GetSelectedText(bool html) { |
| 663 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 683 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
| 664 return pp::Var(); | 684 return pp::Var(); |
| (...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2751 return instance_->HasScriptableMethod(name, exception); | 2771 return instance_->HasScriptableMethod(name, exception); |
| 2752 } | 2772 } |
| 2753 | 2773 |
| 2754 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2774 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
| 2755 const std::vector<pp::Var>& args, | 2775 const std::vector<pp::Var>& args, |
| 2756 pp::Var* exception) { | 2776 pp::Var* exception) { |
| 2757 return instance_->CallScriptableMethod(method, args, exception); | 2777 return instance_->CallScriptableMethod(method, args, exception); |
| 2758 } | 2778 } |
| 2759 | 2779 |
| 2760 } // namespace chrome_pdf | 2780 } // namespace chrome_pdf |
| OLD | NEW |