Index: third_party/WebKit/Source/core/css/cssom/CSSCalcLength.cpp |
diff --git a/third_party/WebKit/Source/core/css/cssom/CSSCalcLength.cpp b/third_party/WebKit/Source/core/css/cssom/CSSCalcLength.cpp |
index b5066f42f5e65e44efafcc1c423f91f844628ad3..37da951d1ff32830d3dc3dc0d77dfd0f51261a03 100644 |
--- a/third_party/WebKit/Source/core/css/cssom/CSSCalcLength.cpp |
+++ b/third_party/WebKit/Source/core/css/cssom/CSSCalcLength.cpp |
@@ -6,10 +6,14 @@ |
#include "core/css/CSSCalculationValue.h" |
#include "core/css/CSSPrimitiveValue.h" |
+#include "core/css/CSSValue.h" |
#include "core/css/cssom/CSSSimpleLength.h" |
#include "core/css/cssom/CalcDictionary.h" |
+#include "core/css/cssom/CalcDictionaryHelper.h" |
#include "wtf/Vector.h" |
+#include <iostream> |
+ |
namespace blink { |
CSSCalcLength::CSSCalcLength() : m_values(CSSLengthValue::kNumSupportedUnits), m_hasValues(CSSLengthValue::kNumSupportedUnits) {} |
@@ -35,7 +39,7 @@ CSSCalcLength* CSSCalcLength::create(const CSSLengthValue* length) |
return new CSSCalcLength(*toCSSCalcLength(length)); |
} |
-CSSCalcLength* CSSCalcLength::create(const CalcDictionary& dictionary, ExceptionState& exceptionState) |
+CSSCalcLength* CSSCalcLength::create(const CalcDictionary& dictionary) |
{ |
CSSCalcLength* result = new CSSCalcLength(); |
int numSet = 0; |
@@ -62,12 +66,140 @@ CSSCalcLength* CSSCalcLength::create(const CalcDictionary& dictionary, Exception |
setFromDictValue(pc, Pc, Picas) |
setFromDictValue(pt, Pt, Points) |
- if (numSet == 0) { |
+ if (numSet == 0) |
+ return nullptr; |
+ |
+ return result; |
+} |
+ |
+CSSCalcLength* CSSCalcLength::create(const CalcDictionary& dictionary, ExceptionState& exceptionState) |
+{ |
+ CSSCalcLength* result = CSSCalcLength::create(dictionary); |
+ if (!result) { |
exceptionState.throwTypeError("Must specify at least one value in CalcDictionary for creating a CSSCalcLength."); |
} |
return result; |
} |
+CSSCalcLength* CSSCalcLength::populateCalcLengthFromExpressionNode(const CSSCalcExpressionNode* expressionNode) |
+{ |
+ std::cout << "populateCalcLengthFromExpressionNode" << std::endl; |
+ if (expressionNode->getType() == CSSCalcExpressionNode::Type::CssCalcPrimitiveValue) { |
+ std::cout << "node is simple" << std::endl; |
+ CSSPrimitiveValue::UnitType unit = expressionNode->typeWithCalcResolved(); |
+ int unitIndex = CSSCalcLength::indexForUnit(unit); |
+ if (unitIndex < 0 || unitIndex >= kNumSupportedUnits) { |
+ std::cout << "Didn't recognize unit." << std::endl; |
+ return nullptr; |
+ } |
+ CSSCalcLength* result = new CSSCalcLength(); |
+ result->setAtIndex(expressionNode->doubleValue(), unitIndex); |
+ return result; |
+ } |
+ |
+ const CSSCalcExpressionNode* left = expressionNode->getLHS(); |
+ const CSSCalcExpressionNode* right = expressionNode->getRHS(); |
+ CalcOperator op = expressionNode->op(); |
+ |
+ CSSCalcLength* leftDict = nullptr; |
+ CSSCalcLength* rightDict = nullptr; |
+ if (op == CalcMultiply) { |
+ // One side should be a plain number. |
+ if (left->getType() == CSSCalcExpressionNode::Type::CssCalcPrimitiveValue) { |
+ rightDict = populateCalcLengthFromExpressionNode(right); |
+ if (!rightDict || left->typeWithCalcResolved() != CSSPrimitiveValue::UnitType::Number) { |
+ if (!rightDict) |
+ std::cout << "!rightDict" << std::endl; |
+ else |
+ std::cout << "left wasn't a number value" << std::endl; |
+ return nullptr; |
+ } |
+ rightDict->multiplyInternal(left->doubleValue()); |
+ } else if (right->getType() == CSSCalcExpressionNode::Type::CssCalcPrimitiveValue) { |
+ leftDict = populateCalcLengthFromExpressionNode(left); |
+ if (!leftDict || right->typeWithCalcResolved() != CSSPrimitiveValue::UnitType::Number) { |
+ if (!leftDict) |
+ std::cout << "!leftDict" << std::endl; |
+ else |
+ std::cout << "right wasn't a number value" << std::endl; |
+ return nullptr; |
+ } |
+ leftDict->multiplyInternal(right->doubleValue()); |
+ } else { |
+ std::cout << "Neither side was a primitive value" << std::endl; |
+ return nullptr; |
+ } |
+ } |
+ |
+ leftDict = populateCalcLengthFromExpressionNode(left); |
+ rightDict = populateCalcLengthFromExpressionNode(right); |
+ if (!leftDict || !rightDict) { |
+ std::cout << "One of left or right didn't expand to a dict" << std::endl; |
+ return nullptr; |
+ } |
+ |
+ if (op == CalcAdd) { |
+ //CalcDictionaryHelper::add(leftDict, rightDict); |
+ return leftDict; |
+ } else if (op == CalcSubtract) { |
+ //CalcDictionaryHelper::subtract(leftDict, rightDict); |
+ return leftDict; |
+ } |
+ |
+ std::cout << "Unrecognized op" << std::endl; |
+ return nullptr; |
+ |
+ /* |
+ if (expressionNode->getType() == CSSCalcExpressionNode::Type::CssCalcPrimitiveValue) { |
+ if (operation == CalcAdd || operation == CalcSubtract) { |
+ int unitIndex = CSSCalcLength::indexForUnit(expressionNode->typeWithCalcResolved()); |
+ if (unitIndex < 0 || unitIndex >= kNumSupportedUnits) { |
+ std::cout << "Didn't recognize unit." << std::endl; |
+ *error = true; |
+ } else { |
+ if (operation == CalcAdd) |
+ std::cout << "Adding "; |
+ else |
+ std::cout << "Subtracting "; |
+ std::cout << expressionNode->doubleValue(); |
+ std::cout << " "; |
+ std::cout << int(expressionNode->typeWithCalcResolved()) << std::endl; |
+ calcLength->setAtIndex( |
+ operation == CalcAdd ? |
+ calcLength->getAtIndex(unitIndex) + expressionNode->doubleValue() : |
+ calcLength->getAtIndex(unitIndex) - expressionNode->doubleValue(), |
+ unitIndex); |
+ } |
+ } else if (operation == CalcMultiply) { |
+ std::cout << "Multiplying " << expressionNode->doubleValue() << std::endl; |
+ calcLength->multiplyInternal(expressionNode->doubleValue()); |
+ } else if (operation == CalcDivide) { |
+ std::cout << "Dividing " << expressionNode->doubleValue() << std::endl; |
+ calcLength->divideInternal(expressionNode->doubleValue()); |
+ } else { |
+ std::cout << "Didn't recognize operator." << std::endl; |
+ *error = true; |
+ } |
+ return; |
+ } |
+ |
+ populateCalcLengthFromExpressionNode(expressionNode->getLHS(), CalcAdd, calcLength, error); |
+ populateCalcLengthFromExpressionNode(expressionNode->getRHS(), expressionNode->op(), calcLength, error); |
+ */ |
+} |
+ |
+CSSCalcLength* CSSCalcLength::fromCSSValue(const CSSValue& value) |
+{ |
+ if (!value.isPrimitiveValue()) |
+ return nullptr; |
+ const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
+ if (!primitiveValue.isLength() || !primitiveValue.isCalculated()) |
+ return nullptr; |
+ |
+ const CSSCalcValue* calcValue = primitiveValue.cssCalcValue(); |
+ return populateCalcLengthFromExpressionNode(calcValue->expressionNode()); |
+} |
+ |
bool CSSCalcLength::containsPercent() const |
{ |
return has(CSSPrimitiveValue::UnitType::Percentage); |
@@ -101,9 +233,9 @@ CSSLengthValue* CSSCalcLength::subtractInternal(const CSSLengthValue* other, Exc |
return result; |
} |
-CSSLengthValue* CSSCalcLength::multiplyInternal(double x, ExceptionState& exceptionState) |
+CSSLengthValue* CSSCalcLength::multiplyInternal(double x) |
{ |
- CSSCalcLength* result = CSSCalcLength::create(this, exceptionState); |
+ CSSCalcLength* result = CSSCalcLength::create(this); |
for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { |
if (hasAtIndex(i)) { |
result->setAtIndex(getAtIndex(i) * x, i); |
@@ -112,9 +244,9 @@ CSSLengthValue* CSSCalcLength::multiplyInternal(double x, ExceptionState& except |
return result; |
} |
-CSSLengthValue* CSSCalcLength::divideInternal(double x, ExceptionState& exceptionState) |
+CSSLengthValue* CSSCalcLength::divideInternal(double x) |
{ |
- CSSCalcLength* result = CSSCalcLength::create(this, exceptionState); |
+ CSSCalcLength* result = CSSCalcLength::create(this); |
for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { |
if (hasAtIndex(i)) { |
result->setAtIndex(getAtIndex(i) / x, i); |