From 7c4dc9e79728e5ae212d3d1effa8f7df4330d51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 21 Aug 2019 22:45:26 +0000 Subject: [PATCH] style: Make font-variant-alternates use cbindgen. Differential Revision: https://phabricator.services.mozilla.com/D42859 --- components/style/properties/gecko.mako.rs | 118 +--------------------- components/style/values/computed/font.rs | 4 +- components/style/values/specified/font.rs | 26 ++--- 3 files changed, 18 insertions(+), 130 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index ae252f46a83..4fc4615020a 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1247,6 +1247,8 @@ fn static_assert() { ${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")} + ${impl_simple("font_variant_alternates", "mFont.variantAlternates")} + pub fn set_font_size_adjust(&mut self, v: longhands::font_size_adjust::computed_value::T) { use crate::properties::longhands::font_size_adjust::computed_value::T; match v { @@ -1319,122 +1321,6 @@ fn static_assert() { ${impl_simple("_moz_script_level", "mScriptLevel")} <% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %> - pub fn set_font_variant_alternates( - &mut self, - v: values::computed::font::FontVariantAlternates, - ) { - use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues}; - % for value in "normal swash stylistic ornaments annotation styleset character_variant historical".split(): - use crate::gecko_bindings::structs::NS_FONT_VARIANT_ALTERNATES_${value.upper()}; - % endfor - use crate::values::specified::font::VariantAlternates; - - unsafe { - Gecko_ClearAlternateValues(&mut self.gecko.mFont, v.len()); - } - - if v.0.is_empty() { - self.gecko.mFont.variantAlternates = NS_FONT_VARIANT_ALTERNATES_NORMAL as u16; - return; - } - - for val in v.0.iter() { - match *val { - % for value in "Swash Stylistic Ornaments Annotation".split(): - VariantAlternates::${value}(ref ident) => { - self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_${value.upper()} as u16; - unsafe { - Gecko_AppendAlternateValues(&mut self.gecko.mFont, - NS_FONT_VARIANT_ALTERNATES_${value.upper()}, - ident.0.as_ptr()); - } - }, - % endfor - % for value in "styleset character_variant".split(): - VariantAlternates::${to_camel_case(value)}(ref slice) => { - self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_${value.upper()} as u16; - for ident in slice.iter() { - unsafe { - Gecko_AppendAlternateValues(&mut self.gecko.mFont, - NS_FONT_VARIANT_ALTERNATES_${value.upper()}, - ident.0.as_ptr()); - } - } - }, - % endfor - VariantAlternates::HistoricalForms => { - self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_HISTORICAL as u16; - } - } - } - } - - #[allow(non_snake_case)] - pub fn copy_font_variant_alternates_from(&mut self, other: &Self) { - use crate::gecko_bindings::bindings::Gecko_CopyAlternateValuesFrom; - - self.gecko.mFont.variantAlternates = other.gecko.mFont.variantAlternates; - unsafe { - Gecko_CopyAlternateValuesFrom(&mut self.gecko.mFont, &other.gecko.mFont); - } - } - - pub fn reset_font_variant_alternates(&mut self, other: &Self) { - self.copy_font_variant_alternates_from(other) - } - - pub fn clone_font_variant_alternates(&self) -> values::computed::font::FontVariantAlternates { - % for value in "normal swash stylistic ornaments annotation styleset character_variant historical".split(): - use crate::gecko_bindings::structs::NS_FONT_VARIANT_ALTERNATES_${value.upper()}; - % endfor - use crate::values::specified::font::VariantAlternates; - use crate::values::specified::font::VariantAlternatesList; - use crate::values::CustomIdent; - - if self.gecko.mFont.variantAlternates == NS_FONT_VARIANT_ALTERNATES_NORMAL as u16 { - return VariantAlternatesList(vec![].into_boxed_slice()); - } - - let mut alternates = Vec::with_capacity(self.gecko.mFont.alternateValues.len()); - if self.gecko.mFont.variantAlternates & (NS_FONT_VARIANT_ALTERNATES_HISTORICAL as u16) != 0 { - alternates.push(VariantAlternates::HistoricalForms); - } - - <% - property_need_ident_list = "styleset character_variant".split() - %> - % for value in property_need_ident_list: - let mut ${value}_list = Vec::new(); - % endfor - - for gecko_alternate_value in self.gecko.mFont.alternateValues.iter() { - let ident = Atom::from(gecko_alternate_value.value.to_string()); - match gecko_alternate_value.alternate { - % for value in "Swash Stylistic Ornaments Annotation".split(): - NS_FONT_VARIANT_ALTERNATES_${value.upper()} => { - alternates.push(VariantAlternates::${value}(CustomIdent(ident))); - }, - % endfor - % for value in property_need_ident_list: - NS_FONT_VARIANT_ALTERNATES_${value.upper()} => { - ${value}_list.push(CustomIdent(ident)); - }, - % endfor - _ => { - panic!("Found unexpected value for font-variant-alternates"); - } - } - } - - % for value in property_need_ident_list: - if !${value}_list.is_empty() { - alternates.push(VariantAlternates::${to_camel_case(value)}(${value}_list.into_boxed_slice())); - } - % endfor - - VariantAlternatesList(alternates.into_boxed_slice()) - } - ${impl_simple_type_with_conversion("font_variant_ligatures", "mFont.variantLigatures")} ${impl_simple_type_with_conversion("font_variant_east_asian", "mFont.variantEastAsian")} ${impl_simple_type_with_conversion("font_variant_numeric", "mFont.variantNumeric")} diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 0063a6946ba..fee8c24ee3b 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -644,10 +644,10 @@ impl ToAnimatedValue for FontSizeAdjust { pub type FontVariantAlternates = specified::VariantAlternatesList; impl FontVariantAlternates { - #[inline] /// Get initial value with VariantAlternatesList + #[inline] pub fn get_initial_value() -> Self { - specified::VariantAlternatesList(vec![].into_boxed_slice()) + Self::default() } } diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index d42272e396b..9e680ec7758 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -1089,17 +1089,20 @@ bitflags! { #[derive( Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem, )] +#[repr(C, u8)] /// Set of variant alternates +/// +/// cbindgen:derive-tagged-enum-copy-constructor=true pub enum VariantAlternates { /// Enables display of stylistic alternates #[css(function)] Stylistic(CustomIdent), /// Enables display with stylistic sets #[css(comma, function)] - Styleset(#[css(iterable)] Box<[CustomIdent]>), + Styleset(#[css(iterable)] crate::OwnedSlice), /// Enables display of specific character variants #[css(comma, function)] - CharacterVariant(#[css(iterable)] Box<[CustomIdent]>), + CharacterVariant(#[css(iterable)] crate::OwnedSlice), /// Enables display of swash glyphs #[css(function)] Swash(CustomIdent), @@ -1114,11 +1117,12 @@ pub enum VariantAlternates { } #[derive( - Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem, + Clone, Debug, Default, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToResolvedValue, ToShmem, )] +#[repr(transparent)] /// List of Variant Alternates pub struct VariantAlternatesList( - #[css(if_empty = "normal", iterable)] pub Box<[VariantAlternates]>, + #[css(if_empty = "normal", iterable)] crate::OwnedSlice, ); impl VariantAlternatesList { @@ -1150,7 +1154,7 @@ impl FontVariantAlternates { #[inline] /// Get initial specified value with VariantAlternatesList pub fn get_initial_specified_value() -> Self { - FontVariantAlternates::Value(VariantAlternatesList(vec![].into_boxed_slice())) + FontVariantAlternates::Value(Default::default()) } system_font_methods!(FontVariantAlternates, font_variant_alternates); @@ -1184,16 +1188,14 @@ impl Parse for FontVariantAlternates { _: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let mut alternates = Vec::new(); if input .try(|input| input.expect_ident_matching("normal")) .is_ok() { - return Ok(FontVariantAlternates::Value(VariantAlternatesList( - alternates.into_boxed_slice(), - ))); + return Ok(FontVariantAlternates::Value(Default::default())) } + let mut alternates = Vec::new(); let mut parsed_alternates = VariantAlternatesParsingFlags::empty(); macro_rules! check_if_parsed( ($input:expr, $flag:path) => ( @@ -1247,7 +1249,7 @@ impl Parse for FontVariantAlternates { let location = i.current_source_location(); CustomIdent::from_ident(location, i.expect_ident()?, &[]) })?; - alternates.push(VariantAlternates::Styleset(idents.into_boxed_slice())); + alternates.push(VariantAlternates::Styleset(idents.into())); Ok(()) }, "character-variant" => { @@ -1256,7 +1258,7 @@ impl Parse for FontVariantAlternates { let location = i.current_source_location(); CustomIdent::from_ident(location, i.expect_ident()?, &[]) })?; - alternates.push(VariantAlternates::CharacterVariant(idents.into_boxed_slice())); + alternates.push(VariantAlternates::CharacterVariant(idents.into())); Ok(()) }, _ => return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError)), @@ -1270,7 +1272,7 @@ impl Parse for FontVariantAlternates { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } Ok(FontVariantAlternates::Value(VariantAlternatesList( - alternates.into_boxed_slice(), + alternates.into(), ))) } }