mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #16016 - Manishearth:graft-font-size, r=upsuper
Add separate specified value for keyword font sizes In Gecko, these keywords compute to different values depending on the font. See https://bugzilla.mozilla.org/show_bug.cgi?id=1341775 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16016) <!-- Reviewable:end -->
This commit is contained in:
commit
50fd39f068
6 changed files with 162 additions and 109 deletions
|
@ -478,7 +478,10 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
if let Some(font_size) = font_size {
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::FontSize(font_size::SpecifiedValue(font_size.into()))))
|
||||
PropertyDeclaration::FontSize(
|
||||
font_size::SpecifiedValue::from_html_size(font_size as u8)
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
let cellspacing = if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||
|
|
|
@ -18,7 +18,6 @@ use html5ever_atoms::LocalName;
|
|||
use servo_atoms::Atom;
|
||||
use style::attr::AttrValue;
|
||||
use style::str::{HTML_SPACE_CHARACTERS, read_numbers};
|
||||
use style::values::specified;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLFontElement {
|
||||
|
@ -62,8 +61,7 @@ impl HTMLFontElementMethods for HTMLFontElement {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-font-size
|
||||
fn SetSize(&self, value: DOMString) {
|
||||
let element = self.upcast::<Element>();
|
||||
let length = parse_length(&value);
|
||||
element.set_attribute(&local_name!("size"), AttrValue::Length(value.into(), length));
|
||||
element.set_attribute(&local_name!("size"), parse_size(&value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,10 +74,7 @@ impl VirtualMethods for HTMLFontElement {
|
|||
match name {
|
||||
&local_name!("face") => AttrValue::from_atomic(value.into()),
|
||||
&local_name!("color") => AttrValue::from_legacy_color(value.into()),
|
||||
&local_name!("size") => {
|
||||
let length = parse_length(&value);
|
||||
AttrValue::Length(value.into(), length)
|
||||
},
|
||||
&local_name!("size") => parse_size(&value),
|
||||
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +83,7 @@ impl VirtualMethods for HTMLFontElement {
|
|||
pub trait HTMLFontElementLayoutHelpers {
|
||||
fn get_color(&self) -> Option<RGBA>;
|
||||
fn get_face(&self) -> Option<Atom>;
|
||||
fn get_size(&self) -> Option<specified::Length>;
|
||||
fn get_size(&self) -> Option<u32>;
|
||||
}
|
||||
|
||||
impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
|
||||
|
@ -113,18 +108,21 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn get_size(&self) -> Option<specified::Length> {
|
||||
unsafe {
|
||||
fn get_size(&self) -> Option<u32> {
|
||||
let size = unsafe {
|
||||
(*self.upcast::<Element>().unsafe_get())
|
||||
.get_attr_for_layout(&ns!(), &local_name!("size"))
|
||||
.and_then(AttrValue::as_length)
|
||||
.cloned()
|
||||
};
|
||||
match size {
|
||||
Some(&AttrValue::UInt(_, s)) => Some(s),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
|
||||
fn parse_length(mut input: &str) -> Option<specified::Length> {
|
||||
fn parse_size(mut input: &str) -> AttrValue {
|
||||
let original_input = input;
|
||||
// Steps 1 & 2 are not relevant
|
||||
|
||||
// Step 3
|
||||
|
@ -138,7 +136,7 @@ fn parse_length(mut input: &str) -> Option<specified::Length> {
|
|||
let mut input_chars = input.chars().peekable();
|
||||
let parse_mode = match input_chars.peek() {
|
||||
// Step 4
|
||||
None => return None,
|
||||
None => return AttrValue::String(original_input.into()),
|
||||
|
||||
// Step 5
|
||||
Some(&'+') => {
|
||||
|
@ -155,7 +153,7 @@ fn parse_length(mut input: &str) -> Option<specified::Length> {
|
|||
// Steps 6, 7, 8
|
||||
let mut value = match read_numbers(input_chars) {
|
||||
(Some(v), _) if v >= 0 => v,
|
||||
_ => return None,
|
||||
_ => return AttrValue::String(original_input.into()),
|
||||
};
|
||||
|
||||
// Step 9
|
||||
|
@ -166,5 +164,5 @@ fn parse_length(mut input: &str) -> Option<specified::Length> {
|
|||
}
|
||||
|
||||
// Steps 10, 11, 12
|
||||
Some(specified::Length::from_font_size_int(value as u8))
|
||||
AttrValue::UInt(original_input.into(), value as u32)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue