Navigation Menu

Skip to content

Commit

Permalink
Implement HTMLFieldSetElement.elements.(fixes #1843)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpy committed Mar 17, 2014
1 parent caf1ed9 commit 5915b06
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/script/dom/bindings/codegen/Bindings.conf
Expand Up @@ -147,7 +147,7 @@ addHTMLElement('HTMLDirectoryElement')
addHTMLElement('HTMLDListElement')
addHTMLElement('HTMLElement')
addHTMLElement('HTMLEmbedElement')
addHTMLElement('HTMLFieldSetElement')
addHTMLElement('HTMLFieldSetElement', needsAbstract=['elements'])
addHTMLElement('HTMLFontElement')
addHTMLElement('HTMLFormElement')
addHTMLElement('HTMLFrameElement')
Expand Down
17 changes: 9 additions & 8 deletions src/components/script/dom/htmlfieldsetelement.rs
Expand Up @@ -3,16 +3,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::codegen::HTMLFieldSetElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLFieldSetElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast};
use dom::bindings::js::JS;
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLFieldSetElementTypeId;
use dom::element::{Element, HTMLFieldSetElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlformelement::HTMLFormElement;
use dom::htmlcollection::HTMLCollection;
use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId};
use dom::node::{Node, ElementNodeTypeId, window_from_node};
use dom::validitystate::ValidityState;
use servo_util::str::DOMString;

Expand Down Expand Up @@ -68,11 +68,12 @@ impl HTMLFieldSetElement {
~""
}

pub fn Elements(&self) -> JS<HTMLCollection> {
// FIXME: https://github.com/mozilla/servo/issues/1843
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
HTMLCollection::new(&doc.window, ~[])
pub fn Elements(&self, abstract_self: &JS<HTMLFieldSetElement>) -> JS<HTMLCollection> {
let node: JS<Node> = NodeCast::from(abstract_self);
let element: JS<Element> = ElementCast::from(abstract_self);
let window = &window_from_node(&node);
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 {
Expand Down
45 changes: 45 additions & 0 deletions src/test/content/test_htmlfieldsetelement_elements.html
@@ -0,0 +1,45 @@
<html>
<script src="harness.js"></script>
<fieldset id="fs">
<legend>Display</legend>
<input type=radio name=a>
<fieldset>
<button>Click!</button>
</fieldset>
<keygen name="key">
<textarea>
A
</textarea>
<select>
<option value="1"> A </option>
<option value="2" selected> B </option>
</select>
<form onsubmit="return false" oninput="o.value = a.valueAsNumber + b.valueAsNumber">
<input name=a type=number step=any> +
<input name=b type=number step=any> =
<output name=c for="a b"></output>
</form>
<figure>
<object type="application/x-java-applet">
<param name="code" value="MyJavaClass">
<p>You do not have Java available, or it is disabled.</p>
</object>
<figcaption>My Java Clock</figcaption>
</figure>
</fieldset>
<script>
var fs = document.getElementById("fs");
is(fs.elements.length, 10);
is_a(fs.elements[0], HTMLInputElement);
is_a(fs.elements[1], HTMLFieldSetElement);
is_a(fs.elements[2], HTMLButtonElement);
is_a(fs.elements[3], HTMLUnknownElement);
is_a(fs.elements[4], HTMLTextAreaElement);
is_a(fs.elements[5], HTMLSelectElement);
is_a(fs.elements[6], HTMLInputElement);
is_a(fs.elements[7], HTMLInputElement);
is_a(fs.elements[8], HTMLOutputElement);
is_a(fs.elements[9], HTMLObjectElement);
finish();
</script>
</html>

9 comments on commit 5915b06

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue1843 = 5915b06 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue1843 = 5915b06 merged ok, testing candidate = 9bf34c7

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lpy/servo/issue1843 = 5915b06 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpy/servo/issue1843 = 5915b06 merged ok, testing candidate = b345e94

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = b345e94

Please sign in to comment.