mirror of
https://github.com/servo/servo.git
synced 2025-06-20 23:28:59 +01:00
Auto merge of #7592 - nox:nonelementparentnode, r=jdm
Introduce NonElementParentNode This is the interface where Document.getElementById() belong. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7592) <!-- Reviewable:end -->
This commit is contained in:
commit
4c64c870c6
5 changed files with 27 additions and 10 deletions
|
@ -17,6 +17,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||||
use dom::htmlcollection::HTMLCollection;
|
use dom::htmlcollection::HTMLCollection;
|
||||||
use dom::node::{Node, NodeTypeId, window_from_node};
|
use dom::node::{Node, NodeTypeId, window_from_node};
|
||||||
use dom::nodelist::NodeList;
|
use dom::nodelist::NodeList;
|
||||||
|
use string_cache::Atom;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#documentfragment
|
// https://dom.spec.whatwg.org/#documentfragment
|
||||||
|
@ -58,6 +59,18 @@ impl DocumentFragmentMethods for DocumentFragment {
|
||||||
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
|
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||||
|
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
|
||||||
|
let node = NodeCast::from_ref(self);
|
||||||
|
let id = Atom::from_slice(&id);
|
||||||
|
node.traverse_preorder().filter_map(ElementCast::to_root).find(|descendant| {
|
||||||
|
match descendant.get_attribute(&ns!(""), &atom!(id)) {
|
||||||
|
None => false,
|
||||||
|
Some(attr) => *attr.value().as_atom() == id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||||
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).child_elements().next()
|
NodeCast::from_ref(self).child_elements().next()
|
||||||
|
|
|
@ -26,7 +26,6 @@ interface Document : Node {
|
||||||
HTMLCollection getElementsByTagName(DOMString localName);
|
HTMLCollection getElementsByTagName(DOMString localName);
|
||||||
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
|
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
|
||||||
HTMLCollection getElementsByClassName(DOMString classNames);
|
HTMLCollection getElementsByClassName(DOMString classNames);
|
||||||
Element? getElementById(DOMString elementId);
|
|
||||||
|
|
||||||
[NewObject, Throws]
|
[NewObject, Throws]
|
||||||
Element createElement(DOMString localName);
|
Element createElement(DOMString localName);
|
||||||
|
@ -65,6 +64,8 @@ interface Document : Node {
|
||||||
TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF,
|
TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF,
|
||||||
optional NodeFilter? filter = null);
|
optional NodeFilter? filter = null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Document implements NonElementParentNode;
|
||||||
Document implements ParentNode;
|
Document implements ParentNode;
|
||||||
|
|
||||||
enum DocumentReadyState { "loading", "interactive", "complete" };
|
enum DocumentReadyState { "loading", "interactive", "complete" };
|
||||||
|
|
|
@ -8,4 +8,5 @@
|
||||||
interface DocumentFragment : Node {
|
interface DocumentFragment : Node {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DocumentFragment implements NonElementParentNode;
|
||||||
DocumentFragment implements ParentNode;
|
DocumentFragment implements ParentNode;
|
||||||
|
|
11
components/script/dom/webidls/NonElementParentNode.webidl
Normal file
11
components/script/dom/webidls/NonElementParentNode.webidl
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#nonelementparentnode
|
||||||
|
[NoInterfaceObject,
|
||||||
|
Exposed=Window]
|
||||||
|
interface NonElementParentNode {
|
||||||
|
Element? getElementById(DOMString elementId);
|
||||||
|
};
|
|
@ -123,21 +123,12 @@
|
||||||
[DocumentFragment interface: existence and properties of interface object]
|
[DocumentFragment interface: existence and properties of interface object]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[DocumentFragment interface: operation getElementById(DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment interface: operation query(DOMString)]
|
[DocumentFragment interface: operation query(DOMString)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[DocumentFragment interface: operation queryAll(DOMString)]
|
[DocumentFragment interface: operation queryAll(DOMString)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[DocumentFragment interface: document.createDocumentFragment() must inherit property "getElementById" with the proper type (0)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment interface: calling getElementById(DOMString) on document.createDocumentFragment() with too few arguments must throw TypeError]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[DocumentFragment interface: document.createDocumentFragment() must inherit property "query" with the proper type (7)]
|
[DocumentFragment interface: document.createDocumentFragment() must inherit property "query" with the proper type (7)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue