style: Derive more length stuff, and shrink MaxLength / MozLength's repr(C) representation.

This patch:

 * Makes LengthPercentageOrAuto generic, and removes a bunch of code fo
   LengthPercentageOrNone, which was used only for servo and now can use the
   normal MaxLength (with a cfg() guard for the ExtremumLength variant).

 * Shrinks MaxLength / MozLength's repr(C) reperesentation by reducing enum
   nesting. The shrinking is in preparation for using them from C++ too, though
   that'd be a different bug.

 * Moves NonNegative usage to the proper places so that stuff for them can be
   derived.

I did this on top of bug 1523071 to prove both that it could be possible and
that stuff wasn't too messy. It got a bit messy, but just because of a bug I
had fixed in bindgen long time ago already, so this updates bindgen's patch
version to grab a fix instead of ugly workarounds :)

Differential Revision: https://phabricator.services.mozilla.com/D17762
This commit is contained in:
Emilio Cobos Álvarez 2019-01-27 01:03:44 +01:00
parent 8dad956513
commit a68bc29b96
17 changed files with 337 additions and 520 deletions

View file

@ -1390,7 +1390,6 @@ impl Clone for ${style_struct.gecko_struct_name} {
"LengthOrNormal": impl_style_coord,
"LengthPercentage": impl_simple,
"LengthPercentageOrAuto": impl_style_coord,
"LengthPercentageOrNone": impl_style_coord,
"MaxLength": impl_style_coord,
"MozLength": impl_style_coord,
"MozScriptMinSize": impl_absolute_length,
@ -3831,11 +3830,11 @@ fn static_assert() {
BackgroundSize::Explicit { width: explicit_width, height: explicit_height } => {
let mut w_type = nsStyleImageLayers_Size_DimensionType::eAuto;
let mut h_type = nsStyleImageLayers_Size_DimensionType::eAuto;
if let Some(w) = explicit_width.0.to_calc_value() {
if let Some(w) = explicit_width.to_calc_value() {
width = w;
w_type = nsStyleImageLayers_Size_DimensionType::eLengthPercentage;
}
if let Some(h) = explicit_height.0.to_calc_value() {
if let Some(h) = explicit_height.to_calc_value() {
height = h;
h_type = nsStyleImageLayers_Size_DimensionType::eLengthPercentage;
}

View file

@ -13,7 +13,7 @@
${helpers.predefined_type(
side,
"LengthPercentageOrAuto",
"computed::LengthPercentageOrAuto::Auto",
"computed::LengthPercentageOrAuto::auto()",
spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side,
flags="GETCS_NEEDS_LAYOUT_FLUSH",
animation_value_type="ComputedValue",
@ -27,7 +27,7 @@
${helpers.predefined_type(
"inset-%s" % side,
"LengthPercentageOrAuto",
"computed::LengthPercentageOrAuto::Auto",
"computed::LengthPercentageOrAuto::auto()",
spec="https://drafts.csswg.org/css-logical-props/#propdef-inset-%s" % side,
flags="GETCS_NEEDS_LAYOUT_FLUSH",
alias="offset-%s:layout.css.offset-logical-properties.enabled" % side,
@ -270,24 +270,12 @@ ${helpers.predefined_type(
animation_value_type="MozLength",
servo_restyle_damage="reflow",
)}
${helpers.predefined_type(
"max-%s" % size,
"MaxLength",
"computed::MaxLength::none()",
logical=logical,
logical_group="max-size",
allow_quirks=not logical,
spec=spec % size,
animation_value_type="MaxLength",
servo_restyle_damage="reflow",
)}
% else:
// servo versions (no keyword support)
${helpers.predefined_type(
size,
"LengthPercentageOrAuto",
"computed::LengthPercentageOrAuto::Auto",
"parse_non_negative",
"NonNegativeLengthPercentageOrAuto",
"computed::NonNegativeLengthPercentageOrAuto::auto()",
spec=spec % size,
logical_group="size",
allow_quirks=not logical,
@ -296,9 +284,8 @@ ${helpers.predefined_type(
)}
${helpers.predefined_type(
"min-%s" % size,
"LengthPercentage",
"computed::LengthPercentage::zero()",
"parse_non_negative",
"NonNegativeLengthPercentage",
"computed::NonNegativeLengthPercentage::zero()",
spec=spec % ("min-%s" % size),
logical_group="min-size",
animation_value_type="ComputedValue",
@ -306,19 +293,18 @@ ${helpers.predefined_type(
allow_quirks=not logical,
servo_restyle_damage="reflow",
)}
${helpers.predefined_type(
"max-%s" % size,
"LengthPercentageOrNone",
"computed::LengthPercentageOrNone::None",
"parse_non_negative",
spec=spec % ("max-%s" % size),
logical_group="max-size",
animation_value_type="ComputedValue",
logical=logical,
allow_quirks=not logical,
servo_restyle_damage="reflow",
)}
% endif
${helpers.predefined_type(
"max-%s" % size,
"MaxLength",
"computed::MaxLength::none()",
logical=logical,
logical_group="max-size",
allow_quirks=not logical,
spec=spec % size,
animation_value_type="MaxLength",
servo_restyle_damage="reflow",
)}
% endfor
${helpers.single_keyword(

View file

@ -3016,7 +3016,7 @@ impl ComputedValuesInner {
/// Get the logical computed inline size.
#[inline]
pub fn content_inline_size(&self) -> computed::LengthPercentageOrAuto {
pub fn content_inline_size(&self) -> computed::NonNegativeLengthPercentageOrAuto {
let position_style = self.get_position();
if self.writing_mode.is_vertical() {
position_style.height
@ -3027,35 +3027,35 @@ impl ComputedValuesInner {
/// Get the logical computed block size.
#[inline]
pub fn content_block_size(&self) -> computed::LengthPercentageOrAuto {
pub fn content_block_size(&self) -> computed::NonNegativeLengthPercentageOrAuto {
let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.width } else { position_style.height }
}
/// Get the logical computed min inline size.
#[inline]
pub fn min_inline_size(&self) -> computed::LengthPercentage {
pub fn min_inline_size(&self) -> computed::NonNegativeLengthPercentage {
let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width }
}
/// Get the logical computed min block size.
#[inline]
pub fn min_block_size(&self) -> computed::LengthPercentage {
pub fn min_block_size(&self) -> computed::NonNegativeLengthPercentage {
let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height }
}
/// Get the logical computed max inline size.
#[inline]
pub fn max_inline_size(&self) -> computed::LengthPercentageOrNone {
pub fn max_inline_size(&self) -> computed::MaxLength {
let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width }
}
/// Get the logical computed max block size.
#[inline]
pub fn max_block_size(&self) -> computed::LengthPercentageOrNone {
pub fn max_block_size(&self) -> computed::MaxLength {
let position_style = self.get_position();
if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height }
}