Skip to content

Truly independent web browser

LibWeb: Keep accessibility node data between accessibility-tree builds

sideshowbarker3da7f10bc78c
diff --git a/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp b/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp
index c8666603e89..e226fe2205a 100644
--- a/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp
+++ b/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp
@@ -235,560 +235,610 @@ Document::CachedAccessibleText AccessibilityTreeNode::compute_accessible_text(El
return text;
}
-void AccessibilityTreeNode::serialize_tree_as_node_data(Vector<WebView::AccessibilityNodeData>& out, Document const& document, Layout::BegunRead const& read, i64 parent_id) const
+// Fills in where each character of a text leaf renders, relative to the text's own top-left; where its lines break and
+// how tall they are; and, once its lines are known, its bounds. Any layout can change all of that, with nothing changing
+// in the text node itself, so it's computed again on every build of the tree.
+static void fill_text_geometry(WebView::AccessibilityNodeData& node_data, DOM::Text const& text_node, Gfx::Font const* font, Document const& document, Layout::BegunRead const& read)
{
- WebView::AccessibilityNodeData node_data;
- node_data.parent_id = parent_id;
+ // Compute per-character (x, y) offsets and line-break positions. Visual lines give the DOM offsets
+ // of each rendered line of this text node; the caret rect at a line's first offset gives that line's
+ // origin and height. Text that renders no lines falls back to a single-line font-metrics computation.
+ auto utf8 = node_data.name.bytes_as_string_view();
+ Utf8View view { utf8 };
+
+ auto* layout = text_node.layout_node(read);
+
+ // The caret rect at a DOM offset is document-absolute and spans the height of the line the offset
+ // renders on, which is what a line's geometry is read from here.
+ auto line_rect_at_offset = [&](size_t offset) -> Optional<CSSPixelRect> {
+ if (!layout)
+ return {};
+ Layout::RustFFI::FfiOptionalCssPixelRect result;
+ Layout::RustFFI::layout_script_text_caret_rect_in_dom_range(
+ layout->document_host(), Layout::Node::slot_id(layout), offset, &result);
+ if (!result.has_value)
+ return {};
+ return result.rect;
+ };
- if (value()->is_element()) {
- auto const& element = static_cast<DOM::Element const&>(*value());
-
- node_data.id = static_cast<i64>(element.unique_id().value());
- // role_or_default() already applies the presentational-role conflict rules: a none/presentation role on an
- // element that's focusable or carries a global ARIA attribute is ignored, and the implicit role comes back in
- // its place — as Blink/WebKit/Gecko do in AXObject::DetermineAriaRole() / AccessibilityNodeObject::
- // determineAriaRoleAttribute() / nsAccessibilityService::CreateAccessible() before they fall back to the
- // element's own implicit role.
- auto role = element.role_or_default();
- if (role.has_value() && !ARIA::is_abstract_role(*role))
- node_data.role = ARIA::role_name(*role).to_utf8();
- else if (is_frame_element(element))
- node_data.role = "iframe"_string;
-
- // While an assistive technology consumes the tree, it's rebuilt after every change to the page, so keep each
- // element's name and description from one build to the next until a change could alter them.
- Document::CachedAccessibleText text;
- if (!document.page().accessibility_interested()) {
- text = compute_accessible_text(element, document);
- } else if (auto const* cached = document.cached_accessible_text(element)) {
- text = *cached;
- } else {
- text = compute_accessible_text(element, document);
- document.cache_accessible_text(element, text);
+ struct RenderedLine {
+ VisualLine line;
+ CSSPixelRect rect;
+ };
+ Vector<RenderedLine> rendered_lines;
+ for (auto const& line : collect_visual_lines(read, text_node)) {
+ if (!line.has_fragments)
+ continue;
+ if (auto rect = line_rect_at_offset(line.start_offset); rect.has_value())
+ rendered_lines.append({ line, *rect });
+ }
+
+ if (!rendered_lines.is_empty()) {
+ if (auto own_box = text_bounding_client_rect(document, *layout); own_box.has_value())
+ node_data.bounds = own_box->to_type<int>();
+
+ // Report positions relative to the text's own top-left (its leftmost line's left edge and its
+ // topmost line's top): Caret rects are document-absolute, so the offsets don't move with scrolling,
+ // and node_data.bounds' top-left is that same point in viewport space — so bounds' top-left plus an
+ // offset is where the character is on screen.
+ auto text_origin = rendered_lines.first().rect.top_left();
+ for (auto const& rendered : rendered_lines) {
+ text_origin.set_x(min(text_origin.x(), rendered.rect.x()));
+ text_origin.set_y(min(text_origin.y(), rendered.rect.y()));
}
- node_data.name = move(text.name);
- node_data.description = move(text.description);
- node_data.bounds = accessibility_bounds(read, element);
-
- // aria-level is a heading's level only on a heading. On a treeitem, row or listitem it's the item's depth,
- // which the bridges expose as a hierarchical level (the ATK "level" object attribute, AXDisclosureLevel) and
- // never as the node's value — the split WebKit (AccessibilityNodeObject::headingLevel() vs. AXCoreObject::
- // hierarchicalLevel()), Blink (AXNodeObject::HeadingLevel() vs. AXNodeObject::HierarchicalLevel()) and Gecko
- // (HTMLHeadingAccessible vs. GroupPosition().level) all make. On any other role aria-level is an author error
- // and is ignored. A treeitem's depth isn't computed from its nesting yet, as Blink's HierarchicalLevel() does.
- if (auto level = element.aria_level(); level.has_value() && role.has_value()) {
- if (auto parsed = level->to_number<i32>(); parsed.has_value() && *parsed >= 1) {
- if (*role == ARIA::Role::heading)
- node_data.heading_level = *parsed;
- else if (*role == ARIA::Role::treeitem || *role == ARIA::Role::row || *role == ARIA::Role::listitem)
- node_data.hierarchical_level = *parsed;
+ auto text_utf16 = text_node.data().utf16_view();
+
+ // The document-absolute x where each DOM offset's character starts, and where each fragment's text
+ // ends, from the glyph runs layout shaped the text into.
+ struct CharacterXPositions {
+ Vector<Optional<float>> start_x;
+ Vector<Optional<float>> fragment_end_x;
+ };
+ CharacterXPositions x_positions;
+ x_positions.start_x.resize(text_utf16.length_in_code_units() + 1);
+ x_positions.fragment_end_x.resize(text_utf16.length_in_code_units() + 1);
+ Layout::RustFFI::layout_script_text_character_x_positions(
+ layout->document_host(), Layout::Node::slot_id(layout), &x_positions,
+ [](void* context, size_t offset, float x, bool is_fragment_end) {
+ auto& positions = *static_cast<CharacterXPositions*>(context);
+ auto& list = is_fragment_end ? positions.fragment_end_x : positions.start_x;
+ if (offset < list.size())
+ list[offset] = x;
+ });
+ auto origin_x = text_origin.x().to_float();
+ auto known_x = [&](Vector<Optional<float>> const& list, size_t offset) -> Optional<float> {
+ if (offset >= list.size() || !list[offset].has_value())
+ return {};
+ return *list[offset] - origin_x;
+ };
+
+ // Where the rendered text last reached: the position of the characters no line renders.
+ Optional<Gfx::IntPoint> rendered_end;
+ for (auto const& [line, line_rect] : rendered_lines) {
+ auto line_top_y = static_cast<i32>(line_rect.y().to_int() - text_origin.y().to_int());
+ auto line_left_x = static_cast<i32>(line_rect.x().to_int() - text_origin.x().to_int());
+ auto line_height = static_cast<i32>(line_rect.height().to_int());
+ // A visual line's offsets index the DOM data(), which is what node_data.name and text_utf16
+ // hold. Collapsed whitespace renders on no line: a line starts past any leading run, and its
+ // end_offset excludes the run hanging at a soft wrap.
+ auto line_character_start = text_utf16.code_point_offset_of(line.start_offset);
+ auto line_character_end = text_utf16.code_point_offset_of(line.end_offset);
+ // Entry N is character N's position, so the characters no line renders take the position the
+ // rendered text last reached (a leading run: the first line's start), and the first line starts
+ // at character 0, leading run included.
+ auto gap_position = rendered_end.value_or(Gfx::IntPoint { line_left_x, line_top_y });
+ while (node_data.character_offsets.size() < line_character_start)
+ node_data.character_offsets.append(gap_position);
+ node_data.line_break_character_offsets.append(node_data.line_break_character_offsets.is_empty() ? 0 : static_cast<i32>(line_character_start));
+ node_data.line_heights.append(line_height);
+ // Each character's x is where layout's glyph run puts it. A character layout gives no position
+ // to (whitespace that collapsed away) takes no width: It sits where the next positioned character
+ // on the line starts, or where the line ends. Only a line layout positions nothing on (e.g. vertical
+ // text) falls back to advancing each character by its own width, shaped on its own.
+ auto utf8_start = view.byte_offset_of(line_character_start);
+ auto utf8_end = view.byte_offset_of(line_character_end);
+ Utf8View line_view { utf8.substring_view(utf8_start, utf8_end - utf8_start) };
+ Vector<u32> line_code_points;
+ Vector<Optional<float>> line_x;
+ size_t code_unit_offset = line.start_offset;
+ for (u32 code_point : line_view) {
+ line_code_points.append(code_point);
+ line_x.append(known_x(x_positions.start_x, code_unit_offset));
+ code_unit_offset += code_point > 0xFFFF ? 2 : 1;
}
- }
-
- // https://www.w3.org/TR/wai-aria-1.2/#aria-live
- // Only assertive, polite, and off are aria-live values. Any other value is ignored and the property treated as
- // not present (ARIA 1.2, Handling Author Errors), so the role's implicit value applies. WebKit does the same
- // (defaultLiveRegionStatusForRole(), with liveRegionStatusIsEnabled() admitting only polite and assertive);
- // Blink and Gecko instead pass an unknown value through as the platform's live attribute for the AT to judge
- // (AXObject::LiveRegionStatus(), nsAccUtils::SetLiveContainerAttributes()) — an attribute our bridges don't
- // expose. Here the value only decides whether a change is announced, and at which priority.
- auto live = ARIA::AriaData::parse_aria_live(element.aria_live());
- if (!live.has_value() && role.has_value())
- live = ARIA::implicit_aria_live_for_role(*role);
- if (live.has_value())
- node_data.live = aria_live_name(*live);
-
- // https://www.w3.org/TR/wai-aria-1.2/#aria-disabled
- auto aria_disabled = element.get_attribute(ARIA::AttributeNames::aria_disabled);
- if (element.is_actually_disabled() || (aria_disabled.has_value() && aria_disabled.value() == "true"sv))
- node_data.is_disabled = true;
-
- if (auto const* cell = as_if<HTML::HTMLTableCellElement>(element)) {
- node_data.column_span = static_cast<i32>(cell->col_span());
- node_data.row_span = static_cast<i32>(cell->row_span());
-
- // The cell's column index: the col_span sum of the cells before it in its row. Its row index isn't
- // serialized — both bridges derive it from the row's position in the tree.
- auto row_result = cell->closest("tr"sv);
- if (!row_result.is_exception() && row_result.value()) {
- auto const* row = row_result.value();
- i32 col_index = 0;
- for (auto const* prev = row->first_child(); prev && prev != cell; prev = prev->next_sibling()) {
- if (auto const* prev_cell = as_if<HTML::HTMLTableCellElement>(prev))
- col_index += static_cast<i32>(prev_cell->col_span());
+ auto line_end_x = known_x(x_positions.fragment_end_x, line.end_offset);
+ bool layout_positions_line = line_end_x.has_value() || any_of(line_x, [](auto const& x) { return x.has_value(); });
+
+ float end_x = static_cast<float>(line_left_x);
+ if (layout_positions_line) {
+ Optional<float> next_x = line_end_x;
+ for (size_t i = line_x.size(); i-- > 0;) {
+ if (line_x[i].has_value())
+ next_x = line_x[i];
+ else
+ line_x[i] = next_x;
+ }
+ Optional<float> previous_x;
+ for (auto& x : line_x) {
+ if (!x.has_value())
+ x = previous_x.value_or(static_cast<float>(line_left_x));
+ previous_x = x;
+ }
+ end_x = line_end_x.value_or(previous_x.value_or(static_cast<float>(line_left_x)));
+ } else {
+ for (size_t i = 0; i < line_x.size(); ++i) {
+ line_x[i] = end_x;
+ end_x += font ? glyph_advance(*font, line_code_points[i]) : 0.0f;
}
- node_data.cell_column_index = col_index;
}
+ for (auto const& x : line_x)
+ node_data.character_offsets.append(Gfx::IntPoint { static_cast<i32>(*x), line_top_y });
+ rendered_end = Gfx::IntPoint { static_cast<i32>(end_x), line_top_y };
+ }
+ // A trailing run that renders on no line, likewise.
+ while (rendered_end.has_value() && node_data.character_offsets.size() < view.length())
+ node_data.character_offsets.append(*rendered_end);
+ } else if (font) {
+ // Fallback: single-line font-metrics computation.
+ node_data.line_break_character_offsets.append(0);
+ node_data.line_heights.append(node_data.bounds.height());
+ float cumulative = 0;
+ for (u32 code_point : view) {
+ node_data.character_offsets.append(Gfx::IntPoint { static_cast<i32>(cumulative), 0 });
+ cumulative += glyph_advance(*font, code_point);
}
+ }
+}
- if (auto const* table = as_if<HTML::HTMLTableElement>(element)) {
- auto rows = table->rows();
- node_data.table_row_count = static_cast<i32>(rows->length());
- // Column count: maximum over all rows of summed col_span.
- i32 max_cols = 0;
- for (u32 i = 0; i < rows->length(); ++i) {
- auto* row = rows->item(i);
- if (!row)
- continue;
- i32 cols = 0;
- for (auto const* c = row->first_child(); c; c = c->next_sibling()) {
- if (auto const* cell = as_if<HTML::HTMLTableCellElement>(c))
- cols += static_cast<i32>(cell->col_span());
+// The fields that can change with nothing changing in the node itself or its style: its bounds and text geometry,
+// which any layout can move, and whether it has the focus. They're computed again even for a node whose other fields
+// are kept from the last build.
+static void fill_volatile_fields(WebView::AccessibilityNodeData& node_data, DOM::Node const& node, Document const& document, Layout::BegunRead const& read)
+{
+ node_data.bounds = {};
+ node_data.is_focused = false;
+ node_data.character_offsets.clear();
+ node_data.line_break_character_offsets.clear();
+ node_data.line_heights.clear();
+ if (auto const* element = as_if<DOM::Element>(node)) {
+ node_data.bounds = accessibility_bounds(read, *element);
+ node_data.is_focused = element->is_focused();
+ return;
+ }
+ auto const* text_node = as_if<DOM::Text>(node);
+ if (!text_node)
+ return;
+ auto parent = text_node->parent_element();
+ if (!parent)
+ return;
+ node_data.bounds = accessibility_bounds(read, *parent);
+ if (!parent->style_group<CSS::ComputedValues::FontValues>() || !parent->style_group<CSS::ComputedValues::InheritedTextValues>())
+ return;
+ Gfx::Font const* font = nullptr;
+ if (auto layout = parent->layout_node(read))
+ font = &layout->first_available_font();
+ fill_text_geometry(node_data, *text_node, font, document, read);
+}
+
+void AccessibilityTreeNode::serialize_tree_as_node_data(Vector<WebView::AccessibilityNodeData>& out, Document const& document, Layout::BegunRead const& read, i64 parent_id) const
+{
+ WebView::AccessibilityNodeData node_data;
+ node_data.parent_id = parent_id;
+
+ // While an assistive technology consumes the tree, it's rebuilt after every change to the page. So keep what each
+ // node's data holds from one build to the next until a change to the node or its style could alter it, and compute
+ // again just the fields that can change without one.
+ auto keeps_records = document.page().accessibility_interested();
+ if (auto const* record = keeps_records ? document.cached_accessibility_record(*value()) : nullptr) {
+ node_data = *record;
+ fill_volatile_fields(node_data, *value(), document, read);
+ } else {
+ if (value()->is_element()) {
+ auto const& element = static_cast<DOM::Element const&>(*value());
+
+ node_data.id = static_cast<i64>(element.unique_id().value());
+ // role_or_default() already applies the presentational-role conflict rules: a none/presentation role on an
+ // element that's focusable or carries a global ARIA attribute is ignored, and the implicit role comes back in
+ // its place — as Blink/WebKit/Gecko do in AXObject::DetermineAriaRole() / AccessibilityNodeObject::
+ // determineAriaRoleAttribute() / nsAccessibilityService::CreateAccessible() before they fall back to the
+ // element's own implicit role.
+ auto role = element.role_or_default();
+ if (role.has_value() && !ARIA::is_abstract_role(*role))
+ node_data.role = ARIA::role_name(*role).to_utf8();
+ else if (is_frame_element(element))
+ node_data.role = "iframe"_string;
+
+ // While an assistive technology consumes the tree, it's rebuilt after every change to the page, so keep each
+ // element's name and description from one build to the next until a change could alter them.
+ Document::CachedAccessibleText text;
+ if (!document.page().accessibility_interested() || document.accessibility_caches_bypassed()) {
+ text = compute_accessible_text(element, document);
+ } else if (auto const* cached = document.cached_accessible_text(element)) {
+ text = *cached;
+ } else {
+ text = compute_accessible_text(element, document);
+ document.cache_accessible_text(element, text);
+ }
+ node_data.name = move(text.name);
+ node_data.description = move(text.description);
+ node_data.bounds = accessibility_bounds(read, element);
+
+ // aria-level is a heading's level only on a heading. On a treeitem, row or listitem it's the item's depth,
+ // which the bridges expose as a hierarchical level (the ATK "level" object attribute, AXDisclosureLevel) and
+ // never as the node's value — the split WebKit (AccessibilityNodeObject::headingLevel() vs. AXCoreObject::
+ // hierarchicalLevel()), Blink (AXNodeObject::HeadingLevel() vs. AXNodeObject::HierarchicalLevel()) and Gecko
+ // (HTMLHeadingAccessible vs. GroupPosition().level) all make. On any other role aria-level is an author error
+ // and is ignored. A treeitem's depth isn't computed from its nesting yet, as Blink's HierarchicalLevel() does.
+ if (auto level = element.aria_level(); level.has_value() && role.has_value()) {
+ if (auto parsed = level->to_number<i32>(); parsed.has_value() && *parsed >= 1) {
+ if (*role == ARIA::Role::heading)
+ node_data.heading_level = *parsed;
+ else if (*role == ARIA::Role::treeitem || *role == ARIA::Role::row || *role == ARIA::Role::listitem)
+ node_data.hierarchical_level = *parsed;
}
- max_cols = max(max_cols, cols);
}
- node_data.table_column_count = max_cols;
- for (auto const* c = table->first_child(); c; c = c->next_sibling()) {
- if (c->is_element()
- && static_cast<DOM::Element const&>(*c).tag_name().equals_ignoring_ascii_case("caption"sv)) {
- node_data.table_caption_id = static_cast<i64>(c->unique_id().value());
- break;
+ // https://www.w3.org/TR/wai-aria-1.2/#aria-live
+ // Only assertive, polite, and off are aria-live values. Any other value is ignored and the property treated as
+ // not present (ARIA 1.2, Handling Author Errors), so the role's implicit value applies. WebKit does the same
+ // (defaultLiveRegionStatusForRole(), with liveRegionStatusIsEnabled() admitting only polite and assertive);
+ // Blink and Gecko instead pass an unknown value through as the platform's live attribute for the AT to judge
+ // (AXObject::LiveRegionStatus(), nsAccUtils::SetLiveContainerAttributes()) — an attribute our bridges don't
+ // expose. Here the value only decides whether a change is announced, and at which priority.
+ auto live = ARIA::AriaData::parse_aria_live(element.aria_live());
+ if (!live.has_value() && role.has_value())
+ live = ARIA::implicit_aria_live_for_role(*role);
+ if (live.has_value())
+ node_data.live = aria_live_name(*live);
+
+ // https://www.w3.org/TR/wai-aria-1.2/#aria-disabled
+ auto aria_disabled = element.get_attribute(ARIA::AttributeNames::aria_disabled);
+ if (element.is_actually_disabled() || (aria_disabled.has_value() && aria_disabled.value() == "true"sv))
+ node_data.is_disabled = true;
+
+ if (auto const* cell = as_if<HTML::HTMLTableCellElement>(element)) {
+ node_data.column_span = static_cast<i32>(cell->col_span());
+ node_data.row_span = static_cast<i32>(cell->row_span());
+
+ // The cell's column index: the col_span sum of the cells before it in its row. Its row index isn't
+ // serialized — both bridges derive it from the row's position in the tree.
+ auto row_result = cell->closest("tr"sv);
+ if (!row_result.is_exception() && row_result.value()) {
+ auto const* row = row_result.value();
+ i32 col_index = 0;
+ for (auto const* prev = row->first_child(); prev && prev != cell; prev = prev->next_sibling()) {
+ if (auto const* prev_cell = as_if<HTML::HTMLTableCellElement>(prev))
+ col_index += static_cast<i32>(prev_cell->col_span());
+ }
+ node_data.cell_column_index = col_index;
}
}
- if (auto summary = table->get_attribute(HTML::AttributeNames::summary); summary.has_value())
- node_data.table_summary = summary.release_value().to_utf8();
-
- // Column headers: first row's th cells (or any row with explicit scope=col). Row headers: first th cell in
- // each row (or any cell with scope=row).
- node_data.column_header_ids.resize(max_cols, true);
- for (i32 c = 0; c < max_cols; ++c)
- node_data.column_header_ids[c] = -1;
- node_data.row_header_ids.resize(rows->length(), true);
- for (u32 r = 0; r < rows->length(); ++r)
- node_data.row_header_ids[r] = -1;
-
- for (u32 row_index = 0; row_index < rows->length(); ++row_index) {
- auto* row = rows->item(row_index);
- if (!row)
- continue;
- i32 col_index = 0;
- for (auto const* c = row->first_child(); c; c = c->next_sibling()) {
- auto const* cell = as_if<HTML::HTMLTableCellElement>(c);
- if (!cell)
+ if (auto const* table = as_if<HTML::HTMLTableElement>(element)) {
+ auto rows = table->rows();
+ node_data.table_row_count = static_cast<i32>(rows->length());
+ // Column count: maximum over all rows of summed col_span.
+ i32 max_cols = 0;
+ for (u32 i = 0; i < rows->length(); ++i) {
+ auto* row = rows->item(i);
+ if (!row)
continue;
- auto cell_id = static_cast<i64>(cell->unique_id().value());
- auto tag = cell->tag_name();
- auto scope_attr = cell->get_attribute(HTML::AttributeNames::scope).value_or({});
- auto scope = scope_attr.utf16_view();
- bool is_th = tag.equals_ignoring_ascii_case("th"sv);
- if (is_th && (scope == "col"sv || (scope.is_empty() && row_index == 0))) {
- if (col_index < max_cols)
- node_data.column_header_ids[col_index] = cell_id;
+ i32 cols = 0;
+ for (auto const* c = row->first_child(); c; c = c->next_sibling()) {
+ if (auto const* cell = as_if<HTML::HTMLTableCellElement>(c))
+ cols += static_cast<i32>(cell->col_span());
}
- if (is_th && (scope == "row"sv || (scope.is_empty() && col_index == 0))) {
- if (row_index < node_data.row_header_ids.size())
- node_data.row_header_ids[row_index] = cell_id;
+ max_cols = max(max_cols, cols);
+ }
+ node_data.table_column_count = max_cols;
+
+ for (auto const* c = table->first_child(); c; c = c->next_sibling()) {
+ if (c->is_element()
+ && static_cast<DOM::Element const&>(*c).tag_name().equals_ignoring_ascii_case("caption"sv)) {
+ node_data.table_caption_id = static_cast<i64>(c->unique_id().value());
+ break;
}
- col_index += static_cast<i32>(cell->col_span());
}
- }
- }
- // The text a control now holds, which AT reads back as its value. A password field's is the mask the field
- // renders — one U+25CF BLACK CIRCLE per code point, as text_transform.rs draws it — never the text typed,
- // so an AT's caret and selection offsets stay valid without the password reaching every AT client. That's
- // the rendered text WebKit (AccessibilityRenderObject::secureFieldValue()) and Blink (AXNodeObject::
- // GetValueForControl() masks with the text-security character) hand out; Gecko (HTMLTextFieldAccessible::
- // Value()) exposes no value for a password field at all.
- if (auto const* input = as_if<HTML::HTMLInputElement>(element)) {
- using TAS = HTML::HTMLInputElement::TypeAttributeState;
- auto type = input->type_state();
- if (type == TAS::Text || type == TAS::Search || type == TAS::Email || type == TAS::Telephone
- || type == TAS::URL) {
- node_data.value = input->value().to_utf8();
- } else if (type == TAS::Password) {
- node_data.is_password = true;
- node_data.value = MUST(String::repeated(0x25CF, input->value().length_in_code_points()));
+ if (auto summary = table->get_attribute(HTML::AttributeNames::summary); summary.has_value())
+ node_data.table_summary = summary.release_value().to_utf8();
+
+ // Column headers: first row's th cells (or any row with explicit scope=col). Row headers: first th cell in
+ // each row (or any cell with scope=row).
+ node_data.column_header_ids.resize(max_cols, true);
+ for (i32 c = 0; c < max_cols; ++c)
+ node_data.column_header_ids[c] = -1;
+ node_data.row_header_ids.resize(rows->length(), true);
+ for (u32 r = 0; r < rows->length(); ++r)
+ node_data.row_header_ids[r] = -1;
+
+ for (u32 row_index = 0; row_index < rows->length(); ++row_index) {
+ auto* row = rows->item(row_index);
+ if (!row)
+ continue;
+ i32 col_index = 0;
+ for (auto const* c = row->first_child(); c; c = c->next_sibling()) {
+ auto const* cell = as_if<HTML::HTMLTableCellElement>(c);
+ if (!cell)
+ continue;
+ auto cell_id = static_cast<i64>(cell->unique_id().value());
+ auto tag = cell->tag_name();
+ auto scope_attr = cell->get_attribute(HTML::AttributeNames::scope).value_or({});
+ auto scope = scope_attr.utf16_view();
+ bool is_th = tag.equals_ignoring_ascii_case("th"sv);
+ if (is_th && (scope == "col"sv || (scope.is_empty() && row_index == 0))) {
+ if (col_index < max_cols)
+ node_data.column_header_ids[col_index] = cell_id;
+ }
+ if (is_th && (scope == "row"sv || (scope.is_empty() && col_index == 0))) {
+ if (row_index < node_data.row_header_ids.size())
+ node_data.row_header_ids[row_index] = cell_id;
+ }
+ col_index += static_cast<i32>(cell->col_span());
+ }
+ }
}
- } else if (auto const* text_area = as_if<HTML::HTMLTextAreaElement>(element)) {
- node_data.value = text_area->value().to_utf8();
- }
- // AtkValue fields for numeric-value elements.
- if (auto const* progress = as_if<HTML::HTMLProgressElement>(element)) {
- node_data.value_numeric = progress->value();
- node_data.value_minimum = 0.0;
- node_data.value_maximum = progress->max();
- } else if (auto const* meter = as_if<HTML::HTMLMeterElement>(element)) {
- node_data.value_numeric = meter->value();
- node_data.value_minimum = meter->min();
- node_data.value_maximum = meter->max();
- } else if (auto const* input = as_if<HTML::HTMLInputElement>(element)) {
- if (input->value_as_number_applies()) {
- // NB: An input whose value is not a number, such as an empty one, has a NaN valueAsNumber.
- if (auto number = input->value_as_number(); !isnan(number))
- node_data.value_numeric = number;
- if (auto min_attr = input->get_attribute(HTML::AttributeNames::min); min_attr.has_value()) {
- if (auto parsed = min_attr->to_number<double>(); parsed.has_value())
- node_data.value_minimum = *parsed;
+ // The text a control now holds, which AT reads back as its value. A password field's is the mask the field
+ // renders — one U+25CF BLACK CIRCLE per code point, as text_transform.rs draws it — never the text typed,
+ // so an AT's caret and selection offsets stay valid without the password reaching every AT client. That's
+ // the rendered text WebKit (AccessibilityRenderObject::secureFieldValue()) and Blink (AXNodeObject::
+ // GetValueForControl() masks with the text-security character) hand out; Gecko (HTMLTextFieldAccessible::
+ // Value()) exposes no value for a password field at all.
+ if (auto const* input = as_if<HTML::HTMLInputElement>(element)) {
+ using TAS = HTML::HTMLInputElement::TypeAttributeState;
+ auto type = input->type_state();
+ if (type == TAS::Text || type == TAS::Search || type == TAS::Email || type == TAS::Telephone
+ || type == TAS::URL) {
+ node_data.value = input->value().to_utf8();
+ } else if (type == TAS::Password) {
+ node_data.is_password = true;
+ node_data.value = MUST(String::repeated(0x25CF, input->value().length_in_code_points()));
}
- if (auto max_attr = input->get_attribute(HTML::AttributeNames::max); max_attr.has_value()) {
- if (auto parsed = max_attr->to_number<double>(); parsed.has_value())
- node_data.value_maximum = *parsed;
- }
- if (auto step_attr = input->get_attribute(HTML::AttributeNames::step); step_attr.has_value()) {
- if (auto parsed = step_attr->to_number<double>(); parsed.has_value())
- node_data.value_step = *parsed;
+ } else if (auto const* text_area = as_if<HTML::HTMLTextAreaElement>(element)) {
+ node_data.value = text_area->value().to_utf8();
+ }
+
+ // AtkValue fields for numeric-value elements.
+ if (auto const* progress = as_if<HTML::HTMLProgressElement>(element)) {
+ node_data.value_numeric = progress->value();
+ node_data.value_minimum = 0.0;
+ node_data.value_maximum = progress->max();
+ } else if (auto const* meter = as_if<HTML::HTMLMeterElement>(element)) {
+ node_data.value_numeric = meter->value();
+ node_data.value_minimum = meter->min();
+ node_data.value_maximum = meter->max();
+ } else if (auto const* input = as_if<HTML::HTMLInputElement>(element)) {
+ if (input->value_as_number_applies()) {
+ // NB: An input whose value is not a number, such as an empty one, has a NaN valueAsNumber.
+ if (auto number = input->value_as_number(); !isnan(number))
+ node_data.value_numeric = number;
+ if (auto min_attr = input->get_attribute(HTML::AttributeNames::min); min_attr.has_value()) {
+ if (auto parsed = min_attr->to_number<double>(); parsed.has_value())
+ node_data.value_minimum = *parsed;
+ }
+ if (auto max_attr = input->get_attribute(HTML::AttributeNames::max); max_attr.has_value()) {
+ if (auto parsed = max_attr->to_number<double>(); parsed.has_value())
+ node_data.value_maximum = *parsed;
+ }
+ if (auto step_attr = input->get_attribute(HTML::AttributeNames::step); step_attr.has_value()) {
+ if (auto parsed = step_attr->to_number<double>(); parsed.has_value())
+ node_data.value_step = *parsed;
+ }
}
}
- }
- // AtkSelection state. An <option> carries the state in the host language; anything else, such as a
- // role="option" element, carries it in aria-selected.
- // https://www.w3.org/TR/wai-aria-1.2/#aria-selected
- if (auto const* option = as_if<HTML::HTMLOptionElement>(element)) {
- node_data.is_selected = option->selected();
- } else if (auto aria_selected = element.get_attribute(ARIA::AttributeNames::aria_selected); aria_selected.has_value()) {
- node_data.is_selected = aria_selected.value() == "true"sv;
- }
+ // AtkSelection state. An <option> carries the state in the host language; anything else, such as a
+ // role="option" element, carries it in aria-selected.
+ // https://www.w3.org/TR/wai-aria-1.2/#aria-selected
+ if (auto const* option = as_if<HTML::HTMLOptionElement>(element)) {
+ node_data.is_selected = option->selected();
+ } else if (auto aria_selected = element.get_attribute(ARIA::AttributeNames::aria_selected); aria_selected.has_value()) {
+ node_data.is_selected = aria_selected.value() == "true"sv;
+ }
- // A checkbox or radio button carries the state in the host language, which wins over aria-checked. Any other
- // element (including an input whose role's been overridden to one that's checkable) takes it from aria-checked.
- if (auto const* input = as_if<HTML::HTMLInputElement>(element);
- input && (input->type_state() == HTML::HTMLInputElement::TypeAttributeState::Checkbox || input->type_state() == HTML::HTMLInputElement::TypeAttributeState::RadioButton)) {
- if (input->indeterminate())
- node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Mixed;
- else
- node_data.checked_state = input->checked()
- ? WebView::AccessibilityNodeData::CheckedState::Checked
- : WebView::AccessibilityNodeData::CheckedState::Unchecked;
- } else if (auto aria_checked = element.get_attribute(ARIA::AttributeNames::aria_checked); aria_checked.has_value()) {
- auto value = aria_checked.value();
- if (value == "true"sv)
- node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Checked;
- else if (value == "false"sv)
- node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Unchecked;
- else if (value == "mixed"sv)
- node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Mixed;
- }
+ // A checkbox or radio button carries the state in the host language, which wins over aria-checked. Any other
+ // element (including an input whose role's been overridden to one that's checkable) takes it from aria-checked.
+ if (auto const* input = as_if<HTML::HTMLInputElement>(element);
+ input && (input->type_state() == HTML::HTMLInputElement::TypeAttributeState::Checkbox || input->type_state() == HTML::HTMLInputElement::TypeAttributeState::RadioButton)) {
+ if (input->indeterminate())
+ node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Mixed;
+ else
+ node_data.checked_state = input->checked()
+ ? WebView::AccessibilityNodeData::CheckedState::Checked
+ : WebView::AccessibilityNodeData::CheckedState::Unchecked;
+ } else if (auto aria_checked = element.get_attribute(ARIA::AttributeNames::aria_checked); aria_checked.has_value()) {
+ auto value = aria_checked.value();
+ if (value == "true"sv)
+ node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Checked;
+ else if (value == "false"sv)
+ node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Unchecked;
+ else if (value == "mixed"sv)
+ node_data.checked_state = WebView::AccessibilityNodeData::CheckedState::Mixed;
+ }
- if (auto const* details = as_if<HTML::HTMLDetailsElement>(element)) {
- node_data.expanded_state = details->has_attribute(HTML::AttributeNames::open)
- ? WebView::AccessibilityNodeData::ExpandedState::Expanded
- : WebView::AccessibilityNodeData::ExpandedState::Collapsed;
- } else if (auto aria_expanded = element.get_attribute(ARIA::AttributeNames::aria_expanded);
- aria_expanded.has_value()) {
- auto value = aria_expanded.value();
- if (value == "true"sv)
- node_data.expanded_state = WebView::AccessibilityNodeData::ExpandedState::Expanded;
- else if (value == "false"sv)
- node_data.expanded_state = WebView::AccessibilityNodeData::ExpandedState::Collapsed;
- }
+ if (auto const* details = as_if<HTML::HTMLDetailsElement>(element)) {
+ node_data.expanded_state = details->has_attribute(HTML::AttributeNames::open)
+ ? WebView::AccessibilityNodeData::ExpandedState::Expanded
+ : WebView::AccessibilityNodeData::ExpandedState::Collapsed;
+ } else if (auto aria_expanded = element.get_attribute(ARIA::AttributeNames::aria_expanded);
+ aria_expanded.has_value()) {
+ auto value = aria_expanded.value();
+ if (value == "true"sv)
+ node_data.expanded_state = WebView::AccessibilityNodeData::ExpandedState::Expanded;
+ else if (value == "false"sv)
+ node_data.expanded_state = WebView::AccessibilityNodeData::ExpandedState::Collapsed;
+ }
- // Editable/multi-line/read-only for text inputs and textareas and contenteditable.
- auto is_readonly_attr = element.has_attribute(HTML::AttributeNames::readonly);
- auto is_required_attr = element.has_attribute(HTML::AttributeNames::required);
- if (auto const* input = as_if<HTML::HTMLInputElement>(element)) {
- // Only text-like inputs are "editable"; checkbox/radio/button/submit, etc., are form controls but not
- // text-editable. AT-SPI2's EDITABLE state refers specifically to text editing.
- using TAS = HTML::HTMLInputElement::TypeAttributeState;
- auto type = input->type_state();
- bool is_text_type = type == TAS::Text || type == TAS::Search || type == TAS::Email
- || type == TAS::Password || type == TAS::Telephone || type == TAS::URL || type == TAS::Number;
- if (is_text_type && !is_readonly_attr)
- node_data.is_editable = true;
- if (is_text_type && is_readonly_attr)
- node_data.is_read_only = true;
- if (is_required_attr)
- node_data.is_required = true;
- } else if (is<HTML::HTMLTextAreaElement>(element)) {
- if (!is_readonly_attr)
+ // Editable/multi-line/read-only for text inputs and textareas and contenteditable.
+ auto is_readonly_attr = element.has_attribute(HTML::AttributeNames::readonly);
+ auto is_required_attr = element.has_attribute(HTML::AttributeNames::required);
+ if (auto const* input = as_if<HTML::HTMLInputElement>(element)) {
+ // Only text-like inputs are "editable"; checkbox/radio/button/submit, etc., are form controls but not
+ // text-editable. AT-SPI2's EDITABLE state refers specifically to text editing.
+ using TAS = HTML::HTMLInputElement::TypeAttributeState;
+ auto type = input->type_state();
+ bool is_text_type = type == TAS::Text || type == TAS::Search || type == TAS::Email
+ || type == TAS::Password || type == TAS::Telephone || type == TAS::URL || type == TAS::Number;
+ if (is_text_type && !is_readonly_attr)
+ node_data.is_editable = true;
+ if (is_text_type && is_readonly_attr)
+ node_data.is_read_only = true;
+ if (is_required_attr)
+ node_data.is_required = true;
+ } else if (is<HTML::HTMLTextAreaElement>(element)) {
+ if (!is_readonly_attr)
+ node_data.is_editable = true;
+ if (is_readonly_attr)
+ node_data.is_read_only = true;
+ if (is_required_attr)
+ node_data.is_required = true;
+ node_data.is_multi_line = true;
+ } else if (element.is_editable_or_editing_host()) {
node_data.is_editable = true;
- if (is_readonly_attr)
- node_data.is_read_only = true;
- if (is_required_attr)
- node_data.is_required = true;
- node_data.is_multi_line = true;
- } else if (element.is_editable_or_editing_host()) {
- node_data.is_editable = true;
- node_data.is_multi_line = true; // contenteditable elements default to multi-line.
- }
+ node_data.is_multi_line = true; // contenteditable elements default to multi-line.
+ }
- // A disabled control cannot be edited, whichever branch above decided it was editable.
- if (node_data.is_disabled)
- node_data.is_editable = false;
+ // A disabled control cannot be edited, whichever branch above decided it was editable.
+ if (node_data.is_disabled)
+ node_data.is_editable = false;
- // aria-* overrides.
- if (auto ro = element.get_attribute(ARIA::AttributeNames::aria_read_only);
- ro.has_value() && ro.value() == "true"sv) {
- node_data.is_read_only = true;
- node_data.is_editable = false;
- }
- if (auto req = element.get_attribute(ARIA::AttributeNames::aria_required);
- req.has_value() && req.value() == "true"sv)
- node_data.is_required = true;
- if (auto ml = element.get_attribute(ARIA::AttributeNames::aria_multi_line);
- ml.has_value() && ml.value() == "true"sv)
- node_data.is_multi_line = true;
-
- if (auto invalid = element.get_attribute(ARIA::AttributeNames::aria_invalid);
- invalid.has_value() && invalid.value() != "false"sv
- && !invalid.value().is_empty())
- node_data.is_invalid = true;
-
- if (auto const* select = as_if<HTML::HTMLSelectElement>(element)) {
- if (select->has_attribute(HTML::AttributeNames::multiple))
+ // aria-* overrides.
+ if (auto ro = element.get_attribute(ARIA::AttributeNames::aria_read_only);
+ ro.has_value() && ro.value() == "true"sv) {
+ node_data.is_read_only = true;
+ node_data.is_editable = false;
+ }
+ if (auto req = element.get_attribute(ARIA::AttributeNames::aria_required);
+ req.has_value() && req.value() == "true"sv)
+ node_data.is_required = true;
+ if (auto ml = element.get_attribute(ARIA::AttributeNames::aria_multi_line);
+ ml.has_value() && ml.value() == "true"sv)
+ node_data.is_multi_line = true;
+
+ if (auto invalid = element.get_attribute(ARIA::AttributeNames::aria_invalid);
+ invalid.has_value() && invalid.value() != "false"sv
+ && !invalid.value().is_empty())
+ node_data.is_invalid = true;
+
+ if (auto const* select = as_if<HTML::HTMLSelectElement>(element)) {
+ if (select->has_attribute(HTML::AttributeNames::multiple))
+ node_data.is_multi_selectable = true;
+ }
+ if (auto ms = element.get_attribute(ARIA::AttributeNames::aria_multi_selectable);
+ ms.has_value() && ms.value() == "true"sv)
node_data.is_multi_selectable = true;
- }
- if (auto ms = element.get_attribute(ARIA::AttributeNames::aria_multi_selectable);
- ms.has_value() && ms.value() == "true"sv)
- node_data.is_multi_selectable = true;
-
- if (auto aria_pressed = element.get_attribute(ARIA::AttributeNames::aria_pressed); aria_pressed.has_value()) {
- auto value = aria_pressed.value();
- if (value == "true"sv)
- node_data.pressed_state = WebView::AccessibilityNodeData::PressedState::Pressed;
- else if (value == "false"sv)
- node_data.pressed_state = WebView::AccessibilityNodeData::PressedState::NotPressed;
- else if (value == "mixed"sv)
- node_data.pressed_state = WebView::AccessibilityNodeData::PressedState::Mixed;
- }
- // Visited links.
- if (auto const* anchor = as_if<HTML::HTMLAnchorElement>(element)) {
- (void)anchor;
- }
+ if (auto aria_pressed = element.get_attribute(ARIA::AttributeNames::aria_pressed); aria_pressed.has_value()) {
+ auto value = aria_pressed.value();
+ if (value == "true"sv)
+ node_data.pressed_state = WebView::AccessibilityNodeData::PressedState::Pressed;
+ else if (value == "false"sv)
+ node_data.pressed_state = WebView::AccessibilityNodeData::PressedState::NotPressed;
+ else if (value == "mixed"sv)
+ node_data.pressed_state = WebView::AccessibilityNodeData::PressedState::Mixed;
+ }
- if (auto accesskey = element.get_attribute(HTML::AttributeNames::accesskey); accesskey.has_value())
- node_data.keybinding = accesskey.release_value().to_utf8();
+ // Visited links.
+ if (auto const* anchor = as_if<HTML::HTMLAnchorElement>(element)) {
+ (void)anchor;
+ }
- if (auto const* anchor = as_if<HTML::HTMLAnchorElement>(element))
- node_data.url = anchor->href().to_utf8();
- else if (auto const* area = as_if<HTML::HTMLAreaElement>(element))
- node_data.url = area->href().to_utf8();
+ if (auto accesskey = element.get_attribute(HTML::AttributeNames::accesskey); accesskey.has_value())
+ node_data.keybinding = accesskey.release_value().to_utf8();
- if (auto const* html_element = as_if<HTML::HTMLHtmlElement>(element)) {
- if (auto lang = html_element->get_attribute(HTML::AttributeNames::lang); lang.has_value())
- node_data.language = lang.release_value().to_utf8();
- }
+ if (auto const* anchor = as_if<HTML::HTMLAnchorElement>(element))
+ node_data.url = anchor->href().to_utf8();
+ else if (auto const* area = as_if<HTML::HTMLAreaElement>(element))
+ node_data.url = area->href().to_utf8();
- // Only the element that has the focus is focused — not the body that activeElement falls back to when nothing
- // does. Focus is on the document then, and the bridges hand the AT the document root, as Gecko, WebKit, and
- // Blink do (FocusManager::FocusedDOMNode() / AccessibilityNodeObject::isFocused() / AXNodeObject::IsFocused()).
- node_data.is_focused = element.is_focused();
- } else if (value()->is_text()) {
- auto const& text_node = static_cast<DOM::Text const&>(*value());
- node_data.id = static_cast<i64>(text_node.unique_id().value());
- node_data.role = "text leaf"_string;
- node_data.name = text_node.data().to_utf8();
-
- // A text leaf's box is the union of its rendered lines, set below once those are known. Until then — and for
- // good when the text renders no line — the parent element's box stands in.
- if (auto parent = text_node.parent_element()) {
- node_data.bounds = accessibility_bounds(read, *parent);
-
- // Read text formatting from the parent element's computed style. Text leaves inherit all their formatting
- // from their containing element. So this covers the common case: mixed inline text and formatting changes.
- // <p>Hello <b>world</b>: "Hello " and "world" are separate text leaves with different computed_properties.
- auto const* font_values = parent->style_group<CSS::ComputedValues::FontValues>();
- auto const* text_values = parent->style_group<CSS::ComputedValues::InheritedTextValues>();
- auto const* text_reset_values = parent->style_group<CSS::ComputedValues::TextResetValues>();
- auto const* background_values = parent->style_group<CSS::ComputedValues::BackgroundValues>();
- if (font_values && text_values) {
- Gfx::Font const* font = nullptr;
- if (auto layout = parent->layout_node(read)) {
- font = &layout->first_available_font();
- node_data.font_family = font->family().to_string();
- }
- node_data.font_size = MUST(String::formatted("{}", font_values->font_size.to_double()));
- node_data.font_weight = MUST(String::formatted("{}", font_values->font_weight));
-
- switch (font_values->font_style_keyword()) {
- case CSS::FontStyleKeyword::Italic:
- node_data.font_style = "italic"_string;
- break;
- case CSS::FontStyleKeyword::Oblique:
- node_data.font_style = "oblique"_string;
- break;
- default:
- node_data.font_style = "normal"_string;
- break;
- }
+ if (auto const* html_element = as_if<HTML::HTMLHtmlElement>(element)) {
+ if (auto lang = html_element->get_attribute(HTML::AttributeNames::lang); lang.has_value())
+ node_data.language = lang.release_value().to_utf8();
+ }
- StringBuilder decoration_builder;
- for (auto line : text_reset_values ? text_reset_values->decoration_lines() : ReadonlySpan<CSS::TextDecorationLine> {}) {
- if (!decoration_builder.is_empty())
- decoration_builder.append(' ');
- switch (line) {
- case CSS::TextDecorationLine::Underline:
- decoration_builder.append("underline"sv);
- break;
- case CSS::TextDecorationLine::LineThrough:
- decoration_builder.append("line-through"sv);
- break;
- case CSS::TextDecorationLine::Overline:
- decoration_builder.append("overline"sv);
+ // Only the element that has the focus is focused — not the body that activeElement falls back to when nothing
+ // does. Focus is on the document then, and the bridges hand the AT the document root, as Gecko, WebKit, and
+ // Blink do (FocusManager::FocusedDOMNode() / AccessibilityNodeObject::isFocused() / AXNodeObject::IsFocused()).
+ node_data.is_focused = element.is_focused();
+ } else if (value()->is_text()) {
+ auto const& text_node = static_cast<DOM::Text const&>(*value());
+ node_data.id = static_cast<i64>(text_node.unique_id().value());
+ node_data.role = "text leaf"_string;
+ node_data.name = text_node.data().to_utf8();
+
+ // A text leaf's box is the union of its rendered lines, set below once those are known. Until then — and for
+ // good when the text renders no line — the parent element's box stands in.
+ if (auto parent = text_node.parent_element()) {
+ node_data.bounds = accessibility_bounds(read, *parent);
+
+ // Read text formatting from the parent element's computed style. Text leaves inherit all their formatting
+ // from their containing element. So this covers the common case: mixed inline text and formatting changes.
+ // <p>Hello <b>world</b>: "Hello " and "world" are separate text leaves with different computed_properties.
+ auto const* font_values = parent->style_group<CSS::ComputedValues::FontValues>();
+ auto const* text_values = parent->style_group<CSS::ComputedValues::InheritedTextValues>();
+ auto const* text_reset_values = parent->style_group<CSS::ComputedValues::TextResetValues>();
+ auto const* background_values = parent->style_group<CSS::ComputedValues::BackgroundValues>();
+ if (font_values && text_values) {
+ Gfx::Font const* font = nullptr;
+ if (auto layout = parent->layout_node(read)) {
+ font = &layout->first_available_font();
+ node_data.font_family = font->family().to_string();
+ }
+ node_data.font_size = MUST(String::formatted("{}", font_values->font_size.to_double()));
+ node_data.font_weight = MUST(String::formatted("{}", font_values->font_weight));
+
+ switch (font_values->font_style_keyword()) {
+ case CSS::FontStyleKeyword::Italic:
+ node_data.font_style = "italic"_string;
break;
- case CSS::TextDecorationLine::Blink:
- decoration_builder.append("blink"sv);
+ case CSS::FontStyleKeyword::Oblique:
+ node_data.font_style = "oblique"_string;
break;
default:
+ node_data.font_style = "normal"_string;
break;
}
- }
- node_data.text_decoration = decoration_builder.is_empty()
- ? "none"_string
- : MUST(decoration_builder.to_string());
-
- auto fg = text_values->color_value();
- node_data.color = MUST(String::from_byte_string(fg.to_byte_string_without_alpha()));
- auto bg = background_values ? background_values->background_color_value(fg) : Color::Transparent;
- if (bg.alpha() > 0)
- node_data.background_color = MUST(String::from_byte_string(bg.to_byte_string_without_alpha()));
-
- // Compute per-character (x, y) offsets and line-break positions. Visual lines give the DOM offsets
- // of each rendered line of this text node; the caret rect at a line's first offset gives that line's
- // origin and height. Text that renders no lines falls back to a single-line font-metrics computation.
- auto utf8 = node_data.name.bytes_as_string_view();
- Utf8View view { utf8 };
-
- auto* layout = text_node.layout_node(read);
-
- // The caret rect at a DOM offset is document-absolute and spans the height of the line the offset
- // renders on, which is what a line's geometry is read from here.
- auto line_rect_at_offset = [&](size_t offset) -> Optional<CSSPixelRect> {
- if (!layout)
- return {};
- Layout::RustFFI::FfiOptionalCssPixelRect result;
- Layout::RustFFI::layout_script_text_caret_rect_in_dom_range(
- layout->document_host(), Layout::Node::slot_id(layout), offset, &result);
- if (!result.has_value)
- return {};
- return result.rect;
- };
-
- struct RenderedLine {
- VisualLine line;
- CSSPixelRect rect;
- };
- Vector<RenderedLine> rendered_lines;
- for (auto const& line : collect_visual_lines(read, text_node)) {
- if (!line.has_fragments)
- continue;
- if (auto rect = line_rect_at_offset(line.start_offset); rect.has_value())
- rendered_lines.append({ line, *rect });
- }
- if (!rendered_lines.is_empty()) {
- if (auto own_box = text_bounding_client_rect(document, *layout); own_box.has_value())
- node_data.bounds = own_box->to_type<int>();
-
- // Report positions relative to the text's own top-left (its leftmost line's left edge and its
- // topmost line's top): Caret rects are document-absolute, so the offsets don't move with scrolling,
- // and node_data.bounds' top-left is that same point in viewport space — so bounds' top-left plus an
- // offset is where the character is on screen.
- auto text_origin = rendered_lines.first().rect.top_left();
- for (auto const& rendered : rendered_lines) {
- text_origin.set_x(min(text_origin.x(), rendered.rect.x()));
- text_origin.set_y(min(text_origin.y(), rendered.rect.y()));
- }
- auto text_utf16 = text_node.data().utf16_view();
-
- // The document-absolute x where each DOM offset's character starts, and where each fragment's text
- // ends, from the glyph runs layout shaped the text into.
- struct CharacterXPositions {
- Vector<Optional<float>> start_x;
- Vector<Optional<float>> fragment_end_x;
- };
- CharacterXPositions x_positions;
- x_positions.start_x.resize(text_utf16.length_in_code_units() + 1);
- x_positions.fragment_end_x.resize(text_utf16.length_in_code_units() + 1);
- Layout::RustFFI::layout_script_text_character_x_positions(
- layout->document_host(), Layout::Node::slot_id(layout), &x_positions,
- [](void* context, size_t offset, float x, bool is_fragment_end) {
- auto& positions = *static_cast<CharacterXPositions*>(context);
- auto& list = is_fragment_end ? positions.fragment_end_x : positions.start_x;
- if (offset < list.size())
- list[offset] = x;
- });
- auto origin_x = text_origin.x().to_float();
- auto known_x = [&](Vector<Optional<float>> const& list, size_t offset) -> Optional<float> {
- if (offset >= list.size() || !list[offset].has_value())
- return {};
- return *list[offset] - origin_x;
- };
-
- // Where the rendered text last reached: the position of the characters no line renders.
- Optional<Gfx::IntPoint> rendered_end;
- for (auto const& [line, line_rect] : rendered_lines) {
- auto line_top_y = static_cast<i32>(line_rect.y().to_int() - text_origin.y().to_int());
- auto line_left_x = static_cast<i32>(line_rect.x().to_int() - text_origin.x().to_int());
- auto line_height = static_cast<i32>(line_rect.height().to_int());
- // A visual line's offsets index the DOM data(), which is what node_data.name and text_utf16
- // hold. Collapsed whitespace renders on no line: a line starts past any leading run, and its
- // end_offset excludes the run hanging at a soft wrap.
- auto line_character_start = text_utf16.code_point_offset_of(line.start_offset);
- auto line_character_end = text_utf16.code_point_offset_of(line.end_offset);
- // Entry N is character N's position, so the characters no line renders take the position the
- // rendered text last reached (a leading run: the first line's start), and the first line starts
- // at character 0, leading run included.
- auto gap_position = rendered_end.value_or(Gfx::IntPoint { line_left_x, line_top_y });
- while (node_data.character_offsets.size() < line_character_start)
- node_data.character_offsets.append(gap_position);
- node_data.line_break_character_offsets.append(node_data.line_break_character_offsets.is_empty() ? 0 : static_cast<i32>(line_character_start));
- node_data.line_heights.append(line_height);
- // Each character's x is where layout's glyph run puts it. A character layout gives no position
- // to (whitespace that collapsed away) takes no width: It sits where the next positioned character
- // on the line starts, or where the line ends. Only a line layout positions nothing on (e.g. vertical
- // text) falls back to advancing each character by its own width, shaped on its own.
- auto utf8_start = view.byte_offset_of(line_character_start);
- auto utf8_end = view.byte_offset_of(line_character_end);
- Utf8View line_view { utf8.substring_view(utf8_start, utf8_end - utf8_start) };
- Vector<u32> line_code_points;
- Vector<Optional<float>> line_x;
- size_t code_unit_offset = line.start_offset;
- for (u32 code_point : line_view) {
- line_code_points.append(code_point);
- line_x.append(known_x(x_positions.start_x, code_unit_offset));
- code_unit_offset += code_point > 0xFFFF ? 2 : 1;
+ StringBuilder decoration_builder;
+ for (auto line : text_reset_values ? text_reset_values->decoration_lines() : ReadonlySpan<CSS::TextDecorationLine> {}) {
+ if (!decoration_builder.is_empty())
+ decoration_builder.append(' ');
+ switch (line) {
+ case CSS::TextDecorationLine::Underline:
+ decoration_builder.append("underline"sv);
+ break;
+ case CSS::TextDecorationLine::LineThrough:
+ decoration_builder.append("line-through"sv);
+ break;
+ case CSS::TextDecorationLine::Overline:
+ decoration_builder.append("overline"sv);
+ break;
+ case CSS::TextDecorationLine::Blink:
+ decoration_builder.append("blink"sv);
+ break;
+ default:
+ break;
}
- auto line_end_x = known_x(x_positions.fragment_end_x, line.end_offset);
- bool layout_positions_line = line_end_x.has_value() || any_of(line_x, [](auto const& x) { return x.has_value(); });
-
- float end_x = static_cast<float>(line_left_x);
- if (layout_positions_line) {
- Optional<float> next_x = line_end_x;
- for (size_t i = line_x.size(); i-- > 0;) {
- if (line_x[i].has_value())
- next_x = line_x[i];
- else
- line_x[i] = next_x;
- }
- Optional<float> previous_x;
- for (auto& x : line_x) {
- if (!x.has_value())
- x = previous_x.value_or(static_cast<float>(line_left_x));
- previous_x = x;
- }
- end_x = line_end_x.value_or(previous_x.value_or(static_cast<float>(line_left_x)));
- } else {
- for (size_t i = 0; i < line_x.size(); ++i) {
- line_x[i] = end_x;
- end_x += font ? glyph_advance(*font, line_code_points[i]) : 0.0f;
- }
- }
- for (auto const& x : line_x)
- node_data.character_offsets.append(Gfx::IntPoint { static_cast<i32>(*x), line_top_y });
- rendered_end = Gfx::IntPoint { static_cast<i32>(end_x), line_top_y };
- }
- // A trailing run that renders on no line, likewise.
- while (rendered_end.has_value() && node_data.character_offsets.size() < view.length())
- node_data.character_offsets.append(*rendered_end);
- } else if (font) {
- // Fallback: single-line font-metrics computation.
- node_data.line_break_character_offsets.append(0);
- node_data.line_heights.append(node_data.bounds.height());
- float cumulative = 0;
- for (u32 code_point : view) {
- node_data.character_offsets.append(Gfx::IntPoint { static_cast<i32>(cumulative), 0 });
- cumulative += glyph_advance(*font, code_point);
}
+ node_data.text_decoration = decoration_builder.is_empty()
+ ? "none"_string
+ : MUST(decoration_builder.to_string());
+
+ auto fg = text_values->color_value();
+ node_data.color = MUST(String::from_byte_string(fg.to_byte_string_without_alpha()));
+ auto bg = background_values ? background_values->background_color_value(fg) : Color::Transparent;
+ if (bg.alpha() > 0)
+ node_data.background_color = MUST(String::from_byte_string(bg.to_byte_string_without_alpha()));
+
+ fill_text_geometry(node_data, text_node, font, document, read);
}
}
}
+ if (keeps_records)
+ document.cache_accessibility_record(*value(), node_data);
}
+ node_data.parent_id = parent_id;
// Populate caret offset and selection range from the DOM Selection — for any node (element or text) that contains
// it. This is what AtkText::get_caret_offset and get_n_selections report.
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index c26de7bd7df..0a3384552ea 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -10,6 +10,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/AnyOf.h>
#include <AK/Bitmap.h>
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
@@ -165,6 +166,7 @@
#include <LibWeb/HTML/HTMLDocument.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/HTMLEmbedElement.h>
+#include <LibWeb/HTML/HTMLFieldSetElement.h>
#include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLFrameSetElement.h>
#include <LibWeb/HTML/HTMLHeadElement.h>
@@ -174,12 +176,19 @@
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/HTMLInsertion.h>
#include <LibWeb/HTML/HTMLLabelElement.h>
+#include <LibWeb/HTML/HTMLLegendElement.h>
#include <LibWeb/HTML/HTMLLinkElement.h>
#include <LibWeb/HTML/HTMLMediaElement.h>
#include <LibWeb/HTML/HTMLMetaElement.h>
#include <LibWeb/HTML/HTMLObjectElement.h>
#include <LibWeb/HTML/HTMLScriptElement.h>
#include <LibWeb/HTML/HTMLStyleElement.h>
+#include <LibWeb/HTML/HTMLTableCaptionElement.h>
+#include <LibWeb/HTML/HTMLTableCellElement.h>
+#include <LibWeb/HTML/HTMLTableColElement.h>
+#include <LibWeb/HTML/HTMLTableElement.h>
+#include <LibWeb/HTML/HTMLTableRowElement.h>
+#include <LibWeb/HTML/HTMLTableSectionElement.h>
#include <LibWeb/HTML/HTMLTextAreaElement.h>
#include <LibWeb/HTML/HTMLTitleElement.h>
#include <LibWeb/HTML/HTMLVideoElement.h>
@@ -292,6 +301,11 @@
namespace Web::DOM {
+struct Document::AccessibilityRecordCache {
+ AK_ALLOC_WITH_KMALLOC;
+ HashMap<UniqueNodeID, WebView::AccessibilityNodeData> records;
+};
+
static CSS::ComputedValuesFFI::FfiUtf16View ffi_utf16_view(Utf16View view)
{
return {
@@ -2177,6 +2191,9 @@ void Document::set_id(HTML::CrossProcessId id)
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#set-the-url
void Document::set_url(URL::URL const& url)
{
+ // Link URLs resolve against the document's URL.
+ if (m_accessibility_record_cache)
+ m_accessibility_record_cache->records.clear();
// OPTIMIZATION: Avoid unnecessary work if the URL is already set.
if (m_url == url)
return;
@@ -7330,13 +7347,60 @@ void Document::cache_accessible_text(Element const& element, CachedAccessibleTex
m_cached_accessible_text_depending_on_any_node.set(id);
}
-void Document::invalidate_cached_accessible_text(Node const& node, Optional<Utf16FlyString> const& attribute_name, ReadonlySpan<GC::Ref<Node>> added_nodes, ReadonlySpan<GC::Ref<Node>> removed_nodes)
+WebView::AccessibilityNodeData const* Document::cached_accessibility_record(Node const& node) const
+{
+ if (!m_accessibility_record_cache || m_accessibility_caches_bypassed)
+ return nullptr;
+ return m_accessibility_record_cache->records.get(node.unique_id()).map([](auto& record) { return &record; }).value_or(nullptr);
+}
+
+void Document::cache_accessibility_record(Node const& node, WebView::AccessibilityNodeData const& record) const
+{
+ if (m_accessibility_caches_bypassed)
+ return;
+ if (!m_accessibility_record_cache)
+ m_accessibility_record_cache = make<AccessibilityRecordCache>();
+ // Leave out what every build computes again anyway, so it isn't kept, and copied out, for nothing.
+ auto kept = record;
+ kept.bounds = {};
+ kept.is_focused = false;
+ kept.character_offsets.clear();
+ kept.line_break_character_offsets.clear();
+ kept.line_heights.clear();
+ m_accessibility_record_cache->records.set(node.unique_id(), move(kept));
+}
+
+static bool is_table_structure(Element const& element)
{
- if (m_cached_accessible_text.is_empty())
+ return is<HTML::HTMLTableElement>(element) || is<HTML::HTMLTableSectionElement>(element)
+ || is<HTML::HTMLTableRowElement>(element) || is<HTML::HTMLTableCellElement>(element)
+ || is<HTML::HTMLTableCaptionElement>(element) || is<HTML::HTMLTableColElement>(element);
+}
+
+void Document::invalidate_cached_accessibility_data(Node const& node, Optional<Utf16FlyString> const& attribute_name, ReadonlySpan<GC::Ref<Node>> added_nodes, ReadonlySpan<GC::Ref<Node>> removed_nodes)
+{
+ auto* records = m_accessibility_record_cache ? &m_accessibility_record_cache->records : nullptr;
+ if (m_cached_accessible_text.is_empty() && (!records || records->is_empty()))
return;
+ auto drop_text_and_record = [&](UniqueNodeID id) {
+ m_cached_accessible_text.remove(id);
+ if (records)
+ records->remove(id);
+ };
+ auto drop_records_of_subtree = [&](Node const& root) {
+ if (!records || records->is_empty())
+ return;
+ const_cast<Node&>(root).for_each_shadow_including_inclusive_descendant([&](Node const& descendant) {
+ records->remove(descendant.unique_id());
+ return TraversalDecision::Continue;
+ });
+ };
auto touches_labels = false;
auto touches_referenced_ids = false;
+ auto touches_table_structure = false;
+ auto touches_base_url = false;
+ auto touches_legend = false;
auto note_element = [&](Element const& element) {
if (is<HTML::HTMLLabelElement>(element))
touches_labels = true;
@@ -7344,13 +7408,19 @@ void Document::invalidate_cached_accessible_text(Node const& node, Optional<Utf1
touches_labels = true;
if (auto const& id = element.id(); id.has_value() && m_ids_referenced_by_cached_accessible_text.contains(*id))
touches_referenced_ids = true;
+ if (is_table_structure(element))
+ touches_table_structure = true;
+ if (is<HTML::HTMLBaseElement>(element))
+ touches_base_url = true;
+ if (is<HTML::HTMLLegendElement>(element))
+ touches_legend = true;
};
// An element's name can come from its content, so a change to a node can change the name of every element that
// contains it, across shadow roots too. And so can the names that come from the label elements and the elements
// referenced by ID that contain it.
for (auto const* ancestor = &node; ancestor; ancestor = ancestor->parent_or_shadow_host()) {
- m_cached_accessible_text.remove(ancestor->unique_id());
+ drop_text_and_record(ancestor->unique_id());
if (auto const* element = as_if<Element>(*ancestor)) {
if (is<HTML::HTMLLabelElement>(*element))
touches_labels = true;
@@ -7359,10 +7429,28 @@ void Document::invalidate_cached_accessible_text(Node const& node, Optional<Utf1
}
}
- // Changing an ID or a label's for attribute can change which element a label or a reference goes to.
- if (attribute_name.has_value() && (*attribute_name == HTML::AttributeNames::id || *attribute_name == HTML::AttributeNames::for_)) {
- touches_labels = true;
- touches_referenced_ids = true;
+ if (attribute_name.has_value()) {
+ // Changing an ID or a label's for attribute can change which element a label or a reference goes to.
+ if (*attribute_name == HTML::AttributeNames::id || *attribute_name == HTML::AttributeNames::for_) {
+ touches_labels = true;
+ touches_referenced_ids = true;
+ }
+ // Some of an element's attributes can change the data of its descendants too: their roles (which can follow
+ // the element's role, and its name), whether they're disabled, whether they're editable, and a details
+ // element's summary's expanded state.
+ auto const& name = *attribute_name;
+ auto reaches_descendants = name == ARIA::AttributeNames::role || name == HTML::AttributeNames::disabled
+ || name == HTML::AttributeNames::contenteditable || name == ARIA::AttributeNames::aria_label
+ || name == ARIA::AttributeNames::aria_labelled_by || name == HTML::AttributeNames::title
+ || name == HTML::AttributeNames::open || name == HTML::AttributeNames::inert;
+ if (reaches_descendants)
+ drop_records_of_subtree(node);
+ if (*attribute_name == HTML::AttributeNames::colspan || *attribute_name == HTML::AttributeNames::rowspan
+ || *attribute_name == HTML::AttributeNames::headers || *attribute_name == HTML::AttributeNames::scope
+ || *attribute_name == HTML::AttributeNames::span)
+ touches_table_structure = true;
+ if (is<HTML::HTMLBaseElement>(node) && *attribute_name == HTML::AttributeNames::href)
+ touches_base_url = true;
}
// And so can inserting or removing a label, a labelable element, or an element with a referenced ID.
@@ -7374,9 +7462,9 @@ void Document::invalidate_cached_accessible_text(Node const& node, Optional<Utf1
});
}
for (auto const& removed : removed_nodes) {
- // The text of a removed node is never asked for again (until it's inserted somewhere, as if new), so drop it.
+ // The data of a removed node is never asked for again (until it's inserted somewhere, as if new), so drop it.
removed->for_each_shadow_including_inclusive_descendant([&](Node const& descendant) {
- m_cached_accessible_text.remove(descendant.unique_id());
+ drop_text_and_record(descendant.unique_id());
m_cached_accessible_text_depending_on_labels.remove(descendant.unique_id());
m_cached_accessible_text_depending_on_referenced_ids.remove(descendant.unique_id());
m_cached_accessible_text_depending_on_any_node.remove(descendant.unique_id());
@@ -7386,9 +7474,14 @@ void Document::invalidate_cached_accessible_text(Node const& node, Optional<Utf1
});
}
+ // A dependent element's name can decide its role (a region needs one), and its descendants' roles can follow its
+ // role (a header inside a region isn't a banner), so their records go too.
auto drop = [&](HashTable<UniqueNodeID>& ids) {
- for (auto id : ids)
- m_cached_accessible_text.remove(id);
+ for (auto id : ids) {
+ drop_text_and_record(id);
+ if (auto* dependent = Node::from_unique_id(id))
+ drop_records_of_subtree(*dependent);
+ }
ids.clear();
};
if (touches_labels)
@@ -7398,6 +7491,88 @@ void Document::invalidate_cached_accessible_text(Node const& node, Optional<Utf1
m_ids_referenced_by_cached_accessible_text.clear();
}
drop(m_cached_accessible_text_depending_on_any_node);
+
+ // A cell's place in its table, and the headers it reports, come from the rows and cells around it.
+ if (touches_table_structure) {
+ for (auto const* ancestor = &node; ancestor; ancestor = ancestor->parent()) {
+ if (is<HTML::HTMLTableElement>(*ancestor)) {
+ drop_records_of_subtree(*ancestor);
+ break;
+ }
+ }
+ }
+
+ // Whether a fieldset disables a control can depend on which of its legends is first.
+ if (touches_legend) {
+ for (auto const* ancestor = &node; ancestor; ancestor = ancestor->parent()) {
+ if (is<HTML::HTMLFieldSetElement>(*ancestor)) {
+ drop_records_of_subtree(*ancestor);
+ break;
+ }
+ }
+ }
+
+ // Link URLs resolve against the document's base URL.
+ if (touches_base_url && records)
+ records->clear();
+}
+
+void Document::invalidate_cached_accessibility_records_after_style_change(Element const& element)
+{
+ if (!m_accessibility_record_cache)
+ return;
+ auto& records = m_accessibility_record_cache->records;
+
+ // A style change can change the states an element reports (the ones its style follows through pseudo-classes, like
+ // :checked), and the formatting its text reports.
+ records.remove(element.unique_id());
+ for (auto const* child = element.first_child(); child; child = child->next_sibling()) {
+ if (child->is_text())
+ records.remove(child->unique_id());
+ }
+
+ // And an element in a shadow tree can be part of how its host presents its value (a range input's slider, e.g.).
+ for (auto const* shadow_root = as_if<ShadowRoot>(element.root()); shadow_root && shadow_root->host(); shadow_root = as_if<ShadowRoot>(shadow_root->host()->root()))
+ records.remove(shadow_root->host()->unique_id());
+}
+
+Vector<String> Document::cached_accessibility_record_mismatches()
+{
+ update_layout(UpdateLayoutReason::InspectAccessibilityTree);
+ if (!m_accessibility_record_cache)
+ return {};
+
+ // Leave out what every build computes again anyway.
+ auto kept_part = [](WebView::AccessibilityNodeData data) {
+ data.parent_id = -1;
+ data.child_ids.clear();
+ data.bounds = {};
+ data.is_focused = false;
+ data.character_offsets.clear();
+ data.line_break_character_offsets.clear();
+ data.line_heights.clear();
+ data.caret_offset = -1;
+ data.selection_start = -1;
+ data.selection_end = -1;
+ return data;
+ };
+
+ m_accessibility_caches_bypassed = true;
+ auto fresh = build_accessibility_node_data();
+ m_accessibility_caches_bypassed = false;
+
+ Vector<String> mismatches;
+ for (auto const& data : fresh) {
+ auto cached = m_accessibility_record_cache->records.get(UniqueNodeID { data.id });
+ if (!cached.has_value() || kept_part(*cached) == kept_part(data))
+ continue;
+ auto* node = Node::from_unique_id(UniqueNodeID { data.id });
+ auto const* element = as_if<Element>(node);
+ mismatches.append(MUST(String::formatted("{} \"{}\" (role {}): the kept data differs from computing it again",
+ element ? element->local_name().to_utf16_string().to_utf8() : "#text"_string, data.name, data.role)));
+ }
+ quick_sort(mismatches);
+ return mismatches;
}
Vector<String> Document::cached_accessible_text_mismatches()
@@ -10154,6 +10329,10 @@ void Document::set_design_mode_enabled_state(bool design_mode_enabled)
if (m_design_mode_enabled == design_mode_enabled)
return;
+ // Design mode makes the whole document editable.
+ if (m_accessibility_record_cache)
+ m_accessibility_record_cache->records.clear();
+
struct PreviousReadWriteState {
GC::Ptr<Element> element;
bool value;
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index d7f57ddd08f..e4017c20591 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -1261,7 +1261,17 @@ public:
};
CachedAccessibleText const* cached_accessible_text(Element const&) const;
void cache_accessible_text(Element const&, CachedAccessibleText) const;
- void invalidate_cached_accessible_text(Node const&, Optional<Utf16FlyString> const& attribute_name = {}, ReadonlySpan<GC::Ref<Node>> added_nodes = {}, ReadonlySpan<GC::Ref<Node>> removed_nodes = {});
+ void invalidate_cached_accessibility_data(Node const&, Optional<Utf16FlyString> const& attribute_name = {}, ReadonlySpan<GC::Ref<Node>> added_nodes = {}, ReadonlySpan<GC::Ref<Node>> removed_nodes = {});
+
+ // What a build of the accessibility tree keeps of each node's data for the next build, while an assistive
+ // technology consumes the tree; see AccessibilityTreeNode::serialize_tree_as_node_data().
+ WebView::AccessibilityNodeData const* cached_accessibility_record(Node const&) const;
+ void cache_accessibility_record(Node const&, WebView::AccessibilityNodeData const&) const;
+ void invalidate_cached_accessibility_records_after_style_change(Element const&);
+ // For tests: builds that compute every node's data again, without what earlier builds kept.
+ bool accessibility_caches_bypassed() const { return m_accessibility_caches_bypassed; }
+ // For tests: each node whose kept data differs from what computing it again gives.
+ Vector<String> cached_accessibility_record_mismatches();
size_t cached_accessible_text_count() const { return m_cached_accessible_text.size(); }
// For tests: each cached name or description that differs from what computing it again gives.
Vector<String> cached_accessible_text_mismatches();
@@ -2053,6 +2063,9 @@ private:
mutable HashTable<UniqueNodeID> m_cached_accessible_text_depending_on_referenced_ids;
mutable HashTable<UniqueNodeID> m_cached_accessible_text_depending_on_any_node;
mutable HashTable<Utf16FlyString> m_ids_referenced_by_cached_accessible_text;
+ struct AccessibilityRecordCache;
+ mutable OwnPtr<AccessibilityRecordCache> m_accessibility_record_cache;
+ bool m_accessibility_caches_bypassed { false };
// https://html.spec.whatwg.org/multipage/interaction.html#autofocus-candidates
Vector<GC::Ref<Element>> m_autofocus_candidates;
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 36278170816..3a724296f41 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -1956,6 +1956,9 @@ void Element::swap_in_style_record(Layout::BegunRead const& read, Optional<CSS::
++m_animation_style_generation;
VERIFY(record);
m_installed_style = CSS::InstalledStyle { record };
+ // A new style can change the states and the text formatting the accessibility tree reports for the element.
+ if (document().page().accessibility_interested())
+ document().invalidate_cached_accessibility_records_after_style_change(*this);
auto const style_record = m_installed_style.record();
// NB: The render side installed the record in a box it styles itself, which the box adopts.
if (auto* layout_node = unsafe_layout_node(read))
@@ -2059,7 +2062,7 @@ void Element::apply_style_main_effects(Layout::BegunRead const& read, CSS::MainE
// Content that isn't visible is left out of a name that comes from content.
auto visibility_changed = old_values && old_values->visibility() != new_computed_values->visibility();
if ((invalidation.needs_relayout() || visibility_changed) && document().page().accessibility_interested())
- document().invalidate_cached_accessible_text(*this);
+ document().invalidate_cached_accessibility_data(*this);
// The environment the record was published with: what the element inherits, or what the engine resolved its own
// custom declarations to over that, and those of the pseudo-elements over the element's.
@@ -5370,6 +5373,10 @@ void Element::replace_installed_style(Layout::BegunRead const& read, CSS::Instal
if (m_installed_style.record() == style_record_identity)
return;
auto held_before = exchange(m_installed_style, move(style));
+ // Every new style, an animation's included, can change the states and the text formatting the accessibility tree
+ // reports for the element.
+ if (document().page().accessibility_interested())
+ document().invalidate_cached_accessibility_records_after_style_change(*this);
// The element holds the record it installed before until the engine takes the new one in, so the layout node reads
// what it moves from, and everything below that compares against the old record is read from it, before the
// element lets go of it. The engine keeps the old record until it takes the new one in.
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 9d5d6624717..38b1d6f5c54 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -4124,7 +4124,7 @@ void Node::queue_mutation_record(Utf16FlyString const& type, Optional<Utf16FlySt
// assistive technology is consuming it. This is independent of DevTools' mutation listener and of whether any
// MutationObserver is registered, so it runs before the observer-only bails below.
if (page.accessibility_interested()) {
- document.invalidate_cached_accessible_text(*this, attribute_name, added_nodes, removed_nodes);
+ document.invalidate_cached_accessibility_data(*this, attribute_name, added_nodes, removed_nodes);
page.client().page_did_change_accessibility_tree();
}
diff --git a/Libraries/LibWeb/HTML/ElementInternals.cpp b/Libraries/LibWeb/HTML/ElementInternals.cpp
index 0975f7ac858..40ee1e0845d 100644
--- a/Libraries/LibWeb/HTML/ElementInternals.cpp
+++ b/Libraries/LibWeb/HTML/ElementInternals.cpp
@@ -305,8 +305,11 @@ void ElementInternals::remove_attribute(Utf16FlyString const& content_attribute)
void ElementInternals::did_change_default_aria_semantics()
{
auto& page = m_target_element->document().page();
- if (page.accessibility_interested())
+ if (page.accessibility_interested()) {
+ // Default ARIA semantics can change the element's role, and so its descendants' roles, as its role attribute can.
+ m_target_element->document().invalidate_cached_accessibility_data(*m_target_element, ARIA::AttributeNames::role);
page.client().page_did_change_accessibility_tree();
+ }
}
#define __ENUMERATE_ARIA_ATTRIBUTE(name, attribute) \
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index abc22663b2f..61ee3bcaa45 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -213,6 +213,9 @@ void HTMLInputElement::set_checked(bool checked)
return;
m_checked = checked;
+ // The accessibility tree reports this state, with nothing else about the element changing.
+ if (document().page().accessibility_interested())
+ document().invalidate_cached_accessibility_data(*this);
CSS::Invalidation::invalidate_style_after_checked_state_change(*this);
@@ -258,6 +261,9 @@ void HTMLInputElement::set_indeterminate(bool value)
return;
m_indeterminateness = value;
CSS::Invalidation::invalidate_style_after_indeterminate_state_change(*this, value);
+ // The accessibility tree reports this state, with nothing else about the element changing.
+ if (document().page().accessibility_interested())
+ document().invalidate_cached_accessibility_data(*this);
Painting::push_form_control_paint_facts(*this);
set_needs_repaint(InvalidateDisplayList::PaintCommands);
}
diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
index 620b09c6762..e33494f93c4 100644
--- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
@@ -23,6 +23,7 @@
#include <LibWeb/HTML/TagNames.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Namespace.h>
+#include <LibWeb/Page/Page.h>
#include <LibWeb/SVG/SVGScriptElement.h>
#include <LibWebCommon/Infra/Strings.h>
@@ -163,6 +164,9 @@ void HTMLOptionElement::set_selected_internal(bool selected)
{
if (m_selected != selected) {
CSS::Invalidation::invalidate_style_after_option_selected_state_change(*this, selected);
+ // The accessibility tree reports this state, with nothing else about the element changing.
+ if (document().page().accessibility_interested())
+ document().invalidate_cached_accessibility_data(*this);
document().bump_option_selectedness_version();
if (m_cached_nearest_select_element) {
if (selected)
diff --git a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp
index 2655210694c..c845e0fee15 100644
--- a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp
@@ -9,10 +9,12 @@
#include <LibGC/ConservativeHashTable.h>
#include <LibGC/RootVector.h>
#include <LibWeb/Bindings/HTMLSlotElement.h>
+#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/HTMLSlotElement.h>
+#include <LibWeb/Page/Page.h>
namespace Web::HTML {
@@ -116,6 +118,10 @@ void HTMLSlotElement::assign(GC::ConservativeVector<SlottableHandle> nodes)
// AD-HOC: Assigned nodes are recomputed lazily.
assign_slottables_if_needed();
+ // A name that comes from content can come from the nodes assigned to a slot.
+ if (document().page().accessibility_interested())
+ document().invalidate_cached_accessibility_data(*this);
+
// 1. For each node of this's manually assigned nodes, set node's manual slot assignment to null.
for (auto& node : m_manually_assigned_nodes) {
node.visit([&](auto& node) {
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index bc425c5cbdd..984dd3771e4 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2077,6 +2077,14 @@ String Internals::accessibility_cached_text_mismatches()
return builder.to_string_without_validation();
}
+String Internals::accessibility_cached_record_mismatches()
+{
+ StringBuilder builder;
+ for (auto const& mismatch : window().associated_document().cached_accessibility_record_mismatches())
+ builder.appendff("{}\n", mismatch);
+ return builder.to_string_without_validation();
+}
+
Utf16String Internals::dump_layout_tree(GC::Ref<DOM::Node> node)
{
// The test API's read of the render state of the node's document.
diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h
index 6abf0a54403..e99a68f0f57 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -229,6 +229,7 @@ public:
String accessibility_character_offsets(GC::Ref<DOM::Node>);
String dump_accessibility_node_data(GC::Ref<DOM::Node>);
String accessibility_cached_text_mismatches();
+ String accessibility_cached_record_mismatches();
Utf16String dump_layout_tree(GC::Ref<DOM::Node>);
Utf16String dump_stacking_context_tree();
Utf16String stacking_context_structure_verification_report();
diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl
index 638e9a08ade..976c778628e 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -234,6 +234,9 @@ interface Internals {
// Each accessible name or description kept between builds of the accessibility tree that differs from what
// computing it again gives, one per line. Empty when every one is current.
DOMString accessibilityCachedTextMismatches();
+ // Each node whose accessibility data kept between builds of the tree differs from what computing it again gives,
+ // one per line. Empty when all of it is current.
+ DOMString accessibilityCachedRecordMismatches();
DOMString dumpLayoutTree(Node node);
DOMString dumpStackingContextTree();
DOMString stackingContextStructureVerificationReport();
diff --git a/Libraries/LibWebCommon/WebView/AccessibilityNodeData.h b/Libraries/LibWebCommon/WebView/AccessibilityNodeData.h
index 84afe948b1a..2faf848e87d 100644
--- a/Libraries/LibWebCommon/WebView/AccessibilityNodeData.h
+++ b/Libraries/LibWebCommon/WebView/AccessibilityNodeData.h
@@ -140,6 +140,8 @@ struct WEBCOMMON_API AccessibilityNodeData {
// Per-line height in CSS pixels (index matches line_break_character_offsets). Used to compute vertical extent of
// per-character rectangles for wrapping text.
Vector<i32> line_heights;
+
+ bool operator==(AccessibilityNodeData const&) const = default;
};
}
diff --git a/Tests/LibWeb/Text/expected/accessibility-node-data-indirect.txt b/Tests/LibWeb/Text/expected/accessibility-node-data-indirect.txt
new file mode 100644
index 00000000000..ded60bf9c91
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/accessibility-node-data-indirect.txt
@@ -0,0 +1,146 @@
+== initial
+n0 generic bounds=8,8 784x191
+ n1 alert bounds=8,10 124x16 live=assertive
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=140,10 93x16
+ n4 text leaf name="region label" bounds=140,10 93x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 17,0 25,0 29,0 40,0 49,0 57,0 61,0 71,0 80,0 89,0 lines=0@16
+ n5 region name="region label" bounds=8,28 784x20
+ n6 sectionheader bounds=8,28 784x20
+ n7 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n8 group bounds=10,48 780x43 disabled
+ n9 checkbox bounds=30,58 13x13 disabled checked=false
+ n10 paragraph bounds=8,107 784x20
+ n11 text leaf name="becomes editable" bounds=8,109 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n12 paragraph bounds=8,143 784x20
+ n13 text leaf name="animated color" bounds=8,145 119x16 font="SerenitySans" 16 400 normal color=#ff0000 characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n14 button name="first slotted" bounds=8,179 784x20
+ n15 text leaf name="first slotted" bounds=8,181 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n16 text leaf name="second slotted" bounds=8,179 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== ElementInternals role
+n0 generic bounds=8,8 784x191
+ n1 status bounds=8,10 124x16 live=polite
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=140,10 93x16
+ n4 text leaf name="region label" bounds=140,10 93x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 17,0 25,0 29,0 40,0 49,0 57,0 61,0 71,0 80,0 89,0 lines=0@16
+ n5 region name="region label" bounds=8,28 784x20
+ n6 sectionheader bounds=8,28 784x20
+ n7 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n8 group bounds=10,48 780x43 disabled
+ n9 checkbox bounds=30,58 13x13 disabled checked=false
+ n10 paragraph bounds=8,107 784x20
+ n11 text leaf name="becomes editable" bounds=8,109 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n12 paragraph bounds=8,143 784x20
+ n13 text leaf name="animated color" bounds=8,145 119x16 font="SerenitySans" 16 400 normal color=#ff0000 characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n14 button name="first slotted" bounds=8,179 784x20
+ n15 text leaf name="first slotted" bounds=8,181 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n16 text leaf name="second slotted" bounds=8,179 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== region label emptied
+n0 generic bounds=8,8 784x191
+ n1 status bounds=8,10 124x16 live=polite
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=8,8 0x20
+ n4 generic bounds=8,28 784x20
+ n5 banner bounds=8,28 784x20
+ n6 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n7 group bounds=10,48 780x43 disabled
+ n8 checkbox bounds=30,58 13x13 disabled checked=false
+ n9 paragraph bounds=8,107 784x20
+ n10 text leaf name="becomes editable" bounds=8,109 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n11 paragraph bounds=8,143 784x20
+ n12 text leaf name="animated color" bounds=8,145 119x16 font="SerenitySans" 16 400 normal color=#ff0000 characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n13 button name="first slotted" bounds=8,179 784x20
+ n14 text leaf name="first slotted" bounds=8,181 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n15 text leaf name="second slotted" bounds=8,179 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== first legend removed
+n0 generic bounds=8,8 784x189
+ n1 status bounds=8,10 124x16 live=polite
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=8,8 0x20
+ n4 generic bounds=8,28 784x20
+ n5 banner bounds=8,28 784x20
+ n6 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n7 group bounds=10,48 780x41 disabled
+ n8 checkbox bounds=30,51 13x13 checked=false
+ n9 paragraph bounds=8,105 784x20
+ n10 text leaf name="becomes editable" bounds=8,107 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n11 paragraph bounds=8,141 784x20
+ n12 text leaf name="animated color" bounds=8,143 119x16 font="SerenitySans" 16 400 normal color=#ff0000 characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n13 button name="first slotted" bounds=8,177 784x20
+ n14 text leaf name="first slotted" bounds=8,179 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n15 text leaf name="second slotted" bounds=8,177 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== design mode on
+n0 generic bounds=8,8 784x189 editable multi_line
+ n1 status bounds=8,10 124x16 live=polite editable multi_line
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=8,8 0x20 editable multi_line
+ n4 generic bounds=8,28 784x20 editable multi_line
+ n5 banner bounds=8,28 784x20 editable multi_line
+ n6 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n7 group bounds=10,48 780x41 disabled multi_line
+ n8 checkbox bounds=30,51 13x13 checked=false
+ n9 paragraph bounds=8,105 784x20 editable multi_line
+ n10 text leaf name="becomes editable" bounds=8,107 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n11 paragraph bounds=8,141 784x20 editable multi_line
+ n12 text leaf name="animated color" bounds=8,143 119x16 font="SerenitySans" 16 400 normal color=#ff0000 characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n13 button name="first slotted" bounds=8,177 784x20 editable multi_line
+ n14 text leaf name="first slotted" bounds=8,179 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n15 text leaf name="second slotted" bounds=8,177 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== design mode off
+n0 generic bounds=8,8 784x189
+ n1 status bounds=8,10 124x16 live=polite
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=8,8 0x20
+ n4 generic bounds=8,28 784x20
+ n5 banner bounds=8,28 784x20
+ n6 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n7 group bounds=10,48 780x41 disabled
+ n8 checkbox bounds=30,51 13x13 checked=false
+ n9 paragraph bounds=8,105 784x20
+ n10 text leaf name="becomes editable" bounds=8,107 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n11 paragraph bounds=8,141 784x20
+ n12 text leaf name="animated color" bounds=8,143 119x16 font="SerenitySans" 16 400 normal color=#ff0000 characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n13 button name="first slotted" bounds=8,177 784x20
+ n14 text leaf name="first slotted" bounds=8,179 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n15 text leaf name="second slotted" bounds=8,177 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== animated color sampled later
+n0 generic bounds=8,8 784x189
+ n1 status bounds=8,10 124x16 live=polite
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=8,8 0x20
+ n4 generic bounds=8,28 784x20
+ n5 banner bounds=8,28 784x20
+ n6 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n7 group bounds=10,48 780x41 disabled
+ n8 checkbox bounds=30,51 13x13 checked=false
+ n9 paragraph bounds=8,105 784x20
+ n10 text leaf name="becomes editable" bounds=8,107 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n11 paragraph bounds=8,141 784x20
+ n12 text leaf name="animated color" bounds=8,143 119x16 font="SerenitySans" 16 400 normal color=#0000ff characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n13 button name="first slotted" bounds=8,177 784x20
+ n14 text leaf name="first slotted" bounds=8,179 98x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@16
+ n15 text leaf name="second slotted" bounds=8,177 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@20
+
+== manual slot assignment
+n0 generic bounds=8,8 784x189
+ n1 status bounds=8,10 124x16 live=polite
+ n2 text leaf name="custom element" bounds=8,10 124x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 8,0 18,0 28,0 34,0 45,0 57,0 65,0 74,0 78,0 87,0 99,0 108,0 117,0 lines=0@16
+ n3 generic bounds=8,8 0x20
+ n4 generic bounds=8,28 784x20
+ n5 banner bounds=8,28 784x20
+ n6 text leaf name="section header" bounds=8,30 119x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 33,0 38,0 48,0 58,0 66,0 75,0 84,0 93,0 101,0 110,0 lines=0@16
+ n7 group bounds=10,48 780x41 disabled
+ n8 checkbox bounds=30,51 13x13 checked=false
+ n9 paragraph bounds=8,105 784x20
+ n10 text leaf name="becomes editable" bounds=8,107 135x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 27,0 37,0 49,0 58,0 67,0 75,0 84,0 92,0 96,0 103,0 113,0 122,0 126,0 lines=0@16
+ n11 paragraph bounds=8,141 784x20
+ n12 text leaf name="animated color" bounds=8,143 119x16 font="SerenitySans" 16 400 normal color=#0000ff characters=0,0 9,0 18,0 23,0 35,0 45,0 51,0 60,0 68,0 76,0 85,0 95,0 99,0 110,0 lines=0@16
+ n13 button name="second slotted" bounds=8,177 784x20
+ n14 text leaf name="first slotted" bounds=8,177 784x20 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 6,0 11,0 19,0 29,0 36,0 44,0 53,0 57,0 67,0 74,0 81,0 90,0 lines=0@20
+ n15 text leaf name="second slotted" bounds=8,179 117x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 37,0 46,0 54,0 62,0 72,0 76,0 86,0 93,0 100,0 109,0 lines=0@16
+
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html b/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html
new file mode 100644
index 00000000000..7c5a38d6253
--- /dev/null
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body {
+ font: 16px/20px SerenitySans;
+ }
+</style>
+<!-- After each change that reaches a node's accessibility data without touching the node itself, the data reflects it:
+ a custom element's default ARIA semantics, an ancestor whose role follows from its name, a fieldset's first legend,
+ design mode, an animated color, and a manual slot assignment. -->
+<div id="root">
+ <custom-status id="custom">custom element</custom-status>
+ <span id="region-label">region label</span>
+ <div role="region" aria-labelledby="region-label"><header>section header</header></div>
+ <fieldset disabled>
+ <legend id="first-legend"></legend>
+ <legend><input type="checkbox" id="in-second-legend"></legend>
+ </fieldset>
+ <p id="editable">becomes editable</p>
+ <p id="animated">animated color</p>
+ <div role="button" id="slot-host"></div>
+</div>
+<script>
+ class CustomStatus extends HTMLElement {
+ constructor() {
+ super();
+ this.internals = this.attachInternals();
+ this.internals.role = "alert";
+ }
+ }
+ customElements.define("custom-status", CustomStatus);
+
+ test(() => {
+ internals.setAccessibilityInterested();
+ const root = document.getElementById("root");
+ const step = (label, change) => {
+ change();
+ // Printing adds to the DOM, so read everything before printing anything.
+ const dump = internals.dumpAccessibilityNodeData(root);
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
+ println(`== ${label}`);
+ println(dump);
+ if (stale)
+ println(`stale cached data:\n${stale}`);
+ };
+
+ const host = document.getElementById("slot-host");
+ const shadow = host.attachShadow({ mode: "open", slotAssignment: "manual" });
+ const slot = document.createElement("slot");
+ shadow.append(slot);
+ const firstText = document.createTextNode("first slotted");
+ const secondText = document.createTextNode("second slotted");
+ host.append(firstText, secondText);
+ slot.assign(firstText);
+
+ const animation = document.getElementById("animated").animate({ color: ["rgb(255, 0, 0)", "rgb(0, 0, 255)"] }, 1000);
+ animation.pause();
+ animation.currentTime = 0;
+
+ step("initial", () => {});
+ step("ElementInternals role", () => document.getElementById("custom").internals.role = "status");
+ step("region label emptied", () => document.getElementById("region-label").textContent = "");
+ step("first legend removed", () => document.getElementById("first-legend").remove());
+ step("design mode on", () => document.designMode = "on");
+ step("design mode off", () => document.designMode = "off");
+ step("animated color sampled later", () => animation.currentTime = 999);
+ step("manual slot assignment", () => slot.assign(secondText));
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-names.html b/Tests/LibWeb/Text/input/accessibility-node-data-names.html
index 91c7f5d19f1..9fe92ce9223 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-names.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-names.html
@@ -38,11 +38,13 @@
const root = document.getElementById("root");
const step = (label, change) => {
change();
+ // Printing adds to the DOM, so read everything before printing anything.
+ const dump = internals.dumpAccessibilityNodeData(root);
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
println(`== ${label}`);
- println(internals.dumpAccessibilityNodeData(root));
- const stale = internals.accessibilityCachedTextMismatches();
+ println(dump);
if (stale)
- println(`stale cached text:\n${stale}`);
+ println(`stale cached data:\n${stale}`);
};
step("initial", () => {});
step("cell textContent", () => document.getElementById("cell").textContent = "new cell text");
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-states.html b/Tests/LibWeb/Text/input/accessibility-node-data-states.html
index 7bfdd2a8b06..eb87d24a12d 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-states.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-states.html
@@ -22,11 +22,13 @@
const root = document.getElementById("root");
const step = (label, change) => {
change();
+ // Printing adds to the DOM, so read everything before printing anything.
+ const dump = internals.dumpAccessibilityNodeData(root);
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
println(`== ${label}`);
- println(internals.dumpAccessibilityNodeData(root));
- const stale = internals.accessibilityCachedTextMismatches();
+ println(dump);
if (stale)
- println(`stale cached text:\n${stale}`);
+ println(`stale cached data:\n${stale}`);
};
step("initial", () => {});
step("value property", () => document.getElementById("text-field").value = "typed value");
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-structure.html b/Tests/LibWeb/Text/input/accessibility-node-data-structure.html
index b29a3e15f3e..54a46587a81 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-structure.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-structure.html
@@ -24,11 +24,13 @@
const toggled = document.getElementById("toggled");
const step = (label, change) => {
change();
+ // Printing adds to the DOM, so read everything before printing anything.
+ const dump = internals.dumpAccessibilityNodeData(root);
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
println(`== ${label}`);
- println(internals.dumpAccessibilityNodeData(root));
- const stale = internals.accessibilityCachedTextMismatches();
+ println(dump);
if (stale)
- println(`stale cached text:\n${stale}`);
+ println(`stale cached data:\n${stale}`);
};
step("initial", () => {});
step("insert a list item", () => {
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-tables-and-geometry.html b/Tests/LibWeb/Text/input/accessibility-node-data-tables-and-geometry.html
index e67f233e986..5133427a384 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-tables-and-geometry.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-tables-and-geometry.html
@@ -26,11 +26,13 @@
const root = document.getElementById("root");
const step = (label, change) => {
change();
+ // Printing adds to the DOM, so read everything before printing anything.
+ const dump = internals.dumpAccessibilityNodeData(root);
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
println(`== ${label}`);
- println(internals.dumpAccessibilityNodeData(root));
- const stale = internals.accessibilityCachedTextMismatches();
+ println(dump);
if (stale)
- println(`stale cached text:\n${stale}`);
+ println(`stale cached data:\n${stale}`);
};
step("initial", () => {});
step("row added", () => {