Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Unified Diff: Source/core/css/CSSPrimitiveValue.cpp

Issue 64293008: Wrap CSS length conversion arguments in an object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: erm.. use DEFINE_STATIC_REF Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/CSSPrimitiveValue.cpp
diff --git a/Source/core/css/CSSPrimitiveValue.cpp b/Source/core/css/CSSPrimitiveValue.cpp
index 16612d6a7e3d4dda348cf4d94f451d71f32394a0..215dff694cc42a12c9f7f7b6064d6190311618c5 100644
--- a/Source/core/css/CSSPrimitiveValue.cpp
+++ b/Source/core/css/CSSPrimitiveValue.cpp
@@ -28,6 +28,7 @@
#include "core/css/CSSCalculationValue.h"
#include "core/css/CSSHelper.h"
#include "core/css/CSSParser.h"
+#include "core/css/CSSToLengthConversionData.h"
#include "core/css/Counter.h"
#include "core/css/Pair.h"
#include "core/css/RGBColor.h"
@@ -519,70 +520,70 @@ double CSSPrimitiveValue::computeDegrees()
}
}
-template<> int CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> int CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return roundForImpreciseConversion<int>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
+ return roundForImpreciseConversion<int>(computeLengthDouble(conversionData));
}
-template<> unsigned CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> unsigned CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return roundForImpreciseConversion<unsigned>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
+ return roundForImpreciseConversion<unsigned>(computeLengthDouble(conversionData));
}
-template<> Length CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> Length CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return Length(clampTo<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize), minValueForCssLength, maxValueForCssLength), Fixed);
+ return Length(clampTo<float>(computeLengthDouble(conversionData), minValueForCssLength, maxValueForCssLength), Fixed);
}
-template<> short CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> short CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return roundForImpreciseConversion<short>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
+ return roundForImpreciseConversion<short>(computeLengthDouble(conversionData));
}
-template<> unsigned short CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> unsigned short CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return roundForImpreciseConversion<unsigned short>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
+ return roundForImpreciseConversion<unsigned short>(computeLengthDouble(conversionData));
}
-template<> float CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> float CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
+ return static_cast<float>(computeLengthDouble(conversionData));
}
-template<> double CSSPrimitiveValue::computeLength(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+template<> double CSSPrimitiveValue::computeLength(const CSSToLengthConversionData& conversionData)
{
- return computeLengthDouble(style, rootStyle, multiplier, computingFontSize);
+ return computeLengthDouble(conversionData);
}
-double CSSPrimitiveValue::computeLengthDouble(const RenderStyle* style, const RenderStyle* rootStyle, float multiplier, bool computingFontSize)
+double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& conversionData)
{
if (m_primitiveUnitType == CSS_CALC)
- // The multiplier and factor is applied to each value in the calc expression individually
- return m_value.calc->computeLengthPx(style, rootStyle, multiplier, computingFontSize);
+ return m_value.calc->computeLengthPx(conversionData);
+
+ const RenderStyle& style = conversionData.style();
+ const RenderStyle& rootStyle = conversionData.rootStyle();
+ bool computingFontSize = conversionData.computingFontSize();
double factor;
switch (primitiveType()) {
case CSS_EMS:
- factor = computingFontSize ? style->fontDescription().specifiedSize() : style->fontDescription().computedSize();
+ factor = computingFontSize ? style.fontDescription().specifiedSize() : style.fontDescription().computedSize();
break;
case CSS_EXS:
// FIXME: We have a bug right now where the zoom will be applied twice to EX units.
// We really need to compute EX using fontMetrics for the original specifiedSize and not use
// our actual constructed rendering font.
- if (style->fontMetrics().hasXHeight())
- factor = style->fontMetrics().xHeight();
+ if (style.fontMetrics().hasXHeight())
+ factor = style.fontMetrics().xHeight();
else
- factor = (computingFontSize ? style->fontDescription().specifiedSize() : style->fontDescription().computedSize()) / 2.0;
+ factor = (computingFontSize ? style.fontDescription().specifiedSize() : style.fontDescription().computedSize()) / 2.0;
break;
case CSS_REMS:
- if (rootStyle)
- factor = computingFontSize ? rootStyle->fontDescription().specifiedSize() : rootStyle->fontDescription().computedSize();
- else
- factor = 1.0;
+ factor = computingFontSize ? rootStyle.fontDescription().specifiedSize() : rootStyle.fontDescription().computedSize();
break;
case CSS_CHS:
- factor = style->fontMetrics().zeroWidth();
+ factor = style.fontMetrics().zeroWidth();
break;
case CSS_PX:
factor = 1.0;
@@ -619,7 +620,7 @@ double CSSPrimitiveValue::computeLengthDouble(const RenderStyle* style, const Re
if (computingFontSize || isFontRelativeLength())
return result;
- return result * multiplier;
+ return result * conversionData.zoom();
}
void CSSPrimitiveValue::setFloatValue(unsigned short, double, ExceptionState& exceptionState)

Powered by Google App Engine
This is Rietveld 408576698