Implement shadow dom slots (#35013)

* Implement slot-related algorithms

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Hook up slot elements to DOM creation logic

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Set a slot assignment mode for servo-internal shadow roots

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Assign slots when a slottable's slot attribute changes

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Properly compute slot name

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* ./mach test-tidy

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update <slot> name when name attribute changes

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Implement fast path for Node::assign_slottables_for_a_tree

assign_slottables_for_a_tree traverses all descendants of the node
and is potentially very expensive. If the node is not a shadow root
then assigning slottables to it won't have any effect, so we
take a fast path out.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Move slottable data into ElementRareData

This shrinks all element descendants back to their
original size.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Address review comments

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-01-19 15:05:05 +01:00 committed by GitHub
parent 8bb50fa3c9
commit dabe162d44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 758 additions and 355 deletions

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::RefCell;
use dom_struct::dom_struct;
use js::rust::HandleObject;
@ -12,10 +14,12 @@ use crate::dom::bindings::codegen::Bindings::TextBinding::TextMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::characterdata::CharacterData;
use crate::dom::document::Document;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlslotelement::{HTMLSlotElement, Slottable, SlottableData};
use crate::dom::node::Node;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
@ -24,12 +28,14 @@ use crate::script_runtime::CanGc;
#[dom_struct]
pub(crate) struct Text {
characterdata: CharacterData,
slottable_data: RefCell<SlottableData>,
}
impl Text {
pub(crate) fn new_inherited(text: DOMString, document: &Document) -> Text {
Text {
characterdata: CharacterData::new_inherited(text, document),
slottable_data: Default::default(),
}
}
@ -50,6 +56,10 @@ impl Text {
can_gc,
)
}
pub(crate) fn slottable_data(&self) -> &RefCell<SlottableData> {
&self.slottable_data
}
}
impl TextMethods<crate::DomTypeHolder> for Text {
@ -119,4 +129,14 @@ impl TextMethods<crate::DomTypeHolder> for Text {
}
DOMString::from(text)
}
/// <https://dom.spec.whatwg.org/#dom-slotable-assignedslot>
fn GetAssignedSlot(&self) -> Option<DomRoot<HTMLSlotElement>> {
let cx = GlobalScope::get_cx();
// > The assignedSlot getter steps are to return the result of
// > find a slot given this and with the open flag set.
rooted!(in(*cx) let slottable = Slottable::Text(Dom::from_ref(self)));
slottable.find_a_slot(true)
}
}