Skip to content

Commit dac3139

Browse files
committed
Provide the position of some elements when the dimensions of the viewport are updated (bug 1907890)
1 parent 2d25437 commit dac3139

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

web/app.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ const PDFViewerApplication = {
178178
_nimbusDataPromise: null,
179179
_caretBrowsing: null,
180180
_isScrolling: false,
181+
_idsToWatchOutPromise: null,
181182

182183
// Called once when the document is loaded.
183184
async initialize(appConfig) {
@@ -187,6 +188,7 @@ const PDFViewerApplication = {
187188
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
188189
l10nPromise = this.externalServices.createL10n();
189190
if (PDFJSDev.test("MOZCENTRAL")) {
191+
this._idsToWatchOutPromise = this.externalServices.getIdsToWatchOut();
190192
this._allowedGlobalEventsPromise =
191193
this.externalServices.getGlobalEventNames();
192194
}
@@ -1995,6 +1997,49 @@ const PDFViewerApplication = {
19951997
}
19961998
addWindowResolutionChange();
19971999

2000+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
2001+
// We want to track the position of some elements in order to display a
2002+
// positioned callout.
2003+
// If the viewer has its dimensions in some specific range, some elements
2004+
// are either hidden or made visible (for example the print button is
2005+
// moved from the main toolbar to the secondary one).
2006+
this._idsToWatchOutPromise?.then(ids => {
2007+
if (!ids) {
2008+
return;
2009+
}
2010+
const callback = () => {
2011+
const detail = Object.create(null);
2012+
for (const id of ids) {
2013+
detail[id] = document.getElementById(id).getBoundingClientRect();
2014+
}
2015+
eventBus.dispatch("updateviewermaxwidth", {
2016+
source: this,
2017+
detail,
2018+
});
2019+
};
2020+
2021+
// The list of sizes is based on the ones we've in viewer.css.
2022+
const sizes = [900, 840, 750, 690, 560];
2023+
for (let i = 0, ii = sizes.length; i < ii; i++) {
2024+
let mediaQueryList;
2025+
const size = sizes[i];
2026+
if (i === 0) {
2027+
mediaQueryList = window.matchMedia(`(width > ${size}px)`);
2028+
} else if (i === ii - 1) {
2029+
mediaQueryList = window.matchMedia(`(width <= ${size}px)`);
2030+
} else {
2031+
mediaQueryList = window.matchMedia(
2032+
`(width > ${sizes[i + 1]}px) and (width <= ${size}px)`
2033+
);
2034+
}
2035+
mediaQueryList.addEventListener("change", callback, {
2036+
signal,
2037+
});
2038+
}
2039+
callback();
2040+
});
2041+
}
2042+
19982043
window.addEventListener("wheel", webViewerWheel, {
19992044
passive: false,
20002045
signal,

web/external_services.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class BaseExternalServices {
5252
}
5353

5454
dispatchGlobalEvent(_event) {}
55+
56+
async getIdsToWatchOut() {}
5557
}
5658

5759
export { BaseExternalServices };

web/firefoxcom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ class ExternalServices extends BaseExternalServices {
425425
dispatchGlobalEvent(event) {
426426
FirefoxCom.request("dispatchGlobalEvent", event);
427427
}
428+
429+
async getIdsToWatchOut() {
430+
return FirefoxCom.requestAsync("getIdsToWatchOut", null);
431+
}
428432
}
429433

430434
export { DownloadManager, ExternalServices, initCom, MLManager, Preferences };

web/viewer.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,12 @@ dialog :link {
14841484
display: none;
14851485
}
14861486

1487+
/*
1488+
In order to correctly display the potential callouts in Firefox we want to
1489+
track the positions of some elements.
1490+
So the different dimensions used here are also used in app.js (see
1491+
bindWindowEvents)
1492+
*/
14871493
@media all and (max-width: 900px) {
14881494
#toolbarViewerMiddle {
14891495
display: table;

0 commit comments

Comments
 (0)