Auto merge of #7841 - frewsxcv:htmlbodyelement-text, r=nox

Implement <body>'s "text" attribute



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7841)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-09 06:11:46 -06:00
commit 1029feb55d
10 changed files with 63 additions and 145 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::RGBA;
use devtools_traits::AttrInfo; use devtools_traits::AttrInfo;
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods}; use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods};
@ -28,6 +29,7 @@ pub enum AttrValue {
UInt(DOMString, u32), UInt(DOMString, u32),
Atom(Atom), Atom(Atom),
Length(DOMString, Option<Length>), Length(DOMString, Option<Length>),
Color(DOMString, Option<RGBA>),
} }
impl AttrValue { 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 /// Assumes the `AttrValue` is a `Length` and returns its value
/// ///
/// ## Panics /// ## Panics
@ -134,7 +148,8 @@ impl Deref for AttrValue {
AttrValue::String(ref value) | AttrValue::String(ref value) |
AttrValue::TokenList(ref value, _) | AttrValue::TokenList(ref value, _) |
AttrValue::UInt(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, AttrValue::Atom(ref value) => &value,
} }
} }

View file

@ -298,6 +298,9 @@ impl LayoutElementHelpers for LayoutJS<Element> {
let color = if let Some(this) = HTMLFontElementCast::to_layout_js(self) { let color = if let Some(this) = HTMLFontElementCast::to_layout_js(self) {
(*this.unsafe_get()).get_color() (*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 { } else {
None None
}; };

View file

@ -3,17 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::RGBA; use cssparser::RGBA;
use dom::attr::Attr; use dom::attr::{Attr, AttrValue};
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods}; use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; 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::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
use dom::bindings::js::Root; use dom::bindings::js::Root;
use dom::bindings::utils::Reflectable; use dom::bindings::utils::Reflectable;
use dom::document::Document; use dom::document::Document;
use dom::element::{AttributeMutation, ElementTypeId}; use dom::element::{AttributeMutation, ElementTypeId, RawLayoutElementHelpers};
use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId, document_from_node, window_from_node}; 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::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
use std::rc::Rc; use std::rc::Rc;
use string_cache::Atom;
use time; use time;
use url::{Url, UrlParser}; use url::{Url, UrlParser};
use util::str::{self, DOMString}; use util::str::{self, DOMString};
@ -73,6 +74,16 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
// https://html.spec.whatwg.org/multipage#dom-body-bgcolor // https://html.spec.whatwg.org/multipage#dom-body-bgcolor
make_setter!(SetBgColor, "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 // https://html.spec.whatwg.org/multipage/#the-body-element
fn GetOnunload(&self) -> Option<Rc<EventHandlerNonNull>> { fn GetOnunload(&self) -> Option<Rc<EventHandlerNonNull>> {
let win = window_from_node(self); let win = window_from_node(self);
@ -92,6 +103,16 @@ impl HTMLBodyElement {
self.background_color.get() self.background_color.get()
} }
#[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)] #[allow(unsafe_code)]
pub fn get_background(&self) -> Option<Url> { pub fn get_background(&self) -> Option<Url> {
unsafe { unsafe {
@ -123,6 +144,16 @@ impl VirtualMethods for HTMLBodyElement {
chan.send(event).unwrap(); 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) { fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation); self.super_type().unwrap().attribute_mutated(attr, mutation);
match (attr.local_name(), mutation) { match (attr.local_name(), mutation) {

View file

@ -11,7 +11,7 @@ HTMLBodyElement implements WindowEventHandlers;
// https://www.whatwg.org/html/#HTMLBodyElement-partial // https://www.whatwg.org/html/#HTMLBodyElement-partial
partial interface HTMLBodyElement { partial interface HTMLBodyElement {
//[TreatNullAs=EmptyString] attribute DOMString text; [TreatNullAs=EmptyString] attribute DOMString text;
//[TreatNullAs=EmptyString] attribute DOMString link; //[TreatNullAs=EmptyString] attribute DOMString link;
//[TreatNullAs=EmptyString] attribute DOMString vLink; //[TreatNullAs=EmptyString] attribute DOMString vLink;
//[TreatNullAs=EmptyString] attribute DOMString aLink; //[TreatNullAs=EmptyString] attribute DOMString aLink;

View file

@ -2199,9 +2199,6 @@
[HTMLBodyElement interface: existence and properties of interface object] [HTMLBodyElement interface: existence and properties of interface object]
expected: FAIL expected: FAIL
[HTMLBodyElement interface: attribute text]
expected: FAIL
[HTMLBodyElement interface: attribute link] [HTMLBodyElement interface: attribute link]
expected: FAIL expected: FAIL
@ -2250,9 +2247,6 @@
[HTMLBodyElement interface: attribute onstorage] [HTMLBodyElement interface: attribute onstorage]
expected: FAIL 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)] [HTMLBodyElement interface: document.createElement("body") must inherit property "link" with the proper type (1)]
expected: FAIL expected: FAIL

View file

@ -459,135 +459,6 @@
[body.tabIndex: IDL set to -2147483648 followed by getAttribute()] [body.tabIndex: IDL set to -2147483648 followed by getAttribute()]
expected: FAIL 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] [body.link: typeof IDL attribute]
expected: FAIL expected: FAIL

View file

@ -12,3 +12,6 @@
[document: fg/bg/link/vlink/alink-color 5] [document: fg/bg/link/vlink/alink-color 5]
expected: FAIL expected: FAIL
[document: fg/bg/link/vlink/alink-color]
expected: FAIL

View file

@ -12,3 +12,6 @@
[document: fg/bg/link/vlink/alink-color 5] [document: fg/bg/link/vlink/alink-color 5]
expected: FAIL expected: FAIL
[document: fg/bg/link/vlink/alink-color]
expected: FAIL

View file

@ -12,3 +12,6 @@
[document: fg/bg/link/vlink/alink-color 5] [document: fg/bg/link/vlink/alink-color 5]
expected: FAIL expected: FAIL
[document: fg/bg/link/vlink/alink-color]
expected: FAIL

View file

@ -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