Bug 1758391 - Rename text-wrap to text-wrap-style, and create the text-wrap shorthand. r=firefox-style-system-reviewers,emilio

This depends on having `text-wrap-mode`, introduced in bug 1852478 as part of
turning `white-space` into a shorthand.

Differential Revision: https://phabricator.services.mozilla.com/D198791
This commit is contained in:
Jonathan Kew 2024-01-26 09:40:03 +00:00
parent 5741b2b190
commit 16f020d34a
9 changed files with 131 additions and 34 deletions

View file

@ -131,7 +131,7 @@ use.counter.error:
send_in_pings:
- use-counters
# Total of 2307 use counter metrics (excludes denominators).
# Total of 2309 use counter metrics (excludes denominators).
# Total of 358 'page' use counters.
use.counter.page:
svgsvgelement_getelementbyid:
@ -15735,7 +15735,7 @@ use.counter.deprecated_ops.doc:
send_in_pings:
- use-counters
# Total of 695 'CSS (page)' use counters.
# Total of 696 'CSS (page)' use counters.
use.counter.css.page:
css_align_content:
type: counter
@ -17692,10 +17692,10 @@ use.counter.css.page:
send_in_pings:
- use-counters
css_text_wrap:
css_text_wrap_mode:
type: counter
description: >
Whether a page used the CSS property text-wrap.
Whether a page used the CSS property text-wrap-mode.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
@ -17709,10 +17709,10 @@ use.counter.css.page:
send_in_pings:
- use-counters
css_text_wrap_mode:
css_text_wrap_style:
type: counter
description: >
Whether a page used the CSS property text-wrap-mode.
Whether a page used the CSS property text-wrap-style.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
@ -23268,6 +23268,23 @@ use.counter.css.page:
send_in_pings:
- use-counters
css_text_wrap:
type: counter
description: >
Whether a page used the CSS property text-wrap.
Compare against `use.counter.top_level_content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- dom-core@mozilla.com
- emilio@mozilla.com
expires: never
send_in_pings:
- use-counters
css_white_space:
type: counter
description: >
@ -27552,7 +27569,7 @@ use.counter.css.page:
send_in_pings:
- use-counters
# Total of 695 'CSS (document)' use counters.
# Total of 696 'CSS (document)' use counters.
use.counter.css.doc:
css_align_content:
type: counter
@ -29509,10 +29526,10 @@ use.counter.css.doc:
send_in_pings:
- use-counters
css_text_wrap:
css_text_wrap_mode:
type: counter
description: >
Whether a document used the CSS property text-wrap.
Whether a document used the CSS property text-wrap-mode.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
@ -29526,10 +29543,10 @@ use.counter.css.doc:
send_in_pings:
- use-counters
css_text_wrap_mode:
css_text_wrap_style:
type: counter
description: >
Whether a document used the CSS property text-wrap-mode.
Whether a document used the CSS property text-wrap-style.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
@ -35085,6 +35102,23 @@ use.counter.css.doc:
send_in_pings:
- use-counters
css_text_wrap:
type: counter
description: >
Whether a document used the CSS property text-wrap.
Compare against `use.counter.content_documents_destroyed`
to calculate the rate.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1852098
notification_emails:
- dom-core@mozilla.com
- emilio@mozilla.com
expires: never
send_in_pings:
- use-counters
css_white_space:
type: counter
description: >

View file

@ -1470,8 +1470,9 @@ void nsBlockFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
}
// Whether to apply text-wrap: balance behavior.
bool tryBalance = StyleText()->mTextWrap == StyleTextWrap::Balance &&
!GetPrevContinuation();
bool tryBalance =
StyleText()->mTextWrapStyle == StyleTextWrapStyle::Balance &&
!GetPrevContinuation();
// Struct used to hold the "target" number of lines or clamp position to
// maintain when doing text-wrap: balance.

View file

@ -177,7 +177,7 @@ rusty-enums = [
"mozilla::StyleBlend",
"mozilla::StyleMaskComposite",
"mozilla::StyleWritingModeProperty",
"mozilla::StyleTextWrap",
"mozilla::StyleTextWrapStyle",
"StyleFontVariantEmoji",
]
allowlist-vars = [

View file

@ -409,7 +409,7 @@ enum class StyleTextWrapMode : uint8_t {
// (see https://bugzilla.mozilla.org/show_bug.cgi?id=1758391) and
// white-space (https://bugzilla.mozilla.org/show_bug.cgi?id=1852478)
// into shorthands.
enum class StyleTextWrap : uint8_t {
enum class StyleTextWrapStyle : uint8_t {
Auto = 0,
Stable,
Balance,

View file

@ -2855,7 +2855,7 @@ nsStyleText::nsStyleText(const nsStyleText& aSource)
mTextEmphasisStyle(aSource.mTextEmphasisStyle),
mHyphenateCharacter(aSource.mHyphenateCharacter),
mWebkitTextSecurity(aSource.mWebkitTextSecurity),
mTextWrap(aSource.mTextWrap) {
mTextWrapStyle(aSource.mTextWrapStyle) {
MOZ_COUNT_CTOR(nsStyleText);
}
@ -2890,7 +2890,7 @@ nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aNewData) const {
(mTabSize != aNewData.mTabSize) ||
(mHyphenateCharacter != aNewData.mHyphenateCharacter) ||
(mWebkitTextSecurity != aNewData.mWebkitTextSecurity) ||
(mTextWrap != aNewData.mTextWrap)) {
(mTextWrapStyle != aNewData.mTextWrapStyle)) {
return NS_STYLE_HINT_REFLOW;
}

View file

@ -887,7 +887,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
mozilla::StyleTextSecurity mWebkitTextSecurity =
mozilla::StyleTextSecurity::None;
mozilla::StyleTextWrap mTextWrap = mozilla::StyleTextWrap::Auto;
mozilla::StyleTextWrapStyle mTextWrapStyle =
mozilla::StyleTextWrapStyle::Auto;
char16_t TextSecurityMaskChar() const {
switch (mWebkitTextSecurity) {

View file

@ -882,6 +882,7 @@ def _remove_common_first_line_and_first_letter_properties(props, engine):
props.remove("text-justify")
props.remove("white-space-collapse")
props.remove("text-wrap-mode")
props.remove("text-wrap-style")
props.remove("word-break")
props.remove("text-indent")
@ -983,10 +984,11 @@ class PropertyRestrictions:
def placeholder(data):
props = PropertyRestrictions.first_line(data)
props.add("opacity")
props.add("text-wrap")
props.add("text-overflow")
props.add("text-align")
props.add("text-justify")
for p in PropertyRestrictions.shorthand(data, "text-wrap"):
props.add(p)
for p in PropertyRestrictions.shorthand(data, "white-space"):
props.add(p)
return props
@ -996,7 +998,6 @@ class PropertyRestrictions:
def marker(data):
return set(
[
"text-wrap",
"color",
"text-combine-upright",
"text-transform",
@ -1006,6 +1007,7 @@ class PropertyRestrictions:
"line-height",
"-moz-osx-font-smoothing",
]
+ PropertyRestrictions.shorthand(data, "text-wrap")
+ PropertyRestrictions.shorthand(data, "white-space")
+ PropertyRestrictions.spec(data, "css-fonts")
+ PropertyRestrictions.spec(data, "css-animations")
@ -1021,7 +1023,6 @@ class PropertyRestrictions:
"opacity",
"visibility",
"text-shadow",
"text-wrap",
"text-combine-upright",
"ruby-position",
# XXX Should these really apply to cue?
@ -1032,6 +1033,7 @@ class PropertyRestrictions:
"background-blend-mode",
]
+ PropertyRestrictions.shorthand(data, "text-decoration")
+ PropertyRestrictions.shorthand(data, "text-wrap")
+ PropertyRestrictions.shorthand(data, "white-space")
+ PropertyRestrictions.shorthand(data, "background")
+ PropertyRestrictions.shorthand(data, "outline")

View file

@ -160,16 +160,6 @@ ${helpers.single_keyword(
affects="layout",
)}
${helpers.single_keyword(
name="text-wrap-mode",
values="wrap nowrap",
engines="gecko",
gecko_enum_prefix="StyleTextWrapMode",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text-4/#propdef-text-wrap-mode",
affects="layout",
)}
${helpers.predefined_type(
"text-shadow",
"SimpleShadow",
@ -402,13 +392,23 @@ ${helpers.single_keyword(
)}
${helpers.single_keyword(
"text-wrap",
"text-wrap-mode",
"wrap nowrap",
engines="gecko",
gecko_enum_prefix="StyleTextWrapMode",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text-4/#propdef-text-wrap-mode",
affects="layout",
)}
${helpers.single_keyword(
"text-wrap-style",
"auto stable balance",
engines="gecko",
gecko_pref="layout.css.text-wrap-balance.enabled",
has_effect_on_gecko_scrollbars=False,
gecko_enum_prefix="StyleTextWrap",
gecko_enum_prefix="StyleTextWrapStyle",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text-4/#text-wrap",
spec="https://drafts.csswg.org/css-text-4/#text-wrap-style",
affects="layout",
)}

View file

@ -46,6 +46,65 @@
}
</%helpers:shorthand>
<%helpers:shorthand
name="text-wrap"
engines="gecko"
sub_properties="text-wrap-mode text-wrap-style"
spec="https://www.w3.org/TR/css-text-4/#text-wrap"
>
use crate::properties::longhands::{text_wrap_mode, text_wrap_style};
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut mode = None;
let mut style = None;
loop {
if mode.is_none() {
if let Ok(value) = input.try_parse(|input| text_wrap_mode::parse(context, input)) {
mode = Some(value);
continue
}
}
if style.is_none() {
if let Ok(value) = input.try_parse(|input| text_wrap_style::parse(context, input)) {
style = Some(value);
continue
}
}
break
}
if mode.is_some() || style.is_some() {
Ok(expanded! {
text_wrap_mode: unwrap_or_initial!(text_wrap_mode, mode),
text_wrap_style: unwrap_or_initial!(text_wrap_style, style),
})
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
use text_wrap_mode::computed_value::T as Mode;
use text_wrap_style::computed_value::T as Style;
if matches!(self.text_wrap_style, None | Some(&Style::Auto)) {
return self.text_wrap_mode.to_css(dest);
}
if *self.text_wrap_mode != Mode::Wrap {
self.text_wrap_mode.to_css(dest)?;
dest.write_char(' ')?;
}
self.text_wrap_style.to_css(dest)
}
}
</%helpers:shorthand>
<%helpers:shorthand
name="white-space"
engines="gecko"