mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
tidy and test fixes
This commit is contained in:
parent
5a07227db5
commit
8bfcc6992e
7 changed files with 44 additions and 20 deletions
|
@ -20,6 +20,7 @@ SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
|
|||
font_variant_ligatures font_variant_east_asian
|
||||
font_variant_numeric font_language_override""".split()
|
||||
|
||||
|
||||
def maybe_moz_logical_alias(product, side, prop):
|
||||
if product == "gecko" and side[1]:
|
||||
axis, dir = side[0].split("-")
|
||||
|
@ -38,9 +39,10 @@ def to_rust_ident(name):
|
|||
def to_camel_case(ident):
|
||||
return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-"))
|
||||
|
||||
|
||||
def to_camel_case_lower(ident):
|
||||
camel = to_camel_case(ident)
|
||||
return camel[0].lower() + camel[1:]
|
||||
return camel[0].lower() + camel[1:]
|
||||
|
||||
|
||||
def parse_aliases(value):
|
||||
|
|
|
@ -95,6 +95,7 @@ pub struct ComputedValues {
|
|||
/// When this is Some, we compute font sizes by computing the keyword against
|
||||
/// the generic font, and then multiplying it by the ratio.
|
||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
/// The cached system font. See longhand/font.mako.rs
|
||||
pub cached_system_font: Option<longhands::system_font::ComputedSystemFont>,
|
||||
}
|
||||
|
||||
|
|
|
@ -411,7 +411,8 @@ impl AnimationValue {
|
|||
}
|
||||
|
||||
/// Construct an AnimationValue from a property declaration
|
||||
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context, initial: &ComputedValues) -> Option<Self> {
|
||||
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context,
|
||||
initial: &ComputedValues) -> Option<Self> {
|
||||
use error_reporting::StdoutErrorReporter;
|
||||
use properties::LonghandId;
|
||||
use properties::DeclaredValue;
|
||||
|
|
|
@ -45,12 +45,12 @@
|
|||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::Value(v) => v,
|
||||
SpecifiedValue::System(_) => {
|
||||
<%self:nongecko_unreachable>
|
||||
context.style.cached_system_font.as_ref().unwrap().${name}
|
||||
_context.style.cached_system_font.as_ref().unwrap().${name}
|
||||
</%self:nongecko_unreachable>
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%helpers:longhand name="font-family" animation_type="none" need_index="True"
|
||||
<%helpers:longhand name="font-family" animation_type="none" need_index="True" boxed="${product == 'gecko'}"
|
||||
spec="https://drafts.csswg.org/css-fonts/#propdef-font-family">
|
||||
use properties::longhands::system_font::SystemFont;
|
||||
use self::computed_value::{FontFamily, FamilyName};
|
||||
|
@ -1850,7 +1850,8 @@ ${helpers.single_keyword_system("font-variant-position",
|
|||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="font-language-override" products="gecko" animation_type="none" extra_prefixes="moz"
|
||||
<%helpers:longhand name="font-language-override" products="gecko" animation_type="none"
|
||||
extra_prefixes="moz" boxed="True"
|
||||
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override">
|
||||
use properties::longhands::system_font::SystemFont;
|
||||
use std::fmt;
|
||||
|
@ -1938,7 +1939,7 @@ ${helpers.single_keyword_system("font-variant-position",
|
|||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
||||
use std::ascii::AsciiExt;
|
||||
match *self {
|
||||
SpecifiedValue::Normal => computed_value::T(0),
|
||||
|
@ -1955,7 +1956,7 @@ ${helpers.single_keyword_system("font-variant-position",
|
|||
}
|
||||
SpecifiedValue::System(_) => {
|
||||
<%self:nongecko_unreachable>
|
||||
context.style.cached_system_font.as_ref().unwrap().font_language_override
|
||||
_context.style.cached_system_font.as_ref().unwrap().font_language_override
|
||||
</%self:nongecko_unreachable>
|
||||
}
|
||||
}
|
||||
|
@ -2180,6 +2181,21 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
|
||||
% if product == "gecko":
|
||||
pub mod system_font {
|
||||
//! We deal with system fonts here
|
||||
//!
|
||||
//! System fonts can only be set as a group via the font shorthand.
|
||||
//! They resolve at compute time (not parse time -- this lets the
|
||||
//! browser respond to changes to the OS font settings).
|
||||
//!
|
||||
//! While Gecko handles these as a separate property and keyword
|
||||
//! values on each property indicating that the font should be picked
|
||||
//! from the -x-system-font property, we avoid this. Instead,
|
||||
//! each font longhand has a special SystemFont variant which contains
|
||||
//! the specified system font. When the cascade function (in helpers)
|
||||
//! detects that a value has a system font, it will resolve it, and
|
||||
//! cache it on the ComputedValues. After this, it can be just fetched
|
||||
//! whenever a font longhand on the same element needs the system font.
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use properties::longhands;
|
||||
|
@ -2270,7 +2286,8 @@ ${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),
|
||||
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_', ''))}
|
||||
|
@ -2279,7 +2296,8 @@ ${helpers.single_keyword("-moz-math-variant",
|
|||
% endif
|
||||
),
|
||||
% endfor
|
||||
font_language_override: longhands::font_language_override::computed_value::T(system.languageOverride),
|
||||
font_language_override: longhands::font_language_override::computed_value
|
||||
::T(system.languageOverride),
|
||||
system_font: *self,
|
||||
};
|
||||
unsafe { bindings::Gecko_nsFont_Destroy(&mut system); }
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
|
||||
use properties::longhands::{font_family, font_style, font_weight, font_stretch};
|
||||
use properties::longhands::{font_size, line_height, font_variant_caps};
|
||||
#[cfg(feature = "gecko")]
|
||||
use properties::longhands::system_font::SystemFont;
|
||||
<%
|
||||
gecko_sub_properties = "kerning language_override size_adjust \
|
||||
|
@ -31,7 +32,7 @@
|
|||
use properties::longhands::font_${prop};
|
||||
% endfor
|
||||
% endif
|
||||
use properties::longhands::font_family::SpecifiedValue as FontFamily;
|
||||
use self::font_family::SpecifiedValue as FontFamily;
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let mut nb_normals = 0;
|
||||
|
@ -114,13 +115,13 @@
|
|||
})
|
||||
}
|
||||
|
||||
enum CheckSystemResult {
|
||||
AllSystem(SystemFont),
|
||||
SomeSystem,
|
||||
None
|
||||
}
|
||||
|
||||
% if product == "gecko":
|
||||
enum CheckSystemResult {
|
||||
AllSystem(SystemFont),
|
||||
SomeSystem,
|
||||
None
|
||||
}
|
||||
|
||||
impl<'a> LonghandsToSerialize<'a> {
|
||||
/// Check if some or all members are system fonts
|
||||
fn check_system(&self) -> CheckSystemResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue