Skip to content

Commit

Permalink
Bug 1520229 - [css-logical] Implement the inset-block/inline shorthan…
Browse files Browse the repository at this point in the history
…ds. r=emilio
  • Loading branch information
Mats Palmgren committed Jan 16, 2019
1 parent b610730 commit 59d51f4
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
28 changes: 28 additions & 0 deletions devtools/shared/css/generated/properties-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -6445,6 +6445,20 @@ exports.CSS_PROPERTIES = {
"unset"
]
},
"inset-block": {
"isInherited": false,
"subproperties": [
"inset-block-start",
"inset-block-end"
],
"supports": [],
"values": [
"auto",
"inherit",
"initial",
"unset"
]
},
"inset-block-end": {
"isInherited": false,
"subproperties": [
Expand All @@ -6471,6 +6485,20 @@ exports.CSS_PROPERTIES = {
"unset"
]
},
"inset-inline": {
"isInherited": false,
"subproperties": [
"inset-inline-start",
"inset-inline-end"
],
"supports": [],
"values": [
"auto",
"inherit",
"initial",
"unset"
]
},
"inset-inline-end": {
"isInherited": false,
"subproperties": [
Expand Down
36 changes: 36 additions & 0 deletions layout/style/test/property_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -6386,6 +6386,24 @@ var gCSSProperties = {
],
invalid_values: [ "none", "5" ]
},
"inset-block": {
domProp: "insetBlock",
inherited: false,
type: CSS_TYPE_TRUE_SHORTHAND,
subproperties: [ "inset-block-start", "inset-block-end" ],
/* FIXME: run tests with multiple prerequisites */
prerequisites: { "position": "relative" },
initial_values: [ "auto", "auto auto" ],
other_values: [ "32px", "-3em", "12%", "32px auto", "auto -3em", "12% auto",
"calc(2px)", "calc(2px) auto",
"calc(-2px)", "auto calc(-2px)",
"calc(50%)", "auto calc(50%)",
"calc(3*25px)", "calc(3*25px) auto",
"calc(25px*3)", "auto calc(25px*3)",
"calc(3*25px + 50%)", "auto calc(3*25px + 50%)",
],
invalid_values: [ "none" ]
},
"inset-block-end": {
domProp: "insetBlockEnd",
inherited: false,
Expand Down Expand Up @@ -6424,6 +6442,24 @@ var gCSSProperties = {
],
invalid_values: []
},
"inset-inline": {
domProp: "insetInline",
inherited: false,
type: CSS_TYPE_TRUE_SHORTHAND,
subproperties: [ "inset-inline-start", "inset-inline-end" ],
/* FIXME: run tests with multiple prerequisites */
prerequisites: { "position": "relative" },
initial_values: [ "auto", "auto auto" ],
other_values: [ "32px", "-3em", "12%", "32px auto", "auto -3em", "12% auto",
"calc(2px)", "calc(2px) auto",
"calc(-2px)", "auto calc(-2px)",
"calc(50%)", "auto calc(50%)",
"calc(3*25px)", "calc(3*25px) auto",
"calc(25px*3)", "auto calc(25px*3)",
"calc(3*25px + 50%)", "auto calc(3*25px + 50%)",
],
invalid_values: [ "none" ]
},
"inset-inline-end": {
domProp: "insetInlineEnd",
inherited: false,
Expand Down
43 changes: 43 additions & 0 deletions servo/components/style/properties/shorthands/position.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,46 @@
}
}
</%helpers:shorthand>

% for axis in ["block", "inline"]:
<%
spec = "https://drafts.csswg.org/css-logical/#propdef-inset-%s" % axis
%>
<%helpers:shorthand
name="inset-${axis}"
sub_properties="${' '.join(
'inset-%s-%s' % (axis, side)
for side in ['start', 'end']
)}"
spec="${spec}">

use crate::parser::Parse;
use crate::values::specified::length::LengthPercentageOrAuto;
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let start_value = LengthPercentageOrAuto::parse(context, input)?;
let end_value =
input.try(|input| LengthPercentageOrAuto::parse(context, input)).unwrap_or_else(|_| start_value.clone());

Ok(expanded! {
inset_${axis}_start: start_value,
inset_${axis}_end: end_value,
})
}

impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.inset_${axis}_start.to_css(dest)?;

if self.inset_${axis}_end != self.inset_${axis}_start {
dest.write_str(" ")?;
self.inset_${axis}_end.to_css(dest)?;
}

Ok(())
}
}
</%helpers:shorthand>
% endfor

0 comments on commit 59d51f4

Please sign in to comment.