Skip to content

Commit

Permalink
[IFC] Minimum content width with "line-break: after-white-space" shou…
Browse files Browse the repository at this point in the history
…ld not include trailing whitespace

https://bugs.webkit.org/show_bug.cgi?id=260617

Reviewed by Antti Koivisto.

This matches legacy line layout behavior (except inside table cells with one (unbreakable) word, where legacy diverges from default behavior).

* LayoutTests/fast/text/preferred-widht-with-line-break-after-whitespace-expected.html: Added.
* LayoutTests/fast/text/preferred-widht-with-line-break-after-whitespace.html: Added.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::placeInlineAndFloatContent):
* Source/WebCore/layout/formattingContexts/inline/TextOnlySimpleLineBuilder.cpp:
(WebCore::Layout::TextOnlySimpleLineBuilder::handleLineEnding):

Canonical link: https://commits.webkit.org/267214@main
  • Loading branch information
alanbaradlay committed Aug 24, 2023
1 parent 2f77755 commit c9e3f24
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 53 deletions.
6 changes: 3 additions & 3 deletions LayoutTests/editing/deleting/delete-block-table-expected.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This test checks that deleting into a table works properly. When deleting three times with the cursor after the character "a" in the "after" text after the table, the "a" should be deleted, as should the "o" of "buffalo" in the last table cell.

Before
Foo baz
bar buffalfter
Foo baz
bar buffalofter
execDeleteCommand: <div>Before</div> <table style="border:3px solid #aaa;"> <tbody><tr> <td> Foo </td> <td> baz </td> </tr> <tr> <td> bar </td> <td> buffalo </td> </tr> </tbody></table> <span id="start">fter</span>
execDeleteCommand: <div>Before</div> <table style="border:3px solid #aaa;"> <tbody><tr> <td> Foo </td> <td> baz </td> </tr> <tr> <td> bar </td> <td> buffalo fter</td></tr></tbody></table>
execDeleteCommand: <div>Before</div> <table style="border:3px solid #aaa;"> <tbody><tr> <td> Foo </td> <td> baz </td> </tr> <tr> <td> bar </td> <td> buffalofter</td></tr></tbody></table>
execDeleteCommand: <div>Before</div> <table style="border:3px solid #aaa;"> <tbody><tr> <td> Foo </td> <td> baz </td> </tr> <tr> <td> bar </td> <td> buffalfter</td></tr></tbody></table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<style>
div {
border: 1px solid green;
line-break: after-white-space;
float: left;
font-family: Ahem;
margin-left: 10px;
}
</style>
<div>X</div>
<div>X X</div>
<div>X X X</div>
<div>X X X</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<style>
div {
border: 1px solid green;
line-break: after-white-space;
float: left;
font-family: Ahem;
margin-left: 10px;
}
</style>
<!-- Pass if border hugs inline content -->
<div>X </div>
<div>X X </div>
<div>X X X</div>
<div>X X X </div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {DIV} at (0,0) size 784x80 [border: (2px solid #FF0000)]
RenderTable {TABLE} at (14,14) size 33x52
RenderTableSection {TBODY} at (0,0) size 33x52
RenderTableRow {TR} at (0,2) size 33x23
RenderTableCell {TD} at (2,2) size 29x23 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (3,1) size 23x20
text run at (3,1) width 23: "foo"
RenderTableRow {TR} at (0,27) size 33x23
RenderTableCell {TD} at (2,27) size 29x23 [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (3,1) size 23x20
text run at (3,1) width 23: "bar"
RenderTable {TABLE} at (14,14) size 29x52
RenderTableSection {TBODY} at (0,0) size 29x52
RenderTableRow {TR} at (0,2) size 29x23
RenderTableCell {TD} at (2,2) size 25x23 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 27x20
text run at (1,1) width 27: "foo "
RenderTableRow {TR} at (0,27) size 29x23
RenderTableCell {TD} at (2,27) size 25x23 [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 26x20
text run at (1,1) width 26: "bar "
selection start: position 1 of child 0 {#text} of child 1 {TD} of child 0 {TR} of child 1 {TBODY} of child 1 {TABLE} of child 1 {DIV} of body
selection end: position 2 of child 1 {TABLE} of child 1 {DIV} of body
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document toDOMRange:range from 1 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
Expand All @@ -31,21 +33,21 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {DIV} at (0,0) size 784x56
RenderTable {TABLE} at (0,0) size 95x56 [border: (3px solid #AAAAAA)]
RenderTableSection {TBODY} at (3,3) size 89x50
RenderTableRow {TR} at (0,2) size 89x22
RenderTableCell {TD} at (2,2) size 31x22 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 25x19
text run at (1,1) width 25: "Foo"
RenderTableCell {TD} at (34,2) size 53x22 [r=0 c=1 rs=1 cs=1]
RenderTable {TABLE} at (0,0) size 87x56 [border: (3px solid #AAAAAA)]
RenderTableSection {TBODY} at (3,3) size 81x50
RenderTableRow {TR} at (0,2) size 81x22
RenderTableCell {TD} at (2,2) size 27x22 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 29x19
text run at (1,1) width 29: "Foo "
RenderTableCell {TD} at (30,2) size 49x22 [r=0 c=1 rs=1 cs=1]
RenderText {#text} at (1,1) size 23x19
text run at (1,1) width 23: "baz"
RenderTableRow {TR} at (0,26) size 89x22
RenderTableCell {TD} at (2,26) size 31x22 [r=1 c=0 rs=1 cs=1]
RenderTableRow {TR} at (0,26) size 81x22
RenderTableCell {TD} at (2,26) size 27x22 [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 21x19
text run at (1,1) width 21: "bar"
RenderTableCell {TD} at (34,26) size 53x22 [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (1,1) size 46x19
text run at (1,1) width 46: "buffalo"
RenderTableCell {TD} at (30,26) size 49x22 [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (1,1) size 50x19
text run at (1,1) width 50: "buffalo "
selection start: position 0 of child 1 {TABLE} of child 0 {DIV} of body
selection end: position 2 of child 1 {TABLE} of child 0 {DIV} of body
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ layer at (0,0) size 800x600
RenderTableRow {TR} at (0,2) size 77x44
RenderTableCell {TD} at (2,2) size 35x44 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 31x19
text run at (2,2) width 27: "Cell"
text run at (28,2) width 5: " "
text run at (2,2) width 31: "Cell "
RenderBR {BR} at (32,2) size 1x19
RenderBR {BR} at (2,22) size 0x19
RenderTableCell {TD} at (38,12) size 37x24 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document toDOMRange:range from 1 of DIV > BODY > HTML > #document to 2 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
Expand All @@ -31,21 +33,21 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {DIV} at (0,0) size 784x52
RenderTable {TABLE} at (0,0) size 95x52 [border: (3px solid #AAAAAA)]
RenderTableSection {TBODY} at (3,3) size 89x46
RenderTableRow {TR} at (0,2) size 89x20
RenderTableCell {TD} at (2,2) size 31x20 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 25x18
text run at (1,1) width 25: "Foo"
RenderTableCell {TD} at (34,2) size 53x20 [r=0 c=1 rs=1 cs=1]
RenderTable {TABLE} at (0,0) size 87x52 [border: (3px solid #AAAAAA)]
RenderTableSection {TBODY} at (3,3) size 81x46
RenderTableRow {TR} at (0,2) size 81x20
RenderTableCell {TD} at (2,2) size 27x20 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 29x18
text run at (1,1) width 29: "Foo "
RenderTableCell {TD} at (30,2) size 49x20 [r=0 c=1 rs=1 cs=1]
RenderText {#text} at (1,1) size 23x18
text run at (1,1) width 23: "baz"
RenderTableRow {TR} at (0,24) size 89x20
RenderTableCell {TD} at (2,24) size 31x20 [r=1 c=0 rs=1 cs=1]
RenderTableRow {TR} at (0,24) size 81x20
RenderTableCell {TD} at (2,24) size 27x20 [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 21x18
text run at (1,1) width 21: "bar"
RenderTableCell {TD} at (34,24) size 53x20 [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (1,1) size 46x18
text run at (1,1) width 46: "buffalo"
RenderTableCell {TD} at (30,24) size 49x20 [r=1 c=1 rs=1 cs=1]
RenderText {#text} at (1,1) size 50x18
text run at (1,1) width 50: "buffalo "
selection start: position 0 of child 1 {TABLE} of child 0 {DIV} of body
selection end: position 2 of child 1 {TABLE} of child 0 {DIV} of body
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ layer at (0,0) size 800x600
RenderTableRow {TR} at (0,2) size 77x40
RenderTableCell {TD} at (2,2) size 35x40 [border: (1px inset #808080)] [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (2,2) size 31x18
text run at (2,2) width 27: "Cell"
text run at (28,2) width 5: " "
text run at (2,2) width 31: "Cell "
RenderBR {BR} at (32,2) size 1x18
RenderBR {BR} at (2,20) size 0x18
RenderTableCell {TD} at (38,11) size 37x22 [border: (1px inset #808080)] [r=0 c=1 rs=1 cs=1]
Expand Down
20 changes: 10 additions & 10 deletions LayoutTests/platform/mac/editing/style/table-selection-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock {DIV} at (0,0) size 784x78 [border: (2px solid #FF0000)]
RenderTable {TABLE} at (14,14) size 33x50
RenderTableSection {TBODY} at (0,0) size 33x50
RenderTableRow {TR} at (0,2) size 33x22
RenderTableCell {TD} at (2,2) size 29x22 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (3,1) size 23x20
text run at (3,1) width 23: "foo"
RenderTableRow {TR} at (0,26) size 33x22
RenderTableCell {TD} at (2,26) size 29x22 [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (3,1) size 23x20
text run at (3,1) width 23: "bar"
RenderTable {TABLE} at (14,14) size 29x50
RenderTableSection {TBODY} at (0,0) size 29x50
RenderTableRow {TR} at (0,2) size 29x22
RenderTableCell {TD} at (2,2) size 25x22 [r=0 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 27x20
text run at (1,1) width 27: "foo "
RenderTableRow {TR} at (0,26) size 29x22
RenderTableCell {TD} at (2,26) size 25x22 [r=1 c=0 rs=1 cs=1]
RenderText {#text} at (1,1) size 26x20
text run at (1,1) width 26: "bar "
selection start: position 1 of child 0 {#text} of child 1 {TD} of child 0 {TR} of child 1 {TBODY} of child 1 {TABLE} of child 1 {DIV} of body
selection end: position 2 of child 1 {TABLE} of child 1 {DIV} of body
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ LineContent LineBuilder::placeInlineAndFloatContent(const InlineItemRange& needs
return horizontalAvailableSpace < m_line.contentLogicalWidth();
};
auto isLineBreakAfterWhitespace = [&] {
return (!isLastLine || lineHasOverflow()) && rootStyle.lineBreak() == LineBreak::AfterWhiteSpace;
return rootStyle.lineBreak() == LineBreak::AfterWhiteSpace && intrinsicWidthMode() != IntrinsicWidthMode::Minimum && (!isLastLine || lineHasOverflow());
};
m_line.handleTrailingTrimmableContent(isLineBreakAfterWhitespace() ? Line::TrailingContentAction::Preserve : Line::TrailingContentAction::Remove);
if (quirks.trailingNonBreakingSpaceNeedsAdjustment(isInIntrinsicWidthMode(), lineHasOverflow()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void TextOnlySimpleLineBuilder::handleLineEnding(InlineItemPosition placedConten
auto horizontalAvailableSpace = m_lineLogicalRect.width();
auto isLastLine = isLastLineWithInlineContent(placedContentEnd, layoutRangeEndIndex);
auto shouldPreserveTrailingWhitespace = [&] {
return root().style().lineBreak() == LineBreak::AfterWhiteSpace && (!isLastLine || horizontalAvailableSpace < m_line.contentLogicalWidth());
return root().style().lineBreak() == LineBreak::AfterWhiteSpace && intrinsicWidthMode() != IntrinsicWidthMode::Minimum && (!isLastLine || horizontalAvailableSpace < m_line.contentLogicalWidth());
};
m_line.handleTrailingTrimmableContent(shouldPreserveTrailingWhitespace() ? Line::TrailingContentAction::Preserve : Line::TrailingContentAction::Remove);
if (formattingContext().formattingQuirks().trailingNonBreakingSpaceNeedsAdjustment(isInIntrinsicWidthMode(), horizontalAvailableSpace < m_line.contentLogicalWidth()))
Expand Down

0 comments on commit c9e3f24

Please sign in to comment.