auto merge of #1117 : Ms2ger/servo/HTMLCollection, r=kmcallister

This commit is contained in:
bors-servo 2013-10-24 06:22:16 -07:00
commit d222443b38
7 changed files with 32 additions and 39 deletions

View file

@ -219,13 +219,11 @@ impl Document {
}
pub fn GetElementsByTagNameNS(&self, _ns: &DOMString, _tag: &DOMString) -> @mut HTMLCollection {
let (scope, cx) = self.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
HTMLCollection::new(self.window, ~[])
}
pub fn GetElementsByClassName(&self, _class: &DOMString) -> @mut HTMLCollection {
let (scope, cx) = self.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
HTMLCollection::new(self.window, ~[])
}
pub fn GetElementById(&self, id: &DOMString) -> Option<AbstractNode<ScriptView>> {
@ -366,8 +364,7 @@ impl Document {
}
}
}
let (scope, cx) = self.get_scope_and_cx();
HTMLCollection::new(elements, cx, scope)
HTMLCollection::new(self.window, elements)
}
pub fn content_changed(&self) {

View file

@ -252,18 +252,15 @@ impl Element {
}
pub fn GetElementsByTagName(&self, _localname: &DOMString) -> @mut HTMLCollection {
let (scope, cx) = self.node.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
HTMLCollection::new(self.node.owner_doc().document().window, ~[])
}
pub fn GetElementsByTagNameNS(&self, _namespace: &DOMString, _localname: &DOMString) -> Fallible<@mut HTMLCollection> {
let (scope, cx) = self.node.get_scope_and_cx();
Ok(HTMLCollection::new(~[], cx, scope))
Ok(HTMLCollection::new(self.node.owner_doc().document().window, ~[]))
}
pub fn GetElementsByClassName(&self, _names: &DOMString) -> @mut HTMLCollection {
let (scope, cx) = self.node.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
HTMLCollection::new(self.node.owner_doc().document().window, ~[])
}
pub fn MozMatchesSelector(&self, _selector: &DOMString) -> Fallible<bool> {

View file

@ -3,10 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::HTMLCollectionBinding;
use dom::bindings::utils::{Reflectable, Reflector};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::{DOMString, Fallible};
use dom::node::{AbstractNode, ScriptView};
use script_task::page_from_context;
use dom::window::Window;
use js::jsapi::{JSObject, JSContext};
@ -14,21 +14,24 @@ use std::ptr;
pub struct HTMLCollection {
elements: ~[AbstractNode<ScriptView>],
reflector_: Reflector
reflector_: Reflector,
window: @mut Window,
}
impl HTMLCollection {
pub fn new(elements: ~[AbstractNode<ScriptView>], cx: *JSContext, scope: *JSObject) -> @mut HTMLCollection {
let collection = @mut HTMLCollection {
pub fn new_inherited(window: @mut Window,
elements: ~[AbstractNode<ScriptView>]) -> HTMLCollection {
HTMLCollection {
elements: elements,
reflector_: Reflector::new()
};
collection.init_wrapper(cx, scope);
collection
reflector_: Reflector::new(),
window: window,
}
}
pub fn init_wrapper(@mut self, cx: *JSContext, scope: *JSObject) {
self.wrap_object_shared(cx, scope);
pub fn new(window: @mut Window,
elements: ~[AbstractNode<ScriptView>]) -> @mut HTMLCollection {
reflect_dom_object(@mut HTMLCollection::new_inherited(window, elements),
window, HTMLCollectionBinding::Wrap)
}
pub fn Length(&self) -> u32 {
@ -66,15 +69,11 @@ impl Reflectable for HTMLCollection {
&mut self.reflector_
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
HTMLCollectionBinding::Wrap(cx, scope, self)
fn wrap_object_shared(@mut self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
unreachable!();
}
fn GetParentObject(&self, cx: *JSContext) -> Option<@mut Reflectable> {
let page = page_from_context(cx);
// TODO(tkuehn): This only handles the top-level frame. Need to grab subframes.
unsafe {
Some((*page).frame.get_ref().window as @mut Reflectable)
}
fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut Reflectable> {
Some(self.window as @mut Reflectable)
}
}

View file

@ -11,7 +11,7 @@ pub struct HTMLDataListElement {
impl HTMLDataListElement {
pub fn Options(&self) -> @mut HTMLCollection {
let (scope, cx) = self.htmlelement.element.node.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
let window = self.htmlelement.element.node.owner_doc().document().window;
HTMLCollection::new(window, ~[])
}
}

View file

@ -38,8 +38,8 @@ impl HTMLFieldSetElement {
}
pub fn Elements(&self) -> @mut HTMLCollection {
let (scope, cx) = self.htmlelement.element.node.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
let window = self.htmlelement.element.node.owner_doc().document().window;
HTMLCollection::new(window, ~[])
}
pub fn WillValidate(&self) -> bool {

View file

@ -85,8 +85,8 @@ impl HTMLFormElement {
}
pub fn Elements(&self) -> @mut HTMLCollection {
let (scope, cx) = self.htmlelement.element.node.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
let window = self.htmlelement.element.node.owner_doc().document().window;
HTMLCollection::new(window, ~[])
}
pub fn Length(&self) -> i32 {

View file

@ -20,7 +20,7 @@ impl HTMLMapElement {
}
pub fn Areas(&self) -> @mut HTMLCollection {
let (scope, cx) = self.htmlelement.element.node.get_scope_and_cx();
HTMLCollection::new(~[], cx, scope)
let window = self.htmlelement.element.node.owner_doc().document().window;
HTMLCollection::new(window, ~[])
}
}