#ifndef Shape_h
#define Shape_h
#include "LayoutRect.h"
#include "Path.h"
#include "WritingMode.h"
namespace WebCore {
struct LineSegment {
LineSegment()
: logicalLeft(0)
, logicalRight(0)
, isValid(false)
{
}
LineSegment(float logicalLeft, float logicalRight)
: logicalLeft(logicalLeft)
, logicalRight(logicalRight)
, isValid(true)
{
}
float logicalLeft;
float logicalRight;
bool isValid;
};
class BasicShape;
class Image;
class RoundedRect;
class Shape {
WTF_MAKE_FAST_ALLOCATED;
public:
struct DisplayPaths {
Path shape;
Path marginShape;
};
static std::unique_ptr<Shape> createShape(const BasicShape&, const LayoutSize& logicalBoxSize, WritingMode, float margin);
static std::unique_ptr<Shape> createRasterShape(Image*, float threshold, const LayoutRect& imageRect, const LayoutRect& marginRect, WritingMode, float margin);
static std::unique_ptr<Shape> createBoxShape(const RoundedRect&, WritingMode, float margin);
virtual ~Shape() { }
virtual LayoutRect shapeMarginLogicalBoundingBox() const = 0;
virtual bool isEmpty() const = 0;
virtual LineSegment getExcludedInterval(LayoutUnit logicalTop, LayoutUnit logicalHeight) const = 0;
bool lineOverlapsShapeMarginBounds(LayoutUnit lineTop, LayoutUnit lineHeight) const { return lineOverlapsBoundingBox(lineTop, lineHeight, shapeMarginLogicalBoundingBox()); }
virtual void buildDisplayPaths(DisplayPaths&) const = 0;
protected:
float shapeMargin() const { return m_margin; }
private:
bool lineOverlapsBoundingBox(LayoutUnit lineTop, LayoutUnit lineHeight, const LayoutRect& rect) const
{
if (rect.isEmpty())
return false;
return (lineTop < rect.maxY() && lineTop + lineHeight > rect.y()) || (!lineHeight && lineTop == rect.y());
}
WritingMode m_writingMode;
float m_margin;
};
}
#endif // Shape_h