Skip to content

Commit e08b079

Browse files
Merge pull request #15113 from Snuffleupagus/annotationEditorMode-pref
[editor] Introduce a proper `annotationEditorMode` option/preference (PR 15075 follow-up)
2 parents f1d4015 + 44a75c2 commit e08b079

File tree

8 files changed

+42
-32
lines changed

8 files changed

+42
-32
lines changed

extensions/chromium/preferences_schema.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160
],
161161
"default": 2
162162
},
163-
"annotationEditorEnabled": {
164-
"type": "boolean",
165-
"default": false
163+
"annotationEditorMode": {
164+
"type": "integer",
165+
"default": -1
166166
},
167167
"enablePermissions": {
168168
"type": "boolean",

l10n/en-US/viewer.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ editor_free_text_label=FreeText Annotation
258258
editor_ink.title=Add Ink Annotation
259259
editor_ink_label=Ink Annotation
260260

261-
freetext_default_content=Enter some text…
261+
freetext_default_content=Enter text…
262262

263263
# Editor Parameters
264264
editor_free_text_font_color=Font Color

src/shared/util.js

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const AnnotationMode = {
5555
const AnnotationEditorPrefix = "pdfjs_internal_editor_";
5656

5757
const AnnotationEditorType = {
58+
DISABLE: -1,
5859
NONE: 0,
5960
FREETEXT: 3,
6061
INK: 15,

web/app.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ import {
3434
SpreadMode,
3535
TextLayerMode,
3636
} from "./ui_utils.js";
37-
import { AppOptions, OptionKind } from "./app_options.js";
38-
import { AutomationEventBus, EventBus } from "./event_utils.js";
3937
import {
38+
AnnotationEditorType,
4039
build,
4140
createPromiseCapability,
4241
getDocument,
@@ -54,6 +53,8 @@ import {
5453
UNSUPPORTED_FEATURES,
5554
version,
5655
} from "pdfjs-lib";
56+
import { AppOptions, OptionKind } from "./app_options.js";
57+
import { AutomationEventBus, EventBus } from "./event_utils.js";
5758
import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js";
5859
import { LinkTarget, PDFLinkService } from "./pdf_link_service.js";
5960
import { AnnotationEditorParams } from "./annotation_editor_params.js";
@@ -510,7 +511,7 @@ const PDFViewerApplication = {
510511

511512
const container = appConfig.mainContainer,
512513
viewer = appConfig.viewerContainer;
513-
const annotationEditorEnabled = AppOptions.get("annotationEditorEnabled");
514+
const annotationEditorMode = AppOptions.get("annotationEditorMode");
514515
const pageColors = {
515516
background: AppOptions.get("pageColorsBackground"),
516517
foreground: AppOptions.get("pageColorsForeground"),
@@ -534,7 +535,7 @@ const PDFViewerApplication = {
534535
l10n: this.l10n,
535536
textLayerMode: AppOptions.get("textLayerMode"),
536537
annotationMode: AppOptions.get("annotationMode"),
537-
annotationEditorEnabled,
538+
annotationEditorMode,
538539
imageResourcesPath: AppOptions.get("imageResourcesPath"),
539540
enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"),
540541
useOnlyCssZoom: AppOptions.get("useOnlyCssZoom"),
@@ -570,7 +571,7 @@ const PDFViewerApplication = {
570571
this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n);
571572
}
572573

573-
if (annotationEditorEnabled) {
574+
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
574575
this.annotationEditorParams = new AnnotationEditorParams(
575576
appConfig.annotationEditorParams,
576577
eventBus

web/app_options.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ const OptionKind = {
5959
* primitive types and cannot rely on any imported types.
6060
*/
6161
const defaultOptions = {
62-
annotationEditorEnabled: {
62+
annotationEditorMode: {
6363
/** @type {boolean} */
6464
value:
65-
typeof PDFJSDev === "undefined" ||
66-
PDFJSDev.test("!PRODUCTION || TESTING"),
65+
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING")
66+
? 0
67+
: -1,
6768
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
6869
},
6970
annotationMode: {

web/base_viewer.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ const PagesCountLimit = {
8686
};
8787

8888
function isValidAnnotationEditorMode(mode) {
89-
return Object.values(AnnotationEditorType).includes(mode);
89+
return (
90+
Object.values(AnnotationEditorType).includes(mode) &&
91+
mode !== AnnotationEditorType.DISABLE
92+
);
9093
}
9194

9295
/**
@@ -113,8 +116,9 @@ function isValidAnnotationEditorMode(mode) {
113116
* being rendered. The constants from {@link AnnotationMode} should be used;
114117
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
115118
* The default value is `AnnotationMode.ENABLE_FORMS`.
116-
* @property {boolean} [annotationEditorEnabled] - Enables the creation and
117-
* editing of new Annotations.
119+
* @property {boolean} [annotationEditorMode] - Enables the creation and editing
120+
* of new Annotations. The constants from {@link AnnotationEditorType} should
121+
* be used. The default value is `AnnotationEditorType.DISABLE`.
118122
* @property {string} [imageResourcesPath] - Path for image resources, mainly
119123
* mainly for annotation icons. Include trailing slash.
120124
* @property {boolean} [enablePrintAutoRotate] - Enables automatic rotation of
@@ -213,7 +217,7 @@ class PDFPageViewBuffer {
213217
class BaseViewer {
214218
#buffer = null;
215219

216-
#annotationEditorMode = AnnotationEditorType.NONE;
220+
#annotationEditorMode = AnnotationEditorType.DISABLE;
217221

218222
#annotationEditorUIManager = null;
219223

@@ -273,9 +277,8 @@ class BaseViewer {
273277
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
274278
this.#annotationMode =
275279
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
276-
this.#annotationEditorMode = options.annotationEditorEnabled
277-
? AnnotationEditorType.NONE
278-
: null;
280+
this.#annotationEditorMode =
281+
options.annotationEditorMode ?? AnnotationEditorType.DISABLE;
279282
this.imageResourcesPath = options.imageResourcesPath || "";
280283
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
281284
this.renderer = options.renderer || RendererType.CANVAS;
@@ -560,7 +563,7 @@ class BaseViewer {
560563
}
561564

562565
if (!permissions.includes(PermissionFlag.MODIFY_CONTENTS)) {
563-
params.annotationEditorMode = null;
566+
params.annotationEditorMode = AnnotationEditorType.DISABLE;
564567
}
565568

566569
if (
@@ -710,19 +713,26 @@ class BaseViewer {
710713
const { annotationEditorMode, annotationMode, textLayerMode } =
711714
this.#initializePermissions(permissions);
712715

713-
if (annotationEditorMode !== null) {
716+
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
717+
const mode = annotationEditorMode;
718+
714719
if (isPureXfa) {
715720
console.warn("Warning: XFA-editing is not implemented.");
716-
} else {
721+
} else if (isValidAnnotationEditorMode(mode)) {
717722
// Ensure that the Editor buttons, in the toolbar, are updated.
718723
this.eventBus.dispatch("annotationeditormodechanged", {
719724
source: this,
720-
mode: annotationEditorMode,
725+
mode,
721726
});
722727

723728
this.#annotationEditorUIManager = new AnnotationEditorUIManager(
724729
this.eventBus
725730
);
731+
if (mode !== AnnotationEditorType.NONE) {
732+
this.#annotationEditorUIManager.updateMode(mode);
733+
}
734+
} else {
735+
console.error(`Invalid AnnotationEditor mode: ${mode}`);
726736
}
727737
}
728738

@@ -885,9 +895,6 @@ class BaseViewer {
885895
}
886896

887897
_resetView() {
888-
if (this.#annotationEditorMode !== null) {
889-
this.#annotationEditorMode = AnnotationEditorType.NONE;
890-
}
891898
this.#annotationEditorUIManager = null;
892899
this._pages = [];
893900
this._currentPageNumber = 1;
@@ -2142,7 +2149,7 @@ class BaseViewer {
21422149
}
21432150

21442151
/**
2145-
* @type {number | null}
2152+
* @type {number}
21462153
*/
21472154
get annotationEditorMode() {
21482155
return this.#annotationEditorMode;

web/l10n_utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const DEFAULT_L10N_STRINGS = {
8282
web_fonts_disabled:
8383
"Web fonts are disabled: unable to use embedded PDF fonts.",
8484

85-
freetext_default_content: "Enter some text…",
85+
freetext_default_content: "Enter text…",
8686
};
8787

8888
function getL10nFallback(key, args) {

web/viewer.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@
151151
<div class="editorParamsToolbarContainer">
152152
<div class="editorParamsSetter">
153153
<label for="editorFreeTextColor" class="editorParamsLabel" data-l10n-id="editor_free_text_font_color">Font Color</label>
154-
<input type="color" id="editorFreeTextColor" name="fontColor" class="editorParamsColor" tabindex="100">
154+
<input type="color" id="editorFreeTextColor" class="editorParamsColor" tabindex="100">
155155
</div>
156156
<div class="editorParamsSetter">
157157
<label for="editorFreeTextFontSize" class="editorParamsLabel" data-l10n-id="editor_free_text_font_size">Font Size</label>
158-
<input type="range" id="editorFreeTextFontSize" class="editorParamsSlider" name="fontSize" value="10" min="5" max="100" step="1" tabindex="101">
158+
<input type="range" id="editorFreeTextFontSize" class="editorParamsSlider" value="10" min="5" max="100" step="1" tabindex="101">
159159
</div>
160160
</div>
161161
</div>
@@ -164,11 +164,11 @@
164164
<div class="editorParamsToolbarContainer">
165165
<div class="editorParamsSetter">
166166
<label for="editorInkColor" class="editorParamsLabel" data-l10n-id="editor_ink_line_color">Line Color</label>
167-
<input type="color" id="editorInkColor" name="inkColor" class="editorParamsColor" tabindex="102">
167+
<input type="color" id="editorInkColor" class="editorParamsColor" tabindex="102">
168168
</div>
169169
<div class="editorParamsSetter">
170170
<label for="editorInkThickness" class="editorParamsLabel" data-l10n-id="editor_ink_line_thickness">Line Thickness</label>
171-
<input type="range" id="editorInkThickness" class="editorParamsSlider" name="lineThickness" value="1" min="1" max="20" step="1" tabindex="103">
171+
<input type="range" id="editorInkThickness" class="editorParamsSlider" value="1" min="1" max="20" step="1" tabindex="103">
172172
</div>
173173
</div>
174174
</div>

0 commit comments

Comments
 (0)