Ignore:
Timestamp:
Oct 29, 2017, 4:07:45 PM (8 years ago)
Author:
[email protected]
Message:

[Conic Gradients] Add support for parsing conic gradients
https://bugs.webkit.org/show_bug.cgi?id=178987

Reviewed by Dean Jackson.

Source/WebCore:

Adds initial support, disabled by default, for parsing conic gradients as per
CSS 4 Images - https://www.w3.org/TR/css-images-4/#conic-gradients.

Test: fast/gradients/conic-gradient-parsing.html

  • css/CSSGradientValue.cpp:

(WebCore::clone):
(WebCore::CSSGradientValue::isCacheable const):
(WebCore::CSSConicGradientValue::customCSSText const):
(WebCore::CSSConicGradientValue::createGradient):
(WebCore::CSSConicGradientValue::equals const):

  • css/CSSGradientValue.h:


Add CSSConicGradientValue as a subclass of CSSGradientValue and implement
customCSSText() and equals(). Stub out createGradient() as painting is not
yet implemented.


  • css/CSSImageGeneratorValue.cpp:

(WebCore::CSSImageGeneratorValue::image):
(WebCore::CSSImageGeneratorValue::isFixedSize const):
(WebCore::CSSImageGeneratorValue::fixedSize):
(WebCore::CSSImageGeneratorValue::isPending const):
(WebCore::CSSImageGeneratorValue::knownToBeOpaque const):
(WebCore::CSSImageGeneratorValue::loadSubimages):

  • css/CSSValue.cpp:

(WebCore::CSSValue::equals const):
(WebCore::CSSValue::cssText const):
(WebCore::CSSValue::destroy):

Dispatch to CSSConicGradientValue as needed.


  • css/CSSValue.h:

(WebCore::CSSValue::isImageGeneratorValue const):
(WebCore::CSSValue::isGradientValue const):
(WebCore::CSSValue::isConicGradientValue const):

Add conic gradient predicate support and update isImageGeneratorValue and
isGradientValue to include conic gradient.


  • css/CSSValueKeywords.in:


Add conic-gradient and repeating-conic-gradient.


  • css/parser/CSSParser.cpp:

(WebCore::CSSParserContext::CSSParserContext):
(WebCore::operator==):

  • css/parser/CSSParserMode.h:

(WebCore::CSSParserContextHash::hash):

Add runtime flags to enable conic gradients.


  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::consumeAngleOrPercent):

Helper, similar to consumeLengthOrPercent, for consumeGradientColorStops.
Corresponds to https://drafts.csswg.org/css-values-4/#typedef-angle-percentage


(WebCore::CSSPropertyParserHelpers::consumeGradientColorStops):

Convert to take CSSGradientValue by reference.


(WebCore::CSSPropertyParserHelpers::consumeAngularGradientColorStops):

Helper, similar to consumeGradientColorStops, but for angular color stops
used in conic gradients. Corresponds to https://www.w3.org/TR/css-images-4/#typedef-angular-color-stop-list
but does not yet support double position syntax.


(WebCore::CSSPropertyParserHelpers::consumeDeprecatedRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeLinearGradient):

Pass CSSGradientValue by reference.


(WebCore::CSSPropertyParserHelpers::consumeConicGradient):

Parse conic gradient.


(WebCore::CSSPropertyParserHelpers::consumeGeneratedImage):

Dispatch to consumeConicGradient for repeating and non-repeating
conic gradients.


(WebCore::CSSPropertyParserHelpers::isGeneratedImage):

Put each value on its own line to make it more readable and add CSSValueConicGradient
and CSSValueRepeatingConicGradient.


  • page/Settings.yaml:


Add a setting to enable conic gradients. Disabled by default.

  • features.json:


Move conic gradients to "In Development".

LayoutTests:

  • http/wpt/css: Added.
  • http/wpt/css/css-images-4: Added.
  • http/wpt/css/css-images-4/conic-gradient-parsing-expected.txt: Added.
  • http/wpt/css/css-images-4/conic-gradient-parsing.html: Added.

Add tests for basic parsing of conic gradients.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r210215 r224165  
    9696    if (is<CSSLinearGradientValue>(value))
    9797        return downcast<CSSLinearGradientValue>(value).clone();
    98     ASSERT(is<CSSRadialGradientValue>(value));
    99     return downcast<CSSRadialGradientValue>(value).clone();
     98    if (is<CSSRadialGradientValue>(value))
     99        return downcast<CSSRadialGradientValue>(value).clone();
     100    ASSERT(is<CSSConicGradientValue>(value));
     101    return downcast<CSSConicGradientValue>(value).clone();
    100102}
    101103
     
    545547bool CSSGradientValue::isCacheable() const
    546548{
    547     for (size_t i = 0; i < m_stops.size(); ++i) {
    548         const CSSGradientColorStop& stop = m_stops[i];
    549 
     549    for (auto& stop : m_stops) {
    550550        if (stop.m_colorIsDerivedFromElement)
    551551            return false;
     
    12751275}
    12761276
     1277
     1278String CSSConicGradientValue::customCSSText() const
     1279{
     1280    StringBuilder result;
     1281
     1282    if (m_repeating)
     1283        result.appendLiteral("repeating-conic-gradient(");
     1284    else
     1285        result.appendLiteral("conic-gradient(");
     1286
     1287    bool wroteSomething = false;
     1288
     1289    if (m_angle) {
     1290        result.appendLiteral("from ");
     1291        result.append(m_angle->cssText());
     1292        wroteSomething = true;
     1293    }
     1294
     1295    if (m_firstX && m_firstY) {
     1296        if (wroteSomething)
     1297            result.appendLiteral(" ");
     1298        result.appendLiteral("at ");
     1299        result.append(m_firstX->cssText());
     1300        result.append(' ');
     1301        result.append(m_firstY->cssText());
     1302        wroteSomething = true;
     1303    }
     1304
     1305    if (wroteSomething)
     1306        result.appendLiteral(", ");
     1307
     1308    bool wroteFirstStop = false;
     1309    for (auto& stop : m_stops) {
     1310        if (wroteFirstStop)
     1311            result.appendLiteral(", ");
     1312        wroteFirstStop = true;
     1313        if (!stop.isMidpoint)
     1314            result.append(stop.m_color->cssText());
     1315        if (stop.m_position) {
     1316            if (!stop.isMidpoint)
     1317                result.append(' ');
     1318            result.append(stop.m_position->cssText());
     1319        }
     1320    }
     1321   
     1322    result.append(')');
     1323    return result.toString();
     1324}
     1325
     1326Ref<Gradient> CSSConicGradientValue::createGradient(RenderElement&, const FloatSize&)
     1327{
     1328    // FIXME: Implement.
     1329    return Gradient::create(FloatPoint { }, FloatPoint { });
     1330}
     1331
     1332bool CSSConicGradientValue::equals(const CSSConicGradientValue& other) const
     1333{
     1334    if (m_repeating != other.m_repeating)
     1335        return false;
     1336
     1337    if (!compareCSSValuePtr(m_angle, other.m_angle))
     1338        return false;
     1339
     1340    bool equalXandY = false;
     1341    if (m_firstX && m_firstY)
     1342        equalXandY = compareCSSValuePtr(m_firstX, other.m_firstX) && compareCSSValuePtr(m_firstY, other.m_firstY);
     1343    else if (m_firstX)
     1344        equalXandY = compareCSSValuePtr(m_firstX, other.m_firstX) && !other.m_firstY;
     1345    else if (m_firstY)
     1346        equalXandY = compareCSSValuePtr(m_firstY, other.m_firstY) && !other.m_firstX;
     1347    else
     1348        equalXandY = !other.m_firstX && !other.m_firstY;
     1349
     1350    return equalXandY && m_stops == other.m_stops;
     1351}
     1352
    12771353} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.