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

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

Issue 345903005: calc expressions should support time, angle and frequency values. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix build warrning. Created 6 years, 5 months 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 ae9dc85a4265d88911e438e6c17be192c0e03145..3df44cc1d45a414ead7c3d22f48de134f82b3e07 100644
--- a/Source/core/css/CSSPrimitiveValue.cpp
+++ b/Source/core/css/CSSPrimitiveValue.cpp
@@ -143,6 +143,13 @@ StringToUnitTable createStringToUnitTable()
return table;
}
+CSSPrimitiveValue::UnitType CSSPrimitiveValue::calcUnitType() const
+{
+ CSSCalcExpressionNode* calcExpressionNode = cssCalcValue()->expressionNode();
+ if (calcExpressionNode)
+ return calcExpressionNode->primitiveType();
+ return CSS_UNKNOWN;
alancutter (OOO until 2018) 2014/07/21 14:03:47 This function should only get called if we are a c
+}
CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit)
{
@@ -216,6 +223,10 @@ CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const
return static_cast<UnitType>(m_primitiveUnitType);
switch (m_value.calc->category()) {
+ case CalcAngle:
+ return CSS_DEG;
+ case CalcFrequency:
+ return CSS_HZ;
case CalcNumber:
return CSS_NUMBER;
case CalcPercent:
@@ -226,6 +237,8 @@ CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const
return CSS_CALC_PERCENTAGE_WITH_NUMBER;
case CalcPercentLength:
return CSS_CALC_PERCENTAGE_WITH_LENGTH;
+ case CalcTime:
+ return CSS_MS;
case CalcOther:
return CSS_UNKNOWN;
}
@@ -534,9 +547,23 @@ void CSSPrimitiveValue::cleanup()
}
}
+double CSSPrimitiveValue::computeSeconds()
+{
+ ASSERT(isTime() || (isCalculated() && cssCalcValue()->category() == CalcTime));
+ UnitType currentType = isCalculated() ? calcUnitType() : static_cast<UnitType>(m_primitiveUnitType);
+ if (currentType == CSS_S)
+ return getDoubleValue();
+ if (currentType == CSS_MS)
+ return getDoubleValue() / 1000;
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
double CSSPrimitiveValue::computeDegrees()
{
- switch (m_primitiveUnitType) {
+ ASSERT(isAngle() || (isCalculated() && cssCalcValue()->category() == CalcAngle));
+ UnitType currentType = isCalculated() ? calcUnitType() : static_cast<UnitType>(m_primitiveUnitType);
+ switch (currentType) {
case CSS_DEG:
return getDoubleValue();
case CSS_RAD:

Powered by Google App Engine
This is Rietveld 408576698