Skip to content

Commit

Permalink
stylo: System font support for font-size-adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Apr 21, 2017
1 parent 5184f29 commit 83484c7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/style/properties/data.py
Expand Up @@ -15,7 +15,7 @@

SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_variant_caps font_stretch font_kerning
font_variant_position font_weight""".split()
font_variant_position font_weight font_size_adjust""".split()

def maybe_moz_logical_alias(product, side, prop):
if product == "gecko" and side[1]:
Expand Down
5 changes: 1 addition & 4 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1564,10 +1564,7 @@ fn static_assert() {
pub fn clone_font_size_adjust(&self) -> longhands::font_size_adjust::computed_value::T {
use properties::longhands::font_size_adjust::computed_value::T;

match self.gecko.mFont.sizeAdjust {
-1.0 => T::None,
_ => T::Number(self.gecko.mFont.sizeAdjust),
}
T::from_gecko_adjust(self.gecko.mFont.sizeAdjust)
}

#[allow(non_snake_case)]
Expand Down
52 changes: 51 additions & 1 deletion components/style/properties/longhand/font.mako.rs
Expand Up @@ -890,6 +890,7 @@ ${helpers.single_keyword_system("font-variant-caps",

<%helpers:longhand products="gecko" name="font-size-adjust" animation_type="normal"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust">
use properties::longhands::system_font::SystemFont;
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
Expand All @@ -901,6 +902,7 @@ ${helpers.single_keyword_system("font-variant-caps",
pub enum SpecifiedValue {
None,
Number(specified::Number),
System(SystemFont),
}

impl ToCss for SpecifiedValue {
Expand All @@ -910,6 +912,7 @@ ${helpers.single_keyword_system("font-variant-caps",
match *self {
SpecifiedValue::None => dest.write_str("none"),
SpecifiedValue::Number(number) => number.to_css(dest),
SpecifiedValue::System(_) => Ok(()),
}
}
}
Expand All @@ -921,6 +924,11 @@ ${helpers.single_keyword_system("font-variant-caps",
match *self {
SpecifiedValue::None => computed_value::T::None,
SpecifiedValue::Number(ref n) => computed_value::T::Number(n.to_computed_value(context)),
SpecifiedValue::System(_) => {
<%self:nongecko_unreachable>
context.style.cached_system_font.as_ref().unwrap().font_size_adjust
</%self:nongecko_unreachable>
}
}
}

Expand All @@ -932,6 +940,19 @@ ${helpers.single_keyword_system("font-variant-caps",
}
}

impl SpecifiedValue {
pub fn system_font(f: SystemFont) -> Self {
SpecifiedValue::System(f)
}
pub fn get_system(&self) -> Option<SystemFont> {
if let SpecifiedValue::System(s) = *self {
Some(s)
} else {
None
}
}
}

pub mod computed_value {
use properties::animated_properties::{ComputeDistance, Interpolate};
use std::fmt;
Expand All @@ -956,6 +977,15 @@ ${helpers.single_keyword_system("font-variant-caps",
}
}

impl T {
pub fn from_gecko_adjust(gecko: f32) -> Self {
match gecko {
-1.0 => T::None,
_ => T::Number(gecko),
}
}
}

impl Interpolate for T {
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
match (*self, *other) {
Expand Down Expand Up @@ -2001,6 +2031,7 @@ ${helpers.single_keyword("-moz-math-variant",
use app_units::Au;
use cssparser::Parser;
use properties::longhands;
use std::hash::{Hash, Hasher};
use values::computed::{ToComputedValue, Context};
<%
system_fonts = """caption icon menu message-box small-caption status-bar
Expand All @@ -2017,6 +2048,24 @@ ${helpers.single_keyword("-moz-math-variant",
% endfor
}

// ComputedValues are compared at times
// so we need these impls. We don't want to
// add Eq to Number (which contains a float)
// so instead we have an eq impl which skips the
// cached values
impl PartialEq for ComputedSystemFont {
fn eq(&self, other: &Self) -> bool {
self.system_font == other.system_font
}
}
impl Eq for ComputedSystemFont {}

impl Hash for ComputedSystemFont {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.system_font.hash(hasher)
}
}

impl ToComputedValue for SystemFont {
type ComputedValue = ComputedSystemFont;

Expand Down Expand Up @@ -2053,6 +2102,7 @@ ${helpers.single_keyword("-moz-math-variant",
font_family: longhands::font_family::computed_value::T(family),
font_size: Au(system.size),
font_weight: weight,
font_size_adjust: longhands::font_size_adjust::computed_value::T::from_gecko_adjust(system.sizeAdjust),
% for kwprop in kw_font_props:
${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword(
system.${to_camel_case_lower(kwprop.replace('font_', ''))} as u32
Expand Down Expand Up @@ -2082,7 +2132,7 @@ ${helpers.single_keyword("-moz-math-variant",
debug_assert!(system == context.style.cached_system_font.as_ref().unwrap().system_font)
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug)]
pub struct ComputedSystemFont {
% for name in SYSTEM_FONT_LONGHANDS:
pub ${name}: longhands::${name}::computed_value::T,
Expand Down

0 comments on commit 83484c7

Please sign in to comment.