Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[editor] Disable the editor-buttons in XFA documents #14991

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ class BaseViewer {
return this.#annotationMode === AnnotationMode.ENABLE_FORMS;
}

/**
* @type {boolean}
*/
get enableAnnotationEditor() {
return !!this.#annotationEditorUIManager;
}

/**
* @type {boolean}
*/
Expand Down Expand Up @@ -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({
Expand Down
14 changes: 12 additions & 2 deletions web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class Toolbar {
next: options.next,
zoomIn: options.zoomIn,
zoomOut: options.zoomOut,
editorNoneButton: options.editorNoneButton,
editorFreeTextButton: options.editorFreeTextButton,
};

this._wasLocalized = false;
Expand Down Expand Up @@ -133,6 +135,7 @@ class Toolbar {
this.pageScale = DEFAULT_SCALE;
this._updateUIState(true);
this.updateLoadingIndicatorState();
this.updateEditorModeButtonsState();
}

_bindListeners(options) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion web/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down