#ifndef ShapeInfo_h
#define ShapeInfo_h
#if ENABLE(CSS_SHAPES)
#include "FloatRect.h"
#include "LayoutUnit.h"
#include "RenderStyle.h"
#include "Shape.h"
#include "ShapeValue.h"
#include <wtf/OwnPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
template<class KeyType, class InfoType>
class MappedInfo {
public:
static InfoType* ensureInfo(const KeyType* key)
{
InfoMap& infoMap = MappedInfo<KeyType, InfoType>::infoMap();
if (InfoType* info = infoMap.get(key))
return info;
typename InfoMap::AddResult result = infoMap.add(key, InfoType::createInfo(key));
return result.iterator->value.get();
}
static void removeInfo(const KeyType* key) { infoMap().remove(key); }
static InfoType* info(const KeyType* key) { return infoMap().get(key); }
private:
typedef HashMap<const KeyType*, OwnPtr<InfoType> > InfoMap;
static InfoMap& infoMap()
{
DEFINE_STATIC_LOCAL(InfoMap, staticInfoMap, ());
return staticInfoMap;
}
};
template<class RenderType, ShapeValue* (RenderStyle::*shapeGetter)() const, void (Shape::*intervalGetter)(LayoutUnit, LayoutUnit, SegmentList&) const>
class ShapeInfo {
WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~ShapeInfo() { }
void setShapeSize(LayoutUnit logicalWidth, LayoutUnit logicalHeight)
{
if (m_renderer->style()->boxSizing() == CONTENT_BOX) {
logicalWidth -= m_renderer->borderAndPaddingLogicalWidth();
logicalHeight -= m_renderer->borderAndPaddingLogicalHeight();
}
if (m_shapeLogicalWidth == logicalWidth && m_shapeLogicalHeight == logicalHeight)
return;
dirtyShapeSize();
m_shapeLogicalWidth = logicalWidth;
m_shapeLogicalHeight = logicalHeight;
}
virtual bool computeSegmentsForLine(LayoutUnit lineTop, LayoutUnit lineHeight);
void clearSegments() { m_segments.clear(); }
LayoutUnit shapeLogicalTop() const { return computedShapeLogicalBoundingBox().y() + logicalTopOffset(); }
LayoutUnit shapeLogicalBottom() const { return computedShapeLogicalBoundingBox().maxY() + logicalTopOffset(); }
LayoutUnit shapeLogicalLeft() const { return computedShapeLogicalBoundingBox().x() + logicalLeftOffset(); }
LayoutUnit shapeLogicalRight() const { return computedShapeLogicalBoundingBox().maxX() + logicalLeftOffset(); }
LayoutUnit shapeLogicalWidth() const { return computedShapeLogicalBoundingBox().width(); }
LayoutUnit shapeLogicalHeight() const { return computedShapeLogicalBoundingBox().height(); }
LayoutUnit logicalLineTop() const { return m_shapeLineTop + logicalTopOffset(); }
LayoutUnit logicalLineBottom() const { return m_shapeLineTop + m_lineHeight + logicalTopOffset(); }
LayoutUnit shapeContainingBlockHeight() const { return (m_renderer->style()->boxSizing() == CONTENT_BOX) ? (m_shapeLogicalHeight + m_renderer->borderAndPaddingLogicalHeight()) : m_shapeLogicalHeight; }
bool lineOverlapsShapeBounds() const { return logicalLineTop() < shapeLogicalBottom() && shapeLogicalTop() <= logicalLineBottom(); }
bool lineWithinShapeBounds() const { return lineOverlapsShapeBounds() && (logicalLineBottom() <= shapeLogicalBottom()); }
void dirtyShapeSize() { m_shape.clear(); }
bool shapeSizeDirty() { return !m_shape.get(); }
const RenderType* owner() const { return m_renderer; }
protected:
ShapeInfo(const RenderType* renderer): m_renderer(renderer) { }
const Shape* computedShape() const;
virtual LayoutRect computedShapeLogicalBoundingBox() 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(); }
LayoutUnit m_shapeLineTop;
LayoutUnit m_lineHeight;
SegmentList m_segments;
private:
mutable OwnPtr<Shape> m_shape;
LayoutUnit m_shapeLogicalWidth;
LayoutUnit m_shapeLogicalHeight;
const RenderType* m_renderer;
};
}
#endif
#endif