mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
stylo: System font support for font-size-adjust
This commit is contained in:
parent
5184f29e10
commit
83484c7054
3 changed files with 53 additions and 6 deletions
|
@ -15,7 +15,7 @@ ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size
|
|||
|
||||
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]:
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
@ -901,6 +902,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
|||
pub enum SpecifiedValue {
|
||||
None,
|
||||
Number(specified::Number),
|
||||
System(SystemFont),
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
|
@ -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(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue