servo: Merge #20191 - style: Make 'font' shorthand reset 'font-variation-settings' property (from jfkthame:font-shorthand-resets-variation-settings); r=emilio

As required by the spec: https://drafts.csswg.org/css-fonts-4/#font-prop

See https://bugzilla.mozilla.org/show_bug.cgi?id=1435983

Basically, make font-variation-settings work in the same way as font-feature-settings
already does.

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

- [ ] There are tests for these changes OR
- [X] These changes do not require tests because font-variation-settings isn't supported in servo; it is implemented here for gecko/stylo, and will be tested by mozilla-central mochitests.

Source-Repo: https://github.com/servo/servo
Source-Revision: 1783e41f34c75bc7dfb158b4aa2628fd945eceb3

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : ccc26bb6fcbce339c34504dc3c493cee879970a0
This commit is contained in:
Jonathan Kew 2018-03-04 11:50:56 -05:00
parent 0bb1806dc2
commit 9137f16912
8 changed files with 87 additions and 14 deletions

View File

@ -26,7 +26,7 @@ use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
use style_traits::{StyleParseErrorKind, ToCss};
use values::computed::font::FamilyName;
#[cfg(feature = "gecko")]
use values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
use values::specified::url::SpecifiedUrl;
/// A source for a font-face rule.
@ -397,7 +397,7 @@ font_face_descriptors! {
"font-feature-settings" feature_settings / mFontFeatureSettings: SpecifiedFontFeatureSettings,
/// The variation settings of this font face.
"font-variation-settings" variation_settings / mFontVariationSettings: FontVariationSettings,
"font-variation-settings" variation_settings / mFontVariationSettings: SpecifiedFontVariationSettings,
/// The language override of this font face.
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue,

View File

@ -22,7 +22,7 @@ use std::str;
use str::CssStringWriter;
use values::computed::font::FamilyName;
use values::generics::font::FontTag;
use values::specified::font::{FontVariationSettings, SpecifiedFontFeatureSettings};
use values::specified::font::{SpecifiedFontVariationSettings, SpecifiedFontFeatureSettings};
/// A @font-face rule
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
@ -74,7 +74,7 @@ impl ToNsCssValue for SpecifiedFontFeatureSettings {
}
}
impl ToNsCssValue for FontVariationSettings {
impl ToNsCssValue for SpecifiedFontVariationSettings {
fn convert(self, nscssvalue: &mut nsCSSValue) {
if self.0.is_empty() {
nscssvalue.set_normal();

View File

@ -19,7 +19,8 @@ SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_size_adjust font_variant_alternates
font_variant_ligatures font_variant_east_asian
font_variant_numeric font_language_override
font_feature_settings font_optical_sizing""".split()
font_feature_settings font_variation_settings
font_optical_sizing""".split()
def maybe_moz_logical_alias(product, side, prop):

View File

@ -167,6 +167,7 @@ ${helpers.predefined_type("font-variation-settings",
products="gecko",
gecko_pref="layout.css.font-variations.enabled",
initial_value="computed::FontVariationSettings::normal()",
initial_specified_value="specified::FontVariationSettings::normal()",
animation_value_type="ComputedValue",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="${variation_spec}")}
@ -371,6 +372,7 @@ ${helpers.predefined_type("-x-text-zoom",
font_language_override: longhands::font_language_override::computed_value
::T(system.languageOverride),
font_feature_settings: longhands::font_feature_settings::get_initial_value(),
font_variation_settings: longhands::font_variation_settings::get_initial_value(),
font_variant_alternates: longhands::font_variant_alternates::get_initial_value(),
system_font: *self,
default_font_type: system.fontlist.mDefaultFontType,

View File

@ -17,7 +17,8 @@
${'font-variant-numeric' if product == 'gecko' else ''}
${'font-variant-position' if product == 'gecko' else ''}
${'font-language-override' if product == 'gecko' else ''}
${'font-feature-settings' if product == 'gecko' else ''}"
${'font-feature-settings' if product == 'gecko' else ''}
${'font-variation-settings' if product == 'gecko' else ''}"
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
use parser::Parse;
use properties::longhands::{font_family, font_style, font_weight, font_stretch};
@ -32,7 +33,7 @@
variant_alternates variant_east_asian \
variant_ligatures variant_numeric \
variant_position feature_settings \
optical_sizing".split()
variation_settings optical_sizing".split()
%>
% if product == "gecko":
% for prop in gecko_sub_properties:
@ -162,9 +163,14 @@
return Ok(());
}
}
if let Some(v) = self.font_variation_settings {
if v != &font_variation_settings::get_initial_specified_value() {
return Ok(());
}
}
% for name in gecko_sub_properties:
% if name != "optical_sizing":
% if name != "optical_sizing" and name != "variation_settings":
if self.font_${name} != &font_${name}::get_initial_specified_value() {
return Ok(());
}
@ -203,7 +209,7 @@
let mut all = true;
% for prop in SYSTEM_FONT_LONGHANDS:
% if prop == "font_optical_sizing":
% if prop == "font_optical_sizing" or prop == "font_variation_settings":
if let Some(value) = self.${prop} {
% else:
{

View File

@ -1653,7 +1653,7 @@ impl Parse for FontVariantNumeric {
}
}
/// This property provides low-level control over OpenType or TrueType font variations.
/// This property provides low-level control over OpenType or TrueType font features.
pub type SpecifiedFontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;
/// Define initial settings that apply when the font defined by an @font-face
@ -1910,7 +1910,71 @@ impl Parse for FontLanguageOverride {
/// This property provides low-level control over OpenType or TrueType font
/// variations.
pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
pub type SpecifiedFontVariationSettings = FontSettings<VariationValue<Number>>;
/// Define initial settings that apply when the font defined by an @font-face
/// rule is rendered.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
pub enum FontVariationSettings {
/// Value of `FontSettings`
Value(SpecifiedFontVariationSettings),
/// System font
System(SystemFont)
}
impl FontVariationSettings {
#[inline]
/// Get default value of `font-variation-settings` as normal
pub fn normal() -> FontVariationSettings {
FontVariationSettings::Value(FontSettings::normal())
}
/// Get `font-variation-settings` with system font
pub fn system_font(f: SystemFont) -> Self {
FontVariationSettings::System(f)
}
/// Get system font
pub fn get_system(&self) -> Option<SystemFont> {
if let FontVariationSettings::System(s) = *self {
Some(s)
} else {
None
}
}
}
impl ToComputedValue for FontVariationSettings {
type ComputedValue = computed::FontVariationSettings;
fn to_computed_value(&self, context: &Context) -> computed::FontVariationSettings {
match *self {
FontVariationSettings::Value(ref v) => v.to_computed_value(context),
FontVariationSettings::System(_) => {
#[cfg(feature = "gecko")] {
context.cached_system_font.as_ref().unwrap().font_variation_settings.clone()
}
#[cfg(feature = "servo")] {
unreachable!()
}
}
}
}
fn from_computed_value(other: &computed::FontVariationSettings) -> Self {
FontVariationSettings::Value(ToComputedValue::from_computed_value(other))
}
}
impl Parse for FontVariationSettings {
/// normal | <variation-tag-value>#
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<FontVariationSettings, ParseError<'i>> {
SpecifiedFontVariationSettings::parse(context, input).map(FontVariationSettings::Value)
}
}
fn parse_one_feature_value<'i, 't>(
context: &ParserContext,

View File

@ -4857,7 +4857,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
use style::font_face::{FontDisplay, FontWeight, Source};
use style::properties::longhands::font_language_override;
use style::values::computed::font::FamilyName;
use style::values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
use style::values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
let string = unsafe { (*value).to_string() };
let mut input = ParserInput::new(&string);
@ -4907,7 +4907,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
eCSSFontDesc_Src / Vec<Source>,
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
eCSSFontDesc_FontVariationSettings / FontVariationSettings,
eCSSFontDesc_FontVariationSettings / SpecifiedFontVariationSettings,
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
eCSSFontDesc_Display / FontDisplay,
]

View File

@ -40,7 +40,7 @@ size_of_test!(test_size_of_rule_node, RuleNode, 80);
// This is huge, but we allocate it on the stack and then never move it,
// we only pass `&mut SourcePropertyDeclaration` references around.
size_of_test!(test_size_of_parsed_declaration, style::properties::SourcePropertyDeclaration, 576);
size_of_test!(test_size_of_parsed_declaration, style::properties::SourcePropertyDeclaration, 608);
size_of_test!(test_size_of_computed_image, computed::image::Image, 40);
size_of_test!(test_size_of_specified_image, specified::image::Image, 40);