style: Support break-inside: avoid-{page,column}

break-before/after: page|column seem harder because you need to deal
with nested breaks, I think, but this should be straight-forward.

Differential Revision: https://phabricator.services.mozilla.com/D121206
This commit is contained in:
Emilio Cobos Álvarez 2023-05-22 13:21:38 +02:00 committed by Oriol Brufau
parent cf44eb3e77
commit 5530f7e90c
3 changed files with 66 additions and 21 deletions

View file

@ -503,7 +503,6 @@ ${helpers.predefined_type(
"BreakWithin",
"computed::BreakWithin::Auto",
engines="gecko",
aliases="page-break-inside",
spec="https://drafts.csswg.org/css-break/#propdef-break-inside",
animation_value_type="discrete",
)}

View file

@ -316,15 +316,15 @@ ${helpers.two_properties_shorthand(
name="page-break-before"
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
sub_properties="break-before"
spec="https://drafts.csswg.org/css2/page.html#propdef-page-break-before"
spec="https://drafts.csswg.org/css-break-3/#page-break-properties"
>
pub fn parse_value<'i>(
_: &ParserContext,
context: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::values::specified::box_::BreakBetween;
Ok(expanded! {
break_before: BreakBetween::parse_legacy(input)?,
break_before: BreakBetween::parse_legacy(context, input)?,
})
}
@ -340,15 +340,15 @@ ${helpers.two_properties_shorthand(
name="page-break-after"
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
sub_properties="break-after"
spec="https://drafts.csswg.org/css2/page.html#propdef-page-break-after"
spec="https://drafts.csswg.org/css-break-3/#page-break-properties"
>
pub fn parse_value<'i>(
_: &ParserContext,
context: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::values::specified::box_::BreakBetween;
Ok(expanded! {
break_after: BreakBetween::parse_legacy(input)?,
break_after: BreakBetween::parse_legacy(context, input)?,
})
}
@ -359,6 +359,30 @@ ${helpers.two_properties_shorthand(
}
</%helpers:shorthand>
<%helpers:shorthand
engines="gecko"
name="page-break-inside"
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
sub_properties="break-inside"
spec="https://drafts.csswg.org/css-break-3/#page-break-properties"
>
pub fn parse_value<'i>(
context: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::values::specified::box_::BreakWithin;
Ok(expanded! {
break_inside: BreakWithin::parse_legacy(context, input)?,
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.break_inside.to_css_legacy(dest)
}
}
</%helpers:shorthand>
<%helpers:shorthand name="offset"
engines="gecko"
sub_properties="offset-path offset-distance offset-rotate offset-anchor"

View file

@ -1894,28 +1894,19 @@ pub enum BreakBetween {
}
impl BreakBetween {
/// Parse a legacy break-between value for `page-break-*`.
/// Parse a legacy break-between value for `page-break-{before,after}`.
///
/// See https://drafts.csswg.org/css-break/#page-break-properties.
#[inline]
pub fn parse_legacy<'i>(input: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
let ident = input.expect_ident()?;
let break_value = match BreakBetween::from_ident(ident) {
Ok(v) => v,
Err(()) => {
return Err(location
.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
},
};
pub(crate) fn parse_legacy<'i>(_: &ParserContext, input: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
let break_value = BreakBetween::parse(input)?;
match break_value {
BreakBetween::Always => Ok(BreakBetween::Page),
BreakBetween::Auto | BreakBetween::Avoid | BreakBetween::Left | BreakBetween::Right => {
Ok(break_value)
},
BreakBetween::Page => {
Err(location
.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
},
}
}
@ -1923,7 +1914,7 @@ impl BreakBetween {
/// Serialize a legacy break-between value for `page-break-*`.
///
/// See https://drafts.csswg.org/css-break/#page-break-properties.
pub fn to_css_legacy<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
pub(crate) fn to_css_legacy<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
@ -1960,6 +1951,37 @@ impl BreakBetween {
pub enum BreakWithin {
Auto,
Avoid,
AvoidPage,
AvoidColumn,
}
impl BreakWithin {
/// Parse a legacy break-between value for `page-break-inside`.
///
/// See https://drafts.csswg.org/css-break/#page-break-properties.
#[inline]
pub(crate) fn parse_legacy<'i>(_: &ParserContext, input: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
let break_value = BreakWithin::parse(input)?;
match break_value {
BreakWithin::Auto | BreakWithin::Avoid => Ok(break_value),
BreakWithin::AvoidPage | BreakWithin::AvoidColumn => {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
},
}
}
/// Serialize a legacy break-between value for `page-break-inside`.
///
/// See https://drafts.csswg.org/css-break/#page-break-properties.
pub(crate) fn to_css_legacy<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match *self {
BreakWithin::Auto | BreakWithin::Avoid => self.to_css(dest),
BreakWithin::AvoidPage | BreakWithin::AvoidColumn => Ok(()),
}
}
}
/// The value for the `overflow-x` / `overflow-y` properties.