Simplify the ShapeOutsideInfo and ShapeInfo interfaces
authorbjonesbe@adobe.com <bjonesbe@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2013 17:16:01 +0000 (17:16 +0000)
committerbjonesbe@adobe.com <bjonesbe@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Sep 2013 17:16:01 +0000 (17:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121685

Reviewed by Darin Adler.

With the creation ShapeInfo::computeSegmentsForLine, it became possible to
simplify the ShapeInfo classes. ShapeOutsideInfo has no need to save the
segments, and now that segment creation is in its own method, it doesn't have
to save the segments anymore. This also simplifies the public interface of
ShapeOutsideInfo, as it only has one method to do the computation.

Also, the methods in ShapeOutsideInfo have been renamed to reflect the fact
that ShapeOutsideInfo isn't really interested in segments.

No new tests, no new behavior.

* rendering/FloatingObjects.cpp:
(WebCore::FloatingObjects::logicalLeftOffset):
(WebCore::FloatingObjects::logicalRightOffset):
* rendering/LineWidth.cpp:
(WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded):
* rendering/shapes/ShapeInfo.cpp:
* rendering/shapes/ShapeInfo.h:
* rendering/shapes/ShapeInsideInfo.h:
* rendering/shapes/ShapeOutsideInfo.cpp:
(WebCore::ShapeOutsideInfo::updateDeltasForContainingBlockLine):
* rendering/shapes/ShapeOutsideInfo.h:

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/FloatingObjects.cpp
Source/WebCore/rendering/LineWidth.cpp
Source/WebCore/rendering/shapes/ShapeInfo.cpp
Source/WebCore/rendering/shapes/ShapeInfo.h
Source/WebCore/rendering/shapes/ShapeInsideInfo.h
Source/WebCore/rendering/shapes/ShapeOutsideInfo.cpp
Source/WebCore/rendering/shapes/ShapeOutsideInfo.h

index a303a43..5bf1de3 100644 (file)
@@ -1,3 +1,33 @@
+2013-09-20  Bem Jones-Bey  <bjonesbe@adobe.com>
+
+        Simplify the ShapeOutsideInfo and ShapeInfo interfaces
+        https://bugs.webkit.org/show_bug.cgi?id=121685
+
+        Reviewed by Darin Adler.
+
+        With the creation ShapeInfo::computeSegmentsForLine, it became possible to
+        simplify the ShapeInfo classes. ShapeOutsideInfo has no need to save the
+        segments, and now that segment creation is in its own method, it doesn't have
+        to save the segments anymore. This also simplifies the public interface of
+        ShapeOutsideInfo, as it only has one method to do the computation.
+
+        Also, the methods in ShapeOutsideInfo have been renamed to reflect the fact
+        that ShapeOutsideInfo isn't really interested in segments.
+
+        No new tests, no new behavior.
+
+        * rendering/FloatingObjects.cpp:
+        (WebCore::FloatingObjects::logicalLeftOffset):
+        (WebCore::FloatingObjects::logicalRightOffset):
+        * rendering/LineWidth.cpp:
+        (WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded):
+        * rendering/shapes/ShapeInfo.cpp:
+        * rendering/shapes/ShapeInfo.h:
+        * rendering/shapes/ShapeInsideInfo.h:
+        * rendering/shapes/ShapeOutsideInfo.cpp:
+        (WebCore::ShapeOutsideInfo::updateDeltasForContainingBlockLine):
+        * rendering/shapes/ShapeOutsideInfo.h:
+
 2013-09-20  Antonio Gomes  <a1.gomes@sisa.samsung.com>
 
         Making tests added in r156157 JS-only, given that other
index 02c8273..a3f8208 100644 (file)
@@ -288,8 +288,8 @@ LayoutUnit FloatingObjects::logicalLeftOffset(LayoutUnit fixedOffset, LayoutUnit
     const FloatingObject* outermostFloat = adapter.outermostFloat();
     if (offsetMode == ShapeOutsideFloatShapeOffset && outermostFloat) {
         if (ShapeOutsideInfo* shapeOutside = outermostFloat->renderer()->shapeOutsideInfo()) {
-            shapeOutside->computeSegmentsForContainingBlockLine(m_renderer, outermostFloat, logicalTop, logicalHeight);
-            offset += shapeOutside->rightSegmentMarginBoxDelta();
+            shapeOutside->updateDeltasForContainingBlockLine(m_renderer, outermostFloat, logicalTop, logicalHeight);
+            offset += shapeOutside->rightMarginBoxDelta();
         }
     }
 #endif
@@ -314,8 +314,8 @@ LayoutUnit FloatingObjects::logicalRightOffset(LayoutUnit fixedOffset, LayoutUni
     const FloatingObject* outermostFloat = adapter.outermostFloat();
     if (offsetMode == ShapeOutsideFloatShapeOffset && outermostFloat) {
         if (ShapeOutsideInfo* shapeOutside = outermostFloat->renderer()->shapeOutsideInfo()) {
-            shapeOutside->computeSegmentsForContainingBlockLine(m_renderer, outermostFloat, logicalTop, logicalHeight);
-            offset += shapeOutside->leftSegmentMarginBoxDelta();
+            shapeOutside->updateDeltasForContainingBlockLine(m_renderer, outermostFloat, logicalTop, logicalHeight);
+            offset += shapeOutside->leftMarginBoxDelta();
         }
     }
 #endif
index 83dc534..b396e04 100644 (file)
@@ -107,23 +107,23 @@ void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(FloatingObject* newFloat
         if (previousFloat != newFloat && previousFloat->type() == newFloat->type()) {
             previousShapeOutsideInfo = previousFloat->renderer()->shapeOutsideInfo();
             if (previousShapeOutsideInfo)
-                previousShapeOutsideInfo->computeSegmentsForContainingBlockLine(&m_block, previousFloat, m_block.logicalHeight(), logicalHeightForLine(&m_block, m_isFirstLine));
+                previousShapeOutsideInfo->updateDeltasForContainingBlockLine(&m_block, previousFloat, m_block.logicalHeight(), logicalHeightForLine(&m_block, m_isFirstLine));
             break;
         }
     }
 
     ShapeOutsideInfo* shapeOutsideInfo = newFloat->renderer()->shapeOutsideInfo();
     if (shapeOutsideInfo)
-        shapeOutsideInfo->computeSegmentsForContainingBlockLine(&m_block, newFloat, m_block.logicalHeight(), logicalHeightForLine(&m_block, m_isFirstLine));
+        shapeOutsideInfo->updateDeltasForContainingBlockLine(&m_block, newFloat, m_block.logicalHeight(), logicalHeightForLine(&m_block, m_isFirstLine));
 #endif
 
     if (newFloat->type() == FloatingObject::FloatLeft) {
         float newLeft = newFloat->logicalRight(m_block.isHorizontalWritingMode());
 #if ENABLE(CSS_SHAPES)
         if (previousShapeOutsideInfo)
-            newLeft -= previousShapeOutsideInfo->rightSegmentMarginBoxDelta();
+            newLeft -= previousShapeOutsideInfo->rightMarginBoxDelta();
         if (shapeOutsideInfo)
-            newLeft += shapeOutsideInfo->rightSegmentMarginBoxDelta();
+            newLeft += shapeOutsideInfo->rightMarginBoxDelta();
 #endif
 
         if (shouldIndentText() && m_block.style()->isLeftToRightDirection())
@@ -133,9 +133,9 @@ void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(FloatingObject* newFloat
         float newRight = newFloat->logicalLeft(m_block.isHorizontalWritingMode());
 #if ENABLE(CSS_SHAPES)
         if (previousShapeOutsideInfo)
-            newRight -= previousShapeOutsideInfo->leftSegmentMarginBoxDelta();
+            newRight -= previousShapeOutsideInfo->leftMarginBoxDelta();
         if (shapeOutsideInfo)
-            newRight += shapeOutsideInfo->leftSegmentMarginBoxDelta();
+            newRight += shapeOutsideInfo->leftMarginBoxDelta();
 #endif
 
         if (shouldIndentText() && !m_block.style()->isLeftToRightDirection())
index e7bb554..2a14b8a 100644 (file)
@@ -84,20 +84,6 @@ SegmentList ShapeInfo<RenderType>::computeSegmentsForLine(LayoutUnit lineTop, La
     return segments;
 }
 
-template<class RenderType>
-bool ShapeInfo<RenderType>::updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight)
-{
-    ASSERT(lineHeight >= 0);
-    m_shapeLineTop = lineTop - logicalTopOffset();
-    m_lineHeight = lineHeight;
-    m_segments.clear();
-
-    if (lineOverlapsShapeBounds())
-        m_segments = computeSegmentsForLine(lineTop, lineHeight);
-
-    return m_segments.size();
-}
-
 template class ShapeInfo<RenderBlock>;
 template class ShapeInfo<RenderBox>;
 }
index 091303c..5b83e27 100644 (file)
@@ -84,8 +84,6 @@ public:
     }
 
     SegmentList computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) const;
-    virtual bool updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight);
-    void clearSegments() { m_segments.clear(); }
 
     LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox().y() + logicalTopOffset(); }
     LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingBox().maxY() + logicalTopOffset(); }
@@ -119,7 +117,6 @@ protected:
 
     LayoutUnit m_shapeLineTop;
     LayoutUnit m_lineHeight;
-    SegmentList m_segments;
 
     const RenderType* m_renderer;
 
index 9ab353c..4874265 100644 (file)
@@ -71,7 +71,7 @@ public:
     bool updateSegmentsForLine(LayoutSize lineOffset, LayoutUnit lineHeight)
     {
         m_segmentRanges.clear();
-        bool result = ShapeInfo<RenderBlock>::updateSegmentsForLine(lineOffset.height(), lineHeight);
+        bool result = updateSegmentsForLine(lineOffset.height(), lineHeight);
         for (size_t i = 0; i < m_segments.size(); i++) {
             m_segments[i].logicalLeft -= lineOffset.width();
             m_segments[i].logicalRight -= lineOffset.width();
@@ -79,10 +79,18 @@ public:
         return result;
     }
 
-    virtual bool updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) OVERRIDE
+    bool updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight)
     {
+        ASSERT(lineHeight >= 0);
+        m_shapeLineTop = lineTop - logicalTopOffset();
+        m_lineHeight = lineHeight;
+        m_segments.clear();
         m_segmentRanges.clear();
-        return ShapeInfo<RenderBlock>::updateSegmentsForLine(lineTop, lineHeight);
+
+        if (lineOverlapsShapeBounds())
+            m_segments = computeSegmentsForLine(lineTop, lineHeight);
+
+        return m_segments.size();
     }
 
     bool hasSegments() const
@@ -103,6 +111,7 @@ public:
         ASSERT(m_segmentRanges.size() < m_segments.size());
         return &m_segments[m_segmentRanges.size()];
     }
+    void clearSegments() { m_segments.clear(); }
     bool adjustLogicalLineTop(float minSegmentWidth);
     LayoutUnit computeFirstFitPositionForFloat(const LayoutSize) const;
 
@@ -131,6 +140,7 @@ private:
 
     SegmentRangeList m_segmentRanges;
     bool m_needsLayout:1;
+    SegmentList m_segments;
 };
 
 }
index 9ff0a3c..077920a 100644 (file)
@@ -54,27 +54,28 @@ bool ShapeOutsideInfo::isEnabledFor(const RenderBox* box)
     }
 }
 
-bool ShapeOutsideInfo::computeSegmentsForContainingBlockLine(const RenderBlock* containingBlock, const FloatingObject* floatingObject, LayoutUnit lineTop, LayoutUnit lineHeight)
+void ShapeOutsideInfo::updateDeltasForContainingBlockLine(const RenderBlock* containingBlock, const FloatingObject* floatingObject, LayoutUnit lineTop, LayoutUnit lineHeight)
 {
     LayoutUnit shapeTop = floatingObject->logicalTop(containingBlock->isHorizontalWritingMode()) + std::max(LayoutUnit(), containingBlock->marginBeforeForChild(m_renderer));
     LayoutUnit lineTopInShapeCoordinates = lineTop - shapeTop + logicalTopOffset();
-    return updateSegmentsForLine(lineTopInShapeCoordinates, lineHeight);
-}
 
-bool ShapeOutsideInfo::updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight)
-{
-    if (shapeSizeDirty() || m_lineTop != lineTop || m_lineHeight != lineHeight) {
-        if (ShapeInfo<RenderBox>::updateSegmentsForLine(lineTop, lineHeight)) {
-            m_leftSegmentMarginBoxDelta = m_segments[0].logicalLeft + m_renderer->marginStart();
-            m_rightSegmentMarginBoxDelta = m_segments[m_segments.size()-1].logicalRight - m_renderer->logicalWidth() - m_renderer->marginEnd();
-        } else {
-            m_leftSegmentMarginBoxDelta = m_renderer->logicalWidth() + m_renderer->marginStart();
-            m_rightSegmentMarginBoxDelta = -m_renderer->logicalWidth() - m_renderer->marginEnd();
+    if (shapeSizeDirty() || m_lineTop != lineTopInShapeCoordinates || m_lineHeight != lineHeight) {
+        m_lineTop = lineTopInShapeCoordinates;
+        m_shapeLineTop = lineTopInShapeCoordinates - logicalTopOffset();
+        m_lineHeight = lineHeight;
+
+        if (lineOverlapsShapeBounds()) {
+            SegmentList segments = computeSegmentsForLine(lineTopInShapeCoordinates, lineHeight);
+            if (segments.size()) {
+                m_leftMarginBoxDelta = segments[0].logicalLeft + m_renderer->marginStart();
+                m_rightMarginBoxDelta = segments[segments.size()-1].logicalRight - m_renderer->logicalWidth() - m_renderer->marginEnd();
+                return;
+            }
         }
-        m_lineTop = lineTop;
-    }
 
-    return m_segments.size();
+        m_leftMarginBoxDelta = m_renderer->logicalWidth() + m_renderer->marginStart();
+        m_rightMarginBoxDelta = -m_renderer->logicalWidth() - m_renderer->marginEnd();
+    }
 }
 
 ShapeValue* ShapeOutsideInfo::shapeValue() const
index 34fe7a6..6a39fa7 100644 (file)
@@ -43,11 +43,10 @@ class FloatingObject;
 
 class ShapeOutsideInfo FINAL : public ShapeInfo<RenderBox>, public MappedInfo<RenderBox, ShapeOutsideInfo> {
 public:
-    LayoutUnit leftSegmentMarginBoxDelta() const { return m_leftSegmentMarginBoxDelta; }
-    LayoutUnit rightSegmentMarginBoxDelta() const { return m_rightSegmentMarginBoxDelta; }
+    LayoutUnit leftMarginBoxDelta() const { return m_leftMarginBoxDelta; }
+    LayoutUnit rightMarginBoxDelta() const { return m_rightMarginBoxDelta; }
 
-    bool computeSegmentsForContainingBlockLine(const RenderBlock*, const FloatingObject*, LayoutUnit lineTop, LayoutUnit lineHeight);
-    virtual bool updateSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) OVERRIDE;
+    void updateDeltasForContainingBlockLine(const RenderBlock*, const FloatingObject*, LayoutUnit lineTop, LayoutUnit lineHeight);
 
     static PassOwnPtr<ShapeOutsideInfo> createInfo(const RenderBox* renderer) { return adoptPtr(new ShapeOutsideInfo(renderer)); }
     static bool isEnabledFor(const RenderBox*);
@@ -69,8 +68,8 @@ protected:
 private:
     ShapeOutsideInfo(const RenderBox* renderer) : ShapeInfo<RenderBox>(renderer) { }
 
-    LayoutUnit m_leftSegmentMarginBoxDelta;
-    LayoutUnit m_rightSegmentMarginBoxDelta;
+    LayoutUnit m_leftMarginBoxDelta;
+    LayoutUnit m_rightMarginBoxDelta;
     LayoutUnit m_lineTop;
 };