Skip to content

Commit

Permalink
tidy and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Apr 19, 2017
1 parent 59f16b5 commit 14c6324
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion components/style/gecko_string_cache/mod.rs
Expand Up @@ -11,8 +11,8 @@ use gecko_bindings::bindings::Gecko_Atomize;
use gecko_bindings::bindings::Gecko_Atomize16;
use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::structs::nsIAtom;
use precomputed_hash::PrecomputedHash;
use nsstring::nsAString;
use precomputed_hash::PrecomputedHash;
use std::borrow::{Cow, Borrow};
use std::char::{self, DecodeUtf16};
use std::fmt::{self, Write};
Expand Down
4 changes: 3 additions & 1 deletion components/style/properties/data.py
Expand Up @@ -20,6 +20,7 @@
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("-")
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -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>,
}

Expand Down
Expand Up @@ -360,7 +360,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;
Expand Down
34 changes: 26 additions & 8 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -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>
}
}
Expand All @@ -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};
Expand Down Expand Up @@ -1770,7 +1770,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;
Expand Down Expand Up @@ -1858,7 +1859,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),
Expand All @@ -1875,7 +1876,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>
}
}
Expand Down Expand Up @@ -2100,6 +2101,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;
Expand Down Expand Up @@ -2190,7 +2206,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_', ''))}
Expand All @@ -2199,7 +2216,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); }
Expand Down
15 changes: 8 additions & 7 deletions components/style/properties/shorthand/font.mako.rs
Expand Up @@ -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 \
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions ports/geckolib/glue.rs
Expand Up @@ -1631,7 +1631,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations:
let mut parser = Parser::new(&string);
if let Ok(family) = FontFamily::parse(&mut parser) {
if parser.is_exhausted() {
let decl = PropertyDeclaration::FontFamily(family);
let decl = PropertyDeclaration::FontFamily(Box::new(family));
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
decls.push(decl, Importance::Normal);
})
Expand Down Expand Up @@ -1956,7 +1956,8 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
.filter_map(|&(ref decl, imp)| {
if imp == Importance::Normal {
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(),
"The failure condition of TransitionProperty::from_declaration \
and AnimationValue::from_declaration should be the same");
Expand Down

0 comments on commit 14c6324

Please sign in to comment.