Files
sousa-gecko/devtools/server/tests/browser/browser_accessibility_node.js
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

169 lines
5.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Checks for the AccessibleActor
add_task(async function () {
const { target, walker, a11yWalker, parentAccessibility } =
await initAccessibilityFrontsForUrl(MAIN_DOMAIN + "doc_accessibility.html");
const modifiers =
Services.appinfo.OS === "Darwin" ? "\u2303\u2325" : "Alt+Shift+";
const buttonNode = await walker.querySelector(walker.rootNode, "#button");
const accessibleFront = await a11yWalker.getAccessibleFor(buttonNode);
checkA11yFront(accessibleFront, {
name: "Accessible Button",
role: "button",
childCount: 1,
});
await accessibleFront.hydrate();
checkA11yFront(accessibleFront, {
name: "Accessible Button",
role: "button",
value: "",
description: "Accessibility Test",
keyboardShortcut: modifiers + "b",
childCount: 1,
domNodeType: 1,
indexInParent: 1,
states: ["focusable", "opaque", "enabled", "sensitive"],
actions: ["Press"],
attributes: {
"margin-top": "0px",
display: "inline-block",
"text-align": "center",
"text-indent": "0px",
"margin-left": "0px",
tag: "button",
"margin-right": "0px",
id: "button",
formatting: "block",
"margin-bottom": "0px",
},
});
info("Children");
const children = await accessibleFront.children();
is(children.length, 1, "Accessible Front has correct number of children");
checkA11yFront(children[0], {
name: "Accessible Button",
role: "text leaf",
});
info("Relations");
const labelNode = await walker.querySelector(walker.rootNode, "#label");
const controlNode = await walker.querySelector(walker.rootNode, "#control");
const labelAccessibleFront = await a11yWalker.getAccessibleFor(labelNode);
const controlAccessibleFront = await a11yWalker.getAccessibleFor(controlNode);
const docAccessibleFront = await a11yWalker.getAccessibleFor(walker.rootNode);
const labelRelations = await labelAccessibleFront.getRelations();
is(labelRelations.length, 2, "Label has correct number of relations");
is(labelRelations[0].type, "label for", "Label has a label for relation");
is(labelRelations[0].targets.length, 1, "Label is a label for one target");
is(
labelRelations[0].targets[0],
controlAccessibleFront,
"Label is a label for control accessible front"
);
is(
labelRelations[1].type,
"containing document",
"Label has a containing document relation"
);
is(
labelRelations[1].targets.length,
1,
"Label is contained by just one document"
);
is(
labelRelations[1].targets[0],
docAccessibleFront,
"Label's containing document is a root document"
);
const controlRelations = await controlAccessibleFront.getRelations();
is(controlRelations.length, 4, "Control has correct number of relations");
is(controlRelations[3].type, "details", "Control has a details relation");
is(controlRelations[3].targets.length, 1, "Control has one details target");
const detailsNode = await walker.querySelector(walker.rootNode, "#details");
const detailsAccessibleFront = await a11yWalker.getAccessibleFor(detailsNode);
is(
controlRelations[3].targets[0],
detailsAccessibleFront,
"Control has correct details target"
);
info("Snapshot");
const snapshot = await controlAccessibleFront.snapshot();
Assert.deepEqual(snapshot, {
name: "Label",
role: "textbox",
actions: ["Activate"],
value: "",
nodeCssSelector: "#control",
nodeType: 1,
description: "",
keyboardShortcut: "",
childCount: 0,
indexInParent: 1,
states: [
"focusable",
"autocompletion",
"selectable text",
"editable",
"opaque",
"single line",
"enabled",
"sensitive",
],
children: [],
attributes: {
"margin-left": "0px",
"text-align": "start",
"text-indent": "0px",
id: "control",
tag: "input",
"margin-top": "0px",
"margin-bottom": "0px",
"margin-right": "0px",
display: "inline-block",
"explicit-name": "true",
"details-from": "aria-details",
},
});
// Check that we're using ARIA role tokens for landmarks implicit in native
// markup.
const headerNode = await walker.querySelector(walker.rootNode, "#header");
const headerAccessibleFront = await a11yWalker.getAccessibleFor(headerNode);
checkA11yFront(headerAccessibleFront, {
name: null,
role: "banner",
childCount: 1,
});
const navNode = await walker.querySelector(walker.rootNode, "#nav");
const navAccessibleFront = await a11yWalker.getAccessibleFor(navNode);
checkA11yFront(navAccessibleFront, {
name: null,
role: "navigation",
childCount: 1,
});
const footerNode = await walker.querySelector(walker.rootNode, "#footer");
const footerAccessibleFront = await a11yWalker.getAccessibleFor(footerNode);
checkA11yFront(footerAccessibleFront, {
name: null,
role: "contentinfo",
childCount: 1,
});
await waitForA11yShutdown(parentAccessibility);
await target.destroy();
gBrowser.removeCurrentTab();
});