Skip to content
Open
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
5 changes: 5 additions & 0 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@
"type": "boolean",
"default": false
},
"enableEraser": {
"description": "Enable the eraser to erase annotations like Ink.",
"type": "boolean",
"default": false
},
"enableOptimizedPartialRendering": {
"description": "Enable tracking of PDF operations to optimize partial rendering.",
"type": "boolean",
Expand Down
26 changes: 26 additions & 0 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
FeatureTest,
} from "../../shared/util.js";
import { AnnotationEditor } from "./editor.js";
import { EraserEditor } from "./eraser.js";
import { FreeTextEditor } from "./freetext.js";
import { HighlightEditor } from "./highlight.js";
import { InkEditor } from "./ink.js";
Expand Down Expand Up @@ -99,6 +100,7 @@ class AnnotationEditorLayer {

static #editorTypes = new Map(
[
EraserEditor,
FreeTextEditor,
InkEditor,
StampEditor,
Expand Down Expand Up @@ -168,6 +170,7 @@ class AnnotationEditorLayer {
*/
updateMode(mode = this.#uiManager.getMode()) {
this.#cleanup();
this.#toogleEditorPointerEvents(true);
switch (mode) {
case AnnotationEditorType.NONE:
this.div.classList.toggle("nonEditing", true);
Expand All @@ -176,6 +179,15 @@ class AnnotationEditorLayer {
this.toggleAnnotationLayerPointerEvents(true);
this.disableClick();
return;
case AnnotationEditorType.ERASER:
this.#toogleEditorPointerEvents(false);
this.disableTextSelection();
this.togglePointerEvents(true);
this.enableClick();
this.addNewEditor({
/* eraser */
});
break;
case AnnotationEditorType.INK:
this.disableTextSelection();
this.togglePointerEvents(true);
Expand Down Expand Up @@ -251,6 +263,20 @@ class AnnotationEditorLayer {
: this.#uiManager.getEditors(this.pageIndex);
}

#toogleEditorPointerEvents(enabled = false) {
const value = enabled ? "" : "none";
for (const editor of this.#editors.values()) {
editor.div.style.pointerEvents = value;
// for highlight editors, we must also set pointer-events
// of the clipped child.
for (const child of editor.div.children) {
if (child.className === "internal") {
child.style.pointerEvents = value;
}
}
}
}

/**
* Enable pointer events on the main div in order to enable
* editor creation.
Expand Down
4 changes: 4 additions & 0 deletions src/display/editor/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class DrawingEditor extends AnnotationEditor {
this._addOutlines(params);
}

get _drawOutlines() {
return this.#drawOutlines;
}

/** @inheritdoc */
onUpdatedColor() {
this._colorPicker?.update(this.color);
Expand Down
21 changes: 21 additions & 0 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class AnnotationEditor {

_editToolbar = null;

_erasable = false;

_initialOptions = Object.create(null);

_initialData = null;
Expand Down Expand Up @@ -217,6 +219,10 @@ class AnnotationEditor {
return Object.getPrototypeOf(this).constructor._editorType;
}

get erasable() {
return this._erasable;
}

static get isDrawer() {
return false;
}
Expand Down Expand Up @@ -508,6 +514,21 @@ class AnnotationEditor {
this.#translate(this.parentDimensions, x, y);
}

/**
* Erase everything in a radius of (x,y) position.
* @param {number} x
* @param {number} y
* @param {number} radius
*/
erase(x, y, radius) {
unreachable("Not implemented");
}

/** call once the erasing operation is done */
endErase() {
unreachable("Not implemented");
}

/**
* Translate the editor position within its page and adjust the scroll
* in order to have the editor in the view.
Expand Down
Loading