mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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:
parent
cf44eb3e77
commit
5530f7e90c
3 changed files with 66 additions and 21 deletions
|
@ -503,7 +503,6 @@ ${helpers.predefined_type(
|
||||||
"BreakWithin",
|
"BreakWithin",
|
||||||
"computed::BreakWithin::Auto",
|
"computed::BreakWithin::Auto",
|
||||||
engines="gecko",
|
engines="gecko",
|
||||||
aliases="page-break-inside",
|
|
||||||
spec="https://drafts.csswg.org/css-break/#propdef-break-inside",
|
spec="https://drafts.csswg.org/css-break/#propdef-break-inside",
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -316,15 +316,15 @@ ${helpers.two_properties_shorthand(
|
||||||
name="page-break-before"
|
name="page-break-before"
|
||||||
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
|
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
|
||||||
sub_properties="break-before"
|
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>(
|
pub fn parse_value<'i>(
|
||||||
_: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, '_>,
|
input: &mut Parser<'i, '_>,
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
) -> Result<Longhands, ParseError<'i>> {
|
||||||
use crate::values::specified::box_::BreakBetween;
|
use crate::values::specified::box_::BreakBetween;
|
||||||
Ok(expanded! {
|
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"
|
name="page-break-after"
|
||||||
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
|
flags="SHORTHAND_IN_GETCS IS_LEGACY_SHORTHAND"
|
||||||
sub_properties="break-after"
|
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>(
|
pub fn parse_value<'i>(
|
||||||
_: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, '_>,
|
input: &mut Parser<'i, '_>,
|
||||||
) -> Result<Longhands, ParseError<'i>> {
|
) -> Result<Longhands, ParseError<'i>> {
|
||||||
use crate::values::specified::box_::BreakBetween;
|
use crate::values::specified::box_::BreakBetween;
|
||||||
Ok(expanded! {
|
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>
|
||||||
|
|
||||||
|
<%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"
|
<%helpers:shorthand name="offset"
|
||||||
engines="gecko"
|
engines="gecko"
|
||||||
sub_properties="offset-path offset-distance offset-rotate offset-anchor"
|
sub_properties="offset-path offset-distance offset-rotate offset-anchor"
|
||||||
|
|
|
@ -1894,28 +1894,19 @@ pub enum BreakBetween {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
/// See https://drafts.csswg.org/css-break/#page-break-properties.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse_legacy<'i>(input: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
|
pub(crate) fn parse_legacy<'i>(_: &ParserContext, input: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
let break_value = BreakBetween::parse(input)?;
|
||||||
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())));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
match break_value {
|
match break_value {
|
||||||
BreakBetween::Always => Ok(BreakBetween::Page),
|
BreakBetween::Always => Ok(BreakBetween::Page),
|
||||||
BreakBetween::Auto | BreakBetween::Avoid | BreakBetween::Left | BreakBetween::Right => {
|
BreakBetween::Auto | BreakBetween::Avoid | BreakBetween::Left | BreakBetween::Right => {
|
||||||
Ok(break_value)
|
Ok(break_value)
|
||||||
},
|
},
|
||||||
BreakBetween::Page => {
|
BreakBetween::Page => {
|
||||||
Err(location
|
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1923,7 +1914,7 @@ impl BreakBetween {
|
||||||
/// Serialize a legacy break-between value for `page-break-*`.
|
/// Serialize a legacy break-between value for `page-break-*`.
|
||||||
///
|
///
|
||||||
/// See https://drafts.csswg.org/css-break/#page-break-properties.
|
/// 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
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
|
@ -1960,6 +1951,37 @@ impl BreakBetween {
|
||||||
pub enum BreakWithin {
|
pub enum BreakWithin {
|
||||||
Auto,
|
Auto,
|
||||||
Avoid,
|
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.
|
/// The value for the `overflow-x` / `overflow-y` properties.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue