Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/validation/css-anchor-overlay-903-20260921.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,13 +10,15 @@ 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"
|| value == "revert-layer"
? 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"
Expand Down Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
#include <array>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<std::string_view, layout_rect> named_anchors;
bool unresolved_named_anchor{false};
};

// dom_node has one fixed allocation size and stable-address lifetime.
Expand Down
Loading
Loading