aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlhrelement.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2015-11-08 11:45:11 -0500
committerCorey Farwell <coreyf@rwell.org>2015-11-08 18:34:27 -0500
commitee0800abe9a00b089d703a28b3a58b13529bfdbd (patch)
tree425707ffb013bf9a1a6b3ff5f607dc63824dc19c /components/script/dom/htmlhrelement.rs
parent9bcae9a866b85a90b75b9cbfcb9058287c1c0871 (diff)
downloadservo-ee0800abe9a00b089d703a28b3a58b13529bfdbd.tar.gz
servo-ee0800abe9a00b089d703a28b3a58b13529bfdbd.zip
Implement <hr> 'color' attribute
Diffstat (limited to 'components/script/dom/htmlhrelement.rs')
-rw-r--r--components/script/dom/htmlhrelement.rs51
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),
+ }
+ }
+}