aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2015-09-25 09:39:35 -0400
committerCorey Farwell <coreyf@rwell.org>2015-09-26 15:38:54 -0400
commitdec00311121b0847b9c038daf62e15a361ae309a (patch)
tree667d237991030869bcf48c777e5dfdb550dcea33 /components/script/dom
parent37ce248f316ba3cb5a2cfb0b4bb95918c1c45828 (diff)
downloadservo-dec00311121b0847b9c038daf62e15a361ae309a.tar.gz
servo-dec00311121b0847b9c038daf62e15a361ae309a.zip
Implement <option> 'defaultSelected' and 'selected' attributes
Continued from #7743
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmloptionelement.rs46
-rw-r--r--components/script/dom/webidls/HTMLOptionElement.webidl4
2 files changed, 46 insertions, 4 deletions
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index 132de2335b2..79f710db1d2 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -17,11 +17,18 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId};
use dom::virtualmethods::VirtualMethods;
+use std::cell::Cell;
use util::str::{DOMString, split_html_space_chars};
#[dom_struct]
pub struct HTMLOptionElement {
- htmlelement: HTMLElement
+ htmlelement: HTMLElement,
+
+ /// https://html.spec.whatwg.org/multipage/#attr-option-selected
+ selectedness: Cell<bool>,
+
+ /// https://html.spec.whatwg.org/multipage/#concept-option-dirtiness
+ dirtiness: Cell<bool>,
}
impl HTMLOptionElementDerived for EventTarget {
@@ -38,7 +45,9 @@ impl HTMLOptionElement {
document: &Document) -> HTMLOptionElement {
HTMLOptionElement {
htmlelement:
- HTMLElement::new_inherited(HTMLElementTypeId::HTMLOptionElement, localName, prefix, document)
+ HTMLElement::new_inherited(HTMLElementTypeId::HTMLOptionElement, localName, prefix, document),
+ selectedness: Cell::new(false),
+ dirtiness: Cell::new(false),
}
}
@@ -122,6 +131,23 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
// https://html.spec.whatwg.org/multipage/#attr-option-label
make_setter!(SetLabel, "label");
+ // https://html.spec.whatwg.org/multipage/#dom-option-defaultselected
+ make_bool_getter!(DefaultSelected, "selected");
+
+ // https://html.spec.whatwg.org/multipage/#dom-option-defaultselected
+ make_bool_setter!(SetDefaultSelected, "selected");
+
+ // https://html.spec.whatwg.org/multipage/#dom-option-selected
+ fn Selected(&self) -> bool {
+ self.selectedness.get()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-option-selected
+ fn SetSelected(&self, selected: bool) {
+ self.dirtiness.set(true);
+ self.selectedness.set(selected);
+ // FIXME: as per the spec, implement 'ask for a reset'
+ }
}
impl VirtualMethods for HTMLOptionElement {
@@ -147,6 +173,22 @@ impl VirtualMethods for HTMLOptionElement {
}
}
},
+ &atom!(selected) => {
+ match mutation {
+ AttributeMutation::Set(_) => {
+ // https://html.spec.whatwg.org/multipage/#concept-option-selectedness
+ if !self.dirtiness.get() {
+ self.selectedness.set(true);
+ }
+ },
+ AttributeMutation::Removed => {
+ // https://html.spec.whatwg.org/multipage/#concept-option-selectedness
+ if !self.dirtiness.get() {
+ self.selectedness.set(false);
+ }
+ },
+ }
+ },
_ => {},
}
}
diff --git a/components/script/dom/webidls/HTMLOptionElement.webidl b/components/script/dom/webidls/HTMLOptionElement.webidl
index c4f57ab4963..b4e3bdac353 100644
--- a/components/script/dom/webidls/HTMLOptionElement.webidl
+++ b/components/script/dom/webidls/HTMLOptionElement.webidl
@@ -11,8 +11,8 @@ interface HTMLOptionElement : HTMLElement {
attribute boolean disabled;
//readonly attribute HTMLFormElement? form;
attribute DOMString label;
- // attribute boolean defaultSelected;
- // attribute boolean selected;
+ attribute boolean defaultSelected;
+ attribute boolean selected;
attribute DOMString value;
attribute DOMString text;