2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include "core/rendering/shapes/ShapeInfo.h"
33 #include "core/rendering/RenderBlock.h"
34 #include "core/rendering/RenderImage.h"
38 bool checkShapeImageOrigin(Document& document, ImageResource& imageResource)
40 if (imageResource.isAccessAllowed(document.securityOrigin()))
43 const KURL& url = imageResource.url();
44 String urlString = url.isNull() ? "''" : url.elidedString();
45 document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Unsafe attempt to load URL " + urlString + ".");
50 static LayoutRect getShapeImageRect(const StyleImage& styleImage, const RenderBox* renderBox)
52 if (renderBox->isRenderImage())
53 return toRenderImage(renderBox)->replacedContentRect();
55 ASSERT(styleImage.cachedImage());
56 ASSERT(styleImage.cachedImage()->hasImage());
57 return LayoutRect(LayoutPoint(), styleImage.cachedImage()->image()->size());
60 template<class RenderType>
61 const Shape* ShapeInfo<RenderType>::computedShape() const
63 if (Shape* shape = m_shape.get())
66 WritingMode writingMode = m_renderer->style()->writingMode();
67 Length margin = m_renderer->style()->shapeMargin();
68 Length padding = m_renderer->style()->shapePadding();
69 float shapeImageThreshold = m_renderer->style()->shapeImageThreshold();
70 const ShapeValue* shapeValue = this->shapeValue();
73 switch (shapeValue->type()) {
74 case ShapeValue::Shape:
75 ASSERT(shapeValue->shape());
76 m_shape = Shape::createShape(shapeValue->shape(), m_shapeLogicalSize, writingMode, margin, padding);
78 case ShapeValue::Image: {
79 ASSERT(shapeValue->image());
80 const StyleImage& styleImage = *(shapeValue->image());
81 m_shape = Shape::createRasterShape(styleImage, shapeImageThreshold, getShapeImageRect(styleImage, m_renderer), m_shapeLogicalSize, writingMode, margin, padding);
84 case ShapeValue::Box: {
85 const RoundedRect& shapeRect = m_renderer->style()->getRoundedBorderFor(LayoutRect(LayoutPoint(), m_shapeLogicalSize), m_renderer->view());
86 m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin, padding);
89 case ShapeValue::Outside:
90 // Outside should have already resolved to a different shape value.
98 template<class RenderType>
99 SegmentList ShapeInfo<RenderType>::computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight) const
101 ASSERT(lineHeight >= 0);
102 SegmentList segments;
104 getIntervals((lineTop - logicalTopOffset()), std::min(lineHeight, shapeLogicalBottom() - lineTop), segments);
106 for (size_t i = 0; i < segments.size(); i++) {
107 segments[i].logicalLeft += logicalLeftOffset();
108 segments[i].logicalRight += logicalLeftOffset();
114 template class ShapeInfo<RenderBlock>;
115 template class ShapeInfo<RenderBox>;