Use start/end instead of textOffset/textLength for simple text runs
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 10 Nov 2013 23:32:48 +0000 (23:32 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 10 Nov 2013 23:32:48 +0000 (23:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124130

Reviewed by Oliver Hunt.

The code reads better this way.

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::createTextRuns):
* rendering/SimpleLineLayout.h:
(WebCore::SimpleLineLayout::Run::Run):
* rendering/SimpleLineLayoutFunctions.h:
(WebCore::SimpleLineLayout::findTextCaretMinimumOffset):
(WebCore::SimpleLineLayout::findTextCaretMaximumOffset):
(WebCore::SimpleLineLayout::containsTextCaretOffset):
(WebCore::SimpleLineLayout::isTextRendered):
* rendering/SimpleLineLayoutResolver.h:
(WebCore::SimpleLineLayout::RunResolver::Run::text):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/SimpleLineLayout.cpp
Source/WebCore/rendering/SimpleLineLayout.h
Source/WebCore/rendering/SimpleLineLayoutFunctions.h
Source/WebCore/rendering/SimpleLineLayoutResolver.h

index 8af41de..3e81f78 100644 (file)
@@ -1,5 +1,26 @@
 2013-11-10  Antti Koivisto  <antti@apple.com>
 
+        Use start/end instead of textOffset/textLength for simple text runs
+        https://bugs.webkit.org/show_bug.cgi?id=124130
+
+        Reviewed by Oliver Hunt.
+        
+        The code reads better this way.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::createTextRuns):
+        * rendering/SimpleLineLayout.h:
+        (WebCore::SimpleLineLayout::Run::Run):
+        * rendering/SimpleLineLayoutFunctions.h:
+        (WebCore::SimpleLineLayout::findTextCaretMinimumOffset):
+        (WebCore::SimpleLineLayout::findTextCaretMaximumOffset):
+        (WebCore::SimpleLineLayout::containsTextCaretOffset):
+        (WebCore::SimpleLineLayout::isTextRendered):
+        * rendering/SimpleLineLayoutResolver.h:
+        (WebCore::SimpleLineLayout::RunResolver::Run::text):
+
+2013-11-10  Antti Koivisto  <antti@apple.com>
+
         Implement white-space property on simple line layout path
         https://bugs.webkit.org/show_bug.cgi?id=124122
 
index f851619..e05617b 100644 (file)
@@ -310,7 +310,7 @@ void createTextRuns(Layout::RunVector& runs, unsigned& lineCount, RenderBlockFlo
                 if (wordStart > lineStart)
                     lineRuns.append(Run(lineEnd, lineRuns.last().right));
                 lineRuns.last().right = lineRuns.last().left;
-                lineRuns.last().textLength = 1;
+                lineRuns.last().end = lineEnd + 1;
                 lineEnd = wordEnd;
                 break;
             }
@@ -343,7 +343,7 @@ void createTextRuns(Layout::RunVector& runs, unsigned& lineCount, RenderBlockFlo
                         // Include newline to this run too.
                         if (whitespaceEnd < textLength && text[whitespaceEnd] == '\n')
                             ++whitespaceEnd;
-                        lineRuns.last().textLength = whitespaceEnd - lineRuns.last().textOffset;
+                        lineRuns.last().end = whitespaceEnd;
                         lineRuns.last().right = lineWidth.availableWidth();
                         lineEnd = whitespaceEnd;
                         break;
@@ -355,7 +355,7 @@ void createTextRuns(Layout::RunVector& runs, unsigned& lineCount, RenderBlockFlo
                 // There were more than one consecutive whitespace.
                 ASSERT(wordIsPrecededByWhitespace);
                 // Include space to the end of the previous run.
-                lineRuns.last().textLength++;
+                lineRuns.last().end++;
                 lineRuns.last().right += spaceWidth;
                 // Start a new run on the same line.
                 lineRuns.append(Run(wordStart + 1, lineRuns.last().right));
@@ -364,7 +364,7 @@ void createTextRuns(Layout::RunVector& runs, unsigned& lineCount, RenderBlockFlo
             lineWidth.commit();
 
             lineRuns.last().right = lineWidth.committedWidth();
-            lineRuns.last().textLength = wordEnd - lineRuns.last().textOffset;
+            lineRuns.last().end = wordEnd;
 
             lineEnd = wordEnd;
             if (collapseWhitespace)
index 9dad3f2..5d02fd1 100644 (file)
@@ -44,16 +44,16 @@ bool canUseFor(const RenderBlockFlow&);
 
 struct Run {
     Run() { }
-    Run(unsigned textOffset, float left)
-        : textOffset(textOffset)
-        , textLength(0)
+    Run(unsigned start, float left)
+        : start(start)
+        , end(start)
         , isEndOfLine(false)
         , left(left)
         , right(left)
     { }
 
-    unsigned textOffset;
-    unsigned textLength : 31;
+    unsigned start;
+    unsigned end : 31;
     unsigned isEndOfLine : 1;
     float left;
     float right;
index 794f407..82c2423 100644 (file)
@@ -84,7 +84,7 @@ inline unsigned findTextCaretMinimumOffset(const RenderText&, const Layout& layo
 {
     if (!layout.runCount())
         return 0;
-    return layout.runAt(0).textOffset;
+    return layout.runAt(0).start;
 }
 
 inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Layout& layout)
@@ -92,16 +92,16 @@ inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Lay
     if (!layout.runCount())
         return renderer.textLength();
     auto& last = layout.runAt(layout.runCount() - 1);
-    return last.textOffset + last.textLength;
+    return last.end;
 }
 
 inline bool containsTextCaretOffset(const RenderText&, const Layout& layout, unsigned offset)
 {
     for (unsigned i = 0; i < layout.runCount(); ++i) {
         auto& run = layout.runAt(i);
-        if (offset < run.textOffset)
+        if (offset < run.start)
             return false;
-        if (offset <= run.textOffset + run.textLength)
+        if (offset <= run.end)
             return true;
     }
     return false;
@@ -110,7 +110,8 @@ inline bool containsTextCaretOffset(const RenderText&, const Layout& layout, uns
 inline bool isTextRendered(const RenderText&, const Layout& layout)
 {
     for (unsigned i = 0; i < layout.runCount(); ++i) {
-        if (layout.runAt(i).textLength)
+        auto& run = layout.runAt(i);
+        if (run.end > run.start)
             return true;
     }
     return false;
index 76c1b60..cf519ac 100644 (file)
@@ -148,7 +148,7 @@ inline String RunResolver::Run::text() const
 {
     auto& resolver = m_iterator.resolver();
     auto& run = m_iterator.simpleRun();
-    return resolver.m_string.substringSharingImpl(run.textOffset, run.textLength);
+    return resolver.m_string.substringSharingImpl(run.start, run.end - run.start);
 }
 
 inline unsigned RunResolver::Run::lineIndex() const