#pragma once
#include "LayoutUnit.h"
#include "Length.h"
namespace WebCore {
class FloatSize;
class FloatPoint;
class LayoutSize;
struct Length;
struct LengthSize;
struct LengthPoint;
int intValueForLength(const Length&, LayoutUnit maximumValue);
float floatValueForLength(const Length&, LayoutUnit maximumValue);
WEBCORE_EXPORT float floatValueForLength(const Length&, float maximumValue);
WEBCORE_EXPORT LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue);
LayoutSize sizeForLengthSize(const LengthSize&, const LayoutSize& maximumValue);
FloatSize floatSizeForLengthSize(const LengthSize&, const FloatSize& maximumValue);
LayoutPoint pointForLengthPoint(const LengthPoint&, const LayoutSize& maximumValue);
FloatPoint floatPointForLengthPoint(const LengthPoint&, const FloatSize& maximumValue);
inline LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue)
{
switch (length.type()) {
case Fixed:
return LayoutUnit(length.value());
case Percent:
return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 100.0f));
case Calculated:
return LayoutUnit(length.nonNanCalculatedValue(maximumValue));
case FillAvailable:
case Auto:
return 0;
case Relative:
case Intrinsic:
case MinIntrinsic:
case MinContent:
case MaxContent:
case FitContent:
case Undefined:
break;
}
ASSERT_NOT_REACHED();
return 0;
}
inline int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue)
{
return static_cast<int>(minimumValueForLength(length, maximumValue));
}
template<typename T> inline LayoutUnit valueForLength(const Length& length, T maximumValue) { return valueForLength(length, LayoutUnit(maximumValue)); }
template<typename T> inline LayoutUnit minimumValueForLength(const Length& length, T maximumValue) { return minimumValueForLength(length, LayoutUnit(maximumValue)); }
}