Make a common base class for calc ops that use nsStyleCoord as input. (Bug 585715) r=bzbarsky a2.0=blocking2.0+

This commit is contained in:
L. David Baron 2010-08-11 12:32:52 -07:00
Родитель fb76c8e137
Коммит e9ab54ed5b
2 изменённых файлов: 58 добавлений и 50 удалений

Просмотреть файл

@ -38,6 +38,7 @@
#define CSSCalc_h_
#include "nsCSSValue.h"
#include "nsStyleCoord.h"
#include <math.h>
namespace mozilla {
@ -152,6 +153,37 @@ ComputeCalc(const typename CalcOps::input_type& aValue, CalcOps &aOps)
}
}
#define CHECK_UNIT(u_) \
PR_STATIC_ASSERT(int(eCSSUnit_Calc_##u_) + 14 == int(eStyleUnit_Calc_##u_));\
PR_STATIC_ASSERT(eCSSUnit_Calc_##u_ >= eCSSUnit_Calc_Plus); \
PR_STATIC_ASSERT(eCSSUnit_Calc_##u_ <= eCSSUnit_Calc_Maximum);
CHECK_UNIT(Plus)
CHECK_UNIT(Minus)
CHECK_UNIT(Times_L)
CHECK_UNIT(Times_R)
CHECK_UNIT(Divided)
CHECK_UNIT(Minimum)
CHECK_UNIT(Maximum)
#undef CHECK_UNIT
inline nsStyleUnit
ConvertCalcUnit(nsCSSUnit aUnit)
{
NS_ABORT_IF_FALSE(eCSSUnit_Calc_Plus <= aUnit &&
aUnit <= eCSSUnit_Calc_Maximum, "out of range");
return nsStyleUnit(aUnit + 14);
}
inline nsCSSUnit
ConvertCalcUnit(nsStyleUnit aUnit)
{
NS_ABORT_IF_FALSE(eStyleUnit_Calc_Plus <= aUnit &&
aUnit <= eStyleUnit_Calc_Maximum, "out of range");
return nsCSSUnit(aUnit - 14);
}
/**
* The input unit operation for input_type being nsCSSValue.
*/
@ -167,6 +199,30 @@ struct CSSValueInputCalcOps
};
/**
* The input unit operation for input_type being nsStyleCoord
*/
struct StyleCoordInputCalcOps
{
typedef nsStyleCoord input_type;
typedef nsStyleCoord::Array input_array_type;
static nsCSSUnit GetUnit(const nsStyleCoord& aValue)
{
if (aValue.IsCalcUnit()) {
return css::ConvertCalcUnit(aValue.GetUnit());
}
return eCSSUnit_Null;
}
float ComputeNumber(const nsStyleCoord& aValue)
{
NS_ABORT_IF_FALSE(PR_FALSE, "SpecifiedToComputedCalcOps should not "
"leave numbers in structure");
return 0.0f;
}
};
/**
* Basic*CalcOps provide a partial implementation of the CalcOps
* template parameter to ComputeCalc, for those callers whose merging
@ -275,37 +331,6 @@ struct NumbersAlreadyNormalizedOps : public CSSValueInputCalcOps
}
};
#define CHECK_UNIT(u_) \
PR_STATIC_ASSERT(int(eCSSUnit_Calc_##u_) + 14 == int(eStyleUnit_Calc_##u_));\
PR_STATIC_ASSERT(eCSSUnit_Calc_##u_ >= eCSSUnit_Calc_Plus); \
PR_STATIC_ASSERT(eCSSUnit_Calc_##u_ <= eCSSUnit_Calc_Maximum);
CHECK_UNIT(Plus)
CHECK_UNIT(Minus)
CHECK_UNIT(Times_L)
CHECK_UNIT(Times_R)
CHECK_UNIT(Divided)
CHECK_UNIT(Minimum)
CHECK_UNIT(Maximum)
#undef CHECK_UNIT
inline nsStyleUnit
ConvertCalcUnit(nsCSSUnit aUnit)
{
NS_ABORT_IF_FALSE(eCSSUnit_Calc_Plus <= aUnit &&
aUnit <= eCSSUnit_Calc_Maximum, "out of range");
return nsStyleUnit(aUnit + 14);
}
inline nsCSSUnit
ConvertCalcUnit(nsStyleUnit aUnit)
{
NS_ABORT_IF_FALSE(eStyleUnit_Calc_Plus <= aUnit &&
aUnit <= eStyleUnit_Calc_Maximum, "out of range");
return nsCSSUnit(aUnit - 14);
}
/**
* SerializeCalc appends the serialization of aValue to a string.
*

Просмотреть файл

@ -512,19 +512,9 @@ SpecifiedCalcToComputedCalc(const nsCSSValue& aValue, nsStyleCoord& aCoord,
aCoord = ComputeCalc(aValue, ops);
}
struct ComputeComputedCalcCalcOps : public css::BasicCoordCalcOps
struct ComputeComputedCalcCalcOps : public css::StyleCoordInputCalcOps,
public css::BasicCoordCalcOps
{
typedef nsStyleCoord input_type;
typedef nsStyleCoord::Array input_array_type;
static nsCSSUnit GetUnit(const nsStyleCoord& aValue)
{
if (aValue.IsCalcUnit()) {
return css::ConvertCalcUnit(aValue.GetUnit());
}
return eCSSUnit_Null;
}
const nscoord mPercentageBasis;
ComputeComputedCalcCalcOps(nscoord aPercentageBasis)
@ -543,13 +533,6 @@ struct ComputeComputedCalcCalcOps : public css::BasicCoordCalcOps
}
return result;
}
float ComputeNumber(const nsStyleCoord& aValue)
{
NS_ABORT_IF_FALSE(PR_FALSE, "SpecifiedToComputedCalcOps should not "
"leave numbers in structure");
return 0.0f;
}
};
// This is our public API for handling calc() expressions that involve