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
CSSPositionAxisListInterpolationType::convertPositionAxisCSSValue(
    const CSSValue& value) {
  if (value.isValuePair()) {
    const CSSValuePair& pair = toCSSValuePair(value);
    InterpolationValue result =
        LengthInterpolationFunctions::maybeConvertCSSValue(pair.second());
    CSSValueID side = toCSSIdentifierValue(pair.first()).getValueID();
    if (side == CSSValueRight || side == CSSValueBottom)
      LengthInterpolationFunctions::subtractFromOneHundredPercent(result);
    return result;
  }

  if (value.isPrimitiveValue())
    return LengthInterpolationFunctions::maybeConvertCSSValue(value);

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

  const CSSIdentifierValue& ident = toCSSIdentifierValue(value);
  switch (ident.getValueID()) {
    case CSSValueLeft:
    case CSSValueTop:
      return LengthInterpolationFunctions::createInterpolablePercent(0);
    case CSSValueRight:
    case CSSValueBottom:
      return LengthInterpolationFunctions::createInterpolablePercent(100);
    case CSSValueCenter:
      return LengthInterpolationFunctions::createInterpolablePercent(50);
    default:
      NOTREACHED();
      return nullptr;
  }
}
InterpolationValue SizeInterpolationFunctions::maybeConvertCSSSizeSide(
    const CSSValue& value,
    bool convertWidth) {
  if (value.isValuePair()) {
    const CSSValuePair& pair = toCSSValuePair(value);
    const CSSValue& side = convertWidth ? pair.first() : pair.second();
    if (side.isIdentifierValue() &&
        toCSSIdentifierValue(side).getValueID() == CSSValueAuto)
      return convertKeyword(CSSValueAuto);
    return wrapConvertedLength(
        LengthInterpolationFunctions::maybeConvertCSSValue(side));
  }

  if (!value.isIdentifierValue() && !value.isPrimitiveValue())
    return nullptr;
  if (value.isIdentifierValue())
    return convertKeyword(toCSSIdentifierValue(value).getValueID());

  // A single length is equivalent to "<length> auto".
  if (convertWidth)
    return wrapConvertedLength(
        LengthInterpolationFunctions::maybeConvertCSSValue(value));
  return convertKeyword(CSSValueAuto);
}
Example #4
0
static bool isCSSAuto(const CSSValue& value) {
  return value.isIdentifierValue() &&
         toCSSIdentifierValue(value).getValueID() == CSSValueAuto;
}