Commit 0cb6b59e authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Handle FFI_PageEvent from PDFium in PDF Viewer.

Add or remove pages from the viewer in response to these events.

Bug: pdfium:401,chromium:872903,chromium:867135
Change-Id: Iddc88c5a90370213619a0f3f2587f215d0dafbc8
Reviewed-on: https://chromium-review.googlesource.com/1169691
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584515}
parent 2741204b
...@@ -2606,22 +2606,24 @@ void PDFiumEngine::LoadPageInfo(bool reload) { ...@@ -2606,22 +2606,24 @@ void PDFiumEngine::LoadPageInfo(bool reload) {
pp::Size old_document_size = document_size_; pp::Size old_document_size = document_size_;
document_size_ = pp::Size(); document_size_ = pp::Size();
std::vector<pp::Rect> page_rects; std::vector<pp::Rect> page_rects;
int page_count = FPDF_GetPageCount(doc()); size_t new_page_count = FPDF_GetPageCount(doc());
bool doc_complete = doc_loader_->IsDocumentComplete(); bool doc_complete = doc_loader_->IsDocumentComplete();
bool is_linear = bool is_linear =
FPDFAvail_IsLinearized(fpdf_availability()) == PDF_LINEARIZED; FPDFAvail_IsLinearized(fpdf_availability()) == PDF_LINEARIZED;
for (int i = 0; i < page_count; ++i) { for (size_t i = 0; i < new_page_count; ++i) {
if (i != 0) { if (i != 0) {
// Add space for horizontal separator. // Add space for horizontal separator.
document_size_.Enlarge(0, kPageSeparatorThickness); document_size_.Enlarge(0, kPageSeparatorThickness);
} }
// Get page availability. If |reload| == true, then the document has been // Get page availability. If |reload| == true and the page is not new,
// constructed already. Get page availability flag from already existing // then the page has been constructed already. Get page availability flag
// PDFiumPage class. // from already existing PDFiumPage object.
// If |reload| == false, then the document may not be fully loaded yet. // If |reload| == false or the page is new, then the page may not be fully
// loaded yet.
bool page_available; bool page_available;
if (reload) { if (reload && i < pages_.size()) {
page_available = pages_[i]->available(); page_available = pages_[i]->available();
} else if (is_linear) { } else if (is_linear) {
FX_DOWNLOADHINTS& download_hints = document_->download_hints(); FX_DOWNLOADHINTS& download_hints = document_->download_hints();
...@@ -2644,22 +2646,34 @@ void PDFiumEngine::LoadPageInfo(bool reload) { ...@@ -2644,22 +2646,34 @@ void PDFiumEngine::LoadPageInfo(bool reload) {
document_size_.Enlarge(0, size.height()); document_size_.Enlarge(0, size.height());
} }
for (int i = 0; i < page_count; ++i) { for (size_t i = 0; i < new_page_count; ++i) {
// Center pages relative to the entire document. // Center pages relative to the entire document.
page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2); page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2);
pp::Rect page_rect(page_rects[i]); pp::Rect page_rect(page_rects[i]);
page_rect.Inset(kPageShadowLeft, kPageShadowTop, kPageShadowRight, page_rect.Inset(kPageShadowLeft, kPageShadowTop, kPageShadowRight,
kPageShadowBottom); kPageShadowBottom);
if (reload) { if (!reload) {
pages_[i]->set_rect(page_rect);
} else {
// The page is marked as not being available even if |doc_complete| is // The page is marked as not being available even if |doc_complete| is
// true because FPDFAvail_IsPageAvail() still has to be called for this // true because FPDFAvail_IsPageAvail() still has to be called for this
// page, which will be done in FinishLoadingDocument(). // page, which will be done in FinishLoadingDocument().
pages_.push_back(std::make_unique<PDFiumPage>(this, i, page_rect, false)); pages_.push_back(std::make_unique<PDFiumPage>(this, i, page_rect, false));
} else if (i < pages_.size()) {
pages_[i]->set_rect(page_rect);
} else {
bool available = FPDFAvail_IsPageAvail(fpdf_availability(), i, nullptr);
pages_.push_back(
std::make_unique<PDFiumPage>(this, i, page_rect, available));
} }
} }
// Remove pages that do not exist anymore.
if (pages_.size() > new_page_count) {
for (size_t i = new_page_count; i < pages_.size(); ++i)
pages_[i]->Unload();
pages_.resize(new_page_count);
}
CalculateVisiblePages(); CalculateVisiblePages();
if (document_size_ != old_document_size) if (document_size_ != old_document_size)
client_->DocumentSizeUpdated(document_size_); client_->DocumentSizeUpdated(document_size_);
...@@ -3593,6 +3607,12 @@ void PDFiumEngine::GetSelection(uint32_t* selection_start_page_index, ...@@ -3593,6 +3607,12 @@ void PDFiumEngine::GetSelection(uint32_t* selection_start_page_index,
} }
} }
#if defined(PDF_ENABLE_XFA)
void PDFiumEngine::UpdatePageCount() {
InvalidateAllPages();
}
#endif // defined(PDF_ENABLE_XFA)
PDFiumEngine::ProgressivePaint::ProgressivePaint(int index, PDFiumEngine::ProgressivePaint::ProgressivePaint(int index,
const pp::Rect& rect) const pp::Rect& rect)
: page_index_(index), rect_(rect) {} : page_index_(index), rect_(rect) {}
......
...@@ -138,6 +138,10 @@ class PDFiumEngine : public PDFEngine, ...@@ -138,6 +138,10 @@ class PDFiumEngine : public PDFEngine,
void CancelBrowserDownload() override; void CancelBrowserDownload() override;
void KillFormFocus() override; void KillFormFocus() override;
#if defined(PDF_ENABLE_XFA)
void UpdatePageCount();
#endif // defined(PDF_ENABLE_XFA)
void UnsupportedFeature(const std::string& feature); void UnsupportedFeature(const std::string& feature);
void FontSubstituted(); void FontSubstituted();
......
...@@ -52,7 +52,7 @@ PDFiumFormFiller::PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript) ...@@ -52,7 +52,7 @@ PDFiumFormFiller::PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript)
FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex; FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex;
FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect; FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect;
FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform; FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform;
FPDF_FORMFILLINFO::FFI_PageEvent = nullptr; FPDF_FORMFILLINFO::FFI_PageEvent = Form_PageEvent;
FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu; FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu;
FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL; FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL;
FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL; FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL;
...@@ -393,6 +393,18 @@ int PDFiumFormFiller::Form_GetPlatform(FPDF_FORMFILLINFO* param, ...@@ -393,6 +393,18 @@ int PDFiumFormFiller::Form_GetPlatform(FPDF_FORMFILLINFO* param,
return platform_flag; return platform_flag;
} }
// static
void PDFiumFormFiller::Form_PageEvent(FPDF_FORMFILLINFO* param,
int page_count,
unsigned long event_type) {
DCHECK(page_count != 0);
DCHECK(event_type == FXFA_PAGEVIEWEVENT_POSTADDED ||
event_type == FXFA_PAGEVIEWEVENT_POSTREMOVED);
PDFiumEngine* engine = GetEngine(param);
engine->UpdatePageCount();
}
// static // static
FPDF_BOOL PDFiumFormFiller::Form_PopupMenu(FPDF_FORMFILLINFO* param, FPDF_BOOL PDFiumFormFiller::Form_PopupMenu(FPDF_FORMFILLINFO* param,
FPDF_PAGE page, FPDF_PAGE page,
......
...@@ -91,6 +91,9 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM { ...@@ -91,6 +91,9 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
static int Form_GetPlatform(FPDF_FORMFILLINFO* param, static int Form_GetPlatform(FPDF_FORMFILLINFO* param,
void* platform, void* platform,
int length); int length);
static void Form_PageEvent(FPDF_FORMFILLINFO* param,
int page_count,
unsigned long event_type);
static FPDF_BOOL Form_PopupMenu(FPDF_FORMFILLINFO* param, static FPDF_BOOL Form_PopupMenu(FPDF_FORMFILLINFO* param,
FPDF_PAGE page, FPDF_PAGE page,
FPDF_WIDGET widget, FPDF_WIDGET widget,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment