Implement <font> 'face' attribute

This commit is contained in:
Corey Farwell 2015-09-13 22:54:23 -04:00
parent 768993f03f
commit 3ae76f4e76
8 changed files with 72 additions and 138 deletions

View file

@ -62,7 +62,7 @@ use devtools_traits::AttrInfo;
use smallvec::VecLike; use smallvec::VecLike;
use style::legacy::{UnsignedIntegerAttribute, from_declaration}; use style::legacy::{UnsignedIntegerAttribute, from_declaration};
use style::properties::DeclaredValue; use style::properties::DeclaredValue;
use style::properties::longhands::{self, background_image, border_spacing}; use style::properties::longhands::{self, background_image, border_spacing, font_family};
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute};
use style::values::CSSFloat; use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA}; use style::values::specified::{self, CSSColor, CSSRGBA};
@ -302,6 +302,22 @@ impl RawLayoutElementHelpers for Element {
})))); }))));
} }
let font_family = if self.is_htmlfontelement() {
let this: &HTMLFontElement = mem::transmute(self);
this.get_face()
} else {
None
};
if let Some(font_family) = font_family {
hints.push(from_declaration(
PropertyDeclaration::FontFamily(
DeclaredValue::Value(
font_family::computed_value::T(vec![
font_family::computed_value::FontFamily::FamilyName(
font_family)])))));
}
let cellspacing = if self.is_htmltableelement() { let cellspacing = if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self); let this: &HTMLTableElement = mem::transmute(self);
this.get_cellspacing() this.get_cellspacing()

View file

@ -2,7 +2,8 @@
* 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 dom::attr::Attr; use dom::attr::{Attr, AttrValue};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HTMLFontElementBinding; use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods; use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFontElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFontElementDerived};
@ -13,6 +14,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId}; use dom::node::{Node, NodeTypeId};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use util::str::{self, DOMString}; use util::str::{self, DOMString};
use cssparser::RGBA; use cssparser::RGBA;
@ -22,6 +24,7 @@ use std::cell::Cell;
pub struct HTMLFontElement { pub struct HTMLFontElement {
htmlelement: HTMLElement, htmlelement: HTMLElement,
color: Cell<Option<RGBA>>, color: Cell<Option<RGBA>>,
face: DOMRefCell<Option<Atom>>,
} }
impl HTMLFontElementDerived for EventTarget { impl HTMLFontElementDerived for EventTarget {
@ -37,6 +40,7 @@ impl HTMLFontElement {
HTMLFontElement { HTMLFontElement {
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document), htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document),
color: Cell::new(None), color: Cell::new(None),
face: DOMRefCell::new(None),
} }
} }
@ -55,6 +59,12 @@ impl HTMLFontElementMethods for HTMLFontElement {
// https://html.spec.whatwg.org/multipage/#dom-font-color // https://html.spec.whatwg.org/multipage/#dom-font-color
make_setter!(SetColor, "color"); make_setter!(SetColor, "color");
// https://html.spec.whatwg.org/multipage/#dom-font-face
make_getter!(Face);
// https://html.spec.whatwg.org/multipage/#dom-font-face
make_atomic_setter!(SetFace, "face");
} }
impl VirtualMethods for HTMLFontElement { impl VirtualMethods for HTMLFontElement {
@ -71,9 +81,21 @@ impl VirtualMethods for HTMLFontElement {
str::parse_legacy_color(&value).ok() str::parse_legacy_color(&value).ok()
})); }));
}, },
&atom!(face) => {
*self.face.borrow_mut() =
mutation.new_value(attr)
.map(|value| value.as_atom().clone())
},
_ => {}, _ => {},
} }
} }
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("face") => AttrValue::from_atomic(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
} }
@ -81,4 +103,13 @@ impl HTMLFontElement {
pub fn get_color(&self) -> Option<RGBA> { pub fn get_color(&self) -> Option<RGBA> {
self.color.get() self.color.get()
} }
#[allow(unsafe_code)]
pub fn get_face(&self) -> Option<Atom> {
let face = unsafe { self.face.borrow_for_layout() };
match *face {
Some(ref s) => Some(s.clone()),
None => None,
}
}
} }

View file

@ -6,6 +6,6 @@
// https://www.whatwg.org/html/#htmlfontelement // https://www.whatwg.org/html/#htmlfontelement
interface HTMLFontElement : HTMLElement { interface HTMLFontElement : HTMLElement {
[TreatNullAs=EmptyString] attribute DOMString color; [TreatNullAs=EmptyString] attribute DOMString color;
// attribute DOMString face; attribute DOMString face;
// attribute DOMString size; // attribute DOMString size;
}; };

View file

@ -121,6 +121,7 @@ prefs:"layout.flex.enabled" == flex_row_direction.html flex_row_direction_ref.ht
== focus_selector.html focus_selector_ref.html == focus_selector.html focus_selector_ref.html
== font_advance.html font_advance_ref.html == font_advance.html font_advance_ref.html
== font_color_attribute_a.html font_color_attribute_ref.html == font_color_attribute_a.html font_color_attribute_ref.html
== font_face_attribute.html font_face_attribute_ref.html
== font_size.html font_size_ref.html == font_size.html font_size_ref.html
== font_style.html font_style_ref.html == font_style.html font_style_ref.html
== height_compute_reset.html height_compute.html == height_compute_reset.html height_compute.html

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><font face=monospace>Servo</font></p>
<p><font id=1>Servo</font></p>
<script>
document.getElementById("1").face = "monospace";
</script>
</body>
</html>

View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body style="font-family: monospace">
<p>Servo</p>
<p>Servo</p>
</body>
</html>

View file

@ -8736,15 +8736,9 @@
[HTMLFontElement interface: existence and properties of interface object] [HTMLFontElement interface: existence and properties of interface object]
expected: FAIL expected: FAIL
[HTMLFontElement interface: attribute face]
expected: FAIL
[HTMLFontElement interface: attribute size] [HTMLFontElement interface: attribute size]
expected: FAIL expected: FAIL
[HTMLFontElement interface: document.createElement("font") must inherit property "face" with the proper type (1)]
expected: FAIL
[HTMLFontElement interface: document.createElement("font") must inherit property "size" with the proper type (2)] [HTMLFontElement interface: document.createElement("font") must inherit property "size" with the proper type (2)]
expected: FAIL expected: FAIL

View file

@ -8523,135 +8523,6 @@
[font.tabIndex: IDL set to -2147483648 followed by getAttribute()] [font.tabIndex: IDL set to -2147483648 followed by getAttribute()]
expected: FAIL expected: FAIL
[font.face: typeof IDL attribute]
expected: FAIL
[font.face: IDL get with DOM attribute unset]
expected: FAIL
[font.face: setAttribute() to "" followed by IDL get]
expected: FAIL
[font.face: 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
[font.face: setAttribute() to undefined followed by IDL get]
expected: FAIL
[font.face: setAttribute() to 7 followed by IDL get]
expected: FAIL
[font.face: setAttribute() to 1.5 followed by IDL get]
expected: FAIL
[font.face: setAttribute() to true followed by IDL get]
expected: FAIL
[font.face: setAttribute() to false followed by IDL get]
expected: FAIL
[font.face: setAttribute() to object "[object Object\]" followed by IDL get]
expected: FAIL
[font.face: setAttribute() to NaN followed by IDL get]
expected: FAIL
[font.face: setAttribute() to Infinity followed by IDL get]
expected: FAIL
[font.face: setAttribute() to -Infinity followed by IDL get]
expected: FAIL
[font.face: setAttribute() to "\\0" followed by IDL get]
expected: FAIL
[font.face: setAttribute() to null followed by IDL get]
expected: FAIL
[font.face: setAttribute() to object "test-toString" followed by IDL get]
expected: FAIL
[font.face: setAttribute() to object "test-valueOf" followed by IDL get]
expected: FAIL
[font.face: IDL set to "" followed by getAttribute()]
expected: FAIL
[font.face: 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
[font.face: IDL set to undefined followed by getAttribute()]
expected: FAIL
[font.face: IDL set to undefined followed by IDL get]
expected: FAIL
[font.face: IDL set to 7 followed by getAttribute()]
expected: FAIL
[font.face: IDL set to 7 followed by IDL get]
expected: FAIL
[font.face: IDL set to 1.5 followed by getAttribute()]
expected: FAIL
[font.face: IDL set to 1.5 followed by IDL get]
expected: FAIL
[font.face: IDL set to true followed by getAttribute()]
expected: FAIL
[font.face: IDL set to true followed by IDL get]
expected: FAIL
[font.face: IDL set to false followed by getAttribute()]
expected: FAIL
[font.face: IDL set to false followed by IDL get]
expected: FAIL
[font.face: IDL set to object "[object Object\]" followed by getAttribute()]
expected: FAIL
[font.face: IDL set to object "[object Object\]" followed by IDL get]
expected: FAIL
[font.face: IDL set to NaN followed by getAttribute()]
expected: FAIL
[font.face: IDL set to NaN followed by IDL get]
expected: FAIL
[font.face: IDL set to Infinity followed by getAttribute()]
expected: FAIL
[font.face: IDL set to Infinity followed by IDL get]
expected: FAIL
[font.face: IDL set to -Infinity followed by getAttribute()]
expected: FAIL
[font.face: IDL set to -Infinity followed by IDL get]
expected: FAIL
[font.face: IDL set to "\\0" followed by getAttribute()]
expected: FAIL
[font.face: IDL set to null followed by getAttribute()]
expected: FAIL
[font.face: IDL set to null followed by IDL get]
expected: FAIL
[font.face: IDL set to object "test-toString" followed by getAttribute()]
expected: FAIL
[font.face: IDL set to object "test-toString" followed by IDL get]
expected: FAIL
[font.face: IDL set to object "test-valueOf" followed by IDL get]
expected: FAIL
[font.size: typeof IDL attribute] [font.size: typeof IDL attribute]
expected: FAIL expected: FAIL