mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
tidy and test fixes
This commit is contained in:
parent
5a07227db5
commit
8bfcc6992e
7 changed files with 44 additions and 20 deletions
|
@ -11,8 +11,8 @@ use gecko_bindings::bindings::Gecko_Atomize;
|
||||||
use gecko_bindings::bindings::Gecko_Atomize16;
|
use gecko_bindings::bindings::Gecko_Atomize16;
|
||||||
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
use gecko_bindings::bindings::Gecko_ReleaseAtom;
|
||||||
use gecko_bindings::structs::nsIAtom;
|
use gecko_bindings::structs::nsIAtom;
|
||||||
use precomputed_hash::PrecomputedHash;
|
|
||||||
use nsstring::nsAString;
|
use nsstring::nsAString;
|
||||||
|
use precomputed_hash::PrecomputedHash;
|
||||||
use std::borrow::{Cow, Borrow};
|
use std::borrow::{Cow, Borrow};
|
||||||
use std::char::{self, DecodeUtf16};
|
use std::char::{self, DecodeUtf16};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
|
|
@ -20,6 +20,7 @@ SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
|
||||||
font_variant_ligatures font_variant_east_asian
|
font_variant_ligatures font_variant_east_asian
|
||||||
font_variant_numeric font_language_override""".split()
|
font_variant_numeric font_language_override""".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]:
|
||||||
axis, dir = side[0].split("-")
|
axis, dir = side[0].split("-")
|
||||||
|
@ -38,9 +39,10 @@ def to_rust_ident(name):
|
||||||
def to_camel_case(ident):
|
def to_camel_case(ident):
|
||||||
return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-"))
|
return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-"))
|
||||||
|
|
||||||
|
|
||||||
def to_camel_case_lower(ident):
|
def to_camel_case_lower(ident):
|
||||||
camel = to_camel_case(ident)
|
camel = to_camel_case(ident)
|
||||||
return camel[0].lower() + camel[1:]
|
return camel[0].lower() + camel[1:]
|
||||||
|
|
||||||
|
|
||||||
def parse_aliases(value):
|
def parse_aliases(value):
|
||||||
|
|
|
@ -95,6 +95,7 @@ pub struct ComputedValues {
|
||||||
/// When this is Some, we compute font sizes by computing the keyword against
|
/// When this is Some, we compute font sizes by computing the keyword against
|
||||||
/// the generic font, and then multiplying it by the ratio.
|
/// the generic font, and then multiplying it by the ratio.
|
||||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
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>,
|
pub cached_system_font: Option<longhands::system_font::ComputedSystemFont>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,8 @@ impl AnimationValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct an AnimationValue from a property declaration
|
/// 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 error_reporting::StdoutErrorReporter;
|
||||||
use properties::LonghandId;
|
use properties::LonghandId;
|
||||||
use properties::DeclaredValue;
|
use properties::DeclaredValue;
|
||||||
|
|
|
@ -45,12 +45,12 @@
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
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 {
|
match *self {
|
||||||
SpecifiedValue::Value(v) => v,
|
SpecifiedValue::Value(v) => v,
|
||||||
SpecifiedValue::System(_) => {
|
SpecifiedValue::System(_) => {
|
||||||
<%self:nongecko_unreachable>
|
<%self:nongecko_unreachable>
|
||||||
context.style.cached_system_font.as_ref().unwrap().${name}
|
_context.style.cached_system_font.as_ref().unwrap().${name}
|
||||||
</%self:nongecko_unreachable>
|
</%self:nongecko_unreachable>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
}
|
}
|
||||||
</%def>
|
</%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">
|
spec="https://drafts.csswg.org/css-fonts/#propdef-font-family">
|
||||||
use properties::longhands::system_font::SystemFont;
|
use properties::longhands::system_font::SystemFont;
|
||||||
use self::computed_value::{FontFamily, FamilyName};
|
use self::computed_value::{FontFamily, FamilyName};
|
||||||
|
@ -1850,7 +1850,8 @@ ${helpers.single_keyword_system("font-variant-position",
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%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">
|
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override">
|
||||||
use properties::longhands::system_font::SystemFont;
|
use properties::longhands::system_font::SystemFont;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -1938,7 +1939,7 @@ ${helpers.single_keyword_system("font-variant-position",
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
|
||||||
#[inline]
|
#[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;
|
use std::ascii::AsciiExt;
|
||||||
match *self {
|
match *self {
|
||||||
SpecifiedValue::Normal => computed_value::T(0),
|
SpecifiedValue::Normal => computed_value::T(0),
|
||||||
|
@ -1955,7 +1956,7 @@ ${helpers.single_keyword_system("font-variant-position",
|
||||||
}
|
}
|
||||||
SpecifiedValue::System(_) => {
|
SpecifiedValue::System(_) => {
|
||||||
<%self:nongecko_unreachable>
|
<%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>
|
</%self:nongecko_unreachable>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2180,6 +2181,21 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
|
|
||||||
% if product == "gecko":
|
% if product == "gecko":
|
||||||
pub mod system_font {
|
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 app_units::Au;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use properties::longhands;
|
use properties::longhands;
|
||||||
|
@ -2270,7 +2286,8 @@ ${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),
|
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_', ''))}
|
system.${to_camel_case_lower(kwprop.replace('font_', ''))}
|
||||||
|
@ -2279,7 +2296,8 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
% endif
|
% endif
|
||||||
),
|
),
|
||||||
% endfor
|
% 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,
|
system_font: *self,
|
||||||
};
|
};
|
||||||
unsafe { bindings::Gecko_nsFont_Destroy(&mut system); }
|
unsafe { bindings::Gecko_nsFont_Destroy(&mut system); }
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
|
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_family, font_style, font_weight, font_stretch};
|
||||||
use properties::longhands::{font_size, line_height, font_variant_caps};
|
use properties::longhands::{font_size, line_height, font_variant_caps};
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
use properties::longhands::system_font::SystemFont;
|
use properties::longhands::system_font::SystemFont;
|
||||||
<%
|
<%
|
||||||
gecko_sub_properties = "kerning language_override size_adjust \
|
gecko_sub_properties = "kerning language_override size_adjust \
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
use properties::longhands::font_${prop};
|
use properties::longhands::font_${prop};
|
||||||
% endfor
|
% endfor
|
||||||
% endif
|
% 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, ()> {
|
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||||
let mut nb_normals = 0;
|
let mut nb_normals = 0;
|
||||||
|
@ -114,13 +115,13 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CheckSystemResult {
|
|
||||||
AllSystem(SystemFont),
|
|
||||||
SomeSystem,
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
% if product == "gecko":
|
% if product == "gecko":
|
||||||
|
enum CheckSystemResult {
|
||||||
|
AllSystem(SystemFont),
|
||||||
|
SomeSystem,
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> LonghandsToSerialize<'a> {
|
impl<'a> LonghandsToSerialize<'a> {
|
||||||
/// Check if some or all members are system fonts
|
/// Check if some or all members are system fonts
|
||||||
fn check_system(&self) -> CheckSystemResult {
|
fn check_system(&self) -> CheckSystemResult {
|
||||||
|
|
|
@ -1631,7 +1631,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations:
|
||||||
let mut parser = Parser::new(&string);
|
let mut parser = Parser::new(&string);
|
||||||
if let Ok(family) = FontFamily::parse(&mut parser) {
|
if let Ok(family) = FontFamily::parse(&mut parser) {
|
||||||
if parser.is_exhausted() {
|
if parser.is_exhausted() {
|
||||||
let decl = PropertyDeclaration::FontFamily(family);
|
let decl = PropertyDeclaration::FontFamily(Box::new(family));
|
||||||
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
|
||||||
decls.push(decl, Importance::Normal);
|
decls.push(decl, Importance::Normal);
|
||||||
})
|
})
|
||||||
|
@ -1956,7 +1956,8 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
||||||
.filter_map(|&(ref decl, imp)| {
|
.filter_map(|&(ref decl, imp)| {
|
||||||
if imp == Importance::Normal {
|
if imp == Importance::Normal {
|
||||||
let property = TransitionProperty::from_declaration(decl);
|
let property = TransitionProperty::from_declaration(decl);
|
||||||
let animation = AnimationValue::from_declaration(decl, &mut context, default_values);
|
let animation = AnimationValue::from_declaration(decl, &mut context,
|
||||||
|
default_values);
|
||||||
debug_assert!(property.is_none() == animation.is_none(),
|
debug_assert!(property.is_none() == animation.is_none(),
|
||||||
"The failure condition of TransitionProperty::from_declaration \
|
"The failure condition of TransitionProperty::from_declaration \
|
||||||
and AnimationValue::from_declaration should be the same");
|
and AnimationValue::from_declaration should be the same");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue