mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Support live HTMLCollection for FieldSet.elements
This commit is contained in:
parent
e95aa0febd
commit
9038f21026
2 changed files with 15 additions and 6 deletions
|
@ -10,11 +10,11 @@ use dom::document::Document;
|
||||||
use dom::element::{Element, HTMLFieldSetElementTypeId};
|
use dom::element::{Element, HTMLFieldSetElementTypeId};
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
use dom::htmlformelement::HTMLFormElement;
|
use dom::htmlformelement::HTMLFormElement;
|
||||||
use dom::htmlcollection::HTMLCollection;
|
use dom::htmlcollection::{HTMLCollection, CollectionFilter};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
||||||
use dom::validitystate::ValidityState;
|
use dom::validitystate::ValidityState;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::{DOMString, StaticStringVec};
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub struct HTMLFieldSetElement {
|
pub struct HTMLFieldSetElement {
|
||||||
|
@ -68,12 +68,20 @@ impl HTMLFieldSetElement {
|
||||||
~""
|
~""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://www.whatwg.org/html/#dom-fieldset-elements
|
||||||
pub fn Elements(&self, abstract_self: &JS<HTMLFieldSetElement>) -> JS<HTMLCollection> {
|
pub fn Elements(&self, abstract_self: &JS<HTMLFieldSetElement>) -> JS<HTMLCollection> {
|
||||||
|
struct ElementsFilter;
|
||||||
|
impl CollectionFilter for ElementsFilter {
|
||||||
|
fn filter(&self, elem: &JS<Element>, root: &JS<Node>) -> bool {
|
||||||
|
static tag_names: StaticStringVec = &["button", "fieldset", "input",
|
||||||
|
"keygen", "object", "output", "select", "textarea"];
|
||||||
|
let root: &JS<Element> = &ElementCast::to(root).unwrap();
|
||||||
|
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().tag_name)
|
||||||
|
}
|
||||||
|
}
|
||||||
let node: JS<Node> = NodeCast::from(abstract_self);
|
let node: JS<Node> = NodeCast::from(abstract_self);
|
||||||
let element: JS<Element> = ElementCast::from(abstract_self);
|
let filter = ~ElementsFilter;
|
||||||
let window = &window_from_node(&node);
|
HTMLCollection::create_live(&window_from_node(&node), &node, ~filter)
|
||||||
let listed_elements = ["button", "fieldset", "input", "keygen", "object", "output", "select", "textarea"];
|
|
||||||
HTMLCollection::create(window, &node, |elem| *elem != element && listed_elements.iter().any(|&tag_name| tag_name == elem.get().tag_name))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn WillValidate(&self) -> bool {
|
pub fn WillValidate(&self) -> bool {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
pub type DOMString = ~str;
|
pub type DOMString = ~str;
|
||||||
|
pub type StaticStringVec = &'static [&'static str];
|
||||||
|
|
||||||
pub fn null_str_as_empty(s: &Option<DOMString>) -> DOMString {
|
pub fn null_str_as_empty(s: &Option<DOMString>) -> DOMString {
|
||||||
// We don't use map_default because it would allocate ~"" even for Some.
|
// We don't use map_default because it would allocate ~"" even for Some.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue