Commit 4f10679e authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Simplify LayoutText line box collection

This uses the same mechanism used in
https://chromium-review.googlesource.com/c/chromium/src/+/1612358
for LayoutInline.

The new code favors LayoutNG for performance, to avoid back-and-forth
flipping in some cases for LayoutNG and allow that for Legacy.

Also fix an issue of unnecessary flipping for SVG text.

Change-Id: I70dc61807d2284a3cdda1fd4733b7ab2bfdd00e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1615680
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660998}
parent b2dad40f
...@@ -120,11 +120,8 @@ class CORE_EXPORT LayoutText : public LayoutObject { ...@@ -120,11 +120,8 @@ class CORE_EXPORT LayoutText : public LayoutObject {
FloatRect LocalBoundingBoxRectForAccessibility() const final; FloatRect LocalBoundingBoxRectForAccessibility() const final;
enum ClippingOption { kNoClipping, kClipToEllipsis }; enum ClippingOption { kNoClipping, kClipToEllipsis };
enum LocalOrAbsoluteOption { kLocalQuads, kAbsoluteQuads }; void LocalQuadsInFlippedBlocksDirection(Vector<FloatQuad>&,
void Quads(Vector<FloatQuad>&, ClippingOption = kNoClipping) const;
ClippingOption = kNoClipping,
LocalOrAbsoluteOption = kAbsoluteQuads,
MapCoordinatesFlags mode = 0) const;
PositionWithAffinity PositionForPoint(const LayoutPoint&) const override; PositionWithAffinity PositionForPoint(const LayoutPoint&) const override;
...@@ -346,11 +343,11 @@ class CORE_EXPORT LayoutText : public LayoutObject { ...@@ -346,11 +343,11 @@ class CORE_EXPORT LayoutText : public LayoutObject {
private: private:
InlineTextBoxList& MutableTextBoxes(); InlineTextBoxList& MutableTextBoxes();
void AccumlateQuads(Vector<FloatQuad>&, // PhysicalRectCollector should be like a function:
const IntRect& ellipsis_rect, // void (const PhysicalRect&).
LocalOrAbsoluteOption, template <typename PhysicalRectCollector>
MapCoordinatesFlags mode, void CollectLineBoxRects(const PhysicalRectCollector&,
const LayoutRect&) const; ClippingOption option = kNoClipping) const;
void ComputePreferredLogicalWidths(float lead_width); void ComputePreferredLogicalWidths(float lead_width);
void ComputePreferredLogicalWidths( void ComputePreferredLogicalWidths(
...@@ -395,6 +392,22 @@ class CORE_EXPORT LayoutText : public LayoutObject { ...@@ -395,6 +392,22 @@ class CORE_EXPORT LayoutText : public LayoutObject {
bool CanOptimizeSetText() const; bool CanOptimizeSetText() const;
void SetFirstTextBoxLogicalLeft(float text_width) const; void SetFirstTextBoxLogicalLeft(float text_width) const;
bool NeedsFlipForWritingMode() const {
return HasFlippedBlocksWritingMode() && !IsSVG();
}
// These functions flip the input rect in ContainingBlock() if
// NeedsFlipForWritingMode() is true. If |block_for_flipping| is not null,
// it should be ContainingBlock(), otherwise the function will call
// ContainingBlock() by themselves. The caller should prepare
// |block_for_flipping| if it will loop through many rects to flip to avoid
// the cost of repeated ContainingBlock() calls.
ALWAYS_INLINE WARN_UNUSED_RESULT LayoutRect
FlipForWritingMode(const PhysicalRect& r,
const LayoutBlock* block_for_flipping = nullptr) const;
ALWAYS_INLINE WARN_UNUSED_RESULT PhysicalRect
FlipForWritingMode(const LayoutRect& r,
const LayoutBlock* block_for_flipping = nullptr) const;
private: private:
ContentCaptureManager* GetContentCaptureManager(); ContentCaptureManager* GetContentCaptureManager();
NodeHolder node_holder_; NodeHolder node_holder_;
......
...@@ -662,21 +662,6 @@ TEST_P(ParameterizedLayoutTextTest, PhysicalLinesBoundingBoxVerticalRL) { ...@@ -662,21 +662,6 @@ TEST_P(ParameterizedLayoutTextTest, PhysicalLinesBoundingBoxVerticalRL) {
->PhysicalLinesBoundingBox()); ->PhysicalLinesBoundingBox());
} }
TEST_P(ParameterizedLayoutTextTest, QuadsBasic) {
GetDocument().SetCompatibilityMode(Document::kQuirksMode);
LoadAhem();
SetBasicBody(
"<style>p {font: 13px/17px Ahem;}</style>"
"<p id=one>one</p>");
const Element& one = *GetDocument().getElementById("one");
Vector<FloatQuad> actual_quads;
ToLayoutText(one.firstChild()->GetLayoutObject())->Quads(actual_quads);
EXPECT_EQ(
Vector<FloatQuad>({FloatQuad(FloatPoint(8, 10), FloatPoint(47, 10),
FloatPoint(47, 23), FloatPoint(8, 23))}),
actual_quads);
}
TEST_P(ParameterizedLayoutTextTest, WordBreakElement) { TEST_P(ParameterizedLayoutTextTest, WordBreakElement) {
SetBasicBody("foo <wbr> bar"); SetBasicBody("foo <wbr> bar");
...@@ -807,4 +792,51 @@ TEST_P(ParameterizedLayoutTextTest, LocalSelectionRectLineHeightVertical) { ...@@ -807,4 +792,51 @@ TEST_P(ParameterizedLayoutTextTest, LocalSelectionRectLineHeightVertical) {
"foo bar b^a|z</div>")); "foo bar b^a|z</div>"));
} }
TEST_P(ParameterizedLayoutTextTest, VisualRectInDocumentSVGTspan) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<style>
body {
margin:0px;
font: 20px/20px Ahem;
}
</style>
<svg>
<text x="10" y="50" width="100">
<tspan id="target" dx="15" dy="25">tspan</tspan>
</text>
</svg>
)HTML");
LayoutText* target =
ToLayoutText(GetLayoutObjectByElementId("target")->SlowFirstChild());
const int ascent = 16;
PhysicalRect expected(10 + 15, 50 + 25 - ascent, 20 * 5, 20);
EXPECT_EQ(expected, target->VisualRectInDocument());
EXPECT_EQ(expected, target->VisualRectInDocument(kUseGeometryMapper));
}
TEST_P(ParameterizedLayoutTextTest, VisualRectInDocumentSVGTspanTB) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<style>
body {
margin:0px;
font: 20px/20px Ahem;
}
</style>
<svg>
<text x="50" y="10" width="100" writing-mode="tb">
<tspan id="target" dx="15" dy="25">tspan</tspan>
</text>
</svg>
)HTML");
LayoutText* target =
ToLayoutText(GetLayoutObjectByElementId("target")->SlowFirstChild());
PhysicalRect expected(50 + 15 - 20 / 2, 10 + 25, 20, 20 * 5);
EXPECT_EQ(expected, target->VisualRectInDocument());
EXPECT_EQ(expected, target->VisualRectInDocument(kUseGeometryMapper));
}
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment