Implement white-space:break-spaces value
authorjfernandez@igalia.com <jfernandez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Apr 2019 20:31:05 +0000 (20:31 +0000)
committerjfernandez@igalia.com <jfernandez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Apr 2019 20:31:05 +0000 (20:31 +0000)
commit30a9ad47549f6006fd861a935de96c327e8426e2
tree0cde16b7929a9ffc07284ca2b209d9d4cbc8d14d
parentd71a955bd31ee211a25bddbbe24ab55394f4bcc0
Implement white-space:break-spaces value
https://bugs.webkit.org/show_bug.cgi?id=177327

Reviewed by Myles Maxfield and Zalan Bujtas.

LayoutTests/imported/w3c:

Imoprted a few aditional tests from the CSS Text WPT suite that are relevant for this change.

* web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-008-expected.html: Added.
* web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-008.html: Added.
* web-platform-tests/css/css-text/overflow-wrap/w3c-import.log:
* web-platform-tests/css/css-text/parsing/white-space-valid-expected.txt:
* web-platform-tests/css/css-text/white-space/break-spaces-003-expected.html: Added.
* web-platform-tests/css/css-text/white-space/break-spaces-003.html: Added.
* web-platform-tests/css/css-text/white-space/break-spaces-009-expected.html: Added.
* web-platform-tests/css/css-text/white-space/break-spaces-009.html: Added.
* web-platform-tests/css/css-text/white-space/w3c-import.log:

Source/WebCore:

Finally the CSS WG decided [1] to move back the 'break-spaces' value to
the 'white-space' property. This makes the parsing logic easier than
the previous approach of using the 'overflow-wrap' property.

This new value prevents the white-space sequence to collapse and gives
breaking opportunities after every preserved white-space.

https://drafts.csswg.org/css-text-3/#valdef-white-space-break-spaces

Additionally, unlike 'pre-wrap', non-collapsible spaces or tabs at the
end of a line cannot be hung or visually collapsed, since we want them
to be preserved and broken.

[1] https://github.com/w3c/csswg-drafts/pull/2841

Tests: imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-008.html
       imported/w3c/web-platform-tests/css/css-text/white-space/break-spaces-003.html
       imported/w3c/web-platform-tests/css/css-text/white-space/break-spaces-009.html

* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue): New mapping for CSSVaueBreakSpaces.
(WebCore::CSSPrimitiveValue::operator WhiteSpace const): New value BreakSpaces for the Whitespace enum.
* css/CSSProperties.json: new 'break-spaces' value for the 'white-space' property.
* css/CSSValueKeywords.in: new break-spaces keyword
* css/parser/CSSParserFastPaths.cpp:
(WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue):
* rendering/SimpleLineLayout.cpp:  The SimpleLineLayut codepath must handle properly the new behavior of preserved whitespaces.
(WebCore::SimpleLineLayout::LineState::hasTrailingWhitespace const): Require that m_trailingWhitespaceWidth being greater than zero.
(WebCore::SimpleLineLayout::LineState::hasWhitespaceFragments const): New function to detect former whitespae fragments that could be breaking opportunities.
(WebCore::SimpleLineLayout::removeTrailingWhitespace): The 'break-spaces' feature forbids to remove any trailing whitespace.
(WebCore::SimpleLineLayout::firstFragment): We have now leading whitespace sequences comming from the previous line.
(WebCore::SimpleLineLayout::createLineRuns): We should revert some breaking opportunities if others were formerly found in the line.
* rendering/SimpleLineLayoutTextFragmentIterator.cpp:
(WebCore::SimpleLineLayout::TextFragmentIterator::Style::Style): New style fields to determine whether the break-space feature is being used. Also split out the break-all and breal-all values.
* rendering/SimpleLineLayoutTextFragmentIterator.h:
* rendering/line/BreakingContext.h: Different codepath but similar changes to properly handle the new behavior of preserved whitespace.
(WebCore::BreakingContext::BreakingContext): New class field to determine whether there are some whitespace that may prevent the word ot be broken.
(WebCore::BreakingContext::handleText): New line-breaking logic to implement the break-spaces behavior.
(WebCore::BreakingContext::trailingSpacesHang): Cases where the preserved breakspaces should hand or overflow.
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::collapseWhiteSpace): With break-spaces collapsing whitespaces is not allowed.
(WebCore::RenderStyle::breakOnlyAfterWhiteSpace const): Add the WhiteSpace::BreakSpaces to this group.
* rendering/style/RenderStyleConstants.h: A new constan added.

LayoutTests:

Removed many failure expectations of tests that pass now thanks to this change.

The overflow-wrap-break-word-003.html tests fails in mac and iOS platforms due to an issue related to
how we compute widths using 'ch' units and 'monospace' fonts. I filed bug #196169 to report the specific
case of this test (break-word+pre-wrap) but the root cause it's probably the bug #196353.

I have submitted a PR [1] to the Web Platform Tests to change several tests that failed only if the
monospace font is used, but pass with the Ahem font. Additionally, I've requested another PR [2] to
add new layout tests, with the same case than overflow-wrap-break-word-003.html but using the Ahem
font.

[1] https://github.com/web-platform-tests/wpt/pull/16137
[2] https://github.com/web-platform-tests/wpt/pull/16124

* TestExpectations: Removed many Failure entries on tests that pass now thanks to this change.
* platform/mac/TestExpectations: Added one Failure entry and filed the corresponding bug report.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244036 268f45cc-cd09-0410-ab3c-d52691b4dbfc
26 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-008-expected.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/overflow-wrap-break-word-008.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/overflow-wrap/w3c-import.log
LayoutTests/imported/w3c/web-platform-tests/css/css-text/parsing/white-space-valid-expected.txt
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/break-spaces-003-expected.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/break-spaces-003.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/break-spaces-009-expected.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/break-spaces-009.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/textarea-break-spaces-001-expected.html
LayoutTests/imported/w3c/web-platform-tests/css/css-text/white-space/w3c-import.log
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSProperties.json
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/parser/CSSParserFastPaths.cpp
Source/WebCore/rendering/SimpleLineLayout.cpp
Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp
Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h
Source/WebCore/rendering/line/BreakingContext.h
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/RenderStyleConstants.h