aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/documentfragment.rs
diff options
context:
space:
mode:
authorJack Moffitt <jack@metajack.im>2014-08-28 09:34:23 -0600
committerJack Moffitt <jack@metajack.im>2014-09-08 20:21:42 -0600
commitc6ab60dbfc6da7b4f800c9e40893c8b58413960c (patch)
treed1d74076cf7fa20e4f77ec7cb82cae98b67362cb /components/script/dom/documentfragment.rs
parentdb2f642c32fc5bed445bb6f2e45b0f6f0b4342cf (diff)
downloadservo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.tar.gz
servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.zip
Cargoify servo
Diffstat (limited to 'components/script/dom/documentfragment.rs')
-rw-r--r--components/script/dom/documentfragment.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs
new file mode 100644
index 00000000000..1f3fcb29424
--- /dev/null
+++ b/components/script/dom/documentfragment.rs
@@ -0,0 +1,78 @@
+/* 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/. */
+
+use dom::bindings::codegen::Bindings::DocumentFragmentBinding;
+use dom::bindings::codegen::Bindings::DocumentFragmentBinding::DocumentFragmentMethods;
+use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
+use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast};
+use dom::bindings::js::{JSRef, Temporary};
+use dom::bindings::error::Fallible;
+use dom::bindings::global::GlobalRef;
+use dom::bindings::utils::{Reflectable, Reflector};
+use dom::document::Document;
+use dom::element::Element;
+use dom::eventtarget::{EventTarget, NodeTargetTypeId};
+use dom::htmlcollection::HTMLCollection;
+use dom::node::{DocumentFragmentNodeTypeId, Node, NodeHelpers, window_from_node};
+use dom::nodelist::NodeList;
+use servo_util::str::DOMString;
+
+#[deriving(Encodable)]
+pub struct DocumentFragment {
+ pub node: Node,
+}
+
+impl DocumentFragmentDerived for EventTarget {
+ fn is_documentfragment(&self) -> bool {
+ self.type_id == NodeTargetTypeId(DocumentFragmentNodeTypeId)
+ }
+}
+
+impl DocumentFragment {
+ /// Creates a new DocumentFragment.
+ pub fn new_inherited(document: &JSRef<Document>) -> DocumentFragment {
+ DocumentFragment {
+ node: Node::new_inherited(DocumentFragmentNodeTypeId, document),
+ }
+ }
+
+ pub fn new(document: &JSRef<Document>) -> Temporary<DocumentFragment> {
+ let node = DocumentFragment::new_inherited(document);
+ Node::reflect_node(box node, document, DocumentFragmentBinding::Wrap)
+ }
+
+ pub fn Constructor(global: &GlobalRef) -> Fallible<Temporary<DocumentFragment>> {
+ let document = global.as_window().Document();
+ let document = document.root();
+
+ Ok(DocumentFragment::new(&document.root_ref()))
+ }
+}
+
+impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> {
+ // http://dom.spec.whatwg.org/#dom-parentnode-children
+ fn Children(&self) -> Temporary<HTMLCollection> {
+ let window = window_from_node(self).root();
+ HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self))
+ }
+
+ // http://dom.spec.whatwg.org/#dom-parentnode-queryselector
+ fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Temporary<Element>>> {
+ let root: &JSRef<Node> = NodeCast::from_ref(self);
+ root.query_selector(selectors)
+ }
+
+ // http://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
+ fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Temporary<NodeList>> {
+ let root: &JSRef<Node> = NodeCast::from_ref(self);
+ root.query_selector_all(selectors)
+ }
+
+}
+
+impl Reflectable for DocumentFragment {
+ fn reflector<'a>(&'a self) -> &'a Reflector {
+ self.node.reflector()
+ }
+}