Files
sousa-gecko/layout/forms/test/test_bug549170.html
T
Emilio Cobos Álvarez 34b249c82e Bug 2031757 - Rejigger text input / textarea rendering to make field-sizing easier. r=layout-reviewers,devtools-reviewers,fxview-reviewers,firefox-style-system-reviewers,ochameau,jsudiaman,dshin
This also should fix bug 1881942 (placeholder is now scrollable
alongside the textarea).

This makes nsTextControlFrame a subclass of ScrollContainerFrame (with
an inner block), and tweaks layout to match.

It lays out the inner content using block layout and align-content,
rather than bespoke reflow primitives. This makes field-sizing trivial
to implement on top.

This is a bit scary, but simpler in most ways. In particular, it needs
to teach ScrollContainerFrame of the button, because that goes outside
the scrollable area, like scrollbars. That said it needs less
special-cases added than those removed, and it should also be faster
(needs less frames to layout an input with placeholder etc), and match
other browsers better.

The general set-up is:

  <text-control-editing-root/>
  <placeholder/>
  <autofill-preview/>

text-control-editing-root is always inline-block and always displayed
(since it's what grabs the focus / shows the caret). If the
autofill-preview or placeholder are displayed, the editing-root is
zero-width and clipped (note that for placeholder that's guaranteed
because placeholder is only shown with an empty value, but
autofill-preview needs it).

placeholder and autofill-preview are hidden via `display` rather than
visibility. This doesn't make a difference with this patch but it
matters for bug 1977176.

Caret painting needs an extra hop to paint atop the placeholder (no
observable behavior change, but worth calling out).

There is one subtle behavior change, which is that single-line inputs
never report scrollable overflow in the block axis. This matches other
browsers (see the tweak in nsBlockFrame's overflow computation) and is
needed to avoid regressing scrollable-overflow-padding-input.html.

The changes in window_composition_text_querycontent.xhtml are needed
because before this patch, the height of the control editing root was
always the height of the whole textarea. The characters you're composing
might legitimately be taller than the line. Bump the line height so that
that doesn't happen in this test.

Differential Revision: https://phabricator.services.mozilla.com/D293666
2026-04-16 17:09:40 +00:00

76 lines
2.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=549170
-->
<head>
<title>Test for Bug 549170</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="window.setTimeout(runTests, 0);">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=549170">Mozilla Bug 549170</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<input id='i'
onmouseup="mouseHandler(event);"
onmousedown="mouseHandler(event);">
<textarea id='t'
onmouseup="mouseHandler(event);"
onmousedown="mouseHandler(event);"></textarea><br>
<input id='ip' placeholder='foo'
onmouseup="mouseHandler(event);"
onmousedown="mouseHandler(event);">
<textarea id='tp' placeholder='foo'
onmouseup="mouseHandler(event);"
onmousedown="mouseHandler(event);"></textarea>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 549170 */
var gNumberOfMouseEventsCaught = 0;
SimpleTest.waitForExplicitFinish();
function mouseHandler(aEvent)
{
gNumberOfMouseEventsCaught++;
}
function checkMouseEvents(element)
{
gNumberOfMouseEventsCaught = 0;
let x = element.offsetWidth / 2;
let y = element.offsetHeight / 2;
synthesizeMouse(element, x, y, {type: "mousedown", button: 0});
synthesizeMouse(element, x, y, {type: "mouseup", button: 0});
synthesizeMouse(element, x, y, {type: "mousedown", button: 1});
// NOTE: this event is going to copy the buffer on linux, this should not be a problem
synthesizeMouse(element, x, y, {type: "mouseup", button: 1});
synthesizeMouse(element, x, y, {type: "mousedown", button: 2});
synthesizeMouse(element, x, y, {type: "mouseup", button: 2});
is(gNumberOfMouseEventsCaught, 6, "Some mouse events have not been caught");
}
function runTests()
{
checkMouseEvents(document.getElementById('i'));
checkMouseEvents(document.getElementById('t'));
checkMouseEvents(document.getElementById('ip'));
checkMouseEvents(document.getElementById('tp'));
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>