Class Evaluator

java.lang.Object
io.sf.carte.doc.style.css.property.Evaluator

public class Evaluator extends Object
Expression/Function evaluator.

Evaluates calc() expressions as well as functions like min(), clamp() or cos().

To support percentages within calc() expressions, it must be subclassed by something that supports a box model implementation, overriding the percentage(ExtendedCSSPrimitiveValue, short) method.

  • Constructor Details

    • Evaluator

      public Evaluator()
  • Method Details

    • evaluateFunction

      public ExtendedCSSPrimitiveValue evaluateFunction(CSSFunctionValue function) throws DOMException
      Evaluate the given function.

      This method checks the result unit, assuming that the unit must match that of the returned primitive value (some functions may return values where the units are raised to a power greater than one, or lesser than zero).

      Parameters:
      function - the function to evaluate.
      Returns:
      the result of evaluating the function, or the function itself if this class does not know how to evaluate it.
      Throws:
      DOMException - if a problem was found evaluating the function, or the resulting unit is not a valid CSS unit.
    • evaluateExpression

      public ExtendedCSSPrimitiveValue evaluateExpression(ExpressionValue calc) throws DOMException
      Evaluate the given expression.

      This method checks the result unit, assuming that the unit must match that of the returned primitive value (some functions may return values where the units are raised to a power greater than one, or lesser than zero).

      Parameters:
      calc - the expression value to evaluate.
      Returns:
      the result from evaluating the expression.
      Throws:
      DOMException - if a problem was found evaluating the expression.
    • absoluteValue

      protected ExtendedCSSPrimitiveValue absoluteValue(ExtendedCSSPrimitiveValue partialValue)
      Obtain an absolute (numeric) value, starting from a primitive value.

      If the supplied value is already absolute, or it is not known how to express it in absolute units, return it.

      Parameters:
      partialValue - the value that has to be expressed in absolute units.
      Returns:
      the value in absolute units.
    • percentage

      protected float percentage(ExtendedCSSPrimitiveValue value, short resultType) throws DOMException
      Obtain the float value (in the requested absolute unit) corresponding to the given percentage value.
      Parameters:
      value - the percentage value.
      resultType - the desired absolute result type.
      Returns:
      the absolute float value in the requested unit.
      Throws:
      DOMException - if the percentage could not be converted to the requested unit.