Implement support for 'disabled' property in HTMLOptGroupElement

This commit is contained in:
Bruno de Oliveira Abinader 2014-06-27 16:21:44 -04:00
parent 4e37b3c8c7
commit 1e52a5afb8
3 changed files with 74 additions and 4 deletions

View file

@ -3,14 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementDerived;
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLOptGroupElementDerived, HTMLOptionElementDerived};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::HTMLOptGroupElementTypeId;
use dom::element::{AttributeHandlers, Element, HTMLOptGroupElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId};
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;
use servo_util::str::DOMString;
#[deriving(Encodable)]
@ -37,6 +40,66 @@ impl HTMLOptGroupElement {
}
}
impl<'a> HTMLOptGroupElementMethods for JSRef<'a, HTMLOptGroupElement> {
// http://www.whatwg.org/html#dom-optgroup-disabled
fn Disabled(&self) -> bool {
let elem: &JSRef<Element> = ElementCast::from_ref(self);
elem.has_attribute("disabled")
}
// http://www.whatwg.org/html#dom-optgroup-disabled
fn SetDisabled(&self, disabled: bool) {
let elem: &JSRef<Element> = ElementCast::from_ref(self);
elem.set_bool_attribute("disabled", disabled)
}
}
impl<'a> VirtualMethods for JSRef<'a, HTMLOptGroupElement> {
fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> {
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
Some(htmlelement as &VirtualMethods)
}
fn after_set_attr(&self, name: DOMString, value: DOMString) {
match self.super_type() {
Some(ref s) => s.after_set_attr(name.clone(), value.clone()),
_ => (),
}
let node: &JSRef<Node> = NodeCast::from_ref(self);
match name.as_slice() {
"disabled" => {
node.set_disabled_state(true);
node.set_enabled_state(false);
for child in node.children().filter(|child| child.is_htmloptionelement()) {
child.set_disabled_state(true);
child.set_enabled_state(false);
}
},
_ => ()
}
}
fn before_remove_attr(&self, name: DOMString, value: DOMString) {
match self.super_type() {
Some(ref s) => s.before_remove_attr(name.clone(), value),
_ => (),
}
let node: &JSRef<Node> = NodeCast::from_ref(self);
match name.as_slice() {
"disabled" => {
node.set_disabled_state(false);
node.set_enabled_state(true);
for child in node.children().filter(|child| child.is_htmloptionelement()) {
child.check_disabled_attribute();
}
},
_ => ()
}
}
}
impl Reflectable for HTMLOptGroupElement {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.htmlelement.reflector()