Skip to content

Commit

Permalink
Implement support for 'disabled' property in HTMLOptGroupElement
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Aug 5, 2014
1 parent 4e37b3c commit 1e52a5a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
69 changes: 66 additions & 3 deletions src/components/script/dom/htmloptgroupelement.rs
Expand Up @@ -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)]
Expand All @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions src/components/script/dom/virtualmethods.rs
Expand Up @@ -14,6 +14,7 @@ use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast;
use dom::bindings::codegen::InheritTypes::HTMLImageElementCast;
use dom::bindings::codegen::InheritTypes::HTMLInputElementCast;
use dom::bindings::codegen::InheritTypes::HTMLObjectElementCast;
use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementCast;
use dom::bindings::codegen::InheritTypes::HTMLStyleElementCast;
use dom::bindings::js::JSRef;
use dom::element::Element;
Expand All @@ -27,6 +28,7 @@ use dom::element::HTMLIFrameElementTypeId;
use dom::element::HTMLImageElementTypeId;
use dom::element::HTMLInputElementTypeId;
use dom::element::HTMLObjectElementTypeId;
use dom::element::HTMLOptGroupElementTypeId;
use dom::element::HTMLStyleElementTypeId;
use dom::event::Event;
use dom::htmlanchorelement::HTMLAnchorElement;
Expand All @@ -39,6 +41,7 @@ use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmlimageelement::HTMLImageElement;
use dom::htmlinputelement::HTMLInputElement;
use dom::htmlobjectelement::HTMLObjectElement;
use dom::htmloptgroupelement::HTMLOptGroupElement;
use dom::htmlstyleelement::HTMLStyleElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use servo_util::str::DOMString;
Expand Down Expand Up @@ -156,6 +159,10 @@ pub fn vtable_for<'a>(node: &'a JSRef<Node>) -> &'a VirtualMethods {
let element: &JSRef<HTMLObjectElement> = HTMLObjectElementCast::to_ref(node).unwrap();
element as &VirtualMethods
}
ElementNodeTypeId(HTMLOptGroupElementTypeId) => {
let element: &JSRef<HTMLOptGroupElement> = HTMLOptGroupElementCast::to_ref(node).unwrap();
element as &VirtualMethods
}
ElementNodeTypeId(HTMLStyleElementTypeId) => {
let element: &JSRef<HTMLStyleElement> = HTMLStyleElementCast::to_ref(node).unwrap();
element as &VirtualMethods
Expand Down
Expand Up @@ -5,6 +5,6 @@

// http://www.whatwg.org/html/#htmloptgroupelement
interface HTMLOptGroupElement : HTMLElement {
// attribute boolean disabled;
attribute boolean disabled;
// attribute DOMString label;
};

0 comments on commit 1e52a5a

Please sign in to comment.