Chromium Code Reviews| 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_) | |
|
Tom Sepez
2016/08/25 20:36:28
nit: branch probably not needed.
| |
| 3192 in_flight_visible_page_.reset(); | |
| 3193 | |
| 3183 if (index == most_visible_page_ || !form_) | 3194 if (index == most_visible_page_ || !form_) |
| 3184 return; | 3195 return; |
| 3185 if (most_visible_page_ != -1 && called_do_document_action_) { | 3196 if (most_visible_page_ != -1 && called_do_document_action_) { |
| 3186 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); | 3197 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); |
| 3187 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); | 3198 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); |
| 3188 } | 3199 } |
| 3189 most_visible_page_ = index; | 3200 most_visible_page_ = index; |
| 3190 #if defined(OS_LINUX) | 3201 #if defined(OS_LINUX) |
| 3191 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); | 3202 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); |
| 3192 #endif | 3203 #endif |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3506 if (index == -1) | 3517 if (index == -1) |
| 3507 index = engine->GetMostVisiblePage(); | 3518 index = engine->GetMostVisiblePage(); |
| 3508 */ | 3519 */ |
| 3509 if (index == -1) | 3520 if (index == -1) |
| 3510 return; | 3521 return; |
| 3511 | 3522 |
| 3512 // This is the only list of named actions per the spec (see 12.6.4.11). Adobe | 3523 // 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 | 3524 // 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. | 3525 // and we haven't got bugs about them, no need to now. |
| 3515 if (action == "NextPage") { | 3526 if (action == "NextPage") { |
| 3516 engine->client_->ScrollToPage(index + 1); | 3527 engine->ScrollToPage(index + 1); |
| 3517 } else if (action == "PrevPage") { | 3528 } else if (action == "PrevPage") { |
| 3518 engine->client_->ScrollToPage(index - 1); | 3529 engine->ScrollToPage(index - 1); |
| 3519 } else if (action == "FirstPage") { | 3530 } else if (action == "FirstPage") { |
| 3520 engine->client_->ScrollToPage(0); | 3531 engine->ScrollToPage(0); |
| 3521 } else if (action == "LastPage") { | 3532 } else if (action == "LastPage") { |
| 3522 engine->client_->ScrollToPage(engine->pages_.size() - 1); | 3533 engine->ScrollToPage(engine->pages_.size() - 1); |
| 3523 } | 3534 } |
| 3524 } | 3535 } |
| 3525 | 3536 |
| 3526 void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param, | 3537 void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param, |
| 3527 FPDF_WIDESTRING value, | 3538 FPDF_WIDESTRING value, |
| 3528 FPDF_DWORD valueLen, | 3539 FPDF_DWORD valueLen, |
| 3529 FPDF_BOOL is_focus) { | 3540 FPDF_BOOL is_focus) { |
| 3530 // Do nothing for now. | 3541 // Do nothing for now. |
| 3531 // TODO(gene): use this signal to trigger OSK. | 3542 // TODO(gene): use this signal to trigger OSK. |
| 3532 } | 3543 } |
| 3533 | 3544 |
| 3534 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, | 3545 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, |
| 3535 FPDF_BYTESTRING uri) { | 3546 FPDF_BYTESTRING uri) { |
| 3536 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3547 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3537 engine->client_->NavigateTo(std::string(uri), CURRENT_TAB); | 3548 engine->client_->NavigateTo(std::string(uri), CURRENT_TAB); |
| 3538 } | 3549 } |
| 3539 | 3550 |
| 3540 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, | 3551 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, |
| 3541 int page_index, | 3552 int page_index, |
| 3542 int zoom_mode, | 3553 int zoom_mode, |
| 3543 float* position_array, | 3554 float* position_array, |
| 3544 int size_of_array) { | 3555 int size_of_array) { |
| 3545 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3556 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3546 engine->client_->ScrollToPage(page_index); | 3557 engine->ScrollToPage(page_index); |
| 3547 } | 3558 } |
| 3548 | 3559 |
| 3549 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, | 3560 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, |
| 3550 FPDF_WIDESTRING message, | 3561 FPDF_WIDESTRING message, |
| 3551 FPDF_WIDESTRING title, | 3562 FPDF_WIDESTRING title, |
| 3552 int type, | 3563 int type, |
| 3553 int icon) { | 3564 int icon) { |
| 3554 // See fpdfformfill.h for these values. | 3565 // See fpdfformfill.h for these values. |
| 3555 enum AlertType { | 3566 enum AlertType { |
| 3556 ALERT_TYPE_OK = 0, | 3567 ALERT_TYPE_OK = 0, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3665 FPDF_WIDESTRING url) { | 3676 FPDF_WIDESTRING url) { |
| 3666 std::string url_str = | 3677 std::string url_str = |
| 3667 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); | 3678 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); |
| 3668 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3679 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3669 engine->client_->SubmitForm(url_str, form_data, length); | 3680 engine->client_->SubmitForm(url_str, form_data, length); |
| 3670 } | 3681 } |
| 3671 | 3682 |
| 3672 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, | 3683 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, |
| 3673 int page_number) { | 3684 int page_number) { |
| 3674 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3685 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3675 engine->client_->ScrollToPage(page_number); | 3686 engine->ScrollToPage(page_number); |
| 3676 } | 3687 } |
| 3677 | 3688 |
| 3678 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, | 3689 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, |
| 3679 void* file_path, | 3690 void* file_path, |
| 3680 int length) { | 3691 int length) { |
| 3681 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); | 3692 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); |
| 3682 std::string path = engine->client_->ShowFileSelectionDialog(); | 3693 std::string path = engine->client_->ShowFileSelectionDialog(); |
| 3683 if (path.size() + 1 <= static_cast<size_t>(length)) | 3694 if (path.size() + 1 <= static_cast<size_t>(length)) |
| 3684 memcpy(file_path, &path[0], path.size() + 1); | 3695 memcpy(file_path, &path[0], path.size() + 1); |
| 3685 return path.size() + 1; | 3696 return path.size() + 1; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3918 FPDF_DOCUMENT doc = | 3929 FPDF_DOCUMENT doc = |
| 3919 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 3930 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
| 3920 if (!doc) | 3931 if (!doc) |
| 3921 return false; | 3932 return false; |
| 3922 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3933 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3923 FPDF_CloseDocument(doc); | 3934 FPDF_CloseDocument(doc); |
| 3924 return success; | 3935 return success; |
| 3925 } | 3936 } |
| 3926 | 3937 |
| 3927 } // namespace chrome_pdf | 3938 } // namespace chrome_pdf |
| OLD | NEW |