Bug 1969829 - Non-editable <canvas> elements should use the frame edge for selection targetting. r=masayuki, a=dmeehan

Just like images.

Differential Revision: https://phabricator.services.mozilla.com/D253705
This commit is contained in:
Emilio Cobos Álvarez
2025-06-14 09:40:31 +00:00
committed by dmeehan@mozilla.com
parent fe50381f10
commit 4e9167a7b1
2 changed files with 30 additions and 1 deletions

View File

@@ -5853,7 +5853,8 @@ static bool UseFrameEdge(nsIFrame* aFrame) {
return true;
}
const nsImageFrame* image = do_QueryFrame(aFrame);
if (image && !aFrame->GetContent()->IsEditable()) {
if ((image || aFrame->IsHTMLCanvasFrame()) &&
!aFrame->GetContent()->IsEditable()) {
// Editable images are a special-case because editing relies on clicking on
// an editable image selecting it, for it to show resizers.
return true;

View File

@@ -0,0 +1,28 @@
<!doctype html>
<meta charset="utf-8">
<title>Clicking on a text-selectable canvas should not select it</title>
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="https://mozilla.com" title="Mozilla">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1969829">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
:root { user-select: none }
canvas {
user-select: text;
outline: 2px solid hotpink;
background-color: green;
width: 200px;
height: 200px;
}
</style>
Clicking the green square should not select it.<br>
<canvas></canvas>
<script>
promise_test(async function() {
await test_driver.click(document.querySelector("canvas"));
assert_true(getSelection().isCollapsed, "Clicking a canvas shouldn't generate a non-collapsed selection");
});
</script>