Bug 1351432 - Implement the break-spaces value of the white-space property r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D34499

--HG--
extra : moz-landing-system : lando
This commit is contained in:
violet 2019-06-12 10:23:49 +00:00
parent f7f51ced95
commit d5bbf998dd
28 changed files with 37 additions and 55 deletions

View file

@ -10459,6 +10459,7 @@ exports.CSS_PROPERTIES = {
"supports": [],
"values": [
"-moz-pre-space",
"break-spaces",
"inherit",
"initial",
"normal",

View file

@ -864,7 +864,7 @@ uint32_t gfxTextRun::BreakAndMeasureText(
gfxFloat* aTrimWhitespace, bool aWhitespaceCanHang, Metrics* aMetrics,
gfxFont::BoundingBoxType aBoundingBoxType, DrawTarget* aRefDrawTarget,
bool* aUsedHyphenation, uint32_t* aLastBreak, bool aCanWordWrap,
gfxBreakPriority* aBreakPriority) {
bool aCanWhitespaceWrap, gfxBreakPriority* aBreakPriority) {
aMaxLength = std::min(aMaxLength, GetLength() - aStart);
NS_ASSERTION(aStart + aMaxLength <= GetLength(), "Substring out of range");
@ -984,7 +984,16 @@ uint32_t gfxTextRun::BreakAndMeasureText(
mCharacterGlyphs[i].IsClusterStart() &&
*aBreakPriority <= gfxBreakPriority::eWordWrapBreak;
if (atBreak || wordWrapping) {
bool whitespaceWrapping = false;
if (i > aStart) {
// The spec says the breaking opportunity is *after* whitespace.
auto const& g = mCharacterGlyphs[i - 1];
whitespaceWrapping =
aCanWhitespaceWrap &&
(g.CharIsSpace() || g.CharIsTab() || g.CharIsNewline());
}
if (atBreak || wordWrapping || whitespaceWrapping) {
gfxFloat hyphenatedAdvance = advance;
if (atHyphenationBreak) {
hyphenatedAdvance += aProvider->GetHyphenWidth();
@ -997,8 +1006,9 @@ uint32_t gfxTextRun::BreakAndMeasureText(
lastBreakTrimmableChars = trimmableChars;
lastBreakTrimmableAdvance = trimmableAdvance;
lastBreakUsedHyphenation = atHyphenationBreak;
*aBreakPriority = atBreak ? gfxBreakPriority::eNormalBreak
: gfxBreakPriority::eWordWrapBreak;
*aBreakPriority = (atBreak || whitespaceWrapping)
? gfxBreakPriority::eNormalBreak
: gfxBreakPriority::eWordWrapBreak;
}
width += advance;

View file

@ -444,7 +444,7 @@ class gfxTextRun : public gfxShapedText {
gfxFont::BoundingBoxType aBoundingBoxType,
DrawTarget* aDrawTargetForTightBoundingBox,
bool* aUsedHyphenation, uint32_t* aLastBreak,
bool aCanWordWrap,
bool aCanWordWrap, bool aCanWhitespaceWrap,
gfxBreakPriority* aBreakPriority);
// Utility getters

View file

@ -1171,6 +1171,7 @@ static nsTextFrameUtils::CompressionMode GetCSSWhitespaceToCompressionMode(
return nsTextFrameUtils::COMPRESS_WHITESPACE_NEWLINE;
case StyleWhiteSpace::Pre:
case StyleWhiteSpace::PreWrap:
case StyleWhiteSpace::BreakSpaces:
if (!aStyleText->NewlineIsSignificant(aFrame)) {
// If newline is set to be preserved, but then suppressed,
// transform newline to space.
@ -8979,8 +8980,11 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
}
bool canTrimTrailingWhitespace = !textStyle->WhiteSpaceIsSignificant() ||
(GetStateBits() & TEXT_IS_IN_TOKEN_MATHML);
bool isBreakSpaces = textStyle->mWhiteSpace == StyleWhiteSpace::BreakSpaces;
// allow whitespace to overflow the container
bool whitespaceCanHang = textStyle->WhiteSpaceCanWrapStyle() &&
bool whitespaceCanHang = !isBreakSpaces &&
textStyle->WhiteSpaceCanWrapStyle() &&
textStyle->WhiteSpaceIsSignificant();
gfxBreakPriority breakPriority = aLineLayout.LastOptionalBreakPriority();
gfxTextRun::SuppressBreak suppressBreak = gfxTextRun::eNoSuppressBreak;
@ -8996,7 +9000,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
suppressBreak, canTrimTrailingWhitespace ? &trimmedWidth : nullptr,
whitespaceCanHang, &textMetrics, boundingBoxType, aDrawTarget,
&usedHyphenation, &transformedLastBreak, textStyle->WordCanWrap(this),
&breakPriority);
isBreakSpaces, &breakPriority);
if (!length && !textMetrics.mAscent && !textMetrics.mDescent) {
// If we're measuring a zero-length piece of text, update
// the height manually.

View file

@ -566,6 +566,7 @@ enum class StyleWhiteSpace : uint8_t {
PreWrap,
PreLine,
PreSpace,
BreakSpaces,
};
// ruby-align, see nsStyleText

View file

@ -1295,30 +1295,35 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
bool WhiteSpaceIsSignificant() const {
return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreSpace;
}
bool NewlineIsSignificantStyle() const {
return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreLine;
}
bool WhiteSpaceOrNewlineIsSignificant() const {
return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreLine ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreSpace;
}
bool TabIsSignificant() const {
return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap;
mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces;
}
bool WhiteSpaceCanWrapStyle() const {
return mWhiteSpace == mozilla::StyleWhiteSpace::Normal ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
mWhiteSpace == mozilla::StyleWhiteSpace::PreLine;
}

View file

@ -4978,7 +4978,7 @@ var gCSSProperties = {
type: CSS_TYPE_LONGHAND,
applies_to_placeholder: true,
initial_values: [ "normal" ],
other_values: [ "pre", "nowrap", "pre-wrap", "pre-line", "-moz-pre-space" ],
other_values: [ "pre", "nowrap", "pre-wrap", "pre-line", "-moz-pre-space", "break-spaces" ],
invalid_values: []
},
"width": {

View file

@ -175,7 +175,7 @@ ${helpers.predefined_type(
<%helpers:single_keyword
name="white-space"
values="normal pre nowrap pre-wrap pre-line"
values="normal pre nowrap pre-wrap pre-line break-spaces"
extra_gecko_values="-moz-pre-space"
gecko_enum_prefix="StyleWhiteSpace"
needs_conversion="True"
@ -193,7 +193,8 @@ ${helpers.predefined_type(
SpecifiedValue::Pre => false,
SpecifiedValue::Normal |
SpecifiedValue::PreWrap |
SpecifiedValue::PreLine => true,
SpecifiedValue::PreLine |
SpecifiedValue::BreakSpaces => true,
}
}
@ -203,7 +204,8 @@ ${helpers.predefined_type(
SpecifiedValue::Nowrap => false,
SpecifiedValue::Pre |
SpecifiedValue::PreWrap |
SpecifiedValue::PreLine => true,
SpecifiedValue::PreLine |
SpecifiedValue::BreakSpaces => true,
}
}
@ -213,7 +215,8 @@ ${helpers.predefined_type(
SpecifiedValue::Nowrap |
SpecifiedValue::PreLine => false,
SpecifiedValue::Pre |
SpecifiedValue::PreWrap => true,
SpecifiedValue::PreWrap |
SpecifiedValue::BreakSpaces => true,
}
}
}

View file

@ -1,2 +0,0 @@
[overflow-wrap-anywhere-002.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[overflow-wrap-anywhere-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[overflow-wrap-break-word-002.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[overflow-wrap-break-word-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[overflow-wrap-break-word-006.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[overflow-wrap-break-word-008.html]
expected: FAIL

View file

@ -1,4 +0,0 @@
[white-space-valid.html]
[e.style['white-space'\] = "break-spaces" should set the property value]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-004.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-005.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-006.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-007.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[break-spaces-009.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[tab-stop-threshold-005.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[tab-stop-threshold-006.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[textarea-break-spaces-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[white-space-intrinsic-size-002.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[word-break-break-all-012.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[word-break-break-all-013.html]
expected: FAIL