Merge pull request #16826 from calixteman/editor_remove_empty_stamp
[Editor] Remove the stamp editor displayed when the image was loading (bug 1848313)
This commit is contained in:
commit
4b2eebf32e
@ -68,22 +68,34 @@ class StampEditor extends AnnotationEditor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#getBitmapDone() {
|
||||||
|
this._uiManager.enableWaiting(false);
|
||||||
|
if (this.#canvas) {
|
||||||
|
this.div.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#getBitmap() {
|
#getBitmap() {
|
||||||
if (this.#bitmapId) {
|
if (this.#bitmapId) {
|
||||||
this._uiManager.imageManager.getFromId(this.#bitmapId).then(data => {
|
this._uiManager.enableWaiting(true);
|
||||||
if (!data) {
|
this._uiManager.imageManager
|
||||||
this.remove();
|
.getFromId(this.#bitmapId)
|
||||||
return;
|
.then(data => {
|
||||||
}
|
if (!data) {
|
||||||
this.#bitmap = data.bitmap;
|
this.remove();
|
||||||
this.#createCanvas();
|
return;
|
||||||
});
|
}
|
||||||
|
this.#bitmap = data.bitmap;
|
||||||
|
this.#createCanvas();
|
||||||
|
})
|
||||||
|
.finally(() => this.#getBitmapDone());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#bitmapUrl) {
|
if (this.#bitmapUrl) {
|
||||||
const url = this.#bitmapUrl;
|
const url = this.#bitmapUrl;
|
||||||
this.#bitmapUrl = null;
|
this.#bitmapUrl = null;
|
||||||
|
this._uiManager.enableWaiting(true);
|
||||||
this.#bitmapPromise = this._uiManager.imageManager
|
this.#bitmapPromise = this._uiManager.imageManager
|
||||||
.getFromUrl(url)
|
.getFromUrl(url)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@ -98,7 +110,8 @@ class StampEditor extends AnnotationEditor {
|
|||||||
isSvg: this.#isSvg,
|
isSvg: this.#isSvg,
|
||||||
} = data);
|
} = data);
|
||||||
this.#createCanvas();
|
this.#createCanvas();
|
||||||
});
|
})
|
||||||
|
.finally(() => this.#getBitmapDone());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +129,7 @@ class StampEditor extends AnnotationEditor {
|
|||||||
if (!input.files || input.files.length === 0) {
|
if (!input.files || input.files.length === 0) {
|
||||||
this.remove();
|
this.remove();
|
||||||
} else {
|
} else {
|
||||||
|
this._uiManager.enableWaiting(true);
|
||||||
const data = await this._uiManager.imageManager.getFromFile(
|
const data = await this._uiManager.imageManager.getFromFile(
|
||||||
input.files[0]
|
input.files[0]
|
||||||
);
|
);
|
||||||
@ -140,7 +154,7 @@ class StampEditor extends AnnotationEditor {
|
|||||||
this.remove();
|
this.remove();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
}).finally(() => this.#getBitmapDone());
|
||||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("TESTING")) {
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("TESTING")) {
|
||||||
input.click();
|
input.click();
|
||||||
}
|
}
|
||||||
@ -218,11 +232,11 @@ class StampEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.render();
|
super.render();
|
||||||
|
this.div.hidden = true;
|
||||||
|
|
||||||
if (this.#bitmap) {
|
if (this.#bitmap) {
|
||||||
this.#createCanvas();
|
this.#createCanvas();
|
||||||
} else {
|
} else {
|
||||||
this.div.classList.add("loading");
|
|
||||||
this.#getBitmap();
|
this.#getBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,11 +281,12 @@ class StampEditor extends AnnotationEditor {
|
|||||||
(height * parentHeight) / pageHeight
|
(height * parentHeight) / pageHeight
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this._uiManager.enableWaiting(false);
|
||||||
const canvas = (this.#canvas = document.createElement("canvas"));
|
const canvas = (this.#canvas = document.createElement("canvas"));
|
||||||
div.append(canvas);
|
div.append(canvas);
|
||||||
|
div.hidden = false;
|
||||||
this.#drawBitmap(width, height);
|
this.#drawBitmap(width, height);
|
||||||
this.#createObserver();
|
this.#createObserver();
|
||||||
div.classList.remove("loading");
|
|
||||||
if (!this.#hasBeenAddedInUndoStack) {
|
if (!this.#hasBeenAddedInUndoStack) {
|
||||||
this.parent.addUndoableEditor(this);
|
this.parent.addUndoableEditor(this);
|
||||||
this.#hasBeenAddedInUndoStack = true;
|
this.#hasBeenAddedInUndoStack = true;
|
||||||
|
@ -547,6 +547,8 @@ class AnnotationEditorUIManager {
|
|||||||
|
|
||||||
#isEnabled = false;
|
#isEnabled = false;
|
||||||
|
|
||||||
|
#isWaiting = false;
|
||||||
|
|
||||||
#lastActiveElement = null;
|
#lastActiveElement = null;
|
||||||
|
|
||||||
#mode = AnnotationEditorType.NONE;
|
#mode = AnnotationEditorType.NONE;
|
||||||
@ -1159,6 +1161,21 @@ class AnnotationEditorUIManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableWaiting(mustWait = false) {
|
||||||
|
if (this.#isWaiting === mustWait) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#isWaiting = mustWait;
|
||||||
|
for (const layer of this.#allLayers.values()) {
|
||||||
|
if (mustWait) {
|
||||||
|
layer.disableClick();
|
||||||
|
} else {
|
||||||
|
layer.enableClick();
|
||||||
|
}
|
||||||
|
layer.div.classList.toggle("waiting", mustWait);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable all the layers.
|
* Enable all the layers.
|
||||||
*/
|
*/
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
closePages,
|
closePages,
|
||||||
dragAndDropAnnotation,
|
|
||||||
getEditorDimensions,
|
getEditorDimensions,
|
||||||
getEditorSelector,
|
|
||||||
loadAndWait,
|
loadAndWait,
|
||||||
serializeBitmapDimensions,
|
serializeBitmapDimensions,
|
||||||
waitForAnnotationEditorLayer,
|
waitForAnnotationEditorLayer,
|
||||||
@ -114,68 +112,6 @@ describe("Stamp Editor", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Page overflow", () => {
|
|
||||||
let pages;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer", 50);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await closePages(pages);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("must check that an added image stay within the page", async () => {
|
|
||||||
await Promise.all(
|
|
||||||
pages.map(async ([browserName, page]) => {
|
|
||||||
if (browserName === "firefox") {
|
|
||||||
// Disabled in Firefox, because of https://bugzilla.mozilla.org/1553847.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await page.click("#editorStamp");
|
|
||||||
await page.click("#editorStampAddImage");
|
|
||||||
|
|
||||||
const rect = await page.$eval(".annotationEditorLayer", el => {
|
|
||||||
// With Chrome something is wrong when serializing a DomRect,
|
|
||||||
// hence we extract the values and just return them.
|
|
||||||
const { right, bottom } = el.getBoundingClientRect();
|
|
||||||
return { x: right, y: bottom };
|
|
||||||
});
|
|
||||||
|
|
||||||
const editorRect = await page.$eval(getEditorSelector(0), el => {
|
|
||||||
// With Chrome something is wrong when serializing a DomRect,
|
|
||||||
// hence we extract the values and just return them.
|
|
||||||
const { x, y } = el.getBoundingClientRect();
|
|
||||||
return { x, y };
|
|
||||||
});
|
|
||||||
|
|
||||||
const input = await page.$("#stampEditorFileInput");
|
|
||||||
await input.uploadFile(
|
|
||||||
`${path.join(__dirname, "../images/firefox_logo.png")}`
|
|
||||||
);
|
|
||||||
|
|
||||||
await page.waitForTimeout(300);
|
|
||||||
|
|
||||||
await dragAndDropAnnotation(
|
|
||||||
page,
|
|
||||||
editorRect.x + 10,
|
|
||||||
editorRect.y + 10,
|
|
||||||
rect.x - 10,
|
|
||||||
rect.y - 10
|
|
||||||
);
|
|
||||||
await page.waitForTimeout(10);
|
|
||||||
|
|
||||||
const { left } = await getEditorDimensions(page, 0);
|
|
||||||
|
|
||||||
// The image is bigger than the page, so it has been scaled down to
|
|
||||||
// 75% of the page width.
|
|
||||||
expect(left).toEqual("25%");
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Resize", () => {
|
describe("Resize", () => {
|
||||||
let pages;
|
let pages;
|
||||||
|
|
||||||
|
@ -72,6 +72,15 @@
|
|||||||
z-index: 4;
|
z-index: 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.annotationEditorLayer.waiting {
|
||||||
|
content: "";
|
||||||
|
cursor: wait;
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.annotationEditorLayer.freeTextEditing {
|
.annotationEditorLayer.freeTextEditing {
|
||||||
cursor: var(--editorFreeText-editing-cursor);
|
cursor: var(--editorFreeText-editing-cursor);
|
||||||
}
|
}
|
||||||
@ -168,19 +177,6 @@
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.annotationEditorLayer .stampEditor.loading {
|
|
||||||
aspect-ratio: 1;
|
|
||||||
width: 10%;
|
|
||||||
height: auto;
|
|
||||||
background-color: rgba(128, 128, 128, 0.5);
|
|
||||||
background-image: var(--loading-icon);
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: 50%;
|
|
||||||
background-size: 16px 16px;
|
|
||||||
transition-property: background-size;
|
|
||||||
transition-delay: var(--loading-icon-delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
.annotationEditorLayer .stampEditor canvas {
|
.annotationEditorLayer .stampEditor canvas {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user