aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.rs
diff options
context:
space:
mode:
authorPatrick Shaughnessy <pshaughn@comcast.net>2020-01-22 15:50:21 -0500
committerPatrick Shaughnessy <pshaughn@comcast.net>2020-02-13 15:37:03 -0500
commite48eac6879add4512dd42cbed0216508ace2c31e (patch)
tree1a8af67ee342d8a95c7158255fec0353f676e04a /components/script/dom/node.rs
parent4b750ca0d09701d84e9790925d63315e90dde24c (diff)
downloadservo-e48eac6879add4512dd42cbed0216508ace2c31e.tar.gz
servo-e48eac6879add4512dd42cbed0216508ace2c31e.zip
Doc named getter improvements
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index b6d4389d441..1cbba04ad16 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -83,6 +83,7 @@ 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::ToOwned;
@@ -1170,6 +1171,34 @@ 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,
+ }
+ }
}
/// Iterate through `nodes` until we find a `Node` that is not in `not_in`