Merge pull request #16284 from calixteman/gv_keep_button

[GeckoView] Show the download button by default and add a pref to disable it (bug 1827963)
This commit is contained in:
calixteman 2023-04-13 21:17:32 +02:00 committed by GitHub
commit 342dc760da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 23 deletions

View File

@ -588,7 +588,17 @@ const PDFViewerApplication = {
} }
if (appConfig.toolbar) { if (appConfig.toolbar) {
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n); if (
typeof PDFJSDev === "undefined"
? window.isGECKOVIEW
: PDFJSDev.test("GECKOVIEW")
) {
if (AppOptions.get("enableFloatingToolbar")) {
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n);
}
} else {
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, this.l10n);
}
} }
if (appConfig.secondaryToolbar) { if (appConfig.secondaryToolbar) {
@ -2917,17 +2927,6 @@ function webViewerTouchEnd(evt) {
} }
function webViewerClick(evt) { function webViewerClick(evt) {
if (
typeof PDFJSDev === "undefined"
? window.isGECKOVIEW
: PDFJSDev.test("GECKOVIEW")
) {
if (
document.activeElement === PDFViewerApplication.appConfig.mainContainer
) {
PDFViewerApplication.toolbar?.toggle();
}
}
if (!PDFViewerApplication.secondaryToolbar?.isOpen) { if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
return; return;
} }

View File

@ -88,6 +88,11 @@ const defaultOptions = {
value: false, value: false,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE, kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
}, },
enableFloatingToolbar: {
/** @type {boolean} */
value: typeof PDFJSDev === "undefined",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
enablePermissions: { enablePermissions: {
/** @type {boolean} */ /** @type {boolean} */
value: false, value: false,

View File

@ -20,16 +20,24 @@
* @property {HTMLButtonElement} download - Button to download the document. * @property {HTMLButtonElement} download - Button to download the document.
*/ */
const TIME_BEFORE_SHOWING_TOOLBAR = 200;
class Toolbar { class Toolbar {
#buttons; #buttons;
#checkForScrollEndBound = this.#checkForScrollEnd.bind(this);
#eventBus; #eventBus;
#toolbar; #hideBound = this.#hide.bind(this);
#mainContainer; #mainContainer;
#toggleBound = this.toggle.bind(this); #scrollEndTimeoutId = null;
#showBound = this.#show.bind(this);
#toolbar;
/** /**
* @param {ToolbarOptions} options * @param {ToolbarOptions} options
@ -44,6 +52,7 @@ class Toolbar {
// Bind the event listeners for click and various other actions. // Bind the event listeners for click and various other actions.
this.#bindListeners(options); this.#bindListeners(options);
this.#checkForScrollEnd();
} }
setPageNumber(pageNumber, pageLabel) {} setPageNumber(pageNumber, pageLabel) {}
@ -67,12 +76,34 @@ class Toolbar {
updateLoadingIndicatorState(loading = false) {} updateLoadingIndicatorState(loading = false) {}
toggle() { #checkForScrollEnd() {
if (this.#toolbar.classList.toggle("show")) { if (this.#scrollEndTimeoutId !== null) {
this.#mainContainer.addEventListener("scroll", this.#toggleBound); clearTimeout(this.#scrollEndTimeoutId);
} else {
this.#mainContainer.removeEventListener("scroll", this.#toggleBound);
} }
this.#scrollEndTimeoutId = setTimeout(
this.#showBound,
TIME_BEFORE_SHOWING_TOOLBAR
);
}
#show() {
this.#toolbar.classList.toggle("show", true);
this.#mainContainer.removeEventListener(
"scroll",
this.#checkForScrollEndBound
);
this.#scrollEndTimeoutId = null;
this.#mainContainer.addEventListener("scroll", this.#hideBound);
}
#hide() {
this.#toolbar.classList.toggle("show", false);
this.#mainContainer.removeEventListener("scroll", this.#hideBound);
this.#mainContainer.addEventListener(
"scroll",
this.#checkForScrollEndBound
);
this.#checkForScrollEnd();
} }
} }

View File

@ -19,7 +19,7 @@
--dir-factor: 1; --dir-factor: 1;
--scale-select-width: 140px; --scale-select-width: 140px;
--toolbar-icon-opacity: 0.7; --toolbar-icon-opacity: 1;
--doorhanger-icon-opacity: 0.9; --doorhanger-icon-opacity: 0.9;
--main-color: rgba(12, 12, 13, 1); --main-color: rgba(12, 12, 13, 1);
@ -158,15 +158,18 @@ body {
bottom: 5%; bottom: 5%;
right: 5%; right: 5%;
background-color: transparent; background-color: transparent;
z-index: 100000; transition-property: opacity;
transition-duration: 400ms;
} }
#floatingToolbar.show { #floatingToolbar.show {
display: block; z-index: 100000;
opacity: 1;
} }
#floatingToolbar:not(show) { #floatingToolbar:not(show) {
display: none; z-index: -1;
opacity: 0;
} }
.toolbarButton { .toolbarButton {