From f2a132f826a9b739b19bfb14efb86dfc02531d86 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 1 Oct 2024 17:17:40 +0200 Subject: [PATCH 1/3] Use the "correct" toolbar container element in `getViewerConfiguration` (PR 18385 follow-up) With the changes made in PR 18385 the `toolbarViewer` element is now shorter than before, since the padding is applied on its `toolbarContainer` parent-element instead. This causes two separate regressions: - Clicking at the very top/bottom of the toolbar no longer closes the secondaryToolbar like previously. - The `CaretBrowsingMode`-constructor no longer computes the toolbar-height correctly. Given how/where the `container`-property is being used these changes *should* thus be safe. --- web/viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index 1115af56e03aa..a60142ae5d1b1 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -41,7 +41,7 @@ function getViewerConfiguration() { mainContainer: document.getElementById("viewerContainer"), viewerContainer: document.getElementById("viewer"), toolbar: { - container: document.getElementById("toolbarViewer"), + container: document.getElementById("toolbarContainer"), numPages: document.getElementById("numPages"), pageNumber: document.getElementById("pageNumber"), scaleSelect: document.getElementById("scaleSelect"), From 7c9d177826958bd02fe4d337f7becb8b9fe54c17 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 1 Oct 2024 17:37:44 +0200 Subject: [PATCH 2/3] Update the `CaretBrowsingMode` toolbar-height if the `toolbarDensity` preference changes (PR 18786 follow-up) Otherwise the isVisible-calculations may not work correctly. --- web/app.js | 1 + web/caret_browsing.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index 2f18b60498cba..d5d61b82b7e2a 100644 --- a/web/app.js +++ b/web/app.js @@ -876,6 +876,7 @@ const PDFViewerApplication = { moveCaret(isUp, select) { this._caretBrowsing ||= new CaretBrowsingMode( + this._globalAbortController.signal, this.appConfig.mainContainer, this.appConfig.viewerContainer, this.appConfig.toolbar?.container diff --git a/web/caret_browsing.js b/web/caret_browsing.js index 9fc3275bec6dd..fbbc9c9594f9d 100644 --- a/web/caret_browsing.js +++ b/web/caret_browsing.js @@ -19,14 +19,32 @@ const PRECISION = 1e-1; class CaretBrowsingMode { #mainContainer; - #toolBarHeight; + #toolBarHeight = 0; #viewerContainer; - constructor(mainContainer, viewerContainer, toolbarContainer) { + constructor(abortSignal, mainContainer, viewerContainer, toolbarContainer) { this.#mainContainer = mainContainer; this.#viewerContainer = viewerContainer; - this.#toolBarHeight = toolbarContainer?.getBoundingClientRect().height ?? 0; + + if (!toolbarContainer) { + return; + } + this.#toolBarHeight = toolbarContainer.getBoundingClientRect().height; + + const toolbarObserver = new ResizeObserver(entries => { + for (const entry of entries) { + if (entry.target === toolbarContainer) { + this.#toolBarHeight = Math.floor(entry.borderBoxSize[0].blockSize); + break; + } + } + }); + toolbarObserver.observe(toolbarContainer); + + abortSignal.addEventListener("abort", () => toolbarObserver.disconnect(), { + once: true, + }); } /** From 07e8afb247e78c50e478ce4b7796cd1f1079eeb0 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 1 Oct 2024 17:54:22 +0200 Subject: [PATCH 3/3] Always set `AppOptions.eventBus`, regardless of build, to make local testing easier --- web/app.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/web/app.js b/web/app.js index d5d61b82b7e2a..2a56c8916bb96 100644 --- a/web/app.js +++ b/web/app.js @@ -376,18 +376,16 @@ const PDFViewerApplication = { async _initializeViewerComponents() { const { appConfig, externalServices, l10n } = this; - let eventBus; - if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { - eventBus = AppOptions.eventBus = new FirefoxEventBus( - AppOptions.get("allowedGlobalEvents"), - externalServices, - AppOptions.get("isInAutomation") - ); - } else { - eventBus = new EventBus(); - } + const eventBus = + typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") + ? new FirefoxEventBus( + AppOptions.get("allowedGlobalEvents"), + externalServices, + AppOptions.get("isInAutomation") + ) + : new EventBus(); + this.eventBus = AppOptions.eventBus = eventBus; this.mlManager?.setEventBus(eventBus, this._globalAbortController.signal); - this.eventBus = eventBus; this.overlayManager = new OverlayManager();