Diff
Modified: trunk/Source/WebCore/ChangeLog (88552 => 88553)
--- trunk/Source/WebCore/ChangeLog 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/ChangeLog 2011-06-10 18:17:21 UTC (rev 88553)
@@ -1,3 +1,30 @@
+2011-06-10 Luke Macpherson <[email protected]>
+
+ Reviewed by Eric Seidel.
+
+ Clean up CSSPrimitiveValue::computeLength*
+ https://bugs.webkit.org/show_bug.cgi?id=61612
+
+ No new tests as no functionality changed.
+
+ * css/CSSGradientValue.cpp:
+ Use new computeLength functions.
+ * css/CSSPrimitiveValue.cpp:
+ (WebCore::CSSPrimitiveValue::computeLengthIntForLength):
+ Reduce to a single function using default parameter values.
+ (WebCore::CSSPrimitiveValue::computeLength):
+ Redefine existing functions with separate names as a single function using templated function specialization.
+ * css/CSSPrimitiveValue.h:
+ Prototypes for computeLengthIntForLength and computeLength.
+ * css/CSSStyleApplyProperty.cpp:
+ Use new computeLength functions.
+ * css/CSSStyleSelector.cpp:
+ Use new computeLength functions.
+ * css/MediaQueryEvaluator.cpp:
+ Use new computeLength functions.
+ * css/SVGCSSStyleSelector.cpp:
+ Use new computeLength functions.
+
2011-06-10 Simon Fraser <[email protected]>
Reviewed by Beth Dakin.
Modified: trunk/Source/WebCore/css/CSSGradientValue.cpp (88552 => 88553)
--- trunk/Source/WebCore/css/CSSGradientValue.cpp 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/CSSGradientValue.cpp 2011-06-10 18:17:21 UTC (rev 88553)
@@ -159,7 +159,7 @@
if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100;
else if (CSSPrimitiveValue::isUnitTypeLength(type)) {
- float length = stop.m_position->computeLengthFloat(style, rootStyle, style->effectiveZoom());
+ float length = stop.m_position->computeLength<float>(style, rootStyle, style->effectiveZoom());
if (!computedGradientLength) {
FloatSize gradientSize(gradientStart - gradientEnd);
gradientLength = gradientSize.diagonalLength();
@@ -391,7 +391,7 @@
}
default:
- return value->computeLengthFloat(style, rootStyle, zoomFactor);
+ return value->computeLength<float>(style, rootStyle, zoomFactor);
}
}
@@ -644,7 +644,7 @@
else if (widthOrHeight && radius->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
result = *widthOrHeight * radius->getFloatValue() / 100;
else
- result = radius->computeLengthFloat(style, rootStyle, zoomFactor);
+ result = radius->computeLength<float>(style, rootStyle, zoomFactor);
return result;
}
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (88552 => 88553)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp 2011-06-10 18:17:21 UTC (rev 88553)
@@ -249,48 +249,38 @@
}
}
-int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle)
+template<> int CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
- return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle));
+ return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
}
-int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
-{
- return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier));
-}
-
// Lengths expect an int that is only 28-bits, so we have to check for a
// different overflow.
-int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle)
+int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
- return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle));
+ return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
}
-int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
+template<> Length CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
- return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier));
+ return Length(computeLengthIntForLength(style, rootStyle, multiplier, computingFontSize), Fixed);
}
-short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle)
+template<> short CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
- return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle));
+ return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
}
-short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
+template<> float CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
- return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier));
+ return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
}
-float CSSPrimitiveValue::computeLengthFloat(RenderStyle* style, RenderStyle* rootStyle, bool computingFontSize)
+template<> double CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
- return static_cast<float>(computeLengthDouble(style, rootStyle, 1.0, computingFontSize));
+ return computeLengthDouble(style, rootStyle, multiplier, computingFontSize);
}
-float CSSPrimitiveValue::computeLengthFloat(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
-{
- return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
-}
-
double CSSPrimitiveValue::computeLengthDouble(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
unsigned short type = primitiveType();
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (88552 => 88553)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.h 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h 2011-06-10 18:17:21 UTC (rev 88553)
@@ -136,15 +136,8 @@
* this is screen/printer dependent, so we probably need a config option for this,
* and some tool to calibrate.
*/
- int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle);
- int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
- int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle);
- int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
- short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle);
- short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
- float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, bool computingFontSize = false);
- float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize = false);
- double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
+ template<typename T> T computeLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
+ int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
// use with care!!!
void setPrimitiveType(unsigned short type) { m_type = type; }
@@ -221,6 +214,8 @@
void init(PassRefPtr<DashboardRegion>); // FIXME: Dashboard region should not be a primitive value.
bool getDoubleValueInternal(UnitTypes targetUnitType, double* result) const;
+ double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize);
+
virtual bool isPrimitiveValue() const { return true; }
virtual unsigned short cssValueType() const;
Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (88552 => 88553)
--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp 2011-06-10 18:17:21 UTC (rev 88553)
@@ -371,7 +371,7 @@
width = 5;
break;
case CSSValueInvalid:
- width = primitiveValue->computeLengthShort(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
+ width = primitiveValue->computeLength<short>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
// CSS2 box model does not allow negative lengths for borders.
if (width < 0)
return;
Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (88552 => 88553)
--- trunk/Source/WebCore/css/CSSStyleSelector.cpp 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp 2011-06-10 18:17:21 UTC (rev 88553)
@@ -3344,7 +3344,7 @@
*ok = false;
} else if (CSSPrimitiveValue::isUnitTypeLength(type)) {
if (toFloat)
- l = Length(primitiveValue->computeLengthDouble(style, rootStyle, multiplier), Fixed);
+ l = Length(primitiveValue->computeLength<double>(style, rootStyle, multiplier), Fixed);
else
l = Length(primitiveValue->computeLengthIntForLength(style, rootStyle, multiplier), Fixed);
}
@@ -3740,7 +3740,7 @@
HANDLE_INHERIT_AND_INITIAL(horizontalBorderSpacing, HorizontalBorderSpacing)
if (!primitiveValue)
return;
- short spacing = primitiveValue->computeLengthShort(style(), m_rootElementStyle, zoomFactor);
+ short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor);
m_style->setHorizontalBorderSpacing(spacing);
return;
}
@@ -3748,7 +3748,7 @@
HANDLE_INHERIT_AND_INITIAL(verticalBorderSpacing, VerticalBorderSpacing)
if (!primitiveValue)
return;
- short spacing = primitiveValue->computeLengthShort(style(), m_rootElementStyle, zoomFactor);
+ short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor);
m_style->setVerticalBorderSpacing(spacing);
return;
}
@@ -3817,7 +3817,7 @@
} else {
if (!primitiveValue)
return;
- width = primitiveValue->computeLengthInt(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor);
+ width = primitiveValue->computeLength<int>(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor);
}
switch (id) {
case CSSPropertyLetterSpacing:
@@ -3942,7 +3942,7 @@
type != CSSPrimitiveValue::CSS_EXS &&
type != CSSPrimitiveValue::CSS_REMS));
if (CSSPrimitiveValue::isUnitTypeLength(type))
- size = primitiveValue->computeLengthFloat(m_parentStyle, m_rootElementStyle, true);
+ size = primitiveValue->computeLength<float>(m_parentStyle, m_rootElementStyle, 1.0, true);
else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
size = (primitiveValue->getFloatValue() * oldSize) / 100.0f;
else
@@ -4562,11 +4562,11 @@
if (pair->first()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
radiusWidth = Length(pair->first()->getDoubleValue(), Percent);
else
- radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLengthInt(style(), m_rootElementStyle, zoomFactor))), Fixed);
+ radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLength<int>(style(), m_rootElementStyle, zoomFactor))), Fixed);
if (pair->second()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
radiusHeight = Length(pair->second()->getDoubleValue(), Percent);
else
- radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLengthInt(style(), m_rootElementStyle, zoomFactor))), Fixed);
+ radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLength<int>(style(), m_rootElementStyle, zoomFactor))), Fixed);
int width = radiusWidth.value();
int height = radiusHeight.value();
if (width < 0 || height < 0)
@@ -4599,7 +4599,7 @@
case CSSPropertyOutlineOffset:
HANDLE_INHERIT_AND_INITIAL(outlineOffset, OutlineOffset)
- m_style->setOutlineOffset(primitiveValue->computeLengthInt(style(), m_rootElementStyle, zoomFactor));
+ m_style->setOutlineOffset(primitiveValue->computeLength<int>(style(), m_rootElementStyle, zoomFactor));
return;
case CSSPropertyImageRendering:
if (!primitiveValue)
@@ -4627,10 +4627,10 @@
if (!currValue->isShadowValue())
continue;
ShadowValue* item = static_cast<ShadowValue*>(list->itemWithoutBoundsCheck(i));
- int x = item->x->computeLengthInt(style(), m_rootElementStyle, zoomFactor);
- int y = item->y->computeLengthInt(style(), m_rootElementStyle, zoomFactor);
- int blur = item->blur ? item->blur->computeLengthInt(style(), m_rootElementStyle, zoomFactor) : 0;
- int spread = item->spread ? item->spread->computeLengthInt(style(), m_rootElementStyle, zoomFactor) : 0;
+ int x = item->x->computeLength<int>(style(), m_rootElementStyle, zoomFactor);
+ int y = item->y->computeLength<int>(style(), m_rootElementStyle, zoomFactor);
+ int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0;
+ int spread = item->spread ? item->spread->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0;
ShadowStyle shadowStyle = item->style && item->style->getIdent() == CSSValueInset ? Inset : Normal;
Color color;
if (item->color)
@@ -4760,7 +4760,7 @@
m_style->setHasNormalColumnGap();
return;
}
- m_style->setColumnGap(primitiveValue->computeLengthFloat(style(), m_rootElementStyle, zoomFactor));
+ m_style->setColumnGap(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor));
return;
}
case CSSPropertyWebkitColumnSpan: {
@@ -4779,7 +4779,7 @@
m_style->setHasAutoColumnWidth();
return;
}
- m_style->setColumnWidth(primitiveValue->computeLengthFloat(style(), m_rootElementStyle, zoomFactor));
+ m_style->setColumnWidth(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor));
return;
}
case CSSPropertyWebkitColumnRuleStyle:
@@ -5056,11 +5056,11 @@
result *= 3;
else if (primitiveValue->getIdent() == CSSValueThick)
result *= 5;
- width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLengthFloat(style(), m_rootElementStyle, zoomFactor);
+ width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLength<float>(style(), m_rootElementStyle, zoomFactor);
break;
}
default:
- width = primitiveValue->computeLengthFloat(style(), m_rootElementStyle, zoomFactor);
+ width = primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor);
break;
}
m_style->setTextStrokeWidth(width);
@@ -5109,7 +5109,7 @@
perspectiveValue = static_cast<float>(primitiveValue->computeLengthIntForLength(style(), m_rootElementStyle, zoomFactor));
else if (type == CSSPrimitiveValue::CSS_NUMBER) {
// For backward compatibility, treat valueless numbers as px.
- perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLengthFloat(style(), m_rootElementStyle, zoomFactor);
+ perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength<float>(style(), m_rootElementStyle, zoomFactor);
} else
return;
Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (88552 => 88553)
--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp 2011-06-10 18:17:21 UTC (rev 88553)
@@ -311,7 +311,7 @@
if (value) {
FloatRect sg = screenRect(frame->page()->mainFrame()->view());
RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
- return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
+ return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
}
// ({,min-,max-}device-height)
// assume if we have a device, assume non-zero
@@ -323,7 +323,7 @@
if (value) {
FloatRect sg = screenRect(frame->page()->mainFrame()->view());
RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
- return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
+ return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
}
// ({,min-,max-}device-width)
// assume if we have a device, assume non-zero
@@ -336,7 +336,7 @@
RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
if (value)
- return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
+ return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
return view->layoutHeight() != 0;
}
@@ -347,7 +347,7 @@
RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
if (value)
- return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
+ return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
return view->layoutWidth() != 0;
}
Modified: trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp (88552 => 88553)
--- trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp 2011-06-10 18:10:37 UTC (rev 88552)
+++ trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp 2011-06-10 18:17:21 UTC (rev 88553)
@@ -572,9 +572,9 @@
if (!firstValue->isShadowValue())
return;
ShadowValue* item = static_cast<ShadowValue*>(firstValue);
- int x = item->x->computeLengthInt(style(), m_rootElementStyle);
- int y = item->y->computeLengthInt(style(), m_rootElementStyle);
- int blur = item->blur ? item->blur->computeLengthInt(style(), m_rootElementStyle) : 0;
+ int x = item->x->computeLength<int>(style(), m_rootElementStyle);
+ int y = item->y->computeLength<int>(style(), m_rootElementStyle);
+ int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle) : 0;
Color color;
if (item->color)
color = getColorFromPrimitiveValue(item->color.get());