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/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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; | 602 IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm; |
603 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; | 603 IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage; |
604 IPDF_JSPLATFORM::Field_browse = Form_Browse; | 604 IPDF_JSPLATFORM::Field_browse = Form_Browse; |
605 | 605 |
606 IFSDK_PAUSE::version = 1; | 606 IFSDK_PAUSE::version = 1; |
607 IFSDK_PAUSE::user = NULL; | 607 IFSDK_PAUSE::user = NULL; |
608 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; | 608 IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow; |
609 } | 609 } |
610 | 610 |
611 PDFiumEngine::~PDFiumEngine() { | 611 PDFiumEngine::~PDFiumEngine() { |
612 for (size_t i = 0; i < pages_.size(); ++i) | 612 for (auto& page : pages_) |
613 pages_[i]->Unload(); | 613 page->Unload(); |
614 | 614 |
615 if (doc_) { | 615 if (doc_) { |
616 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); | 616 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC); |
617 | 617 |
618 #ifdef PDF_USE_XFA | 618 #ifdef PDF_USE_XFA |
619 // XFA may require |form_| to outlive |doc_|, so shut down in that order. | 619 // XFA may require |form_| to outlive |doc_|, so shut down in that order. |
620 FPDF_CloseDocument(doc_); | 620 FPDF_CloseDocument(doc_); |
621 FPDFDOC_ExitFormFillEnvironment(form_); | 621 FPDFDOC_ExitFormFillEnvironment(form_); |
622 #else | 622 #else |
623 // Normally |doc_| should outlive |form_|. | 623 // Normally |doc_| should outlive |form_|. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 file_wrapper->file_handler.Truncate = Sample_Truncate; | 875 file_wrapper->file_handler.Truncate = Sample_Truncate; |
876 file_wrapper->file_handler.WriteBlock = Sample_WriteBlock; | 876 file_wrapper->file_handler.WriteBlock = Sample_WriteBlock; |
877 | 877 |
878 return &file_wrapper->file_handler; | 878 return &file_wrapper->file_handler; |
879 } | 879 } |
880 | 880 |
881 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, | 881 FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* param, |
882 int file_flag, | 882 int file_flag, |
883 FPDF_WIDESTRING url, | 883 FPDF_WIDESTRING url, |
884 const char* mode) { | 884 const char* mode) { |
885 std::string url_str = "NULL"; | 885 std::string url_str = url ? |
886 if (url != NULL) { | 886 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)) : "NULL"; |
887 url_str = | 887 |
888 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | |
889 } | |
890 // TODO: need to implement open file from the url | 888 // TODO: need to implement open file from the url |
891 // Use a file path for the ease of testing | 889 // Use a file path for the ease of testing |
892 FILE* file = fopen(XFA_TESTFILE("tem.txt"), mode); | 890 FILE* file = fopen(XFA_TESTFILE("tem.txt"), mode); |
893 FPDF_FILE* file_wrapper = new FPDF_FILE; | 891 FPDF_FILE* file_wrapper = new FPDF_FILE; |
894 file_wrapper->file = file; | 892 file_wrapper->file = file; |
895 file_wrapper->file_handler.clientData = file_wrapper; | 893 file_wrapper->file_handler.clientData = file_wrapper; |
896 file_wrapper->file_handler.Flush = Sample_Flush; | 894 file_wrapper->file_handler.Flush = Sample_Flush; |
897 file_wrapper->file_handler.GetSize = Sample_GetSize; | 895 file_wrapper->file_handler.GetSize = Sample_GetSize; |
898 file_wrapper->file_handler.ReadBlock = Sample_ReadBlock; | 896 file_wrapper->file_handler.ReadBlock = Sample_ReadBlock; |
899 file_wrapper->file_handler.Release = Sample_Release; | 897 file_wrapper->file_handler.Release = Sample_Release; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 void PDFiumEngine::ScrolledToYPosition(int position) { | 969 void PDFiumEngine::ScrolledToYPosition(int position) { |
972 CancelPaints(); | 970 CancelPaints(); |
973 | 971 |
974 int old_y = position_.y(); | 972 int old_y = position_.y(); |
975 position_.set_y(position); | 973 position_.set_y(position); |
976 CalculateVisiblePages(); | 974 CalculateVisiblePages(); |
977 client_->Scroll(pp::Point(0, old_y - position)); | 975 client_->Scroll(pp::Point(0, old_y - position)); |
978 } | 976 } |
979 | 977 |
980 void PDFiumEngine::PrePaint() { | 978 void PDFiumEngine::PrePaint() { |
981 for (size_t i = 0; i < progressive_paints_.size(); ++i) | 979 for (auto& paint : progressive_paints_) |
982 progressive_paints_[i].painted_ = false; | 980 paint.painted_ = false; |
983 } | 981 } |
984 | 982 |
985 void PDFiumEngine::Paint(const pp::Rect& rect, | 983 void PDFiumEngine::Paint(const pp::Rect& rect, |
986 pp::ImageData* image_data, | 984 pp::ImageData* image_data, |
987 std::vector<pp::Rect>* ready, | 985 std::vector<pp::Rect>* ready, |
988 std::vector<pp::Rect>* pending) { | 986 std::vector<pp::Rect>* pending) { |
989 DCHECK(image_data); | 987 DCHECK(image_data); |
990 DCHECK(ready); | 988 DCHECK(ready); |
991 DCHECK(pending); | 989 DCHECK(pending); |
992 | 990 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 void PDFiumEngine::OnPendingRequestComplete() { | 1130 void PDFiumEngine::OnPendingRequestComplete() { |
1133 if (!doc_ || !form_) { | 1131 if (!doc_ || !form_) { |
1134 LoadDocument(); | 1132 LoadDocument(); |
1135 return; | 1133 return; |
1136 } | 1134 } |
1137 | 1135 |
1138 // LoadDocument() will result in |pending_pages_| being reset so there's no | 1136 // LoadDocument() will result in |pending_pages_| being reset so there's no |
1139 // need to run the code below in that case. | 1137 // need to run the code below in that case. |
1140 bool update_pages = false; | 1138 bool update_pages = false; |
1141 std::vector<int> still_pending; | 1139 std::vector<int> still_pending; |
1142 for (size_t i = 0; i < pending_pages_.size(); ++i) { | 1140 for (int pending_page : pending_pages_) { |
1143 if (CheckPageAvailable(pending_pages_[i], &still_pending)) { | 1141 if (CheckPageAvailable(pending_page, &still_pending)) { |
1144 update_pages = true; | 1142 update_pages = true; |
1145 if (IsPageVisible(pending_pages_[i])) | 1143 if (IsPageVisible(pending_page)) |
1146 client_->Invalidate(GetPageScreenRect(pending_pages_[i])); | 1144 client_->Invalidate(GetPageScreenRect(pending_page)); |
1147 } | 1145 } |
1148 } | 1146 } |
1149 pending_pages_.swap(still_pending); | 1147 pending_pages_.swap(still_pending); |
1150 if (update_pages) | 1148 if (update_pages) |
1151 LoadPageInfo(true); | 1149 LoadPageInfo(true); |
1152 } | 1150 } |
1153 | 1151 |
1154 void PDFiumEngine::OnNewDataAvailable() { | 1152 void PDFiumEngine::OnNewDataAvailable() { |
1155 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), | 1153 client_->DocumentLoadProgress(doc_loader_.GetAvailableData(), |
1156 doc_loader_.document_size()); | 1154 doc_loader_.document_size()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 break; | 1271 break; |
1274 case PP_INPUTEVENT_TYPE_CHAR: | 1272 case PP_INPUTEVENT_TYPE_CHAR: |
1275 rv = OnChar(pp::KeyboardInputEvent(event)); | 1273 rv = OnChar(pp::KeyboardInputEvent(event)); |
1276 break; | 1274 break; |
1277 default: | 1275 default: |
1278 break; | 1276 break; |
1279 } | 1277 } |
1280 | 1278 |
1281 DCHECK(defer_page_unload_); | 1279 DCHECK(defer_page_unload_); |
1282 defer_page_unload_ = false; | 1280 defer_page_unload_ = false; |
1283 for (size_t i = 0; i < deferred_page_unloads_.size(); ++i) | 1281 for (int page_index : deferred_page_unloads_) |
1284 pages_[deferred_page_unloads_[i]]->Unload(); | 1282 pages_[page_index]->Unload(); |
1285 deferred_page_unloads_.clear(); | 1283 deferred_page_unloads_.clear(); |
1286 return rv; | 1284 return rv; |
1287 } | 1285 } |
1288 | 1286 |
1289 uint32_t PDFiumEngine::QuerySupportedPrintOutputFormats() { | 1287 uint32_t PDFiumEngine::QuerySupportedPrintOutputFormats() { |
1290 if (!HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) | 1288 if (!HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY)) |
1291 return 0; | 1289 return 0; |
1292 return PP_PRINTOUTPUTFORMAT_PDF; | 1290 return PP_PRINTOUTPUTFORMAT_PDF; |
1293 } | 1291 } |
1294 | 1292 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 return pp::Buffer_Dev(); | 1380 return pp::Buffer_Dev(); |
1383 | 1381 |
1384 SaveSelectedFormForPrint(); | 1382 SaveSelectedFormForPrint(); |
1385 | 1383 |
1386 std::vector<PDFiumPage> pages_to_print; | 1384 std::vector<PDFiumPage> pages_to_print; |
1387 // width and height of source PDF pages. | 1385 // width and height of source PDF pages. |
1388 std::vector<std::pair<double, double> > source_page_sizes; | 1386 std::vector<std::pair<double, double> > source_page_sizes; |
1389 // Collect pages to print and sizes of source pages. | 1387 // Collect pages to print and sizes of source pages. |
1390 std::vector<uint32_t> page_numbers = | 1388 std::vector<uint32_t> page_numbers = |
1391 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); | 1389 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); |
1392 for (size_t i = 0; i < page_numbers.size(); ++i) { | 1390 for (uint32_t page_number : page_numbers) { |
1393 uint32_t page_number = page_numbers[i]; | |
1394 FPDF_PAGE pdf_page = FPDF_LoadPage(doc_, page_number); | 1391 FPDF_PAGE pdf_page = FPDF_LoadPage(doc_, page_number); |
1395 double source_page_width = FPDF_GetPageWidth(pdf_page); | 1392 double source_page_width = FPDF_GetPageWidth(pdf_page); |
1396 double source_page_height = FPDF_GetPageHeight(pdf_page); | 1393 double source_page_height = FPDF_GetPageHeight(pdf_page); |
1397 source_page_sizes.push_back(std::make_pair(source_page_width, | 1394 source_page_sizes.push_back(std::make_pair(source_page_width, |
1398 source_page_height)); | 1395 source_page_height)); |
1399 | 1396 |
1400 int width_in_pixels = ConvertUnit(source_page_width, | 1397 int width_in_pixels = ConvertUnit(source_page_width, |
1401 kPointsPerInch, | 1398 kPointsPerInch, |
1402 print_settings.dpi); | 1399 print_settings.dpi); |
1403 int height_in_pixels = ConvertUnit(source_page_height, | 1400 int height_in_pixels = ConvertUnit(source_page_height, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 if (page_ranges[index].first_page_number != | 1493 if (page_ranges[index].first_page_number != |
1497 page_ranges[index].last_page_number) { | 1494 page_ranges[index].last_page_number) { |
1498 page_number_str.append("-"); | 1495 page_number_str.append("-"); |
1499 page_number_str.append( | 1496 page_number_str.append( |
1500 base::UintToString(page_ranges[index].last_page_number + 1)); | 1497 base::UintToString(page_ranges[index].last_page_number + 1)); |
1501 } | 1498 } |
1502 } | 1499 } |
1503 | 1500 |
1504 std::vector<uint32_t> page_numbers = | 1501 std::vector<uint32_t> page_numbers = |
1505 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); | 1502 GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count); |
1506 for (size_t i = 0; i < page_numbers.size(); ++i) { | 1503 for (uint32_t page_number : page_numbers) { |
1507 uint32_t page_number = page_numbers[i]; | |
1508 pages_[page_number]->GetPage(); | 1504 pages_[page_number]->GetPage(); |
1509 if (!IsPageVisible(page_numbers[i])) | 1505 if (!IsPageVisible(page_number)) |
1510 pages_[page_number]->Unload(); | 1506 pages_[page_number]->Unload(); |
1511 } | 1507 } |
1512 | 1508 |
1513 FPDF_CopyViewerPreferences(output_doc, doc_); | 1509 FPDF_CopyViewerPreferences(output_doc, doc_); |
1514 if (!FPDF_ImportPages(output_doc, doc_, page_number_str.c_str(), 0)) { | 1510 if (!FPDF_ImportPages(output_doc, doc_, page_number_str.c_str(), 0)) { |
1515 FPDF_CloseDocument(output_doc); | 1511 FPDF_CloseDocument(output_doc); |
1516 return pp::Buffer_Dev(); | 1512 return pp::Buffer_Dev(); |
1517 } | 1513 } |
1518 | 1514 |
1519 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); | 1515 FitContentsToPrintableAreaIfRequired(output_doc, print_settings); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 | 1558 |
1563 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::Point& point, | 1559 PDFiumPage::Area PDFiumEngine::GetCharIndex(const pp::Point& point, |
1564 int* page_index, | 1560 int* page_index, |
1565 int* char_index, | 1561 int* char_index, |
1566 int* form_type, | 1562 int* form_type, |
1567 PDFiumPage::LinkTarget* target) { | 1563 PDFiumPage::LinkTarget* target) { |
1568 int page = -1; | 1564 int page = -1; |
1569 pp::Point point_in_page( | 1565 pp::Point point_in_page( |
1570 static_cast<int>((point.x() + position_.x()) / current_zoom_), | 1566 static_cast<int>((point.x() + position_.x()) / current_zoom_), |
1571 static_cast<int>((point.y() + position_.y()) / current_zoom_)); | 1567 static_cast<int>((point.y() + position_.y()) / current_zoom_)); |
1572 for (size_t i = 0; i < visible_pages_.size(); ++i) { | 1568 for (int visible_page : visible_pages_) { |
1573 if (pages_[visible_pages_[i]]->rect().Contains(point_in_page)) { | 1569 if (pages_[visible_page]->rect().Contains(point_in_page)) { |
1574 page = visible_pages_[i]; | 1570 page = visible_page; |
1575 break; | 1571 break; |
1576 } | 1572 } |
1577 } | 1573 } |
1578 if (page == -1) | 1574 if (page == -1) |
1579 return PDFiumPage::NONSELECTABLE_AREA; | 1575 return PDFiumPage::NONSELECTABLE_AREA; |
1580 | 1576 |
1581 // If the page hasn't finished rendering, calling into the page sometimes | 1577 // If the page hasn't finished rendering, calling into the page sometimes |
1582 // leads to hangs. | 1578 // leads to hangs. |
1583 for (size_t i = 0; i < progressive_paints_.size(); ++i) { | 1579 for (const auto& paint : progressive_paints_) { |
1584 if (progressive_paints_[i].page_index == page) | 1580 if (paint.page_index == page) |
1585 return PDFiumPage::NONSELECTABLE_AREA; | 1581 return PDFiumPage::NONSELECTABLE_AREA; |
1586 } | 1582 } |
1587 | 1583 |
1588 *page_index = page; | 1584 *page_index = page; |
1589 return pages_[page]->GetCharIndex( | 1585 return pages_[page]->GetCharIndex( |
1590 point_in_page, current_rotation_, char_index, form_type, target); | 1586 point_in_page, current_rotation_, char_index, form_type, target); |
1591 } | 1587 } |
1592 | 1588 |
1593 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { | 1589 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
1594 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT) { | 1590 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT) { |
1595 if (!selection_.size()) | 1591 if (selection_.empty()) |
1596 return false; | 1592 return false; |
1597 std::vector<pp::Rect> selection_rect_vector; | 1593 std::vector<pp::Rect> selection_rect_vector; |
1598 GetAllScreenRectsUnion(&selection_, GetVisibleRect().point(), | 1594 GetAllScreenRectsUnion(&selection_, GetVisibleRect().point(), |
1599 &selection_rect_vector); | 1595 &selection_rect_vector); |
1600 pp::Point point = event.GetPosition(); | 1596 pp::Point point = event.GetPosition(); |
1601 for (size_t i = 0; i < selection_rect_vector.size(); ++i) { | 1597 for (const auto& rect : selection_rect_vector) { |
1602 if (selection_rect_vector[i].Contains(point.x(), point.y())) | 1598 if (rect.Contains(point.x(), point.y())) |
1603 return false; | 1599 return false; |
1604 } | 1600 } |
1605 SelectionChangeInvalidator selection_invalidator(this); | 1601 SelectionChangeInvalidator selection_invalidator(this); |
1606 selection_.clear(); | 1602 selection_.clear(); |
1607 return true; | 1603 return true; |
1608 } | 1604 } |
1609 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) | 1605 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) |
1610 return false; | 1606 return false; |
1611 | 1607 |
1612 SelectionChangeInvalidator selection_invalidator(this); | 1608 SelectionChangeInvalidator selection_invalidator(this); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 // Check if the user has descreased their selection area and we need to remove | 1804 // Check if the user has descreased their selection area and we need to remove |
1809 // pages from selection_. | 1805 // pages from selection_. |
1810 for (size_t i = 0; i < selection_.size(); ++i) { | 1806 for (size_t i = 0; i < selection_.size(); ++i) { |
1811 if (selection_[i].page_index() == page_index) { | 1807 if (selection_[i].page_index() == page_index) { |
1812 // There should be no other pages after this. | 1808 // There should be no other pages after this. |
1813 selection_.erase(selection_.begin() + i + 1, selection_.end()); | 1809 selection_.erase(selection_.begin() + i + 1, selection_.end()); |
1814 break; | 1810 break; |
1815 } | 1811 } |
1816 } | 1812 } |
1817 | 1813 |
1818 if (selection_.size() == 0) | 1814 if (selection_.empty()) |
1819 return false; | 1815 return false; |
1820 | 1816 |
1821 int last = selection_.size() - 1; | 1817 int last = selection_.size() - 1; |
1822 if (selection_[last].page_index() == page_index) { | 1818 if (selection_[last].page_index() == page_index) { |
1823 // Selecting within a page. | 1819 // Selecting within a page. |
1824 int count; | 1820 int count; |
1825 if (char_index >= selection_[last].char_index()) { | 1821 if (char_index >= selection_[last].char_index()) { |
1826 // Selecting forward. | 1822 // Selecting forward. |
1827 count = char_index - selection_[last].char_index() + 1; | 1823 count = char_index - selection_[last].char_index() + 1; |
1828 } else { | 1824 } else { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2064 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); | 2060 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); |
2065 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), | 2061 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), |
2066 character_to_start_searching_from, | 2062 character_to_start_searching_from, |
2067 text_length, | 2063 text_length, |
2068 data); | 2064 data); |
2069 api_string_adapter.Close(written); | 2065 api_string_adapter.Close(written); |
2070 | 2066 |
2071 std::vector<PDFEngine::Client::SearchStringResult> results; | 2067 std::vector<PDFEngine::Client::SearchStringResult> results; |
2072 client_->SearchString( | 2068 client_->SearchString( |
2073 page_text.c_str(), term.c_str(), case_sensitive, &results); | 2069 page_text.c_str(), term.c_str(), case_sensitive, &results); |
2074 for (size_t i = 0; i < results.size(); ++i) { | 2070 for (const auto& result : results) { |
2075 // Need to map the indexes from the page text, which may have generated | 2071 // Need to map the indexes from the page text, which may have generated |
2076 // characters like space etc, to character indices from the page. | 2072 // characters like space etc, to character indices from the page. |
2077 int temp_start = results[i].start_index + character_to_start_searching_from; | 2073 int temp_start = result.start_index + character_to_start_searching_from; |
2078 int start = FPDFText_GetCharIndexFromTextIndex( | 2074 int start = FPDFText_GetCharIndexFromTextIndex( |
2079 pages_[current_page]->GetTextPage(), temp_start); | 2075 pages_[current_page]->GetTextPage(), temp_start); |
2080 int end = FPDFText_GetCharIndexFromTextIndex( | 2076 int end = FPDFText_GetCharIndexFromTextIndex( |
2081 pages_[current_page]->GetTextPage(), | 2077 pages_[current_page]->GetTextPage(), |
2082 temp_start + results[i].length); | 2078 temp_start + result.length); |
2083 AddFindResult(PDFiumRange(pages_[current_page], start, end - start)); | 2079 AddFindResult(PDFiumRange(pages_[current_page], start, end - start)); |
2084 } | 2080 } |
2085 } | 2081 } |
2086 | 2082 |
2087 void PDFiumEngine::AddFindResult(const PDFiumRange& result) { | 2083 void PDFiumEngine::AddFindResult(const PDFiumRange& result) { |
2088 // Figure out where to insert the new location, since we could have | 2084 // Figure out where to insert the new location, since we could have |
2089 // started searching midway and now we wrapped. | 2085 // started searching midway and now we wrapped. |
2090 size_t result_index; | 2086 size_t result_index; |
2091 int page_index = result.page_index(); | 2087 int page_index = result.page_index(); |
2092 int char_index = result.char_index(); | 2088 int char_index = result.char_index(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2143 selection_.clear(); | 2139 selection_.clear(); |
2144 selection_.push_back(find_results_[current_find_index_.GetIndex()]); | 2140 selection_.push_back(find_results_[current_find_index_.GetIndex()]); |
2145 | 2141 |
2146 // If the result is not in view, scroll to it. | 2142 // If the result is not in view, scroll to it. |
2147 pp::Rect bounding_rect; | 2143 pp::Rect bounding_rect; |
2148 pp::Rect visible_rect = GetVisibleRect(); | 2144 pp::Rect visible_rect = GetVisibleRect(); |
2149 // Use zoom of 1.0 since visible_rect is without zoom. | 2145 // Use zoom of 1.0 since visible_rect is without zoom. |
2150 std::vector<pp::Rect> rects; | 2146 std::vector<pp::Rect> rects; |
2151 rects = find_results_[current_find_index_.GetIndex()].GetScreenRects( | 2147 rects = find_results_[current_find_index_.GetIndex()].GetScreenRects( |
2152 pp::Point(), 1.0, current_rotation_); | 2148 pp::Point(), 1.0, current_rotation_); |
2153 for (size_t i = 0; i < rects.size(); ++i) | 2149 for (const auto& rect : rects) |
2154 bounding_rect = bounding_rect.Union(rects[i]); | 2150 bounding_rect = bounding_rect.Union(rect); |
2155 if (!visible_rect.Contains(bounding_rect)) { | 2151 if (!visible_rect.Contains(bounding_rect)) { |
2156 pp::Point center = bounding_rect.CenterPoint(); | 2152 pp::Point center = bounding_rect.CenterPoint(); |
2157 // Make the page centered. | 2153 // Make the page centered. |
2158 int new_y = static_cast<int>(center.y() * current_zoom_) - | 2154 int new_y = static_cast<int>(center.y() * current_zoom_) - |
2159 static_cast<int>(visible_rect.height() * current_zoom_ / 2); | 2155 static_cast<int>(visible_rect.height() * current_zoom_ / 2); |
2160 if (new_y < 0) | 2156 if (new_y < 0) |
2161 new_y = 0; | 2157 new_y = 0; |
2162 client_->ScrollToY(new_y); | 2158 client_->ScrollToY(new_y); |
2163 | 2159 |
2164 // Only move horizontally if it's not visible. | 2160 // Only move horizontally if it's not visible. |
(...skipping 21 matching lines...) Expand all Loading... |
2186 last_character_index_to_search_ = -1; | 2182 last_character_index_to_search_ = -1; |
2187 current_find_index_.Invalidate(); | 2183 current_find_index_.Invalidate(); |
2188 current_find_text_.clear(); | 2184 current_find_text_.clear(); |
2189 UpdateTickMarks(); | 2185 UpdateTickMarks(); |
2190 find_factory_.CancelAll(); | 2186 find_factory_.CancelAll(); |
2191 } | 2187 } |
2192 | 2188 |
2193 void PDFiumEngine::GetAllScreenRectsUnion(std::vector<PDFiumRange>* rect_range, | 2189 void PDFiumEngine::GetAllScreenRectsUnion(std::vector<PDFiumRange>* rect_range, |
2194 const pp::Point& offset_point, | 2190 const pp::Point& offset_point, |
2195 std::vector<pp::Rect>* rect_vector) { | 2191 std::vector<pp::Rect>* rect_vector) { |
2196 for (std::vector<PDFiumRange>::iterator it = rect_range->begin(); | 2192 for (auto& range : *rect_range) { |
2197 it != rect_range->end(); ++it) { | 2193 pp::Rect result_rect; |
2198 pp::Rect rect; | |
2199 std::vector<pp::Rect> rects = | 2194 std::vector<pp::Rect> rects = |
2200 it->GetScreenRects(offset_point, current_zoom_, current_rotation_); | 2195 range.GetScreenRects(offset_point, current_zoom_, current_rotation_); |
2201 for (size_t j = 0; j < rects.size(); ++j) | 2196 for (const auto& rect : rects) |
2202 rect = rect.Union(rects[j]); | 2197 result_rect = result_rect.Union(rect); |
2203 rect_vector->push_back(rect); | 2198 rect_vector->push_back(result_rect); |
2204 } | 2199 } |
2205 } | 2200 } |
2206 | 2201 |
2207 void PDFiumEngine::UpdateTickMarks() { | 2202 void PDFiumEngine::UpdateTickMarks() { |
2208 std::vector<pp::Rect> tickmarks; | 2203 std::vector<pp::Rect> tickmarks; |
2209 GetAllScreenRectsUnion(&find_results_, pp::Point(0, 0), &tickmarks); | 2204 GetAllScreenRectsUnion(&find_results_, pp::Point(0, 0), &tickmarks); |
2210 client_->UpdateTickMarks(tickmarks); | 2205 client_->UpdateTickMarks(tickmarks); |
2211 } | 2206 } |
2212 | 2207 |
2213 void PDFiumEngine::ZoomUpdated(double new_zoom_level) { | 2208 void PDFiumEngine::ZoomUpdated(double new_zoom_level) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; | 2295 return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0; |
2301 default: | 2296 default: |
2302 return true; | 2297 return true; |
2303 } | 2298 } |
2304 } | 2299 } |
2305 | 2300 |
2306 void PDFiumEngine::SelectAll() { | 2301 void PDFiumEngine::SelectAll() { |
2307 SelectionChangeInvalidator selection_invalidator(this); | 2302 SelectionChangeInvalidator selection_invalidator(this); |
2308 | 2303 |
2309 selection_.clear(); | 2304 selection_.clear(); |
2310 for (size_t i = 0; i < pages_.size(); ++i) | 2305 for (const auto& page : pages_) { |
2311 if (pages_[i]->available()) { | 2306 if (page->available()) |
2312 selection_.push_back(PDFiumRange(pages_[i], 0, | 2307 selection_.push_back(PDFiumRange(page, 0, page->GetCharCount())); |
2313 pages_[i]->GetCharCount())); | 2308 } |
2314 } | |
2315 } | 2309 } |
2316 | 2310 |
2317 int PDFiumEngine::GetNumberOfPages() { | 2311 int PDFiumEngine::GetNumberOfPages() { |
2318 return pages_.size(); | 2312 return pages_.size(); |
2319 } | 2313 } |
2320 | 2314 |
2321 pp::VarArray PDFiumEngine::GetBookmarks() { | 2315 pp::VarArray PDFiumEngine::GetBookmarks() { |
2322 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL, 0); | 2316 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL, 0); |
2323 // The root bookmark contains no useful information. | 2317 // The root bookmark contains no useful information. |
2324 return pp::VarArray(dict.Get(pp::Var("children"))); | 2318 return pp::VarArray(dict.Get(pp::Var("children"))); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 client_->DocumentLoadFailed(); | 2489 client_->DocumentLoadFailed(); |
2496 } | 2490 } |
2497 | 2491 |
2498 bool PDFiumEngine::TryLoadingDoc(bool with_password, | 2492 bool PDFiumEngine::TryLoadingDoc(bool with_password, |
2499 const std::string& password, | 2493 const std::string& password, |
2500 bool* needs_password) { | 2494 bool* needs_password) { |
2501 *needs_password = false; | 2495 *needs_password = false; |
2502 if (doc_) | 2496 if (doc_) |
2503 return true; | 2497 return true; |
2504 | 2498 |
2505 const char* password_cstr = NULL; | 2499 const char* password_cstr = nullptr; |
2506 if (with_password) { | 2500 if (with_password) { |
2507 password_cstr = password.c_str(); | 2501 password_cstr = password.c_str(); |
2508 password_tries_remaining_--; | 2502 password_tries_remaining_--; |
2509 } | 2503 } |
2510 if (doc_loader_.IsDocumentComplete()) | 2504 if (doc_loader_.IsDocumentComplete()) |
2511 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); | 2505 doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr); |
2512 else | 2506 else |
2513 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); | 2507 doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr); |
2514 | 2508 |
2515 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) | 2509 if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD) |
2516 *needs_password = true; | 2510 *needs_password = true; |
2517 | 2511 |
2518 return doc_ != NULL; | 2512 return !!doc_; |
2519 } | 2513 } |
2520 | 2514 |
2521 void PDFiumEngine::GetPasswordAndLoad() { | 2515 void PDFiumEngine::GetPasswordAndLoad() { |
2522 getting_password_ = true; | 2516 getting_password_ = true; |
2523 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); | 2517 DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD); |
2524 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( | 2518 client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput( |
2525 &PDFiumEngine::OnGetPasswordComplete)); | 2519 &PDFiumEngine::OnGetPasswordComplete)); |
2526 } | 2520 } |
2527 | 2521 |
2528 void PDFiumEngine::OnGetPasswordComplete(int32_t result, | 2522 void PDFiumEngine::OnGetPasswordComplete(int32_t result, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2694 pp::Rect rc_next = | 2688 pp::Rect rc_next = |
2695 visible_rect.Intersect(GetPageScreenRect(most_visible_page + 1)); | 2689 visible_rect.Intersect(GetPageScreenRect(most_visible_page + 1)); |
2696 if (rc_next.height() > rc_first.height()) | 2690 if (rc_next.height() > rc_first.height()) |
2697 most_visible_page++; | 2691 most_visible_page++; |
2698 } | 2692 } |
2699 | 2693 |
2700 SetCurrentPage(most_visible_page); | 2694 SetCurrentPage(most_visible_page); |
2701 } | 2695 } |
2702 | 2696 |
2703 bool PDFiumEngine::IsPageVisible(int index) const { | 2697 bool PDFiumEngine::IsPageVisible(int index) const { |
2704 for (size_t i = 0; i < visible_pages_.size(); ++i) { | 2698 return ContainsValue(visible_pages_, index); |
2705 if (visible_pages_[i] == index) | |
2706 return true; | |
2707 } | |
2708 | |
2709 return false; | |
2710 } | 2699 } |
2711 | 2700 |
2712 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { | 2701 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { |
2713 if (!doc_ || !form_) | 2702 if (!doc_ || !form_) |
2714 return false; | 2703 return false; |
2715 | 2704 |
2716 if (static_cast<int>(pages_.size()) > index && pages_[index]->available()) | 2705 if (static_cast<int>(pages_.size()) > index && pages_[index]->available()) |
2717 return true; | 2706 return true; |
2718 | 2707 |
2719 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { | 2708 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2828 DrawSelections(progressive_index, image_data); | 2817 DrawSelections(progressive_index, image_data); |
2829 | 2818 |
2830 FPDF_RenderPage_Close(pages_[page_index]->GetPage()); | 2819 FPDF_RenderPage_Close(pages_[page_index]->GetPage()); |
2831 FPDFBitmap_Destroy(bitmap); | 2820 FPDFBitmap_Destroy(bitmap); |
2832 progressive_paints_.erase(progressive_paints_.begin() + progressive_index); | 2821 progressive_paints_.erase(progressive_paints_.begin() + progressive_index); |
2833 | 2822 |
2834 client_->DocumentPaintOccurred(); | 2823 client_->DocumentPaintOccurred(); |
2835 } | 2824 } |
2836 | 2825 |
2837 void PDFiumEngine::CancelPaints() { | 2826 void PDFiumEngine::CancelPaints() { |
2838 for (size_t i = 0; i < progressive_paints_.size(); ++i) { | 2827 for (const auto& paint : progressive_paints_) { |
2839 FPDF_RenderPage_Close(pages_[progressive_paints_[i].page_index]->GetPage()); | 2828 FPDF_RenderPage_Close(pages_[paint.page_index]->GetPage()); |
2840 FPDFBitmap_Destroy(progressive_paints_[i].bitmap); | 2829 FPDFBitmap_Destroy(paint.bitmap); |
2841 } | 2830 } |
2842 progressive_paints_.clear(); | 2831 progressive_paints_.clear(); |
2843 } | 2832 } |
2844 | 2833 |
2845 void PDFiumEngine::FillPageSides(int progressive_index) { | 2834 void PDFiumEngine::FillPageSides(int progressive_index) { |
2846 DCHECK_GE(progressive_index, 0); | 2835 DCHECK_GE(progressive_index, 0); |
2847 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); | 2836 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); |
2848 | 2837 |
2849 int page_index = progressive_paints_[progressive_index].page_index; | 2838 int page_index = progressive_paints_[progressive_index].page_index; |
2850 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2839 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2926 | 2915 |
2927 int page_index = progressive_paints_[progressive_index].page_index; | 2916 int page_index = progressive_paints_[progressive_index].page_index; |
2928 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; | 2917 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; |
2929 | 2918 |
2930 void* region = NULL; | 2919 void* region = NULL; |
2931 int stride; | 2920 int stride; |
2932 GetRegion(dirty_in_screen.point(), image_data, ®ion, &stride); | 2921 GetRegion(dirty_in_screen.point(), image_data, ®ion, &stride); |
2933 | 2922 |
2934 std::vector<pp::Rect> highlighted_rects; | 2923 std::vector<pp::Rect> highlighted_rects; |
2935 pp::Rect visible_rect = GetVisibleRect(); | 2924 pp::Rect visible_rect = GetVisibleRect(); |
2936 for (size_t k = 0; k < selection_.size(); ++k) { | 2925 for (auto& range : selection_) { |
2937 if (selection_[k].page_index() != page_index) | 2926 if (range.page_index() != page_index) |
2938 continue; | 2927 continue; |
2939 std::vector<pp::Rect> rects = selection_[k].GetScreenRects( | 2928 |
| 2929 std::vector<pp::Rect> rects = range.GetScreenRects( |
2940 visible_rect.point(), current_zoom_, current_rotation_); | 2930 visible_rect.point(), current_zoom_, current_rotation_); |
2941 for (size_t j = 0; j < rects.size(); ++j) { | 2931 for (const auto& rect : rects) { |
2942 pp::Rect visible_selection = rects[j].Intersect(dirty_in_screen); | 2932 pp::Rect visible_selection = rect.Intersect(dirty_in_screen); |
2943 if (visible_selection.IsEmpty()) | 2933 if (visible_selection.IsEmpty()) |
2944 continue; | 2934 continue; |
2945 | 2935 |
2946 visible_selection.Offset( | 2936 visible_selection.Offset( |
2947 -dirty_in_screen.point().x(), -dirty_in_screen.point().y()); | 2937 -dirty_in_screen.point().x(), -dirty_in_screen.point().y()); |
2948 Highlight(region, stride, visible_selection, &highlighted_rects); | 2938 Highlight(region, stride, visible_selection, &highlighted_rects); |
2949 } | 2939 } |
2950 } | 2940 } |
2951 | 2941 |
2952 for (size_t k = 0; k < form_highlights_.size(); ++k) { | 2942 for (const auto& highlight : form_highlights_) { |
2953 pp::Rect visible_selection = form_highlights_[k].Intersect(dirty_in_screen); | 2943 pp::Rect visible_selection = highlight.Intersect(dirty_in_screen); |
2954 if (visible_selection.IsEmpty()) | 2944 if (visible_selection.IsEmpty()) |
2955 continue; | 2945 continue; |
2956 | 2946 |
2957 visible_selection.Offset( | 2947 visible_selection.Offset( |
2958 -dirty_in_screen.point().x(), -dirty_in_screen.point().y()); | 2948 -dirty_in_screen.point().x(), -dirty_in_screen.point().y()); |
2959 Highlight(region, stride, visible_selection, &highlighted_rects); | 2949 Highlight(region, stride, visible_selection, &highlighted_rects); |
2960 } | 2950 } |
2961 form_highlights_.clear(); | 2951 form_highlights_.clear(); |
2962 } | 2952 } |
2963 | 2953 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3053 } | 3043 } |
3054 | 3044 |
3055 void PDFiumEngine::Highlight(void* buffer, | 3045 void PDFiumEngine::Highlight(void* buffer, |
3056 int stride, | 3046 int stride, |
3057 const pp::Rect& rect, | 3047 const pp::Rect& rect, |
3058 std::vector<pp::Rect>* highlighted_rects) { | 3048 std::vector<pp::Rect>* highlighted_rects) { |
3059 if (!buffer) | 3049 if (!buffer) |
3060 return; | 3050 return; |
3061 | 3051 |
3062 pp::Rect new_rect = rect; | 3052 pp::Rect new_rect = rect; |
3063 for (size_t i = 0; i < highlighted_rects->size(); ++i) | 3053 for (const auto& highlighted : *highlighted_rects) |
3064 new_rect = new_rect.Subtract((*highlighted_rects)[i]); | 3054 new_rect = new_rect.Subtract(highlighted); |
3065 | 3055 |
3066 highlighted_rects->push_back(new_rect); | 3056 highlighted_rects->push_back(new_rect); |
3067 int l = new_rect.x(); | 3057 int l = new_rect.x(); |
3068 int t = new_rect.y(); | 3058 int t = new_rect.y(); |
3069 int w = new_rect.width(); | 3059 int w = new_rect.width(); |
3070 int h = new_rect.height(); | 3060 int h = new_rect.height(); |
3071 | 3061 |
3072 for (int y = t; y < t + h; ++y) { | 3062 for (int y = t; y < t + h; ++y) { |
3073 for (int x = l; x < l + w; ++x) { | 3063 for (int x = l; x < l + w; ++x) { |
3074 uint8_t* pixel = static_cast<uint8_t*>(buffer) + y * stride + x * 4; | 3064 uint8_t* pixel = static_cast<uint8_t*>(buffer) + y * stride + x * 4; |
3075 // This is our highlight color. | 3065 // This is our highlight color. |
3076 pixel[0] = static_cast<uint8_t>(pixel[0] * (kHighlightColorB / 255.0)); | 3066 pixel[0] = static_cast<uint8_t>(pixel[0] * (kHighlightColorB / 255.0)); |
3077 pixel[1] = static_cast<uint8_t>(pixel[1] * (kHighlightColorG / 255.0)); | 3067 pixel[1] = static_cast<uint8_t>(pixel[1] * (kHighlightColorG / 255.0)); |
3078 pixel[2] = static_cast<uint8_t>(pixel[2] * (kHighlightColorR / 255.0)); | 3068 pixel[2] = static_cast<uint8_t>(pixel[2] * (kHighlightColorR / 255.0)); |
3079 } | 3069 } |
3080 } | 3070 } |
3081 } | 3071 } |
3082 | 3072 |
3083 PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator( | 3073 PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator( |
3084 PDFiumEngine* engine) : engine_(engine) { | 3074 PDFiumEngine* engine) : engine_(engine) { |
3085 previous_origin_ = engine_->GetVisibleRect().point(); | 3075 previous_origin_ = engine_->GetVisibleRect().point(); |
3086 GetVisibleSelectionsScreenRects(&old_selections_); | 3076 GetVisibleSelectionsScreenRects(&old_selections_); |
3087 } | 3077 } |
3088 | 3078 |
3089 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { | 3079 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { |
3090 // Offset the old selections if the document scrolled since we recorded them. | 3080 // Offset the old selections if the document scrolled since we recorded them. |
3091 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); | 3081 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); |
3092 for (size_t i = 0; i < old_selections_.size(); ++i) | 3082 for (auto& old_selection : old_selections_) |
3093 old_selections_[i].Offset(offset); | 3083 old_selection.Offset(offset); |
3094 | 3084 |
3095 std::vector<pp::Rect> new_selections; | 3085 std::vector<pp::Rect> new_selections; |
3096 GetVisibleSelectionsScreenRects(&new_selections); | 3086 GetVisibleSelectionsScreenRects(&new_selections); |
3097 for (size_t i = 0; i < new_selections.size(); ++i) { | 3087 for (auto& new_selection : new_selections) { |
3098 for (size_t j = 0; j < old_selections_.size(); ++j) { | 3088 for (auto& old_selection : old_selections_) { |
3099 if (!old_selections_[j].IsEmpty() && | 3089 if (!old_selection.IsEmpty() && new_selection == old_selection) { |
3100 new_selections[i] == old_selections_[j]) { | |
3101 // Rectangle was selected before and after, so no need to invalidate it. | 3090 // Rectangle was selected before and after, so no need to invalidate it. |
3102 // Mark the rectangles by setting them to empty. | 3091 // Mark the rectangles by setting them to empty. |
3103 new_selections[i] = old_selections_[j] = pp::Rect(); | 3092 new_selection = old_selection = pp::Rect(); |
3104 break; | 3093 break; |
3105 } | 3094 } |
3106 } | 3095 } |
3107 } | 3096 } |
3108 | 3097 |
3109 for (size_t i = 0; i < old_selections_.size(); ++i) { | 3098 for (const auto& old_selection : old_selections_) { |
3110 if (!old_selections_[i].IsEmpty()) | 3099 if (!old_selection.IsEmpty()) |
3111 engine_->client_->Invalidate(old_selections_[i]); | 3100 engine_->client_->Invalidate(old_selection); |
3112 } | 3101 } |
3113 for (size_t i = 0; i < new_selections.size(); ++i) { | 3102 for (const auto& new_selection : new_selections) { |
3114 if (!new_selections[i].IsEmpty()) | 3103 if (!new_selection.IsEmpty()) |
3115 engine_->client_->Invalidate(new_selections[i]); | 3104 engine_->client_->Invalidate(new_selection); |
3116 } | 3105 } |
3117 engine_->OnSelectionChanged(); | 3106 engine_->OnSelectionChanged(); |
3118 } | 3107 } |
3119 | 3108 |
3120 void | 3109 void PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( |
3121 PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( | |
3122 std::vector<pp::Rect>* rects) { | 3110 std::vector<pp::Rect>* rects) { |
3123 pp::Rect visible_rect = engine_->GetVisibleRect(); | 3111 pp::Rect visible_rect = engine_->GetVisibleRect(); |
3124 for (size_t i = 0; i < engine_->selection_.size(); ++i) { | 3112 for (auto& range : engine_->selection_) { |
3125 int page_index = engine_->selection_[i].page_index(); | 3113 int page_index = range.page_index(); |
3126 if (!engine_->IsPageVisible(page_index)) | 3114 if (!engine_->IsPageVisible(page_index)) |
3127 continue; // This selection is on a page that's not currently visible. | 3115 continue; // This selection is on a page that's not currently visible. |
3128 | 3116 |
3129 std::vector<pp::Rect> selection_rects = | 3117 std::vector<pp::Rect> selection_rects = |
3130 engine_->selection_[i].GetScreenRects( | 3118 range.GetScreenRects( |
3131 visible_rect.point(), | 3119 visible_rect.point(), |
3132 engine_->current_zoom_, | 3120 engine_->current_zoom_, |
3133 engine_->current_rotation_); | 3121 engine_->current_rotation_); |
3134 rects->insert(rects->end(), selection_rects.begin(), selection_rects.end()); | 3122 rects->insert(rects->end(), selection_rects.begin(), selection_rects.end()); |
3135 } | 3123 } |
3136 } | 3124 } |
3137 | 3125 |
3138 PDFiumEngine::MouseDownState::MouseDownState( | 3126 PDFiumEngine::MouseDownState::MouseDownState( |
3139 const PDFiumPage::Area& area, | 3127 const PDFiumPage::Area& area, |
3140 const PDFiumPage::LinkTarget& target) | 3128 const PDFiumPage::LinkTarget& target) |
(...skipping 10 matching lines...) Expand all Loading... |
3151 } | 3139 } |
3152 | 3140 |
3153 void PDFiumEngine::MouseDownState::Reset() { | 3141 void PDFiumEngine::MouseDownState::Reset() { |
3154 area_ = PDFiumPage::NONSELECTABLE_AREA; | 3142 area_ = PDFiumPage::NONSELECTABLE_AREA; |
3155 target_ = PDFiumPage::LinkTarget(); | 3143 target_ = PDFiumPage::LinkTarget(); |
3156 } | 3144 } |
3157 | 3145 |
3158 bool PDFiumEngine::MouseDownState::Matches( | 3146 bool PDFiumEngine::MouseDownState::Matches( |
3159 const PDFiumPage::Area& area, | 3147 const PDFiumPage::Area& area, |
3160 const PDFiumPage::LinkTarget& target) const { | 3148 const PDFiumPage::LinkTarget& target) const { |
3161 if (area_ == area) { | 3149 if (area_ != area) |
3162 if (area == PDFiumPage::WEBLINK_AREA) | 3150 return false; |
3163 return target_.url == target.url; | 3151 |
3164 if (area == PDFiumPage::DOCLINK_AREA) | 3152 if (area == PDFiumPage::WEBLINK_AREA) |
3165 return target_.page == target.page; | 3153 return target_.url == target.url; |
3166 return true; | 3154 |
3167 } | 3155 if (area == PDFiumPage::DOCLINK_AREA) |
3168 return false; | 3156 return target_.page == target.page; |
| 3157 |
| 3158 return true; |
3169 } | 3159 } |
3170 | 3160 |
3171 PDFiumEngine::FindTextIndex::FindTextIndex() | 3161 PDFiumEngine::FindTextIndex::FindTextIndex() |
3172 : valid_(false), index_(0) { | 3162 : valid_(false), index_(0) { |
3173 } | 3163 } |
3174 | 3164 |
3175 PDFiumEngine::FindTextIndex::~FindTextIndex() { | 3165 PDFiumEngine::FindTextIndex::~FindTextIndex() { |
3176 } | 3166 } |
3177 | 3167 |
3178 void PDFiumEngine::FindTextIndex::Invalidate() { | 3168 void PDFiumEngine::FindTextIndex::Invalidate() { |
(...skipping 25 matching lines...) Expand all Loading... |
3204 pages_[page_index]->rect().x()); | 3194 pages_[page_index]->rect().x()); |
3205 int temp_y = static_cast<int>((device_y + position_.y())/ current_zoom_ - | 3195 int temp_y = static_cast<int>((device_y + position_.y())/ current_zoom_ - |
3206 pages_[page_index]->rect().y()); | 3196 pages_[page_index]->rect().y()); |
3207 FPDF_DeviceToPage( | 3197 FPDF_DeviceToPage( |
3208 pages_[page_index]->GetPage(), 0, 0, | 3198 pages_[page_index]->GetPage(), 0, 0, |
3209 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(), | 3199 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(), |
3210 current_rotation_, temp_x, temp_y, page_x, page_y); | 3200 current_rotation_, temp_x, temp_y, page_x, page_y); |
3211 } | 3201 } |
3212 | 3202 |
3213 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { | 3203 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { |
3214 for (size_t i = 0; i < visible_pages_.size(); ++i) { | 3204 for (int page_index : visible_pages_) { |
3215 if (pages_[visible_pages_[i]]->GetPage() == page) | 3205 if (pages_[page_index]->GetPage() == page) |
3216 return visible_pages_[i]; | 3206 return page_index; |
3217 } | 3207 } |
3218 return -1; | 3208 return -1; |
3219 } | 3209 } |
3220 | 3210 |
3221 void PDFiumEngine::SetCurrentPage(int index) { | 3211 void PDFiumEngine::SetCurrentPage(int index) { |
3222 if (index == most_visible_page_ || !form_) | 3212 if (index == most_visible_page_ || !form_) |
3223 return; | 3213 return; |
3224 if (most_visible_page_ != -1 && called_do_document_action_) { | 3214 if (most_visible_page_ != -1 && called_do_document_action_) { |
3225 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); | 3215 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); |
3226 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); | 3216 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3955 double* height) { | 3945 double* height) { |
3956 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3946 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3957 if (!doc) | 3947 if (!doc) |
3958 return false; | 3948 return false; |
3959 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3949 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3960 FPDF_CloseDocument(doc); | 3950 FPDF_CloseDocument(doc); |
3961 return success; | 3951 return success; |
3962 } | 3952 } |
3963 | 3953 |
3964 } // namespace chrome_pdf | 3954 } // namespace chrome_pdf |
OLD | NEW |