FilterOperation* FilterInterpolationFunctions::createFilter(
    const InterpolableValue& interpolableValue,
    const NonInterpolableValue& untypedNonInterpolableValue,
    const StyleResolverState& state) {
  const FilterNonInterpolableValue& nonInterpolableValue =
      toFilterNonInterpolableValue(untypedNonInterpolableValue);
  FilterOperation::OperationType type = nonInterpolableValue.type();

  switch (type) {
    case FilterOperation::GRAYSCALE:
    case FilterOperation::HUE_ROTATE:
    case FilterOperation::SATURATE:
    case FilterOperation::SEPIA: {
      double value =
          clampParameter(toInterpolableNumber(interpolableValue).value(), type);
      return BasicColorMatrixFilterOperation::create(value, type);
    }

    case FilterOperation::BRIGHTNESS:
    case FilterOperation::CONTRAST:
    case FilterOperation::INVERT:
    case FilterOperation::OPACITY: {
      double value =
          clampParameter(toInterpolableNumber(interpolableValue).value(), type);
      return BasicComponentTransferFilterOperation::create(value, type);
    }

    case FilterOperation::BLUR: {
      Length stdDeviation = LengthInterpolationFunctions::createLength(
          interpolableValue, nonInterpolableValue.typeNonInterpolableValue(),
          state.cssToLengthConversionData(), ValueRangeNonNegative);
      return BlurFilterOperation::create(stdDeviation);
    }

    case FilterOperation::DROP_SHADOW: {
      ShadowData shadowData = ShadowInterpolationFunctions::createShadowData(
          interpolableValue, nonInterpolableValue.typeNonInterpolableValue(),
          state);
      Color color = shadowData.color().isCurrentColor()
                        ? Color::black
                        : shadowData.color().getColor();
      return DropShadowFilterOperation::create(
          IntPoint(shadowData.x(), shadowData.y()), shadowData.blur(), color);
    }

    default:
      NOTREACHED();
      return nullptr;
  }
}
ShadowData ShadowData::blend(const ShadowData& from, double progress, const Color& currentColor) const
{
    ASSERT(style() == from.style());
    return ShadowData(blink::blend(from.location(), location(), progress),
        clampTo(blink::blend(from.blur(), blur(), progress), 0.0f),
        blink::blend(from.spread(), spread(), progress),
        style(),
        blink::blend(from.color().resolve(currentColor), color().resolve(currentColor), progress));
}
Esempio n. 3
0
ShadowData ShadowData::blend(const ShadowData& from, double progress) const
{
    if (style() != from.style())
        return *this;

    return ShadowData(WebCore::blend(from.location(), location(), progress),
        clampTo<int>(WebCore::blend(from.blur(), blur(), progress), 0),
        WebCore::blend(from.spread(), spread(), progress),
        style(),
        WebCore::blend(from.color(), color(), progress));
}