diff options
Diffstat (limited to 'components/script/dom/htmlhrelement.rs')
-rw-r--r-- | components/script/dom/htmlhrelement.rs | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/components/script/dom/htmlhrelement.rs b/components/script/dom/htmlhrelement.rs index dc5ab695d6b..6f2362f592c 100644 --- a/components/script/dom/htmlhrelement.rs +++ b/components/script/dom/htmlhrelement.rs @@ -2,11 +2,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::codegen::Bindings::HTMLHRElementBinding; -use dom::bindings::js::Root; +use cssparser::RGBA; +use dom::attr::AttrValue; +use dom::bindings::codegen::Bindings::HTMLHRElementBinding::{self, HTMLHRElementMethods}; +use dom::bindings::inheritance::Castable; +use dom::bindings::js::{LayoutJS, Root}; use dom::document::Document; +use dom::element::{Element, RawLayoutElementHelpers}; use dom::htmlelement::HTMLElement; use dom::node::Node; +use dom::virtualmethods::VirtualMethods; +use string_cache::Atom; use util::str::DOMString; #[dom_struct] @@ -29,3 +35,44 @@ impl HTMLHRElement { Node::reflect_node(box element, document, HTMLHRElementBinding::Wrap) } } + +impl HTMLHRElementMethods for HTMLHRElement { + // https://html.spec.whatwg.org/multipage/#dom-hr-color + make_getter!(Color); + + // https://html.spec.whatwg.org/multipage/#dom-hr-color + fn SetColor(&self, value: DOMString) { + self.upcast::<Element>() + .set_attribute(&atom!("color"), AttrValue::from_legacy_color(value)); + } +} + +pub trait HTMLHRLayoutHelpers { + fn get_color(&self) -> Option<RGBA>; +} + +impl HTMLHRLayoutHelpers for LayoutJS<HTMLHRElement> { + #[allow(unsafe_code)] + fn get_color(&self) -> Option<RGBA> { + unsafe { + (&*self.upcast::<Element>().unsafe_get()) + .get_attr_for_layout(&ns!(""), &atom!("color")) + .and_then(AttrValue::as_color) + .cloned() + } + } +} + + +impl VirtualMethods for HTMLHRElement { + fn super_type(&self) -> Option<&VirtualMethods> { + Some(self.upcast::<HTMLElement>() as &VirtualMethods) + } + + fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { + match name { + &atom!("color") => AttrValue::from_legacy_color(value), + _ => self.super_type().unwrap().parse_plain_attribute(name, value), + } + } +} |