diff options
author | Simon Wülker <simon.wuelker@arcor.de> | 2025-01-19 15:05:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-19 14:05:05 +0000 |
commit | dabe162d44a2b8a47b7a9dc8566e7f51ae678d05 (patch) | |
tree | 0b915202184ab6924ecb38cc961bbd4dd8ed830e /components/script/dom/text.rs | |
parent | 8bb50fa3c9d82e2575b02cefb6558467a8187439 (diff) | |
download | servo-dabe162d44a2b8a47b7a9dc8566e7f51ae678d05.tar.gz servo-dabe162d44a2b8a47b7a9dc8566e7f51ae678d05.zip |
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>
Diffstat (limited to 'components/script/dom/text.rs')
-rw-r--r-- | components/script/dom/text.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs index 2f0e1c66857..3f81f0be6e2 100644 --- a/components/script/dom/text.rs +++ b/components/script/dom/text.rs @@ -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) + } } |