| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> // for min/max() | 10 #include <algorithm> // for min/max() |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 PP_PdfPrintPresetOptions_Dev* options) { | 199 PP_PdfPrintPresetOptions_Dev* options) { |
| 200 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); | 200 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
| 201 if (object) { | 201 if (object) { |
| 202 OutOfProcessInstance* obj_instance = | 202 OutOfProcessInstance* obj_instance = |
| 203 static_cast<OutOfProcessInstance*>(object); | 203 static_cast<OutOfProcessInstance*>(object); |
| 204 obj_instance->GetPrintPresetOptionsFromDocument(options); | 204 obj_instance->GetPrintPresetOptionsFromDocument(options); |
| 205 } | 205 } |
| 206 return PP_TRUE; | 206 return PP_TRUE; |
| 207 } | 207 } |
| 208 | 208 |
| 209 void EnableAccessibility(PP_Instance instance) { |
| 210 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); |
| 211 if (object) { |
| 212 OutOfProcessInstance* obj_instance = |
| 213 static_cast<OutOfProcessInstance*>(object); |
| 214 return obj_instance->EnableAccessibility(); |
| 215 } |
| 216 } |
| 217 |
| 209 const PPP_Pdf ppp_private = { | 218 const PPP_Pdf ppp_private = { |
| 210 &GetLinkAtPosition, | 219 &GetLinkAtPosition, |
| 211 &Transform, | 220 &Transform, |
| 212 &GetPrintPresetOptionsFromDocument | 221 &GetPrintPresetOptionsFromDocument, |
| 222 &EnableAccessibility, |
| 213 }; | 223 }; |
| 214 | 224 |
| 215 int ExtractPrintPreviewPageIndex(const std::string& src_url) { | 225 int ExtractPrintPreviewPageIndex(const std::string& src_url) { |
| 216 // Sample |src_url| format: chrome://print/id/page_index/print.pdf | 226 // Sample |src_url| format: chrome://print/id/page_index/print.pdf |
| 217 std::vector<std::string> url_substr = base::SplitString( | 227 std::vector<std::string> url_substr = base::SplitString( |
| 218 src_url.substr(strlen(kChromePrint)), "/", | 228 src_url.substr(strlen(kChromePrint)), "/", |
| 219 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 229 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 220 if (url_substr.size() != 3) | 230 if (url_substr.size() != 3) |
| 221 return -1; | 231 return -1; |
| 222 | 232 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); | 617 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 608 options->duplex = | 618 options->duplex = |
| 609 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); | 619 static_cast<PP_PrivateDuplexMode_Dev>(engine_->GetDuplexType()); |
| 610 options->copies = engine_->GetCopiesToPrint(); | 620 options->copies = engine_->GetCopiesToPrint(); |
| 611 pp::Size uniform_page_size; | 621 pp::Size uniform_page_size; |
| 612 options->is_page_size_uniform = | 622 options->is_page_size_uniform = |
| 613 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); | 623 PP_FromBool(engine_->GetPageSizeAndUniformity(&uniform_page_size)); |
| 614 options->uniform_page_size = uniform_page_size; | 624 options->uniform_page_size = uniform_page_size; |
| 615 } | 625 } |
| 616 | 626 |
| 627 void OutOfProcessInstance::EnableAccessibility() { |
| 628 engine_->EnableAccessibility(); |
| 629 } |
| 630 |
| 617 pp::Var OutOfProcessInstance::GetLinkAtPosition( | 631 pp::Var OutOfProcessInstance::GetLinkAtPosition( |
| 618 const pp::Point& point) { | 632 const pp::Point& point) { |
| 619 pp::Point offset_point(point); | 633 pp::Point offset_point(point); |
| 620 ScalePoint(device_scale_, &offset_point); | 634 ScalePoint(device_scale_, &offset_point); |
| 621 offset_point.set_x(offset_point.x() - available_area_.x()); | 635 offset_point.set_x(offset_point.x() - available_area_.x()); |
| 622 return engine_->GetLinkAtPosition(offset_point); | 636 return engine_->GetLinkAtPosition(offset_point); |
| 623 } | 637 } |
| 624 | 638 |
| 625 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() { | 639 uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() { |
| 626 return engine_->QuerySupportedPrintOutputFormats(); | 640 return engine_->QuerySupportedPrintOutputFormats(); |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 return background_color_; | 1401 return background_color_; |
| 1388 } | 1402 } |
| 1389 | 1403 |
| 1390 void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) { | 1404 void OutOfProcessInstance::IsSelectingChanged(bool is_selecting) { |
| 1391 pp::VarDictionary message; | 1405 pp::VarDictionary message; |
| 1392 message.Set(kType, kJSSetIsSelectingType); | 1406 message.Set(kType, kJSSetIsSelectingType); |
| 1393 message.Set(kJSIsSelecting, pp::Var(is_selecting)); | 1407 message.Set(kJSIsSelecting, pp::Var(is_selecting)); |
| 1394 PostMessage(message); | 1408 PostMessage(message); |
| 1395 } | 1409 } |
| 1396 | 1410 |
| 1411 int OutOfProcessInstance::GetToolbarHeight() { |
| 1412 return top_toolbar_height_ * device_scale_; |
| 1413 } |
| 1414 |
| 1397 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, | 1415 void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url, |
| 1398 int dst_page_index) { | 1416 int dst_page_index) { |
| 1399 if (!IsPrintPreview()) | 1417 if (!IsPrintPreview()) |
| 1400 return; | 1418 return; |
| 1401 | 1419 |
| 1402 int src_page_index = ExtractPrintPreviewPageIndex(url); | 1420 int src_page_index = ExtractPrintPreviewPageIndex(url); |
| 1403 if (src_page_index < 1) | 1421 if (src_page_index < 1) |
| 1404 return; | 1422 return; |
| 1405 | 1423 |
| 1406 preview_pages_info_.push(std::make_pair(url, dst_page_index)); | 1424 preview_pages_info_.push(std::make_pair(url, dst_page_index)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1436 const pp::FloatPoint& scroll_offset) { | 1454 const pp::FloatPoint& scroll_offset) { |
| 1437 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1455 float max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1438 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); | 1456 float x = std::max(std::min(scroll_offset.x(), max_x), 0.0f); |
| 1439 float min_y = -top_toolbar_height_; | 1457 float min_y = -top_toolbar_height_; |
| 1440 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1458 float max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1441 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); | 1459 float y = std::max(std::min(scroll_offset.y(), max_y), min_y); |
| 1442 return pp::FloatPoint(x, y); | 1460 return pp::FloatPoint(x, y); |
| 1443 } | 1461 } |
| 1444 | 1462 |
| 1445 } // namespace chrome_pdf | 1463 } // namespace chrome_pdf |
| OLD | NEW |