String CSSValue::cssText() const { if (m_isTextClone) { ASSERT(isCSSOMSafe()); return toTextCloneCSSValue(this)->cssText(); } ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); switch (classType()) { case AspectRatioClass: return toCSSAspectRatioValue(this)->customCSSText(); case BorderImageSliceClass: return toCSSBorderImageSliceValue(this)->customCSSText(); case FontClass: return toCSSFontValue(this)->customCSSText(); case FontFaceSrcClass: return toCSSFontFaceSrcValue(this)->customCSSText(); case FontFeatureClass: return toCSSFontFeatureValue(this)->customCSSText(); case FunctionClass: return toCSSFunctionValue(this)->customCSSText(); case LinearGradientClass: return toCSSLinearGradientValue(this)->customCSSText(); case RadialGradientClass: return toCSSRadialGradientValue(this)->customCSSText(); case CrossfadeClass: return toCSSCrossfadeValue(this)->customCSSText(); case ImageClass: return toCSSImageValue(this)->customCSSText(); case InheritedClass: return toCSSInheritedValue(this)->customCSSText(); case InitialClass: return toCSSInitialValue(this)->customCSSText(); case PrimitiveClass: return toCSSPrimitiveValue(this)->customCSSText(); case ShadowClass: return toCSSShadowValue(this)->customCSSText(); case CubicBezierTimingFunctionClass: return toCSSCubicBezierTimingFunctionValue(this)->customCSSText(); case StepsTimingFunctionClass: return toCSSStepsTimingFunctionValue(this)->customCSSText(); case UnicodeRangeClass: return toCSSUnicodeRangeValue(this)->customCSSText(); case ValueListClass: return toCSSValueList(this)->customCSSText(); case CSSTransformClass: return toCSSTransformValue(this)->customCSSText(); case LineBoxContainClass: return toCSSLineBoxContainValue(this)->customCSSText(); case CalculationClass: return toCSSCalcValue(this)->customCSSText(); case ImageSetClass: return toCSSImageSetValue(this)->customCSSText(); case CSSFilterClass: return toCSSFilterValue(this)->customCSSText(); } ASSERT_NOT_REACHED(); return String(); }
v8::Handle<v8::Object> wrap(CSSValue* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) { ASSERT(impl); if (impl->isTransformValue()) return wrap(toCSSTransformValue(impl), creationContext, isolate); if (impl->isFilterValue()) return wrap(toCSSFilterValue(impl), creationContext, isolate); if (impl->isValueList()) return wrap(toCSSValueList(impl), creationContext, isolate); if (impl->isPrimitiveValue()) return wrap(toCSSPrimitiveValue(impl), creationContext, isolate); return V8CSSValue::createWrapper(impl, creationContext, isolate); }
PassRefPtr<CSSValue> CSSValue::cloneForCSSOM() const { switch (classType()) { case PrimitiveClass: return toCSSPrimitiveValue(this)->cloneForCSSOM(); case ValueListClass: return toCSSValueList(this)->cloneForCSSOM(); case ImageClass: return toCSSImageValue(this)->cloneForCSSOM(); case CSSFilterClass: return toCSSFilterValue(this)->cloneForCSSOM(); case CSSTransformClass: return toCSSTransformValue(this)->cloneForCSSOM(); case ImageSetClass: return toCSSImageSetValue(this)->cloneForCSSOM(); default: ASSERT(!isSubtypeExposedToCSSOM()); return TextCloneCSSValue::create(classType(), cssText()); } }
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; float zoomFactor = unadjustedConversionData.zoom() * state.elementStyleResources().deviceScaleFactor(); 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::VALIDATED_CUSTOM) { // ValidatedCustomFilterOperation is not supposed to end up in the RenderStyle. ASSERT_NOT_REACHED(); continue; } if (operationType == FilterOperation::CUSTOM) { RefPtr<CustomFilterOperation> operation = createCustomFilterOperation(filterValue, state); if (!operation) return false; operations.operations().append(operation); continue; } 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(), 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; } // Check that all parameters are primitive values, with the // exception of drop shadow which has a CSSShadowValue parameter. 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); if (stdDeviation.isUndefined()) return false; 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; if (item->color) shadowColor = state.document().textLinkColors().colorFromPrimitiveValue(item->color.get(), state.style()->color()); operations.operations().append(DropShadowFilterOperation::create(location, blur, shadowColor.isValid() ? shadowColor : Color::transparent)); break; } case CSSFilterValue::UnknownFilterOperation: default: ASSERT_NOT_REACHED(); break; } } outOperations = operations; return true; }
void CSSValue::trace(Visitor* visitor) { if (m_isTextClone) { ASSERT(isCSSOMSafe()); toTextCloneCSSValue(this)->traceAfterDispatch(visitor); return; } ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); switch (classType()) { case AspectRatioClass: toCSSAspectRatioValue(this)->traceAfterDispatch(visitor); return; case BorderImageSliceClass: toCSSBorderImageSliceValue(this)->traceAfterDispatch(visitor); return; case CanvasClass: toCSSCanvasValue(this)->traceAfterDispatch(visitor); return; case CursorImageClass: toCSSCursorImageValue(this)->traceAfterDispatch(visitor); return; case FontClass: toCSSFontValue(this)->traceAfterDispatch(visitor); return; case FontFaceSrcClass: toCSSFontFaceSrcValue(this)->traceAfterDispatch(visitor); return; case FontFeatureClass: toCSSFontFeatureValue(this)->traceAfterDispatch(visitor); return; case FunctionClass: toCSSFunctionValue(this)->traceAfterDispatch(visitor); return; case LinearGradientClass: toCSSLinearGradientValue(this)->traceAfterDispatch(visitor); return; case RadialGradientClass: toCSSRadialGradientValue(this)->traceAfterDispatch(visitor); return; case CrossfadeClass: toCSSCrossfadeValue(this)->traceAfterDispatch(visitor); return; case ImageClass: toCSSImageValue(this)->traceAfterDispatch(visitor); return; case InheritedClass: toCSSInheritedValue(this)->traceAfterDispatch(visitor); return; case InitialClass: toCSSInitialValue(this)->traceAfterDispatch(visitor); return; case GridLineNamesClass: toCSSGridLineNamesValue(this)->traceAfterDispatch(visitor); return; case GridTemplateAreasClass: toCSSGridTemplateAreasValue(this)->traceAfterDispatch(visitor); return; case PrimitiveClass: toCSSPrimitiveValue(this)->traceAfterDispatch(visitor); return; case ShadowClass: toCSSShadowValue(this)->traceAfterDispatch(visitor); return; case CubicBezierTimingFunctionClass: toCSSCubicBezierTimingFunctionValue(this)->traceAfterDispatch(visitor); return; case StepsTimingFunctionClass: toCSSStepsTimingFunctionValue(this)->traceAfterDispatch(visitor); return; case UnicodeRangeClass: toCSSUnicodeRangeValue(this)->traceAfterDispatch(visitor); return; case ValueListClass: toCSSValueList(this)->traceAfterDispatch(visitor); return; case CSSTransformClass: toCSSTransformValue(this)->traceAfterDispatch(visitor); return; case LineBoxContainClass: toCSSLineBoxContainValue(this)->traceAfterDispatch(visitor); return; case CalculationClass: toCSSCalcValue(this)->traceAfterDispatch(visitor); return; case ImageSetClass: toCSSImageSetValue(this)->traceAfterDispatch(visitor); return; case CSSFilterClass: toCSSFilterValue(this)->traceAfterDispatch(visitor); return; } ASSERT_NOT_REACHED(); }