#ifndef GridPosition_h
#define GridPosition_h
#include "wtf/text/WTFString.h"
namespace WebCore {
enum GridPositionType {
AutoPosition,
ExplicitPosition,
SpanPosition,
NamedGridAreaPosition
};
enum GridPositionSide {
ColumnStartSide,
ColumnEndSide,
RowStartSide,
RowEndSide
};
class GridPosition {
public:
GridPosition()
: m_type(AutoPosition)
, m_integerPosition(0)
{
}
static size_t adjustGridPositionForAfterEndSide(size_t resolvedPosition)
{
return resolvedPosition ? resolvedPosition - 1 : 0;
}
static size_t adjustGridPositionForSide(size_t resolvedPosition, GridPositionSide side)
{
if (side == ColumnEndSide || side == RowEndSide)
return adjustGridPositionForAfterEndSide(resolvedPosition);
return resolvedPosition;
}
bool isPositive() const { return integerPosition() > 0; }
GridPositionType type() const { return m_type; }
bool isAuto() const { return m_type == AutoPosition; }
bool isSpan() const { return m_type == SpanPosition; }
bool isNamedGridArea() const { return m_type == NamedGridAreaPosition; }
void setExplicitPosition(int position, const String& namedGridLine)
{
m_type = ExplicitPosition;
m_integerPosition = position;
m_namedGridLine = namedGridLine;
}
void setAutoPosition()
{
m_type = AutoPosition;
m_integerPosition = 0;
}
void setSpanPosition(int position, const String& namedGridLine)
{
m_type = SpanPosition;
m_integerPosition = position;
m_namedGridLine = namedGridLine;
}
void setNamedGridArea(const String& namedGridArea)
{
m_type = NamedGridAreaPosition;
m_namedGridLine = namedGridArea;
}
int integerPosition() const
{
ASSERT(type() == ExplicitPosition);
return m_integerPosition;
}
String namedGridLine() const
{
ASSERT(type() == ExplicitPosition || type() == SpanPosition || type() == NamedGridAreaPosition);
return m_namedGridLine;
}
int spanPosition() const
{
ASSERT(type() == SpanPosition);
return m_integerPosition;
}
bool operator==(const GridPosition& other) const
{
return m_type == other.m_type && m_integerPosition == other.m_integerPosition && m_namedGridLine == other.m_namedGridLine;
}
bool shouldBeResolvedAgainstOppositePosition() const
{
return isAuto() || isSpan();
}
private:
GridPositionType m_type;
int m_integerPosition;
String m_namedGridLine;
};
}
#endif