#ifndef GridTrackSize_h
#define GridTrackSize_h
#include "core/rendering/style/GridLength.h"
namespace WebCore {
enum GridTrackSizeType {
LengthTrackSizing,
MinMaxTrackSizing
};
class GridTrackSize {
public:
GridTrackSize(const GridLength& length)
: m_type(LengthTrackSizing)
, m_minTrackBreadth(length)
, m_maxTrackBreadth(length)
, m_minTrackBreadthIsMinOrMaxContent(false)
, m_minTrackBreadthIsMaxContent(false)
, m_maxTrackBreadthIsMinOrMaxContent(false)
, m_maxTrackBreadthIsMaxContent(false)
{
cacheMinMaxTrackBreadthTypes();
}
GridTrackSize(const GridLength& minTrackBreadth, const GridLength& maxTrackBreadth)
: m_type(MinMaxTrackSizing)
, m_minTrackBreadth(minTrackBreadth)
, m_maxTrackBreadth(maxTrackBreadth)
, m_minTrackBreadthIsMinOrMaxContent(false)
, m_minTrackBreadthIsMaxContent(false)
, m_maxTrackBreadthIsMinOrMaxContent(false)
, m_maxTrackBreadthIsMaxContent(false)
{
cacheMinMaxTrackBreadthTypes();
}
const GridLength& length() const
{
ASSERT(m_type == LengthTrackSizing);
ASSERT(m_minTrackBreadth == m_maxTrackBreadth);
const GridLength& minTrackBreadth = m_minTrackBreadth;
return minTrackBreadth;
}
const GridLength& minTrackBreadth() const
{
if (m_minTrackBreadth.isLength() && m_minTrackBreadth.length().isAuto()) {
DEFINE_STATIC_LOCAL(GridLength, minContent, (Length(MinContent)));
return minContent;
}
return m_minTrackBreadth;
}
const GridLength& maxTrackBreadth() const
{
if (m_maxTrackBreadth.isLength() && m_maxTrackBreadth.length().isAuto()) {
DEFINE_STATIC_LOCAL(GridLength, maxContent, (Length(MaxContent)));
return maxContent;
}
return m_maxTrackBreadth;
}
GridTrackSizeType type() const { return m_type; }
bool isContentSized() const { return m_minTrackBreadth.isContentSized() || m_maxTrackBreadth.isContentSized(); }
bool isPercentage() const { return m_type == LengthTrackSizing && length().isLength() && length().length().isPercent(); }
bool operator==(const GridTrackSize& other) const
{
return m_type == other.m_type && m_minTrackBreadth == other.m_minTrackBreadth && m_maxTrackBreadth == other.m_maxTrackBreadth;
}
void cacheMinMaxTrackBreadthTypes()
{
m_minTrackBreadthIsMaxContent = minTrackBreadth().isLength() && minTrackBreadth().length().isMaxContent();
m_minTrackBreadthIsMinOrMaxContent = m_minTrackBreadthIsMaxContent || (minTrackBreadth().isLength() && minTrackBreadth().length().isMinContent());
m_maxTrackBreadthIsMaxContent = maxTrackBreadth().isLength() && maxTrackBreadth().length().isMaxContent();
m_maxTrackBreadthIsMinOrMaxContent = m_maxTrackBreadthIsMaxContent || (maxTrackBreadth().isLength() && maxTrackBreadth().length().isMinContent());
}
bool hasMinOrMaxContentMinTrackBreadth() const { return m_minTrackBreadthIsMinOrMaxContent; }
bool hasMaxContentMinTrackBreadth() const { return m_minTrackBreadthIsMaxContent; }
bool hasMinOrMaxContentMaxTrackBreadth() const { return m_maxTrackBreadthIsMinOrMaxContent; }
bool hasMaxContentMaxTrackBreadth() const { return m_maxTrackBreadthIsMaxContent; }
private:
GridTrackSizeType m_type;
GridLength m_minTrackBreadth;
GridLength m_maxTrackBreadth;
bool m_minTrackBreadthIsMinOrMaxContent;
bool m_minTrackBreadthIsMaxContent;
bool m_maxTrackBreadthIsMinOrMaxContent;
bool m_maxTrackBreadthIsMaxContent;
};
}
#endif