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 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2277 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); | 2277 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); |
2278 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); | 2278 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); |
2279 if (!bookmark) | 2279 if (!bookmark) |
2280 return -1; | 2280 return -1; |
2281 dest = FPDFBookmark_GetDest(doc_, bookmark); | 2281 dest = FPDFBookmark_GetDest(doc_, bookmark); |
2282 } | 2282 } |
2283 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; | 2283 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; |
2284 } | 2284 } |
2285 | 2285 |
2286 int PDFiumEngine::GetMostVisiblePage() { | 2286 int PDFiumEngine::GetMostVisiblePage() { |
2287 if (in_flight_visible_page_) | |
2288 return *in_flight_visible_page_; | |
2289 | |
2287 CalculateVisiblePages(); | 2290 CalculateVisiblePages(); |
2288 return most_visible_page_; | 2291 return most_visible_page_; |
2289 } | 2292 } |
2290 | 2293 |
2291 pp::Rect PDFiumEngine::GetPageRect(int index) { | 2294 pp::Rect PDFiumEngine::GetPageRect(int index) { |
2292 pp::Rect rc(pages_[index]->rect()); | 2295 pp::Rect rc(pages_[index]->rect()); |
2293 rc.Inset(-kPageShadowLeft, -kPageShadowTop, | 2296 rc.Inset(-kPageShadowLeft, -kPageShadowTop, |
2294 -kPageShadowRight, -kPageShadowBottom); | 2297 -kPageShadowRight, -kPageShadowBottom); |
2295 return rc; | 2298 return rc; |
2296 } | 2299 } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2667 most_visible_page++; | 2670 most_visible_page++; |
2668 } | 2671 } |
2669 | 2672 |
2670 SetCurrentPage(most_visible_page); | 2673 SetCurrentPage(most_visible_page); |
2671 } | 2674 } |
2672 | 2675 |
2673 bool PDFiumEngine::IsPageVisible(int index) const { | 2676 bool PDFiumEngine::IsPageVisible(int index) const { |
2674 return base::ContainsValue(visible_pages_, index); | 2677 return base::ContainsValue(visible_pages_, index); |
2675 } | 2678 } |
2676 | 2679 |
2680 void PDFiumEngine::ScrollToPage(int page) { | |
2681 in_flight_visible_page_ = page; | |
2682 client_->ScrollToPage(page); | |
2683 } | |
2684 | |
2677 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { | 2685 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { |
2678 if (!doc_ || !form_) | 2686 if (!doc_ || !form_) |
2679 return false; | 2687 return false; |
2680 | 2688 |
2681 const int num_pages = static_cast<int>(pages_.size()); | 2689 const int num_pages = static_cast<int>(pages_.size()); |
2682 if (index < num_pages && pages_[index]->available()) | 2690 if (index < num_pages && pages_[index]->available()) |
2683 return true; | 2691 return true; |
2684 | 2692 |
2685 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { | 2693 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { |
2686 if (!base::ContainsValue(*pending, index)) | 2694 if (!base::ContainsValue(*pending, index)) |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3173 | 3181 |
3174 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { | 3182 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { |
3175 for (int page_index : visible_pages_) { | 3183 for (int page_index : visible_pages_) { |
3176 if (pages_[page_index]->GetPage() == page) | 3184 if (pages_[page_index]->GetPage() == page) |
3177 return page_index; | 3185 return page_index; |
3178 } | 3186 } |
3179 return -1; | 3187 return -1; |
3180 } | 3188 } |
3181 | 3189 |
3182 void PDFiumEngine::SetCurrentPage(int index) { | 3190 void PDFiumEngine::SetCurrentPage(int index) { |
3191 if (in_flight_visible_page_) { | |
3192 DCHECK(*in_flight_visible_page_ == index); | |
Tom Sepez
2016/08/25 19:19:22
This dcheck may be too strong -- what if we get a
tonikitoo
2016/08/25 20:17:51
Done.
| |
3193 in_flight_visible_page_.reset(); | |
3194 } | |
3195 | |
3183 if (index == most_visible_page_ || !form_) | 3196 if (index == most_visible_page_ || !form_) |
3184 return; | 3197 return; |
3185 if (most_visible_page_ != -1 && called_do_document_action_) { | 3198 if (most_visible_page_ != -1 && called_do_document_action_) { |
3186 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); | 3199 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); |
3187 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); | 3200 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); |
3188 } | 3201 } |
3189 most_visible_page_ = index; | 3202 most_visible_page_ = index; |
3190 #if defined(OS_LINUX) | 3203 #if defined(OS_LINUX) |
3191 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 3204 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
3192 #endif | 3205 #endif |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3506 if (index == -1) | 3519 if (index == -1) |
3507 index = engine->GetMostVisiblePage(); | 3520 index = engine->GetMostVisiblePage(); |
3508 */ | 3521 */ |
3509 if (index == -1) | 3522 if (index == -1) |
3510 return; | 3523 return; |
3511 | 3524 |
3512 // This is the only list of named actions per the spec (see 12.6.4.11). Adobe | 3525 // This is the only list of named actions per the spec (see 12.6.4.11). Adobe |
3513 // Reader supports more, like FitWidth, but since they're not part of the spec | 3526 // Reader supports more, like FitWidth, but since they're not part of the spec |
3514 // and we haven't got bugs about them, no need to now. | 3527 // and we haven't got bugs about them, no need to now. |
3515 if (action == "NextPage") { | 3528 if (action == "NextPage") { |
3516 engine->client_->ScrollToPage(index + 1); | 3529 engine->ScrollToPage(index + 1); |
3517 } else if (action == "PrevPage") { | 3530 } else if (action == "PrevPage") { |
3518 engine->client_->ScrollToPage(index - 1); | 3531 engine->ScrollToPage(index - 1); |
3519 } else if (action == "FirstPage") { | 3532 } else if (action == "FirstPage") { |
3520 engine->client_->ScrollToPage(0); | 3533 engine->ScrollToPage(0); |
3521 } else if (action == "LastPage") { | 3534 } else if (action == "LastPage") { |
3522 engine->client_->ScrollToPage(engine->pages_.size() - 1); | 3535 engine->ScrollToPage(engine->pages_.size() - 1); |
3523 } | 3536 } |
3524 } | 3537 } |
3525 | 3538 |
3526 void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param, | 3539 void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param, |
3527 FPDF_WIDESTRING value, | 3540 FPDF_WIDESTRING value, |
3528 FPDF_DWORD valueLen, | 3541 FPDF_DWORD valueLen, |
3529 FPDF_BOOL is_focus) { | 3542 FPDF_BOOL is_focus) { |
3530 // Do nothing for now. | 3543 // Do nothing for now. |
3531 // TODO(gene): use this signal to trigger OSK. | 3544 // TODO(gene): use this signal to trigger OSK. |
3532 } | 3545 } |
3533 | 3546 |
3534 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, | 3547 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, |
3535 FPDF_BYTESTRING uri) { | 3548 FPDF_BYTESTRING uri) { |
3536 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3549 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3537 engine->client_->NavigateTo(std::string(uri), CURRENT_TAB); | 3550 engine->client_->NavigateTo(std::string(uri), CURRENT_TAB); |
3538 } | 3551 } |
3539 | 3552 |
3540 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, | 3553 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, |
3541 int page_index, | 3554 int page_index, |
3542 int zoom_mode, | 3555 int zoom_mode, |
3543 float* position_array, | 3556 float* position_array, |
3544 int size_of_array) { | 3557 int size_of_array) { |
3545 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3558 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3546 engine->client_->ScrollToPage(page_index); | 3559 engine->ScrollToPage(page_index); |
3547 } | 3560 } |
3548 | 3561 |
3549 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, | 3562 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, |
3550 FPDF_WIDESTRING message, | 3563 FPDF_WIDESTRING message, |
3551 FPDF_WIDESTRING title, | 3564 FPDF_WIDESTRING title, |
3552 int type, | 3565 int type, |
3553 int icon) { | 3566 int icon) { |
3554 // See fpdfformfill.h for these values. | 3567 // See fpdfformfill.h for these values. |
3555 enum AlertType { | 3568 enum AlertType { |
3556 ALERT_TYPE_OK = 0, | 3569 ALERT_TYPE_OK = 0, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3665 FPDF_WIDESTRING url) { | 3678 FPDF_WIDESTRING url) { |
3666 std::string url_str = | 3679 std::string url_str = |
3667 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 3680 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
3668 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3681 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3669 engine->client_->SubmitForm(url_str, form_data, length); | 3682 engine->client_->SubmitForm(url_str, form_data, length); |
3670 } | 3683 } |
3671 | 3684 |
3672 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, | 3685 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, |
3673 int page_number) { | 3686 int page_number) { |
3674 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3687 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3675 engine->client_->ScrollToPage(page_number); | 3688 engine->ScrollToPage(page_number); |
3676 } | 3689 } |
3677 | 3690 |
3678 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, | 3691 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, |
3679 void* file_path, | 3692 void* file_path, |
3680 int length) { | 3693 int length) { |
3681 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3694 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
3682 std::string path = engine->client_->ShowFileSelectionDialog(); | 3695 std::string path = engine->client_->ShowFileSelectionDialog(); |
3683 if (path.size() + 1 <= static_cast<size_t>(length)) | 3696 if (path.size() + 1 <= static_cast<size_t>(length)) |
3684 memcpy(file_path, &path[0], path.size() + 1); | 3697 memcpy(file_path, &path[0], path.size() + 1); |
3685 return path.size() + 1; | 3698 return path.size() + 1; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3918 FPDF_DOCUMENT doc = | 3931 FPDF_DOCUMENT doc = |
3919 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 3932 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
3920 if (!doc) | 3933 if (!doc) |
3921 return false; | 3934 return false; |
3922 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3935 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3923 FPDF_CloseDocument(doc); | 3936 FPDF_CloseDocument(doc); |
3924 return success; | 3937 return success; |
3925 } | 3938 } |
3926 | 3939 |
3927 } // namespace chrome_pdf | 3940 } // namespace chrome_pdf |
OLD | NEW |