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
66 changes: 66 additions & 0 deletions docs/validation/css-placeholder-pseudo-paint-237-235.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Bounded placeholder pseudo-element paint

Issues: WebScene #237, parent #235

Base: `2112a6d7e53844d3c1a461fa9937dc5063fa4bfe`

Unchanged Code OSS: `645f29cc3176500b4b5762ba887cf2a7f0ffdf2c`

## Selected inventory gap

The pinned unchanged Code OSS core CSS contains twelve standard
`::placeholder` selectors across the workbench shell, action widget, mobile
picker, issue reporter, chat, plan review, and agent-feedback controls. Every
one authors `color`; one also authors `opacity: 1`. WebScene already parsed the
pseudo-element and painted live `input`/`textarea` placeholder strings, but the
runtime pseudo classifier dropped those rules before cascade.

This slice assigns `::placeholder` its own compiled pseudo kind and retains only
the two observed paint components: resolved color and bounded opacity. The
state lives in the existing copy-on-write pseudo allocation and is created only
for a matching authored rule. It creates no generated box and does not affect
control geometry. Empty-value paint reads the retained state while nonempty
values continue to suppress the placeholder. Re-cascade replaces the complete
record, so class, custom-property, stylesheet, detach, and navigation changes
cannot retain stale placeholder paint.

The selector uses the ordinary compiled origin and its existing subject,
functional, combinator, and attribute dependency routes. Cascade does not scan
the document, parse during paint, poll, request frames, or add visual-tree
nodes. Scene publication performs one color selection and alpha multiplication
only when an eligible empty text control already paints its placeholder.

## Contracts and remaining inventory

The V8 scene contract checks custom-property color, fractional opacity, class
mutation, live-value suppression, restoration, and cleanup. The shared CSS
contract checks pseudo classification plus bounded color/opacity application.
The browser candidate checks the corresponding computed pseudo style.

The unchanged Code OSS core pseudo-class forms in its authored CSS are already
covered by the compiled matcher; `:visited` remains deliberately privacy-closed.
The remaining core pseudo-element inventory is:

- ten `::details-content` rules, which require a disclosure-content pseudo box,
open-state layout and discrete/auto-size transition behavior;
- two functional `::highlight()` rules, which require named Highlight ranges,
functional pseudo parsing, range paint, mutation, and teardown;
- two `::-webkit-details-marker` rules and six internal form-control part
rules (`::-webkit-inner-spin-button`, `::-webkit-outer-spin-button`,
`::-ms-clear`, and `::-webkit-search-cancel-button`), which require bounded
native control-part ownership before their declarations can have an
observable effect.

The two legacy WebKit/Mozilla placeholder aliases duplicate adjacent standard
rules and remain unclaimed. Extension-bundled CSS additionally uses named
highlights and one `::marker`; shadow-only `::part`/`::slotted`, complete marker
styling, first-line/first-letter layout, and cumulative browser/package/
performance evidence remain outside this slice. No Code OSS source changes.

The remaining parser-recognized but runtime-unmaterialized pseudo-elements are
`::first-letter`, `::first-line`, `::marker`, `::file-selector-button`, `::cue`,
`::cue-region`, `::grammar-error`, `::spelling-error`, and `::target-text`.
Functional `::highlight()`, `::details-content`, `::part()`, and `::slotted()`
also still require parser and ownership work. The inventory diagnostics now
report the already implemented selection, backdrop, and WebKit scrollbar kinds
as supported instead of grouping them with those remaining gaps.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ bool apply_native_cascade(native_document& document,dom_node& node,
const auto result=apply_backdrop_declaration(node,declaration,variables,backdrop_important);
observe(declaration,result);
}
else if(kind==8) {
property_result result;
apply_placeholder_declaration(
node,node.style.mutable_placeholder_pseudo(),declaration,
variables,result,[](bool) {});
observe(declaration,result);
}
else if(kind>=3) apply_scrollbar_declaration(node,kind,declaration,variables);
else {
auto& pseudo=kind==1?node.style.mutable_before_pseudo():node.style.mutable_after_pseudo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ inline int split_pseudo_element_selector(const std::string& selector, std::strin
};
if (const auto kind = split_suffix("::before", 1); kind != 0) return kind;
if (const auto kind = split_suffix("::after", 2); kind != 0) return kind;
if (const auto kind = split_suffix("::placeholder", 8); kind != 0) return kind;
if (const auto kind = split_suffix("::backdrop", 7); kind != 0) return kind;
if (const auto kind = split_suffix("::-webkit-scrollbar-thumb", 4); kind != 0) return kind;
if (const auto kind = split_suffix("::-webkit-scrollbar-track", 5); kind != 0) return kind;
Expand All @@ -36,6 +37,66 @@ inline int split_pseudo_element_selector(const std::string& selector, std::strin
if (const auto kind = split_suffix(":before", 1); kind != 0) return kind;
return split_suffix(":after", 2);
}

template<typename Decision,typename Resolved>
void apply_placeholder_declaration(
dom_node& node,
node_style::pseudo_element_pair::placeholder_element& placeholder,
const css_declaration& declaration,
const std::unordered_map<std::string,std::string>& variables,
Decision& decision,
Resolved&& on_resolved)
{
decision.classification = "unsupported";
const auto contains_variable = declaration.value.find("var(") != std::string::npos;
auto resolved_value = std::string{};
const auto& value = contains_variable
? (resolved_value = resolve_value(node,declaration.value,variables))
: declaration.value;
if (value.empty() && contains_variable) {
decision.classification = "invalid-authoring";
decision.semantic_slice = "unresolved custom property at computed-value time";
return;
}
on_resolved(contains_variable);
const auto lower = ascii_lower(trim_value(value));
if (declaration.name == "color") {
if (lower == "currentcolor" || lower == "inherit" || lower == "unset") {
placeholder.foreground_specified = false;
placeholder.foreground_rgba = 0U;
decision.classification = "supported";
} else {
const auto color = native_document::parse_color(value);
if (is_explicit_color_token(value,color)) {
placeholder.foreground_specified = true;
placeholder.foreground_rgba = color;
decision.classification = "supported";
} else {
decision.classification = "invalid-authoring";
}
}
} else if (declaration.name == "opacity") {
if (lower == "initial" || lower == "unset" || lower == "revert") {
placeholder.opacity = 1;
decision.classification = "supported";
return;
}
if (lower == "inherit") {
placeholder.opacity = std::clamp(node.style.opacity, 0.0F, 1.0F);
decision.classification = "supported";
return;
}
char* end = nullptr;
const auto parsed = std::strtof(lower.c_str(), &end);
if (end != lower.c_str() && end == lower.c_str() + lower.size()
&& std::isfinite(parsed)) {
placeholder.opacity = std::clamp(parsed, 0.0F, 1.0F);
decision.classification = "supported";
} else {
decision.classification = "invalid-authoring";
}
}
}
inline void apply_scrollbar_declaration(
dom_node& node,
int pseudo_kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void for_each_cascaded_pseudo_declaration(
// kind prevents a high-priority ::before declaration from affecting
// ::after while reusing the same layer/importance/rollback machinery
// as the originating element.
std::array<std::vector<const css_rule*>, 8> rules_by_kind;
std::array<std::vector<const css_rule*>, 9> rules_by_kind;
for (const auto& [kind, rule] : matched_rules) {
if (kind > 0 && static_cast<size_t>(kind) < rules_by_kind.size())
rules_by_kind[static_cast<size_t>(kind)].push_back(rule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,15 @@ struct node_style final {
};

struct pseudo_element_pair final {
struct placeholder_element final {
uint32_t foreground_rgba{0};
float opacity{1};
bool foreground_specified{false};
};

pseudo_element before;
pseudo_element after;
placeholder_element placeholder;
};

const pseudo_element& before_pseudo() const noexcept
Expand All @@ -600,6 +607,18 @@ struct node_style final {
return pseudo_elements->after;
}

const pseudo_element_pair::placeholder_element& placeholder_pseudo() const noexcept
{
static const pseudo_element_pair::placeholder_element empty;
return pseudo_elements == nullptr ? empty : pseudo_elements->placeholder;
}

pseudo_element_pair::placeholder_element& mutable_placeholder_pseudo()
{
ensure_unique_pseudo_elements();
return pseudo_elements->placeholder;
}

void clear_pseudo_elements() noexcept
{
pseudo_elements.reset();
Expand Down Expand Up @@ -959,10 +978,10 @@ struct node_style final {
}
}

// Generated pseudo-elements are absent from most DOM nodes. Keeping two
// complete pseudo boxes inline cost 496 bytes on every element. Copy-on-
// write preserves cheap style cloning while paying for this cold state
// only when ::before or ::after participates in the cascade.
// Generated pseudo-elements and authored placeholder paint are absent from
// most DOM nodes. Keeping complete pseudo boxes inline cost 496 bytes on
// every element. Copy-on-write preserves cheap style cloning while paying
// for this cold state only when a supported pseudo participates in cascade.
std::shared_ptr<pseudo_element_pair> pseudo_elements;
// Transition/keyframe state is similarly cold. A complete animation_data
// block is retained only for styles that author transition/animation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,18 @@ void native_document::append_scene(
if (!node.form_control().value.empty() || show_placeholder) {
const auto painted_value = resolved_text_transform(
node, show_placeholder ? placeholder->second : node.form_control().value);
auto text_color = resolved_foreground(node);
if (show_placeholder) {
const auto& placeholder_style = node.style.placeholder_pseudo();
if (placeholder_style.foreground_specified)
text_color = placeholder_style.foreground_rgba;
const auto alpha = static_cast<uint32_t>(std::clamp(
std::lround(static_cast<float>(text_color & 0xFFU)
* placeholder_style.opacity),
0L,
255L));
text_color = (text_color & 0xFFFFFF00U) | alpha;
}
std::ostringstream resource;
resource << font_size << '\t' << line_height << '\t'
<< resolved_font_weight(node) << '\t' << "start" << '\t'
Expand All @@ -2843,7 +2855,7 @@ void native_document::append_scene(
text_y,
text_width,
line_height,
with_opacity(resolved_foreground(node)),
with_opacity(text_color),
node.id,
resolved_letter_spacing(node),
resolved_word_spacing(node),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
});
}

void apply_placeholder_css_declaration(
dom_node& node,
node_style::pseudo_element_pair::placeholder_element& placeholder,
const css_declaration& declaration)
{
feature_decision decision(
*this,
"css",
"placeholder-property:" + declaration.name,
"pseudo-style-application");
css::apply_placeholder_declaration(
node,placeholder,declaration,css_variables,decision,
[&](bool contains_variable) {
if(contains_variable && is_paint_property(declaration.name))
record_composition("css-custom-property-to-paint",node.id);
});
}

static std::optional<std::string> first_css_url(const std::string& value)
{ return css::first_css_url(value); }

Expand Down Expand Up @@ -388,6 +406,11 @@
node,declaration,css_variables,backdrop_important);
return;
}
if (pseudo_kind == 8) {
apply_placeholder_css_declaration(
node,node.style.mutable_placeholder_pseudo(),declaration);
return;
}
if (pseudo_kind >= 3 && pseudo_kind <= 6) {
apply_scrollbar_css_declaration(node, pseudo_kind, declaration);
return;
Expand Down Expand Up @@ -603,6 +626,11 @@
node,declaration,css_variables,backdrop_important);
return;
}
if (pseudo_kind == 8) {
apply_placeholder_css_declaration(
node,node.style.mutable_placeholder_pseudo(),declaration);
return;
}
if (pseudo_kind >= 3 && pseudo_kind <= 6) {
apply_scrollbar_css_declaration(node, pseudo_kind, declaration);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,15 @@
|| name == "before" || name == "after"
|| name == "first-letter" || name == "first-line";
if (pseudo_element) {
const auto supported = name == "before" || name == "after"
|| name == "selection" || name == "placeholder"
|| name == "backdrop" || name == "-webkit-scrollbar"
|| name == "-webkit-scrollbar-thumb"
|| name == "-webkit-scrollbar-track"
|| name == "-webkit-scrollbar-corner";
record_selector_feature(
"selector:pseudo-element:" + name,
name == "before" || name == "after" ? "supported" : "unsupported");
supported ? "supported" : "unsupported");
} else {
static const std::unordered_set<std::string> supported_pseudo_classes{
"root", "first-child", "last-child", "only-child",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,61 @@ void test_modal_backdrop_scene(webscene_engine* engine)
execute(engine,"document.body.innerHTML='';","backdrop-cleanup.js");
}

void test_placeholder_pseudo_color_and_opacity_reach_scene(webscene_engine* engine)
{
resize(engine,320,120,1);
execute(engine,R"JS(
document.body.innerHTML=`
<style>
:root { --placeholder-tone:#2468ac; }
#placeholder-probe::placeholder {
color:var(--placeholder-tone);
opacity:.5;
}
#placeholder-probe.alternate::placeholder {
color:#112233;
opacity:1;
}
</style>
<input id="placeholder-probe" placeholder="Search workspace">
`;
globalThis.placeholderProbe=document.getElementById('placeholder-probe');
)JS","placeholder-pseudo-setup.js");
uint64_t revision=0;
const auto expect_color=[&](uint32_t expected,bool present) {
webscene_engine_request_scene_checkpoint(engine);
for(int attempt=0;attempt<100;++attempt) {
const auto* scene=webscene_engine_acquire_latest_scene(engine);
bool matched=false;
if(scene) {
if(scene->header.revision>revision) {
unsigned count=0;
for(uint32_t i=0;i<scene->header.command_count;++i) {
const auto& command=scene->commands[i];
if(command.kind==3U && command.rgba==expected)++count;
}
matched=count==(present?1U:0U);
if(matched)revision=scene->header.revision;
}
webscene_scene_acknowledge(scene);webscene_scene_release(scene);
}
if(matched)return;
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
fail("placeholder pseudo color/opacity did not reach retained scene");
};
expect_color(0x2468AC80U,true);
execute(engine,"placeholderProbe.className='alternate';","placeholder-pseudo-class.js");
expect_color(0x112233FFU,true);
execute(engine,"placeholderProbe.value='typed';","placeholder-pseudo-value.js");
expect_color(0x112233FFU,false);
execute(engine,
"placeholderProbe.value='';placeholderProbe.className='';",
"placeholder-pseudo-restore.js");
expect_color(0x2468AC80U,true);
execute(engine,"document.body.innerHTML='';","placeholder-pseudo-cleanup.js");
}

void test_responsive_positioned_sizing(webscene_engine* engine)
{
resize(engine, 1280, 720, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ int main()
test_modal_backdrop_scene(focused_engine);
webscene_engine_destroy(focused_engine);return 0;
}
if(selected=="placeholder-pseudo") {
auto* focused_engine=webscene_engine_create(0);
require(focused_engine!=nullptr,"placeholder pseudo engine creation failed");
test_placeholder_pseudo_color_and_opacity_reach_scene(focused_engine);
webscene_engine_destroy(focused_engine);return 0;
}
if (selected == "fragment-attach") {
auto* focused_engine = webscene_engine_create(0);
require(focused_engine != nullptr, "fragment attach engine creation failed");
Expand Down Expand Up @@ -1361,6 +1367,7 @@ int main()
test_dimension_custom_property_inheritance(engine);
test_geometry_variable_positions(engine);
test_modal_backdrop_scene(engine);
test_placeholder_pseudo_color_and_opacity_reach_scene(engine);
test_responsive_positioned_sizing(engine);
test_compact_go_to_fixed_grid_tracks_preserve_trailing_space(engine);
test_named_grid_template_areas_layout_cssom_and_mutation(engine);
Expand Down
Loading
Loading