Merge pull request #16018 from Snuffleupagus/GeckoView-skip-pageLabels

[GeckoView] Skip fetching/parsing of pageLabels
This commit is contained in:
Jonas Jenwald 2023-02-07 21:36:30 +01:00 committed by GitHub
commit 72abcedf48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 17 deletions

View File

@ -467,7 +467,9 @@ const PDFViewerApplication = {
linkService: pdfLinkService, linkService: pdfLinkService,
eventBus, eventBus,
updateMatchesCountOnProgress: updateMatchesCountOnProgress:
typeof PDFJSDev === "undefined" || !PDFJSDev.test("GECKOVIEW"), typeof PDFJSDev === "undefined"
? !window.isGECKOVIEW
: !PDFJSDev.test("GECKOVIEW"),
}); });
this.findController = findController; this.findController = findController;
@ -1251,23 +1253,28 @@ const PDFViewerApplication = {
spreadMode = stored.spreadMode | 0; spreadMode = stored.spreadMode | 0;
} }
} }
// Always let the user preference/view history take precedence. // NOTE: Ignore the pageMode/pageLayout in GeckoView since there's no
if (pageMode && sidebarView === SidebarView.UNKNOWN) { // sidebar available, nor any UI for changing the Scroll/Spread modes.
sidebarView = apiPageModeToSidebarView(pageMode);
}
// NOTE: Always ignore the pageLayout in GeckoView since there's
// no UI available to change Scroll/Spread modes for the user.
if ( if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("GECKOVIEW")) && typeof PDFJSDev === "undefined"
pageLayout && ? !window.isGECKOVIEW
scrollMode === ScrollMode.UNKNOWN && : !PDFJSDev.test("GECKOVIEW")
spreadMode === SpreadMode.UNKNOWN
) { ) {
const modes = apiPageLayoutToViewerModes(pageLayout); // Always let the user preference/view history take precedence.
// TODO: Try to improve page-switching when using the mouse-wheel if (pageMode && sidebarView === SidebarView.UNKNOWN) {
// and/or arrow-keys before allowing the document to control this. sidebarView = apiPageModeToSidebarView(pageMode);
// scrollMode = modes.scrollMode; }
spreadMode = modes.spreadMode; if (
pageLayout &&
scrollMode === ScrollMode.UNKNOWN &&
spreadMode === SpreadMode.UNKNOWN
) {
const modes = apiPageLayoutToViewerModes(pageLayout);
// TODO: Try to improve page-switching when using the mouse-wheel
// and/or arrow-keys before allowing the document to control this.
// scrollMode = modes.scrollMode;
spreadMode = modes.spreadMode;
}
} }
this.setInitialView(hash, { this.setInitialView(hash, {
@ -1528,6 +1535,13 @@ const PDFViewerApplication = {
* @private * @private
*/ */
async _initializePageLabels(pdfDocument) { async _initializePageLabels(pdfDocument) {
if (
typeof PDFJSDev === "undefined"
? window.isGECKOVIEW
: PDFJSDev.test("GECKOVIEW")
) {
return;
}
const labels = await pdfDocument.getPageLabels(); const labels = await pdfDocument.getPageLabels();
if (pdfDocument !== this.pdfDocument) { if (pdfDocument !== this.pdfDocument) {

View File

@ -269,7 +269,9 @@ class PDFScriptingManager {
// NOTE: Always ignore the pageLayout in GeckoView since there's // NOTE: Always ignore the pageLayout in GeckoView since there's
// no UI available to change Scroll/Spread modes for the user. // no UI available to change Scroll/Spread modes for the user.
if ( if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("GECKOVIEW")) || (typeof PDFJSDev === "undefined"
? window.isGECKOVIEW
: PDFJSDev.test("GECKOVIEW")) ||
isInPresentationMode isInPresentationMode
) { ) {
return; return;

View File

@ -68,6 +68,7 @@ function webViewerLoad() {
document.head.append(link); document.head.append(link);
} }
window.isGECKOVIEW = true;
import("pdfjs-web/genericcom.js").then(function (genericCom) { import("pdfjs-web/genericcom.js").then(function (genericCom) {
PDFViewerApplication.run(config); PDFViewerApplication.run(config);