mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Cleanup a few shorthand properties.
Differential Revision: https://phabricator.services.mozilla.com/D17082
This commit is contained in:
parent
af1bbd7b06
commit
45a416b996
5 changed files with 139 additions and 231 deletions
|
@ -793,6 +793,58 @@
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
// A shorthand of kind `<property-1> <property-2>?` where both properties have
|
||||||
|
// the same type.
|
||||||
|
<%def name="two_properties_shorthand(
|
||||||
|
name,
|
||||||
|
first_property,
|
||||||
|
second_property,
|
||||||
|
parser_function,
|
||||||
|
needs_context=True,
|
||||||
|
**kwargs
|
||||||
|
)">
|
||||||
|
<%call expr="self.shorthand(name, sub_properties=' '.join([first_property, second_property]), **kwargs)">
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate::parser::Parse;
|
||||||
|
use crate::values::specified;
|
||||||
|
|
||||||
|
pub fn parse_value<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Longhands, ParseError<'i>> {
|
||||||
|
let parse_one = |_c: &ParserContext, input: &mut Parser<'i, 't>| {
|
||||||
|
% if needs_context:
|
||||||
|
${parser_function}(_c, input)
|
||||||
|
% else:
|
||||||
|
${parser_function}(input)
|
||||||
|
% endif
|
||||||
|
};
|
||||||
|
|
||||||
|
let first = parse_one(context, input)?;
|
||||||
|
let second =
|
||||||
|
input.try(|input| parse_one(context, input)).unwrap_or_else(|_| first.clone());
|
||||||
|
Ok(expanded! {
|
||||||
|
${to_rust_ident(first_property)}: first,
|
||||||
|
${to_rust_ident(second_property)}: second,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||||
|
let first = &self.${to_rust_ident(first_property)};
|
||||||
|
let second = &self.${to_rust_ident(second_property)};
|
||||||
|
|
||||||
|
first.to_css(dest)?;
|
||||||
|
if first != second {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
second.to_css(dest)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</%call>
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="four_sides_shorthand(name, sub_property_pattern, parser_function,
|
<%def name="four_sides_shorthand(name, sub_property_pattern, parser_function,
|
||||||
needs_context=True, allow_quirks=False, **kwargs)">
|
needs_context=True, allow_quirks=False, **kwargs)">
|
||||||
<% sub_properties=' '.join(sub_property_pattern % side for side in PHYSICAL_SIDES) %>
|
<% sub_properties=' '.join(sub_property_pattern % side for side in PHYSICAL_SIDES) %>
|
||||||
|
|
|
@ -4,76 +4,28 @@
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
<%helpers:shorthand
|
${helpers.two_properties_shorthand(
|
||||||
name="overflow"
|
"overflow",
|
||||||
flags="SHORTHAND_IN_GETCS"
|
"overflow-x",
|
||||||
sub_properties="overflow-x overflow-y"
|
"overflow-y",
|
||||||
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow"
|
"specified::Overflow::parse",
|
||||||
>
|
flags="SHORTHAND_IN_GETCS",
|
||||||
use crate::properties::longhands::overflow_x::parse as parse_overflow;
|
needs_context=False,
|
||||||
|
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow",
|
||||||
|
)}
|
||||||
|
|
||||||
pub fn parse_value<'i, 't>(
|
${helpers.two_properties_shorthand(
|
||||||
context: &ParserContext,
|
"overflow-clip-box",
|
||||||
input: &mut Parser<'i, 't>,
|
"overflow-clip-box-block",
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
"overflow-clip-box-inline",
|
||||||
let overflow_x = parse_overflow(context, input)?;
|
"specified::OverflowClipBox::parse",
|
||||||
let overflow_y =
|
enabled_in="ua",
|
||||||
input.try(|i| parse_overflow(context, i)).unwrap_or(overflow_x);
|
needs_context=False,
|
||||||
Ok(expanded! {
|
gecko_pref="layout.css.overflow-clip-box.enabled",
|
||||||
overflow_x: overflow_x,
|
|
||||||
overflow_y: overflow_y,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
|
||||||
self.overflow_x.to_css(dest)?;
|
|
||||||
if self.overflow_x != self.overflow_y {
|
|
||||||
dest.write_char(' ')?;
|
|
||||||
self.overflow_y.to_css(dest)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:shorthand>
|
|
||||||
|
|
||||||
<%helpers:shorthand
|
|
||||||
name="overflow-clip-box"
|
|
||||||
sub_properties="overflow-clip-box-block overflow-clip-box-inline"
|
|
||||||
enabled_in="ua"
|
|
||||||
gecko_pref="layout.css.overflow-clip-box.enabled"
|
|
||||||
spec="Internal, may be standardized in the future "
|
spec="Internal, may be standardized in the future "
|
||||||
"(https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)"
|
"(https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)",
|
||||||
products="gecko"
|
products="gecko",
|
||||||
>
|
)}
|
||||||
use crate::values::specified::OverflowClipBox;
|
|
||||||
pub fn parse_value<'i, 't>(
|
|
||||||
_: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
|
||||||
let block_value = OverflowClipBox::parse(input)?;
|
|
||||||
let inline_value =
|
|
||||||
input.try(|input| OverflowClipBox::parse(input)).unwrap_or(block_value);
|
|
||||||
|
|
||||||
Ok(expanded! {
|
|
||||||
overflow_clip_box_block: block_value,
|
|
||||||
overflow_clip_box_inline: inline_value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
|
||||||
self.overflow_clip_box_block.to_css(dest)?;
|
|
||||||
|
|
||||||
if self.overflow_clip_box_block != self.overflow_clip_box_inline {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
self.overflow_clip_box_inline.to_css(dest)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:shorthand>
|
|
||||||
|
|
||||||
macro_rules! try_parse_one {
|
macro_rules! try_parse_one {
|
||||||
($context: expr, $input: expr, $var: ident, $prop_module: ident) => {
|
($context: expr, $input: expr, $var: ident, $prop_module: ident) => {
|
||||||
|
@ -381,36 +333,16 @@ macro_rules! try_parse_one {
|
||||||
}
|
}
|
||||||
</%helpers:shorthand>
|
</%helpers:shorthand>
|
||||||
|
|
||||||
<%helpers:shorthand name="overscroll-behavior" products="gecko"
|
${helpers.two_properties_shorthand(
|
||||||
gecko_pref="layout.css.overscroll-behavior.enabled"
|
"overscroll-behavior",
|
||||||
sub_properties="overscroll-behavior-x overscroll-behavior-y"
|
"overscroll-behavior-x",
|
||||||
spec="https://wicg.github.io/overscroll-behavior/#overscroll-behavior-properties">
|
"overscroll-behavior-y",
|
||||||
pub fn parse_value<'i, 't>(
|
"specified::OverscrollBehavior::parse",
|
||||||
_: &ParserContext,
|
needs_context=False,
|
||||||
input: &mut Parser<'i, 't>,
|
products="gecko",
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
gecko_pref="layout.css.overscroll-behavior.enabled",
|
||||||
use crate::values::specified::OverscrollBehavior;
|
spec="https://wicg.github.io/overscroll-behavior/#overscroll-behavior-properties",
|
||||||
let behavior_x = OverscrollBehavior::parse(input)?;
|
)}
|
||||||
let behavior_y = input.try(OverscrollBehavior::parse).unwrap_or(behavior_x);
|
|
||||||
Ok(expanded! {
|
|
||||||
overscroll_behavior_x: behavior_x,
|
|
||||||
overscroll_behavior_y: behavior_y,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
|
||||||
// Serializes into the single keyword value if both overscroll-behavior-x and overscroll-behavior-y are same.
|
|
||||||
// Otherwise into two values separated by a space.
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
|
||||||
self.overscroll_behavior_x.to_css(dest)?;
|
|
||||||
if self.overscroll_behavior_y != self.overscroll_behavior_x {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
self.overscroll_behavior_y.to_css(dest)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:shorthand>
|
|
||||||
|
|
||||||
<%helpers:shorthand
|
<%helpers:shorthand
|
||||||
name="page-break-before"
|
name="page-break-before"
|
||||||
|
|
|
@ -4,51 +4,27 @@
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthPercentageOrAuto::parse",
|
${helpers.four_sides_shorthand(
|
||||||
spec="https://drafts.csswg.org/css-box/#propdef-margin",
|
"margin",
|
||||||
allowed_in_page_rule=True,
|
"margin-%s",
|
||||||
allow_quirks=True)}
|
"specified::LengthPercentageOrAuto::parse",
|
||||||
|
spec="https://drafts.csswg.org/css-box/#propdef-margin",
|
||||||
|
allowed_in_page_rule=True,
|
||||||
|
allow_quirks=True,
|
||||||
|
)}
|
||||||
|
|
||||||
% for axis in ["block", "inline"]:
|
${helpers.two_properties_shorthand(
|
||||||
<%
|
"margin-block",
|
||||||
spec = "https://drafts.csswg.org/css-logical/#propdef-margin-%s" % axis
|
"margin-block-start",
|
||||||
%>
|
"margin-block-end",
|
||||||
<%helpers:shorthand
|
"specified::LengthPercentageOrAuto::parse",
|
||||||
name="margin-${axis}"
|
spec="https://drafts.csswg.org/css-logical/#propdef-margin-block"
|
||||||
sub_properties="${' '.join(
|
)}
|
||||||
'margin-%s-%s' % (axis, side)
|
|
||||||
for side in ['start', 'end']
|
|
||||||
)}"
|
|
||||||
spec="${spec}">
|
|
||||||
|
|
||||||
use crate::parser::Parse;
|
${helpers.two_properties_shorthand(
|
||||||
use crate::values::specified::length::LengthPercentageOrAuto;
|
"margin-inline",
|
||||||
pub fn parse_value<'i, 't>(
|
"margin-inline-start",
|
||||||
context: &ParserContext,
|
"margin-inline-end",
|
||||||
input: &mut Parser<'i, 't>,
|
"specified::LengthPercentageOrAuto::parse",
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
spec="https://drafts.csswg.org/css-logical/#propdef-margin-inline"
|
||||||
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! {
|
|
||||||
margin_${axis}_start: start_value,
|
|
||||||
margin_${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.margin_${axis}_start.to_css(dest)?;
|
|
||||||
|
|
||||||
if self.margin_${axis}_end != self.margin_${axis}_start {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
self.margin_${axis}_end.to_css(dest)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:shorthand>
|
|
||||||
% endfor
|
|
||||||
|
|
|
@ -4,50 +4,26 @@
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
|
||||||
${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthPercentage::parse",
|
${helpers.four_sides_shorthand(
|
||||||
spec="https://drafts.csswg.org/css-box-3/#propdef-padding",
|
"padding",
|
||||||
allow_quirks=True)}
|
"padding-%s",
|
||||||
|
"specified::NonNegativeLengthPercentage::parse",
|
||||||
|
spec="https://drafts.csswg.org/css-box-3/#propdef-padding",
|
||||||
|
allow_quirks=True,
|
||||||
|
)}
|
||||||
|
|
||||||
% for axis in ["block", "inline"]:
|
${helpers.two_properties_shorthand(
|
||||||
<%
|
"padding-block",
|
||||||
spec = "https://drafts.csswg.org/css-logical/#propdef-padding-%s" % axis
|
"padding-block-start",
|
||||||
%>
|
"padding-block-end",
|
||||||
<%helpers:shorthand
|
"specified::NonNegativeLengthPercentage::parse",
|
||||||
name="padding-${axis}"
|
spec="https://drafts.csswg.org/css-logical/#propdef-padding-block"
|
||||||
sub_properties="${' '.join(
|
)}
|
||||||
'padding-%s-%s' % (axis, side)
|
|
||||||
for side in ['start', 'end']
|
|
||||||
)}"
|
|
||||||
spec="${spec}">
|
|
||||||
|
|
||||||
use crate::parser::Parse;
|
${helpers.two_properties_shorthand(
|
||||||
use crate::values::specified::length::NonNegativeLengthPercentage;
|
"padding-inline",
|
||||||
pub fn parse_value<'i, 't>(
|
"padding-inline-start",
|
||||||
context: &ParserContext,
|
"padding-inline-end",
|
||||||
input: &mut Parser<'i, 't>,
|
"specified::NonNegativeLengthPercentage::parse",
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
spec="https://drafts.csswg.org/css-logical/#propdef-padding-inline"
|
||||||
let start_value = NonNegativeLengthPercentage::parse(context, input)?;
|
)}
|
||||||
let end_value =
|
|
||||||
input.try(|input| NonNegativeLengthPercentage::parse(context, input))
|
|
||||||
.unwrap_or_else(|_| start_value.clone());
|
|
||||||
|
|
||||||
Ok(expanded! {
|
|
||||||
padding_${axis}_start: start_value,
|
|
||||||
padding_${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.padding_${axis}_start.to_css(dest)?;
|
|
||||||
|
|
||||||
if self.padding_${axis}_end != self.padding_${axis}_start {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
self.padding_${axis}_end.to_css(dest)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:shorthand>
|
|
||||||
% endfor
|
|
||||||
|
|
|
@ -772,46 +772,18 @@ ${helpers.four_sides_shorthand(
|
||||||
allow_quirks=False,
|
allow_quirks=False,
|
||||||
)}
|
)}
|
||||||
|
|
||||||
% for axis in ["block", "inline"]:
|
${helpers.two_properties_shorthand(
|
||||||
<%
|
"inset-block",
|
||||||
spec = "https://drafts.csswg.org/css-logical/#propdef-inset-%s" % axis
|
"inset-block-start",
|
||||||
%>
|
"inset-block-end",
|
||||||
<%helpers:shorthand
|
"specified::LengthPercentageOrAuto::parse",
|
||||||
name="inset-${axis}"
|
spec="https://drafts.csswg.org/css-logical/#propdef-inset-block"
|
||||||
sub_properties="${' '.join(
|
)}
|
||||||
'inset-%s-%s' % (axis, side)
|
|
||||||
for side in ['start', 'end']
|
|
||||||
)}"
|
|
||||||
spec="${spec}">
|
|
||||||
|
|
||||||
use crate::parser::Parse;
|
${helpers.two_properties_shorthand(
|
||||||
use crate::values::specified::length::LengthPercentageOrAuto;
|
"inset-inline",
|
||||||
pub fn parse_value<'i, 't>(
|
"inset-inline-start",
|
||||||
context: &ParserContext,
|
"inset-inline-end",
|
||||||
input: &mut Parser<'i, 't>,
|
"specified::LengthPercentageOrAuto::parse",
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
spec="https://drafts.csswg.org/css-logical/#propdef-inset-inline"
|
||||||
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
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue