Skip to content
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

Fix toolbarViewer/toolbarContainer regressions (PR 18385, 18786 follow-up) #18831

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 10 additions & 11 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -876,6 +874,7 @@ const PDFViewerApplication = {

moveCaret(isUp, select) {
this._caretBrowsing ||= new CaretBrowsingMode(
this._globalAbortController.signal,
this.appConfig.mainContainer,
this.appConfig.viewerContainer,
this.appConfig.toolbar?.container
Expand Down
24 changes: 21 additions & 3 deletions web/caret_browsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down