Implement 'control' attribute for <label> elements

This commit is contained in:
Corey Farwell 2015-10-24 12:46:43 -04:00
parent 3b50f21963
commit f97d1d148b
8 changed files with 74 additions and 60 deletions

View file

@ -296,6 +296,26 @@ impl HTMLElement {
let local_name = Atom::from_slice(&to_snake_case(local_name));
self.upcast::<Element>().remove_attribute(&ns!(""), &local_name);
}
// https://html.spec.whatwg.org/multipage/#category-label
pub fn is_labelable_element(&self) -> bool {
// Note: HTMLKeygenElement is omitted because Servo doesn't currently implement it
match self.upcast::<Node>().type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) =>
match type_id {
HTMLElementTypeId::HTMLInputElement =>
self.downcast::<HTMLInputElement>().unwrap().Type() != "hidden",
HTMLElementTypeId::HTMLButtonElement |
HTMLElementTypeId::HTMLMeterElement |
HTMLElementTypeId::HTMLOutputElement |
HTMLElementTypeId::HTMLProgressElement |
HTMLElementTypeId::HTMLSelectElement |
HTMLElementTypeId::HTMLTextAreaElement => true,
_ => false,
},
_ => false,
}
}
}
impl VirtualMethods for HTMLElement {