Bug 1374233 - Part 7: Add NonNegativeLengthOrPercentage.

For padding-{*} and grid-{*}-gap.

MozReview-Commit-ID: 81G0b1k6JnD
This commit is contained in:
Boris Chiou 2017-07-21 10:52:34 +08:00
parent 9d69cb2866
commit e72a0f126e
14 changed files with 123 additions and 20 deletions

View file

@ -1101,6 +1101,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
"LengthOrNormal": impl_style_coord,
"MaxLength": impl_style_coord,
"MozLength": impl_style_coord,
"NonNegativeLengthOrPercentage": impl_style_coord,
"NonNegativeNumber": impl_simple,
"Number": impl_simple,
"Integer": impl_simple,

View file

@ -46,6 +46,7 @@ use values::computed::{CalcLengthOrPercentage, Color, Context, ComputedValueAsSp
use values::computed::{LengthOrPercentage, MaxLength, MozLength, Percentage, ToComputedValue};
use values::computed::{NonNegativeAu, NonNegativeNumber, PositiveIntegerOrAuto};
use values::computed::length::{NonNegativeLengthOrAuto, NonNegativeLengthOrNormal};
use values::computed::length::NonNegativeLengthOrPercentage;
use values::generics::{GreaterThanOrEqualToOne, NonNegative};
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
use values::generics::effects::Filter;

View file

@ -14,11 +14,10 @@
if side[1]:
spec = "https://drafts.csswg.org/css-logical-props/#propdef-padding-%s" % side[1]
%>
${helpers.predefined_type("padding-%s" % side[0], "LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
${helpers.predefined_type("padding-%s" % side[0], "NonNegativeLengthOrPercentage",
"computed::NonNegativeLengthOrPercentage::zero()",
alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"),
animation_value_type="ComputedValue",
animation_value_type="NonNegativeLengthOrPercentage",
logical = side[1],
spec = spec,
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_PLACEHOLDER",

View file

@ -249,11 +249,10 @@ ${helpers.predefined_type("object-position",
% for kind in ["row", "column"]:
${helpers.predefined_type("grid-%s-gap" % kind,
"LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
"NonNegativeLengthOrPercentage",
"computed::NonNegativeLengthOrPercentage::zero()",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-%s-gap" % kind,
animation_value_type="ComputedValue",
animation_value_type="NonNegativeLengthOrPercentage",
products="gecko")}
% for range in ["start", "end"]:

View file

@ -2192,10 +2192,10 @@ impl ComputedValuesInner {
pub fn logical_padding(&self) -> LogicalMargin<computed::LengthOrPercentage> {
let padding_style = self.get_padding();
LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new(
padding_style.padding_top,
padding_style.padding_right,
padding_style.padding_bottom,
padding_style.padding_left,
padding_style.padding_top.0,
padding_style.padding_right.0,
padding_style.padding_bottom.0,
padding_style.padding_left.0,
))
}

View file

@ -4,6 +4,6 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
${helpers.four_sides_shorthand("padding", "padding-%s", "specified::LengthOrPercentage::parse_non_negative",
${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthOrPercentage::parse",
spec="https://drafts.csswg.org/css-box-3/#propdef-padding",
allow_quirks=True)}

View file

@ -459,7 +459,7 @@
use properties::longhands::grid_auto_flow::computed_value::{AutoFlow, T as SpecifiedAutoFlow};
use values::{Either, None_};
use values::generics::grid::{GridTemplateComponent, TrackListType};
use values::specified::{GenericGridTemplateComponent, LengthOrPercentage, TrackSize};
use values::specified::{GenericGridTemplateComponent, NonNegativeLengthOrPercentage, TrackSize};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
@ -520,8 +520,8 @@
grid_auto_columns: auto_cols,
grid_auto_flow: flow,
// This shorthand also resets grid gap
grid_row_gap: LengthOrPercentage::zero(),
grid_column_gap: LengthOrPercentage::zero(),
grid_row_gap: NonNegativeLengthOrPercentage::zero(),
grid_column_gap: NonNegativeLengthOrPercentage::zero(),
})
}
@ -539,8 +539,8 @@
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
// `grid` shorthand resets these properties. If they are not zero, that means they
// are changed by longhands and in that case we should fail serializing `grid`.
if *self.grid_row_gap != LengthOrPercentage::zero() ||
*self.grid_column_gap != LengthOrPercentage::zero() {
if *self.grid_row_gap != NonNegativeLengthOrPercentage::zero() ||
*self.grid_column_gap != NonNegativeLengthOrPercentage::zero() {
return Ok(());
}