This source file includes following definitions.
- filterOperationForType
- createFilterOperations
#include "config.h"
#include "core/css/resolver/FilterOperationResolver.h"
#include "core/css/CSSFilterValue.h"
#include "core/css/parser/BisonCSSParser.h"
#include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSShadowValue.h"
#include "core/css/resolver/TransformBuilder.h"
#include "core/rendering/svg/ReferenceFilterBuilder.h"
#include "core/svg/SVGURIReference.h"
namespace WebCore {
static FilterOperation::OperationType filterOperationForType(CSSFilterValue::FilterOperationType type)
{
switch (type) {
case CSSFilterValue::ReferenceFilterOperation:
return FilterOperation::REFERENCE;
case CSSFilterValue::GrayscaleFilterOperation:
return FilterOperation::GRAYSCALE;
case CSSFilterValue::SepiaFilterOperation:
return FilterOperation::SEPIA;
case CSSFilterValue::SaturateFilterOperation:
return FilterOperation::SATURATE;
case CSSFilterValue::HueRotateFilterOperation:
return FilterOperation::HUE_ROTATE;
case CSSFilterValue::InvertFilterOperation:
return FilterOperation::INVERT;
case CSSFilterValue::OpacityFilterOperation:
return FilterOperation::OPACITY;
case CSSFilterValue::BrightnessFilterOperation:
return FilterOperation::BRIGHTNESS;
case CSSFilterValue::ContrastFilterOperation:
return FilterOperation::CONTRAST;
case CSSFilterValue::BlurFilterOperation:
return FilterOperation::BLUR;
case CSSFilterValue::DropShadowFilterOperation:
return FilterOperation::DROP_SHADOW;
case CSSFilterValue::UnknownFilterOperation:
return FilterOperation::NONE;
}
return FilterOperation::NONE;
}
bool FilterOperationResolver::createFilterOperations(CSSValue* inValue, const CSSToLengthConversionData& unadjustedConversionData, FilterOperations& outOperations, StyleResolverState& state)
{
ASSERT(outOperations.isEmpty());
if (!inValue)
return false;
if (inValue->isPrimitiveValue()) {
CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(inValue);
if (primitiveValue->getValueID() == CSSValueNone)
return true;
}
if (!inValue->isValueList())
return false;
#ifdef BLINK_SCALE_FILTERS_AT_RECORD_TIME
float zoomFactor = unadjustedConversionData.zoom() * state.elementStyleResources().deviceScaleFactor();
#else
float zoomFactor = unadjustedConversionData.zoom();
#endif
const CSSToLengthConversionData& conversionData = unadjustedConversionData.copyWithAdjustedZoom(zoomFactor);
FilterOperations operations;
for (CSSValueListIterator i = inValue; i.hasMore(); i.advance()) {
CSSValue* currValue = i.value();
if (!currValue->isFilterValue())
continue;
CSSFilterValue* filterValue = toCSSFilterValue(i.value());
FilterOperation::OperationType operationType = filterOperationForType(filterValue->operationType());
if (operationType == FilterOperation::REFERENCE) {
if (filterValue->length() != 1)
continue;
CSSValue* argument = filterValue->itemWithoutBoundsCheck(0);
if (!argument->isSVGDocumentValue())
continue;
CSSSVGDocumentValue* svgDocumentValue = toCSSSVGDocumentValue(argument);
KURL url = state.document().completeURL(svgDocumentValue->url());
RefPtr<ReferenceFilterOperation> operation = ReferenceFilterOperation::create(svgDocumentValue->url(), AtomicString(url.fragmentIdentifier()));
if (SVGURIReference::isExternalURIReference(svgDocumentValue->url(), state.document())) {
if (!svgDocumentValue->loadRequested())
state.elementStyleResources().addPendingSVGDocument(operation.get(), svgDocumentValue);
else if (svgDocumentValue->cachedSVGDocument())
ReferenceFilterBuilder::setDocumentResourceReference(operation.get(), adoptPtr(new DocumentResourceReference(svgDocumentValue->cachedSVGDocument())));
}
operations.operations().append(operation);
continue;
}
if (operationType != FilterOperation::DROP_SHADOW) {
bool haveNonPrimitiveValue = false;
for (unsigned j = 0; j < filterValue->length(); ++j) {
if (!filterValue->itemWithoutBoundsCheck(j)->isPrimitiveValue()) {
haveNonPrimitiveValue = true;
break;
}
}
if (haveNonPrimitiveValue)
continue;
}
CSSPrimitiveValue* firstValue = filterValue->length() && filterValue->itemWithoutBoundsCheck(0)->isPrimitiveValue() ? toCSSPrimitiveValue(filterValue->itemWithoutBoundsCheck(0)) : 0;
switch (filterValue->operationType()) {
case CSSFilterValue::GrayscaleFilterOperation:
case CSSFilterValue::SepiaFilterOperation:
case CSSFilterValue::SaturateFilterOperation: {
double amount = 1;
if (filterValue->length() == 1) {
amount = firstValue->getDoubleValue();
if (firstValue->isPercentage())
amount /= 100;
}
operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType));
break;
}
case CSSFilterValue::HueRotateFilterOperation: {
double angle = 0;
if (filterValue->length() == 1)
angle = firstValue->computeDegrees();
operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType));
break;
}
case CSSFilterValue::InvertFilterOperation:
case CSSFilterValue::BrightnessFilterOperation:
case CSSFilterValue::ContrastFilterOperation:
case CSSFilterValue::OpacityFilterOperation: {
double amount = (filterValue->operationType() == CSSFilterValue::BrightnessFilterOperation) ? 0 : 1;
if (filterValue->length() == 1) {
amount = firstValue->getDoubleValue();
if (firstValue->isPercentage())
amount /= 100;
}
operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType));
break;
}
case CSSFilterValue::BlurFilterOperation: {
Length stdDeviation = Length(0, Fixed);
if (filterValue->length() >= 1)
stdDeviation = firstValue->convertToLength<FixedConversion | PercentConversion>(conversionData);
operations.operations().append(BlurFilterOperation::create(stdDeviation));
break;
}
case CSSFilterValue::DropShadowFilterOperation: {
if (filterValue->length() != 1)
return false;
CSSValue* cssValue = filterValue->itemWithoutBoundsCheck(0);
if (!cssValue->isShadowValue())
continue;
CSSShadowValue* item = toCSSShadowValue(cssValue);
IntPoint location(item->x->computeLength<int>(conversionData), item->y->computeLength<int>(conversionData));
int blur = item->blur ? item->blur->computeLength<int>(conversionData) : 0;
Color shadowColor = Color::transparent;
if (item->color)
shadowColor = state.document().textLinkColors().colorFromPrimitiveValue(item->color.get(), state.style()->color());
operations.operations().append(DropShadowFilterOperation::create(location, blur, shadowColor));
break;
}
case CSSFilterValue::UnknownFilterOperation:
default:
ASSERT_NOT_REACHED();
break;
}
}
outOperations = operations;
return true;
}
}