[CSS Shapes] Remove unnecessarily complex template from ShapeInfo classes
authorbjonesbe@adobe.com <bjonesbe@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Sep 2013 16:50:36 +0000 (16:50 +0000)
committerbjonesbe@adobe.com <bjonesbe@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Sep 2013 16:50:36 +0000 (16:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121213

Reviewed by Darin Adler.

These classes were trying to be way too clever, and as a result were
hard to read and hard to debug. Replace the complex templated method
calls with virtual methods to make these classes much easier to
understand and maintain.

No new tests, no behavior change.

* rendering/shapes/ShapeInfo.cpp:
(WebCore::::computedShape):
(WebCore::::computeSegmentsForLine):
* rendering/shapes/ShapeInfo.h:
* rendering/shapes/ShapeInsideInfo.cpp:
(WebCore::ShapeInsideInfo::getShapeValue):
* rendering/shapes/ShapeInsideInfo.h:
(WebCore::ShapeInsideInfo::computeSegmentsForLine):
(WebCore::ShapeInsideInfo::ShapeInsideInfo):
* rendering/shapes/ShapeOutsideInfo.cpp:
(WebCore::ShapeOutsideInfo::computeSegmentsForLine):
(WebCore::ShapeOutsideInfo::getShapeValue):
* rendering/shapes/ShapeOutsideInfo.h:
(WebCore::ShapeOutsideInfo::ShapeOutsideInfo):

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

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

index f5d17cb..7c1bddf 100644 (file)
@@ -1,3 +1,32 @@
+2013-09-12  Bem Jones-Bey  <bjonesbe@adobe.com>
+
+        [CSS Shapes] Remove unnecessarily complex template from ShapeInfo classes
+        https://bugs.webkit.org/show_bug.cgi?id=121213
+
+        Reviewed by Darin Adler.
+
+        These classes were trying to be way too clever, and as a result were
+        hard to read and hard to debug. Replace the complex templated method
+        calls with virtual methods to make these classes much easier to
+        understand and maintain.
+
+        No new tests, no behavior change.
+
+        * rendering/shapes/ShapeInfo.cpp:
+        (WebCore::::computedShape):
+        (WebCore::::computeSegmentsForLine):
+        * rendering/shapes/ShapeInfo.h:
+        * rendering/shapes/ShapeInsideInfo.cpp:
+        (WebCore::ShapeInsideInfo::getShapeValue):
+        * rendering/shapes/ShapeInsideInfo.h:
+        (WebCore::ShapeInsideInfo::computeSegmentsForLine):
+        (WebCore::ShapeInsideInfo::ShapeInsideInfo):
+        * rendering/shapes/ShapeOutsideInfo.cpp:
+        (WebCore::ShapeOutsideInfo::computeSegmentsForLine):
+        (WebCore::ShapeOutsideInfo::getShapeValue):
+        * rendering/shapes/ShapeOutsideInfo.h:
+        (WebCore::ShapeOutsideInfo::ShapeOutsideInfo):
+
 2013-09-12  Zoltan Horvath  <zoltan@webkit.org>
 
         [CSS Shapes] Turn shape's logicalwidth/height into a LayoutSize
index 6453168..a9cfeb5 100644 (file)
@@ -39,8 +39,8 @@
 #include "Shape.h"
 
 namespace WebCore {
-template<class RenderType, ShapeValue* (RenderStyle::*shapeGetter)() const, void (Shape::*intervalGetter)(LayoutUnit, LayoutUnit, SegmentList&) const>
-const Shape* ShapeInfo<RenderType, shapeGetter, intervalGetter>::computedShape() const
+template<class RenderType>
+const Shape* ShapeInfo<RenderType>::computedShape() const
 {
     if (Shape* shape = m_shape.get())
         return shape;
@@ -48,7 +48,7 @@ const Shape* ShapeInfo<RenderType, shapeGetter, intervalGetter>::computedShape()
     WritingMode writingMode = m_renderer->style()->writingMode();
     Length margin = m_renderer->style()->shapeMargin();
     Length padding = m_renderer->style()->shapePadding();
-    const ShapeValue* shapeValue = (m_renderer->style()->*shapeGetter)();
+    const ShapeValue* shapeValue = this->shapeValue();
     ASSERT(shapeValue);
 
     switch (shapeValue->type()) {
@@ -68,8 +68,8 @@ const Shape* ShapeInfo<RenderType, shapeGetter, intervalGetter>::computedShape()
     return m_shape.get();
 }
 
-template<class RenderType, ShapeValue* (RenderStyle::*shapeGetter)() const, void (Shape::*intervalGetter)(LayoutUnit, LayoutUnit, SegmentList&) const>
-bool ShapeInfo<RenderType, shapeGetter, intervalGetter>::computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight)
+template<class RenderType>
+bool ShapeInfo<RenderType>::computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight)
 {
     ASSERT(lineHeight >= 0);
     m_shapeLineTop = lineTop - logicalTopOffset();
@@ -77,7 +77,7 @@ bool ShapeInfo<RenderType, shapeGetter, intervalGetter>::computeSegmentsForLine(
     m_segments.clear();
 
     if (lineOverlapsShapeBounds())
-        (computedShape()->*intervalGetter)(m_shapeLineTop, std::min(m_lineHeight, shapeLogicalBottom() - lineTop), m_segments);
+        getIntervals(m_shapeLineTop, std::min(m_lineHeight, shapeLogicalBottom() - lineTop), m_segments);
 
     LayoutUnit logicalLeftOffset = this->logicalLeftOffset();
     for (size_t i = 0; i < m_segments.size(); i++) {
@@ -88,7 +88,7 @@ bool ShapeInfo<RenderType, shapeGetter, intervalGetter>::computeSegmentsForLine(
     return m_segments.size();
 }
 
-template class ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals>;
-template class ShapeInfo<RenderBox, &RenderStyle::shapeOutside, &Shape::getExcludedIntervals>;
+template class ShapeInfo<RenderBlock>;
+template class ShapeInfo<RenderBox>;
 }
 #endif
index e4e9073..b5d80b7 100644 (file)
@@ -64,7 +64,7 @@ private:
     }
 };
 
-template<class RenderType, ShapeValue* (RenderStyle::*shapeGetter)() const, void (Shape::*intervalGetter)(LayoutUnit, LayoutUnit, SegmentList&) const>
+template<class RenderType>
 class ShapeInfo {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -109,6 +109,8 @@ protected:
 
     const Shape* computedShape() const;
     virtual LayoutRect computedShapeLogicalBoundingBox() const = 0;
+    virtual ShapeValue* shapeValue() const = 0;
+    virtual void getIntervals(LayoutUnit, LayoutUnit, SegmentList&) const = 0;
 
     LayoutUnit logicalTopOffset() const { return m_renderer->style()->boxSizing() == CONTENT_BOX ? m_renderer->borderAndPaddingBefore() : LayoutUnit(); };
     LayoutUnit logicalLeftOffset() const { return (m_renderer->style()->boxSizing() == CONTENT_BOX && !m_renderer->isRenderRegion()) ? m_renderer->borderAndPaddingStart() : LayoutUnit(); }
index 1c8e113..cbef94c 100644 (file)
@@ -76,5 +76,10 @@ bool ShapeInsideInfo::adjustLogicalLineTop(float minSegmentWidth)
     return false;
 }
 
+ShapeValue* ShapeInsideInfo::shapeValue() const
+{
+    return m_renderer->style()->resolvedShapeInside();
+}
+
 }
 #endif
index 44a74cc..c9c2720 100644 (file)
@@ -62,7 +62,7 @@ struct LineSegmentRange {
 
 typedef Vector<LineSegmentRange> SegmentRangeList;
 
-class ShapeInsideInfo : public ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals> {
+class ShapeInsideInfo FINAL : public ShapeInfo<RenderBlock> { 
 public:
     static PassOwnPtr<ShapeInsideInfo> createInfo(const RenderBlock* renderer) { return adoptPtr(new ShapeInsideInfo(renderer)); }
 
@@ -71,7 +71,7 @@ public:
     bool computeSegmentsForLine(LayoutSize lineOffset, LayoutUnit lineHeight)
     {
         m_segmentRanges.clear();
-        bool result = ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals>::computeSegmentsForLine(lineOffset.height(), lineHeight);
+        bool result = ShapeInfo<RenderBlock>::computeSegmentsForLine(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();
@@ -82,7 +82,7 @@ public:
     virtual bool computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) OVERRIDE
     {
         m_segmentRanges.clear();
-        return ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals>::computeSegmentsForLine(lineTop, lineHeight);
+        return ShapeInfo<RenderBlock>::computeSegmentsForLine(lineTop, lineHeight);
     }
 
     bool hasSegments() const
@@ -110,10 +110,15 @@ public:
 
 protected:
     virtual LayoutRect computedShapeLogicalBoundingBox() const OVERRIDE { return computedShape()->shapePaddingLogicalBoundingBox(); }
+    virtual ShapeValue* shapeValue() const OVERRIDE;
+    virtual void getIntervals(LayoutUnit lineTop, LayoutUnit lineHeight, SegmentList& segments) const OVERRIDE
+    {
+        return computedShape()->getIncludedIntervals(lineTop, lineHeight, segments);
+    }
 
 private:
     ShapeInsideInfo(const RenderBlock* renderer)
-    : ShapeInfo<RenderBlock, &RenderStyle::resolvedShapeInside, &Shape::getIncludedIntervals> (renderer)
+    : ShapeInfo<RenderBlock> (renderer)
     , m_needsLayout(false)
     { }
 
index 06c7908..ec0d3ec 100644 (file)
@@ -61,7 +61,7 @@ bool ShapeOutsideInfo::computeSegmentsForContainingBlockLine(LayoutUnit lineTop,
 bool ShapeOutsideInfo::computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight)
 {
     if (shapeSizeDirty() || m_lineTop != lineTop || m_lineHeight != lineHeight) {
-        if (ShapeInfo<RenderBox, &RenderStyle::shapeOutside, &Shape::getExcludedIntervals>::computeSegmentsForLine(lineTop, lineHeight)) {
+        if (ShapeInfo<RenderBox>::computeSegmentsForLine(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 {
@@ -74,5 +74,10 @@ bool ShapeOutsideInfo::computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lin
     return m_segments.size();
 }
 
+ShapeValue* ShapeOutsideInfo::shapeValue() const
+{
+    return m_renderer->style()->shapeOutside();
+}
+
 }
 #endif
index 685b0f9..76b220e 100644 (file)
@@ -39,7 +39,7 @@ namespace WebCore {
 
 class RenderBox;
 
-class ShapeOutsideInfo : public ShapeInfo<RenderBox, &RenderStyle::shapeOutside, &Shape::getExcludedIntervals>, public MappedInfo<RenderBox, ShapeOutsideInfo> {
+class ShapeOutsideInfo FINAL : public ShapeInfo<RenderBox>, public MappedInfo<RenderBox, ShapeOutsideInfo> {
 public:
     LayoutUnit leftSegmentMarginBoxDelta() const { return m_leftSegmentMarginBoxDelta; }
     LayoutUnit rightSegmentMarginBoxDelta() const { return m_rightSegmentMarginBoxDelta; }
@@ -52,9 +52,14 @@ public:
 
 protected:
     virtual LayoutRect computedShapeLogicalBoundingBox() const OVERRIDE { return computedShape()->shapeMarginLogicalBoundingBox(); }
+    virtual ShapeValue* shapeValue() const OVERRIDE;
+    virtual void getIntervals(LayoutUnit lineTop, LayoutUnit lineHeight, SegmentList& segments) const OVERRIDE
+    {
+        return computedShape()->getExcludedIntervals(lineTop, lineHeight, segments);
+    }
 
 private:
-    ShapeOutsideInfo(const RenderBox* renderer) : ShapeInfo<RenderBox, &RenderStyle::shapeOutside, &Shape::getExcludedIntervals>(renderer) { }
+    ShapeOutsideInfo(const RenderBox* renderer) : ShapeInfo<RenderBox>(renderer) { }
 
     LayoutUnit m_leftSegmentMarginBoxDelta;
     LayoutUnit m_rightSegmentMarginBoxDelta;