pub struct DocumentMutator<'doc> {
pub doc: &'doc mut BaseDocument,
/* private fields */
}Fields§
§doc: &'doc mut BaseDocumentDocument is public as an escape hatch, but users of this API should ideally avoid using it and prefer exposing additional functionality in DocumentMutator.
Implementations§
Source§impl DocumentMutator<'_>
impl DocumentMutator<'_>
pub fn new<'doc>(doc: &'doc mut BaseDocument) -> DocumentMutator<'doc>
pub fn node_has_parent(&self, node_id: NodeId) -> bool
pub fn previous_sibling_id(&self, node_id: NodeId) -> Option<NodeId>
pub fn next_sibling_id(&self, node_id: NodeId) -> Option<NodeId>
pub fn parent_id(&self, node_id: NodeId) -> Option<NodeId>
pub fn last_child_id(&self, node_id: NodeId) -> Option<NodeId>
pub fn child_ids(&self, node_id: NodeId) -> ThinVec<NodeId>
pub fn element_name(&self, node_id: NodeId) -> Option<&QualName>
pub fn node_at_path(&self, start_node_id: NodeId, path: &[u8]) -> NodeId
pub fn create_comment_node(&mut self, contents: &str) -> NodeId
pub fn create_text_node(&mut self, text: &str) -> NodeId
Sourcepub fn create_document_fragment(&mut self) -> NodeId
pub fn create_document_fragment(&mut self) -> NodeId
A DocumentFragment: a parentless container that never appears in a box
tree and whose children are what gets inserted when it is.
jQuery builds one during initialisation, so without this the library
throws before it defines jQuery and every page depending on it loses
its scripting. Eight sites in a hundred-site corpus failed that way, and
they reported it as jQuery is not defined — the missing method itself
says only not a callable function, which names nothing.
Sourcepub fn create_html_document(&mut self, title: &str) -> NodeId
pub fn create_html_document(&mut self, title: &str) -> NodeId
A detached HTML document: html > head > title, and body.
This backs document.implementation.createHTMLDocument, which jQuery
calls during initialisation to decide whether it can parse markup
through a second document. Reading createHTMLDocument off an absent
implementation threw before jQuery had assigned itself to window,
so every site depending on it reported jQuery is not defined – a
global that was never missing.
The node lives in this document’s arena but is attached to nothing, so
it never lays out or paints. That is what makes it cheap: no second
BaseDocument, no second style engine, no second arena.
pub fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, ) -> NodeId
pub fn deep_clone_node(&mut self, node_id: NodeId) -> NodeId
pub fn set_node_text(&mut self, node_id: NodeId, value: &str)
pub fn append_text_to_node( &mut self, node_id: NodeId, text: &str, ) -> Result<(), AppendTextErr>
pub fn add_attrs_if_missing(&mut self, node_id: NodeId, attrs: Vec<Attribute>)
pub fn set_attribute(&mut self, node_id: NodeId, name: QualName, value: &str)
pub fn clear_attribute(&mut self, node_id: NodeId, name: QualName)
pub fn set_style_property(&mut self, node_id: NodeId, name: &str, value: &str)
pub fn remove_style_property(&mut self, node_id: NodeId, name: &str)
pub fn set_sub_document( &mut self, node_id: NodeId, sub_document: Box<dyn Document>, )
pub fn remove_sub_document(&mut self, node_id: NodeId)
pub fn set_custom_widget(&mut self, node_id: NodeId, widget: Box<dyn Widget>)
pub fn remove_custom_widget(&mut self, node_id: NodeId)
Sourcepub fn remove_node(&mut self, node_id: NodeId)
pub fn remove_node(&mut self, node_id: NodeId)
Remove the node from its parent but don’t drop it.
pub fn remove_and_drop_node(&mut self, node_id: NodeId) -> Option<Node>
Sourcepub fn remove_and_drop_node_with(
&mut self,
node_id: NodeId,
on_drop: &mut dyn FnMut(NodeId),
) -> Option<Node>
pub fn remove_and_drop_node_with( &mut self, node_id: NodeId, on_drop: &mut dyn FnMut(NodeId), ) -> Option<Node>
Like Self::remove_and_drop_node, but calls on_drop with the id of
every dropped node (the node itself and all of its descendants).
pub fn remove_and_drop_all_children(&mut self, node_id: NodeId)
pub fn remove_node_if_unparented(&mut self, node_id: NodeId)
Sourcepub fn remove_node_if_unparented_with(
&mut self,
node_id: NodeId,
on_drop: &mut dyn FnMut(NodeId),
)
pub fn remove_node_if_unparented_with( &mut self, node_id: NodeId, on_drop: &mut dyn FnMut(NodeId), )
Like Self::remove_node_if_unparented, but calls on_drop with the id of
every dropped node (the node itself and all of its descendants).
Sourcepub fn append_children(&mut self, parent_id: NodeId, child_ids: &[NodeId])
pub fn append_children(&mut self, parent_id: NodeId, child_ids: &[NodeId])
Remove all of the children from old_parent_id and append them to new_parent_id
pub fn insert_nodes_before( &mut self, anchor_node_id: NodeId, new_node_ids: &[NodeId], )
pub fn insert_nodes_after( &mut self, anchor_node_id: NodeId, new_node_ids: &[NodeId], )
pub fn reparent_children( &mut self, old_parent_id: NodeId, new_parent_id: NodeId, )
pub fn replace_node_with( &mut self, anchor_node_id: NodeId, new_node_ids: &[NodeId], )
Source§impl<'doc> DocumentMutator<'doc>
impl<'doc> DocumentMutator<'doc>
Trait Implementations§
Source§impl Drop for DocumentMutator<'_>
impl Drop for DocumentMutator<'_>
Auto Trait Implementations§
impl<'doc> !RefUnwindSafe for DocumentMutator<'doc>
impl<'doc> !Send for DocumentMutator<'doc>
impl<'doc> !Sync for DocumentMutator<'doc>
impl<'doc> !UnwindSafe for DocumentMutator<'doc>
impl<'doc> Freeze for DocumentMutator<'doc>
impl<'doc> Unpin for DocumentMutator<'doc>
impl<'doc> UnsafeUnpin for DocumentMutator<'doc>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more