script: Implement CSS.registerProperty (#38682)

The implementation is mostly equivalent to
https://searchfox.org/mozilla-central/source/servo/ports/geckolib/glue.rs#9480.

Testing: New web platform tests start to pass

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-08-14 15:34:02 +02:00 committed by GitHub
parent 3a0e8fefde
commit 43da933247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 185 additions and 46 deletions

View file

@ -54,7 +54,7 @@ use style::media_queries::Device;
use style::properties::PropertyId;
use style::properties::style_structs::Font;
use style::selector_parser::{PseudoElement, RestyleDamage, Snapshot};
use style::stylesheets::Stylesheet;
use style::stylesheets::{Stylesheet, UrlExtraData};
use style_traits::CSSPixel;
use webrender_api::units::{DeviceIntSize, LayoutPoint, LayoutVector2D};
use webrender_api::{ExternalScrollId, ImageKey};
@ -206,6 +206,24 @@ pub struct LayoutConfig {
pub theme: Theme,
}
pub struct PropertyRegistration {
pub name: String,
pub syntax: String,
pub initial_value: Option<String>,
pub inherits: bool,
pub url_data: UrlExtraData,
}
#[derive(Debug)]
pub enum RegisterPropertyError {
InvalidName,
AlreadyRegistered,
InvalidSyntax,
InvalidInitialValue,
InitialValueNotComputationallyIndependent,
NoInitialValue,
}
pub trait LayoutFactory: Send + Sync {
fn create(&self, config: LayoutConfig) -> Box<dyn Layout>;
}
@ -299,6 +317,10 @@ pub trait Layout {
point: LayoutPoint,
flags: ElementsFromPointFlags,
) -> Vec<ElementsFromPointResult>;
fn register_custom_property(
&mut self,
property_registration: PropertyRegistration,
) -> Result<(), RegisterPropertyError>;
}
/// This trait is part of `layout_api` because it depends on both `script_traits`