mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
stylo: System font support for font-size-adjust
This commit is contained in:
parent
4a899530be
commit
f973a9720d
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
|
SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
|
||||||
font_variant_caps font_stretch font_kerning
|
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):
|
def maybe_moz_logical_alias(product, side, prop):
|
||||||
if product == "gecko" and side[1]:
|
if product == "gecko" and side[1]:
|
||||||
|
|
|
@ -1405,10 +1405,7 @@ fn static_assert() {
|
||||||
pub fn clone_font_size_adjust(&self) -> longhands::font_size_adjust::computed_value::T {
|
pub fn clone_font_size_adjust(&self) -> longhands::font_size_adjust::computed_value::T {
|
||||||
use properties::longhands::font_size_adjust::computed_value::T;
|
use properties::longhands::font_size_adjust::computed_value::T;
|
||||||
|
|
||||||
match self.gecko.mFont.sizeAdjust {
|
T::from_gecko_adjust(self.gecko.mFont.sizeAdjust)
|
||||||
-1.0 => T::None,
|
|
||||||
_ => T::Number(self.gecko.mFont.sizeAdjust),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -821,6 +821,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
|
|
||||||
<%helpers:longhand products="gecko" name="font-size-adjust" animation_type="normal"
|
<%helpers:longhand products="gecko" name="font-size-adjust" animation_type="normal"
|
||||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust">
|
spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust">
|
||||||
|
use properties::longhands::system_font::SystemFont;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::HasViewportPercentage;
|
use values::HasViewportPercentage;
|
||||||
|
@ -832,6 +833,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
pub enum SpecifiedValue {
|
pub enum SpecifiedValue {
|
||||||
None,
|
None,
|
||||||
Number(specified::Number),
|
Number(specified::Number),
|
||||||
|
System(SystemFont),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for SpecifiedValue {
|
impl ToCss for SpecifiedValue {
|
||||||
|
@ -841,6 +843,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
match *self {
|
match *self {
|
||||||
SpecifiedValue::None => dest.write_str("none"),
|
SpecifiedValue::None => dest.write_str("none"),
|
||||||
SpecifiedValue::Number(number) => number.to_css(dest),
|
SpecifiedValue::Number(number) => number.to_css(dest),
|
||||||
|
SpecifiedValue::System(_) => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -852,6 +855,11 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
match *self {
|
match *self {
|
||||||
SpecifiedValue::None => computed_value::T::None,
|
SpecifiedValue::None => computed_value::T::None,
|
||||||
SpecifiedValue::Number(ref n) => computed_value::T::Number(n.to_computed_value(context)),
|
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>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,6 +871,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 {
|
pub mod computed_value {
|
||||||
use properties::animated_properties::Interpolate;
|
use properties::animated_properties::Interpolate;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -887,6 +908,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 {
|
impl Interpolate for T {
|
||||||
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
|
||||||
match (*self, *other) {
|
match (*self, *other) {
|
||||||
|
@ -1921,6 +1951,7 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use properties::longhands;
|
use properties::longhands;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
use values::computed::{ToComputedValue, Context};
|
use values::computed::{ToComputedValue, Context};
|
||||||
<%
|
<%
|
||||||
system_fonts = """caption icon menu message-box small-caption status-bar
|
system_fonts = """caption icon menu message-box small-caption status-bar
|
||||||
|
@ -1937,6 +1968,24 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
% endfor
|
% 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 {
|
impl ToComputedValue for SystemFont {
|
||||||
type ComputedValue = ComputedSystemFont;
|
type ComputedValue = ComputedSystemFont;
|
||||||
|
|
||||||
|
@ -1973,6 +2022,7 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
font_family: longhands::font_family::computed_value::T(family),
|
font_family: longhands::font_family::computed_value::T(family),
|
||||||
font_size: Au(system.size),
|
font_size: Au(system.size),
|
||||||
font_weight: weight,
|
font_weight: weight,
|
||||||
|
font_size_adjust: longhands::font_size_adjust::computed_value::T::from_gecko_adjust(system.sizeAdjust),
|
||||||
% for kwprop in kw_font_props:
|
% for kwprop in kw_font_props:
|
||||||
${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword(
|
${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword(
|
||||||
system.${to_camel_case_lower(kwprop.replace('font_', ''))} as u32
|
system.${to_camel_case_lower(kwprop.replace('font_', ''))} as u32
|
||||||
|
@ -2002,7 +2052,7 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
debug_assert!(system == context.style.cached_system_font.as_ref().unwrap().system_font)
|
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 {
|
pub struct ComputedSystemFont {
|
||||||
% for name in SYSTEM_FONT_LONGHANDS:
|
% for name in SYSTEM_FONT_LONGHANDS:
|
||||||
pub ${name}: longhands::${name}::computed_value::T,
|
pub ${name}: longhands::${name}::computed_value::T,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue