script/dom/execcommand/commands/
unlink.rs1use html5ever::local_name;
6use js::context::JSContext;
7use script_bindings::inheritance::Castable;
8
9use crate::dom::bindings::root::DomRoot;
10use crate::dom::element::Element;
11use crate::dom::execcommand::basecommand::CommandName;
12use crate::dom::html::htmlanchorelement::HTMLAnchorElement;
13use crate::dom::html::htmlelement::HTMLElement;
14use crate::dom::selection::Selection;
15
16pub(crate) fn execute_unlink_command(cx: &mut JSContext, selection: &Selection) -> bool {
18 let active_range = selection
21 .active_range()
22 .expect("Must always have an active range");
23 let mut hyperlinks = vec![];
24 active_range.for_each_effectively_contained_child(|node| {
25 if let Some(anchor) = node.downcast::<HTMLAnchorElement>() &&
26 anchor
27 .upcast::<Element>()
28 .has_attribute(&local_name!("href"))
29 {
30 hyperlinks.push(DomRoot::from_ref(anchor));
31 }
32 });
33 for anchor in hyperlinks.iter() {
35 anchor
36 .upcast::<HTMLElement>()
37 .clear_the_value(cx, &CommandName::Unlink);
38 }
39 true
41}