void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); if (m_error) return; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. ASSERT(src); ASSERT(src->isValueList()); CSSValueList* srcList = toCSSValueList(src.get()); int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { FontLoader* fontLoader = document->styleEngine()->fontSelector()->fontLoader(); #if ENABLE(SVG_FONTS) if (foundSVGFont) { source = adoptPtrWillBeNoop(new SVGRemoteFontFaceSource(item->resource(), fetched, fontLoader)); } else #endif { source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched, fontLoader)); } } } } else { #if ENABLE(SVG_FONTS) if (item->svgFontFaceElement()) { RefPtrWillBeRawPtr<SVGFontFaceElement> fontfaceElement = item->svgFontFaceElement(); // SVGFontFaceSource assumes that it is the case where <font-face> element resides in the same document. // We put a RELEASE_ASSERT here as it will cause UAF if the assumption is false. RELEASE_ASSERT(fontfaceElement->inDocument()); RELEASE_ASSERT(fontfaceElement->document() == document); source = adoptPtrWillBeNoop(new SVGFontFaceSource(fontfaceElement.get())); } else #endif { source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource())); } } if (source) m_cssFontFace->addSource(source.release()); } }
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); if (m_error) return; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. ASSERT(src); ASSERT(src->isValueList()); CSSValueList* srcList = toCSSValueList(src.get()); int srcLength = srcList->length(); for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr; if (!item->isLocal()) { const Settings* settings = document ? document->settings() : nullptr; bool allowDownloading = settings && settings->downloadableBinaryFontsEnabled(); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { FontLoader* fontLoader = document->styleEngine().fontSelector()->fontLoader(); source = adoptPtrWillBeNoop(new RemoteFontFaceSource(fetched, fontLoader)); } } } else { source = adoptPtrWillBeNoop(new LocalFontFaceSource(item->resource())); } if (source) m_cssFontFace->addSource(source.release()); } }
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(); }
PassRefPtr<CSSFontFace> FontFace::createCSSFontFace(Document* document) { RefPtr<CSSFontFace> cssFontFace = CSSFontFace::create(this); // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. CSSValueList* srcList = toCSSValueList(m_src.get()); int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i)); OwnPtr<CSSFontFaceSource> source; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { source = adoptPtr(new CSSFontFaceSource(item->resource(), fetched)); #if ENABLE(SVG_FONTS) if (foundSVGFont) source->setHasExternalSVGFont(true); #endif } } } else { source = adoptPtr(new CSSFontFaceSource(item->resource())); } if (source) { #if ENABLE(SVG_FONTS) source->setSVGFontFaceElement(item->svgFontFaceElement()); #endif cssFontFace->addSource(source.release()); } } if (CSSValueList* rangeList = toCSSValueList(m_unicodeRange.get())) { unsigned numRanges = rangeList->length(); for (unsigned i = 0; i < numRanges; i++) { CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->itemWithoutBoundsCheck(i)); cssFontFace->ranges().add(range->from(), range->to()); } } return cssFontFace; }
bool CSSValue::hasFailedOrCanceledSubresources() const { if (isValueList()) return toCSSValueList(this)->hasFailedOrCanceledSubresources(); if (getClassType() == FontFaceSrcClass) return toCSSFontFaceSrcValue(this)->hasFailedOrCanceledSubresources(); if (getClassType() == ImageClass) return toCSSImageValue(this)->hasFailedOrCanceledSubresources(); if (getClassType() == CrossfadeClass) return toCSSCrossfadeValue(this)->hasFailedOrCanceledSubresources(); if (getClassType() == ImageSetClass) return toCSSImageSetValue(this)->hasFailedOrCanceledSubresources(); return false; }
void CSSValue::addSubresourceStyleURLs(ListHashSet<URL>& urls, const StyleSheetContents* styleSheet) const { // This should get called for internal instances only. ASSERT(!isCSSOMSafe()); if (isPrimitiveValue()) toCSSPrimitiveValue(this)->addSubresourceStyleURLs(urls, styleSheet); else if (isValueList()) toCSSValueList(this)->addSubresourceStyleURLs(urls, styleSheet); else if (classType() == FontFaceSrcClass) toCSSFontFaceSrcValue(this)->addSubresourceStyleURLs(urls, styleSheet); else if (classType() == ReflectClass) toCSSReflectValue(this)->addSubresourceStyleURLs(urls, styleSheet); }
void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSValue> src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. CSSValueList* srcList = toCSSValueList(src.get()); int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i)); OwnPtr<CSSFontFaceSource> source; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = document ? document->frame() ? document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { #if ENABLE(SVG_FONTS) if (foundSVGFont) { source = adoptPtr(new SVGRemoteFontFaceSource(item->resource(), fetched)); } else #endif { source = adoptPtr(new RemoteFontFaceSource(fetched)); } } } } else { #if ENABLE(SVG_FONTS) if (item->svgFontFaceElement()) { source = adoptPtr(new SVGFontFaceSource(item->svgFontFaceElement())); } else #endif { source = adoptPtr(new LocalFontFaceSource(item->resource())); } } if (source) m_cssFontFace->addSource(source.release()); } }
bool CSSValue::hasFailedOrCanceledSubresources() const { // This should get called for internal instances only. ASSERT(!isCSSOMSafe()); if (isValueList()) return toCSSValueList(this)->hasFailedOrCanceledSubresources(); if (classType() == FontFaceSrcClass) return toCSSFontFaceSrcValue(this)->hasFailedOrCanceledSubresources(); if (classType() == ImageClass) return toCSSImageValue(this)->hasFailedOrCanceledSubresources(); if (classType() == CrossfadeClass) return toCSSCrossfadeValue(this)->hasFailedOrCanceledSubresources(); if (classType() == ImageSetClass) return toCSSImageSetValue(this)->hasFailedOrCanceledSubresources(); return false; }
void SVGFontFaceElement::rebuildFontFace() { if (!inDocument()) { ASSERT(!m_fontElement); return; } bool describesParentFont = isSVGFontElement(*parentNode()); RefPtrWillBeRawPtr<CSSValueList> list = nullptr; if (describesParentFont) { m_fontElement = toSVGFontElement(parentNode()); list = CSSValueList::createCommaSeparated(); list->append(CSSFontFaceSrcValue::createLocal(fontFamily())); } else { m_fontElement = nullptr; // we currently ignore all but the last src element, alternatively we could concat them if (SVGFontFaceSrcElement* element = Traversal<SVGFontFaceSrcElement>::lastChild(*this)) list = element->srcValue(); } if (!list || !list->length()) return; // Parse in-memory CSS rules m_fontFaceRule->mutableProperties().addParsedProperty(CSSProperty(CSSPropertySrc, list)); if (describesParentFont) { // Traverse parsed CSS values and associate CSSFontFaceSrcValue elements with ourselves. RefPtrWillBeRawPtr<CSSValue> src = m_fontFaceRule->properties().getPropertyCSSValue(CSSPropertySrc); CSSValueList* srcList = toCSSValueList(src.get()); unsigned srcLength = srcList ? srcList->length() : 0; for (unsigned i = 0; i < srcLength; i++) { if (CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i))) item->setSVGFontFaceElement(this); } } document().styleResolverChanged(); }
void FontFace::initCSSFontFace(Document* document, CSSValue* src) { m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); if (m_error) return; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. ASSERT(src); ASSERT(src->isValueList()); CSSValueList* srcList = toCSSValueList(src); int srcLength = srcList->length(); for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)); CSSFontFaceSource* source = nullptr; if (!item->isLocal()) { const Settings* settings = document ? document->settings() : nullptr; bool allowDownloading = settings && settings->downloadableBinaryFontsEnabled(); if (allowDownloading && item->isSupportedFormat() && document) { FontResource* fetched = item->fetch(document); if (fetched) { CSSFontSelector* fontSelector = document->styleEngine().fontSelector(); source = new RemoteFontFaceSource(fetched, fontSelector, CSSValueToFontDisplay(m_display.get())); } } } else { source = new LocalFontFaceSource(item->resource()); } if (source) m_cssFontFace->addSource(source); } if (m_display) { DEFINE_STATIC_LOCAL(EnumerationHistogram, fontDisplayHistogram, ("WebFont.FontDisplayValue", FontDisplayEnumMax)); fontDisplayHistogram.count(CSSValueToFontDisplay(m_display.get())); } }
void PageSerializer::retrieveResourcesForCSSValue(CSSValue* cssValue, Document* document) { if (cssValue->isImageValue()) { CSSImageValue* imageValue = toCSSImageValue(cssValue); StyleImage* styleImage = imageValue->cachedOrPendingImage(); // Non cached-images are just place-holders and do not contain data. if (!styleImage || !styleImage->isImageResource()) return; addImageToResources(styleImage->cachedImage(), 0, styleImage->cachedImage()->url()); } else if (cssValue->isFontFaceSrcValue()) { CSSFontFaceSrcValue* fontFaceSrcValue = toCSSFontFaceSrcValue(cssValue); if (fontFaceSrcValue->isLocal()) { return; } addFontToResources(fontFaceSrcValue->fetch(document)); } else if (cssValue->isValueList()) { CSSValueList* cssValueList = toCSSValueList(cssValue); for (unsigned i = 0; i < cssValueList->length(); i++) retrieveResourcesForCSSValue(cssValueList->item(i), document); } }
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(); }
void CSSValue::finalizeGarbageCollectedObject() { switch (getClassType()) { case BasicShapeCircleClass: toCSSBasicShapeCircleValue(this)->~CSSBasicShapeCircleValue(); return; case BasicShapeEllipseClass: toCSSBasicShapeEllipseValue(this)->~CSSBasicShapeEllipseValue(); return; case BasicShapePolygonClass: toCSSBasicShapePolygonValue(this)->~CSSBasicShapePolygonValue(); return; case BasicShapeInsetClass: toCSSBasicShapeInsetValue(this)->~CSSBasicShapeInsetValue(); return; case BorderImageSliceClass: toCSSBorderImageSliceValue(this)->~CSSBorderImageSliceValue(); return; case ColorClass: toCSSColorValue(this)->~CSSColorValue(); return; case CounterClass: toCSSCounterValue(this)->~CSSCounterValue(); return; case CursorImageClass: toCSSCursorImageValue(this)->~CSSCursorImageValue(); return; case FontFaceSrcClass: toCSSFontFaceSrcValue(this)->~CSSFontFaceSrcValue(); return; case FontFamilyClass: toCSSFontFamilyValue(this)->~CSSFontFamilyValue(); return; case FontFeatureClass: toCSSFontFeatureValue(this)->~CSSFontFeatureValue(); return; case FunctionClass: toCSSFunctionValue(this)->~CSSFunctionValue(); return; case LinearGradientClass: toCSSLinearGradientValue(this)->~CSSLinearGradientValue(); return; case RadialGradientClass: toCSSRadialGradientValue(this)->~CSSRadialGradientValue(); return; case CrossfadeClass: toCSSCrossfadeValue(this)->~CSSCrossfadeValue(); return; case PaintClass: toCSSPaintValue(this)->~CSSPaintValue(); return; case CustomIdentClass: toCSSCustomIdentValue(this)->~CSSCustomIdentValue(); return; case ImageClass: toCSSImageValue(this)->~CSSImageValue(); return; case InheritedClass: toCSSInheritedValue(this)->~CSSInheritedValue(); return; case InitialClass: toCSSInitialValue(this)->~CSSInitialValue(); return; case UnsetClass: toCSSUnsetValue(this)->~CSSUnsetValue(); return; case GridAutoRepeatClass: toCSSGridAutoRepeatValue(this)->~CSSGridAutoRepeatValue(); return; case GridLineNamesClass: toCSSGridLineNamesValue(this)->~CSSGridLineNamesValue(); return; case GridTemplateAreasClass: toCSSGridTemplateAreasValue(this)->~CSSGridTemplateAreasValue(); return; case PathClass: toCSSPathValue(this)->~CSSPathValue(); return; case PrimitiveClass: toCSSPrimitiveValue(this)->~CSSPrimitiveValue(); return; case IdentifierClass: toCSSIdentifierValue(this)->~CSSIdentifierValue(); return; case QuadClass: toCSSQuadValue(this)->~CSSQuadValue(); return; case ReflectClass: toCSSReflectValue(this)->~CSSReflectValue(); return; case ShadowClass: toCSSShadowValue(this)->~CSSShadowValue(); return; case StringClass: toCSSStringValue(this)->~CSSStringValue(); return; case CubicBezierTimingFunctionClass: toCSSCubicBezierTimingFunctionValue(this) ->~CSSCubicBezierTimingFunctionValue(); return; case StepsTimingFunctionClass: toCSSStepsTimingFunctionValue(this)->~CSSStepsTimingFunctionValue(); return; case UnicodeRangeClass: toCSSUnicodeRangeValue(this)->~CSSUnicodeRangeValue(); return; case URIClass: toCSSURIValue(this)->~CSSURIValue(); return; case ValueListClass: toCSSValueList(this)->~CSSValueList(); return; case ValuePairClass: toCSSValuePair(this)->~CSSValuePair(); return; case ImageSetClass: toCSSImageSetValue(this)->~CSSImageSetValue(); return; case CSSContentDistributionClass: toCSSContentDistributionValue(this)->~CSSContentDistributionValue(); return; case VariableReferenceClass: toCSSVariableReferenceValue(this)->~CSSVariableReferenceValue(); return; case CustomPropertyDeclarationClass: toCSSCustomPropertyDeclaration(this)->~CSSCustomPropertyDeclaration(); return; case PendingSubstitutionValueClass: toCSSPendingSubstitutionValue(this)->~CSSPendingSubstitutionValue(); return; } ASSERT_NOT_REACHED(); }
String CSSValue::cssText() const { if (m_isTextClone) { ASSERT(isCSSOMSafe()); return static_cast<const TextCloneCSSValue*>(this)->cssText(); } ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); switch (classType()) { case AspectRatioClass: return toCSSAspectRatioValue(this)->customCSSText(); case BorderImageSliceClass: return toCSSBorderImageSliceValue(this)->customCSSText(); case CanvasClass: return toCSSCanvasValue(this)->customCSSText(); case CursorImageClass: return toCSSCursorImageValue(this)->customCSSText(); #if ENABLE(CSS_FILTERS) case FilterImageClass: return toCSSFilterImageValue(this)->customCSSText(); #endif 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(); #if ENABLE(CSS_GRID_LAYOUT) case GridLineNamesClass: return toCSSGridLineNamesValue(this)->customCSSText(); case GridTemplateAreasClass: return toCSSGridTemplateAreasValue(this)->customCSSText(); #endif case PrimitiveClass: return toCSSPrimitiveValue(this)->customCSSText(); case ReflectClass: return toCSSReflectValue(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 WebKitCSSTransformClass: return toWebKitCSSTransformValue(this)->customCSSText(); case LineBoxContainClass: return toCSSLineBoxContainValue(this)->customCSSText(); case CalculationClass: return toCSSCalcValue(this)->customCSSText(); #if ENABLE(CSS_IMAGE_SET) case ImageSetClass: return toCSSImageSetValue(this)->customCSSText(); #endif #if ENABLE(CSS_FILTERS) case WebKitCSSFilterClass: return toWebKitCSSFilterValue(this)->customCSSText(); #endif case SVGColorClass: return toSVGColor(this)->customCSSText(); case SVGPaintClass: return toSVGPaint(this)->customCSSText(); } ASSERT_NOT_REACHED(); return String(); }
void CSSValue::finalizeGarbageCollectedObject() { switch (classType()) { case BorderImageSliceClass: toCSSBorderImageSliceValue(this)->~CSSBorderImageSliceValue(); return; case CanvasClass: toCSSCanvasValue(this)->~CSSCanvasValue(); return; case CounterClass: toCSSCounterValue(this)->~CSSCounterValue(); return; case CursorImageClass: toCSSCursorImageValue(this)->~CSSCursorImageValue(); return; case FontFaceSrcClass: toCSSFontFaceSrcValue(this)->~CSSFontFaceSrcValue(); return; case FontFeatureClass: toCSSFontFeatureValue(this)->~CSSFontFeatureValue(); return; case FunctionClass: toCSSFunctionValue(this)->~CSSFunctionValue(); return; case LinearGradientClass: toCSSLinearGradientValue(this)->~CSSLinearGradientValue(); return; case RadialGradientClass: toCSSRadialGradientValue(this)->~CSSRadialGradientValue(); return; case CrossfadeClass: toCSSCrossfadeValue(this)->~CSSCrossfadeValue(); return; case ImageClass: toCSSImageValue(this)->~CSSImageValue(); return; case InheritedClass: toCSSInheritedValue(this)->~CSSInheritedValue(); return; case InitialClass: toCSSInitialValue(this)->~CSSInitialValue(); return; case UnsetClass: toCSSUnsetValue(this)->~CSSUnsetValue(); return; case GridLineNamesClass: toCSSGridLineNamesValue(this)->~CSSGridLineNamesValue(); return; case GridTemplateAreasClass: toCSSGridTemplateAreasValue(this)->~CSSGridTemplateAreasValue(); return; case PathClass: toCSSPathValue(this)->~CSSPathValue(); return; case PrimitiveClass: toCSSPrimitiveValue(this)->~CSSPrimitiveValue(); return; case QuadClass: toCSSQuadValue(this)->~CSSQuadValue(); return; case ReflectClass: toCSSReflectValue(this)->~CSSReflectValue(); return; case ShadowClass: toCSSShadowValue(this)->~CSSShadowValue(); return; case CubicBezierTimingFunctionClass: toCSSCubicBezierTimingFunctionValue(this)->~CSSCubicBezierTimingFunctionValue(); return; case StepsTimingFunctionClass: toCSSStepsTimingFunctionValue(this)->~CSSStepsTimingFunctionValue(); return; case UnicodeRangeClass: toCSSUnicodeRangeValue(this)->~CSSUnicodeRangeValue(); return; case ValueListClass: toCSSValueList(this)->~CSSValueList(); return; case ValuePairClass: toCSSValuePair(this)->~CSSValuePair(); return; case ImageSetClass: toCSSImageSetValue(this)->~CSSImageSetValue(); return; case CSSSVGDocumentClass: toCSSSVGDocumentValue(this)->~CSSSVGDocumentValue(); return; case CSSContentDistributionClass: toCSSContentDistributionValue(this)->~CSSContentDistributionValue(); return; } ASSERT_NOT_REACHED(); }
void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule) { // Obtain the font-family property and the src property. Both must be defined. const StylePropertySet& style = fontFaceRule->properties(); RefPtr<CSSValue> fontFamily = style.getPropertyCSSValue(CSSPropertyFontFamily); RefPtr<CSSValue> src = style.getPropertyCSSValue(CSSPropertySrc); RefPtr<CSSValue> unicodeRange = style.getPropertyCSSValue(CSSPropertyUnicodeRange); if (!fontFamily || !src || !fontFamily->isValueList() || !src->isValueList() || (unicodeRange && !unicodeRange->isValueList())) return; CSSValueList* familyList = toCSSValueList(fontFamily.get()); if (!familyList->length()) return; CSSValueList* srcList = toCSSValueList(src.get()); if (!srcList->length()) return; CSSValueList* rangeList = toCSSValueList(unicodeRange.get()); unsigned traitsMask = 0; if (RefPtr<CSSValue> fontStyle = style.getPropertyCSSValue(CSSPropertyFontStyle)) { if (!fontStyle->isPrimitiveValue()) return; switch (toCSSPrimitiveValue(fontStyle.get())->getValueID()) { case CSSValueNormal: traitsMask |= FontStyleNormalMask; break; case CSSValueItalic: case CSSValueOblique: traitsMask |= FontStyleItalicMask; break; default: break; } } else traitsMask |= FontStyleNormalMask; if (RefPtr<CSSValue> fontWeight = style.getPropertyCSSValue(CSSPropertyFontWeight)) { if (!fontWeight->isPrimitiveValue()) return; switch (toCSSPrimitiveValue(fontWeight.get())->getValueID()) { case CSSValueBold: case CSSValue700: traitsMask |= FontWeight700Mask; break; case CSSValueNormal: case CSSValue400: traitsMask |= FontWeight400Mask; break; case CSSValue900: traitsMask |= FontWeight900Mask; break; case CSSValue800: traitsMask |= FontWeight800Mask; break; case CSSValue600: traitsMask |= FontWeight600Mask; break; case CSSValue500: traitsMask |= FontWeight500Mask; break; case CSSValue300: traitsMask |= FontWeight300Mask; break; case CSSValue200: traitsMask |= FontWeight200Mask; break; case CSSValue100: traitsMask |= FontWeight100Mask; break; default: break; } } else traitsMask |= FontWeight400Mask; if (RefPtr<CSSValue> fontVariant = style.getPropertyCSSValue(CSSPropertyFontVariant)) { // font-variant descriptor can be a value list. if (fontVariant->isPrimitiveValue()) { RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); list->append(fontVariant); fontVariant = list; } else if (!fontVariant->isValueList()) return; CSSValueList* variantList = toCSSValueList(fontVariant.get()); unsigned numVariants = variantList->length(); if (!numVariants) return; for (unsigned i = 0; i < numVariants; ++i) { switch (toCSSPrimitiveValue(variantList->itemWithoutBoundsCheck(i))->getValueID()) { case CSSValueNormal: traitsMask |= FontVariantNormalMask; break; case CSSValueSmallCaps: traitsMask |= FontVariantSmallCapsMask; break; default: break; } } } else traitsMask |= FontVariantMask; // Each item in the src property's list is a single CSSFontFaceSource. Put them all into a CSSFontFace. RefPtr<CSSFontFace> fontFace; int srcLength = srcList->length(); bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { // An item in the list either specifies a string (local font name) or a URL (remote font to download). CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i)); OwnPtr<CSSFontFaceSource> source; #if ENABLE(SVG_FONTS) foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); #endif if (!item->isLocal()) { Settings* settings = m_document ? m_document->frame() ? &m_document->frame()->settings() : 0 : 0; bool allowDownloading = foundSVGFont || (settings && settings->downloadableBinaryFontsEnabled()); if (allowDownloading && item->isSupportedFormat() && m_document) { CachedFont* cachedFont = item->cachedFont(m_document); if (cachedFont) { source = adoptPtr(new CSSFontFaceSource(item->resource(), cachedFont)); #if ENABLE(SVG_FONTS) if (foundSVGFont) source->setHasExternalSVGFont(true); #endif } } } else { source = adoptPtr(new CSSFontFaceSource(item->resource())); } if (!fontFace) { RefPtr<CSSFontFaceRule> rule; #if ENABLE(FONT_LOAD_EVENTS) // FIXME: https://bugs.webkit.org/show_bug.cgi?id=112116 - This CSSFontFaceRule has no parent. if (RuntimeEnabledFeatures::sharedFeatures().fontLoadEventsEnabled()) rule = static_pointer_cast<CSSFontFaceRule>(fontFaceRule->createCSSOMWrapper()); #endif fontFace = CSSFontFace::create(static_cast<FontTraitsMask>(traitsMask), rule); } if (source) { #if ENABLE(SVG_FONTS) source->setSVGFontFaceElement(item->svgFontFaceElement()); #endif fontFace->addSource(source.release()); } } ASSERT(fontFace); if (fontFace && !fontFace->isValid()) return; if (rangeList) { unsigned numRanges = rangeList->length(); for (unsigned i = 0; i < numRanges; i++) { CSSUnicodeRangeValue* range = static_cast<CSSUnicodeRangeValue*>(rangeList->itemWithoutBoundsCheck(i)); fontFace->addRange(range->from(), range->to()); } } // Hash under every single family name. int familyLength = familyList->length(); for (int i = 0; i < familyLength; i++) { CSSPrimitiveValue* item = toCSSPrimitiveValue(familyList->itemWithoutBoundsCheck(i)); String familyName; if (item->isString()) { familyName = item->getStringValue(); } else if (item->isValueID()) { // We need to use the raw text for all the generic family types, since @font-face is a way of actually // defining what font to use for those types. switch (item->getValueID()) { case CSSValueSerif: familyName = serifFamily; break; case CSSValueSansSerif: familyName = sansSerifFamily; break; case CSSValueCursive: familyName = cursiveFamily; break; case CSSValueFantasy: familyName = fantasyFamily; break; case CSSValueMonospace: familyName = monospaceFamily; break; case CSSValueWebkitPictograph: familyName = pictographFamily; break; default: break; } } if (familyName.isEmpty()) continue; OwnPtr<Vector<RefPtr<CSSFontFace> > >& familyFontFaces = m_fontFaces.add(familyName, nullptr).iterator->value; if (!familyFontFaces) { familyFontFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >); ASSERT(!m_locallyInstalledFontFaces.contains(familyName)); Vector<unsigned> locallyInstalledFontsTraitsMasks; fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTraitsMasks); if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsMasks.size()) { OwnPtr<Vector<RefPtr<CSSFontFace> > > familyLocallyInstalledFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >); for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) { RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace::create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), 0, true); locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFaceSource(familyName))); ASSERT(locallyInstalledFontFace->isValid()); familyLocallyInstalledFaces->append(locallyInstalledFontFace); } m_locallyInstalledFontFaces.set(familyName, familyLocallyInstalledFaces.release()); } } familyFontFaces->append(fontFace); ++m_version; } }
void CSSValue::destroy() { if (m_isTextClone) { ASSERT(isCSSOMSafe()); delete static_cast<TextCloneCSSValue*>(this); return; } ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); switch (classType()) { case AspectRatioClass: delete toCSSAspectRatioValue(this); return; case BorderImageSliceClass: delete toCSSBorderImageSliceValue(this); return; case CanvasClass: delete toCSSCanvasValue(this); return; case CursorImageClass: delete toCSSCursorImageValue(this); return; case FontClass: delete toCSSFontValue(this); return; case FontFaceSrcClass: delete toCSSFontFaceSrcValue(this); return; case FontFeatureClass: delete toCSSFontFeatureValue(this); return; case FunctionClass: delete toCSSFunctionValue(this); return; case LinearGradientClass: delete toCSSLinearGradientValue(this); return; case RadialGradientClass: delete toCSSRadialGradientValue(this); return; case CrossfadeClass: delete toCSSCrossfadeValue(this); return; case ImageClass: delete toCSSImageValue(this); return; case InheritedClass: delete toCSSInheritedValue(this); return; case InitialClass: delete toCSSInitialValue(this); return; case GridTemplateClass: delete toCSSGridTemplateValue(this); return; case PrimitiveClass: delete toCSSPrimitiveValue(this); return; case ReflectClass: delete toCSSReflectValue(this); return; case ShadowClass: delete toCSSShadowValue(this); return; case CubicBezierTimingFunctionClass: delete toCSSCubicBezierTimingFunctionValue(this); return; case StepsTimingFunctionClass: delete toCSSStepsTimingFunctionValue(this); return; case UnicodeRangeClass: delete toCSSUnicodeRangeValue(this); return; case ValueListClass: delete toCSSValueList(this); return; case WebKitCSSTransformClass: delete toWebKitCSSTransformValue(this); return; case LineBoxContainClass: delete toCSSLineBoxContainValue(this); return; case CalculationClass: delete toCSSCalcValue(this); return; #if ENABLE(CSS_IMAGE_SET) case ImageSetClass: delete toCSSImageSetValue(this); return; #endif #if ENABLE(CSS_FILTERS) case FilterImageClass: delete toCSSFilterImageValue(this); return; case WebKitCSSFilterClass: delete toWebKitCSSFilterValue(this); return; #if ENABLE(CSS_SHADERS) case WebKitCSSArrayFunctionValueClass: delete toWebKitCSSArrayFunctionValue(this); return; case WebKitCSSMatFunctionValueClass: delete toWebKitCSSMatFunctionValue(this); return; case WebKitCSSMixFunctionValueClass: delete toWebKitCSSMixFunctionValue(this); return; case WebKitCSSShaderClass: delete toWebKitCSSShaderValue(this); return; #endif #endif #if ENABLE(SVG) case SVGColorClass: delete toSVGColor(this); return; case SVGPaintClass: delete toSVGPaint(this); return; case WebKitCSSSVGDocumentClass: delete toWebKitCSSSVGDocumentValue(this); return; #endif } ASSERT_NOT_REACHED(); }