Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NodeIterator #5981

Merged
merged 5 commits into from May 28, 2015
Merged
Next

Implement NodeIterator's attributes

 - root, whatToShow, and filter
  • Loading branch information
Jinwoo-Song committed May 27, 2015
commit 2701c264ab3a5fce34c3d925fedced193ecc2d19
@@ -3,23 +3,81 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::Bindings::NodeIteratorBinding;
use dom::bindings::codegen::Bindings::NodeIteratorBinding::NodeIteratorMethods;
use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Temporary;
use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::document::{Document, DocumentHelpers};
use dom::node::{Node};

#[dom_struct]
pub struct NodeIterator {
reflector_: Reflector
reflector_: Reflector,
root_node: JS<Node>,
what_to_show: u32,
filter: Filter
}

impl NodeIterator {
fn new_inherited() -> NodeIterator {
fn new_inherited(root_node: JSRef<Node>,
what_to_show: u32,
filter: Filter) -> NodeIterator {
NodeIterator {
reflector_: Reflector::new()
reflector_: Reflector::new(),
root_node: JS::from_rooted(root_node),
what_to_show: what_to_show,
filter: filter
}
}

pub fn new(global: GlobalRef) -> Temporary<NodeIterator> {
reflect_dom_object(box NodeIterator::new_inherited(), global, NodeIteratorBinding::Wrap)
pub fn new_with_filter(document: JSRef<Document>,
root_node: JSRef<Node>,
what_to_show: u32,
filter: Filter) -> Temporary<NodeIterator> {
let window = document.window().root();
reflect_dom_object(box NodeIterator::new_inherited(root_node, what_to_show, filter),
GlobalRef::Window(window.r()),
NodeIteratorBinding::Wrap)
}

pub fn new(document: JSRef<Document>,
root_node: JSRef<Node>,
what_to_show: u32,
node_filter: Option<NodeFilter>) -> Temporary<NodeIterator> {
let filter = match node_filter {
None => Filter::None,
Some(jsfilter) => Filter::JS(jsfilter)
};
NodeIterator::new_with_filter(document, root_node, what_to_show, filter)
}
}

impl<'a> NodeIteratorMethods for JSRef<'a, NodeIterator> {
// https://dom.spec.whatwg.org/#dom-nodeiterator-root
fn Root(self) -> Temporary<Node> {
Temporary::new(self.root_node)
}

// https://dom.spec.whatwg.org/#dom-nodeiterator-whattoshow
fn WhatToShow(self) -> u32 {
self.what_to_show
}

// https://dom.spec.whatwg.org/#dom-nodeiterator-filter
fn GetFilter(self) -> Option<NodeFilter> {
match self.filter {
Filter::None => None,
Filter::JS(nf) => Some(nf),
Filter::Native(_) => panic!("Cannot convert native node filter to DOM NodeFilter")
}
}

}

#[jstraceable]
pub enum Filter {
None,
Native(fn (node: JSRef<Node>) -> u16),
JS(NodeFilter)
}
@@ -12,16 +12,16 @@
// Import from http://hg.mozilla.org/mozilla-central/raw-file/a5a720259d79/dom/webidl/NodeIterator.webidl

interface NodeIterator {
// [Constant]
// readonly attribute Node root;
[Constant]
readonly attribute Node root;
// [Pure]
// readonly attribute Node? referenceNode;
// [Pure]
// readonly attribute boolean pointerBeforeReferenceNode;
// [Constant]
// readonly attribute unsigned long whatToShow;
// [Constant]
// readonly attribute NodeFilter? filter;
[Constant]
readonly attribute unsigned long whatToShow;
[Constant]
readonly attribute NodeFilter? filter;

// [Throws]
// Node? nextNode();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.