Changeset 143028 in webkit


Ignore:
Timestamp:
Feb 15, 2013 11:54:53 AM (11 years ago)
Author:
mvujovic@adobe.com
Message:

Source/WebCore: Add code from other branch.

[CSS Shaders] Parse src property in @-webkit-filter at-rules
https://bugs.webkit.org/show_bug.cgi?id=109770

Reviewed by Dean Jackson.

This patch implements the parsing for the CSS src property in @-webkit-filter at-rules.

The Filter Effects spec [1] specifies its syntax:

src: [ <uri> [format(<string>)]?]#

In practice, it can look like:

src: url(shader.vs) format('x-shader/x-vertex'),

url(shader.fs) format('x-shader/x-fragment');

This src property is similar to the src property in CSS font-face rules, but a little
different. The CSS Fonts spec [2] specifies:

src: [ <uri> [format(<string>#)]? | <font-face-name> ]#
The syntax for a <font-face-name> is a unique font face name enclosed by "local("
and ")".

Unlike the filter src property, the font face src property accepts the local function
[e.g. src: local("SomeFont");]. Also, the font face src property accepts a list of strings
instead of just one string in its format function.

[1]: https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#custom-filter-src
[2]: http://www.w3.org/TR/css3-fonts/#src-desc

Tests: css3/filters/custom-with-at-rule-syntax/parsing-src-property-invalid.html

css3/filters/custom-with-at-rule-syntax/parsing-src-property-valid.html

  • css/CSSGrammar.y.in:

Set (and unset) a flag called "m_inFilterRule", which tells us if we are in a
@-webkit-filter at-rule or in a @font-face at-rule when we encounter a src property.
We parse the two variants of the src property separately so that we can create different
objects (WebKitCSSShaderValue vs. CSSFontFaceSrcValue) and because their syntax is a
little different.

  • css/CSSParser.cpp:

(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseFilterRuleSrcUriAndFormat):

Parses a URI and format pair found in the @-webkit-filter src property.

(WebCore::CSSParser::parseFilterRuleSrc):

Parse the @-webkit-filter src property.

  • css/CSSParser.h:

(CSSParser):

  • css/WebKitCSSShaderValue.cpp:

(WebCore::WebKitCSSShaderValue::customCssText):

WebKitCSSShaderValue now has an m_format member, which needs to be included in its
cssText.

(WebCore::WebKitCSSShaderValue::reportDescendantMemoryUsage):

  • css/WebKitCSSShaderValue.h:

(WebCore::WebKitCSSShaderValue::format):
(WebCore::WebKitCSSShaderValue::setFormat):
(WebKitCSSShaderValue):

LayoutTests: [CSS Shaders] Parse src property in @-webkit-filter at-rules
https://bugs.webkit.org/show_bug.cgi?id=109770

Reviewed by Dean Jackson.

Add positive and negative parsing tests for the @-webkit-filter src property.

  • css3/filters/custom-with-at-rule-syntax/parsing-src-property-invalid-expected.txt: Added.
  • css3/filters/custom-with-at-rule-syntax/parsing-src-property-invalid.html: Added.
  • css3/filters/custom-with-at-rule-syntax/parsing-src-property-valid-expected.txt: Added.
  • css3/filters/custom-with-at-rule-syntax/parsing-src-property-valid.html: Added.
  • css3/filters/custom-with-at-rule-syntax/script-tests/parsing-src-property-invalid.js: Added.

(testInvalidSrcProperty):

  • css3/filters/custom-with-at-rule-syntax/script-tests/parsing-src-property-valid.js: Added.

(testSrcProperty):

Location:
trunk
Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r143026 r143028  
     12013-02-15  Max Vujovic  <mvujovic@adobe.com>
     2
     3        [CSS Shaders] Parse src property in @-webkit-filter at-rules
     4        https://bugs.webkit.org/show_bug.cgi?id=109770
     5
     6        Reviewed by Dean Jackson.
     7
     8        Add positive and negative parsing tests for the @-webkit-filter src property.
     9
     10        * css3/filters/custom-with-at-rule-syntax/parsing-src-property-invalid-expected.txt: Added.
     11        * css3/filters/custom-with-at-rule-syntax/parsing-src-property-invalid.html: Added.
     12        * css3/filters/custom-with-at-rule-syntax/parsing-src-property-valid-expected.txt: Added.
     13        * css3/filters/custom-with-at-rule-syntax/parsing-src-property-valid.html: Added.
     14        * css3/filters/custom-with-at-rule-syntax/script-tests/parsing-src-property-invalid.js: Added.
     15        (testInvalidSrcProperty):
     16        * css3/filters/custom-with-at-rule-syntax/script-tests/parsing-src-property-valid.js: Added.
     17        (testSrcProperty):
     18
    1192013-02-15  Philip Rogers  <pdr@google.com>
    220
  • trunk/Source/WebCore/ChangeLog

    r143021 r143028  
     12013-02-15  Max Vujovic  <mvujovic@adobe.com>
     2
     3        Add code from other branch.
     4
     5        [CSS Shaders] Parse src property in @-webkit-filter at-rules
     6        https://bugs.webkit.org/show_bug.cgi?id=109770
     7
     8        Reviewed by Dean Jackson.
     9
     10        This patch implements the parsing for the CSS src property in @-webkit-filter at-rules.
     11
     12        The Filter Effects spec [1] specifies its syntax:
     13            src: [ <uri> [format(<string>)]?]#
     14
     15        In practice, it can look like:
     16            src: url(shader.vs) format('x-shader/x-vertex'),
     17                 url(shader.fs) format('x-shader/x-fragment');
     18
     19        This src property is similar to the src property in CSS font-face rules, but a little
     20        different. The CSS Fonts spec [2] specifies:
     21            src: [ <uri> [format(<string>#)]? | <font-face-name> ]#
     22            The syntax for a <font-face-name> is a unique font face name enclosed by "local("
     23            and ")".
     24
     25        Unlike the filter src property, the font face src property accepts the local function
     26        [e.g. src: local("SomeFont");]. Also, the font face src property accepts a list of strings
     27        instead of just one string in its format function.
     28
     29        [1]: https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#custom-filter-src
     30        [2]: http://www.w3.org/TR/css3-fonts/#src-desc
     31
     32        Tests: css3/filters/custom-with-at-rule-syntax/parsing-src-property-invalid.html
     33               css3/filters/custom-with-at-rule-syntax/parsing-src-property-valid.html
     34
     35        * css/CSSGrammar.y.in:
     36            Set (and unset) a flag called "m_inFilterRule", which tells us if we are in a
     37            @-webkit-filter at-rule or in a @font-face at-rule when we encounter a src property.
     38            We parse the two variants of the src property separately so that we can create different
     39            objects (WebKitCSSShaderValue vs. CSSFontFaceSrcValue) and because their syntax is a
     40            little different.
     41        * css/CSSParser.cpp:
     42        (WebCore::CSSParser::CSSParser):
     43        (WebCore::CSSParser::parseValue):
     44        (WebCore::CSSParser::parseFilterRuleSrcUriAndFormat):
     45            Parses a URI and format pair found in the @-webkit-filter src property.
     46        (WebCore::CSSParser::parseFilterRuleSrc):
     47            Parse the @-webkit-filter src property.
     48        * css/CSSParser.h:
     49        (CSSParser):
     50        * css/WebKitCSSShaderValue.cpp:
     51        (WebCore::WebKitCSSShaderValue::customCssText):
     52            WebKitCSSShaderValue now has an m_format member, which needs to be included in its
     53            cssText.
     54        (WebCore::WebKitCSSShaderValue::reportDescendantMemoryUsage):
     55        * css/WebKitCSSShaderValue.h:
     56        (WebCore::WebKitCSSShaderValue::format):
     57        (WebCore::WebKitCSSShaderValue::setFormat):
     58        (WebKitCSSShaderValue):
     59
    1602013-02-15  Eric Carlson  <eric.carlson@apple.com>
    261
  • trunk/Source/WebCore/css/CSSGrammar.y.in

    r142904 r143028  
    10681068    /* empty */ {
    10691069        parser->markRuleHeaderStart(CSSRuleSourceData::FILTER_RULE);
     1070        parser->m_inFilterRule = true;
    10701071    }
    10711072    ;
     
    10741075    before_filter_rule WEBKIT_FILTER_RULE_SYM WHITESPACE IDENT at_rule_header_end_maybe_space
    10751076    '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
     1077        parser->m_inFilterRule = false;
    10761078        $$ = parser->createFilterRule($4);
    10771079    }
  • trunk/Source/WebCore/css/CSSParser.cpp

    r143019 r143028  
    316316    , m_hasFontFaceOnlyValues(false)
    317317    , m_hadSyntacticallyValidCSSRule(false)
     318#if ENABLE(CSS_SHADERS)
     319    , m_inFilterRule(false)
     320#endif
    318321    , m_defaultNamespace(starAtom)
    319322    , m_parsedTextPrefixLength(0)
     
    22902293        break;
    22912294
    2292     case CSSPropertySrc:  // Only used within @font-face, so cannot use inherit | initial or be !important.  This is a list of urls or local references.
     2295    case CSSPropertySrc: // Only used within @font-face and @-webkit-filter, so cannot use inherit | initial or be !important. This is a list of urls or local references.
     2296#if ENABLE(CSS_SHADERS)
     2297        if (m_inFilterRule)
     2298            return parseFilterRuleSrc();
     2299#endif
    22932300        return parseFontFaceSrc();
    22942301
     
    86378644}
    86388645
     8646PassRefPtr<WebKitCSSShaderValue> CSSParser::parseFilterRuleSrcUriAndFormat(CSSParserValueList* valueList)
     8647{
     8648    CSSParserValue* value = valueList->current();
     8649    ASSERT(value && value->unit == CSSPrimitiveValue::CSS_URI);
     8650    RefPtr<WebKitCSSShaderValue> shaderValue = WebKitCSSShaderValue::create(completeURL(value->string));
     8651
     8652    value = valueList->next();
     8653    if (value && value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "format(")) {
     8654        CSSParserValueList* args = value->function->args.get();
     8655        if (!args || args->size() != 1)
     8656            return 0;
     8657
     8658        CSSParserValue* arg = args->current();
     8659        if (arg->unit != CSSPrimitiveValue::CSS_STRING)
     8660            return 0;
     8661
     8662        shaderValue->setFormat(arg->string);
     8663        valueList->next();
     8664    }
     8665
     8666    return shaderValue.release();
     8667}
     8668
     8669bool CSSParser::parseFilterRuleSrc()
     8670{
     8671    RefPtr<CSSValueList> srcList = CSSValueList::createCommaSeparated();
     8672
     8673    CSSParserValue* value = m_valueList->current();
     8674    while (value) {
     8675        if (value->unit != CSSPrimitiveValue::CSS_URI)
     8676            return false;
     8677
     8678        RefPtr<WebKitCSSShaderValue> shaderValue = parseFilterRuleSrcUriAndFormat(m_valueList.get());
     8679        if (!shaderValue)
     8680            return false;
     8681        srcList->append(shaderValue.release());
     8682
     8683        if (!acceptCommaOperator(m_valueList.get()))
     8684            return false;
     8685
     8686        value = m_valueList->current();
     8687    }
     8688
     8689    if (!srcList->length())
     8690        return false;
     8691
     8692    addProperty(CSSPropertySrc, srcList.release(), m_important);
     8693    return true;
     8694}
     8695
    86398696StyleRuleBase* CSSParser::createFilterRule(const CSSParserString& filterName)
    86408697{
     
    86478704    return result;
    86488705}
    8649 #endif
     8706
     8707#endif // ENABLE(CSS_SHADERS)
    86508708
    86518709PassRefPtr<WebKitCSSFilterValue> CSSParser::parseBuiltinFilterArguments(CSSParserValueList* args, WebKitCSSFilterValue::FilterOperationType filterType)
  • trunk/Source/WebCore/css/CSSParser.h

    r143019 r143028  
    6969class WebKitCSSArrayFunctionValue;
    7070class WebKitCSSMixFunctionValue;
     71class WebKitCSSShaderValue;
    7172#endif
    7273
     
    244245    PassRefPtr<WebKitCSSFilterValue> parseCustomFilterFunctionWithInlineSyntax(CSSParserValue*);
    245246    PassRefPtr<WebKitCSSFilterValue> parseCustomFilterFunction(CSSParserValue*);
     247    bool parseFilterRuleSrc();
     248    PassRefPtr<WebKitCSSShaderValue> parseFilterRuleSrcUriAndFormat(CSSParserValueList*);
    246249#endif
    247250#endif
     
    374377    bool m_hasFontFaceOnlyValues;
    375378    bool m_hadSyntacticallyValidCSSRule;
     379
     380#if ENABLE(CSS_SHADERS)
     381    bool m_inFilterRule;
     382#endif
    376383
    377384    AtomicString m_defaultNamespace;
  • trunk/Source/WebCore/css/WebKitCSSShaderValue.cpp

    r142444 r143028  
    8181String WebKitCSSShaderValue::customCssText() const
    8282{
    83     return "url(" + quoteCSSURLIfNeeded(m_url) + ")";
     83    StringBuilder result;
     84    result.appendLiteral("url(");
     85    result.append(quoteCSSURLIfNeeded(m_url));
     86    result.append(')');
     87    if (!m_format.isEmpty()) {
     88        result.appendLiteral(" format('");
     89        result.append(m_format);
     90        result.appendLiteral("')");
     91    }
     92    return result.toString();
    8493}
    8594
     
    93102    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
    94103    info.addMember(m_url, "url");
     104    info.addMember(m_format, "format");
    95105}
    96106   
  • trunk/Source/WebCore/css/WebKitCSSShaderValue.h

    r142444 r143028  
    4646    ~WebKitCSSShaderValue();
    4747
     48    const String& format() const { return m_format; }
     49    void setFormat(const String& format) { m_format = format; }
     50
    4851    StyleCachedShader* cachedShader(CachedResourceLoader*);
    4952    StyleShader* cachedOrPendingShader();
     
    5962
    6063    String m_url;
     64    String m_format;
    6165    RefPtr<StyleShader> m_shader;
    6266    bool m_accessedShader;
Note: See TracChangeset for help on using the changeset viewer.