apply pylbrecht/servo/named.window.getter (closes #27952)

This commit is contained in:
Delan Azabani 2023-03-23 18:01:26 +08:00
parent be6e25a1b2
commit fd1de05592
16 changed files with 611 additions and 292 deletions

View file

@ -82,7 +82,6 @@ use script_traits::UntrustedNodeAddress;
use selectors::matching::{matches_selector_list, MatchingContext, MatchingMode};
use selectors::parser::SelectorList;
use servo_arc::Arc;
use servo_atoms::Atom;
use servo_url::ServoUrl;
use smallvec::SmallVec;
use std::borrow::Cow;
@ -1242,34 +1241,6 @@ impl Node {
}
}
// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter
pub fn is_document_named_item(&self, name: &Atom) -> bool {
let html_elem_type = match self.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
_ => return false,
};
let elem = self
.downcast::<Element>()
.expect("Node with an Element::HTMLElement NodeTypeID must be an Element");
match html_elem_type {
HTMLElementTypeId::HTMLFormElement | HTMLElementTypeId::HTMLIFrameElement => {
elem.get_name().map_or(false, |n| n == *name)
},
HTMLElementTypeId::HTMLImageElement =>
// Images can match by id, but only when their name is non-empty.
{
elem.get_name().map_or(false, |n| {
n == *name || elem.get_id().map_or(false, |i| i == *name)
})
},
// TODO: Handle <embed> and <object>; these depend on
// whether the element is "exposed", a concept which
// doesn't fully make sense until embed/object behaviors
// are actually implemented.
_ => false,
}
}
pub fn is_styled(&self) -> bool {
self.style_and_layout_data.borrow().is_some()
}