Skip to content

Commit

Permalink
Support late resolution of symbols in CSS calc
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274001

Reviewed by Darin Adler.

This change makes it so that symbols passed to `calc()`, such as done
for relative colors, are kept as symbols until evaluation of the `calc()`
is performed. This will allow us to delay resolving the symbols in
relative colors in cases like an origin color of `currentColor`, where
we don't have the values to resolve the symbol until much later.

To make this possible, a new `CSSCalcExpressionNode` type is added,
`CSSCalcSymbolNode`, which represents the unresolved symbol. Additionally,
instead of passing the `CSSCalcSymbolTable` to the parser, a new
`CSSCalcSymbolsAllowed` table is passed there, and `CSSCalcSymbolTable`
is passed to the evaluation function `doubleValue()`.

Only a few small changes were needed to processing `calc()` to support
these unresolved symbols, primarily in `CSSCalcOperationNode` where
a few places were making assumptions about how child nodes would be
combined by simplification if they had the same types, but with symbols
that is not possible in all cases anymore.

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
    - Add new files.

* Source/WebCore/css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::doubleValue const):
(WebCore::CSSPrimitiveValue::doubleValueDividingBy100IfPercentage const):
    - Pass empty symbol table to `doubleValue()`.

* Source/WebCore/css/calc/CSSCalcExpressionNode.cpp:
    - Move virtual destructor out of line to avoid vtable duplication.

* Source/WebCore/css/calc/CSSCalcExpressionNode.h:
    - Adds new `CssCalcSymbol` type
    - Adds new `isResolvable()` pure virtual function, which returns false
      if the node, or any of its children, is an unresolved symbol.
    - Adds `CSSCalcSymbolTable` parameter to `doubleValue()`.

* Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp:
(WebCore::CSSCalcExpressionNodeParser::parseValue):
* Source/WebCore/css/calc/CSSCalcExpressionNodeParser.h:
(WebCore::CSSCalcExpressionNodeParser::CSSCalcExpressionNodeParser):
    - Utilize CSSCalcSymbolsAllowed to create symbol nodes for symbols
      at parse time.

* Source/WebCore/css/calc/CSSCalcInvertNode.cpp:
(WebCore::CSSCalcInvertNode::isResolvable const):
(WebCore::CSSCalcInvertNode::doubleValue const):
* Source/WebCore/css/calc/CSSCalcInvertNode.h:
    - Implement `isResolvable() and pass symbol table through to children
      in `doubleValue()`.

* Source/WebCore/css/calc/CSSCalcNegateNode.cpp:
(WebCore::CSSCalcNegateNode::isResolvable const):
(WebCore::CSSCalcNegateNode::doubleValue const):
* Source/WebCore/css/calc/CSSCalcNegateNode.h:
    - Implement `isResolvable() and pass symbol table through to children
      in `doubleValue()`.

* Source/WebCore/css/calc/CSSCalcOperationNode.h:
* Source/WebCore/css/calc/CSSCalcOperationNode.cpp:
(WebCore::CSSCalcOperationNode::combineChildren):
    - Adds check for `isResolvable()` before trying to early evaluate
      math functions, as you can't evaluate them if child is a symbol.
    - Passes empty symbol table through to resolvable children via
      `doubleValue()`.

(WebCore::CSSCalcOperationNode::isResolvable const):
    - Implement by checking children for `isResolvable()`.

(WebCore::CSSCalcOperationNode::isZero const):
    - Move definition to implementation file to avoid #including
      CSSCalcSymbolTable in the header.

(WebCore::CSSCalcOperationNode::primitiveType const):
    - Add support for computing the primitive type when there are
      multiple nodes of the same type that have not been combined,
      which can now happen with symbols.

(WebCore::CSSCalcOperationNode::doubleValue const):
    - Pass symbol table through to children.

(WebCore::CSSCalcOperationNode::buildCSSTextRecursive):
    - Pass empty symbol table to `doubleValue()`, which is fine because the
      child has been explicitly checked to be a `CSSCalcPrimitiveValueNode`.

* Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp:
(WebCore::CSSCalcPrimitiveValueNode::add):
(WebCore::CSSCalcPrimitiveValueNode::doubleValue const):
(WebCore::CSSCalcPrimitiveValueNode::isResolvable const):
* Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.h:
    - Implement `isResolvable() and pass symbol table through to children
      in `doubleValue()`.

* Source/WebCore/css/calc/CSSCalcSymbolNode.cpp: Added.
* Source/WebCore/css/calc/CSSCalcSymbolNode.h: Added.
    - New `calc` node. Only supported for numeric (`doubleValue()`) `calc()`,
      as there are currently no uses of symbols for anything else and adding
      additional support would require significantly more plumbing with
      `CalcExpressionNode` for no benefit.

* Source/WebCore/css/calc/CSSCalcSymbolTable.cpp:
* Source/WebCore/css/calc/CSSCalcSymbolTable.h:
    - Remove WeakPtr support. `CSSCalcSymbolTable` is not stored anywhere
      anymore, just passed through `doubleValue()`.

* Source/WebCore/css/calc/CSSCalcSymbolsAllowed.cpp: Copied from Source/WebCore/css/calc/CSSCalcSymbolTable.cpp.
(WebCore::CSSCalcSymbolsAllowed::CSSCalcSymbolsAllowed):
(WebCore::CSSCalcSymbolsAllowed::get const):
(WebCore::CSSCalcSymbolsAllowed::contains const):
* Source/WebCore/css/calc/CSSCalcSymbolsAllowed.h: Copied from Source/WebCore/css/calc/CSSCalcSymbolTable.h.
    - Added new table for allowed symbols which includes the symbol's
      name and type.

* Source/WebCore/css/calc/CSSCalcValue.cpp:
(WebCore::CSSCalcValue::doubleValue const):
(WebCore::CSSCalcValue::create):
* Source/WebCore/css/calc/CSSCalcValue.h:
    - Pass the `CSSCalcSymbolsAllowed` through the constructor, and
      `CSSCalcSymbolTable` through `doubleValue()`.

* Source/WebCore/css/parser/CSSCalcParser.cpp:
(WebCore::CSSPropertyParserHelpers::CalcParser::CalcParser):
(WebCore::CSSPropertyParserHelpers::consumeCalcRawWithKnownTokenTypeFunction):
* Source/WebCore/css/parser/CSSCalcParser.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Angle.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+AngleDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+CSSPrimitiveValueResolver.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+CSSPrimitiveValueResolver.h:
    - Pass `CSSCalcSymbolTable` to `doubleValue()` for resolution.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Color.cpp:
(WebCore::CSSPropertyParserHelpers::consumeAbsoluteComponent):
(WebCore::CSSPropertyParserHelpers::consumeRelativeComponent):
(WebCore::CSSPropertyParserHelpers::consumeRelativeComponents):
    - Pass both the `CSSCalcSymbolsAllowed` and `CSSCalcSymbolTable` to shared
      consume/resolve functions. This is temporary, and in a subsequent change
      resolution will be in a distinct place from consuming.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Integer.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+IntegerDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Length.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Length.h:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+LengthDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+MetaConsumer.h:
(WebCore::CSSPropertyParserHelpers::MetaConsumer::consume):
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+MetaResolver.h:
(WebCore::CSSPropertyParserHelpers::MetaResolver::consumeAndResolve):
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+None.cpp:
(WebCore::CSSPropertyParserHelpers::NoneKnownTokenTypeIdentConsumer::consume):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+NoneDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Number.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+NumberDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Percent.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+PercentDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Primitives.cpp:
(WebCore::CSSPropertyParserHelpers::equal): Deleted.
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Primitives.h:
    - Moves UnevaluatedCalc out to its own files.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+RawResolver.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+RawResolver.h:
    - Pass `CSSCalcSymbolTable` to `doubleValue()` for resolution.
    - Utilize shared support for symbol replacing via `replaceSymbol()`.
    - Utilize shared support for calc evaluation via `evaluateCalc().

* Source/WebCore/css/parser/CSSPropertyParserConsumer+RawTypes.cpp: Added
(WebCore::replaceSymbol):
    - Added shared place for direct symbol (e.g. not in a `calc()`) replacement
      via a symbol table.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+RawTypes.h:
    - Moved raw types out of the CSSPropertyParserHelpers as it is now used
      beyond just the parser helpers and having that long prefix was unwieldily.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Resolution.cpp:
(WebCore::CSSPropertyParserHelpers::consumeResolution):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+ResolutionDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Symbol.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+SymbolDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+Time.cpp:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+Time.h:
* Source/WebCore/css/parser/CSSPropertyParserConsumer+TimeDefinitions.h:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.cpp: Copied from Source/WebCore/css/parser/CSSPropertyParserConsumer+Primitives.cpp.
(WebCore::CSSPropertyParserHelpers::unevaluatedCalcEqual):
(WebCore::CSSPropertyParserHelpers::unevaluatedCalcSerialization):
(WebCore::CSSPropertyParserHelpers::evaluateCalc):
* Source/WebCore/css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.h: Added.
(WebCore::CSSPropertyParserHelpers::UnevaluatedCalc::operator== const):
(WebCore::CSSPropertyParserHelpers::serializationForCSS):
(WebCore::CSSPropertyParserHelpers::evaluateCalc):
    - Move UnevaluatedCalc to its own files and add support for evaluation that
      passes symbol table through and returns the correct raw type.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
    - Replace `CSSCalcSymbolTable` with `CSSCalcSymbolsAllowed` for parsing,
      and pass empty values for both to combined `consumeAndResolve()`.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.h:
    - Removed CSSPropertyParserHelpers namespace prefixes from raw types.

* Source/WebCore/css/parser/CSSPropertyParserWorkerSafe.cpp:
    - Added now needed missing #include.

* Source/WebCore/css/typedom/CSSNumericValue.cpp:
(WebCore::reifyMathExpression):
(WebCore::CSSNumericValue::reifyMathExpression):
    - Fill in support for the new calc node. Currently unsupported by the spec,
      so throughs an exception.

* Source/WebCore/style/StyleResolveForFontRaw.cpp:
    - Removed CSSPropertyParserHelpers namespace prefixes from raw types.

Canonical link: https://commits.webkit.org/278635@main
  • Loading branch information
weinig authored and nt1m committed May 10, 2024
1 parent 27323d1 commit c7dc51f
Show file tree
Hide file tree
Showing 62 changed files with 823 additions and 225 deletions.
6 changes: 6 additions & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,20 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
css/StyleSheetContents.h
css/StyleSheetList.h

css/calc/CSSCalcSymbolsAllowed.h
css/calc/CSSCalcValue.h

css/color/CSSColorDescriptors.h

css/parser/CSSParser.h
css/parser/CSSParserContext.h
css/parser/CSSParserEnum.h
css/parser/CSSParserMode.h
css/parser/CSSParserToken.h
css/parser/CSSParserTokenRange.h
css/parser/CSSPropertyParserConsumer+Primitives.h
css/parser/CSSPropertyParserConsumer+RawTypes.h
css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.h
css/parser/CSSSelectorParser.h
css/parser/CSSSelectorParserContext.h
css/parser/MutableCSSSelector.h
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ css/calc/CSSCalcInvertNode.cpp
css/calc/CSSCalcNegateNode.cpp
css/calc/CSSCalcOperationNode.cpp
css/calc/CSSCalcPrimitiveValueNode.cpp
css/calc/CSSCalcSymbolNode.cpp
css/calc/CSSCalcSymbolsAllowed.cpp
css/calc/CSSCalcSymbolTable.cpp
css/calc/CSSCalcValue.cpp
css/color/CSSResolvedColorMix.cpp
Expand Down Expand Up @@ -986,9 +988,11 @@ css/parser/CSSPropertyParserConsumer+Number.cpp
css/parser/CSSPropertyParserConsumer+Percent.cpp
css/parser/CSSPropertyParserConsumer+Primitives.cpp
css/parser/CSSPropertyParserConsumer+RawResolver.cpp
css/parser/CSSPropertyParserConsumer+RawTypes.cpp
css/parser/CSSPropertyParserConsumer+Resolution.cpp
css/parser/CSSPropertyParserConsumer+Symbol.cpp
css/parser/CSSPropertyParserConsumer+Time.cpp
css/parser/CSSPropertyParserConsumer+UnevaluatedCalc.cpp
css/parser/CSSPropertyParserHelpers.cpp
css/parser/CSSPropertyParserWorkerSafe.cpp
css/parser/CSSSelectorParser.cpp
Expand Down
44 changes: 34 additions & 10 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Source/WebCore/css/CSSPrimitiveValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "config.h"
#include "CSSPrimitiveValue.h"

#include "CSSCalcSymbolTable.h"
#include "CSSCalcValue.h"
#include "CSSHelper.h"
#include "CSSMarkup.h"
Expand Down Expand Up @@ -1084,13 +1085,13 @@ double CSSPrimitiveValue::doubleValue(CSSUnitType unitType) const

double CSSPrimitiveValue::doubleValue() const
{
return isCalculated() ? m_value.calc->doubleValue() : m_value.number;
return isCalculated() ? m_value.calc->doubleValue({ }) : m_value.number;
}

double CSSPrimitiveValue::doubleValueDividingBy100IfPercentage() const
{
if (isCalculated())
return m_value.calc->primitiveType() == CSSUnitType::CSS_PERCENTAGE ? m_value.calc->doubleValue() / 100.0 : m_value.calc->doubleValue();
return m_value.calc->primitiveType() == CSSUnitType::CSS_PERCENTAGE ? m_value.calc->doubleValue({ }) / 100.0 : m_value.calc->doubleValue({ });
if (isPercentage())
return m_value.number / 100.0;
return m_value.number;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/css/calc/CSSCalcExpressionNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

namespace WebCore {

CSSCalcExpressionNode::~CSSCalcExpressionNode() = default;

TextStream& operator<<(TextStream& ts, const CSSCalcExpressionNode& node)
{
node.dump(ts);
Expand Down
8 changes: 6 additions & 2 deletions Source/WebCore/css/calc/CSSCalcExpressionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace WebCore {

class CSSCalcSymbolTable;
class CSSToLengthConversionData;
class CalcExpressionNode;

Expand All @@ -49,12 +50,15 @@ class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> {
CssCalcOperation,
CssCalcNegate,
CssCalcInvert,
CssCalcSymbol,
};

virtual ~CSSCalcExpressionNode() = default;
virtual ~CSSCalcExpressionNode();

virtual bool isResolvable() const = 0;
virtual bool isZero() const = 0;
virtual std::unique_ptr<CalcExpressionNode> createCalcExpression(const CSSToLengthConversionData&) const = 0;
virtual double doubleValue(CSSUnitType) const = 0;
virtual double doubleValue(CSSUnitType, const CSSCalcSymbolTable&) const = 0;
virtual double computeLengthPx(const CSSToLengthConversionData&) const = 0;
virtual bool equals(const CSSCalcExpressionNode& other) const { return m_category == other.m_category; }
virtual Type type() const = 0;
Expand Down
24 changes: 17 additions & 7 deletions Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#include "CSSCalcNegateNode.h"
#include "CSSCalcOperationNode.h"
#include "CSSCalcPrimitiveValueNode.h"
#include "CSSCalcSymbolNode.h"
#include "CSSCalcSymbolTable.h"
#include "CSSCalcSymbolsAllowed.h"
#include "CSSCalcValue.h"
#include "CSSParserTokenRange.h"
#include "CSSPropertyParserHelpers.h"
Expand Down Expand Up @@ -300,7 +302,15 @@ static bool checkRoundKeyword(CSSValueID functionID, RefPtr<CSSCalcExpressionNod

bool CSSCalcExpressionNodeParser::parseValue(CSSParserTokenRange& tokens, CSSValueID functionID, RefPtr<CSSCalcExpressionNode>& result)
{
auto makeCSSCalcPrimitiveValueNode = [&] (CSSUnitType type, double value) -> bool {
auto makeCSSCalcSymbolNode = [&](CSSValueID value, CSSUnitType type) -> bool {
if (calcUnitCategory(type) == CalculationCategory::Other)
return false;

result = CSSCalcSymbolNode::create(value, type);
return true;
};

auto makeCSSCalcPrimitiveValueNode = [&](double value, CSSUnitType type) -> bool {
if (calcUnitCategory(type) == CalculationCategory::Other)
return false;

Expand All @@ -314,17 +324,17 @@ bool CSSCalcExpressionNodeParser::parseValue(CSSParserTokenRange& tokens, CSSVal
case IdentToken: {
if (checkRoundKeyword(functionID, result, token.id()))
return true;
auto value = m_symbolTable->get(token.id());
value = value ? value : getConstantTable().get(token.id());
if (!value)
return false;
return makeCSSCalcPrimitiveValueNode(value->type, value->value);
if (auto value = m_symbolsAllowed.get(token.id()))
return makeCSSCalcSymbolNode(token.id(), *value);
if (auto value = getConstantTable().get(token.id()))
return makeCSSCalcPrimitiveValueNode(value->value, value->type);
return false;
}

case NumberToken:
case PercentageToken:
case DimensionToken:
return makeCSSCalcPrimitiveValueNode(token.unitType(), token.numericValue());
return makeCSSCalcPrimitiveValueNode(token.numericValue(), token.unitType());

default:
return false;
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/css/calc/CSSCalcExpressionNodeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include "CSSCalcSymbolsAllowed.h"
#include "CSSValueKeywords.h"
#include "CalcOperator.h"
#include "CalculationCategory.h"
Expand All @@ -33,15 +34,14 @@
namespace WebCore {

class CSSCalcExpressionNode;
class CSSCalcSymbolTable;
class CSSParserToken;
class CSSParserTokenRange;

class CSSCalcExpressionNodeParser {
public:
explicit CSSCalcExpressionNodeParser(CalculationCategory destinationCategory, const CSSCalcSymbolTable& symbolTable)
explicit CSSCalcExpressionNodeParser(CalculationCategory destinationCategory, CSSCalcSymbolsAllowed symbolsAllowed)
: m_destinationCategory(destinationCategory)
, m_symbolTable(symbolTable)
, m_symbolsAllowed(WTFMove(symbolsAllowed))
{
}

Expand All @@ -57,7 +57,7 @@ class CSSCalcExpressionNodeParser {
bool parseCalcValue(CSSParserTokenRange&, CSSValueID, int depth, RefPtr<CSSCalcExpressionNode>&);

CalculationCategory m_destinationCategory;
SingleThreadWeakRef<const CSSCalcSymbolTable> m_symbolTable;
CSSCalcSymbolsAllowed m_symbolsAllowed;
};

}
9 changes: 7 additions & 2 deletions Source/WebCore/css/calc/CSSCalcInvertNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@

namespace WebCore {

bool CSSCalcInvertNode::isResolvable() const
{
return protectedChild()->isResolvable();
}

std::unique_ptr<CalcExpressionNode> CSSCalcInvertNode::createCalcExpression(const CSSToLengthConversionData& conversionData) const
{
auto childNode = protectedChild()->createCalcExpression(conversionData);
return makeUnique<CalcExpressionInversion>(WTFMove(childNode));
}

double CSSCalcInvertNode::doubleValue(CSSUnitType unitType) const
double CSSCalcInvertNode::doubleValue(CSSUnitType unitType, const CSSCalcSymbolTable& symbolTable) const
{
auto childValue = protectedChild()->doubleValue(unitType);
auto childValue = protectedChild()->doubleValue(unitType, symbolTable);
if (!childValue)
return std::numeric_limits<double>::infinity();
return 1.0 / childValue;
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/css/calc/CSSCalcInvertNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class CSSCalcInvertNode final : public CSSCalcExpressionNode {

std::unique_ptr<CalcExpressionNode> createCalcExpression(const CSSToLengthConversionData&) const final;

bool isResolvable() const final;
bool isZero() const final { return m_child->isZero(); }
double doubleValue(CSSUnitType) const final;
double doubleValue(CSSUnitType, const CSSCalcSymbolTable&) const final;
double computeLengthPx(const CSSToLengthConversionData&) const final;
Type type() const final { return Type::CssCalcInvert; }
CSSUnitType primitiveType() const final { return m_child->primitiveType(); }
Expand Down
10 changes: 10 additions & 0 deletions Source/WebCore/css/calc/CSSCalcNegateNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@

namespace WebCore {

bool CSSCalcNegateNode::isResolvable() const
{
return protectedChild()->isResolvable();
}

std::unique_ptr<CalcExpressionNode> CSSCalcNegateNode::createCalcExpression(const CSSToLengthConversionData& conversionData) const
{
auto childNode = protectedChild()->createCalcExpression(conversionData);
return makeUnique<CalcExpressionNegation>(WTFMove(childNode));
}

double CSSCalcNegateNode::doubleValue(CSSUnitType unitType, const CSSCalcSymbolTable& symbolTable) const
{
return -m_child->doubleValue(unitType, symbolTable);
}

void CSSCalcNegateNode::dump(TextStream& ts) const
{
ts << "-" << m_child.get();
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/css/calc/CSSCalcNegateNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class CSSCalcNegateNode final : public CSSCalcExpressionNode {

std::unique_ptr<CalcExpressionNode> createCalcExpression(const CSSToLengthConversionData&) const final;

bool isResolvable() const final;
bool isZero() const final { return m_child->isZero(); }
double doubleValue(CSSUnitType unitType) const final { return -m_child->doubleValue(unitType); }
double doubleValue(CSSUnitType, const CSSCalcSymbolTable&) const final;
double computeLengthPx(const CSSToLengthConversionData& conversionData) const final { return -m_child->computeLengthPx(conversionData); }
Type type() const final { return Type::CssCalcNegate; }
CSSUnitType primitiveType() const final { return m_child->primitiveType(); }
Expand Down
Loading

0 comments on commit c7dc51f

Please sign in to comment.