mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement JSManaged for DOM objects.
This commit is contained in:
parent
061269f963
commit
625325434b
137 changed files with 3644 additions and 2778 deletions
|
@ -3,43 +3,46 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::NodeListBinding;
|
||||
use dom::bindings::js::JS;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::node::AbstractNode;
|
||||
use dom::node::{Node, NodeHelpers};
|
||||
use dom::window::Window;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
enum NodeListType {
|
||||
Simple(~[AbstractNode]),
|
||||
Children(AbstractNode)
|
||||
Simple(~[JS<Node>]),
|
||||
Children(JS<Node>)
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct NodeList {
|
||||
list_type: NodeListType,
|
||||
reflector_: Reflector,
|
||||
window: @mut Window,
|
||||
window: JS<Window>
|
||||
}
|
||||
|
||||
impl NodeList {
|
||||
pub fn new_inherited(window: @mut Window,
|
||||
pub fn new_inherited(window: JS<Window>,
|
||||
list_type: NodeListType) -> NodeList {
|
||||
NodeList {
|
||||
list_type: list_type,
|
||||
reflector_: Reflector::new(),
|
||||
window: window,
|
||||
window: window
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(window: @mut Window,
|
||||
list_type: NodeListType) -> @mut NodeList {
|
||||
reflect_dom_object(@mut NodeList::new_inherited(window, list_type),
|
||||
window, NodeListBinding::Wrap)
|
||||
pub fn new(window: JS<Window>,
|
||||
list_type: NodeListType) -> JS<NodeList> {
|
||||
reflect_dom_object(~NodeList::new_inherited(window.clone(), list_type),
|
||||
window.get(), NodeListBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn new_simple_list(window: @mut Window, elements: ~[AbstractNode]) -> @mut NodeList {
|
||||
NodeList::new(window, Simple(elements))
|
||||
pub fn new_simple_list(window: &JS<Window>, elements: ~[JS<Node>]) -> JS<NodeList> {
|
||||
NodeList::new(window.clone(), Simple(elements))
|
||||
}
|
||||
|
||||
pub fn new_child_list(window: @mut Window, node: AbstractNode) -> @mut NodeList {
|
||||
NodeList::new(window, Children(node))
|
||||
pub fn new_child_list(window: &JS<Window>, node: &JS<Node>) -> JS<NodeList> {
|
||||
NodeList::new(window.clone(), Children(node.clone()))
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
|
@ -49,15 +52,15 @@ impl NodeList {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn Item(&self, index: u32) -> Option<AbstractNode> {
|
||||
pub fn Item(&self, index: u32) -> Option<JS<Node>> {
|
||||
match self.list_type {
|
||||
_ if index >= self.Length() => None,
|
||||
Simple(ref elems) => Some(elems[index]),
|
||||
Simple(ref elems) => Some(elems[index].clone()),
|
||||
Children(ref node) => node.children().nth(index as uint)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<AbstractNode> {
|
||||
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Node>> {
|
||||
let item = self.Item(index);
|
||||
*found = item.is_some();
|
||||
item
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue