void CSSToStyleMap::mapNinePieceImage(StyleResolverState& state, CSSPropertyID property, CSSValue* value, NinePieceImage& image) { // If we're not a value list, then we are "none" and don't need to alter the empty image at all. if (!value || !value->isValueList()) return; // Retrieve the border image value. CSSValueList* borderImage = toCSSValueList(value); // Set the image (this kicks off the load). CSSPropertyID imageProperty; if (property == CSSPropertyWebkitBorderImage) imageProperty = CSSPropertyBorderImageSource; else if (property == CSSPropertyWebkitMaskBoxImage) imageProperty = CSSPropertyWebkitMaskBoxImageSource; else imageProperty = property; for (unsigned i = 0 ; i < borderImage->length() ; ++i) { CSSValue* current = borderImage->item(i); if (current->isImageValue() || current->isImageGeneratorValue() || current->isImageSetValue()) image.setImage(state.styleImage(imageProperty, current)); else if (current->isBorderImageSliceValue()) mapNinePieceImageSlice(state, current, image); else if (current->isValueList()) { CSSValueList* slashList = toCSSValueList(current); size_t length = slashList->length(); // Map in the image slices. if (length && slashList->item(0)->isBorderImageSliceValue()) mapNinePieceImageSlice(state, slashList->item(0), image); // Map in the border slices. if (length > 1) image.setBorderSlices(mapNinePieceImageQuad(state, slashList->item(1))); // Map in the outset. if (length > 2) image.setOutset(mapNinePieceImageQuad(state, slashList->item(2))); } else if (current->isPrimitiveValue()) { // Set the appropriate rules for stretch/round/repeat of the slices. mapNinePieceImageRepeat(state, current, image); } } if (property == CSSPropertyWebkitBorderImage) { // We have to preserve the legacy behavior of -webkit-border-image and make the border slices // also set the border widths. We don't need to worry about percentages, since we don't even support // those on real borders yet. if (image.borderSlices().top().isLength() && image.borderSlices().top().length().isFixed()) state.style()->setBorderTopWidth(image.borderSlices().top().length().value()); if (image.borderSlices().right().isLength() && image.borderSlices().right().length().isFixed()) state.style()->setBorderRightWidth(image.borderSlices().right().length().value()); if (image.borderSlices().bottom().isLength() && image.borderSlices().bottom().length().isFixed()) state.style()->setBorderBottomWidth(image.borderSlices().bottom().length().value()); if (image.borderSlices().left().isLength() && image.borderSlices().left().length().isFixed()) state.style()->setBorderLeftWidth(image.borderSlices().left().length().value()); } }
void StyleBuilderFunctions::applyValueCSSPropertySize(StyleResolverState& state, CSSValue* value) { state.style()->resetPageSizeType(); FloatSize size; PageSizeType pageSizeType = PAGE_SIZE_AUTO; CSSValueList* list = toCSSValueList(value); if (list->length() == 2) { // <length>{2} | <page-size> <orientation> CSSPrimitiveValue* first = toCSSPrimitiveValue(list->item(0)); CSSPrimitiveValue* second = toCSSPrimitiveValue(list->item(1)); if (first->isLength()) { // <length>{2} size = FloatSize(first->computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0)), second->computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0))); } else { // <page-size> <orientation> size = getPageSizeFromName(first); ASSERT(second->getValueID() == CSSValueLandscape || second->getValueID() == CSSValuePortrait); if (second->getValueID() == CSSValueLandscape) size = size.transposedSize(); } pageSizeType = PAGE_SIZE_RESOLVED; } else { ASSERT(list->length() == 1); // <length> | auto | <page-size> | [ portrait | landscape] CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(list->item(0)); if (primitiveValue->isLength()) { // <length> pageSizeType = PAGE_SIZE_RESOLVED; float width = primitiveValue->computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0)); size = FloatSize(width, width); } else { switch (primitiveValue->getValueID()) { case CSSValueAuto: pageSizeType = PAGE_SIZE_AUTO; break; case CSSValuePortrait: pageSizeType = PAGE_SIZE_AUTO_PORTRAIT; break; case CSSValueLandscape: pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE; break; default: // <page-size> pageSizeType = PAGE_SIZE_RESOLVED; size = getPageSizeFromName(primitiveValue); } } } state.style()->setPageSizeType(pageSizeType); state.style()->setPageSize(size); }
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()); } }
void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextEmphasisStyle(StyleResolverState& state, CSSValue* value) { if (value->isValueList()) { CSSValueList* list = toCSSValueList(value); ASSERT(list->length() == 2); for (unsigned i = 0; i < 2; ++i) { CSSPrimitiveValue* value = toCSSPrimitiveValue(list->item(i)); if (value->getValueID() == CSSValueFilled || value->getValueID() == CSSValueOpen) state.style()->setTextEmphasisFill(*value); else state.style()->setTextEmphasisMark(*value); } state.style()->setTextEmphasisCustomMark(nullAtom); return; } CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->isString()) { state.style()->setTextEmphasisFill(TextEmphasisFillFilled); state.style()->setTextEmphasisMark(TextEmphasisMarkCustom); state.style()->setTextEmphasisCustomMark(AtomicString(primitiveValue->getStringValue())); return; } state.style()->setTextEmphasisCustomMark(nullAtom); if (primitiveValue->getValueID() == CSSValueFilled || primitiveValue->getValueID() == CSSValueOpen) { state.style()->setTextEmphasisFill(*primitiveValue); state.style()->setTextEmphasisMark(TextEmphasisMarkAuto); } else { state.style()->setTextEmphasisFill(TextEmphasisFillFilled); state.style()->setTextEmphasisMark(*primitiveValue); } }
void StyleBuilderFunctions::applyValueCSSPropertyMotionRotation(StyleResolverState& state, CSSValue* value) { float rotation = 0; MotionRotationType rotationType = MotionRotationFixed; ASSERT(value->isValueList()); CSSValueList* list = toCSSValueList(value); int len = list->length(); for (int i = 0; i < len; i++) { CSSValue* item = list->item(i); ASSERT(item->isPrimitiveValue()); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(item); if (primitiveValue->getValueID() == CSSValueAuto) { rotationType = MotionRotationAuto; } else if (primitiveValue->getValueID() == CSSValueReverse) { rotationType = MotionRotationAuto; rotation += 180; } else { rotation += primitiveValue->computeDegrees(); } } state.style()->setMotionRotation(rotation); state.style()->setMotionRotationType(rotationType); }
PassRefPtr<QuotesData> StyleBuilderConverter::convertQuotes(StyleResolverState&, CSSValue* value) { if (value->isValueList()) { CSSValueList* list = toCSSValueList(value); RefPtr<QuotesData> quotes = QuotesData::create(); for (size_t i = 0; i < list->length(); i += 2) { CSSValue* first = list->item(i); CSSValue* second = list->item(i + 1); String startQuote = toCSSPrimitiveValue(first)->getStringValue(); String endQuote = toCSSPrimitiveValue(second)->getStringValue(); quotes->addPair(std::make_pair(startQuote, endQuote)); } return quotes.release(); } // FIXME: We should assert we're a primitive value with valueID = CSSValueNone return QuotesData::create(); }
void StyleBuilderFunctions::applyValueCSSPropertyTransformOrigin(StyleResolverState& state, CSSValue* value) { CSSValueList* list = toCSSValueList(value); ASSERT(list->length() == 3); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(list->item(0)); if (primitiveValue->isValueID()) { switch (primitiveValue->getValueID()) { case CSSValueLeft: state.style()->setTransformOriginX(Length(0, Percent)); break; case CSSValueRight: state.style()->setTransformOriginX(Length(100, Percent)); break; case CSSValueCenter: state.style()->setTransformOriginX(Length(50, Percent)); break; default: ASSERT_NOT_REACHED(); } } else { state.style()->setTransformOriginX(StyleBuilderConverter::convertLength(state, primitiveValue)); } primitiveValue = toCSSPrimitiveValue(list->item(1)); if (primitiveValue->isValueID()) { switch (primitiveValue->getValueID()) { case CSSValueTop: state.style()->setTransformOriginY(Length(0, Percent)); break; case CSSValueBottom: state.style()->setTransformOriginY(Length(100, Percent)); break; case CSSValueCenter: state.style()->setTransformOriginY(Length(50, Percent)); break; default: ASSERT_NOT_REACHED(); } } else { state.style()->setTransformOriginY(StyleBuilderConverter::convertLength(state, primitiveValue)); } primitiveValue = toCSSPrimitiveValue(list->item(2)); state.style()->setTransformOriginZ(StyleBuilderConverter::convertComputedLength<float>(state, primitiveValue)); }
bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSValueList& valueList) { size_t length = valueList.length(); for (size_t index = 0; index < length; ++index) { if (interpolationRequiresStyleResolve(*valueList.item(index))) return true; } return false; }
GridTrackSize StyleBuilderConverter::convertGridTrackSize(StyleResolverState& state, CSSValue* value) { if (value->isPrimitiveValue()) return GridTrackSize(convertGridTrackBreadth(state, toCSSPrimitiveValue(value))); CSSFunctionValue* minmaxFunction = toCSSFunctionValue(value); CSSValueList* arguments = minmaxFunction->arguments(); ASSERT_WITH_SECURITY_IMPLICATION(arguments->length() == 2); GridLength minTrackBreadth(convertGridTrackBreadth(state, toCSSPrimitiveValue(arguments->item(0)))); GridLength maxTrackBreadth(convertGridTrackBreadth(state, toCSSPrimitiveValue(arguments->item(1)))); return GridTrackSize(minTrackBreadth, maxTrackBreadth); }
JSValue* jsCSSValueListPrototypeFunctionItem(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSCSSValueList::s_info)) return throwError(exec, TypeError); JSCSSValueList* castedThisObj = static_cast<JSCSSValueList*>(thisValue); CSSValueList* imp = static_cast<CSSValueList*>(castedThisObj->impl()); unsigned index = args[0]->toInt32(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->item(index))); return result; }
PassRefPtr<SVGLengthList> StyleBuilderConverter::convertStrokeDasharray(StyleResolverState&, CSSValue* value) { if (!value->isValueList()) { return SVGRenderStyle::initialStrokeDashArray(); } CSSValueList* dashes = toCSSValueList(value); RefPtr<SVGLengthList> array = SVGLengthList::create(); size_t length = dashes->length(); for (size_t i = 0; i < length; ++i) { CSSValue* currValue = dashes->item(i); if (!currValue->isPrimitiveValue()) continue; CSSPrimitiveValue* dash = toCSSPrimitiveValue(dashes->item(i)); array->append(SVGLength::fromCSSPrimitiveValue(dash)); } return array.release(); }
static bool parseAspectRatio(CSSValue* value, int& a, int& b) { if (value->isValueList()){ CSSValueList* valueList = static_cast<CSSValueList*>(value); if (valueList->length() == 3) { CSSValue* i0 = valueList->item(0); CSSValue* i1 = valueList->item(1); CSSValue* i2 = valueList->item(2); if (i0->isPrimitiveValue() && static_cast<CSSPrimitiveValue*>(i0)->primitiveType() == CSSPrimitiveValue::CSS_NUMBER && i1->isPrimitiveValue() && static_cast<CSSPrimitiveValue*>(i1)->primitiveType() == CSSPrimitiveValue::CSS_STRING && i2->isPrimitiveValue() && static_cast<CSSPrimitiveValue*>(i2)->primitiveType() == CSSPrimitiveValue::CSS_NUMBER) { String str = static_cast<CSSPrimitiveValue*>(i1)->getStringValue(); if (!str.isNull() && str.length() == 1 && str[0] == DeprecatedChar('/')) { a = (int) static_cast<CSSPrimitiveValue*>(i0)->getFloatValue(CSSPrimitiveValue::CSS_NUMBER); b = (int) static_cast<CSSPrimitiveValue*>(i2)->getFloatValue(CSSPrimitiveValue::CSS_NUMBER); return true; } } } } return false; }
PassRefPtr<TimingFunction> AnimationInputHelpers::parseTimingFunction(const String& string) { if (string.isEmpty()) return nullptr; RefPtrWillBeRawPtr<CSSValue> value = CSSParser::parseSingleValue(CSSPropertyTransitionTimingFunction, string); if (!value || value->isInitialValue() || value->isInheritedValue()) return nullptr; CSSValueList* valueList = toCSSValueList(value.get()); if (valueList->length() > 1) return nullptr; return CSSToStyleMap::mapAnimationTimingFunction(valueList->item(0), true); }
PassRefPtr<FontFeatureSettings> StyleBuilderConverter::convertFontFeatureSettings(StyleResolverState& state, CSSValue* value) { if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueNormal) return FontBuilder::initialFeatureSettings(); CSSValueList* list = toCSSValueList(value); RefPtr<FontFeatureSettings> settings = FontFeatureSettings::create(); int len = list->length(); for (int i = 0; i < len; ++i) { CSSFontFeatureValue* feature = toCSSFontFeatureValue(list->item(i)); settings->append(FontFeature(feature->tag(), feature->value())); } return settings; }
FontDescription::VariantLigatures StyleBuilderConverter::convertFontVariantLigatures(StyleResolverState&, CSSValue* value) { if (value->isValueList()) { FontDescription::VariantLigatures ligatures; CSSValueList* valueList = toCSSValueList(value); for (size_t i = 0; i < valueList->length(); ++i) { CSSValue* item = valueList->item(i); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(item); switch (primitiveValue->getValueID()) { case CSSValueNoCommonLigatures: ligatures.common = FontDescription::DisabledLigaturesState; break; case CSSValueCommonLigatures: ligatures.common = FontDescription::EnabledLigaturesState; break; case CSSValueNoDiscretionaryLigatures: ligatures.discretionary = FontDescription::DisabledLigaturesState; break; case CSSValueDiscretionaryLigatures: ligatures.discretionary = FontDescription::EnabledLigaturesState; break; case CSSValueNoHistoricalLigatures: ligatures.historical = FontDescription::DisabledLigaturesState; break; case CSSValueHistoricalLigatures: ligatures.historical = FontDescription::EnabledLigaturesState; break; case CSSValueNoContextual: ligatures.contextual = FontDescription::DisabledLigaturesState; break; case CSSValueContextual: ligatures.contextual = FontDescription::EnabledLigaturesState; break; default: ASSERT_NOT_REACHED(); break; } } return ligatures; } ASSERT_WITH_SECURITY_IMPLICATION(value->isPrimitiveValue()); ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNormal); return FontDescription::VariantLigatures(); }
KCDashArray KSVGPainterFactory::dashArrayFromRenderingStyle(const RenderStyle* style) { KCDashArray array; CSSValueList* dashes = style->svgStyle()->strokeDashArray(); if (dashes) { CSSPrimitiveValue* dash = 0; unsigned long len = dashes->length(); for (unsigned long i = 0; i < len; i++) { dash = static_cast<CSSPrimitiveValue*>(dashes->item(i)); if (!dash) continue; array.append(dash->computeLengthFloat(const_cast<RenderStyle*>(style))); } } return array; }
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 StyleBuilderFunctions::applyValueCSSPropertyCursor(StyleResolverState& state, CSSValue* value) { state.style()->clearCursorList(); if (value->isValueList()) { CSSValueList* list = toCSSValueList(value); int len = list->length(); state.style()->setCursor(CURSOR_AUTO); for (int i = 0; i < len; i++) { CSSValue* item = list->item(i); if (item->isCursorImageValue()) { CSSCursorImageValue* image = toCSSCursorImageValue(item); state.style()->addCursor(state.styleImage(CSSPropertyCursor, image), image->hotSpot()); } else { state.style()->setCursor(*toCSSPrimitiveValue(item)); } } } else { state.style()->setCursor(*toCSSPrimitiveValue(value)); } }
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 StyleBuilderFunctions::applyValueCSSPropertyCursor(StyleResolverState& state, CSSValue* value) { state.style()->clearCursorList(); if (value->isValueList()) { CSSValueList* list = toCSSValueList(value); int len = list->length(); state.style()->setCursor(CURSOR_AUTO); for (int i = 0; i < len; i++) { CSSValue* item = list->item(i); if (item->isCursorImageValue()) { CSSCursorImageValue* image = toCSSCursorImageValue(item); if (image->updateIfSVGCursorIsUsed(state.element())) // Elements with SVG cursors are not allowed to share style. state.style()->setUnique(); state.style()->addCursor(state.styleImage(CSSPropertyCursor, image), image->hotSpotSpecified(), image->hotSpot()); } else { state.style()->setCursor(*toCSSPrimitiveValue(item)); } } } else { state.style()->setCursor(*toCSSPrimitiveValue(value)); } }
JSValue* JSCSSValueListPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSCSSValueList::info)) return throwError(exec, TypeError); CSSValueList* imp = static_cast<CSSValueList*>(static_cast<JSCSSValueList*>(thisObj)->impl()); switch (id) { case JSCSSValueList::ItemFuncNum: { bool indexOk; unsigned index = args[0]->toInt32(exec, indexOk); if (!indexOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->item(index))); return result; } } return 0; }
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); } }
FontTraits FontFace::traits() const { FontStretch stretch = FontStretchNormal; if (m_stretch) { if (!m_stretch->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_stretch.get())->getValueID()) { case CSSValueUltraCondensed: stretch = FontStretchUltraCondensed; break; case CSSValueExtraCondensed: stretch = FontStretchExtraCondensed; break; case CSSValueCondensed: stretch = FontStretchCondensed; break; case CSSValueSemiCondensed: stretch = FontStretchSemiCondensed; break; case CSSValueSemiExpanded: stretch = FontStretchSemiExpanded; break; case CSSValueExpanded: stretch = FontStretchExpanded; break; case CSSValueExtraExpanded: stretch = FontStretchExtraExpanded; break; case CSSValueUltraExpanded: stretch = FontStretchUltraExpanded; break; default: break; } } FontStyle style = FontStyleNormal; if (m_style) { if (!m_style->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { case CSSValueNormal: style = FontStyleNormal; break; case CSSValueOblique: style = FontStyleOblique; break; case CSSValueItalic: style = FontStyleItalic; break; default: break; } } FontWeight weight = FontWeight400; if (m_weight) { if (!m_weight->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { case CSSValueBold: case CSSValue700: weight = FontWeight700; break; case CSSValueNormal: case CSSValue400: weight = FontWeight400; break; case CSSValue900: weight = FontWeight900; break; case CSSValue800: weight = FontWeight800; break; case CSSValue600: weight = FontWeight600; break; case CSSValue500: weight = FontWeight500; break; case CSSValue300: weight = FontWeight300; break; case CSSValue200: weight = FontWeight200; break; case CSSValue100: weight = FontWeight100; break; // Although 'lighter' and 'bolder' are valid keywords for font-weights, they are invalid // inside font-face rules so they are ignored. Reference: http://www.w3.org/TR/css3-fonts/#descdef-font-weight. case CSSValueLighter: case CSSValueBolder: break; default: ASSERT_NOT_REACHED(); break; } } FontVariant variant = FontVariantNormal; if (RefPtrWillBeRawPtr<CSSValue> fontVariant = m_variant) { // font-variant descriptor can be a value list. if (fontVariant->isPrimitiveValue()) { RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); list->append(fontVariant); fontVariant = list; } else if (!fontVariant->isValueList()) { return 0; } CSSValueList* variantList = toCSSValueList(fontVariant.get()); unsigned numVariants = variantList->length(); if (!numVariants) return 0; for (unsigned i = 0; i < numVariants; ++i) { switch (toCSSPrimitiveValue(variantList->item(i))->getValueID()) { case CSSValueNormal: variant = FontVariantNormal; break; case CSSValueSmallCaps: variant = FontVariantSmallCaps; break; default: break; } } } return FontTraits(style, variant, weight, stretch); }
FontTraits FontFace::traits() const { FontStyle style = FontStyleNormal; if (m_style) { if (!m_style->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_style.get())->getValueID()) { case CSSValueNormal: style = FontStyleNormal; break; case CSSValueItalic: case CSSValueOblique: style = FontStyleItalic; break; default: break; } } FontWeight weight = FontWeight400; if (m_weight) { if (!m_weight->isPrimitiveValue()) return 0; switch (toCSSPrimitiveValue(m_weight.get())->getValueID()) { case CSSValueBold: case CSSValue700: weight = FontWeight700; break; case CSSValueNormal: case CSSValue400: weight = FontWeight400; break; case CSSValue900: weight = FontWeight900; break; case CSSValue800: weight = FontWeight800; break; case CSSValue600: weight = FontWeight600; break; case CSSValue500: weight = FontWeight500; break; case CSSValue300: weight = FontWeight300; break; case CSSValue200: weight = FontWeight200; break; case CSSValueLighter: case CSSValue100: weight = FontWeight100; break; default: ASSERT_NOT_REACHED(); break; } } FontVariant variant = FontVariantNormal; if (RefPtrWillBeRawPtr<CSSValue> fontVariant = m_variant) { // font-variant descriptor can be a value list. if (fontVariant->isPrimitiveValue()) { RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); list->append(fontVariant); fontVariant = list; } else if (!fontVariant->isValueList()) { return 0; } CSSValueList* variantList = toCSSValueList(fontVariant.get()); unsigned numVariants = variantList->length(); if (!numVariants) return 0; for (unsigned i = 0; i < numVariants; ++i) { switch (toCSSPrimitiveValue(variantList->item(i))->getValueID()) { case CSSValueNormal: variant = FontVariantNormal; break; case CSSValueSmallCaps: variant = FontVariantSmallCaps; break; default: break; } } } return FontTraits(style, variant, weight, FontStretchNormal); }