Make SimpleLineLayout::Layout a class
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2013 14:12:32 +0000 (14:12 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Oct 2013 14:12:32 +0000 (14:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123508

Reviewed by Mario Sanchez Prada.

Improve encapsulation.

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

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

index 9a0dd10..23268d3 100644 (file)
@@ -1,5 +1,14 @@
 2013-10-30  Antti Koivisto  <antti@apple.com>
 
+        Make SimpleLineLayout::Layout a class
+        https://bugs.webkit.org/show_bug.cgi?id=123508
+
+        Reviewed by Mario Sanchez Prada.
+
+        Improve encapsulation.
+
+2013-10-30  Antti Koivisto  <antti@apple.com>
+
         REGRESSION(r158214): It made zillion tests crash on GTK and EFL
         https://bugs.webkit.org/show_bug.cgi?id=123505
 
index 21f9dc0..beaf00e 100644 (file)
@@ -3148,7 +3148,7 @@ bool RenderBlockFlow::hasLines() const
     ASSERT(childrenInline());
 
     if (m_simpleLineLayout)
-        return m_simpleLineLayout->lineCount;
+        return m_simpleLineLayout->lineCount();
 
     return lineBoxes().firstLineBox();
 }
index 23b11e4..db187cf 100644 (file)
@@ -334,10 +334,10 @@ std::unique_ptr<Layout> Layout::create(const RunVector& runVector, unsigned line
 }
 
 Layout::Layout(const RunVector& runVector, unsigned lineCount)
-    : runCount(runVector.size())
-    , lineCount(lineCount)
+    : m_lineCount(lineCount)
+    , m_runCount(runVector.size())
 {
-    memcpy(runs, runVector.data(), runCount * sizeof(Run));
+    memcpy(m_runs, runVector.data(), m_runCount * sizeof(Run));
 }
 
 }
index 95ec307..9dad3f2 100644 (file)
@@ -59,18 +59,23 @@ struct Run {
     float right;
 };
 
-struct Layout {
+class Layout {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     typedef Vector<Run, 10> RunVector;
     static std::unique_ptr<Layout> create(const RunVector&, unsigned lineCount);
 
-    unsigned runCount;
-    unsigned lineCount;
-    Run runs[0];
+    unsigned lineCount() const { return m_lineCount; }
+
+    unsigned runCount() const { return m_runCount; }
+    const Run& runAt(unsigned i) const { return m_runs[i]; }
 
 private:
     Layout(const RunVector&, unsigned lineCount);
+
+    unsigned m_lineCount;
+    unsigned m_runCount;
+    Run m_runs[0];
 };
 
 std::unique_ptr<Layout> create(RenderBlockFlow&);
index 0a4ba7e..cabdb7f 100644 (file)
@@ -74,7 +74,7 @@ bool hitTestFlow(const RenderBlockFlow& flow, const Layout& layout, const HitTes
     if (hitTestAction != HitTestForeground)
         return false;
 
-    if (!layout.runCount)
+    if (!layout.runCount())
         return false;
 
     RenderStyle& style = flow.style();
index 074ea44..794f407 100644 (file)
@@ -65,43 +65,43 @@ namespace SimpleLineLayout {
 
 inline LayoutUnit computeFlowHeight(const RenderBlockFlow& flow, const Layout& layout)
 {
-    return lineHeightFromFlow(flow) * layout.lineCount;
+    return lineHeightFromFlow(flow) * layout.lineCount();
 }
 
 inline LayoutUnit computeFlowFirstLineBaseline(const RenderBlockFlow& flow, const Layout& layout)
 {
-    ASSERT_UNUSED(layout, layout.runCount);
+    ASSERT_UNUSED(layout, layout.runCount());
     return flow.borderAndPaddingBefore() + baselineFromFlow(flow);
 }
 
 inline LayoutUnit computeFlowLastLineBaseline(const RenderBlockFlow& flow, const Layout& layout)
 {
-    ASSERT(layout.runCount);
-    return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.runCount - 1) + baselineFromFlow(flow);
+    ASSERT(layout.runCount());
+    return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.runCount() - 1) + baselineFromFlow(flow);
 }
 
 inline unsigned findTextCaretMinimumOffset(const RenderText&, const Layout& layout)
 {
-    if (!layout.runCount)
+    if (!layout.runCount())
         return 0;
-    return layout.runs[0].textOffset;
+    return layout.runAt(0).textOffset;
 }
 
 inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Layout& layout)
 {
-    if (!layout.runCount)
+    if (!layout.runCount())
         return renderer.textLength();
-    auto& last = layout.runs[layout.runCount - 1];
+    auto& last = layout.runAt(layout.runCount() - 1);
     return last.textOffset + last.textLength;
 }
 
 inline bool containsTextCaretOffset(const RenderText&, const Layout& layout, unsigned offset)
 {
-    for (unsigned i = 0; i < layout.runCount; ++i) {
-        auto& line = layout.runs[i];
-        if (offset < line.textOffset)
+    for (unsigned i = 0; i < layout.runCount(); ++i) {
+        auto& run = layout.runAt(i);
+        if (offset < run.textOffset)
             return false;
-        if (offset <= line.textOffset + line.textLength)
+        if (offset <= run.textOffset + run.textLength)
             return true;
     }
     return false;
@@ -109,8 +109,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.runs[i].textLength)
+    for (unsigned i = 0; i < layout.runCount(); ++i) {
+        if (layout.runAt(i).textLength)
             return true;
     }
     return false;
index 5cd869a..76c1b60 100644 (file)
@@ -189,7 +189,7 @@ inline RunResolver::Run RunResolver::Iterator::operator*() const
 
 inline const SimpleLineLayout::Run& RunResolver::Iterator::simpleRun() const
 {
-    return m_resolver.m_layout.runs[m_runIndex];
+    return m_resolver.m_layout.runAt(m_runIndex);
 }
 
 inline RunResolver::RunResolver(const RenderBlockFlow& flow, const Layout& layout)
@@ -210,7 +210,7 @@ inline RunResolver::Iterator RunResolver::begin() const
 
 inline RunResolver::Iterator RunResolver::end() const
 {
-    return Iterator(*this, m_layout.runCount);
+    return Iterator(*this, m_layout.runCount());
 }
 
 inline LineResolver::Iterator::Iterator(RunResolver::Iterator runIterator)