Example #1
0
InterpolationValue CSSFilterListInterpolationType::maybeConvertValue(
    const CSSValue& value,
    const StyleResolverState&,
    ConversionCheckers&) const {
  if (value.isIdentifierValue() &&
      toCSSIdentifierValue(value).getValueID() == CSSValueNone)
    return InterpolationValue(InterpolableList::create(0),
                              NonInterpolableList::create());

  if (!value.isBaseValueList())
    return nullptr;

  const CSSValueList& list = toCSSValueList(value);
  size_t length = list.length();
  std::unique_ptr<InterpolableList> interpolableList =
      InterpolableList::create(length);
  Vector<RefPtr<NonInterpolableValue>> nonInterpolableValues(length);
  for (size_t i = 0; i < length; i++) {
    InterpolationValue itemResult =
        FilterInterpolationFunctions::maybeConvertCSSFilter(list.item(i));
    if (!itemResult)
      return nullptr;
    interpolableList->set(i, std::move(itemResult.interpolableValue));
    nonInterpolableValues[i] = itemResult.nonInterpolableValue.release();
  }
  return InterpolationValue(
      std::move(interpolableList),
      NonInterpolableList::create(std::move(nonInterpolableValues)));
}
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)));
}
PassOwnPtr<InterpolationValue> CSSImageListInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState&, ConversionCheckers&) const
{
    if (value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == CSSValueNone)
        return nullptr;

    RefPtrWillBeRawPtr<CSSValueList> tempList = nullptr;
    if (!value.isBaseValueList()) {
        tempList = CSSValueList::createCommaSeparated();
        tempList->append(const_cast<CSSValue*>(&value)); // Take ref.
    }
    const CSSValueList& valueList = tempList ? *tempList : toCSSValueList(value);

    const size_t length = valueList.length();
    OwnPtr<InterpolableList> interpolableList = InterpolableList::create(length);
    Vector<RefPtr<NonInterpolableValue>> nonInterpolableValues(length);
    for (size_t i = 0; i < length; i++) {
        InterpolationComponent component = CSSImageInterpolationType::maybeConvertCSSValue(*valueList.item(i), false);
        if (!component)
            return nullptr;
        interpolableList->set(i, component.interpolableValue.release());
        nonInterpolableValues[i] = component.nonInterpolableValue.release();
    }
    return InterpolationValue::create(*this, interpolableList.release(), NonInterpolableList::create(nonInterpolableValues));
}