Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement <font> 'face' attribute #7619

Merged
merged 2 commits into from Sep 15, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Implement <font> 'face' attribute

  • Loading branch information
frewsxcv committed Sep 15, 2015
commit 3ae76f4e7610cfb7af05102292842aafcb62d334
@@ -62,7 +62,7 @@ use devtools_traits::AttrInfo;
use smallvec::VecLike;
use style::legacy::{UnsignedIntegerAttribute, from_declaration};
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::values::CSSFloat;
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 this: &HTMLTableElement = mem::transmute(self);
this.get_cellspacing()
@@ -2,7 +2,8 @@
* 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::attr::Attr;
use dom::attr::{Attr, AttrValue};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFontElementDerived};
@@ -13,6 +14,7 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId};
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use util::str::{self, DOMString};

use cssparser::RGBA;
@@ -22,6 +24,7 @@ use std::cell::Cell;
pub struct HTMLFontElement {
htmlelement: HTMLElement,
color: Cell<Option<RGBA>>,
face: DOMRefCell<Option<Atom>>,
}

impl HTMLFontElementDerived for EventTarget {
@@ -37,6 +40,7 @@ impl HTMLFontElement {
HTMLFontElement {
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document),
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
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 {
@@ -71,14 +81,35 @@ impl VirtualMethods for HTMLFontElement {
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),
}
}
}


impl HTMLFontElement {
pub fn get_color(&self) -> Option<RGBA> {
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,
}
}
}
@@ -6,6 +6,6 @@
// https://www.whatwg.org/html/#htmlfontelement
interface HTMLFontElement : HTMLElement {
[TreatNullAs=EmptyString] attribute DOMString color;
// attribute DOMString face;
attribute DOMString face;
// attribute DOMString size;
};
@@ -121,6 +121,7 @@ prefs:"layout.flex.enabled" == flex_row_direction.html flex_row_direction_ref.ht
== focus_selector.html focus_selector_ref.html
== font_advance.html font_advance_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_style.html font_style_ref.html
== height_compute_reset.html height_compute.html
@@ -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>
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body style="font-family: monospace">
<p>Servo</p>
<p>Servo</p>
</body>
</html>
@@ -8736,15 +8736,9 @@
[HTMLFontElement interface: existence and properties of interface object]
expected: FAIL
[HTMLFontElement interface: attribute face]
expected: FAIL
[HTMLFontElement interface: attribute size]
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)]
expected: FAIL
@@ -8523,135 +8523,6 @@
[font.tabIndex: IDL set to -2147483648 followed by getAttribute()]
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]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.