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

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

Issue 1550193002: Simplify PDFiumEngine::CheckPageAvailable(). Base URL: https://chromium.googlesource.com/chromium/src.git@pdfload
Patch Set: more Created 4 years, 12 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 | « no previous file | pdf/pdfium/pdfium_page.h » ('j') | 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 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 } 1160 }
1161 1161
1162 void PDFiumEngine::FinishLoadingDocument() { 1162 void PDFiumEngine::FinishLoadingDocument() {
1163 DCHECK(doc_loader_.IsDocumentComplete() && doc_); 1163 DCHECK(doc_loader_.IsDocumentComplete() && doc_);
1164 1164
1165 bool need_update = false; 1165 bool need_update = false;
1166 for (size_t i = 0; i < pages_.size(); ++i) { 1166 for (size_t i = 0; i < pages_.size(); ++i) {
1167 if (pages_[i]->available()) 1167 if (pages_[i]->available())
1168 continue; 1168 continue;
1169 1169
1170 pages_[i]->set_available(true); 1170 pages_[i]->set_as_available();
1171 // We still need to call IsPageAvail() even if the whole document is 1171 // We still need to call IsPageAvail() even if the whole document is
1172 // already downloaded. 1172 // already downloaded.
1173 FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_); 1173 // Page should be available because the whole document is available.
1174 int avail = FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_);
1175 DCHECK_EQ(PDF_DATA_AVAIL, avail);
1176
1174 need_update = true; 1177 need_update = true;
1175 if (IsPageVisible(i)) 1178 if (IsPageVisible(i))
1176 client_->Invalidate(GetPageScreenRect(i)); 1179 client_->Invalidate(GetPageScreenRect(i));
1177 } 1180 }
1178 if (need_update) 1181 if (need_update)
1179 LoadPageInfo(true); 1182 LoadPageInfo(true);
1180 1183
1181 if (called_do_document_action_) 1184 if (called_do_document_action_)
1182 return; 1185 return;
1183 called_do_document_action_ = true; 1186 called_do_document_action_ = true;
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2741 bool PDFiumEngine::IsPageVisible(int index) const { 2744 bool PDFiumEngine::IsPageVisible(int index) const {
2742 for (size_t i = 0; i < visible_pages_.size(); ++i) { 2745 for (size_t i = 0; i < visible_pages_.size(); ++i) {
2743 if (visible_pages_[i] == index) 2746 if (visible_pages_[i] == index)
2744 return true; 2747 return true;
2745 } 2748 }
2746 2749
2747 return false; 2750 return false;
2748 } 2751 }
2749 2752
2750 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { 2753 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) {
2751 if (!doc_ || !form_) 2754 if (!doc_ || !form_ || index < 0)
2752 return false; 2755 return false;
2753 2756
2754 if (static_cast<int>(pages_.size()) > index && pages_[index]->available()) 2757 const size_t index_size_t = static_cast<size_t>(index);
2758 if (index_size_t < pages_.size() && pages_[index]->available())
2755 return true; 2759 return true;
2756 2760
2757 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { 2761 int avail =
2758 size_t j; 2762 FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_);
2759 for (j = 0; j < pending->size(); ++j) { 2763 if (avail == PDF_DATA_ERROR)
2760 if ((*pending)[j] == index) 2764 return false;
2761 break;
2762 }
2763 2765
2764 if (j == pending->size()) 2766 if (avail == PDF_DATA_NOTAVAIL) {
2767 if (!ContainsValue(*pending, index))
2765 pending->push_back(index); 2768 pending->push_back(index);
2766 return false; 2769 return false;
2767 } 2770 }
2768 2771
2769 if (static_cast<int>(pages_.size()) > index) 2772 if (index_size_t < pages_.size())
2770 pages_[index]->set_available(true); 2773 pages_[index]->set_as_available();
2771 if (!default_page_size_.GetArea()) 2774 if (!default_page_size_.GetArea())
2772 default_page_size_ = GetPageSize(index); 2775 default_page_size_ = GetPageSize(index);
2773 return true; 2776 return true;
2774 } 2777 }
2775 2778
2776 pp::Size PDFiumEngine::GetPageSize(int index) { 2779 pp::Size PDFiumEngine::GetPageSize(int index) {
2777 pp::Size size; 2780 pp::Size size;
2778 double width_in_points = 0; 2781 double width_in_points = 0;
2779 double height_in_points = 0; 2782 double height_in_points = 0;
2780 int rv = FPDF_GetPageSizeByIndex( 2783 int rv = FPDF_GetPageSizeByIndex(
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
4003 double* height) { 4006 double* height) {
4004 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4007 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4005 if (!doc) 4008 if (!doc)
4006 return false; 4009 return false;
4007 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4010 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4008 FPDF_CloseDocument(doc); 4011 FPDF_CloseDocument(doc);
4009 return success; 4012 return success;
4010 } 4013 }
4011 4014
4012 } // namespace chrome_pdf 4015 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698