aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlbodyelement.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2015-10-03 14:02:58 -0400
committerCorey Farwell <coreyf@rwell.org>2015-10-08 10:55:12 -0400
commit64f4835a4f490ede8b264d611013ee33ea6ad9fe (patch)
treebc8f420d36d53ad4a052eb4c63305c3acea0db58 /components/script/dom/htmlbodyelement.rs
parent26dd1233103eb75c2e94fcc2ba34c18fa4432afc (diff)
downloadservo-64f4835a4f490ede8b264d611013ee33ea6ad9fe.tar.gz
servo-64f4835a4f490ede8b264d611013ee33ea6ad9fe.zip
Implement <body>'s "text" attribute
Diffstat (limited to 'components/script/dom/htmlbodyelement.rs')
-rw-r--r--components/script/dom/htmlbodyelement.rs37
1 files changed, 34 insertions, 3 deletions
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index a86e1375453..6dc5bcdcd83 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -3,17 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::RGBA;
-use dom::attr::Attr;
+use dom::attr::{Attr, AttrValue};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
-use dom::bindings::codegen::InheritTypes::{EventTargetCast};
+use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast};
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
use dom::bindings::js::Root;
use dom::bindings::utils::Reflectable;
use dom::document::Document;
-use dom::element::{AttributeMutation, ElementTypeId};
+use dom::element::{AttributeMutation, ElementTypeId, RawLayoutElementHelpers};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId, document_from_node, window_from_node};
@@ -23,6 +23,7 @@ use msg::constellation_msg::Msg as ConstellationMsg;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::rc::Rc;
+use string_cache::Atom;
use time;
use url::{Url, UrlParser};
use util::str::{self, DOMString};
@@ -73,6 +74,16 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
// https://html.spec.whatwg.org/multipage#dom-body-bgcolor
make_setter!(SetBgColor, "bgcolor");
+ // https://html.spec.whatwg.org/multipage/#dom-body-text
+ make_getter!(Text);
+
+ // https://html.spec.whatwg.org/multipage/#dom-body-text
+ fn SetText(&self, value: DOMString) {
+ let element = ElementCast::from_ref(self);
+ let color = str::parse_legacy_color(&value).ok();
+ element.set_attribute(&Atom::from_slice("text"), AttrValue::Color(value, color));
+ }
+
// https://html.spec.whatwg.org/multipage/#the-body-element
fn GetOnunload(&self) -> Option<Rc<EventHandlerNonNull>> {
let win = window_from_node(self);
@@ -93,6 +104,16 @@ impl HTMLBodyElement {
}
#[allow(unsafe_code)]
+ pub fn get_color(&self) -> Option<RGBA> {
+ unsafe {
+ ElementCast::from_ref(self)
+ .get_attr_for_layout(&ns!(""), &atom!("text"))
+ .and_then(AttrValue::as_color)
+ .cloned()
+ }
+ }
+
+ #[allow(unsafe_code)]
pub fn get_background(&self) -> Option<Url> {
unsafe {
self.background.borrow_for_layout().clone()
@@ -123,6 +144,16 @@ impl VirtualMethods for HTMLBodyElement {
chan.send(event).unwrap();
}
+ fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
+ match name {
+ &atom!("text") => {
+ let parsed = str::parse_legacy_color(&value).ok();
+ AttrValue::Color(value, parsed)
+ },
+ _ => self.super_type().unwrap().parse_plain_attribute(name, value),
+ }
+ }
+
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match (attr.local_name(), mutation) {