Changeset 282795 in webkit
- Timestamp:
- Sep 20, 2021 5:24:50 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 6 added
- 10 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-compute-expected.txt (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-compute.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-invalid-expected.txt (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-invalid.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize-expected.txt (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/CSSValueKeywords.in (modified) (1 diff)
-
Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp (modified) (2 diffs)
-
Source/WebCore/css/calc/CSSCalcOperationNode.cpp (modified) (9 diffs)
-
Source/WebCore/css/calc/CSSCalcOperationNode.h (modified) (2 diffs)
-
Source/WebCore/css/calc/CSSCalcValue.cpp (modified) (2 diffs)
-
Source/WebCore/platform/calc/CalcExpressionOperation.cpp (modified) (1 diff)
-
Source/WebCore/platform/calc/CalcOperator.cpp (modified) (1 diff)
-
Source/WebCore/platform/calc/CalcOperator.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r282778 r282795 1 2021-09-20 Nikos Mouchtaris <nmouchtaris@apple.com> 2 3 Implement exp,log functions calc functions 4 https://bugs.webkit.org/show_bug.cgi?id=229897 5 6 Reviewed by Simon Fraser. 7 8 * web-platform-tests/css/css-values/exp-log-compute.html: Added. 9 * web-platform-tests/css/css-values/exp-log-invalid.html: Added. 10 * web-platform-tests/css/css-values/exp-log-serialize.html: Added. 11 1 12 2021-09-20 Youenn Fablet <youenn@apple.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r282788 r282795 1 2021-09-20 Nikos Mouchtaris <nmouchtaris@apple.com> 2 3 Implement exp,log functions calc functions 4 https://bugs.webkit.org/show_bug.cgi?id=229897 5 6 Reviewed by Simon Fraser. 7 8 Added support for calc functions exp and log. Involved adding exp and log CSS keywords and handling 9 for parsing these functions and their arguments as well as computing the result based on the arguments. 10 Spec for these functions: https://drafts.csswg.org/css-values-4/#exponent-funcs. 11 12 Tests: imported/w3c/web-platform-tests/css/css-values/exp-log-compute.html 13 imported/w3c/web-platform-tests/css/css-values/exp-log-invalid.html 14 imported/w3c/web-platform-tests/css/css-values/exp-log-serialize.html 15 16 * css/CSSValueKeywords.in: 17 * css/calc/CSSCalcExpressionNodeParser.cpp: 18 (WebCore::CSSCalcExpressionNodeParser::parseCalcFunction): 19 * css/calc/CSSCalcOperationNode.cpp: 20 (WebCore::determineCategory): 21 (WebCore::functionFromOperator): 22 (WebCore::CSSCalcOperationNode::createLog): 23 (WebCore::CSSCalcOperationNode::createExp): 24 (WebCore::CSSCalcOperationNode::combineChildren): 25 (WebCore::CSSCalcOperationNode::simplifyNode): 26 (WebCore::functionPrefixForOperator): 27 (WebCore::CSSCalcOperationNode::evaluateOperator): 28 * css/calc/CSSCalcOperationNode.h: 29 * css/calc/CSSCalcValue.cpp: 30 (WebCore::createCSS): 31 (WebCore::CSSCalcValue::isCalcFunction): 32 * platform/calc/CalcExpressionOperation.cpp: 33 (WebCore::CalcExpressionOperation::evaluate const): 34 * platform/calc/CalcOperator.cpp: 35 (WebCore::operator<<): 36 * platform/calc/CalcOperator.h: 37 1 38 2021-09-20 Ross Kirsling <ross.kirsling@sony.com> 2 39 -
trunk/Source/WebCore/css/CSSValueKeywords.in
r282723 r282795 1352 1352 e 1353 1353 pi 1354 exp 1355 log 1354 1356 1355 1357 from-image -
trunk/Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp
r282162 r282795 130 130 maxArgumentCount = 3; 131 131 break; 132 133 case CSSValueLog: 134 maxArgumentCount = 2; 135 break; 136 case CSSValueExp: 132 137 case CSSValueSin: 133 138 case CSSValueCos: … … 187 192 case CSSValueCalc: 188 193 result = CSSCalcOperationNode::createSum(WTFMove(nodes)); 194 break; 195 case CSSValueLog: 196 result = CSSCalcOperationNode::createLog(WTFMove(nodes)); 197 break; 198 case CSSValueExp: 199 result = CSSCalcOperationNode::createExp(WTFMove(nodes)); 189 200 break; 190 201 // TODO: clamp, sin, cos, tan, asin, acos, atan, atan2, pow, sqrt, hypot -
trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp
r282430 r282795 80 80 case CalcOperator::Max: 81 81 case CalcOperator::Clamp: 82 case CalcOperator::Log: 83 case CalcOperator::Exp: 82 84 ASSERT_NOT_REACHED(); 83 85 return CalculationCategory::Other; … … 151 153 case CalcOperator::Max: 152 154 case CalcOperator::Clamp: 155 case CalcOperator::Log: 156 case CalcOperator::Exp: 153 157 // The type of a min(), max(), or clamp() expression is the result of adding the types of its comma-separated calculations 154 158 return CalculationCategory::Other; … … 268 272 case CalcOperator::Tan: 269 273 return CSSValueTan; 274 case CalcOperator::Exp: 275 return CSSValueExp; 276 case CalcOperator::Log: 277 return CSSValueLog; 270 278 } 271 279 return CSSValueCalc; … … 318 326 319 327 return adoptRef(new CSSCalcOperationNode(newCategory, CalcOperator::Multiply, WTFMove(values))); 328 } 329 330 RefPtr<CSSCalcOperationNode> CSSCalcOperationNode::createLog(Vector<Ref<CSSCalcExpressionNode>>&& values) 331 { 332 if (values.size() != 1 && values.size() != 2) 333 return nullptr; 334 for (auto& value : values) { 335 // TODO: Support infinity 336 if (value->category() != CalculationCategory::Number || !value->doubleValue(value->primitiveType())) { 337 LOG_WITH_STREAM(Calc, stream << "Failed to create log node because unable to determine category from " << prettyPrintNodes(values)); 338 return nullptr; 339 } 340 } 341 342 // TODO: Support infinity 343 if ((values.size() == 2 && values[1]->doubleValue(values[1]->primitiveType()) == 1)) { 344 LOG_WITH_STREAM(Calc, stream << "Failed to create log node because unable to determine category from " << prettyPrintNodes(values)); 345 return nullptr; 346 } 347 348 return adoptRef(new CSSCalcOperationNode(CalculationCategory::Number, CalcOperator::Log, WTFMove(values))); 349 } 350 351 RefPtr<CSSCalcOperationNode> CSSCalcOperationNode::createExp(Vector<Ref<CSSCalcExpressionNode>>&& values) 352 { 353 if (values.size() != 1) 354 return nullptr; 355 356 if (values[0]->category() != CalculationCategory::Number) { 357 LOG_WITH_STREAM(Calc, stream << "Failed to create exp node because unable to determine category from " << prettyPrintNodes(values)); 358 return nullptr; 359 } 360 361 return adoptRef(new CSSCalcOperationNode(CalculationCategory::Number, CalcOperator::Exp, WTFMove(values))); 320 362 } 321 363 … … 434 476 if (m_children.size() < 2) { 435 477 if (m_children.size() == 1 && isTrigNode()) { 478 double resolvedValue = doubleValue(m_children[0]->primitiveType()); 479 auto newChild = CSSCalcPrimitiveValueNode::create(CSSPrimitiveValue::create(resolvedValue, CSSUnitType::CSS_NUMBER)); 480 m_children.clear(); 481 m_children.append(WTFMove(newChild)); 482 } 483 484 if (isExpNode()) { 436 485 double resolvedValue = doubleValue(m_children[0]->primitiveType()); 437 486 auto newChild = CSSCalcPrimitiveValueNode::create(CSSPrimitiveValue::create(resolvedValue, CSSUnitType::CSS_NUMBER)); … … 631 680 auto& calcOperationNode = downcast<CSSCalcOperationNode>(rootNode.get()); 632 681 // Simplify operations with only one child node (other than root and operations that only need one node). 633 if (calcOperationNode.children().size() == 1 && depth && !calcOperationNode.isTrigNode() )682 if (calcOperationNode.children().size() == 1 && depth && !calcOperationNode.isTrigNode() && !calcOperationNode.isExpNode()) 634 683 return WTFMove(calcOperationNode.children()[0]); 635 684 … … 648 697 649 698 if (calcOperationNode.isTrigNode() && depth) 699 calcOperationNode.combineChildren(); 700 701 if (calcOperationNode.isExpNode() && depth) 650 702 calcOperationNode.combineChildren(); 651 703 … … 841 893 case CalcOperator::Max: return "max("; 842 894 case CalcOperator::Clamp: return "clamp("; 895 case CalcOperator::Exp: return "exp("; 896 case CalcOperator::Log: return "log("; 843 897 } 844 898 … … 1057 1111 return std::tan(children[0]); 1058 1112 } 1113 case CalcOperator::Log: { 1114 if (children.size() != 1 && children.size() != 2) 1115 return std::numeric_limits<double>::quiet_NaN(); 1116 if (children.size() == 1) 1117 return std::log(children[0]); 1118 return std::log(children[0]) / std::log(children[1]); 1119 } 1120 case CalcOperator::Exp: { 1121 if (children.size() != 1) 1122 return std::numeric_limits<double>::quiet_NaN(); 1123 return std::exp(children[0]); 1124 } 1059 1125 } 1060 1126 ASSERT_NOT_REACHED(); -
trunk/Source/WebCore/css/calc/CSSCalcOperationNode.h
r282162 r282795 39 39 static RefPtr<CSSCalcOperationNode> createMinOrMaxOrClamp(CalcOperator, Vector<Ref<CSSCalcExpressionNode>>&& values, CalculationCategory destinationCategory); 40 40 static RefPtr<CSSCalcOperationNode> createTrig(CalcOperator, Vector<Ref<CSSCalcExpressionNode>>&& values); 41 static RefPtr<CSSCalcOperationNode> createLog(Vector<Ref<CSSCalcExpressionNode>>&& values); 42 static RefPtr<CSSCalcOperationNode> createExp(Vector<Ref<CSSCalcExpressionNode>>&& values); 41 43 42 44 static Ref<CSSCalcExpressionNode> simplify(Ref<CSSCalcExpressionNode>&&); … … 49 51 bool isMinOrMaxNode() const { return m_operator == CalcOperator::Min || m_operator == CalcOperator::Max; } 50 52 bool isTrigNode() const { return m_operator == CalcOperator::Sin || m_operator == CalcOperator::Cos || m_operator == CalcOperator::Tan; } 53 bool isExpNode() const { return m_operator == CalcOperator::Exp || m_operator == CalcOperator::Log; } 51 54 bool shouldSortChildren() const { return isCalcSumNode() || isCalcProductNode(); } 52 55 -
trunk/Source/WebCore/css/calc/CSSCalcValue.cpp
r282162 r282795 181 181 return CSSCalcOperationNode::createMinOrMaxOrClamp(op, WTFMove(children), operationNode.destinationCategory()); 182 182 } 183 case CalcOperator::Log: { 184 auto children = createCSS(operationChildren, style); 185 if (children.size() != 1 && children.size() != 2) 186 return nullptr; 187 return CSSCalcOperationNode::createLog(WTFMove(children)); 188 } 189 case CalcOperator::Exp: { 190 auto children = createCSS(operationChildren, style); 191 if (children.size() != 1) 192 return nullptr; 193 return CSSCalcOperationNode::createExp(WTFMove(children)); 194 } 183 195 } 184 196 return nullptr; … … 295 307 case CSSValueCos: 296 308 case CSSValueTan: 309 case CSSValueExp: 310 case CSSValueLog: 297 311 return true; 298 312 default: -
trunk/Source/WebCore/platform/calc/CalcExpressionOperation.cpp
r282162 r282795 103 103 return std::tan(m_children[0]->evaluate(maxValue)); 104 104 } 105 case CalcOperator::Log: { 106 if (m_children.size() != 1 && m_children.size() != 2) 107 return std::numeric_limits<float>::quiet_NaN(); 108 if (m_children.size() == 1) 109 return std::log(m_children[0]->evaluate(maxValue)); 110 return std::log(m_children[0]->evaluate(maxValue)) / std::log(m_children[1]->evaluate(maxValue)); 111 } 112 case CalcOperator::Exp: { 113 if (m_children.size() != 1) 114 return std::numeric_limits<float>::quiet_NaN(); 115 return std::exp(m_children[0]->evaluate(maxValue)); 116 } 105 117 } 106 118 ASSERT_NOT_REACHED(); -
trunk/Source/WebCore/platform/calc/CalcOperator.cpp
r282162 r282795 44 44 case CalcOperator::Cos: ts << "cos"; break; 45 45 case CalcOperator::Tan: ts << "tan"; break; 46 case CalcOperator::Exp: ts << "exp"; break; 47 case CalcOperator::Log: ts << "log"; break; 46 48 } 47 49 return ts; -
trunk/Source/WebCore/platform/calc/CalcOperator.h
r282162 r282795 42 42 Cos, 43 43 Tan, 44 Exp, 45 Log, 44 46 }; 45 47
Note: See TracChangeset
for help on using the changeset viewer.