Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

feat(cssom): expose missing properties with CSS-wide keywords

ldm07fc70a24090b
diff --git a/moli-renderer-v8/src/context_bootstrap/css_runtime/supports.rs b/moli-renderer-v8/src/context_bootstrap/css_runtime/supports.rs
index 65f62843c..3d7379293 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_runtime/supports.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_runtime/supports.rs
@@ -84,7 +84,9 @@ fn eval_stylo_supports_condition(condition: &SupportsCondition, context: &Parser
SupportsCondition::Or(conditions) => conditions
.iter()
.any(|condition| eval_stylo_supports_condition(condition, context)),
- SupportsCondition::Declaration(declaration) => declaration.eval(context),
+ SupportsCondition::Declaration(declaration) => {
+ shell_supports_declaration(&declaration.0).unwrap_or_else(|| declaration.eval(context))
+ }
SupportsCondition::Selector(selector) => selector.eval(context),
SupportsCondition::FontFormat(_) | SupportsCondition::FontTech(_) => {
let css = condition.to_css_string();
@@ -96,6 +98,27 @@ fn eval_stylo_supports_condition(condition: &SupportsCondition, context: &Parser
}
}
+fn shell_supports_declaration(declaration: &str) -> Option<bool> {
+ let mut input = ParserInput::new(declaration);
+ let mut parser = Parser::new(&mut input);
+ let property = parser.expect_ident_cloned().ok()?;
+ let property = crate::css_style::canonical_style_property_name(&property);
+ if !crate::detached_css_style::css_style_declaration_is_shell_property(&property) {
+ return None;
+ }
+ if parser.expect_colon().is_err() {
+ return Some(false);
+ }
+ let supported = parser
+ .parse_until_before(cssparser::Delimiter::Bang, |input| {
+ style::properties::CSSWideKeyword::parse(input)
+ .map_err(|()| input.new_custom_error::<(), ()>(()))
+ })
+ .is_ok();
+ let _ = parser.try_parse(cssparser::parse_important);
+ Some(supported && parser.expect_exhausted().is_ok())
+}
+
fn with_stylo_supports_context<R>(f: impl FnOnce(&ParserContext) -> R) -> Option<R> {
crate::style_engine::ensure_stylo_browser_compat_prefs();
let base_url = url::Url::parse("about:blank").ok()?;
diff --git a/moli-renderer-v8/src/context_bootstrap/css_runtime/supports/properties.rs b/moli-renderer-v8/src/context_bootstrap/css_runtime/supports/properties.rs
index 12b6aa573..154beed06 100644
--- a/moli-renderer-v8/src/context_bootstrap/css_runtime/supports/properties.rs
+++ b/moli-renderer-v8/src/context_bootstrap/css_runtime/supports/properties.rs
@@ -42,6 +42,10 @@ pub(in crate::context_bootstrap::css_runtime::supports) fn css_supports_property
return false;
}
+ if crate::detached_css_style::css_style_declaration_is_shell_property(&canonical_property) {
+ return crate::css_style::parse_css_style_shell_keyword(value_trimmed).is_some();
+ }
+
if super::stylo_supports_property_value(&canonical_property, value_trimmed) {
return true;
}
diff --git a/moli-renderer-v8/src/css_style.rs b/moli-renderer-v8/src/css_style.rs
index 6e0d64789..8ee249692 100644
--- a/moli-renderer-v8/src/css_style.rs
+++ b/moli-renderer-v8/src/css_style.rs
@@ -20,6 +20,14 @@ pub(crate) fn stylo_property_is_chromium_exposed(name: &str) -> bool {
&& !matches!(name, "mask-position-x" | "mask-position-y")
}
+pub(crate) fn parse_css_style_shell_keyword(value: &str) -> Option<&'static str> {
+ let mut input = ParserInput::new(value);
+ let mut parser = Parser::new(&mut input);
+ let keyword = style::properties::CSSWideKeyword::parse(&mut parser).ok()?;
+ parser.expect_exhausted().ok()?;
+ Some(keyword.to_str())
+}
+
#[derive(webidl::WebIdlArgs)]
#[webidl(prefix = "CSSStyleDeclaration.item")]
pub(crate) struct CssStyleDeclarationItemArgs {
diff --git a/moli-renderer-v8/src/detached_css_style.rs b/moli-renderer-v8/src/detached_css_style.rs
index 953032e3b..72e1de03c 100644
--- a/moli-renderer-v8/src/detached_css_style.rs
+++ b/moli-renderer-v8/src/detached_css_style.rs
@@ -14,7 +14,7 @@ use super::{
CssStyleDeclarationSetPropertyArgs, CssStyleEntry as StyleEntry,
camel_case_style_property_name, canonical_style_property_identifier,
canonical_style_property_name, mask_compat_property_name, mask_compat_value_is_supported,
- parse_css_declaration_list, serialize_css_style_entries,
+ parse_css_declaration_list, parse_css_style_shell_keyword, serialize_css_style_entries,
serialize_css_style_entries_with_pdb_block, stylo_declaration_block_property_names,
stylo_mask_property_name, top_level_comma_separated_component_values,
webkit_transform_origin_compat_property_name,
@@ -544,6 +544,80 @@ const CSS_STYLE_DECLARATION_WEBKIT_ALIASES: &[&str] = &[
"webkitUserSelect",
];
+// CSSOM shells accept CSS-wide keywords through the shared token parser.
+// Property-specific value grammars and layout behavior remain pending.
+const CSS_STYLE_DECLARATION_SHELL_PROPERTIES: &[&str] = &[
+ "-webkit-app-region",
+ "-webkit-border-before",
+ "-webkit-border-horizontal-spacing",
+ "-webkit-border-vertical-spacing",
+ "-webkit-box-reflect",
+ "-webkit-column-break-after",
+ "-webkit-column-break-before",
+ "-webkit-column-break-inside",
+ "-webkit-locale",
+ "-webkit-logical-height",
+ "-webkit-logical-width",
+ "-webkit-max-logical-height",
+ "-webkit-max-logical-width",
+ "-webkit-min-logical-height",
+ "-webkit-min-logical-width",
+ "-webkit-perspective-origin-x",
+ "-webkit-perspective-origin-y",
+ "-webkit-rtl-ordering",
+ "-webkit-tap-highlight-color",
+ "-webkit-text-combine",
+ "-webkit-text-decorations-in-effect",
+ "-webkit-transform-origin-x",
+ "-webkit-transform-origin-y",
+ "-webkit-transform-origin-z",
+ "-webkit-user-drag",
+ "animation-trigger",
+ "buffered-rendering",
+ "caret-shape",
+ "column-rule-break",
+ "column-rule-inset",
+ "column-rule-inset-cap-end",
+ "column-rule-inset-cap-start",
+ "column-rule-inset-junction",
+ "column-rule-inset-junction-end",
+ "column-rule-inset-start",
+ "column-wrap",
+ "dynamic-range-limit",
+ "font-optical-sizing",
+ "interactivity",
+ "interest-delay-end",
+ "interest-delay-start",
+ "object-view-box",
+ "row-rule-break",
+ "row-rule-color",
+ "row-rule-inset-cap",
+ "row-rule-inset-cap-start",
+ "row-rule-inset-end",
+ "row-rule-inset-junction-end",
+ "row-rule-inset-junction-start",
+ "row-rule-style",
+ "row-rule-width",
+ "rule",
+ "rule-color",
+ "rule-inset-cap",
+ "rule-inset-end",
+ "rule-inset-start",
+ "rule-overlap",
+ "rule-visibility-items",
+ "rule-width",
+ "scroll-marker-group",
+ "speak",
+ "text-fit",
+ "text-spacing-trim",
+ "timeline-trigger",
+ "timeline-trigger-activation-range-end",
+ "timeline-trigger-active-range",
+ "timeline-trigger-active-range-end",
+ "timeline-trigger-name",
+ "timeline-trigger-source",
+];
+
static CSS_STYLE_DECLARATION_EXPOSED_PROPERTY_NAMES: LazyLock<HashSet<String>> =
LazyLock::new(|| {
let mut names = HashSet::new();
@@ -575,6 +649,18 @@ pub(crate) fn css_style_declaration_standard_property_names() -> &'static [&'sta
}
fn for_each_css_style_declaration_exposed_property_name(visit: &mut impl FnMut(&str)) {
+ for_each_css_style_declaration_implemented_property_name(visit);
+ for property in CSS_STYLE_DECLARATION_SHELL_PROPERTIES {
+ for_each_css_property_accessor_name(property, visit);
+ }
+}
+
+pub(crate) fn css_style_declaration_is_shell_property(property: &str) -> bool {
+ CSS_STYLE_DECLARATION_SHELL_PROPERTIES.contains(&property)
+ && !css_style_declaration_standard_property_names().contains(&property)
+}
+
+fn for_each_css_style_declaration_implemented_property_name(visit: &mut impl FnMut(&str)) {
let mut seen = HashSet::new();
for name in css_style_declaration_standard_property_names() {
for_each_css_property_accessor_name(name, &mut |name| {
@@ -678,7 +764,8 @@ fn lowercase_ascii_head(input: &str) -> String {
fn all_shorthand_applies_to(property: &str) -> bool {
!property.starts_with("--")
&& !matches!(property, "all" | "direction" | "unicode-bidi")
- && css_style_declaration_standard_property_names().contains(&property)
+ && (css_style_declaration_standard_property_names().contains(&property)
+ || css_style_declaration_is_shell_property(property))
}
fn css_wide_keyword(value: &str) -> Option<String> {
@@ -774,6 +861,13 @@ pub(crate) fn install_css_style_declaration_template_bindings<'s>(
}
"CSSStyleProperties" => {
install_lightweight_css_style_prototype_template(scope, prototype, true);
+ for property in CSS_STYLE_DECLARATION_SHELL_PROPERTIES {
+ for_each_css_property_accessor_name(property, &mut |name| {
+ install_lightweight_style_named_property_template_accessor(
+ scope, prototype, name,
+ );
+ });
+ }
}
"CSSFontFaceDescriptors" => {
install_lightweight_css_style_prototype_template(scope, prototype, true);
@@ -1003,7 +1097,7 @@ fn install_lightweight_style_property_template_accessors<'s>(
scope: &mut v8::PinScope<'s, '_, ()>,
target: v8::Local<'s, v8::ObjectTemplate>,
) {
- for_each_css_style_declaration_exposed_property_name(&mut |name| {
+ for_each_css_style_declaration_implemented_property_name(&mut |name| {
install_lightweight_style_named_property_template_accessor(scope, target, name);
});
}
@@ -2409,6 +2503,9 @@ fn normalize_style_entry_value<'s>(
if keyframe_style_property_write_is_ignored(scope, style, name) {
return None;
}
+ if css_style_declaration_is_shell_property(name) && !value.is_empty() {
+ return parse_css_style_shell_keyword(value).map(str::to_owned);
+ }
// Empty text removes the declaration; it is not a keyword to parse.
if name == "all" && !value.is_empty() {
return css_wide_keyword(value);
@@ -3069,6 +3166,7 @@ mod tests {
fn scanned_css_style_declaration_exposes_property_name(property: &str) -> bool {
css_style_declaration_standard_property_names()
.iter()
+ .chain(CSS_STYLE_DECLARATION_SHELL_PROPERTIES)
.any(|name| scanned_css_property_accessor_exposes_name(name, property))
|| CSS_STYLE_DECLARATION_PROPERTY_ALIASES
.iter()
@@ -3102,6 +3200,7 @@ mod tests {
let mut probes = HashSet::new();
for property in css_style_declaration_standard_property_names()
.iter()
+ .chain(CSS_STYLE_DECLARATION_SHELL_PROPERTIES)
.chain(CSS_STYLE_DECLARATION_PROPERTY_ALIASES)
{
add_accessor_name_probes(&mut probes, property);
diff --git a/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/declaration_parser.rs b/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/declaration_parser.rs
index 6b0a5dee4..c87f7980b 100644
--- a/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/declaration_parser.rs
+++ b/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/declaration_parser.rs
@@ -38,6 +38,18 @@ pub(crate) fn parse_style_property_entries_with_base(
return None;
}
+ if crate::detached_css_style::css_style_declaration_is_shell_property(&name) {
+ let value = crate::css_style::parse_css_style_shell_keyword(value)?;
+ return Some(ParsedStylePropertyEntries {
+ entries: vec![StyleEntry {
+ name: name.clone(),
+ value: value.to_owned(),
+ priority,
+ }],
+ affected_names: vec![name],
+ });
+ }
+
if mask_compat_property_name(&name)
&& !stylo_mask_property_name(&name)
&& !mask_compat_value_is_supported(&name, value)
diff --git a/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/pdb_compat.rs b/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/pdb_compat.rs
index 3c338b061..cba640f4f 100644
--- a/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/pdb_compat.rs
+++ b/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse/pdb_compat.rs
@@ -206,6 +206,9 @@ pub(super) fn style_entries_affecting_property(
pub(super) fn cssom_style_property_write_uses_pdb(name: &str, value: &str) -> bool {
let name = canonical_style_property_name(name);
+ if crate::detached_css_style::css_style_declaration_is_shell_property(&name) {
+ return false;
+ }
if moli_css_parse::is_cssom_custom_property_name(&name) {
return !value.is_empty() && stylo_pdb_entries_for_property(&name, value, false).is_some();
}
@@ -257,6 +260,9 @@ pub(crate) fn cssom_style_property_write_can_use_pdb_storage(name: &str, value:
return true;
}
let name = canonical_style_property_name(name);
+ if crate::detached_css_style::css_style_declaration_is_shell_property(&name) {
+ return false;
+ }
if cssom_border_image_reset_value_uses_pdb_storage(&name, value) {
return true;
}
@@ -415,6 +421,9 @@ pub(super) fn cssom_style_shorthand_query_uses_pdb(name: &str) -> bool {
pub(super) fn cssom_style_property_write_requires_legacy_parser(name: &str, value: &str) -> bool {
let canonical_name = canonical_style_property_name(name);
+ if crate::detached_css_style::css_style_declaration_is_shell_property(&canonical_name) {
+ return true;
+ }
// Stylo's typed transform-origin value cannot preserve whether an authored
// zero depth was omitted. Chromium serializes `20px 30px` and
// `20px 30px 0px` differently. The prefixed mask aliases likewise project
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/css_property_shells.js b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/css_property_shells.js
new file mode 100644
index 000000000..4ed2a48b4
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/css_property_shells.js
@@ -0,0 +1,47 @@
+(() => {
+ function assert(ok, message) { if (!ok) throw new Error(message); }
+ const styles = [
+ document.createElement('div').style,
+ document.implementation.createHTMLDocument('').createElement('div').style
+ ];
+ for (const style of styles) for (const [property, alias] of [
+ ['timeline-trigger', 'timelineTrigger'],
+ ['font-optical-sizing', 'fontOpticalSizing'],
+ ['-webkit-locale', 'webkitLocale']
+ ]) {
+ assert(property in style && alias in style, 'property accessors');
+ for (const keyword of ['initial', 'inherit', 'unset', 'revert', 'revert-layer']) {
+ assert(CSS.supports(property, keyword), 'CSS-wide keyword support');
+ assert(CSS.supports(`(${property}: ${keyword})`), 'condition support');
+ assert(CSS.supports(`(${property}: ${keyword} !important)`), 'condition priority');
+ style.setProperty(property, keyword, 'important');
+ assert(style.getPropertyValue(property) === keyword, 'stored keyword');
+ assert(style[alias] === keyword, 'alias getter');
+ assert(style.getPropertyPriority(property) === 'important', 'priority');
+ style[alias] = keyword;
+ assert(style.getPropertyPriority(property) === '', 'IDL setter priority');
+ }
+ for (const value of ['unsupported-value', 'initial inherit', 'var(--unimplemented)', 'initial; color: red']) {
+ assert(!CSS.supports(property, value), 'unsupported grammar rejected');
+ assert(!CSS.supports(`(${property}: ${value})`), 'unsupported condition rejected');
+ style.setProperty(property, value);
+ assert(style.getPropertyValue(property) === 'revert-layer', 'invalid write preserved value');
+ }
+ style[alias] = '/**/IN\\69 TIAL/**/';
+ assert(style[property] === 'initial', 'shared CSS token parser');
+ assert(CSS.supports(property, '/**/IN\\69 TIAL/**/'), 'escaped keyword support');
+ assert(!CSS.supports(property, 'initial !important'), 'priority forbidden in value pair');
+ assert(CSS.supports(`(not (${property}: unsupported-value)) and (${property}: inherit)`), 'condition boolean evaluation');
+ assert(style.removeProperty(property) === 'initial', 'remove keyword');
+ assert(style[property] === '', 'empty after remove');
+ }
+ for (const style of styles) {
+ // Already implemented native grammars remain available alongside the shells.
+ for (const [property, value] of [['width', '12px'], ['opacity', '0.5'], ['font-size', '16px']]) {
+ assert(CSS.supports(property, value), 'implemented grammar preserved: ' + property);
+ style.setProperty(property, value);
+ assert(style.getPropertyValue(property) === value, 'implemented native value preserved: ' + property);
+ }
+ }
+ return true;
+})()
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/declaration_aliases.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/declaration_aliases.rs
index 6c7c0d976..9d26b96a5 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/declaration_aliases.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/cssom/extracted/declaration_aliases.rs
@@ -1,5 +1,17 @@
use super::*;
+#[test]
+fn css_property_shells_keep_supports_and_declarations_consistent() {
+ let mut vm = new_parsed_test_vm(
+ "https://css-property-shells.test/",
+ "<!doctype html><body></body>",
+ );
+ assert_eq!(
+ vm.eval(include_str!("css_property_shells.js")).unwrap(),
+ "true"
+ );
+}
+
#[test]
fn css_style_declaration_exposes_compat_webkit_aliases() {
let mut vm = new_storage_test_vm("https://css-style-webkit-aliases.test/");