Changeset 214324 in webkit


Ignore:
Timestamp:
Mar 23, 2017 4:14:02 PM (7 years ago)
Author:
mmaxfield@apple.com
Message:

font shorthand should accept variation values
https://bugs.webkit.org/show_bug.cgi?id=168998

Reviewed by Simon Fraser.

Source/WebCore:

The CSS Fonts 4 spec has stabilized as to which variation values are allowed in
the font shorthand property. Weights are allowed because a 0 weight is considered
as a parse error, so there is no conflict with a unitless font-size of 0.
font-style accepts angles, so there is no conflict there. However, font-stretch
accepts percentages, which are also accepted by font-size, which means the newly
extended grammar for font-stretch can't be accepted in the shorthand.

Tests: fast/text/font-style-parse.html

fast/text/font-weight-parse.html

  • css/parser/CSSPropertyParser.cpp:

(WebCore::consumeFontWeight):
(WebCore::consumeFontStyle):
(WebCore::CSSPropertyParser::consumeFont):
(WebCore::consumeFontWeightCSS21): Deleted.

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::consumeFontWeightNumber):

  • css/parser/CSSPropertyParserHelpers.h:

LayoutTests:

  • fast/text/font-style-parse-expected.txt:
  • fast/text/font-style-parse.html:
  • fast/text/font-weight-parse-expected.txt:
  • fast/text/font-weight-parse.html:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r214322 r214324  
     12017-03-22  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        font shorthand should accept variation values
     4        https://bugs.webkit.org/show_bug.cgi?id=168998
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/text/font-style-parse-expected.txt:
     9        * fast/text/font-style-parse.html:
     10        * fast/text/font-weight-parse-expected.txt:
     11        * fast/text/font-weight-parse.html:
     12
    1132017-03-23  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/fast/text/font-style-parse-expected.txt

    r213464 r214324  
    1919PASS window.getComputedStyle(document.getElementById('test19')).fontStyle is "italic"
    2020PASS window.getComputedStyle(document.getElementById('test20')).fontStyle is "normal"
     21PASS window.getComputedStyle(document.getElementById('test21')).fontStyle is "14deg"
    2122PASS window.getComputedStyle(document.getElementById('test1')).font is "normal normal normal normal 16px/18px Times"
    2223PASS window.getComputedStyle(document.getElementById('test2')).font is "16px/18px Times"
     
    3940PASS window.getComputedStyle(document.getElementById('test19')).font is "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'"
    4041PASS window.getComputedStyle(document.getElementById('test20')).font is "normal normal normal normal 16px/18px Times"
     42PASS window.getComputedStyle(document.getElementById('test21')).font is "48px/49px 'Helvetica Neue'"
    4143PASS document.getElementById('test1').style.font is ""
    4244PASS document.getElementById('test15').style.font is "italic 100 48px/49px 'Helvetica Neue'"
     
    4648PASS document.getElementById('test19').style.font is "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'"
    4749PASS document.getElementById('test20').style.font is ""
     50PASS document.getElementById('test21').style.font is "14deg small-caps 123 extra-expanded 48px/49px 'Helvetica Neue'"
    4851PASS successfullyParsed is true
    4952
  • trunk/LayoutTests/fast/text/font-style-parse.html

    r213464 r214324  
    2626<div id="test19" style="font: italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue';"></div>
    2727<div id="test20" style="font: 13deg small-caps 123 extra-expanded 48px/49px 'Helvetica Neue';"></div>
     28<div id="test21" style="font: oblique 14deg small-caps 123 extra-expanded 48px/49px 'Helvetica Neue';"></div>
    2829</div>
    2930<script>
     
    4849shouldBeEqualToString("window.getComputedStyle(document.getElementById('test19')).fontStyle", "italic");
    4950shouldBeEqualToString("window.getComputedStyle(document.getElementById('test20')).fontStyle", "normal");
     51shouldBeEqualToString("window.getComputedStyle(document.getElementById('test21')).fontStyle", "14deg");
    5052
    5153shouldBeEqualToString("window.getComputedStyle(document.getElementById('test1')).font", "normal normal normal normal 16px/18px Times");
     
    6971shouldBeEqualToString("window.getComputedStyle(document.getElementById('test19')).font", "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'");
    7072shouldBeEqualToString("window.getComputedStyle(document.getElementById('test20')).font", "normal normal normal normal 16px/18px Times");
     73shouldBeEqualToString("window.getComputedStyle(document.getElementById('test21')).font", "48px/49px 'Helvetica Neue'");
    7174
    7275shouldBeEqualToString("document.getElementById('test1').style.font", "");
     
    7780shouldBeEqualToString("document.getElementById('test19').style.font", "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'");
    7881shouldBeEqualToString("document.getElementById('test20').style.font", "");
     82shouldBeEqualToString("document.getElementById('test21').style.font", "14deg small-caps 123 extra-expanded 48px/49px 'Helvetica Neue'");
    7983</script>
    8084<script src="../../resources/js-test-post.js"></script>
  • trunk/LayoutTests/fast/text/font-weight-parse-expected.txt

    r213464 r214324  
    2222PASS window.getComputedStyle(document.getElementById('test22')).fontWeight is "100"
    2323PASS window.getComputedStyle(document.getElementById('test23')).fontWeight is "100"
    24 PASS window.getComputedStyle(document.getElementById('test24')).fontWeight is "normal"
     24PASS window.getComputedStyle(document.getElementById('test24')).fontWeight is "123"
     25PASS window.getComputedStyle(document.getElementById('test25')).fontWeight is "normal"
     26PASS window.getComputedStyle(document.getElementById('test26')).fontWeight is "normal"
     27PASS window.getComputedStyle(document.getElementById('test27')).fontWeight is "normal"
     28PASS window.getComputedStyle(document.getElementById('test28')).fontWeight is "0"
     29PASS window.getComputedStyle(document.getElementById('test29')).fontWeight is "1000"
    2530PASS window.getComputedStyle(document.getElementById('test1')).font is "normal normal normal normal 16px/18px Times"
    2631PASS window.getComputedStyle(document.getElementById('test2')).font is "16px/18px Times"
     
    4651PASS window.getComputedStyle(document.getElementById('test22')).font is "normal normal 100 normal 48px/49px 'Helvetica Neue'"
    4752PASS window.getComputedStyle(document.getElementById('test23')).font is "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'"
    48 PASS window.getComputedStyle(document.getElementById('test24')).font is "italic small-caps normal extra-expanded 48px/49px 'Helvetica Neue'"
     53PASS window.getComputedStyle(document.getElementById('test24')).font is "48px/49px 'Helvetica Neue'"
     54PASS window.getComputedStyle(document.getElementById('test25')).font is "normal normal normal normal 16px/18px Times"
     55PASS window.getComputedStyle(document.getElementById('test26')).font is "normal normal normal normal 16px/18px Times"
     56PASS window.getComputedStyle(document.getElementById('test27')).font is "normal normal normal normal 16px/18px Times"
     57PASS window.getComputedStyle(document.getElementById('test28')).font is "16px/18px Times"
     58PASS window.getComputedStyle(document.getElementById('test29')).font is "16px/18px Times"
    4959PASS document.getElementById('test1').style.font is ""
    5060PASS document.getElementById('test19').style.font is "100 extra-condensed 48px/49px 'Helvetica Neue'"
     
    5363PASS document.getElementById('test22').style.font is "100 48px/49px 'Helvetica Neue'"
    5464PASS document.getElementById('test23').style.font is "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'"
    55 PASS document.getElementById('test24').style.font is "italic small-caps extra-expanded 48px/49px 'Helvetica Neue'"
     65PASS document.getElementById('test24').style.font is "italic small-caps 123 extra-expanded 48px/49px 'Helvetica Neue'"
    5666PASS successfullyParsed is true
    5767
  • trunk/LayoutTests/fast/text/font-weight-parse.html

    r213464 r214324  
    3030<div id="test23" style="font: italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue';"></div>
    3131<div id="test24" style="font: italic small-caps 123 extra-expanded 48px/49px 'Helvetica Neue';"></div>
     32<div id="test25" style="font-weight: 0;"></div>
     33<div id="test26" style="font-weight: -7;"></div>
     34<div id="test27" style="font-weight: 1623;"></div>
     35<div id="test28" style="font-weight: calc(-4 - 5);"></div>
     36<div id="test29" style="font-weight: calc(600 + 700);"></div>
    3237</div>
    3338<script>
     
    5560shouldBeEqualToString("window.getComputedStyle(document.getElementById('test22')).fontWeight", "100");
    5661shouldBeEqualToString("window.getComputedStyle(document.getElementById('test23')).fontWeight", "100");
    57 shouldBeEqualToString("window.getComputedStyle(document.getElementById('test24')).fontWeight", "normal");
     62shouldBeEqualToString("window.getComputedStyle(document.getElementById('test24')).fontWeight", "123");
     63shouldBeEqualToString("window.getComputedStyle(document.getElementById('test25')).fontWeight", "normal");
     64shouldBeEqualToString("window.getComputedStyle(document.getElementById('test26')).fontWeight", "normal");
     65shouldBeEqualToString("window.getComputedStyle(document.getElementById('test27')).fontWeight", "normal");
     66shouldBeEqualToString("window.getComputedStyle(document.getElementById('test28')).fontWeight", "0");
     67shouldBeEqualToString("window.getComputedStyle(document.getElementById('test29')).fontWeight", "1000");
    5868
    5969shouldBeEqualToString("window.getComputedStyle(document.getElementById('test1')).font", "normal normal normal normal 16px/18px Times");
     
    8090shouldBeEqualToString("window.getComputedStyle(document.getElementById('test22')).font", "normal normal 100 normal 48px/49px 'Helvetica Neue'");
    8191shouldBeEqualToString("window.getComputedStyle(document.getElementById('test23')).font", "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'");
    82 shouldBeEqualToString("window.getComputedStyle(document.getElementById('test24')).font", "italic small-caps normal extra-expanded 48px/49px 'Helvetica Neue'");
     92shouldBeEqualToString("window.getComputedStyle(document.getElementById('test24')).font", "48px/49px 'Helvetica Neue'");
     93shouldBeEqualToString("window.getComputedStyle(document.getElementById('test25')).font", "normal normal normal normal 16px/18px Times");
     94shouldBeEqualToString("window.getComputedStyle(document.getElementById('test26')).font", "normal normal normal normal 16px/18px Times");
     95shouldBeEqualToString("window.getComputedStyle(document.getElementById('test27')).font", "normal normal normal normal 16px/18px Times");
     96shouldBeEqualToString("window.getComputedStyle(document.getElementById('test28')).font", "16px/18px Times");
     97shouldBeEqualToString("window.getComputedStyle(document.getElementById('test29')).font", "16px/18px Times");
    8398
    8499shouldBeEqualToString("document.getElementById('test1').style.font", "");
     
    88103shouldBeEqualToString("document.getElementById('test22').style.font", "100 48px/49px 'Helvetica Neue'");
    89104shouldBeEqualToString("document.getElementById('test23').style.font", "italic small-caps 100 extra-expanded 48px/49px 'Helvetica Neue'");
    90 shouldBeEqualToString("document.getElementById('test24').style.font", "italic small-caps extra-expanded 48px/49px 'Helvetica Neue'");
     105shouldBeEqualToString("document.getElementById('test24').style.font", "italic small-caps 123 extra-expanded 48px/49px 'Helvetica Neue'");
    91106</script>
    92107<script src="../../resources/js-test-post.js"></script>
  • trunk/Source/WebCore/ChangeLog

    r214322 r214324  
     12017-03-22  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        font shorthand should accept variation values
     4        https://bugs.webkit.org/show_bug.cgi?id=168998
     5
     6        Reviewed by Simon Fraser.
     7
     8        The CSS Fonts 4 spec has stabilized as to which variation values are allowed in
     9        the font shorthand property. Weights are allowed because a 0 weight is considered
     10        as a parse error, so there is no conflict with a unitless font-size of 0.
     11        font-style accepts angles, so there is no conflict there. However, font-stretch
     12        accepts percentages, which are also accepted by font-size, which means the newly
     13        extended grammar for font-stretch can't be accepted in the shorthand.
     14
     15        Tests: fast/text/font-style-parse.html
     16               fast/text/font-weight-parse.html
     17
     18        * css/parser/CSSPropertyParser.cpp:
     19        (WebCore::consumeFontWeight):
     20        (WebCore::consumeFontStyle):
     21        (WebCore::CSSPropertyParser::consumeFont):
     22        (WebCore::consumeFontWeightCSS21): Deleted.
     23        * css/parser/CSSPropertyParserHelpers.cpp:
     24        (WebCore::CSSPropertyParserHelpers::consumeFontWeightNumber):
     25        * css/parser/CSSPropertyParserHelpers.h:
     26
    1272017-03-23  Chris Dumez  <cdumez@apple.com>
    228
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r213831 r214324  
    870870}
    871871
    872 static RefPtr<CSSPrimitiveValue> consumeFontWeightCSS21(CSSParserTokenRange& range)
     872static RefPtr<CSSPrimitiveValue> consumeFontWeight(CSSParserTokenRange& range)
    873873{
    874874    if (auto result = consumeFontWeightKeywordValue(range))
    875875        return result;
    876     int weight;
    877     if (!consumePositiveIntegerRaw(range, weight))
    878         return nullptr;
    879     if (!isCSS21Weight(weight))
    880         return nullptr;
    881     return CSSValuePool::singleton().createValue(weight, CSSPrimitiveValue::CSS_NUMBER);
    882 }
    883 
    884 static RefPtr<CSSPrimitiveValue> consumeFontWeight(CSSParserTokenRange& range)
    885 {
    886     if (auto result = consumeFontWeightKeywordValue(range))
    887         return result;
    888     return consumeNumber(range, ValueRangeAll);
     876    return consumeFontWeightNumber(range);
    889877}
    890878
     
    983971            if (auto number = consumeNumber(range, ValueRangeAll))
    984972                return number;
    985             return nullptr;
    986973        }
    987974        return result;
     
    44314418        CSSValueID id = m_range.peek().id();
    44324419        if (!fontStyle) {
    4433             fontStyle = consumeFontStyleKeywordValue(m_range);
     4420            fontStyle = consumeFontStyle(m_range, m_context.mode);
    44344421            if (fontStyle)
    44354422                continue;
     
    44434430        }
    44444431        if (!fontWeight) {
    4445             fontWeight = consumeFontWeightCSS21(m_range);
     4432            fontWeight = consumeFontWeight(m_range);
    44464433            if (fontWeight)
    44474434                continue;
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r212131 r214324  
    195195        return calcParser.consumeNumber();
    196196    }
     197    return nullptr;
     198}
     199
     200RefPtr<CSSPrimitiveValue> consumeFontWeightNumber(CSSParserTokenRange& range)
     201{
     202    // Values less than or equal to 0 or greater than or equal to 1000 are parse errors.
     203    auto& token = range.peek();
     204    if (token.type() == NumberToken && token.numericValue() > 0 && token.numericValue() < 1000)
     205        return consumeNumber(range, ValueRangeAll);
     206
     207    // "[For calc()], the used value resulting from an expression must be clamped to the range allowed in the target context."
     208    CalcParser calcParser(range, ValueRangeAll);
     209    double result;
     210    if (calcParser.consumeNumberRaw(result)) {
     211        result = std::min(std::max(result, std::nextafter(0., 1.)), std::nextafter(1000., 0.));
     212        return CSSValuePool::singleton().createValue(result, CSSPrimitiveValue::UnitType::CSS_NUMBER);
     213    }
     214
    197215    return nullptr;
    198216}
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h

    r209526 r214324  
    6363bool consumeNumberRaw(CSSParserTokenRange&, double& result);
    6464RefPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRange&, ValueRange);
     65RefPtr<CSSPrimitiveValue> consumeFontWeightNumber(CSSParserTokenRange&);
    6566RefPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRange&, CSSParserMode, ValueRange, UnitlessQuirk = UnitlessQuirk::Forbid);
    6667RefPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange&, ValueRange);
Note: See TracChangeset for help on using the changeset viewer.