diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index bebe74935aa..c597a0a4204 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -2,6 +2,7 @@ * 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 cssparser::RGBA; use devtools_traits::AttrInfo; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods}; @@ -28,6 +29,7 @@ pub enum AttrValue { UInt(DOMString, u32), Atom(Atom), Length(DOMString, Option), + Color(DOMString, Option), } impl AttrValue { @@ -98,6 +100,18 @@ impl AttrValue { } } + /// Assumes the `AttrValue` is a `Color` and returns its value + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `Color` + pub fn as_color(&self) -> Option<&RGBA> { + match *self { + AttrValue::Color(_, ref color) => color.as_ref(), + _ => panic!("Color not found"), + } + } + /// Assumes the `AttrValue` is a `Length` and returns its value /// /// ## Panics @@ -134,7 +148,8 @@ impl Deref for AttrValue { AttrValue::String(ref value) | AttrValue::TokenList(ref value, _) | AttrValue::UInt(ref value, _) | - AttrValue::Length(ref value, _) => &value, + AttrValue::Length(ref value, _) | + AttrValue::Color(ref value, _) => &value, AttrValue::Atom(ref value) => &value, } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index b10f5c3f272..39633b64fef 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -298,6 +298,9 @@ impl LayoutElementHelpers for LayoutJS { let color = if let Some(this) = HTMLFontElementCast::to_layout_js(self) { (*this.unsafe_get()).get_color() + } else if let Some(this) = HTMLBodyElementCast::to_layout_js(self) { + // https://html.spec.whatwg.org/multipage/#the-page:the-body-element-20 + (*this.unsafe_get()).get_color() } else { None }; 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> { let win = window_from_node(self); @@ -92,6 +103,16 @@ impl HTMLBodyElement { self.background_color.get() } + #[allow(unsafe_code)] + pub fn get_color(&self) -> Option { + 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 { unsafe { @@ -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) { diff --git a/components/script/dom/webidls/HTMLBodyElement.webidl b/components/script/dom/webidls/HTMLBodyElement.webidl index f68f51e866e..baf9a106e2a 100644 --- a/components/script/dom/webidls/HTMLBodyElement.webidl +++ b/components/script/dom/webidls/HTMLBodyElement.webidl @@ -11,7 +11,7 @@ HTMLBodyElement implements WindowEventHandlers; // https://www.whatwg.org/html/#HTMLBodyElement-partial partial interface HTMLBodyElement { - //[TreatNullAs=EmptyString] attribute DOMString text; + [TreatNullAs=EmptyString] attribute DOMString text; //[TreatNullAs=EmptyString] attribute DOMString link; //[TreatNullAs=EmptyString] attribute DOMString vLink; //[TreatNullAs=EmptyString] attribute DOMString aLink; diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 066606a1e71..a6ac270327b 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -2199,9 +2199,6 @@ [HTMLBodyElement interface: existence and properties of interface object] expected: FAIL - [HTMLBodyElement interface: attribute text] - expected: FAIL - [HTMLBodyElement interface: attribute link] expected: FAIL @@ -2250,9 +2247,6 @@ [HTMLBodyElement interface: attribute onstorage] expected: FAIL - [HTMLBodyElement interface: document.createElement("body") must inherit property "text" with the proper type (0)] - expected: FAIL - [HTMLBodyElement interface: document.createElement("body") must inherit property "link" with the proper type (1)] expected: FAIL diff --git a/tests/wpt/metadata/html/dom/reflection-sections.html.ini b/tests/wpt/metadata/html/dom/reflection-sections.html.ini index 21a5e3af112..614ea231332 100644 --- a/tests/wpt/metadata/html/dom/reflection-sections.html.ini +++ b/tests/wpt/metadata/html/dom/reflection-sections.html.ini @@ -459,135 +459,6 @@ [body.tabIndex: IDL set to -2147483648 followed by getAttribute()] expected: FAIL - [body.text: typeof IDL attribute] - expected: FAIL - - [body.text: IDL get with DOM attribute unset] - expected: FAIL - - [body.text: setAttribute() to "" followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to undefined followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to 7 followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to 1.5 followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to true followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to false followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to object "[object Object\]" followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to NaN followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to Infinity followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to -Infinity followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to "\\0" followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to null followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to object "test-toString" followed by IDL get] - expected: FAIL - - [body.text: setAttribute() to object "test-valueOf" followed by IDL get] - expected: FAIL - - [body.text: IDL set to "" followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo " followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to undefined followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to undefined followed by IDL get] - expected: FAIL - - [body.text: IDL set to 7 followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to 7 followed by IDL get] - expected: FAIL - - [body.text: IDL set to 1.5 followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to 1.5 followed by IDL get] - expected: FAIL - - [body.text: IDL set to true followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to true followed by IDL get] - expected: FAIL - - [body.text: IDL set to false followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to false followed by IDL get] - expected: FAIL - - [body.text: IDL set to object "[object Object\]" followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to object "[object Object\]" followed by IDL get] - expected: FAIL - - [body.text: IDL set to NaN followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to NaN followed by IDL get] - expected: FAIL - - [body.text: IDL set to Infinity followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to Infinity followed by IDL get] - expected: FAIL - - [body.text: IDL set to -Infinity followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to -Infinity followed by IDL get] - expected: FAIL - - [body.text: IDL set to "\\0" followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to null followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to null followed by IDL get] - expected: FAIL - - [body.text: IDL set to object "test-toString" followed by getAttribute()] - expected: FAIL - - [body.text: IDL set to object "test-toString" followed by IDL get] - expected: FAIL - - [body.text: IDL set to object "test-valueOf" followed by IDL get] - expected: FAIL - [body.link: typeof IDL attribute] expected: FAIL diff --git a/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-02.html.ini b/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-02.html.ini index c06048bc398..14623905ce0 100644 --- a/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-02.html.ini +++ b/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-02.html.ini @@ -12,3 +12,6 @@ [document: fg/bg/link/vlink/alink-color 5] expected: FAIL + [document: fg/bg/link/vlink/alink-color] + expected: FAIL + diff --git a/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-03.html.ini b/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-03.html.ini index f89ad9e82df..fe56f27ac9d 100644 --- a/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-03.html.ini +++ b/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-03.html.ini @@ -12,3 +12,6 @@ [document: fg/bg/link/vlink/alink-color 5] expected: FAIL + [document: fg/bg/link/vlink/alink-color] + expected: FAIL + diff --git a/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-04.html.ini b/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-04.html.ini index 9a926969914..adf0104f035 100644 --- a/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-04.html.ini +++ b/tests/wpt/metadata/html/obsolete/requirements-for-implementations/other-elements-attributes-and-apis/document-color-04.html.ini @@ -12,3 +12,6 @@ [document: fg/bg/link/vlink/alink-color 5] expected: FAIL + [document: fg/bg/link/vlink/alink-color] + expected: FAIL + diff --git a/tests/wpt/metadata/html/rendering/non-replaced-elements/the-page/body_text_00ffff.xhtml.ini b/tests/wpt/metadata/html/rendering/non-replaced-elements/the-page/body_text_00ffff.xhtml.ini deleted file mode 100644 index 0b78fe3508a..00000000000 --- a/tests/wpt/metadata/html/rendering/non-replaced-elements/the-page/body_text_00ffff.xhtml.ini +++ /dev/null @@ -1,5 +0,0 @@ -[body_text_00ffff.xhtml] - type: reftest - reftype: == - refurl: /html/rendering/non-replaced-elements/the-page/body_text_00ffff-ref.html - expected: FAIL