[CSS Shapes] Image valued shape size and position should conform to the spec
[WebKit-https.git] / Source / WebCore / rendering / shapes / ShapeInfo.cpp
index 0a5ec5a..5e2af92 100644 (file)
@@ -35,6 +35,7 @@
 #include "LengthFunctions.h"
 #include "RenderBlock.h"
 #include "RenderBox.h"
+#include "RenderImage.h"
 #include "RenderRegion.h"
 #include "RenderStyle.h"
 #include "Shape.h"
@@ -54,6 +55,18 @@ bool checkShapeImageOrigin(Document& document, CachedImage& cachedImage)
     return false;
 }
 
+static LayoutRect getShapeImageRect(const StyleImage& styleImage, const RenderBox& renderBox)
+{
+    if (renderBox.isRenderImage()) {
+        const RenderImage& renderImage = *toRenderImage(&renderBox);
+        return renderImage.replacedContentRect(renderBox.intrinsicSize());
+    }
+
+    ASSERT(styleImage.cachedImage());
+    ASSERT(styleImage.cachedImage()->hasImage());
+    return LayoutRect(LayoutPoint(), styleImage.cachedImage()->image()->size());
+}
+
 template<class RenderType>
 const Shape& ShapeInfo<RenderType>::computedShape() const
 {
@@ -72,14 +85,15 @@ const Shape& ShapeInfo<RenderType>::computedShape() const
         ASSERT(shapeValue->shape());
         m_shape = Shape::createShape(shapeValue->shape(), m_shapeLogicalSize, writingMode, margin, padding);
         break;
-    case ShapeValue::Image:
+    case ShapeValue::Image: {
         ASSERT(shapeValue->image());
-        m_shape = Shape::createShape(shapeValue->image(), shapeImageThreshold, m_shapeLogicalSize, writingMode, margin, padding);
+        const StyleImage& styleImage = *(shapeValue->image());
+        m_shape = Shape::createRasterShape(styleImage, shapeImageThreshold, getShapeImageRect(styleImage, m_renderer), m_shapeLogicalSize, writingMode, margin, padding);
         break;
+    }
     case ShapeValue::Box: {
-        ASSERT(shapeValue->box());
         const RoundedRect& shapeRect = m_renderer.style().getRoundedBorderFor(LayoutRect(LayoutPoint(), m_shapeLogicalSize), &(m_renderer.view()));
-        m_shape = Shape::createShape(shapeRect, writingMode, margin, padding);
+        m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin, padding);
         break;
     }
     case ShapeValue::Outside: