mirror of
https://github.com/servo/servo.git
synced 2025-07-31 03:00:29 +01:00
Auto merge of #13783 - frewsxcv:select-value, r=nox
Implement `value` property on `<select>`. <!-- 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/13783) <!-- Reviewable:end -->
This commit is contained in:
commit
a71b1e65be
5 changed files with 36 additions and 22 deletions
|
@ -64,6 +64,10 @@ impl HTMLOptionElement {
|
||||||
self.selectedness.set(selected);
|
self.selectedness.set(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_dirtiness(&self, dirtiness: bool) {
|
||||||
|
self.dirtiness.set(dirtiness);
|
||||||
|
}
|
||||||
|
|
||||||
fn pick_if_selected_and_reset(&self) {
|
fn pick_if_selected_and_reset(&self) {
|
||||||
if let Some(select) = self.upcast::<Node>().ancestors()
|
if let Some(select) = self.upcast::<Node>().ancestors()
|
||||||
.filter_map(Root::downcast::<HTMLSelectElement>)
|
.filter_map(Root::downcast::<HTMLSelectElement>)
|
||||||
|
|
|
@ -258,6 +258,37 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
||||||
fn Remove(&self) {
|
fn Remove(&self) {
|
||||||
self.upcast::<Element>().Remove()
|
self.upcast::<Element>().Remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-select-value
|
||||||
|
fn Value(&self) -> DOMString {
|
||||||
|
self.upcast::<Node>()
|
||||||
|
.traverse_preorder()
|
||||||
|
.filter_map(Root::downcast::<HTMLOptionElement>)
|
||||||
|
.filter(|opt_elem| opt_elem.Selected())
|
||||||
|
.map(|opt_elem| opt_elem.Value())
|
||||||
|
.next()
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-select-value
|
||||||
|
fn SetValue(&self, value: DOMString) {
|
||||||
|
let mut opt_iter = self.upcast::<Node>()
|
||||||
|
.traverse_preorder()
|
||||||
|
.filter_map(Root::downcast::<HTMLOptionElement>);
|
||||||
|
// Reset until we find an <option> with a matching value
|
||||||
|
for opt in opt_iter.by_ref() {
|
||||||
|
if opt.Value() == value {
|
||||||
|
opt.set_selectedness(true);
|
||||||
|
opt.set_dirtiness(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
opt.set_selectedness(false);
|
||||||
|
}
|
||||||
|
// Reset remaining <option> elements
|
||||||
|
for opt in opt_iter {
|
||||||
|
opt.set_selectedness(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLSelectElement {
|
impl VirtualMethods for HTMLSelectElement {
|
||||||
|
|
|
@ -26,7 +26,7 @@ interface HTMLSelectElement : HTMLElement {
|
||||||
|
|
||||||
//readonly attribute HTMLCollection selectedOptions;
|
//readonly attribute HTMLCollection selectedOptions;
|
||||||
// attribute long selectedIndex;
|
// attribute long selectedIndex;
|
||||||
// attribute DOMString value;
|
attribute DOMString value;
|
||||||
|
|
||||||
//readonly attribute boolean willValidate;
|
//readonly attribute boolean willValidate;
|
||||||
readonly attribute ValidityState validity;
|
readonly attribute ValidityState validity;
|
||||||
|
|
|
@ -3711,9 +3711,6 @@
|
||||||
[HTMLSelectElement interface: attribute selectedIndex]
|
[HTMLSelectElement interface: attribute selectedIndex]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLSelectElement interface: attribute value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLSelectElement interface: attribute willValidate]
|
[HTMLSelectElement interface: attribute willValidate]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -3744,9 +3741,6 @@
|
||||||
[HTMLSelectElement interface: document.createElement("select") must inherit property "selectedIndex" with the proper type (18)]
|
[HTMLSelectElement interface: document.createElement("select") must inherit property "selectedIndex" with the proper type (18)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLSelectElement interface: document.createElement("select") must inherit property "value" with the proper type (19)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLSelectElement interface: document.createElement("select") must inherit property "willValidate" with the proper type (20)]
|
[HTMLSelectElement interface: document.createElement("select") must inherit property "willValidate" with the proper type (20)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,5 @@
|
||||||
[htmloptionscollection.html]
|
[htmloptionscollection.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
[Setting length to longer value]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Insert <p><option>6</option></p> into <select>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Insert <select><option>6</option></select> into <select>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Insert <optgroup><option>6</option></optgroup> into <select>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Insert <optgroup><optgroup><option>6</option></optgroup></optgroup> into <select>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLOptionsCollection.add method insert HTMLOptionElement Option element]
|
[HTMLOptionsCollection.add method insert HTMLOptionElement Option element]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue