Simple line layout: Move TextFragmentIterator::runWidth to ::textWidth.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2017 22:25:58 +0000 (22:25 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2017 22:25:58 +0000 (22:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167705
<rdar://problem/30314393>

Reviewed by Antti Koivisto.

We also don't need to compute logicalHeight for logicalLeft/right since the
cases where it matters (floating boxes) are not supported by simple line layout.

Covered by existing test.

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::updateLineConstrains):
* rendering/SimpleLineLayoutTextFragmentIterator.cpp:
(WebCore::SimpleLineLayout::nextBreakablePositionInSegment):
(WebCore::SimpleLineLayout::TextFragmentIterator::textWidth):
(WebCore::SimpleLineLayout::TextFragmentIterator::runWidth): Deleted.
* rendering/SimpleLineLayoutTextFragmentIterator.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211531 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/SimpleLineLayout.cpp
Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp
Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h

index 4a004bc..79c6a51 100644 (file)
@@ -1,3 +1,24 @@
+2017-02-01  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Move TextFragmentIterator::runWidth to ::textWidth.
+        https://bugs.webkit.org/show_bug.cgi?id=167705
+        <rdar://problem/30314393>
+
+        Reviewed by Antti Koivisto.
+
+        We also don't need to compute logicalHeight for logicalLeft/right since the
+        cases where it matters (floating boxes) are not supported by simple line layout. 
+
+        Covered by existing test.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::updateLineConstrains):
+        * rendering/SimpleLineLayoutTextFragmentIterator.cpp:
+        (WebCore::SimpleLineLayout::nextBreakablePositionInSegment):
+        (WebCore::SimpleLineLayout::TextFragmentIterator::textWidth):
+        (WebCore::SimpleLineLayout::TextFragmentIterator::runWidth): Deleted.
+        * rendering/SimpleLineLayoutTextFragmentIterator.h:
+
 2017-02-01  Jer Noble  <jer.noble@apple.com>
 
         Fix compilation error under recent clang update
index 7648342..8f3e12d 100644 (file)
@@ -604,10 +604,8 @@ static void updateLineConstrains(const RenderBlockFlow& flow, LineState& line, c
 {
     bool shouldApplyTextIndent = !flow.isAnonymous() || flow.parent()->firstChild() == &flow;
     LayoutUnit height = flow.logicalHeight();
-    LayoutUnit logicalHeight = flow.minLineHeightForReplacedRenderer(false, 0);
-    float logicalRightOffset = flow.logicalRightOffsetForLine(height, DoNotIndentText, logicalHeight);
-    line.setLogicalLeftOffset(flow.logicalLeftOffsetForLine(height, DoNotIndentText, logicalHeight) +
-        (shouldApplyTextIndent && isFirstLine ? flow.textIndentOffset() : LayoutUnit(0)));
+    line.setLogicalLeftOffset(flow.logicalLeftOffsetForLine(height, DoNotIndentText) + (shouldApplyTextIndent && isFirstLine ? flow.textIndentOffset() : LayoutUnit(0)));
+    float logicalRightOffset = flow.logicalRightOffsetForLine(height, DoNotIndentText);
     line.setAvailableWidth(std::max<float>(0, logicalRightOffset - line.logicalLeftOffset()));
     if (style.textAlign == JUSTIFY)
         line.setNeedsAllFragments();
index 7ab34f3..edf89a9 100644 (file)
@@ -119,7 +119,7 @@ void TextFragmentIterator::revertToEndOfFragment(const TextFragment& fragment)
     m_atEndOfSegment = false;
 }
 
-static unsigned nextBreakablePositionInSegment(LazyLineBreakIterator& lineBreakIterator, unsigned startPosition, bool breakNBSP, bool keepAllWordsForCJK)
+static inline unsigned nextBreakablePositionInSegment(LazyLineBreakIterator& lineBreakIterator, unsigned startPosition, bool breakNBSP, bool keepAllWordsForCJK)
 {
     if (keepAllWordsForCJK) {
         if (breakNBSP)
@@ -166,18 +166,6 @@ unsigned TextFragmentIterator::nextNonWhitespacePosition(const FlowContents::Seg
     return position;
 }
 
-float TextFragmentIterator::textWidth(unsigned from, unsigned to, float xPosition) const
-{
-    auto& segment = *m_currentSegment;
-    ASSERT(segment.start <= from && from <= segment.end && segment.start <= to && to <= segment.end);
-    ASSERT(is<RenderText>(segment.renderer));
-    if (!m_style.font.size())
-        return 0;
-    if (m_style.font.isFixedPitch() || (from == segment.start && to == segment.end))
-        return downcast<RenderText>(segment.renderer).width(segment.toSegmentPosition(from), to - from, m_style.font, xPosition, nullptr, nullptr);
-    return runWidth(segment, from, to, xPosition);
-}
-
 std::optional<unsigned> TextFragmentIterator::lastHyphenPosition(const TextFragmentIterator::TextFragment& run, unsigned before) const
 {
     ASSERT(run.start() < before);
@@ -243,20 +231,25 @@ unsigned TextFragmentIterator::skipToNextPosition(PositionType positionType, uns
     return nextPosition;
 }
 
-float TextFragmentIterator::runWidth(const FlowContents::Segment& segment, unsigned startPosition, unsigned endPosition, float xPosition) const
+float TextFragmentIterator::textWidth(unsigned from, unsigned to, float xPosition) const
 {
-    ASSERT(m_style.font.size());
-    ASSERT(startPosition <= endPosition);
-    if (startPosition == endPosition)
+    auto& segment = *m_currentSegment;
+    ASSERT(segment.start <= from && from <= segment.end && segment.start <= to && to <= segment.end);
+    ASSERT(is<RenderText>(segment.renderer));
+    if (!m_style.font.size() || from == to)
         return 0;
-    unsigned segmentFrom = segment.toSegmentPosition(startPosition);
-    unsigned segmentTo = segment.toSegmentPosition(endPosition);
+
+    unsigned segmentFrom = segment.toSegmentPosition(from);
+    unsigned segmentTo = segment.toSegmentPosition(to);
+    if (m_style.font.isFixedPitch())
+        return downcast<RenderText>(segment.renderer).width(segmentFrom, segmentTo - segmentFrom, m_style.font, xPosition, nullptr, nullptr);
+
     bool measureWithEndSpace = m_style.collapseWhitespace && segmentTo < segment.text.length() && segment.text[segmentTo] == ' ';
     if (measureWithEndSpace)
         ++segmentTo;
-    TextRun run(StringView(segment.text).substring(segmentFrom, segmentTo - segmentFrom));
-    run.setXPos(xPosition);
-    run.setTabSize(!!m_style.tabWidth, m_style.tabWidth);
+    TextRun run(StringView(segment.text).substring(segmentFrom, segmentTo - segmentFrom), xPosition);
+    if (m_style.tabWidth)
+        run.setTabSize(true, m_style.tabWidth);
     float width = m_style.font.width(run);
     if (measureWithEndSpace)
         width -= (m_style.spaceWidth + m_style.wordSpacing);
index 0533a32..5858065 100644 (file)
@@ -136,7 +136,6 @@ private:
     bool isHardLineBreak(const FlowContents::Iterator& segment) const;
     unsigned nextBreakablePosition(const FlowContents::Segment&, unsigned startPosition);
     unsigned nextNonWhitespacePosition(const FlowContents::Segment&, unsigned startPosition);
-    float runWidth(const FlowContents::Segment&, unsigned startPosition, unsigned endPosition, float xPosition) const;
 
     FlowContents m_flowContents;
     FlowContents::Iterator m_currentSegment;