Merge pull request #17775 from calixteman/bug1883632
[Editor] Let a free highlight be clipped when its bounding box exceeds the page limits (bug 1883632)
This commit is contained in:
commit
f634cb533c
@ -512,6 +512,14 @@ class AnnotationEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {boolean} true if position must be fixed (i.e. make the x and y
|
||||||
|
* living in the page).
|
||||||
|
*/
|
||||||
|
get _mustFixPosition() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix the position of the editor in order to keep it inside its parent page.
|
* Fix the position of the editor in order to keep it inside its parent page.
|
||||||
* @param {number} [rotation] - the rotation of the page.
|
* @param {number} [rotation] - the rotation of the page.
|
||||||
@ -524,23 +532,25 @@ class AnnotationEditor {
|
|||||||
x *= pageWidth;
|
x *= pageWidth;
|
||||||
y *= pageHeight;
|
y *= pageHeight;
|
||||||
|
|
||||||
switch (rotation) {
|
if (this._mustFixPosition) {
|
||||||
case 0:
|
switch (rotation) {
|
||||||
x = Math.max(0, Math.min(pageWidth - width, x));
|
case 0:
|
||||||
y = Math.max(0, Math.min(pageHeight - height, y));
|
x = Math.max(0, Math.min(pageWidth - width, x));
|
||||||
break;
|
y = Math.max(0, Math.min(pageHeight - height, y));
|
||||||
case 90:
|
break;
|
||||||
x = Math.max(0, Math.min(pageWidth - height, x));
|
case 90:
|
||||||
y = Math.min(pageHeight, Math.max(width, y));
|
x = Math.max(0, Math.min(pageWidth - height, x));
|
||||||
break;
|
y = Math.min(pageHeight, Math.max(width, y));
|
||||||
case 180:
|
break;
|
||||||
x = Math.min(pageWidth, Math.max(width, x));
|
case 180:
|
||||||
y = Math.min(pageHeight, Math.max(height, y));
|
x = Math.min(pageWidth, Math.max(width, x));
|
||||||
break;
|
y = Math.min(pageHeight, Math.max(height, y));
|
||||||
case 270:
|
break;
|
||||||
x = Math.min(pageWidth, Math.max(height, x));
|
case 270:
|
||||||
y = Math.max(0, Math.min(pageHeight - width, y));
|
x = Math.min(pageWidth, Math.max(height, x));
|
||||||
break;
|
y = Math.max(0, Math.min(pageHeight - width, y));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.x = x /= pageWidth;
|
this.x = x /= pageWidth;
|
||||||
|
@ -629,6 +629,11 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritdoc */
|
||||||
|
get _mustFixPosition() {
|
||||||
|
return !this.#isFreeHighlight;
|
||||||
|
}
|
||||||
|
|
||||||
#getRotation() {
|
#getRotation() {
|
||||||
// Highlight annotations are always drawn horizontally but if
|
// Highlight annotations are always drawn horizontally but if
|
||||||
// a free highlight annotation can be rotated.
|
// a free highlight annotation can be rotated.
|
||||||
|
@ -1398,4 +1398,47 @@ describe("Highlight Editor", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Highlight editor mustn't be moved when close to the page limits", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
pages = await loadAndWait("empty.pdf", ".annotationEditorLayer");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("must check the editor coordinates", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
await page.click("#editorHighlight");
|
||||||
|
await page.waitForSelector(".annotationEditorLayer.highlightEditing");
|
||||||
|
|
||||||
|
const rect = await page.$eval(".annotationEditorLayer", el => {
|
||||||
|
const { x, y } = el.getBoundingClientRect();
|
||||||
|
return { x, y };
|
||||||
|
});
|
||||||
|
|
||||||
|
const clickHandle = await waitForPointerUp(page);
|
||||||
|
await page.mouse.move(rect.x + 1, rect.y + 50);
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(rect.x + 1, rect.y + 100);
|
||||||
|
await page.mouse.up();
|
||||||
|
await awaitPromise(clickHandle);
|
||||||
|
|
||||||
|
await page.waitForSelector(getEditorSelector(0));
|
||||||
|
const editorX = await page.$eval(
|
||||||
|
getEditorSelector(0),
|
||||||
|
el => el.getBoundingClientRect().x
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(editorX < rect.x)
|
||||||
|
.withContext(`In ${browserName}`)
|
||||||
|
.toBeTrue();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user