From b1df164a26d22e1c9289962c7267a79aa5ce342e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 28 Sep 2024 12:21:33 +0200 Subject: [PATCH] Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up) We disable any non-default CursorTool in PresentationMode and during Editing, since they don't make sense there and to prevent problems such as e.g. [bug 1792422](https://bugzilla.mozilla.org/show_bug.cgi?id=1792422). Hence it seems like a good idea to *also* disable the relevant SecondaryToolbar-buttons, to avoid the user being surprised that the CursorTools-buttons do nothing if clicked. --- web/pdf_cursor_tools.js | 25 +++++++++++++++++-------- web/secondary_toolbar.js | 5 ++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/web/pdf_cursor_tools.js b/web/pdf_cursor_tools.js index ff94f1238aa8c..ad91c07196fa8 100644 --- a/web/pdf_cursor_tools.js +++ b/web/pdf_cursor_tools.js @@ -65,7 +65,19 @@ class PDFCursorTools { // Cursor tools cannot be used in PresentationMode/AnnotationEditor. return; } + this.#switchTool(tool); + } + + #switchTool(tool, disabled = false) { if (tool === this.#active) { + if (this.#prevActive !== null) { + // Ensure that the `disabled`-attribute of the buttons will be updated. + this.eventBus.dispatch("cursortoolchanged", { + source: this, + tool, + disabled, + }); + } return; // The requested tool is already active. } @@ -103,6 +115,7 @@ class PDFCursorTools { this.eventBus.dispatch("cursortoolchanged", { source: this, tool, + disabled, }); } @@ -122,21 +135,17 @@ class PDFCursorTools { presentationModeState = PresentationModeState.NORMAL; const disableActive = () => { - const prevActive = this.#active; - - this.switchTool(CursorTool.SELECT); - this.#prevActive ??= prevActive; // Keep track of the first one. + this.#prevActive ??= this.#active; // Keep track of the first one. + this.#switchTool(CursorTool.SELECT, /* disabled = */ true); }; const enableActive = () => { - const prevActive = this.#prevActive; - if ( - prevActive !== null && + this.#prevActive !== null && annotationEditorMode === AnnotationEditorType.NONE && presentationModeState === PresentationModeState.NORMAL ) { + this.#switchTool(this.#prevActive); this.#prevActive = null; - this.switchTool(prevActive); } }; diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js index 8ba23f5304e5e..919b17b21c49a 100644 --- a/web/secondary_toolbar.js +++ b/web/secondary_toolbar.js @@ -240,11 +240,14 @@ class SecondaryToolbar { eventBus._on("spreadmodechanged", this.#spreadModeChanged.bind(this)); } - #cursorToolChanged({ tool }) { + #cursorToolChanged({ tool, disabled }) { const { cursorSelectToolButton, cursorHandToolButton } = this.#opts; toggleCheckedBtn(cursorSelectToolButton, tool === CursorTool.SELECT); toggleCheckedBtn(cursorHandToolButton, tool === CursorTool.HAND); + + cursorSelectToolButton.disabled = disabled; + cursorHandToolButton.disabled = disabled; } #scrollModeChanged({ mode }) {