diff options
author | Corey Farwell <coreyf@rwell.org> | 2015-09-19 15:04:11 -0400 |
---|---|---|
committer | Corey Farwell <coreyf@rwell.org> | 2015-09-30 22:51:30 -0400 |
commit | 74e4c4fdc747669f55a639125576d69cb8fa1547 (patch) | |
tree | 80067f4cbc1bb3db7e0085d55b8e0c91cdfdca22 /components/script/dom/htmlfontelement.rs | |
parent | 520c907742afbb94085c6b5e62156a5457530010 (diff) | |
download | servo-74e4c4fdc747669f55a639125576d69cb8fa1547.tar.gz servo-74e4c4fdc747669f55a639125576d69cb8fa1547.zip |
Implement `size` attribute for <font> element
Diffstat (limited to 'components/script/dom/htmlfontelement.rs')
-rw-r--r-- | components/script/dom/htmlfontelement.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index 030d1638c7e..873079bee11 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -7,17 +7,18 @@ 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}; +use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFontElementDerived}; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::{AttributeMutation, ElementTypeId}; +use dom::element::{AttributeMutation, ElementTypeId, RawLayoutElementHelpers}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use std::cell::Cell; use string_cache::Atom; -use util::str::{self, DOMString}; +use style::values::specified; +use util::str::{self, DOMString, parse_legacy_font_size}; #[dom_struct] pub struct HTMLFontElement { @@ -64,6 +65,12 @@ impl HTMLFontElementMethods for HTMLFontElement { // https://html.spec.whatwg.org/multipage/#dom-font-face make_atomic_setter!(SetFace, "face"); + + // https://html.spec.whatwg.org/multipage/#dom-font-size + make_getter!(Size); + + // https://html.spec.whatwg.org/multipage/#dom-font-size + make_setter!(SetSize, "size"); } impl VirtualMethods for HTMLFontElement { @@ -92,6 +99,10 @@ impl VirtualMethods for HTMLFontElement { fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { match name { &atom!("face") => AttrValue::from_atomic(value), + &atom!("size") => { + let length = parse_legacy_font_size(&value).and_then(|parsed| specified::Length::from_str(&parsed)); + AttrValue::Length(value, length) + }, _ => self.super_type().unwrap().parse_plain_attribute(name, value), } } @@ -111,4 +122,14 @@ impl HTMLFontElement { None => None, } } + + #[allow(unsafe_code)] + pub fn get_size(&self) -> Option<specified::Length> { + unsafe { + ElementCast::from_ref(self) + .get_attr_for_layout(&ns!(""), &atom!("size")) + .and_then(AttrValue::as_length) + .cloned() + } + } } |