style: Move moz-control-character-visibility out of mako, and remove support for gecko_pref_controlled_initial_value

No behavior change, just cleanup. Actually seem this technically _adds_ some code even
though it's a cleanup, but that's mostly because of the wrapping of the
derive list.  The resulting code is simpler (more in-line with our usual
things, so I think it's an improvement).

Differential Revision: https://phabricator.services.mozilla.com/D111551
This commit is contained in:
Oriol Brufau 2023-05-16 23:17:16 +02:00
parent fac547276f
commit 743f213c25
5 changed files with 48 additions and 32 deletions

View file

@ -483,6 +483,7 @@ class Longhand(Property):
"LineBreak",
"MasonryAutoFlow",
"MozForceBrokenImageIcon",
"text::MozControlCharacterVisibility",
"MozListReversed",
"MathDepth",
"MozScriptMinSize",

View file

@ -707,8 +707,7 @@
</%def>
<%def name="single_keyword(name, values, vector=False,
needs_conversion=False, gecko_pref_controlled_initial_value=None,
**kwargs)">
needs_conversion=False, **kwargs)">
<%
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
'gecko_constant_prefix',
@ -725,10 +724,13 @@
]}
%>
<%def name="inner_body(keyword, needs_conversion=False,
gecko_pref_controlled_initial_value=None)">
<%def name="variants(variants)">
% for variant in variants:
<%def name="inner_body(keyword, needs_conversion=False)">
pub use self::computed_value::T as SpecifiedValue;
pub mod computed_value {
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, FromPrimitive, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
pub enum T {
% for variant in keyword.values_for(engine):
<%
aliases = []
for alias, v in keyword.aliases_for(engine).items():
@ -740,31 +742,14 @@
% endif
${to_camel_case(variant)},
% endfor
</%def>
pub use self::computed_value::T as SpecifiedValue;
pub mod computed_value {
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, FromPrimitive, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
pub enum T {
${variants(data.longhands_by_name[name].keyword.values_for(engine))}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
% if engine == "gecko" and gecko_pref_controlled_initial_value:
if static_prefs::pref!("${gecko_pref_controlled_initial_value.split('=')[0]}") {
return computed_value::T::${to_camel_case(gecko_pref_controlled_initial_value.split('=')[1])};
}
% endif
computed_value::T::${to_camel_case(values.split()[0])}
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
% if engine == "gecko" and gecko_pref_controlled_initial_value:
if static_prefs::pref!("${gecko_pref_controlled_initial_value.split('=')[0]}") {
return SpecifiedValue::${to_camel_case(gecko_pref_controlled_initial_value.split('=')[1])};
}
% endif
SpecifiedValue::${to_camel_case(values.split()[0])}
}
#[inline]
@ -790,8 +775,7 @@
% else:
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
${inner_body(Keyword(name, values, **keyword_kwargs),
needs_conversion=needs_conversion,
gecko_pref_controlled_initial_value=gecko_pref_controlled_initial_value)}
needs_conversion=needs_conversion)}
% if caller:
${caller.body()}
% endif

View file

@ -331,15 +331,13 @@ ${helpers.single_keyword(
servo_restyle_damage="rebuild_and_reflow",
)}
${helpers.single_keyword(
${helpers.predefined_type(
"-moz-control-character-visibility",
"hidden visible",
"text::MozControlCharacterVisibility",
"Default::default()",
engines="gecko",
gecko_enum_prefix="StyleControlCharacterVisibility",
gecko_pref_controlled_initial_value="layout.css.control-characters.visible=visible",
animation_value_type="none",
gecko_ffi_name="mControlCharacterVisibility",
spec="Nonstandard",
spec="Nonstandard"
)}
// text underline offset

View file

@ -18,7 +18,7 @@ use crate::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
pub use crate::values::specified::text::{TextAlignLast, TextUnderlinePosition};
pub use crate::values::specified::text::{TextAlignLast, TextUnderlinePosition, MozControlCharacterVisibility};
pub use crate::values::specified::{LineBreak, OverflowWrap, RubyPosition, WordBreak};
pub use crate::values::specified::{TextDecorationLine, TextEmphasisPosition};
pub use crate::values::specified::{TextDecorationSkipInk, TextJustify, TextTransform};

View file

@ -1028,6 +1028,39 @@ pub enum TextJustify {
InterCharacter,
}
/// Values for the `-moz-control-character-visibility` CSS property.
#[repr(u8)]
#[derive(
Clone,
Copy,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[allow(missing_docs)]
pub enum MozControlCharacterVisibility {
Hidden,
Visible,
}
impl Default for MozControlCharacterVisibility {
fn default() -> Self {
if static_prefs::pref!("layout.css.control-characters.visible") {
Self::Visible
} else {
Self::Hidden
}
}
}
/// Values for the `line-break` property.
#[repr(u8)]
#[derive(