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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: | 158 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: |
159 obj_instance->RotateClockwise(); | 159 obj_instance->RotateClockwise(); |
160 break; | 160 break; |
161 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: | 161 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: |
162 obj_instance->RotateCounterclockwise(); | 162 obj_instance->RotateCounterclockwise(); |
163 break; | 163 break; |
164 } | 164 } |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
| 168 PP_Bool GetPrintPresetOptionsFromDocument( |
| 169 PP_Instance instance, |
| 170 PP_PdfPrintPresetOptions_Dev* options) { |
| 171 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
| 172 if (object) { |
| 173 OutOfProcessInstance* obj_instance = |
| 174 static_cast<OutOfProcessInstance*>(object); |
| 175 obj_instance->GetPrintPresetOptionsFromDocument(options); |
| 176 } |
| 177 return PP_TRUE; |
| 178 } |
| 179 |
168 const PPP_Pdf ppp_private = { | 180 const PPP_Pdf ppp_private = { |
169 &GetLinkAtPosition, | 181 &GetLinkAtPosition, |
170 &Transform | 182 &Transform, |
| 183 &GetPrintPresetOptionsFromDocument |
171 }; | 184 }; |
172 | 185 |
173 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 186 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
174 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 187 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
175 std::vector<std::string> url_substr; | 188 std::vector<std::string> url_substr; |
176 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); | 189 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); |
177 if (url_substr.size() != 3) | 190 if (url_substr.size() != 3) |
178 return -1; | 191 return -1; |
179 | 192 |
180 if (url_substr[2] != "print.pdf") | 193 if (url_substr[2] != "print.pdf") |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 } | 543 } |
531 | 544 |
532 if (!stop_scrolling_) { | 545 if (!stop_scrolling_) { |
533 pp::Point scroll_offset( | 546 pp::Point scroll_offset( |
534 BoundScrollOffsetToDocument(view.GetScrollOffset())); | 547 BoundScrollOffsetToDocument(view.GetScrollOffset())); |
535 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); | 548 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); |
536 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); | 549 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); |
537 } | 550 } |
538 } | 551 } |
539 | 552 |
| 553 void OutOfProcessInstance::GetPrintPresetOptionsFromDocument( |
| 554 PP_PdfPrintPresetOptions_Dev* options) { |
| 555 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 556 options->copies = engine_->GetCopiesToPrint(); |
| 557 } |
| 558 |
540 pp::Var OutOfProcessInstance::GetLinkAtPosition( | 559 pp::Var OutOfProcessInstance::GetLinkAtPosition( |
541 const pp::Point& point) { | 560 const pp::Point& point) { |
542 pp::Point offset_point(point); | 561 pp::Point offset_point(point); |
543 ScalePoint(device_scale_, &offset_point); | 562 ScalePoint(device_scale_, &offset_point); |
544 offset_point.set_x(offset_point.x() - available_area_.x()); | 563 offset_point.set_x(offset_point.x() - available_area_.x()); |
545 return engine_->GetLinkAtPosition(offset_point); | 564 return engine_->GetLinkAtPosition(offset_point); |
546 } | 565 } |
547 | 566 |
548 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { | 567 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { |
549 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) | 568 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( | 1379 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( |
1361 const pp::Point& scroll_offset) { | 1380 const pp::Point& scroll_offset) { |
1362 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1381 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
1363 int x = std::max(std::min(scroll_offset.x(), max_x), 0); | 1382 int x = std::max(std::min(scroll_offset.x(), max_x), 0); |
1364 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1383 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
1365 int y = std::max(std::min(scroll_offset.y(), max_y), 0); | 1384 int y = std::max(std::min(scroll_offset.y(), max_y), 0); |
1366 return pp::Point(x, y); | 1385 return pp::Point(x, y); |
1367 } | 1386 } |
1368 | 1387 |
1369 } // namespace chrome_pdf | 1388 } // namespace chrome_pdf |
OLD | NEW |