LengthFunctions.cpp [plain text]
#include "config.h"
#include "LengthFunctions.h"
#include "FloatSize.h"
#include "LayoutUnit.h"
#include "LengthSize.h"
namespace WebCore {
int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages)
{
return static_cast<int>(minimumValueForLength(length, maximumValue, roundPercentages));
}
int intValueForLength(const Length& length, LayoutUnit maximumValue)
{
return static_cast<int>(valueForLength(length, maximumValue));
}
LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages)
{
switch (length.type()) {
case Fixed:
return length.value();
case Percent:
if (roundPercentages)
return LayoutUnit(round(maximumValue * length.percent() / 100.0f));
return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 100.0f));
case Calculated:
return length.nonNanCalculatedValue(maximumValue);
case FillAvailable:
case Auto:
return 0;
case Relative:
case Intrinsic:
case MinIntrinsic:
case MinContent:
case MaxContent:
case FitContent:
case Undefined:
ASSERT_NOT_REACHED();
return 0;
}
ASSERT_NOT_REACHED();
return 0;
}
LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue)
{
switch (length.type()) {
case Fixed:
case Percent:
case Calculated:
return minimumValueForLength(length, maximumValue);
case FillAvailable:
case Auto:
return maximumValue;
case Relative:
case Intrinsic:
case MinIntrinsic:
case MinContent:
case MaxContent:
case FitContent:
case Undefined:
ASSERT_NOT_REACHED();
return 0;
}
ASSERT_NOT_REACHED();
return 0;
}
float floatValueForLength(const Length& length, LayoutUnit maximumValue)
{
switch (length.type()) {
case Fixed:
return length.value();
case Percent:
return static_cast<float>(maximumValue * length.percent() / 100.0f);
case FillAvailable:
case Auto:
return static_cast<float>(maximumValue);
case Calculated:
return length.nonNanCalculatedValue(maximumValue);
case Relative:
case Intrinsic:
case MinIntrinsic:
case MinContent:
case MaxContent:
case FitContent:
case Undefined:
ASSERT_NOT_REACHED();
return 0;
}
ASSERT_NOT_REACHED();
return 0;
}
float floatValueForLength(const Length& length, float maximumValue)
{
switch (length.type()) {
case Fixed:
return length.value();
case Percent:
return static_cast<float>(maximumValue * length.percent() / 100.0f);
case FillAvailable:
case Auto:
return static_cast<float>(maximumValue);
case Calculated:
return length.nonNanCalculatedValue(maximumValue);
case Relative:
case Intrinsic:
case MinIntrinsic:
case MinContent:
case MaxContent:
case FitContent:
case Undefined:
ASSERT_NOT_REACHED();
return 0;
}
ASSERT_NOT_REACHED();
return 0;
}
FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, const FloatSize& boxSize)
{
return FloatSize(floatValueForLength(lengthSize.width(), boxSize.width()), floatValueForLength(lengthSize.height(), boxSize.height()));
}
}