Skip to content

Truly independent web browser

LibWeb: Keep text geometry between accessibility-tree builds

sideshowbarkere60c1883c8fc
diff --git a/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp b/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp
index e226fe2205a..eba9340f80f 100644
--- a/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp
+++ b/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp
@@ -238,7 +238,8 @@ Document::CachedAccessibleText AccessibilityTreeNode::compute_accessible_text(El
// 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)
+// Returns whether the geometry came from the lines layout rendered the text on, rather than from font metrics alone.
+static bool fill_text_geometry(WebView::AccessibilityNodeData& node_data, DOM::Text const& text_node, Gfx::Font const* font, Document const& document, Layout::BegunRead const& read)
{
// 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
@@ -378,7 +379,9 @@ static void fill_text_geometry(WebView::AccessibilityNodeData& node_data, DOM::T
// 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) {
+ return true;
+ }
+ 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());
@@ -388,6 +391,21 @@ static void fill_text_geometry(WebView::AccessibilityNodeData& node_data, DOM::T
cumulative += glyph_advance(*font, code_point);
}
}
+ return false;
+}
+
+// What layout computes a text node's character geometry from, or nothing when that can't be told.
+static Optional<Document::CachedTextGeometry> text_geometry_sources(Layout::Node const& layout)
+{
+ Document::CachedTextGeometry geometry;
+ auto known = Layout::RustFFI::layout_script_text_geometry_sources(
+ layout.document_host(), Layout::Node::slot_id(&layout), &geometry,
+ [](void* context, void const* line_content, i32 x, i32 y) {
+ static_cast<Document::CachedTextGeometry*>(context)->sources.append({ line_content, x, y });
+ });
+ if (!known)
+ return {};
+ return geometry;
}
// The fields that can change with nothing changing in the node itself or its style: its bounds and text geometry,
@@ -417,7 +435,27 @@ static void fill_volatile_fields(WebView::AccessibilityNodeData& node_data, DOM:
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);
+
+ // Text geometry is the costliest part of a build, so keep it for as long as the lines it came from stay the same.
+ // Only its bounds are read again: They're viewport-relative, so scrolling moves them.
+ auto* text_layout = text_node->layout_node(read);
+ auto geometry = text_layout ? text_geometry_sources(*text_layout) : Optional<Document::CachedTextGeometry> {};
+ if (geometry.has_value()) {
+ if (auto const* kept = document.cached_text_geometry(*text_node); kept && kept->sources == geometry->sources) {
+ if (auto own_box = text_bounding_client_rect(document, *text_layout); own_box.has_value())
+ node_data.bounds = own_box->to_type<int>();
+ node_data.character_offsets = kept->character_offsets;
+ node_data.line_break_character_offsets = kept->line_break_character_offsets;
+ node_data.line_heights = kept->line_heights;
+ return;
+ }
+ }
+ if (!fill_text_geometry(node_data, *text_node, font, document, read) || !geometry.has_value())
+ return;
+ geometry->character_offsets = node_data.character_offsets;
+ geometry->line_break_character_offsets = node_data.line_break_character_offsets;
+ geometry->line_heights = node_data.line_heights;
+ document.cache_text_geometry(*text_node, geometry.release_value());
}
void AccessibilityTreeNode::serialize_tree_as_node_data(Vector<WebView::AccessibilityNodeData>& out, Document const& document, Layout::BegunRead const& read, i64 parent_id) const
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index c304fee0dba..28241362695 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -303,9 +303,37 @@ namespace Web::DOM {
struct Document::AccessibilityRecordCache {
AK_ALLOC_WITH_KMALLOC;
- HashMap<UniqueNodeID, WebView::AccessibilityNodeData> records;
+ struct Record {
+ WebView::AccessibilityNodeData data;
+ Optional<CachedTextGeometry> text_geometry;
+ };
+ HashMap<UniqueNodeID, Record> records;
};
+static void release_text_geometry_sources(Vector<Document::CachedTextGeometry::Source>& sources)
+{
+ for (auto const& source : sources)
+ Layout::RustFFI::layout_release_inline_content(source.line_content);
+ sources.clear();
+}
+
+Document::CachedTextGeometry& Document::CachedTextGeometry::operator=(CachedTextGeometry&& other)
+{
+ if (this == &other)
+ return *this;
+ release_text_geometry_sources(sources);
+ sources = move(other.sources);
+ character_offsets = move(other.character_offsets);
+ line_break_character_offsets = move(other.line_break_character_offsets);
+ line_heights = move(other.line_heights);
+ return *this;
+}
+
+Document::CachedTextGeometry::~CachedTextGeometry()
+{
+ release_text_geometry_sources(sources);
+}
+
static CSS::ComputedValuesFFI::FfiUtf16View ffi_utf16_view(Utf16View view)
{
return {
@@ -7367,7 +7395,8 @@ WebView::AccessibilityNodeData const* Document::cached_accessibility_record(Node
{
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);
+ auto it = m_accessibility_record_cache->records.find(node.unique_id());
+ return it == m_accessibility_record_cache->records.end() ? nullptr : &it->value.data;
}
void Document::cache_accessibility_record(Node const& node, WebView::AccessibilityNodeData const& record) const
@@ -7383,7 +7412,27 @@ void Document::cache_accessibility_record(Node const& node, WebView::Accessibili
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));
+ m_accessibility_record_cache->records.set(node.unique_id(), { move(kept), {} });
+}
+
+Document::CachedTextGeometry const* Document::cached_text_geometry(Node const& node) const
+{
+ if (!m_accessibility_record_cache || m_accessibility_caches_bypassed)
+ return nullptr;
+ auto it = m_accessibility_record_cache->records.find(node.unique_id());
+ if (it == m_accessibility_record_cache->records.end() || !it->value.text_geometry.has_value())
+ return nullptr;
+ return &*it->value.text_geometry;
+}
+
+void Document::cache_text_geometry(Node const& node, CachedTextGeometry geometry) const
+{
+ // The geometry goes with the node's record, so whatever drops the record drops the geometry too.
+ if (!m_accessibility_record_cache || m_accessibility_caches_bypassed)
+ return;
+ auto it = m_accessibility_record_cache->records.find(node.unique_id());
+ if (it != m_accessibility_record_cache->records.end())
+ it->value.text_geometry = move(geometry);
}
static bool is_table_structure(Element const& element)
@@ -7579,8 +7628,8 @@ Vector<String> Document::cached_accessibility_record_mismatches()
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))
+ auto cached = m_accessibility_record_cache->records.find(UniqueNodeID { data.id });
+ if (cached == m_accessibility_record_cache->records.end() || kept_part(cached->value.data) == kept_part(data))
continue;
auto* node = Node::from_unique_id(UniqueNodeID { data.id });
auto const* element = as_if<Element>(node);
@@ -7591,6 +7640,36 @@ Vector<String> Document::cached_accessibility_record_mismatches()
return mismatches;
}
+Vector<String> Document::cached_text_geometry_mismatches()
+{
+ update_layout(UpdateLayoutReason::InspectAccessibilityTree);
+ if (!m_accessibility_record_cache)
+ return {};
+
+ // A build that reuses the kept geometry wherever it's still good, against one that computes all of it again.
+ auto kept = build_accessibility_node_data();
+ m_accessibility_caches_bypassed = true;
+ auto fresh = build_accessibility_node_data();
+ m_accessibility_caches_bypassed = false;
+
+ HashMap<i64, WebView::AccessibilityNodeData const*> fresh_by_id;
+ for (auto const& data : fresh)
+ fresh_by_id.set(data.id, &data);
+ Vector<String> mismatches;
+ for (auto const& data : kept) {
+ auto fresh_data = fresh_by_id.get(data.id);
+ if (!fresh_data.has_value())
+ continue;
+ auto const& computed = **fresh_data;
+ if (data.bounds == computed.bounds && data.character_offsets == computed.character_offsets
+ && data.line_break_character_offsets == computed.line_break_character_offsets && data.line_heights == computed.line_heights)
+ continue;
+ mismatches.append(MUST(String::formatted("#text \"{}\": the kept geometry differs from computing it again", data.name)));
+ }
+ quick_sort(mismatches);
+ return mismatches;
+}
+
Vector<String> Document::cached_accessible_text_mismatches()
{
update_layout(UpdateLayoutReason::InspectAccessibilityTree);
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 91fa6639ece..996ed8b7084 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -28,6 +28,7 @@
#include <LibCore/Forward.h>
#include <LibCore/SharedVersion.h>
#include <LibGC/WeakHashSet.h>
+#include <LibGfx/Point.h>
#include <LibJS/Forward.h>
#include <LibURL/Origin.h>
#include <LibURL/URL.h>
@@ -1272,6 +1273,38 @@ public:
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&);
+
+ // A text node's character geometry, kept with its record from one build to the next along with what layout
+ // computed it from: The same line content at the same positions gives the same geometry, so it's computed again
+ // only when one of them changes.
+ struct CachedTextGeometry {
+ AK_MAKE_NONCOPYABLE(CachedTextGeometry);
+
+ public:
+ CachedTextGeometry() = default;
+ CachedTextGeometry(CachedTextGeometry&&) = default;
+ // Releases the references this held, before taking the other's.
+ CachedTextGeometry& operator=(CachedTextGeometry&&);
+ ~CachedTextGeometry();
+
+ // A containing block's line content, which each source holds a reference to, and that block's raw
+ // document-absolute position.
+ struct Source {
+ void const* line_content { nullptr };
+ i32 x { 0 };
+ i32 y { 0 };
+ bool operator==(Source const&) const = default;
+ };
+ Vector<Source> sources;
+ Vector<Gfx::IntPoint> character_offsets;
+ Vector<i32> line_break_character_offsets;
+ Vector<i32> line_heights;
+ };
+ CachedTextGeometry const* cached_text_geometry(Node const&) const;
+ void cache_text_geometry(Node const&, CachedTextGeometry) const;
+ // For tests: each text node whose kept geometry differs from what computing it again gives.
+ Vector<String> cached_text_geometry_mismatches();
+
// 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.
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 4918dd456c2..2cd46fdf4f7 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -2094,6 +2094,14 @@ String Internals::accessibility_cached_record_mismatches()
return builder.to_string_without_validation();
}
+String Internals::accessibility_cached_geometry_mismatches()
+{
+ StringBuilder builder;
+ for (auto const& mismatch : window().associated_document().cached_text_geometry_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 affb1f5b816..50ba035c930 100644
--- a/Libraries/LibWeb/Internals/Internals.h
+++ b/Libraries/LibWeb/Internals/Internals.h
@@ -231,6 +231,7 @@ public:
String dump_accessibility_node_data(GC::Ref<DOM::Node>);
String accessibility_cached_text_mismatches();
String accessibility_cached_record_mismatches();
+ String accessibility_cached_geometry_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 c8eb78ec829..3fe5eb4ecc5 100644
--- a/Libraries/LibWeb/Internals/Internals.idl
+++ b/Libraries/LibWeb/Internals/Internals.idl
@@ -239,6 +239,7 @@ interface Internals {
// 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 accessibilityCachedGeometryMismatches();
DOMString dumpLayoutTree(Node node);
DOMString dumpStackingContextTree();
DOMString stackingContextStructureVerificationReport();
diff --git a/Libraries/LibWeb/Rust/src/layout/script_entries.rs b/Libraries/LibWeb/Rust/src/layout/script_entries.rs
index c3fa02382de..07eba4bb95f 100644
--- a/Libraries/LibWeb/Rust/src/layout/script_entries.rs
+++ b/Libraries/LibWeb/Rust/src/layout/script_entries.rs
@@ -223,6 +223,63 @@ pub extern "C" fn layout_script_text_caret_rect_in_dom_range(
});
}
+/// Calls `push_source` with what the character geometry of the text node `primary` is computed from: for each of its
+/// layout nodes, a retained reference to its containing block's line content, and the raw document-absolute position
+/// of that block. The same references at the same positions mean the same geometry. The consumer owns every reference
+/// pushed, and releases each one with layout_release_inline_content(). Returns false when the geometry depends on more
+/// than this: when a block is fragmented, or holds no line content.
+///
+/// # Safety
+///
+/// The callback must be sound to call with `context`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn layout_script_text_geometry_sources(
+ host: &DocumentHost,
+ primary: NodeSlotId,
+ context: *mut c_void,
+ push_source: unsafe extern "C" fn(*mut c_void, *const c_void, i32, i32),
+) -> bool {
+ read_rows(host, |arena| {
+ let fragments = arena.text_fragments(primary);
+ let node_slots = fragments.as_slice();
+ if node_slots.is_empty() {
+ return false;
+ }
+ for &node in node_slots {
+ let Some(block) = crate::painting::text_fragment::containing_block_paintable_of_node(arena, node) else {
+ return false;
+ };
+ let side_data = arena.committed_side_data(block);
+ let Some(content) = side_data.inline_content.as_ref() else {
+ return false;
+ };
+ // Lines in different fragments of a block can each move on their own.
+ if side_data.box_fragments().len() > 1 {
+ return false;
+ }
+ let position = crate::painting::paintable_geometry::absolute_line_root_position(arena, block, 0);
+ let retained = std::sync::Arc::into_raw(content.clone()).cast::<c_void>();
+ // SAFETY: The consumer takes ownership of the reference, and copies the position synchronously.
+ unsafe { push_source(context, retained, position.x.raw_value(), position.y.raw_value()) };
+ }
+ true
+ })
+}
+
+/// Releases a reference to line content that layout_script_text_geometry_sources() handed out.
+///
+/// # Safety
+///
+/// `content` must be a reference layout_script_text_geometry_sources() pushed, released only once.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn layout_release_inline_content(content: *const c_void) {
+ if content.is_null() {
+ return;
+ }
+ // SAFETY: The caller passes a reference from Arc::into_raw() in layout_script_text_geometry_sources(), once.
+ drop(unsafe { std::sync::Arc::from_raw(content.cast::<crate::layout::inline_content::InlineContent>()) });
+}
+
/// Calls `push_position` with each DOM offset (in UTF-16 code units) of the text node `primary` that one of its
/// horizontal fragments renders, along with the document-absolute x coordinate where that offset's character starts,
/// read from the fragment's shaped glyph run. `is_fragment_end` marks the offset one past a fragment's last character,
diff --git a/Tests/LibWeb/Text/expected/accessibility-node-data-geometry.txt b/Tests/LibWeb/Text/expected/accessibility-node-data-geometry.txt
new file mode 100644
index 00000000000..6c3bbe86c1c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/accessibility-node-data-geometry.txt
@@ -0,0 +1,61 @@
+== initial
+n0 generic bounds=8,8 784x76
+ n1 generic bounds=8,8 784x20
+ n2 text leaf name="above" bounds=8,10 46x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n3 generic bounds=8,44 400x40
+ n4 paragraph bounds=8,44 400x40
+ n5 generic bounds=8,46 44x16
+ n6 text leaf name="short" bounds=8,46 44x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n7 text leaf name=" " bounds=52,46 8x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 lines=0@16
+ n8 generic bounds=8,46 390x36
+ n9 text leaf name="the text that follows it on the same line, long enough to wrap" bounds=8,46 398x36 font="SerenitySans" 16 400 normal color=#000000 characters=52,0 59,0 68,0 77,0 85,0 92,0 101,0 110,0 117,0 125,0 132,0 141,0 151,0 158,0 166,0 172,0 182,0 187,0 191,0 201,0 212,0 222,0 230,0 234,0 241,0 249,0 260,0 269,0 277,0 284,0 293,0 302,0 310,0 319,0 329,0 341,0 350,0 358,0 362,0 366,0 376,0 385,0 390,0 0,20 4,20 14,20 24,20 31,20 39,20 48,20 58,20 68,20 78,20 85,20 95,20 103,20 109,20 120,20 128,20 139,20 148,20 157,20 lines=0@16 43@16
+
+== unchanged
+n0 generic bounds=8,8 784x76
+ n1 generic bounds=8,8 784x20
+ n2 text leaf name="above" bounds=8,10 46x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n3 generic bounds=8,44 400x40
+ n4 paragraph bounds=8,44 400x40
+ n5 generic bounds=8,46 44x16
+ n6 text leaf name="short" bounds=8,46 44x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n7 text leaf name=" " bounds=52,46 8x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 lines=0@16
+ n8 generic bounds=8,46 390x36
+ n9 text leaf name="the text that follows it on the same line, long enough to wrap" bounds=8,46 398x36 font="SerenitySans" 16 400 normal color=#000000 characters=52,0 59,0 68,0 77,0 85,0 92,0 101,0 110,0 117,0 125,0 132,0 141,0 151,0 158,0 166,0 172,0 182,0 187,0 191,0 201,0 212,0 222,0 230,0 234,0 241,0 249,0 260,0 269,0 277,0 284,0 293,0 302,0 310,0 319,0 329,0 341,0 350,0 358,0 362,0 366,0 376,0 385,0 390,0 0,20 4,20 14,20 24,20 31,20 39,20 48,20 58,20 68,20 78,20 85,20 95,20 103,20 109,20 120,20 128,20 139,20 148,20 157,20 lines=0@16 43@16
+
+== container narrowed
+n0 generic bounds=8,8 784x96
+ n1 generic bounds=8,8 784x20
+ n2 text leaf name="above" bounds=8,10 46x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n3 generic bounds=8,44 250x60
+ n4 paragraph bounds=8,44 250x60
+ n5 generic bounds=8,46 44x16
+ n6 text leaf name="short" bounds=8,46 44x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n7 text leaf name=" " bounds=52,46 8x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 lines=0@16
+ n8 generic bounds=8,46 243x56
+ n9 text leaf name="the text that follows it on the same line, long enough to wrap" bounds=8,46 251x56 font="SerenitySans" 16 400 normal color=#000000 characters=52,0 59,0 68,0 77,0 85,0 92,0 101,0 110,0 117,0 125,0 132,0 141,0 151,0 158,0 166,0 172,0 182,0 187,0 191,0 201,0 212,0 222,0 230,0 234,0 241,0 0,20 10,20 19,20 27,20 34,20 44,20 52,20 60,20 70,20 79,20 91,20 100,20 108,20 112,20 117,20 126,20 135,20 140,20 148,20 152,20 163,20 172,20 180,20 188,20 197,20 206,20 217,20 226,20 234,20 243,20 0,40 6,40 17,40 25,40 36,40 45,40 54,40 lines=0@16 25@16 55@16
+
+== earlier text on the line grew
+n0 generic bounds=8,8 784x116
+ n1 generic bounds=8,8 784x20
+ n2 text leaf name="above" bounds=8,10 46x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n3 generic bounds=8,44 250x80
+ n4 paragraph bounds=8,44 250x80
+ n5 generic bounds=8,46 201x16
+ n6 text leaf name="much longer than before" bounds=8,46 201x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 12,0 21,0 30,0 40,0 48,0 52,0 62,0 72,0 79,0 88,0 97,0 105,0 112,0 121,0 130,0 140,0 148,0 158,0 166,0 173,0 183,0 192,0 lines=0@16
+ n7 text leaf name=" " bounds=209,46 8x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 lines=0@16
+ n8 generic bounds=8,46 233x76
+ n9 text leaf name="the text that follows it on the same line, long enough to wrap" bounds=8,46 241x76 font="SerenitySans" 16 400 normal color=#000000 characters=209,0 215,0 225,0 233,0 0,20 6,20 15,20 25,20 32,20 40,20 47,20 56,20 65,20 72,20 80,20 86,20 97,20 101,20 105,20 116,20 127,20 136,20 144,20 149,20 156,20 164,20 174,20 184,20 192,20 198,20 208,20 216,20 0,40 9,40 18,40 30,40 39,40 47,40 51,40 56,40 66,40 74,40 79,40 87,40 92,40 102,40 111,40 119,40 127,40 136,40 145,40 156,40 166,40 173,40 182,40 190,40 197,40 208,40 0,60 11,60 20,60 29,60 lines=0@16 4@16 32@16 58@16
+
+== content above grew
+n0 generic bounds=8,8 784x136
+ n1 generic bounds=8,8 784x40
+ n2 text leaf name="above" bounds=8,10 46x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 29,0 37,0 lines=0@16
+ n3 text leaf name="and more" bounds=8,30 74x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 9,0 18,0 26,0 34,0 47,0 57,0 66,0 lines=0@16
+ n4 generic bounds=8,64 250x80
+ n5 paragraph bounds=8,64 250x80
+ n6 generic bounds=8,66 201x16
+ n7 text leaf name="much longer than before" bounds=8,66 201x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 12,0 21,0 30,0 40,0 48,0 52,0 62,0 72,0 79,0 88,0 97,0 105,0 112,0 121,0 130,0 140,0 148,0 158,0 166,0 173,0 183,0 192,0 lines=0@16
+ n8 text leaf name=" " bounds=209,66 8x16 font="SerenitySans" 16 400 normal color=#000000 characters=0,0 lines=0@16
+ n9 generic bounds=8,66 233x76
+ n10 text leaf name="the text that follows it on the same line, long enough to wrap" bounds=8,66 241x76 font="SerenitySans" 16 400 normal color=#000000 characters=209,0 215,0 225,0 233,0 0,20 6,20 15,20 25,20 32,20 40,20 47,20 56,20 65,20 72,20 80,20 86,20 97,20 101,20 105,20 116,20 127,20 136,20 144,20 149,20 156,20 164,20 174,20 184,20 192,20 198,20 208,20 216,20 0,40 9,40 18,40 30,40 39,40 47,40 51,40 56,40 66,40 74,40 79,40 87,40 92,40 102,40 111,40 119,40 127,40 136,40 145,40 156,40 166,40 173,40 182,40 190,40 197,40 208,40 0,60 11,60 20,60 29,60 lines=0@16 4@16 32@16 58@16
+
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-geometry.html b/Tests/LibWeb/Text/input/accessibility-node-data-geometry.html
new file mode 100644
index 00000000000..93798779e03
--- /dev/null
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-geometry.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body {
+ font: 16px/20px SerenitySans;
+ }
+</style>
+<!-- After each change that moves or rewraps text without touching the text node or its parent's style, the text's
+ geometry reflects it: a narrower container, earlier text on the same line growing, and content above it growing. -->
+<div id="root">
+ <div id="above">above</div>
+ <div id="container" style="width: 400px">
+ <p><span id="first">short</span> <span>the text that follows it on the same line, long enough to wrap</span></p>
+ </div>
+</div>
+<script>
+ 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() + internals.accessibilityCachedGeometryMismatches();
+ println(`== ${label}`);
+ println(dump);
+ if (stale)
+ println(`stale cached data:\n${stale}`);
+ };
+
+ step("initial", () => {});
+ step("unchanged", () => {});
+ step("container narrowed", () => document.getElementById("container").style.width = "250px");
+ step("earlier text on the line grew", () => document.getElementById("first").firstChild.data = "much longer than before");
+ step("content above grew", () => document.getElementById("above").append(document.createElement("br"), "and more"));
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html b/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html
index 7c5a38d6253..c47771ece64 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-indirect.html
@@ -37,7 +37,7 @@
change();
// Printing adds to the DOM, so read everything before printing anything.
const dump = internals.dumpAccessibilityNodeData(root);
- const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches() + internals.accessibilityCachedGeometryMismatches();
println(`== ${label}`);
println(dump);
if (stale)
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-names.html b/Tests/LibWeb/Text/input/accessibility-node-data-names.html
index 9fe92ce9223..b4a99481b97 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-names.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-names.html
@@ -40,7 +40,7 @@
change();
// Printing adds to the DOM, so read everything before printing anything.
const dump = internals.dumpAccessibilityNodeData(root);
- const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches() + internals.accessibilityCachedGeometryMismatches();
println(`== ${label}`);
println(dump);
if (stale)
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-states.html b/Tests/LibWeb/Text/input/accessibility-node-data-states.html
index eb87d24a12d..9a254a1f784 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-states.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-states.html
@@ -24,7 +24,7 @@
change();
// Printing adds to the DOM, so read everything before printing anything.
const dump = internals.dumpAccessibilityNodeData(root);
- const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches() + internals.accessibilityCachedGeometryMismatches();
println(`== ${label}`);
println(dump);
if (stale)
diff --git a/Tests/LibWeb/Text/input/accessibility-node-data-structure.html b/Tests/LibWeb/Text/input/accessibility-node-data-structure.html
index 54a46587a81..7d13c10de5e 100644
--- a/Tests/LibWeb/Text/input/accessibility-node-data-structure.html
+++ b/Tests/LibWeb/Text/input/accessibility-node-data-structure.html
@@ -26,7 +26,7 @@
change();
// Printing adds to the DOM, so read everything before printing anything.
const dump = internals.dumpAccessibilityNodeData(root);
- const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches() + internals.accessibilityCachedGeometryMismatches();
println(`== ${label}`);
println(dump);
if (stale)
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 5133427a384..196271bd6b5 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
@@ -28,7 +28,7 @@
change();
// Printing adds to the DOM, so read everything before printing anything.
const dump = internals.dumpAccessibilityNodeData(root);
- const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches();
+ const stale = internals.accessibilityCachedTextMismatches() + internals.accessibilityCachedRecordMismatches() + internals.accessibilityCachedGeometryMismatches();
println(`== ${label}`);
println(dump);
if (stale)