From 4f996c73629eeb328e0371eb5d72901f2e2fc767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Mon, 21 Sep 2026 11:45:59 +0200 Subject: [PATCH] Implement named CSS anchor geometry for webview overlays --- .../css-anchor-overlay-903-20260921.md | 43 +++++ .../native/webscene_css_anchor_values.h | 43 +++++ .../native/webscene_css_application.h | 14 +- .../native/webscene_css_box_application.h | 7 + .../native/webscene_css_reset.h | 13 ++ .../native/webscene_native_dom.cpp | 1 + .../native/webscene_native_dom.h | 6 + .../native/webscene_native_dom_layout.inc | 159 ++++++++++++++---- .../native/webscene_v8_runtime_dom_core.inc | 7 + .../native/webscene_v8_runtime_style.inc | 12 ++ .../css-anchor-overlay-geometry.html | 104 ++++++++++++ .../css-anchor-overlay-paint-ref.html | 11 ++ .../contracts/css-anchor-overlay-paint.html | 12 ++ .../webscene-css-anchor-overlay-profile.json | 25 +++ 14 files changed, 419 insertions(+), 38 deletions(-) create mode 100644 docs/validation/css-anchor-overlay-903-20260921.md create mode 100644 experiments/WebScene.NativeEngine.Probe/native/webscene_css_anchor_values.h create mode 100644 tests/WebPlatformSubset/contracts/css-anchor-overlay-geometry.html create mode 100644 tests/WebPlatformSubset/contracts/css-anchor-overlay-paint-ref.html create mode 100644 tests/WebPlatformSubset/contracts/css-anchor-overlay-paint.html create mode 100644 tests/WebPlatformSubset/webscene-css-anchor-overlay-profile.json diff --git a/docs/validation/css-anchor-overlay-903-20260921.md b/docs/validation/css-anchor-overlay-903-20260921.md new file mode 100644 index 000000000..9cd615926 --- /dev/null +++ b/docs/validation/css-anchor-overlay-903-20260921.md @@ -0,0 +1,43 @@ +# CSS anchor overlay slice for Code OSS webviews — 21 September 2026 + +WebScene issue #903 records a real installed AppScene/Code OSS Release where +unchanged Markdown Preview opens a tab but its overlay and iframe measure 0×0. +Code OSS authors `anchor-name`, `position-anchor`, `anchor(top/left)`, and +`anchor-size(width/height)` in `overlayLayoutElement.ts`. The baseline native +runtime passed only the independent absolute-inset case (1/5 geometry checks); +Chrome passed all five. + +This slice retains the named-anchor tokens in cold style storage and resolves +the used box in the grid, inline, and general positioned layout paths. An +anchor record contains a snapshot of its used rectangle, so a later layout +pass cannot erase its box while resetting inline children. A second tree pass +is taken only when an overlay precedes its anchor in document order. Changes +to a named anchor's CSSOM geometry invalidate the full document, because an +overlay may live outside that anchor's positioned subtree. Ordinary documents +perform no anchor lookups or extra layout pass. + +## Focused gates + +| Gate | Result | +| --- | --- | +| Chrome 152 headless geometry fixture | 9/9 assertions pass, including CSSOM replacement, resize/move, and 64 panel moves | +| Native V8 Release geometry fixture | 9/9 assertions pass; 64 move-and-relayout cycles stay within the fixture's 500 ms budget | +| Native rendered scene | anchor paint reftest equals its explicit-coordinate reference | +| Chrome rendered scene | anchor paint PNG and explicit-coordinate PNG have identical SHA-256 `494c7a9c7df2a72a770a41d19dcebd8f108f36a417e3afdc5c53220aab82dad7` | +| Existing positioned-height regression | paint and descendant contracts pass; focused combined run 4/4 documents, 15/15 subtests | + +The checked-in profile is +`tests/WebPlatformSubset/webscene-css-anchor-overlay-profile.json`. The +browser CDP adapter could not attach to a debuggable page on this host, so the +Chrome geometry fixture was run with headless DOM output and the paint pair +with headless screenshots. The native Release runner produced the checked-in +profile result at `/private/tmp/webscene-anchor-903-visual-native/results.json`; +the temporary combined regression result is at +`/private/tmp/webscene-anchor-903-regression-native/results.json`. + +This is the exact function set needed by the current Code OSS overlay, not +general CSS Anchor Positioning conformance. Named-anchor collision scoping, +fallback syntax, and arbitrary `anchor()` forms remain outside this slice. +The earlier signed AppScene package predates this WebScene change; #903 and +downstream AppScene #402 stay open until a new exact SDK/CLI Release paints +Markdown and the product visual, lifecycle, and idle-CPU gates pass. diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_anchor_values.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_anchor_values.h new file mode 100644 index 000000000..92045349a --- /dev/null +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_anchor_values.h @@ -0,0 +1,43 @@ +#pragma once + +#include "webscene_native_dom.h" + +namespace webscene_native::css { + +// Anchor tokens are cold: only positioned elements that author anchor() +// functions retain a value, while ordinary node_style records stay compact. +inline void retain_anchor_function(node_style& style, + const std::string& property, const std::string& value) +{ + if (value.starts_with("anchor(") || value.starts_with("anchor-size(")) { + style.mutable_textual().effect_values[property] = value; + } else if (auto* textual = style.mutable_textual_if_present(); textual != nullptr) { + textual->effect_values.erase(property); + } +} + +inline void retain_anchor_identifier(node_style& style, + const std::string& property, const std::string& value) +{ + const auto valid = value.starts_with("--") + && value.find_first_of(" \t\r\n,()") == std::string::npos; + if (valid) { + style.mutable_textual().effect_values[property] = value; + } else if (auto* textual = style.mutable_textual_if_present(); textual != nullptr) { + textual->effect_values.erase(property); + } + if (property == "anchor-name") style.anchor_name_present = valid; + if (property == "position-anchor") style.position_anchor_present = valid; +} + +inline std::string_view retained_anchor_value(const node_style& style, + std::string_view property) +{ + const auto* textual = style.textual_data_identity(); + if (textual == nullptr) return {}; + const auto known = textual->effect_values.find(std::string(property)); + return known == textual->effect_values.end() + ? std::string_view{} : std::string_view{known->second}; +} + +} // namespace webscene_native::css diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_application.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_application.h index c030924d7..96eeee17f 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_application.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_application.h @@ -21,6 +21,10 @@ void apply_resolved_declaration(native_document& document,dom_node& node, bool defer_transition_configuration = false) { const auto& name=declaration.name; + if (name == "anchor-name" || name == "position-anchor") { + retain_anchor_identifier(node.style, name, value); + return; + } if (name == "interpolate-size") { const auto lower = ascii_lower(trim_value(value)); if (lower == "allow-keywords" || lower == "numeric-only") { @@ -154,10 +158,16 @@ void apply_resolved_declaration(native_document& document,dom_node& node, && declaration.specified.keyword.empty()) { switch (declaration.property) { case css_property_id::width: - if (!is_inline(inline_width)) node.style.width = declaration.specified.length; + if (!is_inline(inline_width)) { + retain_anchor_function(node.style, "width", value); + node.style.width = declaration.specified.length; + } return; case css_property_id::height: - if (!is_inline(inline_height)) node.style.height = declaration.specified.length; + if (!is_inline(inline_height)) { + retain_anchor_function(node.style, "height", value); + node.style.height = declaration.specified.length; + } return; case css_property_id::padding_left: if (!is_inline(inline_padding)) { diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_box_application.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_box_application.h index b44817381..c671eec6e 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_box_application.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_box_application.h @@ -1,5 +1,6 @@ #pragma once #include "webscene_css_property_mask.h" +#include "webscene_css_anchor_values.h" namespace webscene_native::css { // Apply resolved box values after custom-property substitution. The owner supplies @@ -9,6 +10,7 @@ bool apply_box_metrics(dom_node& node,const std::string& name, const std::string& value,Protected&& is_inline) { if ((name == "width" || name == "inline-size") && !is_inline(inline_width)) { + retain_anchor_function(node.style, "width", value); node.style.width = value == "inherit" && node.parent != nullptr ? node.parent->style.width : value == "initial" || value == "unset" || value == "revert" @@ -16,6 +18,7 @@ bool apply_box_metrics(dom_node& node,const std::string& name, ? css_length{} : native_document::parse_length(value); } else if ((name == "height" || name == "block-size") && !is_inline(inline_height)) { + retain_anchor_function(node.style, "height", value); node.style.height = value == "inherit" && node.parent != nullptr ? node.parent->style.height : value == "initial" || value == "unset" || value == "revert" @@ -47,12 +50,16 @@ bool apply_box_metrics(dom_node& node,const std::string& name, || value == "revert-layer" ? css_length{} : native_document::parse_length(value); } else if ((name == "left" || name == "inset-inline-start") && !is_inline(inline_left)) { + retain_anchor_function(node.style, "left", value); node.style.left = parse_inset_length(value); } else if ((name == "top" || name == "inset-block-start") && !is_inline(inline_top)) { + retain_anchor_function(node.style, "top", value); node.style.top = parse_inset_length(value); } else if ((name == "right" || name == "inset-inline-end") && !is_inline(inline_right)) { + retain_anchor_function(node.style, "right", value); node.style.right = parse_inset_length(value); } else if ((name == "bottom" || name == "inset-block-end") && !is_inline(inline_bottom)) { + retain_anchor_function(node.style, "bottom", value); node.style.bottom = parse_inset_length(value); } else if (name == "inset") { diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_reset.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_reset.h index 2a6485e89..7c95a67c6 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_reset.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_reset.h @@ -336,6 +336,19 @@ inline void apply_all_unset( reset.mutable_textual().list_style_type = previous.textual().list_style_type; } + // The anchor tokens are sparse and stored with other cold authored CSS + // values. Preserve only inline declarations across a stylesheet recascade. + for (const auto property : {"anchor-name", "position-anchor", + "left", "top", "right", "bottom", "width", "height"}) { + if (!has_inline({property})) continue; + const auto known = previous.textual().effect_values.find(property); + if (known == previous.textual().effect_values.end()) continue; + reset.mutable_textual().effect_values[property] = known->second; + if (std::string_view{property} == "anchor-name") + reset.anchor_name_present = true; + if (std::string_view{property} == "position-anchor") + reset.position_anchor_present = true; + } node.style = std::move(reset); } diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.cpp b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.cpp index d674c2318..1b590ea03 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.cpp +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.cpp @@ -1,6 +1,7 @@ #include "webscene_native_dom.h" #include "webscene_css_ascii_number.h" #include "webscene_css_effect_values.h" +#include "webscene_css_anchor_values.h" #include #include diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h index e1fa8c4b4..f021426da 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h @@ -1043,6 +1043,8 @@ struct node_style final { bool visibility_hidden : 1 {false}; bool visibility_specified : 1 {false}; bool pointer_events_none : 1 {false}; + bool anchor_name_present : 1 {false}; + bool position_anchor_present : 1 {false}; bool pointer_events_specified : 1 {false}; bool flex_wrap : 1 {false}; bool flex_reverse : 1 {false}; @@ -2592,6 +2594,10 @@ class native_document final { struct layout_scratch_storage final { tracking_memory_resource upstream; std::pmr::unsynchronized_pool_resource pool{&upstream}; + // Populated only by documents that author named anchors. String views + // point into stable computed style storage for the duration of layout. + std::unordered_map named_anchors; + bool unresolved_named_anchor{false}; }; // dom_node has one fixed allocation size and stable-address lifetime. diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_layout.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_layout.inc index 9d5565f77..1f7d879cd 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_layout.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_layout.inc @@ -95,6 +95,8 @@ void native_document::layout(float viewport_width, float viewport_height) if (layout_scratch_ == nullptr) { layout_scratch_ = std::make_unique(); } + layout_scratch_->named_anchors.clear(); + layout_scratch_->unresolved_named_anchor = false; #if defined(WEBSCENE_NATIVE_ENGINE_CERTIFICATION) const auto intrinsic_cache_disabled = std::getenv("WEBSCENE_DISABLE_INTRINSIC_SIZE_CACHE") != nullptr; @@ -193,6 +195,13 @@ void native_document::layout(float viewport_width, float viewport_height) } } layout_children(*body_); + // A positioned overlay can precede its anchor in tree order. Finish the + // first layout to obtain that anchor's used box, then resolve references + // once more. Most documents never take this second pass. + if (layout_scratch_->unresolved_named_anchor) { + layout_scratch_->unresolved_named_anchor = false; + layout_children(*body_); + } trace_phase("tree"); // Sticky offsets are visual adjustments to completed normal-flow geometry. // Applying them during row layout uses unfinished table/group dimensions @@ -441,6 +450,55 @@ void native_document::layout_children(dom_node& parent) - border_left - border_right - padding_left - padding_right), std::max(0.0F, parent.layout.height - border_top - border_bottom - padding_top - padding_bottom)}; + struct anchor_geometry final { + std::optional left; + std::optional top; + std::optional right; + std::optional bottom; + std::optional width; + std::optional height; + }; + const auto anchored_geometry_for = [&](const dom_node& child, + const layout_rect& containing) -> anchor_geometry { + anchor_geometry result{}; + if (!child.style.position_anchor_present) return result; + const auto name = css::retained_anchor_value(child.style, "position-anchor"); + const auto known = layout_scratch_->named_anchors.find(name); + if (known == layout_scratch_->named_anchors.end()) { + layout_scratch_->unresolved_named_anchor = true; + return result; + } + const auto& target = known->second; + const auto inset = [&](std::string_view property) -> std::optional { + const auto token = css::retained_anchor_value(child.style, property); + auto point = 0.0F; + if (property == "left" || property == "right") { + if (token == "anchor(left)") point = target.x; + else if (token == "anchor(right)") point = target.x + target.width; + else return std::nullopt; + return property == "left" ? point - containing.x + : containing.x + containing.width - point; + } + if (token == "anchor(top)") point = target.y; + else if (token == "anchor(bottom)") point = target.y + target.height; + else return std::nullopt; + return property == "top" ? point - containing.y + : containing.y + containing.height - point; + }; + const auto size = [&](std::string_view property) -> std::optional { + const auto token = css::retained_anchor_value(child.style, property); + if (token == "anchor-size(width)") return target.width; + if (token == "anchor-size(height)") return target.height; + return std::nullopt; + }; + result.left = inset("left"); + result.top = inset("top"); + result.right = inset("right"); + result.bottom = inset("bottom"); + result.width = size("width"); + result.height = size("height"); + return result; + }; // HTML LI marker geometry retains its established path. Generic authored // list-item boxes need an outside marker even though they have no LI tag. if (!marker_text.empty() && !has_inside_marker && parent.tag != "li") { @@ -1338,18 +1396,19 @@ void native_document::layout_children(dom_node& parent) - containing_border_left - containing_border_right), std::max(0.0F, containing_node->layout.height - containing_border_top - containing_border_bottom)}; - const auto has_left = is_specified(child.style.left); - const auto has_top = is_specified(child.style.top); - const auto has_right = is_specified(child.style.right); - const auto has_bottom = is_specified(child.style.bottom); + const auto anchor = anchored_geometry_for(child, containing); + const auto has_left = anchor.left.has_value() || is_specified(child.style.left); + const auto has_top = anchor.top.has_value() || is_specified(child.style.top); + const auto has_right = anchor.right.has_value() || is_specified(child.style.right); + const auto has_bottom = anchor.bottom.has_value() || is_specified(child.style.bottom); const auto left = has_left - ? resolve_length(child, child.style.left, containing.width, 0) : 0.0F; + ? anchor.left.value_or(resolve_length(child, child.style.left, containing.width, 0)) : 0.0F; const auto top = has_top - ? resolve_length(child, child.style.top, containing.height, 0) : 0.0F; + ? anchor.top.value_or(resolve_length(child, child.style.top, containing.height, 0)) : 0.0F; const auto right = has_right - ? resolve_length(child, child.style.right, containing.width, 0) : 0.0F; + ? anchor.right.value_or(resolve_length(child, child.style.right, containing.width, 0)) : 0.0F; const auto bottom = has_bottom - ? resolve_length(child, child.style.bottom, containing.height, 0) : 0.0F; + ? anchor.bottom.value_or(resolve_length(child, child.style.bottom, containing.height, 0)) : 0.0F; auto margin_left = resolve_length( child, child.style.margin_left, containing.width, 0); const auto margin_right = resolve_length( @@ -1359,13 +1418,17 @@ void native_document::layout_children(dom_node& parent) const auto margin_bottom = resolve_length( child, child.style.margin_bottom, containing.height, 0); layout_rect assigned{}; - assigned.width = is_specified(child.style.width) + assigned.width = anchor.width.has_value() + ? *anchor.width + : is_specified(child.style.width) ? outer_authored_size(child, true, containing.width) : has_left && has_right ? std::max(0.0F, containing.width - left - right - margin_left - margin_right) : intrinsic_size(child, true, containing.width); - assigned.height = is_specified(child.style.height) + assigned.height = anchor.height.has_value() + ? *anchor.height + : is_specified(child.style.height) ? outer_authored_size(child, false, containing.height) : has_top && has_bottom ? std::max(0.0F, containing.height - top - bottom @@ -1377,8 +1440,8 @@ void native_document::layout_children(dom_node& parent) assigned.height, containing.width, containing.height, - is_specified(child.style.width), - is_specified(child.style.height)); + anchor.width.has_value() || is_specified(child.style.width), + anchor.height.has_value() || is_specified(child.style.height)); const auto constrain_positioned_size = [&](bool horizontal, float size) { const auto available = horizontal ? containing.width : containing.height; const auto& minimum = horizontal @@ -1969,18 +2032,19 @@ void native_document::layout_children(dom_node& parent) 0.0F, containing.height - border_top - border_bottom); } - const auto has_left = is_specified(child.style.left); - const auto has_top = is_specified(child.style.top); - const auto has_right = is_specified(child.style.right); - const auto has_bottom = is_specified(child.style.bottom); + const auto anchored = anchored_geometry_for(child, containing); + const auto has_left = anchored.left.has_value() || is_specified(child.style.left); + const auto has_top = anchored.top.has_value() || is_specified(child.style.top); + const auto has_right = anchored.right.has_value() || is_specified(child.style.right); + const auto has_bottom = anchored.bottom.has_value() || is_specified(child.style.bottom); const auto left = has_left - ? resolve_length(child, child.style.left, containing.width, 0) : 0; + ? anchored.left.value_or(resolve_length(child, child.style.left, containing.width, 0)) : 0; const auto top = has_top - ? resolve_length(child, child.style.top, containing.height, 0) : 0; + ? anchored.top.value_or(resolve_length(child, child.style.top, containing.height, 0)) : 0; const auto right = has_right - ? resolve_length(child, child.style.right, containing.width, 0) : 0; + ? anchored.right.value_or(resolve_length(child, child.style.right, containing.width, 0)) : 0; const auto bottom = has_bottom - ? resolve_length(child, child.style.bottom, containing.height, 0) : 0; + ? anchored.bottom.value_or(resolve_length(child, child.style.bottom, containing.height, 0)) : 0; const auto margin_left = resolve_length( child, child.style.margin_left, containing.width, 0); const auto margin_right = resolve_length( @@ -1995,13 +2059,17 @@ void native_document::layout_children(dom_node& parent) ? anchor.y : anchor.y + anchor.height; layout_rect assigned{}; - assigned.width = is_specified(child.style.width) + assigned.width = anchored.width.has_value() + ? *anchored.width + : is_specified(child.style.width) ? outer_authored_size(child, true, containing.width) : has_left && has_right ? std::max(0.0F, containing.width - left - right - margin_left - margin_right) : intrinsic_size(child, true, containing.width); - assigned.height = is_specified(child.style.height) + assigned.height = anchored.height.has_value() + ? *anchored.height + : is_specified(child.style.height) ? outer_authored_size(child, false, containing.height) : has_top && has_bottom ? std::max(0.0F, containing.height - top - bottom @@ -2055,7 +2123,7 @@ void native_document::layout_children(dom_node& parent) : has_bottom ? containing.height - bottom - margin_bottom - assigned.height : static_y - containing.y + margin_top); - layout_child(child, containing, assigned); + layout_child(child, containing, assigned, anchored.height.has_value()); } return; } @@ -3421,21 +3489,32 @@ void native_document::layout_children(dom_node& parent) 0.0F, containing.height - border_top - border_bottom); } layout_rect assigned{}; - const auto has_left = is_specified(child->style.left); - const auto has_top = is_specified(child->style.top); - const auto has_right = is_specified(child->style.right); - const auto has_bottom = is_specified(child->style.bottom); + const auto anchored = anchored_geometry_for(*child, containing); + const auto& anchor_left = anchored.left; + const auto& anchor_top = anchored.top; + const auto& anchor_right = anchored.right; + const auto& anchor_bottom = anchored.bottom; + const auto& anchor_width = anchored.width; + const auto& anchor_height = anchored.height; + const auto has_left = anchor_left.has_value() || is_specified(child->style.left); + const auto has_top = anchor_top.has_value() || is_specified(child->style.top); + const auto has_right = anchor_right.has_value() || is_specified(child->style.right); + const auto has_bottom = anchor_bottom.has_value() || is_specified(child->style.bottom); const auto left = has_left - ? resolve_length(*child, child->style.left, containing.width, 0) + ? anchor_left.value_or(resolve_length( + *child, child->style.left, containing.width, 0)) : 0; const auto top = has_top - ? resolve_length(*child, child->style.top, containing.height, 0) + ? anchor_top.value_or(resolve_length( + *child, child->style.top, containing.height, 0)) : 0; const auto right = has_right - ? resolve_length(*child, child->style.right, containing.width, 0) + ? anchor_right.value_or(resolve_length( + *child, child->style.right, containing.width, 0)) : 0; const auto bottom = has_bottom - ? resolve_length(*child, child->style.bottom, containing.height, 0) + ? anchor_bottom.value_or(resolve_length( + *child, child->style.bottom, containing.height, 0)) : 0; auto margin_left = resolve_length( *child, @@ -3459,13 +3538,17 @@ void native_document::layout_children(dom_node& parent) 0); const auto intrinsic_width = intrinsic_size(*child, true, containing.width); const auto intrinsic_height = intrinsic_size(*child, false, containing.height); - assigned.width = is_specified(child->style.width) + assigned.width = anchor_width.has_value() + ? *anchor_width + : is_specified(child->style.width) ? outer_authored_size(*child, true, containing.width) : has_left && has_right ? std::max(0.0F, containing.width - left - right - margin_left - margin_right) : intrinsic_width; - assigned.height = is_specified(child->style.height) + assigned.height = anchor_height.has_value() + ? *anchor_height + : is_specified(child->style.height) ? outer_authored_size(*child, false, containing.height) : has_top && has_bottom ? std::max(0.0F, containing.height - top - bottom @@ -3477,8 +3560,8 @@ void native_document::layout_children(dom_node& parent) assigned.height, containing.width, containing.height, - is_specified(child->style.width), - is_specified(child->style.height)); + anchor_width.has_value() || is_specified(child->style.width), + anchor_height.has_value() || is_specified(child->style.height)); if (child->tag == "img" && !is_specified(child->style.height) && child->replaced_image().natural_width > 0 && child->replaced_image().natural_height > 0) { @@ -3547,7 +3630,7 @@ void native_document::layout_children(dom_node& parent) assigned.y -= containing_node->scroll_top; } } - layout_child(*child, containing, assigned); + layout_child(*child, containing, assigned, anchor_height.has_value()); continue; } @@ -5425,4 +5508,8 @@ void native_document::layout_child( child.layout.height = capped_height; } } + if (child.visible && child.style.anchor_name_present) { + const auto name = css::retained_anchor_value(child.style, "anchor-name"); + if (!name.empty()) layout_scratch_->named_anchors.insert_or_assign(name, child.layout); + } } diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc index 45d425133..5a0cfeb63 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc @@ -763,6 +763,13 @@ document.mark_scene_changed(); return; } + // A named anchor can position an overlay outside its own subtree. + // The ordinary isolated-positioned-box invalidation cannot see that + // dependency, so geometry changes on the anchor relayout the document. + if (node.style.anchor_name_present) { + document.mark_dirty(); + return; + } const auto changes_only_positioned_subtree = canonical_property_name == "width" || canonical_property_name == "height" diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_style.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_style.inc index 3a708defc..38e0aea84 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_style.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_style.inc @@ -826,6 +826,9 @@ // existing numeric grid-column projection when applicable. node->style.inline_property_mask |= inline_grid; } else if (apply_inset_declaration(node->style, name, value)) { + if (name == "left" || name == "top" || name == "right" || name == "bottom") { + css::retain_anchor_function(node->style, name, value); + } node->style.inline_property_mask |= inline_left | inline_top | inline_right | inline_bottom; } else if (apply_margin_declaration(node->style, name, value)) { @@ -835,6 +838,7 @@ } else if (apply_border_declaration(node->style, name, value)) { node->style.inline_property_mask |= inline_border; } else if (name == "width" || name == "inline-size") { + css::retain_anchor_function(node->style, "width", value); node->style.width = value == "inherit" && node->parent != nullptr ? node->parent->style.width : value == "initial" || value == "unset" || value == "revert" @@ -843,6 +847,7 @@ : native_document::parse_length(value); node->style.inline_property_mask |= inline_width; } else if (name == "height" || name == "block-size") { + css::retain_anchor_function(node->style, "height", value); node->style.height = value == "inherit" && node->parent != nullptr ? node->parent->style.height : value == "initial" || value == "unset" || value == "revert" @@ -881,6 +886,8 @@ : value == "relative" ? position_mode::relative : position_mode::normal; node->style.inline_property_mask |= inline_position; + } else if (name == "anchor-name" || name == "position-anchor") { + css::retain_anchor_identifier(node->style, name, value); } else if (name == "contain") { const auto contain = lower_html_name(value); node->style.mutable_textual().contain_value = @@ -1371,6 +1378,11 @@ canonical_css_property_name(name), connected_used_value)) { value = format_pixels(connected_used_value); + } else if (name == "anchor-name" || name == "position-anchor") { + const auto retained = css::retained_anchor_value(node->style, name); + value = retained.empty() + ? (name == "anchor-name" ? "none" : "auto") + : std::string{retained}; } else if (name == "z-index") { value = node->style.z_index_auto ? "auto" : std::to_string(node->style.z_index); diff --git a/tests/WebPlatformSubset/contracts/css-anchor-overlay-geometry.html b/tests/WebPlatformSubset/contracts/css-anchor-overlay-geometry.html new file mode 100644 index 000000000..e50e3522f --- /dev/null +++ b/tests/WebPlatformSubset/contracts/css-anchor-overlay-geometry.html @@ -0,0 +1,104 @@ + + +Named CSS anchor overlay geometry + +
+
+
+
+
+
+PENDING + diff --git a/tests/WebPlatformSubset/contracts/css-anchor-overlay-paint-ref.html b/tests/WebPlatformSubset/contracts/css-anchor-overlay-paint-ref.html new file mode 100644 index 000000000..f92a734d6 --- /dev/null +++ b/tests/WebPlatformSubset/contracts/css-anchor-overlay-paint-ref.html @@ -0,0 +1,11 @@ + + + +
diff --git a/tests/WebPlatformSubset/contracts/css-anchor-overlay-paint.html b/tests/WebPlatformSubset/contracts/css-anchor-overlay-paint.html new file mode 100644 index 000000000..0e94e6c59 --- /dev/null +++ b/tests/WebPlatformSubset/contracts/css-anchor-overlay-paint.html @@ -0,0 +1,12 @@ + + + + +
diff --git a/tests/WebPlatformSubset/webscene-css-anchor-overlay-profile.json b/tests/WebPlatformSubset/webscene-css-anchor-overlay-profile.json new file mode 100644 index 000000000..b096c948a --- /dev/null +++ b/tests/WebPlatformSubset/webscene-css-anchor-overlay-profile.json @@ -0,0 +1,25 @@ +{ + "profile": "webscene-css-anchor-overlay-1", + "wptRevision": "2c705104a295c48053eeddf7fe0170d790a4e853", + "runtime": "v8", + "viewport": { "width": 800, "height": 600, "deviceScaleFactor": 1 }, + "candidate": [ + { + "path": "contracts/css-anchor-overlay-geometry.html", + "type": "contract", + "capabilities": ["css-anchor-positioning", "absolute-inset-stretch", "dynamic-anchor-layout"], + "evidence": ["code-oss-markdown-preview-overlay-20260921", "chrome-browser-reference"], + "reason": "Named-anchor and fixed-overlay geometry used by unchanged Code OSS webviews." + }, + { + "path": "contracts/css-anchor-overlay-paint.html", + "type": "reftest", + "reference": "contracts/css-anchor-overlay-paint-ref.html", + "capabilities": ["css-anchor-positioning", "fixed-overlay-paint", "clipping-anchor-paint"], + "evidence": ["code-oss-markdown-preview-overlay-20260921"], + "reason": "The anchor-positioned preview overlay must paint the same clipped scene as explicit pixel geometry." + } + ], + "harnessBlocked": [], + "excluded": [] +}