Ejemplo n.º 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 CSSBasicShapeInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState&, ConversionCheckers&) const
{
    if (!value.isBaseValueList())
        return BasicShapeInterpolationFunctions::maybeConvertCSSValue(value);

    const CSSValueList& list = toCSSValueList(value);
    if (list.length() != 1)
        return nullptr;
    return BasicShapeInterpolationFunctions::maybeConvertCSSValue(*list.item(0));
}
InterpolationValue CSSLengthListInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState&, ConversionCheckers&) const
{
    if (!value.isBaseValueList())
        return nullptr;

    const CSSValueList& list = toCSSValueList(value);
    return ListInterpolationFunctions::createList(list.length(), [&list](size_t index) {
        return CSSLengthInterpolationType::maybeConvertCSSValue(*list.item(index));
    });
}
InterpolationValue CSSShadowListInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState&, ConversionCheckers&) const
{
    if (value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == CSSValueNone)
        return createNeutralValue();

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

    const CSSValueList& valueList = toCSSValueList(value);
    return ListInterpolationFunctions::createList(valueList.length(), [&valueList](size_t index) {
        return ShadowInterpolationFunctions::maybeConvertCSSValue(valueList.item(index));
    });
}
InterpolationValue CSSPositionAxisListInterpolationType::maybeConvertValue(
    const CSSValue& value,
    const StyleResolverState&,
    ConversionCheckers&) const {
  if (!value.isBaseValueList()) {
    return ListInterpolationFunctions::createList(
        1, [&value](size_t) { return convertPositionAxisCSSValue(value); });
  }

  const CSSValueList& list = toCSSValueList(value);
  return ListInterpolationFunctions::createList(
      list.length(), [&list](size_t index) {
        return convertPositionAxisCSSValue(list.item(index));
      });
}
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));
}
InterpolationValue CSSScaleInterpolationType::maybeConvertValue(
    const CSSValue& value,
    const StyleResolverState&,
    ConversionCheckers&) const {
  Scale scale(1, 1, 1);
  if (!value.isBaseValueList())
    return nullptr;

  const CSSValueList& list = toCSSValueList(value);
  if (list.length() < 1 || list.length() > 3)
    return nullptr;

  for (size_t i = 0; i < list.length(); i++) {
    const CSSValue& item = list.item(i);
    if (!item.isPrimitiveValue() || !toCSSPrimitiveValue(item).isNumber())
      return nullptr;
    scale.array[i] = toCSSPrimitiveValue(item).getDoubleValue();
  }

  if (list.length() == 1)
    scale.array[1] = scale.array[0];

  return InterpolationValue(scale.createInterpolableValue());
}