diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/attr.rs | 31 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 2 | ||||
-rw-r--r-- | components/script/dom/element.rs | 15 | ||||
-rw-r--r-- | components/script/dom/htmlfontelement.rs | 27 | ||||
-rw-r--r-- | components/script/dom/webidls/HTMLFontElement.webidl | 2 |
5 files changed, 71 insertions, 6 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 70f315bcac3..2cd742ee422 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -18,6 +18,7 @@ use std::cell::Ref; use std::mem; use std::ops::Deref; use string_cache::{Atom, Namespace}; +use style::values::specified::Length; use util::str::{DOMString, parse_unsigned_integer, split_html_space_chars, str_join}; #[derive(JSTraceable, PartialEq, Clone, HeapSizeOf)] @@ -26,6 +27,7 @@ pub enum AttrValue { TokenList(DOMString, Vec<Atom>), UInt(DOMString, u32), Atom(Atom), + Length(DOMString, Option<Length>), } impl AttrValue { @@ -72,6 +74,11 @@ impl AttrValue { AttrValue::Atom(value) } + /// Assumes the `AttrValue` is a `TokenList` and returns its tokens + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `TokenList` pub fn as_tokens(&self) -> &[Atom] { match *self { AttrValue::TokenList(_, ref tokens) => tokens, @@ -79,6 +86,11 @@ impl AttrValue { } } + /// Assumes the `AttrValue` is an `Atom` and returns its value + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not an `Atom` pub fn as_atom(&self) -> &Atom { match *self { AttrValue::Atom(ref value) => value, @@ -86,9 +98,25 @@ impl AttrValue { } } + /// Assumes the `AttrValue` is a `Length` and returns its value + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `Length` + pub fn as_length(&self) -> Option<&Length> { + match *self { + AttrValue::Length(_, ref length) => length.as_ref(), + _ => panic!("Length not found"), + } + } + /// Return the AttrValue as its integer representation, if any. /// This corresponds to attribute values returned as `AttrValue::UInt(_)` /// by `VirtualMethods::parse_plain_attribute()`. + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `UInt` pub fn as_uint(&self) -> u32 { if let AttrValue::UInt(_, value) = *self { value @@ -105,7 +133,8 @@ impl Deref for AttrValue { match *self { AttrValue::String(ref value) | AttrValue::TokenList(ref value, _) | - AttrValue::UInt(ref value, _) => &value, + AttrValue::UInt(ref value, _) | + AttrValue::Length(ref value, _) => &value, AttrValue::Atom(ref value) => &value, } } diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 94d3ad97c93..00a7f6c6c90 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -77,6 +77,7 @@ use std::sync::Arc; use std::sync::mpsc::{Receiver, Sender}; use string_cache::{Atom, Namespace}; use style::properties::PropertyDeclarationBlock; +use style::values::specified::Length; use url::Url; use util::str::{LengthOrPercentageOrAuto}; @@ -301,6 +302,7 @@ no_jsmanaged_fields!(WebGLError); no_jsmanaged_fields!(TimeProfilerChan); no_jsmanaged_fields!(MemProfilerChan); no_jsmanaged_fields!(PseudoElement); +no_jsmanaged_fields!(Length); impl JSTraceable for Box<ScriptChan + Send> { #[inline] diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index f99bd564dbe..d1db97128f0 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -71,7 +71,7 @@ use std::sync::Arc; use string_cache::{Atom, Namespace, QualName}; use style::legacy::{UnsignedIntegerAttribute, from_declaration}; use style::properties::DeclaredValue; -use style::properties::longhands::{self, background_image, border_spacing, font_family}; +use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; use style::values::CSSFloat; use style::values::specified::{self, CSSColor, CSSRGBA}; @@ -302,6 +302,19 @@ impl RawLayoutElementHelpers for Element { font_family)]))))); } + let font_size = if let Some(this) = HTMLFontElementCast::to_ref(self) { + this.get_size() + } else { + None + }; + + if let Some(font_size) = font_size { + hints.push(from_declaration( + PropertyDeclaration::FontSize( + DeclaredValue::Value( + font_size::SpecifiedValue(font_size))))) + } + let cellspacing = if let Some(this) = HTMLTableElementCast::to_ref(self) { this.get_cellspacing() } else { 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() + } + } } diff --git a/components/script/dom/webidls/HTMLFontElement.webidl b/components/script/dom/webidls/HTMLFontElement.webidl index 8419fcab10f..2b718558513 100644 --- a/components/script/dom/webidls/HTMLFontElement.webidl +++ b/components/script/dom/webidls/HTMLFontElement.webidl @@ -7,5 +7,5 @@ interface HTMLFontElement : HTMLElement { [TreatNullAs=EmptyString] attribute DOMString color; attribute DOMString face; - // attribute DOMString size; + attribute DOMString size; }; |