Support exporting shadow parts with the exportparts attribute (#37345)

The attribute is implemented as a new `AttrValue` variant containing the
mappings of exported part names
(https://github.com/servo/stylo/pull/197).

Take a look at the [MDN
page](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/exportparts)
for more information about the attribute.


Testing: Covered by WPT
Fixes: https://github.com/servo/servo/issues/35349

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-06-13 13:32:20 +02:00 committed by GitHub
parent 730fe35b42
commit 6cac782fb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 42 additions and 45 deletions

24
Cargo.lock generated
View file

@ -6687,7 +6687,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.28.0" version = "0.28.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cssparser", "cssparser",
@ -6982,7 +6982,7 @@ dependencies = [
[[package]] [[package]]
name = "servo_arc" name = "servo_arc"
version = "0.4.1" version = "0.4.1"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"serde", "serde",
"stable_deref_trait", "stable_deref_trait",
@ -7446,7 +7446,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo" name = "stylo"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"app_units", "app_units",
"arrayvec", "arrayvec",
@ -7503,7 +7503,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo_atoms" name = "stylo_atoms"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"string_cache", "string_cache",
"string_cache_codegen", "string_cache_codegen",
@ -7512,12 +7512,12 @@ dependencies = [
[[package]] [[package]]
name = "stylo_config" name = "stylo_config"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
[[package]] [[package]]
name = "stylo_derive" name = "stylo_derive"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -7529,7 +7529,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo_dom" name = "stylo_dom"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"stylo_malloc_size_of", "stylo_malloc_size_of",
@ -7538,7 +7538,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo_malloc_size_of" name = "stylo_malloc_size_of"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"app_units", "app_units",
"cssparser", "cssparser",
@ -7555,12 +7555,12 @@ dependencies = [
[[package]] [[package]]
name = "stylo_static_prefs" name = "stylo_static_prefs"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
[[package]] [[package]]
name = "stylo_traits" name = "stylo_traits"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"app_units", "app_units",
"bitflags 2.9.1", "bitflags 2.9.1",
@ -7969,7 +7969,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "to_shmem" name = "to_shmem"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"cssparser", "cssparser",
"servo_arc", "servo_arc",
@ -7982,7 +7982,7 @@ dependencies = [
[[package]] [[package]]
name = "to_shmem_derive" name = "to_shmem_derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29" source = "git+https://github.com/servo/stylo?branch=2025-05-01#3a3663a3199282cb06889e48a427db76f320ddc3"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",

View file

@ -225,14 +225,14 @@ codegen-units = 1
# Or for Stylo: # Or for Stylo:
# #
# [patch."https://github.com/servo/stylo"] # [patch."https://github.com/servo/stylo"]
# selectors = { path = "../stylo/selectors" } # selectors = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# servo_arc = { path = "../stylo/servo_arc" } # servo_arc = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# stylo = { path = "../stylo/style" } # stylo = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# stylo_atoms = { path = "../stylo/stylo_atoms" } # stylo_atoms = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# stylo_config = { path = "../stylo/stylo_config" } # stylo_config = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# stylo_dom = { path = "../stylo/stylo_dom" } # stylo_dom = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# stylo_malloc_size_of = { path = "../stylo/malloc_size_of" } # stylo_malloc_size_of = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# stylo_traits = { path = "../stylo/style_traits" } # stylo_traits = { git = "https://github.com/simonwuelker/stylo", branch = "shadow-parts-exportparts" }
# #
# Or for WebRender: # Or for WebRender:
# #

View file

@ -4226,6 +4226,7 @@ impl VirtualMethods for Element {
local_name!("class") | local_name!("part") => { local_name!("class") | local_name!("part") => {
AttrValue::from_serialized_tokenlist(value.into()) AttrValue::from_serialized_tokenlist(value.into())
}, },
local_name!("exportparts") => AttrValue::from_shadow_parts(value.into()),
_ => self _ => self
.super_type() .super_type()
.unwrap() .unwrap()

View file

@ -307,6 +307,21 @@ impl<'dom> style::dom::TElement for ServoLayoutElement<'dom> {
} }
} }
fn each_exported_part<F>(&self, name: &AtomIdent, callback: F)
where
F: FnMut(&AtomIdent),
{
let Some(exported_parts) = self
.element
.get_attr_for_layout(&ns!(), &local_name!("exportparts"))
else {
return;
};
exported_parts
.as_shadow_parts()
.for_each_exported_part(AtomIdent::cast(name), callback);
}
fn has_dirty_descendants(&self) -> bool { fn has_dirty_descendants(&self) -> bool {
unsafe { unsafe {
self.as_node() self.as_node()
@ -751,8 +766,12 @@ impl<'dom> ::selectors::Element for ServoLayoutElement<'dom> {
) )
} }
fn imported_part(&self, _: &AtomIdent) -> Option<AtomIdent> { fn imported_part(&self, name: &AtomIdent) -> Option<AtomIdent> {
None self.element
.get_attr_for_layout(&ns!(), &local_name!("exportparts"))?
.as_shadow_parts()
.imported_part(name)
.map(|import| AtomIdent::new(import.clone()))
} }
#[inline] #[inline]

View file

@ -1,3 +0,0 @@
[both-part-and-exportparts.html]
[::part() rules match elements having both @part and @exportparts]
expected: FAIL

View file

@ -1,3 +0,0 @@
[double-forward.html]
[Part in inner host is forwarded through the middle host for styling by document style sheet]
expected: FAIL

View file

@ -1,2 +0,0 @@
[exportparts-different-scope.html]
expected: FAIL

View file

@ -1,3 +0,0 @@
[exportparts-multiple.html]
[Forwarding part under multiple names should work]
expected: FAIL

View file

@ -1,3 +0,0 @@
[invalidation-complex-selector-forward.html]
[Part in selected host changed color]
expected: FAIL

View file

@ -1,3 +0,0 @@
[precedence-part-vs-part.html]
[Style from document overrides style from outer CE]
expected: FAIL

View file

@ -1,3 +0,0 @@
[simple-forward-shorthand.html]
[Part in inner host is forwarded, under the same name, for styling by document style sheet]
expected: FAIL

View file

@ -1,3 +0,0 @@
[simple-forward.html]
[Part in inner host is forwarded for styling by document style sheet]
expected: FAIL