[CSS Shapes] Image valued shape size and position should conform to the spec
[WebKit-https.git] / Source / WebCore / rendering / shapes / ShapeInfo.cpp
index c77cd1c..5e2af92 100644 (file)
 
 #if ENABLE(CSS_SHAPES)
 
+#include "LengthFunctions.h"
 #include "RenderBlock.h"
 #include "RenderBox.h"
+#include "RenderImage.h"
 #include "RenderRegion.h"
 #include "RenderStyle.h"
 #include "Shape.h"
 
 namespace WebCore {
+
+
+bool checkShapeImageOrigin(Document& document, CachedImage& cachedImage)
+{
+    if (cachedImage.isOriginClean(document.securityOrigin()))
+        return true;
+
+    const URL& url = cachedImage.url();
+    String urlString = url.isNull() ? "''" : url.stringCenterEllipsizedToLength();
+    document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Unsafe attempt to load URL " + urlString + ".");
+
+    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
+const Shape& ShapeInfo<RenderType>::computedShape() const
 {
     if (Shape* shape = m_shape.get())
-        return shape;
+        return *shape;
 
-    WritingMode writingMode = m_renderer->style()->writingMode();
-    Length margin = m_renderer->style()->shapeMargin();
-    Length padding = m_renderer->style()->shapePadding();
-    float shapeImageThreshold = m_renderer->style()->shapeImageThreshold();
+    WritingMode writingMode = this->writingMode();
+    Length margin = m_renderer.style().shapeMargin();
+    Length padding = m_renderer.style().shapePadding();
+    float shapeImageThreshold = m_renderer.style().shapeImageThreshold();
     const ShapeValue* shapeValue = this->shapeValue();
     ASSERT(shapeValue);
 
@@ -57,16 +85,24 @@ 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;
-    default:
+    }
+    case ShapeValue::Box: {
+        const RoundedRect& shapeRect = m_renderer.style().getRoundedBorderFor(LayoutRect(LayoutPoint(), m_shapeLogicalSize), &(m_renderer.view()));
+        m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin, padding);
+        break;
+    }
+    case ShapeValue::Outside:
+        // Outside should have already resolved to a different shape value
         ASSERT_NOT_REACHED();
     }
 
     ASSERT(m_shape);
-    return m_shape.get();
+    return *m_shape;
 }
 
 template<class RenderType>
@@ -87,5 +123,6 @@ SegmentList ShapeInfo<RenderType>::computeSegmentsForLine(LayoutUnit lineTop, La
 
 template class ShapeInfo<RenderBlock>;
 template class ShapeInfo<RenderBox>;
+
 }
 #endif