From 19182d5f25a66f1b822fe491db59959d8ea6d2ab Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Thu, 25 Aug 2022 23:18:02 +0200
Subject: [PATCH] [editor] Remove the `editorNone` toolbar button (bug 1787295)

---
 l10n/en-US/viewer.properties            |  2 --
 web/images/toolbarButton-editorNone.svg |  4 ---
 web/toolbar.js                          | 35 ++++++++++++-------------
 web/viewer.css                          |  5 ----
 web/viewer.html                         |  7 ++---
 web/viewer.js                           |  1 -
 6 files changed, 19 insertions(+), 35 deletions(-)
 delete mode 100644 web/images/toolbarButton-editorNone.svg

diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties
index 9a726c6f1..4a95b937d 100644
--- a/l10n/en-US/viewer.properties
+++ b/l10n/en-US/viewer.properties
@@ -251,8 +251,6 @@ printing_not_ready=Warning: The PDF is not fully loaded for printing.
 web_fonts_disabled=Web fonts are disabled: unable to use embedded PDF fonts.
 
 # Editor
-editor_none.title=Disable Annotation Editing
-editor_none_label=Disable Editing
 editor_free_text.title=Add FreeText Annotation
 editor_free_text_label=FreeText Annotation
 editor_ink.title=Add Ink Annotation
diff --git a/web/images/toolbarButton-editorNone.svg b/web/images/toolbarButton-editorNone.svg
deleted file mode 100644
index 7137e05de..000000000
--- a/web/images/toolbarButton-editorNone.svg
+++ /dev/null
@@ -1,4 +0,0 @@
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M12.407 8.217l-8.083-6.7A.2.2 0 0 0 4 1.672V12.3a.2.2 0 0 0 .333.146l2.56-2.372 1.857 3.9A1.125 1.125 0 1 0 10.782 13L8.913 9.075l3.4-.51a.2.2 0 0 0 .095-.348z"></path></svg>
\ No newline at end of file
diff --git a/web/toolbar.js b/web/toolbar.js
index 866a47d3a..183d072d8 100644
--- a/web/toolbar.js
+++ b/web/toolbar.js
@@ -44,7 +44,6 @@ const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  * @property {HTMLButtonElement} openFile - Button to open a new document.
  * @property {HTMLButtonElement} presentationModeButton - Button to switch to
  *   presentation mode.
- * @property {HTMLButtonElement} editorNoneButton - Button to disable editing.
  * @property {HTMLButtonElement} editorFreeTextButton - Button to switch to
  *   FreeText editing.
  * @property {HTMLButtonElement} download - Button to download the document.
@@ -76,20 +75,29 @@ class Toolbar {
       },
       { element: options.download, eventName: "download" },
       { element: options.viewBookmark, eventName: null },
-      {
-        element: options.editorNoneButton,
-        eventName: "switchannotationeditormode",
-        eventDetails: { mode: AnnotationEditorType.NONE },
-      },
       {
         element: options.editorFreeTextButton,
         eventName: "switchannotationeditormode",
-        eventDetails: { mode: AnnotationEditorType.FREETEXT },
+        eventDetails: {
+          get mode() {
+            const { classList } = options.editorFreeTextButton;
+            return classList.contains("toggled")
+              ? AnnotationEditorType.NONE
+              : AnnotationEditorType.FREETEXT;
+          },
+        },
       },
       {
         element: options.editorInkButton,
         eventName: "switchannotationeditormode",
-        eventDetails: { mode: AnnotationEditorType.INK },
+        eventDetails: {
+          get mode() {
+            const { classList } = options.editorInkButton;
+            return classList.contains("toggled")
+              ? AnnotationEditorType.NONE
+              : AnnotationEditorType.INK;
+          },
+        },
       },
     ];
     if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
@@ -104,11 +112,6 @@ class Toolbar {
       next: options.next,
       zoomIn: options.zoomIn,
       zoomOut: options.zoomOut,
-      editorNoneButton: options.editorNoneButton,
-      editorFreeTextButton: options.editorFreeTextButton,
-      editorFreeTextParamsToolbar: options.editorFreeTextParamsToolbar,
-      editorInkButton: options.editorInkButton,
-      editorInkParamsToolbar: options.editorInkParamsToolbar,
     };
 
     // Bind the event listeners for click and various other actions.
@@ -213,7 +216,6 @@ class Toolbar {
   }
 
   #bindEditorToolsListener({
-    editorNoneButton,
     editorFreeTextButton,
     editorFreeTextParamsToolbar,
     editorInkButton,
@@ -221,7 +223,6 @@ class Toolbar {
   }) {
     const editorModeChanged = (evt, disableButtons = false) => {
       const editorButtons = [
-        { mode: AnnotationEditorType.NONE, button: editorNoneButton },
         {
           mode: AnnotationEditorType.FREETEXT,
           button: editorFreeTextButton,
@@ -239,9 +240,7 @@ class Toolbar {
         button.classList.toggle("toggled", checked);
         button.setAttribute("aria-checked", checked);
         button.disabled = disableButtons;
-        if (toolbar) {
-          toolbar.classList.toggle("hidden", !checked);
-        }
+        toolbar?.classList.toggle("hidden", !checked);
       }
     };
     this.eventBus._on("annotationeditormodechanged", editorModeChanged);
diff --git a/web/viewer.css b/web/viewer.css
index 14aaf1773..8fe1e7d80 100644
--- a/web/viewer.css
+++ b/web/viewer.css
@@ -71,7 +71,6 @@
   --loading-icon: url(images/loading.svg);
   --treeitem-expanded-icon: url(images/treeitem-expanded.svg);
   --treeitem-collapsed-icon: url(images/treeitem-collapsed.svg);
-  --toolbarButton-editorNone-icon: url(images/toolbarButton-editorNone.svg);
   --toolbarButton-editorFreeText-icon: url(images/toolbarButton-editorFreeText.svg);
   --toolbarButton-editorInk-icon: url(images/toolbarButton-editorInk.svg);
   --toolbarButton-menuArrow-icon: url(images/toolbarButton-menuArrow.svg);
@@ -888,10 +887,6 @@ select {
   mask-image: var(--toolbarButton-presentationMode-icon);
 }
 
-#editorNone::before {
-  mask-image: var(--toolbarButton-editorNone-icon);
-}
-
 #editorFreeText::before {
   mask-image: var(--toolbarButton-editorFreeText-icon);
 }
diff --git a/web/viewer.html b/web/viewer.html
index 3d4faef71..0a54dea23 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -318,13 +318,10 @@ See https://github.com/adobe-type-tools/cmap-resources
                 <div class="verticalToolbarSeparator hiddenSmallView"></div>
 
                 <div id="editorModeButtons" class="splitToolbarButton toggled hidden" role="radiogroup">
-                  <button id="editorNone" class="toolbarButton toggled" disabled="disabled" title="Disable Annotation Editing" role="radio" aria-checked="true" tabindex="36" data-l10n-id="editor_none">
-                    <span data-l10n-id="editor_none_label">Disable Editing</span>
-                  </button>
-                  <button id="editorFreeText" class="toolbarButton" disabled="disabled" title="Add FreeText Annotation" role="radio" aria-checked="false" tabindex="37" data-l10n-id="editor_free_text">
+                  <button id="editorFreeText" class="toolbarButton" disabled="disabled" title="Add FreeText Annotation" role="radio" aria-checked="false" tabindex="36" data-l10n-id="editor_free_text">
                     <span data-l10n-id="editor_free_text_label">FreeText Annotation</span>
                   </button>
-                  <button id="editorInk" class="toolbarButton" disabled="disabled" title="Add Ink Annotation" role="radio" aria-checked="false" tabindex="38" data-l10n-id="editor_ink">
+                  <button id="editorInk" class="toolbarButton" disabled="disabled" title="Add Ink Annotation" role="radio" aria-checked="false" tabindex="37" data-l10n-id="editor_ink">
                     <span data-l10n-id="editor_ink_label">Ink Annotation</span>
                   </button>
                 </div>
diff --git a/web/viewer.js b/web/viewer.js
index c08208544..bc55ef3aa 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -101,7 +101,6 @@ function getViewerConfiguration() {
           ? document.getElementById("openFile")
           : null,
       print: document.getElementById("print"),
-      editorNoneButton: document.getElementById("editorNone"),
       editorFreeTextButton: document.getElementById("editorFreeText"),
       editorFreeTextParamsToolbar: document.getElementById(
         "editorFreeTextParamsToolbar"