From 6b25c1777895fc01b0a9c90d479a407582b209e3 Mon Sep 17 00:00:00 2001 From: "rob.buis@samsung.com" Date: Tue, 22 Sep 2015 12:29:09 +0000 Subject: [PATCH] Move parseFontFaceDescriptor to CSSPropertyParser.cpp Move parseFontFaceDescriptor and related functions to CSSPropertyParser.cpp. This also adds helper functions to consume FunctionToken and URLs. BUG=499780 Review URL: https://codereview.chromium.org/1331233003 git-svn-id: svn://svn.chromium.org/blink/trunk@202630 bbb929c8-8fbe-4397-9dbb-9b2b20218538 --- .../WebKit/LayoutTests/fast/css/font-weight-1.html | 2 +- .../Source/core/css/parser/CSSPropertyParser.cpp | 307 ++++++++++++++++++++- .../Source/core/css/parser/CSSPropertyParser.h | 13 +- .../core/css/parser/LegacyCSSPropertyParser.cpp | 267 +----------------- 4 files changed, 316 insertions(+), 273 deletions(-) diff --git a/third_party/WebKit/LayoutTests/fast/css/font-weight-1.html b/third_party/WebKit/LayoutTests/fast/css/font-weight-1.html index 0b315bfb455b..4b9bf2aa2239 100644 --- a/third_party/WebKit/LayoutTests/fast/css/font-weight-1.html +++ b/third_party/WebKit/LayoutTests/fast/css/font-weight-1.html @@ -48,7 +48,7 @@ src: url('../../resources/WebKitWeightWatcher900.ttf'); } div { font-family: 'WebKit WeightWatcher'; font-size: 48px; } - .w1 { font-weight: 100; } + .w1 { font-weight: 100; font-weight: 500.4; font-weight: 500px; font-weigth: 500.4px; } .w2 { font-weight: 200; } .w3 { font-weight: 300; } .w4 { font-weight: 400; } diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp index 2344e5bd7981..398fc32aa914 100644 --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp @@ -7,10 +7,14 @@ #include "core/StylePropertyShorthand.h" #include "core/css/CSSCalculationValue.h" +#include "core/css/CSSFontFaceSrcValue.h" +#include "core/css/CSSFontFeatureValue.h" +#include "core/css/CSSUnicodeRangeValue.h" #include "core/css/CSSValuePool.h" #include "core/css/parser/CSSParserFastPaths.h" #include "core/css/parser/CSSParserValues.h" #include "core/frame/UseCounter.h" +#include "wtf/text/StringBuilder.h" namespace blink { @@ -91,6 +95,42 @@ static PassRefPtrWillBeRawPtr consumeString(CSSParserTokenRan return cssValuePool().createValue(range.consumeIncludingWhitespace().value(), CSSPrimitiveValue::UnitType::String); } +static String consumeUrl(CSSParserTokenRange& range) +{ + const CSSParserToken& token = range.peek(); + if (token.type() == UrlToken) { + range.consumeIncludingWhitespace(); + return token.value(); + } + if (token.functionId() == CSSValueUrl) { + CSSParserTokenRange urlRange = range; + CSSParserTokenRange urlArgs = urlRange.consumeBlock(); + const CSSParserToken& next = urlArgs.consumeIncludingWhitespace(); + if (next.type() == BadStringToken || !urlArgs.atEnd()) + return String(); + ASSERT(next.type() == StringToken); + range = urlRange; + range.consumeWhitespace(); + return next.value(); + } + + return String(); +} + +static CSSParserTokenRange consumeFunction(CSSParserTokenRange& range) +{ + ASSERT(range.peek().type() == FunctionToken); + CSSParserTokenRange contents = range.consumeBlock(); + range.consumeWhitespace(); + contents.consumeWhitespace(); + return contents; +} + +static inline bool isCSSWideKeyword(const CSSValueID& id) +{ + return id == CSSValueInitial || id == CSSValueInherit || id == CSSValueUnset || id == CSSValueDefault; +} + // Methods for consuming non-shorthand properties starts here. static PassRefPtrWillBeRawPtr consumeWillChange(CSSParserTokenRange& range) { @@ -142,6 +182,51 @@ static PassRefPtrWillBeRawPtr consumeWillChange(CSSParserTokenRange& r return values.release(); } +static PassRefPtrWillBeRawPtr consumeFontFeatureTag(CSSParserTokenRange& range) +{ + // Feature tag name consists of 4-letter characters. + static const unsigned tagNameLength = 4; + + const CSSParserToken& token = range.consumeIncludingWhitespace(); + // Feature tag name comes first + if (token.type() != StringToken) + return nullptr; + if (token.value().length() != tagNameLength) + return nullptr; + AtomicString tag = token.value(); + for (unsigned i = 0; i < tagNameLength; ++i) { + // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification. + UChar character = tag[i]; + if (character < 0x20 || character > 0x7E) + return nullptr; + } + + int tagValue = 1; + // Feature tag values could follow: | on | off + if (range.peek().type() == NumberToken && range.peek().numericValueType() == IntegerValueType && range.peek().numericValue() >= 0) { + tagValue = clampTo(range.consumeIncludingWhitespace().numericValue()); + if (tagValue < 0) + return nullptr; + } else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff) { + tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn; + } + return CSSFontFeatureValue::create(tag, tagValue); +} + +static PassRefPtrWillBeRawPtr consumeFontFeatureSettings(CSSParserTokenRange& range) +{ + if (range.peek().id() == CSSValueNormal) + return consumeIdent(range); + RefPtrWillBeRawPtr settings = CSSValueList::createCommaSeparated(); + do { + RefPtrWillBeRawPtr fontFeatureValue = consumeFontFeatureTag(range); + if (!fontFeatureValue) + return nullptr; + settings->append(fontFeatureValue); + } while (consumeCommaIncludingWhitespace(range)); + return settings.release(); +} + static PassRefPtrWillBeRawPtr consumePage(CSSParserTokenRange& range) { if (range.peek().id() == CSSValueAuto) @@ -149,7 +234,6 @@ static PassRefPtrWillBeRawPtr consumePage(CSSParserTokenRange return consumeCustomIdent(range); } -// [ ]+ | none static PassRefPtrWillBeRawPtr consumeQuotes(CSSParserTokenRange& range) { if (range.peek().id() == CSSValueNone) @@ -218,6 +302,48 @@ static PassRefPtrWillBeRawPtr consumeFontVariantLigatures(CSSParserTok return ligatureValues.release(); } +PassRefPtrWillBeRawPtr CSSPropertyParser::consumeFontVariant() +{ + if (m_ruleType != StyleRule::FontFace) { + if (m_range.peek().id() != CSSValueNormal && m_range.peek().id() != CSSValueSmallCaps) + return nullptr; + return consumeIdent(m_range); + } + RefPtrWillBeRawPtr values = CSSValueList::createCommaSeparated(); + do { + if (m_range.peek().id() == CSSValueAll) { + // FIXME: CSSPropertyParser::parseFontVariant() implements + // the old css3 draft: + // http://www.w3.org/TR/2002/WD-css3-webfonts-20020802/#font-variant + // 'all' is only allowed in @font-face and with no other values. + if (values->length()) + return nullptr; + return consumeIdent(m_range); + } + if (m_range.peek().id() == CSSValueNormal || m_range.peek().id() == CSSValueSmallCaps) + values->append(consumeIdent(m_range)); + } while (consumeCommaIncludingWhitespace(m_range)); + + if (values->length()) + return values.release(); + + return nullptr; +} + +static PassRefPtrWillBeRawPtr consumeFontWeight(CSSParserTokenRange& range) +{ + const CSSParserToken& token = range.peek(); + if (token.id() >= CSSValueNormal && token.id() <= CSSValueLighter) + return consumeIdent(range); + if (token.type() != NumberToken || token.numericValueType() != IntegerValueType) + return nullptr; + int weight = static_cast(token.numericValue()); + if ((weight % 100) || weight < 100 || weight > 900) + return nullptr; + range.consumeIncludingWhitespace(); + return cssValuePool().createIdentifierValue(static_cast(CSSValue100 + weight / 100 - 1)); +} + PassRefPtrWillBeRawPtr CSSPropertyParser::parseSingleValue(CSSPropertyID propId) { m_range.consumeWhitespace(); @@ -232,11 +358,190 @@ PassRefPtrWillBeRawPtr CSSPropertyParser::parseSingleValue(CSSProperty return consumeWebkitHighlight(m_range); case CSSPropertyFontVariantLigatures: return consumeFontVariantLigatures(m_range); + case CSSPropertyWebkitFontFeatureSettings: + return consumeFontFeatureSettings(m_range); + case CSSPropertyFontVariant: + return consumeFontVariant(); + case CSSPropertyFontFamily: + return consumeFontFamily(); + case CSSPropertyFontWeight: + return consumeFontWeight(m_range); default: return nullptr; } } +static PassRefPtrWillBeRawPtr consumeFontFaceUnicodeRange(CSSParserTokenRange& range) +{ + RefPtrWillBeRawPtr values = CSSValueList::createCommaSeparated(); + + do { + const CSSParserToken& token = range.consumeIncludingWhitespace(); + if (token.type() != UnicodeRangeToken) + return nullptr; + + UChar32 start = token.unicodeRangeStart(); + UChar32 end = token.unicodeRangeEnd(); + if (start > end) + return nullptr; + values->append(CSSUnicodeRangeValue::create(start, end)); + } while (consumeCommaIncludingWhitespace(range)); + + return values.release(); +} + +PassRefPtrWillBeRawPtr CSSPropertyParser::consumeFontFaceSrcURI() +{ + String url = consumeUrl(m_range); + if (url.isNull()) + return nullptr; + RefPtrWillBeRawPtr uriValue(CSSFontFaceSrcValue::create(completeURL(url), m_context.shouldCheckContentSecurityPolicy())); + uriValue->setReferrer(m_context.referrer()); + + if (m_range.peek().functionId() != CSSValueFormat) + return uriValue.release(); + + // FIXME: https://drafts.csswg.org/css-fonts says that format() contains a comma-separated list of strings, + // but CSSFontFaceSrcValue stores only one format. Allowing one format for now. + // FIXME: IdentToken should not be supported here. + CSSParserTokenRange args = consumeFunction(m_range); + const CSSParserToken& arg = args.consumeIncludingWhitespace(); + if ((arg.type() != StringToken && arg.type() != IdentToken) || !args.atEnd()) + return nullptr; + uriValue->setFormat(arg.value()); + return uriValue.release(); +} + +static String concatenateFamilyName(CSSParserTokenRange& range) +{ + StringBuilder builder; + bool addedSpace = false; + const CSSParserToken& firstToken = range.peek(); + while (range.peek().type() == IdentToken) { + if (!builder.isEmpty()) { + builder.append(' '); + addedSpace = true; + } + builder.append(range.consumeIncludingWhitespace().value()); + } + if (!addedSpace && isCSSWideKeyword(firstToken.id())) { + return String(); +} + return builder.toString(); +} + +PassRefPtrWillBeRawPtr CSSPropertyParser::consumeFontFaceSrcLocal() +{ + CSSParserTokenRange args = consumeFunction(m_range); + ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy = m_context.shouldCheckContentSecurityPolicy(); + if (args.peek().type() == StringToken) { + const CSSParserToken& arg = args.consumeIncludingWhitespace(); + if (!args.atEnd()) + return nullptr; + return CSSFontFaceSrcValue::createLocal(arg.value(), shouldCheckContentSecurityPolicy); + } + if (args.peek().type() == IdentToken) { + String familyName = concatenateFamilyName(args); + if (!args.atEnd()) + return nullptr; + return CSSFontFaceSrcValue::createLocal(familyName, shouldCheckContentSecurityPolicy); + } + return nullptr; +} + +PassRefPtrWillBeRawPtr CSSPropertyParser::consumeFontFaceSrc() +{ + RefPtrWillBeRawPtr values(CSSValueList::createCommaSeparated()); + + do { + const CSSParserToken& token = m_range.peek(); + RefPtrWillBeRawPtr parsedValue = nullptr; + if (token.functionId() == CSSValueLocal) + parsedValue = consumeFontFaceSrcLocal(); + else + parsedValue = consumeFontFaceSrcURI(); + if (!parsedValue) + return nullptr; + values->append(parsedValue); + } while (consumeCommaIncludingWhitespace(m_range)); + return values.release(); +} + +static PassRefPtrWillBeRawPtr consumeFamilyName(CSSParserTokenRange& range) +{ + if (range.peek().type() == StringToken) + return cssValuePool().createFontFamilyValue(range.consumeIncludingWhitespace().value()); + if (range.peek().type() != IdentToken) + return nullptr; + String familyName = concatenateFamilyName(range); + if (familyName.isNull()) + return nullptr; + return cssValuePool().createFontFamilyValue(familyName); +} + +static PassRefPtrWillBeRawPtr consumeGenericFamily(CSSParserTokenRange& range) +{ + if (range.peek().id() >= CSSValueSerif && range.peek().id() <= CSSValueWebkitBody) + return consumeIdent(range); + return nullptr; +} + +PassRefPtrWillBeRawPtr CSSPropertyParser::consumeFontFamily() +{ + RefPtrWillBeRawPtr list = CSSValueList::createCommaSeparated(); + do { + RefPtrWillBeRawPtr parsedValue = nullptr; + if ((parsedValue = consumeGenericFamily(m_range))) { + list->append(parsedValue); + } else if ((parsedValue = consumeFamilyName(m_range))) { + list->append(parsedValue); + } else { + return nullptr; + } + } while (consumeCommaIncludingWhitespace(m_range)); + if (m_ruleType == StyleRule::FontFace && list->length() > 1) + return nullptr; + return list.release(); +} + +bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId) +{ + RefPtrWillBeRawPtr parsedValue = nullptr; + + m_range.consumeWhitespace(); + switch (propId) { + case CSSPropertySrc: // This is a list of urls or local references. + parsedValue = consumeFontFaceSrc(); + break; + case CSSPropertyUnicodeRange: + parsedValue = consumeFontFaceUnicodeRange(m_range); + break; + case CSSPropertyFontStretch: + case CSSPropertyFontStyle: { + CSSValueID id = m_range.consumeIncludingWhitespace().id(); + if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id)) + return false; + parsedValue = cssValuePool().createIdentifierValue(id); + break; + } + // TODO(rwlbuis): check there is only one family-name in font-face descriptor case + case CSSPropertyFontFamily: + case CSSPropertyFontVariant: + case CSSPropertyFontWeight: + case CSSPropertyWebkitFontFeatureSettings: + parsedValue = parseSingleValue(propId); + break; + default: + break; + } + + if (!parsedValue || !m_range.atEnd()) + return false; + + addProperty(propId, parsedValue.release(), false); + return true; +} + bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) { m_range.consumeWhitespace(); diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h index a02331978e98..aad98b0b752d 100644 --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.h @@ -188,6 +188,7 @@ private: bool parseFont(bool important); bool parseSystemFont(bool important); PassRefPtrWillBeRawPtr parseFontFamily(); + PassRefPtrWillBeRawPtr consumeFontFamily(); PassRefPtrWillBeRawPtr parseCounter(int defaultValue); PassRefPtrWillBeRawPtr parseCounterContent(CSSParserValueList* args, bool counters); @@ -201,10 +202,9 @@ private: PassRefPtrWillBeRawPtr parseLineHeight(); bool parseFontSize(bool important); - bool parseFontVariant(bool important); + PassRefPtrWillBeRawPtr consumeFontVariant(); bool parseFontWeight(bool important); - PassRefPtrWillBeRawPtr parseFontFaceSrc(); - PassRefPtrWillBeRawPtr parseFontFaceUnicodeRange(); + PassRefPtrWillBeRawPtr consumeFontFaceSrc(); bool parseSVGValue(CSSPropertyID propId, bool important); PassRefPtrWillBeRawPtr parseSVGStrokeDasharray(); @@ -263,9 +263,6 @@ private: bool parseCalculation(CSSParserValue*, ValueRange); - bool parseFontFeatureTag(CSSValueList*); - PassRefPtrWillBeRawPtr parseFontFeatureSettings(); - bool parseGeneratedImage(CSSParserValueList*, RefPtrWillBeRawPtr&); PassRefPtrWillBeRawPtr createPrimitiveNumericValue(CSSParserValue*); @@ -287,8 +284,8 @@ private: PassRefPtrWillBeRawPtr parseSize(); SizeParameterType parseSizeParameter(CSSValueList* parsedValues, CSSParserValue*, SizeParameterType prevParamType); - bool parseFontFaceSrcURI(CSSValueList*); - bool parseFontFaceSrcLocal(CSSValueList*); + PassRefPtrWillBeRawPtr consumeFontFaceSrcURI(); + PassRefPtrWillBeRawPtr consumeFontFaceSrcLocal(); class ImplicitScope { STACK_ALLOCATED(); diff --git a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp index c1db97307fa8..bcbfc3bec3a9 100644 --- a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp +++ b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp @@ -35,8 +35,6 @@ #include "core/css/CSSCounterValue.h" #include "core/css/CSSCrossfadeValue.h" #include "core/css/CSSCursorImageValue.h" -#include "core/css/CSSFontFaceSrcValue.h" -#include "core/css/CSSFontFeatureValue.h" #include "core/css/CSSFunctionValue.h" #include "core/css/CSSGridLineNamesValue.h" #include "core/css/CSSImageSetValue.h" @@ -50,7 +48,6 @@ #include "core/css/CSSSVGDocumentValue.h" #include "core/css/CSSShadowValue.h" #include "core/css/CSSTimingFunctionValue.h" -#include "core/css/CSSUnicodeRangeValue.h" #include "core/css/CSSValuePair.h" #include "core/css/CSSValuePool.h" #include "core/css/HashTools.h" @@ -469,9 +466,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import } break; - case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit - return parseFontWeight(important) && !m_valueList->next(); - case CSSPropertyBorderSpacing: { ShorthandScope scope(this, CSSPropertyBorderSpacing); if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important)) @@ -747,9 +741,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import case CSSPropertyFontSize: return parseFontSize(important); - case CSSPropertyFontVariant: // normal | small-caps | inherit - return parseFontVariant(important); - case CSSPropertyVerticalAlign: // baseline | sub | super | top | text-top | middle | bottom | text-bottom | // | | inherit @@ -812,12 +803,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import else parsedValue = parseCounter(0); break; - case CSSPropertyFontFamily: - // [[ | ],]* [ | ] | inherit - { - parsedValue = parseFontFamily(); - break; - } case CSSPropertyTextDecoration: // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration @@ -1376,13 +1361,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import validPrimitive = true; break; - case CSSPropertyWebkitFontFeatureSettings: - if (id == CSSValueNormal) - validPrimitive = true; - else - parsedValue = parseFontFeatureSettings(); - break; - case CSSPropertyWebkitClipPath: if (id == CSSValueNone) { validPrimitive = true; @@ -1442,6 +1420,10 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import case CSSPropertyQuotes: case CSSPropertyWebkitHighlight: case CSSPropertyFontVariantLigatures: + case CSSPropertyWebkitFontFeatureSettings: + case CSSPropertyFontVariant: + case CSSPropertyFontFamily: + case CSSPropertyFontWeight: validPrimitive = false; break; @@ -4672,55 +4654,6 @@ bool CSSPropertyParser::parseFontSize(bool important) return validPrimitive; } -bool CSSPropertyParser::parseFontVariant(bool important) -{ - RefPtrWillBeRawPtr values = nullptr; - if (m_valueList->size() > 1) - values = CSSValueList::createCommaSeparated(); - bool expectComma = false; - for (CSSParserValue* val = m_valueList->current(); val; val = m_valueList->current()) { - RefPtrWillBeRawPtr parsedValue = nullptr; - if (!expectComma) { - expectComma = true; - if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps) - parsedValue = cssValuePool().createIdentifierValue(val->id); - else if (val->id == CSSValueAll && !values) { - // FIXME: CSSPropertyParser::parseFontVariant() implements - // the old css3 draft: - // http://www.w3.org/TR/2002/WD-css3-webfonts-20020802/#font-variant - // 'all' is only allowed in @font-face and with no other values. Make a value list to - // indicate that we are in the @font-face case. - values = CSSValueList::createCommaSeparated(); - parsedValue = cssValuePool().createIdentifierValue(val->id); - } - } else if (consumeComma(m_valueList)) { - expectComma = false; - continue; - } - - if (!parsedValue) - return false; - - m_valueList->next(); - - if (values) - values->append(parsedValue.release()); - else { - addProperty(CSSPropertyFontVariant, parsedValue.release(), important); - return true; - } - } - - if (values && values->length()) { - if (m_ruleType != StyleRule::FontFace) - return false; - addProperty(CSSPropertyFontVariant, values.release(), important); - return true; - } - - return false; -} - bool CSSPropertyParser::parseFontWeight(bool important) { CSSParserValue* value = m_valueList->current(); @@ -4738,99 +4671,6 @@ bool CSSPropertyParser::parseFontWeight(bool important) return false; } -bool CSSPropertyParser::parseFontFaceSrcURI(CSSValueList* valueList) -{ - RefPtrWillBeRawPtr uriValue(CSSFontFaceSrcValue::create(completeURL(m_valueList->current()->string), m_context.shouldCheckContentSecurityPolicy())); - uriValue->setReferrer(m_context.referrer()); - - CSSParserValue* value = m_valueList->next(); - if (!value || value->m_unit != CSSParserValue::Function || value->function->id != CSSValueFormat) { - valueList->append(uriValue.release()); - return true; - } - - // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20111004/ says that format() contains a comma-separated list of strings, - // but CSSFontFaceSrcValue stores only one format. Allowing one format for now. - CSSParserValueList* args = value->function->args.get(); - if (!args || args->size() != 1 || (args->current()->unit() != CSSPrimitiveValue::UnitType::String && args->current()->m_unit != CSSParserValue::Identifier)) - return false; - uriValue->setFormat(args->current()->string); - valueList->append(uriValue.release()); - m_valueList->next(); - return true; -} - -bool CSSPropertyParser::parseFontFaceSrcLocal(CSSValueList* valueList) -{ - CSSParserValueList* args = m_valueList->current()->function->args.get(); - if (!args || !args->size()) - return false; - m_valueList->next(); - - ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy = m_context.shouldCheckContentSecurityPolicy(); - if (args->size() == 1 && args->current()->unit() == CSSPrimitiveValue::UnitType::String) { - valueList->append(CSSFontFaceSrcValue::createLocal(args->current()->string, shouldCheckContentSecurityPolicy)); - } else if (args->current()->m_unit == CSSParserValue::Identifier) { - StringBuilder builder; - for (CSSParserValue* localValue = args->current(); localValue; localValue = args->next()) { - if (localValue->m_unit != CSSParserValue::Identifier) - return false; - if (!builder.isEmpty()) - builder.append(' '); - builder.append(localValue->string); - } - valueList->append(CSSFontFaceSrcValue::createLocal(builder.toString(), shouldCheckContentSecurityPolicy)); - } else - return false; - - return true; -} - -PassRefPtrWillBeRawPtr CSSPropertyParser::parseFontFaceSrc() -{ - RefPtrWillBeRawPtr values(CSSValueList::createCommaSeparated()); - - while (true) { - CSSParserValue* value = m_valueList->current(); - if (!value) - return nullptr; - if (value->unit() == CSSPrimitiveValue::UnitType::URI) { - if (!parseFontFaceSrcURI(values.get())) - return nullptr; - } else if (value->m_unit == CSSParserValue::Function && value->function->id == CSSValueLocal) { - if (!parseFontFaceSrcLocal(values.get())) - return nullptr; - } else { - return nullptr; - } - - if (!m_valueList->current()) - return values.release(); - if (!consumeComma(m_valueList)) - return nullptr; - } -} - -PassRefPtrWillBeRawPtr CSSPropertyParser::parseFontFaceUnicodeRange() -{ - RefPtrWillBeRawPtr values = CSSValueList::createCommaSeparated(); - - do { - CSSParserValue* current = m_valueList->current(); - if (!current || current->m_unit != CSSParserValue::UnicodeRange) - return nullptr; - - UChar32 start = current->m_unicodeRange.start; - UChar32 end = current->m_unicodeRange.end; - if (start > end) - return nullptr; - values->append(CSSUnicodeRangeValue::create(start, end)); - m_valueList->next(); - } while (consumeComma(m_valueList)); - - return values.release(); -} - inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v) { bool isPercent; @@ -6967,57 +6807,6 @@ PassRefPtrWillBeRawPtr CSSPropertyParser::parseTextIndent() return list.release(); } -bool CSSPropertyParser::parseFontFeatureTag(CSSValueList* settings) -{ - // Feature tag name consists of 4-letter characters. - static const unsigned tagNameLength = 4; - - CSSParserValue* value = m_valueList->current(); - // Feature tag name comes first - if (value->unit() != CSSPrimitiveValue::UnitType::String) - return false; - if (value->string.length() != tagNameLength) - return false; - for (unsigned i = 0; i < tagNameLength; ++i) { - // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification. - UChar character = value->string[i]; - if (character < 0x20 || character > 0x7E) - return false; - } - - AtomicString tag = value->string; - int tagValue = 1; - // Feature tag values could follow: | on | off - value = m_valueList->next(); - if (value) { - if (value->unit() == CSSPrimitiveValue::UnitType::Number && value->isInt && value->fValue >= 0) { - tagValue = clampTo(value->fValue); - if (tagValue < 0) - return false; - m_valueList->next(); - } else if (value->id == CSSValueOn || value->id == CSSValueOff) { - tagValue = value->id == CSSValueOn; - m_valueList->next(); - } - } - settings->append(CSSFontFeatureValue::create(tag, tagValue)); - return true; -} - -PassRefPtrWillBeRawPtr CSSPropertyParser::parseFontFeatureSettings() -{ - RefPtrWillBeRawPtr settings = CSSValueList::createCommaSeparated(); - while (true) { - if (!m_valueList->current() || !parseFontFeatureTag(settings.get())) - return nullptr; - if (!m_valueList->current()) - break; - if (!consumeComma(m_valueList)) - return nullptr; - } - return settings.release(); -} - bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range) { ASSERT(isCalculation(value)); @@ -7033,54 +6822,6 @@ bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range return true; } -bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId) -{ - CSSParserValue* value = m_valueList->current(); - ASSERT(value); - CSSValueID id = value->id; - RefPtrWillBeRawPtr parsedValue = nullptr; - - switch (propId) { - case CSSPropertyFontFamily: - // - // TODO(rwlbuis): check there is only one family-name - parsedValue = parseFontFamily(); - break; - case CSSPropertySrc: // This is a list of urls or local references. - parsedValue = parseFontFaceSrc(); - break; - case CSSPropertyUnicodeRange: - parsedValue = parseFontFaceUnicodeRange(); - break; - case CSSPropertyFontWeight: // normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 - return parseFontWeight(false) && !m_valueList->next(); - case CSSPropertyFontStretch: - case CSSPropertyFontStyle: - if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id)) - return false; - addProperty(propId, cssValuePool().createIdentifierValue(id), false); - return true; - case CSSPropertyFontVariant: // normal | small-caps | inherit - return parseFontVariant(false); - case CSSPropertyWebkitFontFeatureSettings: - if (id == CSSValueNormal) { - parsedValue = cssValuePool().createIdentifierValue(CSSValueNormal); - m_valueList->next(); - } else { - parsedValue = parseFontFeatureSettings(); - } - break; - default: - break; - } - - if (!parsedValue || m_valueList->current()) - return false; - - addProperty(propId, parsedValue.release(), false); - return true; -} - bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool important) { ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_context.mode())); -- 2.11.4.GIT