Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2267063002: PDF: Put back removed SetScrollPosition(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer; 580 FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer;
581 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime; 581 FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime;
582 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange; 582 FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange;
583 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage; 583 FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage;
584 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage; 584 FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage;
585 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation; 585 FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation;
586 FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction; 586 FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction;
587 FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus; 587 FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus;
588 FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction; 588 FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction;
589 FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction; 589 FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction;
590 #ifdef PDF_USE_XFA 590 #if defined(PDF_USE_XFA)
591 FPDF_FORMFILLINFO::version = 2; 591 FPDF_FORMFILLINFO::version = 2;
592 FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo; 592 FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo;
593 FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret; 593 FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret;
594 FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage; 594 FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage;
595 FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; 595 FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex;
596 FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; 596 FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect;
597 FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; 597 FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform;
598 FPDF_FORMFILLINFO::FFI_PageEvent = nullptr; 598 FPDF_FORMFILLINFO::FFI_PageEvent = nullptr;
599 FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; 599 FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu;
600 FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; 600 FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL;
601 FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; 601 FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL;
602 FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo; 602 FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo;
603 FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL; 603 FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL;
604 FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile; 604 FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile;
605 FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL; 605 FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL;
606 FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage; 606 FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage;
607 #endif // PDF_USE_XFA 607 #endif // defined(PDF_USE_XFA)
608 IPDF_JSPLATFORM::version = 3; 608 IPDF_JSPLATFORM::version = 3;
609 IPDF_JSPLATFORM::app_alert = Form_Alert; 609 IPDF_JSPLATFORM::app_alert = Form_Alert;
610 IPDF_JSPLATFORM::app_beep = Form_Beep; 610 IPDF_JSPLATFORM::app_beep = Form_Beep;
611 IPDF_JSPLATFORM::app_response = Form_Response; 611 IPDF_JSPLATFORM::app_response = Form_Response;
612 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath; 612 IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath;
613 IPDF_JSPLATFORM::Doc_mail = Form_Mail; 613 IPDF_JSPLATFORM::Doc_mail = Form_Mail;
614 IPDF_JSPLATFORM::Doc_print = Form_Print; 614 IPDF_JSPLATFORM::Doc_print = Form_Print;
615 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; 615 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm;
616 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; 616 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage;
617 IPDF_JSPLATFORM::Field_browse = Form_Browse; 617 IPDF_JSPLATFORM::Field_browse = Form_Browse;
(...skipping 10 matching lines...) Expand all
628 #endif 628 #endif
629 } 629 }
630 630
631 PDFiumEngine::~PDFiumEngine() { 631 PDFiumEngine::~PDFiumEngine() {
632 for (auto& page : pages_) 632 for (auto& page : pages_)
633 page->Unload(); 633 page->Unload();
634 634
635 if (doc_) { 635 if (doc_) {
636 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); 636 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC);
637 637
638 #ifdef PDF_USE_XFA 638 #if defined(PDF_USE_XFA)
639 // XFA may require |form_| to outlive |doc_|, so shut down in that order. 639 // XFA may require |form_| to outlive |doc_|, so shut down in that order.
640 FPDF_CloseDocument(doc_); 640 FPDF_CloseDocument(doc_);
641 FPDFDOC_ExitFormFillEnvironment(form_); 641 FPDFDOC_ExitFormFillEnvironment(form_);
642 #else 642 #else
643 // Normally |doc_| should outlive |form_|. 643 // Normally |doc_| should outlive |form_|.
644 FPDFDOC_ExitFormFillEnvironment(form_); 644 FPDFDOC_ExitFormFillEnvironment(form_);
645 FPDF_CloseDocument(doc_); 645 FPDF_CloseDocument(doc_);
646 #endif 646 #endif
647 } 647 }
648 FPDFAvail_Destroy(fpdf_availability_); 648 FPDFAvail_Destroy(fpdf_availability_);
649 649
650 base::STLDeleteElements(&pages_); 650 base::STLDeleteElements(&pages_);
651 } 651 }
652 652
653 #ifdef PDF_USE_XFA 653 #if defined(PDF_USE_XFA)
654 654
655 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param, 655 void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* param,
656 FPDF_FILEHANDLER* file_handler, 656 FPDF_FILEHANDLER* file_handler,
657 FPDF_WIDESTRING to, 657 FPDF_WIDESTRING to,
658 FPDF_WIDESTRING subject, 658 FPDF_WIDESTRING subject,
659 FPDF_WIDESTRING cc, 659 FPDF_WIDESTRING cc,
660 FPDF_WIDESTRING bcc, 660 FPDF_WIDESTRING bcc,
661 FPDF_WIDESTRING message) { 661 FPDF_WIDESTRING message) {
662 std::string to_str = 662 std::string to_str =
663 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to)); 663 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); 825 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url));
826 // TODO: needs to implement GOTO URL action 826 // TODO: needs to implement GOTO URL action
827 } 827 }
828 828
829 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param, 829 int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* param,
830 void* language, 830 void* language,
831 int length) { 831 int length) {
832 return 0; 832 return 0;
833 } 833 }
834 834
835 #endif // PDF_USE_XFA 835 #endif // defined(PDF_USE_XFA)
836 836
837 int PDFiumEngine::GetBlock(void* param, unsigned long position, 837 int PDFiumEngine::GetBlock(void* param, unsigned long position,
838 unsigned char* buffer, unsigned long size) { 838 unsigned char* buffer, unsigned long size) {
839 DocumentLoader* loader = static_cast<DocumentLoader*>(param); 839 DocumentLoader* loader = static_cast<DocumentLoader*>(param);
840 return loader->GetBlock(position, size, buffer); 840 return loader->GetBlock(position, size, buffer);
841 } 841 }
842 842
843 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param, 843 FPDF_BOOL PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param,
844 size_t offset, size_t size) { 844 size_t offset, size_t size) {
845 PDFiumEngine::FileAvail* file_avail = 845 PDFiumEngine::FileAvail* file_avail =
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 FPDF_ImportPages(doc_, 1006 FPDF_ImportPages(doc_,
1007 static_cast<PDFiumEngine*>(engine)->doc(), 1007 static_cast<PDFiumEngine*>(engine)->doc(),
1008 "1", 1008 "1",
1009 index); 1009 index);
1010 pp::Size new_page_size = GetPageSize(index); 1010 pp::Size new_page_size = GetPageSize(index);
1011 if (curr_page_size != new_page_size) 1011 if (curr_page_size != new_page_size)
1012 LoadPageInfo(true); 1012 LoadPageInfo(true);
1013 client_->Invalidate(GetPageScreenRect(index)); 1013 client_->Invalidate(GetPageScreenRect(index));
1014 } 1014 }
1015 1015
1016 #if defined(PDF_USE_XFA)
1017 void PDFiumEngine::SetScrollPosition(const pp::Point& position) {
1018 position_ = position;
1019 }
1020 #endif
1021
1016 bool PDFiumEngine::IsProgressiveLoad() { 1022 bool PDFiumEngine::IsProgressiveLoad() {
1017 return doc_loader_.is_partial_document(); 1023 return doc_loader_.is_partial_document();
1018 } 1024 }
1019 1025
1020 std::string PDFiumEngine::GetMetadata(const std::string& key) { 1026 std::string PDFiumEngine::GetMetadata(const std::string& key) {
1021 return GetDocumentMetadata(doc(), key); 1027 return GetDocumentMetadata(doc(), key);
1022 } 1028 }
1023 1029
1024 void PDFiumEngine::OnPartialDocumentLoaded() { 1030 void PDFiumEngine::OnPartialDocumentLoaded() {
1025 file_access_.m_FileLen = doc_loader_.document_size(); 1031 file_access_.m_FileLen = doc_loader_.document_size();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN); 1118 FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN);
1113 } 1119 }
1114 1120
1115 if (doc_) // This can only happen if loading |doc_| fails. 1121 if (doc_) // This can only happen if loading |doc_| fails.
1116 client_->DocumentLoadComplete(pages_.size()); 1122 client_->DocumentLoadComplete(pages_.size());
1117 } 1123 }
1118 1124
1119 void PDFiumEngine::UnsupportedFeature(int type) { 1125 void PDFiumEngine::UnsupportedFeature(int type) {
1120 std::string feature; 1126 std::string feature;
1121 switch (type) { 1127 switch (type) {
1122 #ifndef PDF_USE_XFA 1128 #if !defined(PDF_USE_XFA)
1123 case FPDF_UNSP_DOC_XFAFORM: 1129 case FPDF_UNSP_DOC_XFAFORM:
1124 feature = "XFA"; 1130 feature = "XFA";
1125 break; 1131 break;
1126 #endif 1132 #endif
1127 case FPDF_UNSP_DOC_PORTABLECOLLECTION: 1133 case FPDF_UNSP_DOC_PORTABLECOLLECTION:
1128 feature = "Portfolios_Packages"; 1134 feature = "Portfolios_Packages";
1129 break; 1135 break;
1130 case FPDF_UNSP_DOC_ATTACHMENT: 1136 case FPDF_UNSP_DOC_ATTACHMENT:
1131 case FPDF_UNSP_ANNOT_ATTACHMENT: 1137 case FPDF_UNSP_ANNOT_ATTACHMENT:
1132 feature = "Attachment"; 1138 feature = "Attachment";
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 last_page_mouse_down_ = page_index; 1561 last_page_mouse_down_ = page_index;
1556 double page_x, page_y; 1562 double page_x, page_y;
1557 pp::Point point = event.GetPosition(); 1563 pp::Point point = event.GetPosition();
1558 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1564 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1559 1565
1560 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1566 FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1561 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes... 1567 if (form_type > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes...
1562 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target); 1568 mouse_down_state_.Set(PDFiumPage::NONSELECTABLE_AREA, target);
1563 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD || 1569 bool is_valid_control = (form_type == FPDF_FORMFIELD_TEXTFIELD ||
1564 form_type == FPDF_FORMFIELD_COMBOBOX); 1570 form_type == FPDF_FORMFIELD_COMBOBOX);
1565 #ifdef PDF_USE_XFA 1571 #if defined(PDF_USE_XFA)
1566 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA); 1572 is_valid_control |= (form_type == FPDF_FORMFIELD_XFA);
1567 #endif 1573 #endif
1568 client_->FormTextFieldFocusChange(is_valid_control); 1574 client_->FormTextFieldFocusChange(is_valid_control);
1569 return true; // Return now before we get into the selection code. 1575 return true; // Return now before we get into the selection code.
1570 } 1576 }
1571 } 1577 }
1572 1578
1573 client_->FormTextFieldFocusChange(false); 1579 client_->FormTextFieldFocusChange(false);
1574 1580
1575 if (area != PDFiumPage::TEXT_AREA) 1581 if (area != PDFiumPage::TEXT_AREA)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index); 1618 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index);
1613 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t'))) 1619 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t')))
1614 break; 1620 break;
1615 } 1621 }
1616 1622
1617 selection_.push_back(PDFiumRange( 1623 selection_.push_back(PDFiumRange(
1618 pages_[page_index], start_index, end_index - start_index)); 1624 pages_[page_index], start_index, end_index - start_index));
1619 } 1625 }
1620 1626
1621 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { 1627 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
1622
1623 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT && 1628 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1624 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) { 1629 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1625 return false; 1630 return false;
1626 } 1631 }
1627 1632
1628 int page_index = -1; 1633 int page_index = -1;
1629 int char_index = -1; 1634 int char_index = -1;
1630 int form_type = FPDF_FORMFIELD_UNKNOWN; 1635 int form_type = FPDF_FORMFIELD_UNKNOWN;
1631 PDFiumPage::LinkTarget target; 1636 PDFiumPage::LinkTarget target;
1632 PDFiumPage::Area area = 1637 PDFiumPage::Area area =
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 int form_status = 2525 int form_status =
2521 FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_); 2526 FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_);
2522 bool doc_complete = doc_loader_.IsDocumentComplete(); 2527 bool doc_complete = doc_loader_.IsDocumentComplete();
2523 // Try again if the data is not available and the document hasn't finished 2528 // Try again if the data is not available and the document hasn't finished
2524 // downloading. 2529 // downloading.
2525 if (form_status == PDF_FORM_NOTAVAIL && !doc_complete) 2530 if (form_status == PDF_FORM_NOTAVAIL && !doc_complete)
2526 return; 2531 return;
2527 2532
2528 form_ = FPDFDOC_InitFormFillEnvironment( 2533 form_ = FPDFDOC_InitFormFillEnvironment(
2529 doc_, static_cast<FPDF_FORMFILLINFO*>(this)); 2534 doc_, static_cast<FPDF_FORMFILLINFO*>(this));
2530 #ifdef PDF_USE_XFA 2535 #if defined(PDF_USE_XFA)
2531 FPDF_LoadXFA(doc_); 2536 FPDF_LoadXFA(doc_);
2532 #endif 2537 #endif
2533 2538
2534 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor); 2539 FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor);
2535 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha); 2540 FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha);
2536 } 2541 }
2537 2542
2538 if (!doc_loader_.IsDocumentComplete()) { 2543 if (!doc_loader_.IsDocumentComplete()) {
2539 // Check if the first page is available. In a linearized PDF, that is not 2544 // Check if the first page is available. In a linearized PDF, that is not
2540 // always page 0. Doing this gives us the default page size, since when the 2545 // always page 0. Doing this gives us the default page size, since when the
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3910 FPDF_DOCUMENT doc = 3915 FPDF_DOCUMENT doc =
3911 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3916 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3912 if (!doc) 3917 if (!doc)
3913 return false; 3918 return false;
3914 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3919 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3915 FPDF_CloseDocument(doc); 3920 FPDF_CloseDocument(doc);
3916 return success; 3921 return success;
3917 } 3922 }
3918 3923
3919 } // namespace chrome_pdf 3924 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698