Merge pull request #14991 from Snuffleupagus/editor-XFA-disable

[editor] Disable the editor-buttons in XFA documents
This commit is contained in:
calixteman 2022-06-05 12:03:05 +02:00 committed by GitHub
commit 193a28431c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 15 deletions

View File

@ -561,10 +561,6 @@ const PDFViewerApplication = {
this.findBar = new PDFFindBar(appConfig.findBar, eventBus, this.l10n);
}
if (AppOptions.get("annotationEditorEnabled")) {
document.getElementById("editorModeButtons").classList.remove("hidden");
}
this.pdfDocumentProperties = new PDFDocumentProperties(
appConfig.documentProperties,
this.overlayManager,
@ -1196,6 +1192,11 @@ const PDFViewerApplication = {
this.toolbar.setPagesCount(pdfDocument.numPages, false);
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
if (pdfDocument.isPureXfa) {
console.warn("Warning: XFA-editing is not implemented.");
this.toolbar.updateEditorModeButtonsState(/* disabled = */ true);
}
let baseDocumentUrl;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
baseDocumentUrl = null;
@ -2237,6 +2238,10 @@ function webViewerInitialized() {
appConfig.toolbar.viewFind.classList.add("hidden");
}
if (PDFViewerApplication.pdfViewer.enableAnnotationEditor) {
appConfig.toolbar.editorModeButtons.classList.remove("hidden");
}
appConfig.mainContainer.addEventListener(
"transitionend",
function (evt) {

View File

@ -53,16 +53,16 @@ const OptionKind = {
* primitive types and cannot rely on any imported types.
*/
const defaultOptions = {
annotationMode: {
/** @type {number} */
value: 2,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
annotationEditorEnabled: {
/** @type {boolean} */
value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING"),
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
annotationMode: {
/** @type {number} */
value: 2,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
cursorToolOnLoad: {
/** @type {number} */
value: 0,

View File

@ -359,6 +359,13 @@ class BaseViewer {
return this.#annotationMode === AnnotationMode.ENABLE_FORMS;
}
/**
* @type {boolean}
*/
get enableAnnotationEditor() {
return !!this.#annotationEditorUIManager;
}
/**
* @type {boolean}
*/
@ -719,9 +726,8 @@ class BaseViewer {
const annotationLayerFactory =
this.#annotationMode !== AnnotationMode.DISABLE ? this : null;
const xfaLayerFactory = isPureXfa ? this : null;
const annotationEditorLayerFactory = this.#annotationEditorUIManager
? this
: null;
const annotationEditorLayerFactory =
this.#annotationEditorUIManager && !isPureXfa ? this : null;
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
const pageView = new PDFPageView({

View File

@ -97,6 +97,8 @@ class Toolbar {
next: options.next,
zoomIn: options.zoomIn,
zoomOut: options.zoomOut,
editorNoneButton: options.editorNoneButton,
editorFreeTextButton: options.editorFreeTextButton,
};
this._wasLocalized = false;
@ -133,6 +135,7 @@ class Toolbar {
this.pageScale = DEFAULT_SCALE;
this._updateUIState(true);
this.updateLoadingIndicatorState();
this.updateEditorModeButtonsState();
}
_bindListeners(options) {
@ -267,9 +270,16 @@ class Toolbar {
}
updateLoadingIndicatorState(loading = false) {
const pageNumberInput = this.items.pageNumber;
const { pageNumber } = this.items;
pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
}
updateEditorModeButtonsState(disabled = false) {
const { editorNoneButton, editorFreeTextButton } = this.items;
editorNoneButton.disabled = disabled;
editorFreeTextButton.disabled = disabled;
}
/**

View File

@ -71,8 +71,8 @@
--loading-icon: url(images/loading.svg);
--treeitem-expanded-icon: url(images/treeitem-expanded.svg);
--treeitem-collapsed-icon: url(images/treeitem-collapsed.svg);
--toolbarButton-editorFreeText-icon: url(images/toolbarButton-editorFreeText.svg);
--toolbarButton-editorNone-icon: url(images/toolbarButton-editorNone.svg);
--toolbarButton-editorFreeText-icon: url(images/toolbarButton-editorFreeText.svg);
--toolbarButton-menuArrow-icon: url(images/toolbarButton-menuArrow.svg);
--toolbarButton-sidebarToggle-icon: url(images/toolbarButton-sidebarToggle.svg);
--toolbarButton-secondaryToolbarToggle-icon: url(images/toolbarButton-secondaryToolbarToggle.svg);

View File

@ -93,6 +93,7 @@ function getViewerConfiguration() {
? document.getElementById("openFile")
: null,
print: document.getElementById("print"),
editorModeButtons: document.getElementById("editorModeButtons"),
editorNoneButton: document.getElementById("editorNone"),
editorFreeTextButton: document.getElementById("editorFreeText"),
presentationModeButton: document.getElementById("presentationMode"),