Auto merge of #13126 - splav:HTMLOptionElement.form#13111, r=metajack

Html option element.form#13111

<!-- Please describe your changes on the following line: -->
Add HTMLOptionElement form attribute support

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #13111 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13126)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-08-30 13:18:10 -05:00 committed by GitHub
commit e07ee3f4cf
5 changed files with 55 additions and 7 deletions

View file

@ -6,6 +6,7 @@ use dom::attr::Attr;
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementBinding::HTMLSelectElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
@ -14,6 +15,8 @@ use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::element::{AttributeMutation, Element};
use dom::htmlelement::HTMLElement;
use dom::htmlformelement::HTMLFormElement;
use dom::htmloptgroupelement::HTMLOptGroupElement;
use dom::htmlscriptelement::HTMLScriptElement;
use dom::htmlselectelement::HTMLSelectElement;
use dom::node::{Node, UnbindContext};
@ -110,6 +113,19 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
self.upcast::<Node>().SetTextContent(Some(value))
}
// https://html.spec.whatwg.org/multipage/#dom-option-form
fn GetForm(&self) -> Option<Root<HTMLFormElement>> {
let parent = self.upcast::<Node>().GetParentNode().and_then(|p|
if p.is::<HTMLOptGroupElement>() {
p.upcast::<Node>().GetParentNode()
} else {
Some(p)
}
);
parent.and_then(|p| p.downcast::<HTMLSelectElement>().and_then(|s| s.GetForm()))
}
// https://html.spec.whatwg.org/multipage/#attr-option-value
fn Value(&self) -> DOMString {
let element = self.upcast::<Element>();

View file

@ -9,7 +9,7 @@
[Exposed=(Window,Worker)]
interface HTMLOptionElement : HTMLElement {
attribute boolean disabled;
//readonly attribute HTMLFormElement? form;
readonly attribute HTMLFormElement? form;
attribute DOMString label;
attribute boolean defaultSelected;
attribute boolean selected;

View file

@ -37215,6 +37215,12 @@
"deleted_reftests": {},
"items": {
"testharness": {
"html/semantics/forms/the-option-element/option-form.html": [
{
"path": "html/semantics/forms/the-option-element/option-form.html",
"url": "/html/semantics/forms/the-option-element/option-form.html"
}
],
"html/semantics/interactive-elements/the-dialog-element/dialog-open.html": [
{
"path": "html/semantics/interactive-elements/the-dialog-element/dialog-open.html",

View file

@ -3855,15 +3855,9 @@
[HTMLOptGroupElement interface: document.createElement("optgroup") must inherit property "label" with the proper type (1)]
expected: FAIL
[HTMLOptionElement interface: attribute form]
expected: FAIL
[HTMLOptionElement interface: attribute index]
expected: FAIL
[HTMLOptionElement interface: document.createElement("option") must inherit property "form" with the proper type (1)]
expected: FAIL
[HTMLOptionElement interface: document.createElement("option") must inherit property "index" with the proper type (7)]
expected: FAIL

View file

@ -0,0 +1,32 @@
<!doctype html>
<meta charset=utf-8>
<title>HTMLOptionElement.form</title>
<link rel=author title="Sergey Alexandrov" href="mailto:splavgm@gmail.com">
<link rel=help href="https://html.spec.whatwg.org/multipage/#dom-option-form">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<form id="form">
<select id="select">
<optgroup id="optgroup"></optgroup>
</select>
</form>
<div id=log></div>
<script>
test(function () {
var form = document.getElementById("form");
var select = document.getElementById("select");
var optgroup = document.getElementById("optgroup");
var o1 = document.createElement("option");
assert_equals(o1.form, null);
select.appendChild(o1);
assert_equals(o1.form, select.form);
var o2 = document.createElement("option");
select.appendChild(o2);
assert_equals(o2.form, select.form);
}, "form");
</script>