mirror of
https://github.com/servo/servo.git
synced 2025-08-01 11:40:30 +01:00
Implement <font> 'face' attribute
This commit is contained in:
parent
768993f03f
commit
3ae76f4e76
8 changed files with 72 additions and 138 deletions
|
@ -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,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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue