Skip to content

Commit

Permalink
[LayoutNG] Don't generate break opportunity right after forced break
Browse files Browse the repository at this point in the history
A generated break opportunity right after a forced break is always
redundant, as there's already a break. So this patch stops adding it.

Bug: 976568
Change-Id: Ia0ef3f608981ba407549358889f388ddff438f8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1668058
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Auto-Submit: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Reviewed-by: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671027}
  • Loading branch information
xiaochengh authored and Commit Bot committed Jun 20, 2019
1 parent 6e40a7d commit 0d28499
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,12 @@ void NGInlineItemsBuilderTemplate<
// removed entirely. However, when the first collapsible space is
// 'nowrap', and the following collapsed space is 'wrap', the
// collapsed space needs to create a break opportunity.
AppendGeneratedBreakOpportunity(layout_object);
// Note that we don't need to generate a break opportunity right
// after a forced break.
if (item->Type() != NGInlineItem::kControl ||
text_[item->StartOffset()] != kNewlineCharacter) {
AppendGeneratedBreakOpportunity(layout_object);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/dom/dom_token_list.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_child_layout_context.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_layout_algorithm.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
Expand Down Expand Up @@ -1520,6 +1521,24 @@ TEST_F(NGInlineNodeTest, InsertedWBRWithLineBreakInRelayout) {
EXPECT_EQ(String(u"foo\u200Bbar"), GetText());
}

TEST_F(NGInlineNodeTest, CollapsibleSpaceFollowingBRWithNoWrapStyle) {
SetupHtml("t", "<div id=t><span style=white-space:pre><br></span> </div>");
EXPECT_EQ("\n", GetText());

GetDocument().QuerySelector("span")->removeAttribute(html_names::kStyleAttr);
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ("\n", GetText());
}

TEST_F(NGInlineNodeTest, CollapsibleSpaceFollowingNewlineWithPreStyle) {
SetupHtml("t", "<div id=t><span style=white-space:pre>\n</span> </div>");
EXPECT_EQ("\n", GetText());

GetDocument().QuerySelector("span")->removeAttribute(html_names::kStyleAttr);
UpdateAllLifecyclePhasesForTest();
EXPECT_EQ("", GetText());
}

#if SEGMENT_BREAK_TRANSFORMATION_FOR_EAST_ASIAN_WIDTH
// https://crbug.com/879088
TEST_F(NGInlineNodeTest, RemoveSegmentBreakFromJapaneseInRelayout) {
Expand Down

0 comments on commit 0d28499

Please sign in to comment.