Move TrailingObjects class into its own h/cpp
authorzoltan@webkit.org <zoltan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Dec 2013 23:21:42 +0000 (23:21 +0000)
committerzoltan@webkit.org <zoltan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Dec 2013 23:21:42 +0000 (23:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124956

Reviewed by David Hyatt.

Since I moved space-ignoring inline functions into MidpointState in r160074,
I can nicely separate TrailingObjects class from BreakingContextInlineHeader.h.
This change improves the readability, and it's part of the RenderBlockLineLayout
refactoring campaign, which is tracked under bug #121261.

No new tests, no behavior change.

* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderBlock.h:
* rendering/RenderBlockFlow.h:
* rendering/line/BreakingContextInlineHeaders.h:
* rendering/line/TrailingObjects.cpp: Added.
(WebCore::TrailingObjects::updateMidpointsForTrailingBoxes):
* rendering/line/TrailingObjects.h: Added.
(WebCore::TrailingObjects::TrailingObjects):
(WebCore::TrailingObjects::setTrailingWhitespace):
(WebCore::TrailingObjects::clear):
(WebCore::TrailingObjects::appendBoxIfNeeded):

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderBlockFlow.h
Source/WebCore/rendering/line/BreakingContextInlineHeaders.h
Source/WebCore/rendering/line/TrailingObjects.cpp [new file with mode: 0644]
Source/WebCore/rendering/line/TrailingObjects.h [new file with mode: 0644]

index b0299d8..9937115 100644 (file)
@@ -2222,6 +2222,7 @@ set(WebCore_SOURCES
     rendering/line/LineBreaker.cpp
     rendering/line/LineInfo.cpp
     rendering/line/LineWidth.cpp
+    rendering/line/TrailingObjects.cpp
 
     rendering/mathml/RenderMathMLBlock.cpp
     rendering/mathml/RenderMathMLFenced.cpp
index a13ca96..4ebfa03 100644 (file)
@@ -1,3 +1,32 @@
+2013-12-04  Zoltan Horvath  <zoltan@webkit.org>
+
+        Move TrailingObjects class into its own h/cpp
+        https://bugs.webkit.org/show_bug.cgi?id=124956
+
+        Reviewed by David Hyatt.
+
+        Since I moved space-ignoring inline functions into MidpointState in r160074,
+        I can nicely separate TrailingObjects class from BreakingContextInlineHeader.h.
+        This change improves the readability, and it's part of the RenderBlockLineLayout
+        refactoring campaign, which is tracked under bug #121261.
+
+        No new tests, no behavior change.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/RenderBlock.h:
+        * rendering/RenderBlockFlow.h:
+        * rendering/line/BreakingContextInlineHeaders.h:
+        * rendering/line/TrailingObjects.cpp: Added.
+        (WebCore::TrailingObjects::updateMidpointsForTrailingBoxes):
+        * rendering/line/TrailingObjects.h: Added.
+        (WebCore::TrailingObjects::TrailingObjects):
+        (WebCore::TrailingObjects::setTrailingWhitespace):
+        (WebCore::TrailingObjects::clear):
+        (WebCore::TrailingObjects::appendBoxIfNeeded):
+
 2013-12-04  Oliver Hunt  <oliver@apple.com>
 
         Refactor static getter function prototype to include thisValue in addition to the base object
index 301cebe..1c6d4ff 100644 (file)
@@ -4528,6 +4528,7 @@ webcore_sources += \
        Source/WebCore/rendering/line/LineLayoutState.h \
        Source/WebCore/rendering/line/LineWidth.h \
        Source/WebCore/rendering/line/LineWidth.cpp \
+    Source/WebCore/rendering/line/TrailingObjects.cpp \
        Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp \
        Source/WebCore/rendering/mathml/RenderMathMLBlock.h \
        Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp \
index 416556c..27509b4 100644 (file)
     <ClCompile Include="..\rendering\line\LineBreaker.cpp" />
     <ClCompile Include="..\rendering\line\LineInfo.cpp" />
     <ClCompile Include="..\rendering\line\LineWidth.cpp" />
+    <ClCompile Include="..\rendering\line\TrailingObjects.cpp" />
     <ClCompile Include="..\rendering\shapes\BoxShape.cpp" />
     <ClCompile Include="..\rendering\shapes\PolygonShape.cpp" />
     <ClCompile Include="..\rendering\shapes\RasterShape.cpp" />
     <ClInclude Include="..\rendering\line\LineInlineHeaders.h" />
     <ClInclude Include="..\rendering\line\LineLayoutState.h" />
     <ClInclude Include="..\rendering\line\LineWidth.h" />
+    <ClInclude Include="..\rendering\line\TrailingObjects.h" />
     <ClInclude Include="..\rendering\shapes\BoxShape.h" />
     <ClInclude Include="..\rendering\shapes\PolygonShape.h" />
     <ClInclude Include="..\rendering\shapes\RasterShape.h" />
index cdc77b8..725a7ec 100644 (file)
                FEE1811416C319E800084849 /* SQLTransactionBackend.h in Headers */ = {isa = PBXBuildFile; fileRef = FEE1811216C319E800084849 /* SQLTransactionBackend.h */; };
                FF945ECB161F7F3600971BC8 /* PseudoElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FF945EC9161F7F3600971BC8 /* PseudoElement.cpp */; };
                FF945ECC161F7F3600971BC8 /* PseudoElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FF945ECA161F7F3600971BC8 /* PseudoElement.h */; };
+               FFAC30FE184FB145008C4F1E /* TrailingObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = FFAC30FC184FB145008C4F1E /* TrailingObjects.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               FFAC30FF184FB145008C4F1E /* TrailingObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FFAC30FD184FB145008C4F1E /* TrailingObjects.cpp */; };
                FFB698CC1833EE0D00158A31 /* LineBreaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FFB698CA1833EC3800158A31 /* LineBreaker.cpp */; };
                FFB698CF183402BB00158A31 /* LineInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FFB698CD1833F17600158A31 /* LineInfo.cpp */; };
                FFD5B97A135CC97800D5E92A /* PageVisibilityState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FFD5B977135CC97800D5E92A /* PageVisibilityState.cpp */; };
                FEE1811216C319E800084849 /* SQLTransactionBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLTransactionBackend.h; sourceTree = "<group>"; };
                FF945EC9161F7F3600971BC8 /* PseudoElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PseudoElement.cpp; sourceTree = "<group>"; };
                FF945ECA161F7F3600971BC8 /* PseudoElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PseudoElement.h; sourceTree = "<group>"; };
+               FFAC30FC184FB145008C4F1E /* TrailingObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrailingObjects.h; sourceTree = "<group>"; };
+               FFAC30FD184FB145008C4F1E /* TrailingObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrailingObjects.cpp; sourceTree = "<group>"; };
                FFB698C91832F10B00158A31 /* BreakingContextInlineHeaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BreakingContextInlineHeaders.h; sourceTree = "<group>"; };
                FFB698CA1833EC3800158A31 /* LineBreaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineBreaker.cpp; sourceTree = "<group>"; };
                FFB698CB1833EC3800158A31 /* LineBreaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineBreaker.h; sourceTree = "<group>"; };
                FFB698C81832F10B00158A31 /* line */ = {
                        isa = PBXGroup;
                        children = (
+                               FFAC30FC184FB145008C4F1E /* TrailingObjects.h */,
+                               FFAC30FD184FB145008C4F1E /* TrailingObjects.cpp */,
                                FFDBC045183D27B700407109 /* LineWidth.h */,
                                FFDBC046183D27B700407109 /* LineWidth.cpp */,
                                FFEFAB2D183BCB6F00514534 /* LineInlineHeaders.h */,
                                49E911CB0EF86D47009D0CAF /* ScaleTransformOperation.h in Headers */,
                                5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */,
                                5162C7F511F77EFB00612EFE /* SchemeRegistry.h in Headers */,
+                               FFAC30FE184FB145008C4F1E /* TrailingObjects.h in Headers */,
                                9BD0BF9312A42BF50072FD43 /* ScopedEventQueue.h in Headers */,
                                BCEC01BE0C274DAC009F4EC9 /* Screen.h in Headers */,
                                A84D82C111D3474800972990 /* ScriptableDocumentParser.h in Headers */,
                                7ACD88D314C08BD60084EDD2 /* InspectorIndexedDBAgent.cpp in Sources */,
                                4D273CF91669420800259CA1 /* InspectorInputAgent.cpp in Sources */,
                                20D629261253690B00081543 /* InspectorInstrumentation.cpp in Sources */,
+                               FFAC30FF184FB145008C4F1E /* TrailingObjects.cpp in Sources */,
                                71B1E1261640491A00B1880A /* InspectorLayerTreeAgent.cpp in Sources */,
                                7AA51DD5148506A900AD2752 /* InspectorMemoryAgent.cpp in Sources */,
                                7C522D4B15B477E8009B7C95 /* InspectorOverlay.cpp in Sources */,
index 8f63806..e9d934e 100644 (file)
@@ -41,7 +41,6 @@
 namespace WebCore {
 
 class BidiContext;
-class InlineIterator;
 class LayoutStateMaintainer;
 class LineLayoutState;
 class LineWidth;
@@ -59,11 +58,7 @@ class BasicShape;
 class TextLayout;
 class WordMeasurement;
 
-template <class Iterator, class Run> class BidiResolver;
 template <class Run> class BidiRunList;
-template <class Iterator> class MidpointState;
-typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver;
-typedef MidpointState<InlineIterator> LineMidpointState;
 typedef WTF::ListHashSet<RenderBox*, 16> TrackedRendererListHashSet;
 typedef WTF::HashMap<const RenderBlock*, OwnPtr<TrackedRendererListHashSet>> TrackedDescendantsMap;
 typedef WTF::HashMap<const RenderBox*, OwnPtr<HashSet<RenderBlock*>>> TrackedContainerMap;
index 5d28101..744d814 100644 (file)
@@ -27,6 +27,7 @@
 #include "RenderBlock.h"
 #include "RenderLineBoxList.h"
 #include "SimpleLineLayout.h"
+#include "TrailingObjects.h"
 
 namespace WebCore {
 
index a386c32..cc96d8f 100644 (file)
@@ -34,6 +34,7 @@
 #include "RenderInline.h"
 #include "RenderListMarker.h"
 #include "RenderRubyRun.h"
+#include "TrailingObjects.h"
 #include "break_lines.h"
 #include <wtf/unicode/CharacterNames.h>
 
@@ -67,86 +68,6 @@ public:
     HashSet<const SimpleFontData*> fallbackFonts;
 };
 
-class TrailingObjects {
-public:
-    TrailingObjects();
-    void setTrailingWhitespace(RenderText*);
-    void clear();
-    void appendBoxIfNeeded(RenderBoxModelObject*);
-
-    enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace };
-
-    void updateMidpointsForTrailingBoxes(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot);
-
-private:
-    RenderText* m_whitespace;
-    Vector<RenderBoxModelObject*, 4> m_boxes;
-};
-
-TrailingObjects::TrailingObjects()
-    : m_whitespace(0)
-{
-}
-
-inline void TrailingObjects::setTrailingWhitespace(RenderText* whitespace)
-{
-    ASSERT(whitespace);
-    m_whitespace = whitespace;
-}
-
-inline void TrailingObjects::clear()
-{
-    m_whitespace = 0;
-    m_boxes.shrink(0); // Use shrink(0) instead of clear() to retain our capacity.
-}
-
-inline void TrailingObjects::appendBoxIfNeeded(RenderBoxModelObject* box)
-{
-    if (m_whitespace)
-        m_boxes.append(box);
-}
-
-void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace)
-{
-    if (!m_whitespace)
-        return;
-
-    // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint.
-    // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline.
-    if (lineMidpointState.numMidpoints % 2) {
-        // Find the trailing space object's midpoint.
-        int trailingSpaceMidpoint = lineMidpointState.numMidpoints - 1;
-        for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints[trailingSpaceMidpoint].renderer() != m_whitespace; --trailingSpaceMidpoint) { }
-        ASSERT(trailingSpaceMidpoint >= 0);
-        if (collapseFirstSpace == CollapseFirstSpace)
-            lineMidpointState.midpoints[trailingSpaceMidpoint].m_pos--;
-
-        // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts
-        // ignoring spaces.
-        size_t currentMidpoint = trailingSpaceMidpoint + 1;
-        for (size_t i = 0; i < m_boxes.size(); ++i) {
-            if (currentMidpoint >= lineMidpointState.numMidpoints) {
-                // We don't have a midpoint for this box yet.
-                lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
-            } else {
-                ASSERT(lineMidpointState.midpoints[currentMidpoint].renderer() == m_boxes[i]);
-                ASSERT(lineMidpointState.midpoints[currentMidpoint + 1].renderer() == m_boxes[i]);
-            }
-            currentMidpoint += 2;
-        }
-    } else if (!lBreak.renderer()) {
-        ASSERT(m_whitespace->isText());
-        ASSERT(collapseFirstSpace == CollapseFirstSpace);
-        // Add a new end midpoint that stops right at the very end.
-        unsigned length = m_whitespace->textLength();
-        unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
-        InlineIterator endMid(0, m_whitespace, pos);
-        lineMidpointState.startIgnoringSpaces(endMid);
-        for (size_t i = 0; i < m_boxes.size(); ++i)
-            lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
-    }
-}
-
 class BreakingContext {
 public:
     BreakingContext(LineBreaker& lineBreaker, InlineBidiResolver& resolver, LineInfo& inLineInfo, LineWidth& lineWidth, RenderTextInfo& inRenderTextInfo, FloatingObject* inLastFloatFromPreviousLine, bool appliedStartWidth, RenderBlockFlow& block)
diff --git a/Source/WebCore/rendering/line/TrailingObjects.cpp b/Source/WebCore/rendering/line/TrailingObjects.cpp
new file mode 100644 (file)
index 0000000..a6ce84a
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
+ * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com>
+ * Copyright (C) 2013 Adobe Systems Inc. All right reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "TrailingObjects.h"
+
+#include "InlineIterator.h"
+
+namespace WebCore {
+
+void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace)
+{
+    if (!m_whitespace)
+        return;
+
+    // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint.
+    // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline.
+    if (lineMidpointState.numMidpoints % 2) {
+        // Find the trailing space object's midpoint.
+        int trailingSpaceMidpoint = lineMidpointState.numMidpoints - 1;
+        for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints[trailingSpaceMidpoint].renderer() != m_whitespace; --trailingSpaceMidpoint) { }
+        ASSERT(trailingSpaceMidpoint >= 0);
+        if (collapseFirstSpace == CollapseFirstSpace)
+            lineMidpointState.midpoints[trailingSpaceMidpoint].m_pos--;
+
+        // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts
+        // ignoring spaces.
+        size_t currentMidpoint = trailingSpaceMidpoint + 1;
+        for (size_t i = 0; i < m_boxes.size(); ++i) {
+            if (currentMidpoint >= lineMidpointState.numMidpoints) {
+                // We don't have a midpoint for this box yet.
+                lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
+            } else {
+                ASSERT(lineMidpointState.midpoints[currentMidpoint].renderer() == m_boxes[i]);
+                ASSERT(lineMidpointState.midpoints[currentMidpoint + 1].renderer() == m_boxes[i]);
+            }
+            currentMidpoint += 2;
+        }
+    } else if (!lBreak.renderer()) {
+        ASSERT(m_whitespace->isText());
+        ASSERT(collapseFirstSpace == CollapseFirstSpace);
+        // Add a new end midpoint that stops right at the very end.
+        unsigned length = m_whitespace->textLength();
+        unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
+        InlineIterator endMid(0, m_whitespace, pos);
+        lineMidpointState.startIgnoringSpaces(endMid);
+        for (size_t i = 0; i < m_boxes.size(); ++i)
+            lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]);
+    }
+}
+
+}
diff --git a/Source/WebCore/rendering/line/TrailingObjects.h b/Source/WebCore/rendering/line/TrailingObjects.h
new file mode 100644 (file)
index 0000000..5aedea6
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
+ * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com>
+ * Copyright (C) 2013 Adobe Systems Inc. All right reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TrailingObjects_h
+#define TrailingObjects_h
+
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class InlineIterator;
+class RenderBoxModelObject;
+class RenderText;
+
+struct BidiRun;
+
+template <class Iterator, class Run> class BidiResolver;
+template <class Iterator> class MidpointState;
+typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver;
+typedef MidpointState<InlineIterator> LineMidpointState;
+
+class TrailingObjects {
+public:
+    TrailingObjects()
+        : m_whitespace(0)
+    { }
+
+    void setTrailingWhitespace(RenderText* whitespace)
+    {
+        ASSERT(whitespace);
+        m_whitespace = whitespace;
+    }
+
+    void clear()
+    {
+        m_whitespace = 0;
+        m_boxes.shrink(0); // Use shrink(0) instead of clear() to retain our capacity.
+    }
+
+    void appendBoxIfNeeded(RenderBoxModelObject* box)
+    {
+        if (m_whitespace)
+            m_boxes.append(box);
+    }
+
+    enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace };
+
+    void updateMidpointsForTrailingBoxes(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot);
+
+private:
+    RenderText* m_whitespace;
+    Vector<RenderBoxModelObject*, 4> m_boxes;
+};
+
+}
+
+#endif // TrailingObjects_h