diff options
author | Corey Farwell <coreyf@rwell.org> | 2015-09-13 22:54:23 -0400 |
---|---|---|
committer | Corey Farwell <coreyf@rwell.org> | 2015-09-14 20:24:52 -0400 |
commit | 3ae76f4e7610cfb7af05102292842aafcb62d334 (patch) | |
tree | 9aef97c7710b31416b96373bc24ef06253b57de5 /components/script/dom | |
parent | 768993f03f338171e58ba7214bcdb6da75df6b26 (diff) | |
download | servo-3ae76f4e7610cfb7af05102292842aafcb62d334.tar.gz servo-3ae76f4e7610cfb7af05102292842aafcb62d334.zip |
Implement <font> 'face' attribute
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/element.rs | 18 | ||||
-rw-r--r-- | components/script/dom/htmlfontelement.rs | 33 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLFontElement.webidl | 2 |
3 files changed, 50 insertions, 3 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index bd522dccf0a..337f7799138 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -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() diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index dbd876b1751..bee1711916e 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -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,9 +81,21 @@ 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), + } + } } @@ -81,4 +103,13 @@ 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, + } + } } diff --git a/components/script/dom/webidls/HTMLFontElement.webidl b/components/script/dom/webidls/HTMLFontElement.webidl index 03b68498db7..8419fcab10f 100644 --- a/components/script/dom/webidls/HTMLFontElement.webidl +++ b/components/script/dom/webidls/HTMLFontElement.webidl @@ -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; }; |