Title: [211531] trunk/Source/WebCore
Revision
211531
Author
za...@apple.com
Date
2017-02-01 14:25:58 -0800 (Wed, 01 Feb 2017)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (211530 => 211531)


--- trunk/Source/WebCore/ChangeLog	2017-02-01 22:15:07 UTC (rev 211530)
+++ trunk/Source/WebCore/ChangeLog	2017-02-01 22:25:58 UTC (rev 211531)
@@ -1,3 +1,24 @@
+2017-02-01  Zalan Bujtas  <za...@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.no...@apple.com>
 
         Fix compilation error under recent clang update

Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (211530 => 211531)


--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2017-02-01 22:15:07 UTC (rev 211530)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2017-02-01 22:25:58 UTC (rev 211531)
@@ -604,10 +604,8 @@
 {
     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();

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp (211530 => 211531)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp	2017-02-01 22:15:07 UTC (rev 211530)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp	2017-02-01 22:25:58 UTC (rev 211531)
@@ -119,7 +119,7 @@
     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 @@
     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 @@
     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);

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h (211530 => 211531)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h	2017-02-01 22:15:07 UTC (rev 211530)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h	2017-02-01 22:25:58 UTC (rev 211531)
@@ -136,7 +136,6 @@
     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;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to