Permalink
Browse files

style: Implement page-break-{before,after} as legacy shorthands for {…

…before,after}.

This is all the style-system work needed for this.

This implements the concept of legacy shorthands, teaches tests to understand
it, and adds a few more tests for these properties in particular.

The WPT even caught a few WebKit / Blink bugs:

  https://bugs.chromium.org/p/chromium/issues/detail?id=906336
  https://bugs.webkit.org/show_bug.cgi?id=191803

This doesn't change the layout behavior for page-break-before: always, since
it'd stop breaking in multicol and such. Similarly, break-before / break-after:
column and page still behave the same, I'll file followups for those given
comment 22.

Differential Revision: https://phabricator.services.mozilla.com/D12211
  • Loading branch information...
emilio committed Nov 30, 2018
1 parent a427e4f commit 374249fa54bb1fd8b855b07f7df7059094d8558b
@@ -438,22 +438,22 @@ ${helpers.single_keyword(
)}
${helpers.predefined_type(
"page-break-after",
"break-after",
"BreakBetween",
"computed::BreakBetween::Auto",
needs_context=False,
products="gecko",
spec="https://drafts.csswg.org/css2/page.html#propdef-page-break-after",
spec="https://drafts.csswg.org/css-break/#propdef-break-after",
animation_value_type="discrete",
)}
${helpers.predefined_type(
"page-break-before",
"break-before",
"BreakBetween",
"computed::BreakBetween::Auto",
needs_context=False,
products="gecko",
spec="https://drafts.csswg.org/css2/page.html#propdef-page-break-before",
spec="https://drafts.csswg.org/css-break/#propdef-break-before",
animation_value_type="discrete",
)}
@@ -447,3 +447,49 @@ macro_rules! try_parse_one {
}
}
</%helpers:shorthand>
<%helpers: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"
>
pub fn parse_value<'i>(
_: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::values::specified::box_::BreakBetween;
Ok(expanded! {
break_before: BreakBetween::parse_legacy(input)?,
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.break_before.to_css_legacy(dest)
}
}
</%helpers:shorthand>
<%helpers: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"
>
pub fn parse_value<'i>(
_: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::values::specified::box_::BreakBetween;
Ok(expanded! {
break_after: BreakBetween::parse_legacy(input)?,
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.break_after.to_css_legacy(dest)
}
}
</%helpers:shorthand>
@@ -1286,13 +1286,60 @@ pub enum Appearance {
)]
#[repr(u8)]
pub enum BreakBetween {
Auto,
Always,
Auto,
Page,
Avoid,
Left,
Right,
}
impl BreakBetween {
/// Parse a legacy break-between value for `page-break-*`.
///
/// 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())
)),
};
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())))
}
}
}
/// 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
where
W: Write,
{
match *self {
BreakBetween::Auto |
BreakBetween::Avoid |
BreakBetween::Left |
BreakBetween::Right => self.to_css(dest),
BreakBetween::Page => dest.write_str("always"),
BreakBetween::Always => Ok(()),
}
}
}
/// A kind of break within a box.
///
/// https://drafts.csswg.org/css-break/#break-within

0 comments on commit 374249f

Please sign in to comment.