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

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

Issue 2271263002: Allows the PDF engine return the page index it is scrolling to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed thestig's review Created 4 years, 3 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 | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | 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 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str()); 2276 reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str());
2277 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide); 2277 FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide);
2278 if (!bookmark) 2278 if (!bookmark)
2279 return -1; 2279 return -1;
2280 dest = FPDFBookmark_GetDest(doc_, bookmark); 2280 dest = FPDFBookmark_GetDest(doc_, bookmark);
2281 } 2281 }
2282 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1; 2282 return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1;
2283 } 2283 }
2284 2284
2285 int PDFiumEngine::GetMostVisiblePage() { 2285 int PDFiumEngine::GetMostVisiblePage() {
2286 if (in_flight_visible_page_)
2287 return *in_flight_visible_page_;
2288
2286 CalculateVisiblePages(); 2289 CalculateVisiblePages();
2287 return most_visible_page_; 2290 return most_visible_page_;
2288 } 2291 }
2289 2292
2290 pp::Rect PDFiumEngine::GetPageRect(int index) { 2293 pp::Rect PDFiumEngine::GetPageRect(int index) {
2291 pp::Rect rc(pages_[index]->rect()); 2294 pp::Rect rc(pages_[index]->rect());
2292 rc.Inset(-kPageShadowLeft, -kPageShadowTop, 2295 rc.Inset(-kPageShadowLeft, -kPageShadowTop,
2293 -kPageShadowRight, -kPageShadowBottom); 2296 -kPageShadowRight, -kPageShadowBottom);
2294 return rc; 2297 return rc;
2295 } 2298 }
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 most_visible_page++; 2673 most_visible_page++;
2671 } 2674 }
2672 2675
2673 SetCurrentPage(most_visible_page); 2676 SetCurrentPage(most_visible_page);
2674 } 2677 }
2675 2678
2676 bool PDFiumEngine::IsPageVisible(int index) const { 2679 bool PDFiumEngine::IsPageVisible(int index) const {
2677 return base::ContainsValue(visible_pages_, index); 2680 return base::ContainsValue(visible_pages_, index);
2678 } 2681 }
2679 2682
2683 void PDFiumEngine::ScrollToPage(int page) {
2684 in_flight_visible_page_ = page;
2685 client_->ScrollToPage(page);
2686 }
2687
2680 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) { 2688 bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) {
2681 if (!doc_ || !form_) 2689 if (!doc_ || !form_)
2682 return false; 2690 return false;
2683 2691
2684 const int num_pages = static_cast<int>(pages_.size()); 2692 const int num_pages = static_cast<int>(pages_.size());
2685 if (index < num_pages && pages_[index]->available()) 2693 if (index < num_pages && pages_[index]->available())
2686 return true; 2694 return true;
2687 2695
2688 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) { 2696 if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) {
2689 if (!base::ContainsValue(*pending, index)) 2697 if (!base::ContainsValue(*pending, index))
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
3176 3184
3177 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { 3185 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) {
3178 for (int page_index : visible_pages_) { 3186 for (int page_index : visible_pages_) {
3179 if (pages_[page_index]->GetPage() == page) 3187 if (pages_[page_index]->GetPage() == page)
3180 return page_index; 3188 return page_index;
3181 } 3189 }
3182 return -1; 3190 return -1;
3183 } 3191 }
3184 3192
3185 void PDFiumEngine::SetCurrentPage(int index) { 3193 void PDFiumEngine::SetCurrentPage(int index) {
3194 in_flight_visible_page_.reset();
3195
3186 if (index == most_visible_page_ || !form_) 3196 if (index == most_visible_page_ || !form_)
3187 return; 3197 return;
3188 3198
3189 if (most_visible_page_ != -1 && called_do_document_action_) { 3199 if (most_visible_page_ != -1 && called_do_document_action_) {
3190 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); 3200 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage();
3191 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); 3201 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE);
3192 } 3202 }
3193 most_visible_page_ = index; 3203 most_visible_page_ = index;
3194 #if defined(OS_LINUX) 3204 #if defined(OS_LINUX)
3195 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); 3205 g_last_instance_id = client_->GetPluginInstance()->pp_instance();
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 if (index == -1) 3529 if (index == -1)
3520 index = engine->GetMostVisiblePage(); 3530 index = engine->GetMostVisiblePage();
3521 */ 3531 */
3522 if (index == -1) 3532 if (index == -1)
3523 return; 3533 return;
3524 3534
3525 // This is the only list of named actions per the spec (see 12.6.4.11). Adobe 3535 // This is the only list of named actions per the spec (see 12.6.4.11). Adobe
3526 // Reader supports more, like FitWidth, but since they're not part of the spec 3536 // Reader supports more, like FitWidth, but since they're not part of the spec
3527 // and we haven't got bugs about them, no need to now. 3537 // and we haven't got bugs about them, no need to now.
3528 if (action == "NextPage") { 3538 if (action == "NextPage") {
3529 engine->client_->ScrollToPage(index + 1); 3539 engine->ScrollToPage(index + 1);
3530 } else if (action == "PrevPage") { 3540 } else if (action == "PrevPage") {
3531 engine->client_->ScrollToPage(index - 1); 3541 engine->ScrollToPage(index - 1);
3532 } else if (action == "FirstPage") { 3542 } else if (action == "FirstPage") {
3533 engine->client_->ScrollToPage(0); 3543 engine->ScrollToPage(0);
3534 } else if (action == "LastPage") { 3544 } else if (action == "LastPage") {
3535 engine->client_->ScrollToPage(engine->pages_.size() - 1); 3545 engine->ScrollToPage(engine->pages_.size() - 1);
3536 } 3546 }
3537 } 3547 }
3538 3548
3539 void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param, 3549 void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param,
3540 FPDF_WIDESTRING value, 3550 FPDF_WIDESTRING value,
3541 FPDF_DWORD valueLen, 3551 FPDF_DWORD valueLen,
3542 FPDF_BOOL is_focus) { 3552 FPDF_BOOL is_focus) {
3543 // Do nothing for now. 3553 // Do nothing for now.
3544 // TODO(gene): use this signal to trigger OSK. 3554 // TODO(gene): use this signal to trigger OSK.
3545 } 3555 }
3546 3556
3547 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param, 3557 void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param,
3548 FPDF_BYTESTRING uri) { 3558 FPDF_BYTESTRING uri) {
3549 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3559 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3550 engine->client_->NavigateTo(std::string(uri), CURRENT_TAB); 3560 engine->client_->NavigateTo(std::string(uri), CURRENT_TAB);
3551 } 3561 }
3552 3562
3553 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param, 3563 void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param,
3554 int page_index, 3564 int page_index,
3555 int zoom_mode, 3565 int zoom_mode,
3556 float* position_array, 3566 float* position_array,
3557 int size_of_array) { 3567 int size_of_array) {
3558 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3568 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3559 engine->client_->ScrollToPage(page_index); 3569 engine->ScrollToPage(page_index);
3560 } 3570 }
3561 3571
3562 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param, 3572 int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param,
3563 FPDF_WIDESTRING message, 3573 FPDF_WIDESTRING message,
3564 FPDF_WIDESTRING title, 3574 FPDF_WIDESTRING title,
3565 int type, 3575 int type,
3566 int icon) { 3576 int icon) {
3567 // See fpdfformfill.h for these values. 3577 // See fpdfformfill.h for these values.
3568 enum AlertType { 3578 enum AlertType {
3569 ALERT_TYPE_OK = 0, 3579 ALERT_TYPE_OK = 0,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3678 FPDF_WIDESTRING url) { 3688 FPDF_WIDESTRING url) {
3679 std::string url_str = 3689 std::string url_str =
3680 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url)); 3690 base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url));
3681 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3691 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3682 engine->client_->SubmitForm(url_str, form_data, length); 3692 engine->client_->SubmitForm(url_str, form_data, length);
3683 } 3693 }
3684 3694
3685 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param, 3695 void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param,
3686 int page_number) { 3696 int page_number) {
3687 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3697 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3688 engine->client_->ScrollToPage(page_number); 3698 engine->ScrollToPage(page_number);
3689 } 3699 }
3690 3700
3691 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param, 3701 int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param,
3692 void* file_path, 3702 void* file_path,
3693 int length) { 3703 int length) {
3694 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3704 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3695 std::string path = engine->client_->ShowFileSelectionDialog(); 3705 std::string path = engine->client_->ShowFileSelectionDialog();
3696 if (path.size() + 1 <= static_cast<size_t>(length)) 3706 if (path.size() + 1 <= static_cast<size_t>(length))
3697 memcpy(file_path, &path[0], path.size() + 1); 3707 memcpy(file_path, &path[0], path.size() + 1);
3698 return path.size() + 1; 3708 return path.size() + 1;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
3961 FPDF_DOCUMENT doc = 3971 FPDF_DOCUMENT doc =
3962 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3972 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3963 if (!doc) 3973 if (!doc)
3964 return false; 3974 return false;
3965 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3975 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3966 FPDF_CloseDocument(doc); 3976 FPDF_CloseDocument(doc);
3967 return success; 3977 return success;
3968 } 3978 }
3969 3979
3970 } // namespace chrome_pdf 3980 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698