Title: [213534] trunk
Revision
213534
Author
[email protected]
Date
2017-03-07 13:02:15 -0800 (Tue, 07 Mar 2017)

Log Message

Simple line layout: Do not use invalid m_lastNonWhitespaceFragment while removing trailing whitespace.
https://bugs.webkit.org/show_bug.cgi?id=169288
rdar://problem/30576976

Reviewed by Antti Koivisto.

Source/WebCore:

When the current line has nothing but whitespace, m_lastNonWhitespaceFragment is invalid so
we should not use the start/end values to decide how many characters we need to revert.
This patch makes m_lastNonWhitespaceFragment optional. When it's invalid we just remove
all the runs from the current line since they are all considered whitespace runs.

Test: fast/text/simple-line-layout-line-is-all-whitespace.html

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::revertAllRunsOnCurrentLine):
(WebCore::SimpleLineLayout::LineState::removeTrailingWhitespace):

LayoutTests:

* fast/text/simple-line-layout-line-is-all-whitespace-expected.txt: Added.
* fast/text/simple-line-layout-line-is-all-whitespace.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (213533 => 213534)


--- trunk/LayoutTests/ChangeLog	2017-03-07 20:54:09 UTC (rev 213533)
+++ trunk/LayoutTests/ChangeLog	2017-03-07 21:02:15 UTC (rev 213534)
@@ -1,3 +1,14 @@
+2017-03-07  Zalan Bujtas  <[email protected]>
+
+        Simple line layout: Do not use invalid m_lastNonWhitespaceFragment while removing trailing whitespace.
+        https://bugs.webkit.org/show_bug.cgi?id=169288
+        rdar://problem/30576976
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text/simple-line-layout-line-is-all-whitespace-expected.txt: Added.
+        * fast/text/simple-line-layout-line-is-all-whitespace.html: Added.
+
 2017-03-07  Antoine Quint  <[email protected]>
 
         Flaky Test: media/modern-media-controls/tracks-support/tracks-support-click-track-in-panel.html

Added: trunk/LayoutTests/fast/text/simple-line-layout-line-is-all-whitespace-expected.txt (0 => 213534)


--- trunk/LayoutTests/fast/text/simple-line-layout-line-is-all-whitespace-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/simple-line-layout-line-is-all-whitespace-expected.txt	2017-03-07 21:02:15 UTC (rev 213534)
@@ -0,0 +1,15 @@
+PASS if no crash.
+f bar f bar foo bar foo bar
+f bar
+foobar foobar foobar
+bar
+f
+
+
+  
+fo
+o
+f bar foo foobar foobar fo
+o
+
+

Added: trunk/LayoutTests/fast/text/simple-line-layout-line-is-all-whitespace.html (0 => 213534)


--- trunk/LayoutTests/fast/text/simple-line-layout-line-is-all-whitespace.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/simple-line-layout-line-is-all-whitespace.html	2017-03-07 21:02:15 UTC (rev 213534)
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<pre>
+PASS if no crash.
+f bar f bar foo bar foo bar
+f bar
+foobar foobar foobar
+f bar foo foobar foobar foobar
+f
+
+foo
+  <script>
+if (window.testRunner)
+  testRunner.dumpAsText();
+document.designMode = "on";
+document.execCommand("SelectAll");
+document.execCommand("JustifyRight");
+document.execCommand("JustifyLeft");
+</script>

Modified: trunk/Source/WebCore/ChangeLog (213533 => 213534)


--- trunk/Source/WebCore/ChangeLog	2017-03-07 20:54:09 UTC (rev 213533)
+++ trunk/Source/WebCore/ChangeLog	2017-03-07 21:02:15 UTC (rev 213534)
@@ -1,3 +1,22 @@
+2017-03-07  Zalan Bujtas  <[email protected]>
+
+        Simple line layout: Do not use invalid m_lastNonWhitespaceFragment while removing trailing whitespace.
+        https://bugs.webkit.org/show_bug.cgi?id=169288
+        rdar://problem/30576976
+
+        Reviewed by Antti Koivisto.
+
+        When the current line has nothing but whitespace, m_lastNonWhitespaceFragment is invalid so
+        we should not use the start/end values to decide how many characters we need to revert.
+        This patch makes m_lastNonWhitespaceFragment optional. When it's invalid we just remove
+        all the runs from the current line since they are all considered whitespace runs.
+
+        Test: fast/text/simple-line-layout-line-is-all-whitespace.html
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::revertAllRunsOnCurrentLine):
+        (WebCore::SimpleLineLayout::LineState::removeTrailingWhitespace):
+
 2017-03-07  Alex Christensen  <[email protected]>
 
         [Content Extensions] Rename "Domain" to "Condition" where appropriate

Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (213533 => 213534)


--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2017-03-07 20:54:09 UTC (rev 213533)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2017-03-07 21:02:15 UTC (rev 213534)
@@ -344,6 +344,12 @@
     return 0;
 }
 
+static void revertAllRunsOnCurrentLine(Layout::RunVector& runs)
+{
+    while (!runs.isEmpty() && !runs.last().isEndOfLine)
+        runs.removeLast();
+}
+
 static void revertRuns(Layout::RunVector& runs, unsigned positionToRevertTo, float width)
 {
     while (runs.size()) {
@@ -489,11 +495,26 @@
 
     void removeTrailingWhitespace(Layout::RunVector& runs)
     {
-        if (m_lastFragment.type() != TextFragmentIterator::TextFragment::Whitespace || m_lastFragment.end() == m_lastNonWhitespaceFragment.end())
+        if (m_lastFragment.type() != TextFragmentIterator::TextFragment::Whitespace)
             return;
-        revertRuns(runs, m_lastNonWhitespaceFragment.end(), m_trailingWhitespaceWidth);
-        m_runsWidth -= m_trailingWhitespaceWidth;
-        m_lastFragment = m_lastNonWhitespaceFragment;
+        if (m_lastNonWhitespaceFragment) {
+            auto needsReverting = m_lastNonWhitespaceFragment->end() != m_lastFragment.end();
+            // Trailing whitespace fragment might actually have zero length.
+            ASSERT(needsReverting || !m_trailingWhitespaceWidth);
+            if (needsReverting) {
+                revertRuns(runs, m_lastNonWhitespaceFragment->end(), m_trailingWhitespaceWidth);
+                m_runsWidth -= m_trailingWhitespaceWidth;
+            }
+            m_trailingWhitespaceWidth = 0;
+            m_lastFragment = *m_lastNonWhitespaceFragment;
+            return;
+        }
+        // This line is all whitespace.
+        revertAllRunsOnCurrentLine(runs);
+        m_runsWidth = 0;
+        m_trailingWhitespaceWidth = 0;
+        // FIXME: Make m_lastFragment optional.
+        m_lastFragment = TextFragmentIterator::TextFragment();
     }
 
 private:
@@ -508,7 +529,7 @@
     float m_runsWidth { 0 };
     TextFragmentIterator::TextFragment m_overflowedFragment;
     TextFragmentIterator::TextFragment m_lastFragment;
-    TextFragmentIterator::TextFragment m_lastNonWhitespaceFragment;
+    std::optional<TextFragmentIterator::TextFragment> m_lastNonWhitespaceFragment;
     TextFragmentIterator::TextFragment m_lastCompleteFragment;
     float m_uncompletedWidth { 0 };
     float m_trailingWhitespaceWidth { 0 }; // Use this to remove trailing whitespace without re-mesuring the text.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to