Skip to content

Provide the position of some elements when the dimensions of the viewport are updated (bug 1907890) #18439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
@@ -178,6 +178,7 @@ const PDFViewerApplication = {
_nimbusDataPromise: null,
_caretBrowsing: null,
_isScrolling: false,
_idsToWatchOutPromise: null,

// Called once when the document is loaded.
async initialize(appConfig) {
@@ -187,6 +188,7 @@ const PDFViewerApplication = {
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
l10nPromise = this.externalServices.createL10n();
if (PDFJSDev.test("MOZCENTRAL")) {
this._idsToWatchOutPromise = this.externalServices.getIdsToWatchOut();
this._allowedGlobalEventsPromise =
this.externalServices.getGlobalEventNames();
}
@@ -486,6 +488,7 @@ const PDFViewerApplication = {
mlManager: this.mlManager,
abortSignal: this._globalAbortController.signal,
enableHWA,
idsToWatchOutPromise: this._idsToWatchOutPromise,
});
this.pdfViewer = pdfViewer;

2 changes: 2 additions & 0 deletions web/external_services.js
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ class BaseExternalServices {
}

dispatchGlobalEvent(_event) {}

async getIdsToWatchOut() {}
}

export { BaseExternalServices };
4 changes: 4 additions & 0 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
@@ -425,6 +425,10 @@ class ExternalServices extends BaseExternalServices {
dispatchGlobalEvent(event) {
FirefoxCom.request("dispatchGlobalEvent", event);
}

async getIdsToWatchOut() {
return FirefoxCom.requestAsync("getIdsToWatchOut", null);
}
}

export { DownloadManager, ExternalServices, initCom, MLManager, Preferences };
26 changes: 26 additions & 0 deletions web/pdf_viewer.js
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
import { SimpleLinkService } from "./pdf_link_service.js";

const DEFAULT_CACHE_SIZE = 10;
const UPDATE_ELEMENTS_RECT_DELAY = 100;

const PagesCountLimit = {
FORCE_SCROLL_MODE_PAGE: 10000,
@@ -233,6 +234,10 @@ class PDFViewer {

#hiddenCopyElement = null;

#idsToWatchOutPromise = null;

#updateElementsRectTimeoutId = null;

#interruptCopyCondition = false;

#previousContainerHeight = 0;
@@ -308,6 +313,7 @@ class PDFViewer {
this.pageColors = options.pageColors || null;
this.#mlManager = options.mlManager || null;
this.#enableHWA = options.enableHWA || false;
this.#idsToWatchOutPromise = options.idsToWatchOutPromise || null;

this.defaultRenderingQueue = !options.renderingQueue;
if (
@@ -2246,12 +2252,32 @@ class PDFViewer {
}
}

#updateElementsRect() {
this.#idsToWatchOutPromise?.then(ids => {
if (!ids?.length) {
this.#idsToWatchOutPromise = null;
return;
}
clearTimeout(this.#updateElementsRectTimeoutId);
this.#updateElementsRectTimeoutId = setTimeout(() => {
const detail = Object.create(null);
for (const id of ids) {
detail[id] = document.getElementById(id).getBoundingClientRect();
}
this.eventBus.dispatch("updateelementsposition", {
detail,
});
}, UPDATE_ELEMENTS_RECT_DELAY);
});
}

#resizeObserverCallback(entries) {
for (const entry of entries) {
if (entry.target === this.container) {
this.#updateContainerHeightCss(
Math.floor(entry.borderBoxSize[0].blockSize)
);
this.#updateElementsRect();
this.#containerTopLeft = null;
break;
}