PassRefPtr<LengthBoxStyleInterpolation> LengthBoxStyleInterpolation::maybeCreateFrom(CSSValue& start, CSSValue& end, CSSPropertyID id)
{
    bool startRect = start.isQuadValue() && toCSSQuadValue(start).serializationType() == CSSQuadValue::TypeForSerialization::SerializeAsRect;
    bool endRect = end.isQuadValue() && toCSSQuadValue(end).serializationType() == CSSQuadValue::TypeForSerialization::SerializeAsRect;

    if (startRect && endRect)
        return adoptRef(new LengthBoxStyleInterpolation(lengthBoxtoInterpolableValue(start, end, false), lengthBoxtoInterpolableValue(end, start, true), id, &start, &end));
    return nullptr;
}
bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSValue& value)
{
    // FIXME: should not require resolving styles for inherit/initial/unset.
    if (value.isCSSWideKeyword())
        return true;
    if (value.isBasicShapeCircleValue())
        return interpolationRequiresStyleResolve(toCSSBasicShapeCircleValue(value));
    if (value.isBasicShapeEllipseValue())
        return interpolationRequiresStyleResolve(toCSSBasicShapeEllipseValue(value));
    if (value.isBasicShapePolygonValue())
        return interpolationRequiresStyleResolve(toCSSBasicShapePolygonValue(value));
    if (value.isBasicShapeInsetValue())
        return interpolationRequiresStyleResolve(toCSSBasicShapeInsetValue(value));
    if (value.isPrimitiveValue())
        return interpolationRequiresStyleResolve(toCSSPrimitiveValue(value));
    if (value.isQuadValue())
        return interpolationRequiresStyleResolve(toCSSQuadValue(value));
    if (value.isValueList())
        return interpolationRequiresStyleResolve(toCSSValueList(value));
    if (value.isValuePair())
        return interpolationRequiresStyleResolve(toCSSValuePair(value));
    if (value.isImageValue())
        return interpolationRequiresStyleResolve(toCSSImageValue(value));
    if (value.isShadowValue())
        return interpolationRequiresStyleResolve(toCSSShadowValue(value));
    if (value.isSVGDocumentValue())
        return interpolationRequiresStyleResolve(toCSSSVGDocumentValue(value));
    // FIXME: consider other custom types.
    return true;
}
bool LengthBoxStyleInterpolation::usesDefaultInterpolation(const CSSValue& start, const CSSValue& end)
{
    if (start.isPrimitiveValue() && end.isPrimitiveValue()) {
        const CSSPrimitiveValue& startValue = toCSSPrimitiveValue(start);
        const CSSPrimitiveValue& endValue = toCSSPrimitiveValue(end);
        return (startValue.isValueID() && startValue.getValueID() == CSSValueAuto)
            || (endValue.isValueID() && endValue.getValueID() == CSSValueAuto);
    }

    if (!start.isQuadValue() || !end.isQuadValue())
        return false;

    const CSSQuadValue& startValue = toCSSQuadValue(start);
    const CSSQuadValue& endValue = toCSSQuadValue(end);
    return onlyInterpolateBetweenLengthAndCSSValueAuto(startValue, endValue);
}
Example #4
0
BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(StyleResolverState& state, const CSSValue& value)
{
    if (!value.isQuadValue())
        return BorderImageLengthBox(Length(Auto));

    const CSSQuadValue& slices = toCSSQuadValue(value);

    // Set up a border image length box to represent our image slices.
    return BorderImageLengthBox(
        toBorderImageLength(*slices.top(), state.cssToLengthConversionData()),
        toBorderImageLength(*slices.right(), state.cssToLengthConversionData()),
        toBorderImageLength(*slices.bottom(), state.cssToLengthConversionData()),
        toBorderImageLength(*slices.left(), state.cssToLengthConversionData()));
}
InterpolationValue CSSClipInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState& state, ConversionCheckers&) const
{
    if (!value.isQuadValue())
        return nullptr;
    const CSSQuadValue& quad = toCSSQuadValue(value);
    OwnPtr<InterpolableList> list = InterpolableList::create(ClipComponentIndexCount);
    list->set(ClipTop, convertClipComponent(*quad.top()));
    list->set(ClipRight, convertClipComponent(*quad.right()));
    list->set(ClipBottom, convertClipComponent(*quad.bottom()));
    list->set(ClipLeft, convertClipComponent(*quad.left()));
    ClipAutos autos(
        isCSSAuto(*quad.top()),
        isCSSAuto(*quad.right()),
        isCSSAuto(*quad.bottom()),
        isCSSAuto(*quad.left()));
    return InterpolationValue(list.release(), CSSClipNonInterpolableValue::create(autos));
}
InterpolationValue CSSBorderImageLengthBoxInterpolationType::maybeConvertValue(
    const CSSValue& value,
    const StyleResolverState&,
    ConversionCheckers&) const {
  if (!value.isQuadValue())
    return nullptr;

  const CSSQuadValue& quad = toCSSQuadValue(value);
  std::unique_ptr<InterpolableList> list =
      InterpolableList::create(SideIndexCount);
  Vector<RefPtr<NonInterpolableValue>> nonInterpolableValues(SideIndexCount);
  const CSSValue* sides[SideIndexCount] = {};
  sides[SideTop] = quad.top();
  sides[SideRight] = quad.right();
  sides[SideBottom] = quad.bottom();
  sides[SideLeft] = quad.left();

  for (size_t i = 0; i < SideIndexCount; i++) {
    const CSSValue& side = *sides[i];
    if (side.isPrimitiveValue() && toCSSPrimitiveValue(side).isNumber()) {
      list->set(i, InterpolableNumber::create(
                       toCSSPrimitiveValue(side).getDoubleValue()));
    } else {
      InterpolationValue convertedSide =
          LengthInterpolationFunctions::maybeConvertCSSValue(side);
      if (!convertedSide)
        return nullptr;
      list->set(i, std::move(convertedSide.interpolableValue));
      nonInterpolableValues[i] = convertedSide.nonInterpolableValue.release();
    }
  }

  return InterpolationValue(
      std::move(list),
      CSSBorderImageLengthBoxNonInterpolableValue::create(
          SideNumbers(quad), std::move(nonInterpolableValues)));
}