Changeset 251916 in webkit


Ignore:
Timestamp:
Nov 1, 2019 8:20:19 AM (4 years ago)
Author:
Antti Koivisto
Message:

Style::Builder should not depend on StyleResolver
https://bugs.webkit.org/show_bug.cgi?id=203729

Reviewed by Zalan Bujtas.

With all style building state in builder, we can remove the back-reference to style resolver.

  • css/CSSFilterImageValue.cpp:

(WebCore::CSSFilterImageValue::createFilterOperations):

  • css/CSSFilterImageValue.h:
  • css/CSSGradientValue.cpp:

(WebCore::CSSGradientValue::gradientWithStylesResolved):
(WebCore::CSSGradientValue::resolveRGBColors):

Add helper for resolving basic colors without style builder.

  • css/CSSGradientValue.h:
  • css/StyleResolver.cpp:

(WebCore::StyleResolver::State::clear):
(WebCore::StyleResolver::State::State):
(WebCore::StyleResolver::State::setStyle):
(WebCore::StyleResolver::applyMatchedProperties):

Register content attributes encountered during style building.

(WebCore::StyleResolver::State::updateConversionData): Deleted.

This is now created by BuilderState constructor.

(WebCore::StyleResolver::styleImage): Deleted.
(WebCore::StyleResolver::colorFromPrimitiveValueIsDerivedFromElement): Deleted.
(WebCore::StyleResolver::colorFromPrimitiveValue const): Deleted.
(WebCore::filterOperationForType): Deleted.
(WebCore::StyleResolver::createFilterOperations): Deleted.

Move image mapping functions to BuilderState.

  • css/StyleResolver.h:

(WebCore::StyleResolver::State::cssToLengthConversionData const): Deleted.

  • html/HTMLInputElement.cpp:

(WebCore::autoFillStrongPasswordMaskImage):
(WebCore::HTMLInputElement::createInnerTextStyle):

Create mask image without requiring style resolver.

  • style/StyleBuilder.cpp:

(WebCore::Style::Builder::Builder):

  • style/StyleBuilderCustom.h:

(WebCore::Style::BuilderCustom::applyValueZoom):
(WebCore::Style::BuilderCustom::applyValueContent):
(WebCore::Style::BuilderCustom::applyValueFontSize):
(WebCore::Style::BuilderCustom::applyValueAlt):

  • style/StyleBuilderState.cpp:

(WebCore::Style::BuilderState::BuilderState):

No more m_styleResolver.

(WebCore::Style::BuilderState::createStyleImage):
(WebCore::Style::filterOperationForType):
(WebCore::Style::BuilderState::createFilterOperations):
(WebCore::Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement):
(WebCore::Style::BuilderState::colorFromPrimitiveValue const):
(WebCore::Style::BuilderState::registerContentAttribute):

Collect content attributes so they can be applied later by StyleResolver.

  • style/StyleBuilderState.h:

(WebCore::Style::BuilderState::builder):
(WebCore::Style::BuilderState::rootElementStyle const):

Restore this to be nullable for simplicity.

(WebCore::Style::BuilderState::registeredContentAttributes const):
(WebCore::Style::BuilderState::styleResolver): Deleted.

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251914 r251916  
     12019-11-01  Antti Koivisto  <antti@apple.com>
     2
     3        Style::Builder should not depend on StyleResolver
     4        https://bugs.webkit.org/show_bug.cgi?id=203729
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        With all style building state in builder, we can remove the back-reference to style resolver.
     9
     10        * css/CSSFilterImageValue.cpp:
     11        (WebCore::CSSFilterImageValue::createFilterOperations):
     12        * css/CSSFilterImageValue.h:
     13        * css/CSSGradientValue.cpp:
     14        (WebCore::CSSGradientValue::gradientWithStylesResolved):
     15        (WebCore::CSSGradientValue::resolveRGBColors):
     16
     17        Add helper for resolving basic colors without style builder.
     18
     19        * css/CSSGradientValue.h:
     20        * css/StyleResolver.cpp:
     21        (WebCore::StyleResolver::State::clear):
     22        (WebCore::StyleResolver::State::State):
     23        (WebCore::StyleResolver::State::setStyle):
     24        (WebCore::StyleResolver::applyMatchedProperties):
     25
     26        Register content attributes encountered during style building.
     27
     28        (WebCore::StyleResolver::State::updateConversionData): Deleted.
     29
     30        This is now created by BuilderState constructor.
     31
     32        (WebCore::StyleResolver::styleImage): Deleted.
     33        (WebCore::StyleResolver::colorFromPrimitiveValueIsDerivedFromElement): Deleted.
     34        (WebCore::StyleResolver::colorFromPrimitiveValue const): Deleted.
     35        (WebCore::filterOperationForType): Deleted.
     36        (WebCore::StyleResolver::createFilterOperations): Deleted.
     37
     38        Move image mapping functions to BuilderState.
     39
     40        * css/StyleResolver.h:
     41        (WebCore::StyleResolver::State::cssToLengthConversionData const): Deleted.
     42        * html/HTMLInputElement.cpp:
     43        (WebCore::autoFillStrongPasswordMaskImage):
     44        (WebCore::HTMLInputElement::createInnerTextStyle):
     45
     46        Create mask image without requiring style resolver.
     47
     48        * style/StyleBuilder.cpp:
     49        (WebCore::Style::Builder::Builder):
     50        * style/StyleBuilderCustom.h:
     51        (WebCore::Style::BuilderCustom::applyValueZoom):
     52        (WebCore::Style::BuilderCustom::applyValueContent):
     53        (WebCore::Style::BuilderCustom::applyValueFontSize):
     54        (WebCore::Style::BuilderCustom::applyValueAlt):
     55        * style/StyleBuilderState.cpp:
     56        (WebCore::Style::BuilderState::BuilderState):
     57
     58        No more m_styleResolver.
     59
     60        (WebCore::Style::BuilderState::createStyleImage):
     61        (WebCore::Style::filterOperationForType):
     62        (WebCore::Style::BuilderState::createFilterOperations):
     63        (WebCore::Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement):
     64        (WebCore::Style::BuilderState::colorFromPrimitiveValue const):
     65        (WebCore::Style::BuilderState::registerContentAttribute):
     66
     67        Collect content attributes so they can be applied later by StyleResolver.
     68
     69        * style/StyleBuilderState.h:
     70        (WebCore::Style::BuilderState::builder):
     71        (WebCore::Style::BuilderState::rootElementStyle const):
     72
     73        Restore this to be nullable for simplicity.
     74
     75        (WebCore::Style::BuilderState::registeredContentAttributes const):
     76        (WebCore::Style::BuilderState::styleResolver): Deleted.
     77
    1782019-11-01  Zan Dobersek  <zdobersek@igalia.com>  and  Chris Lord  <clord@igalia.com>
    279
  • trunk/Source/WebCore/css/CSSFilterImageValue.cpp

    r251493 r251916  
    3434#include "ImageBuffer.h"
    3535#include "RenderElement.h"
     36#include "StyleBuilderState.h"
    3637#include "StyleCachedImage.h"
    37 #include "StyleResolver.h"
    3838#include <wtf/text/StringBuilder.h>
    3939
     
    141141}
    142142
    143 void CSSFilterImageValue::createFilterOperations(StyleResolver* resolver)
     143void CSSFilterImageValue::createFilterOperations(Style::BuilderState& builderState)
    144144{
    145145    m_filterOperations.clear();
    146     resolver->createFilterOperations(m_filterValue, m_filterOperations);
     146    builderState.createFilterOperations(m_filterValue, m_filterOperations);
    147147}
    148148
  • trunk/Source/WebCore/css/CSSFilterImageValue.h

    r251493 r251916  
    4040class RenderElement;
    4141class Document;
    42 class StyleResolver;
     42
     43namespace Style {
     44class BuilderState;
     45}
    4346
    4447class CSSFilterImageValue final : public CSSImageGeneratorValue {
     
    6972    bool equalInputImages(const CSSFilterImageValue&) const;
    7073
    71     void createFilterOperations(StyleResolver*);
     74    void createFilterOperations(Style::BuilderState&);
    7275
    7376    const FilterOperations& filterOperations() const { return m_filterOperations; }
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r251474 r251916  
    3737#include "RenderElement.h"
    3838#include "RenderView.h"
    39 #include "StyleResolver.h"
     39#include "StyleBuilderState.h"
    4040#include <wtf/text/StringBuilder.h>
    4141
     
    104104}
    105105
    106 Ref<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(const StyleResolver& styleResolver)
     106template<typename Function>
     107void resolveStopColors(Vector<CSSGradientColorStop, 2>& stops, Function&& colorResolveFunction)
     108{
     109    for (size_t i = 0; i < stops.size(); ++i) {
     110        auto& stop = stops[i];
     111        if (stop.isMidpoint)
     112            continue;
     113        if (stop.m_color)
     114            stop.m_resolvedColor = colorResolveFunction(*stop.m_color);
     115        else if (i) {
     116            auto& previousStop = stops[i - 1];
     117            ASSERT(previousStop.m_color);
     118            stop.m_color = previousStop.m_color;
     119            stop.m_resolvedColor = previousStop.m_resolvedColor;
     120        }
     121    }
     122}
     123
     124Ref<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(Style::BuilderState& builderState)
    107125{
    108126    bool colorIsDerivedFromElement = false;
    109127    for (auto& stop : m_stops) {
    110         if (!stop.isMidpoint && stop.m_color && styleResolver.colorFromPrimitiveValueIsDerivedFromElement(*stop.m_color)) {
     128        if (!stop.isMidpoint && stop.m_color && Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement(*stop.m_color)) {
    111129            stop.m_colorIsDerivedFromElement = true;
    112130            colorIsDerivedFromElement = true;
     
    115133    }
    116134    auto result = colorIsDerivedFromElement ? clone(*this) : makeRef(*this);
    117     for (size_t i = 0; i < result->m_stops.size(); ++i) {
    118         auto& stop = result->m_stops[i];
    119         if (stop.isMidpoint)
    120             continue;
    121         if (stop.m_color)
    122             stop.m_resolvedColor = styleResolver.colorFromPrimitiveValue(*stop.m_color);
    123         else if (i) {
    124             auto& previousStop = result->m_stops[i - 1];
    125             ASSERT(previousStop.m_color);
    126             stop.m_color = previousStop.m_color;
    127             stop.m_resolvedColor = previousStop.m_resolvedColor;
    128         }
    129     }
     135    resolveStopColors(result->m_stops, [&](const CSSPrimitiveValue& colorValue) {
     136        return builderState.colorFromPrimitiveValue(colorValue);
     137    });
    130138    return result;
     139}
     140
     141void CSSGradientValue::resolveRGBColors()
     142{
     143    resolveStopColors(m_stops, [&](const CSSPrimitiveValue& colorValue) {
     144        ASSERT(colorValue.isRGBColor());
     145        return colorValue.color();
     146    });
    131147}
    132148
  • trunk/Source/WebCore/css/CSSGradientValue.h

    r251437 r251916  
    3636class StyleResolver;
    3737
     38namespace Style {
     39class BuilderState;
     40}
     41
    3842enum CSSGradientType {
    3943    CSSDeprecatedLinearGradient,
     
    8791
    8892    void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&) { }
    89     Ref<CSSGradientValue> gradientWithStylesResolved(const StyleResolver&);
     93    Ref<CSSGradientValue> gradientWithStylesResolved(Style::BuilderState&);
     94    void resolveRGBColors();
    9095
    9196protected:
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r251864 r251916  
    3131#include "StyleResolver.h"
    3232
    33 #include "CSSCalculationValue.h"
    34 #include "CSSCursorImageValue.h"
    3533#include "CSSDefaultStyleSheets.h"
    36 #include "CSSFilterImageValue.h"
    3734#include "CSSFontSelector.h"
    38 #include "CSSFunctionValue.h"
    39 #include "CSSGradientValue.h"
    40 #include "CSSImageSetValue.h"
    41 #include "CSSImageValue.h"
    4235#include "CSSKeyframeRule.h"
    4336#include "CSSKeyframesRule.h"
     
    4538#include "CSSPrimitiveValueMappings.h"
    4639#include "CSSPropertyNames.h"
    47 #include "CSSReflectValue.h"
    4840#include "CSSSelector.h"
    49 #include "CSSShadowValue.h"
    5041#include "CSSStyleRule.h"
    5142#include "CSSStyleSheet.h"
    52 #include "CSSValueList.h"
    5343#include "CachedResourceLoader.h"
    5444#include "ElementRuleCollector.h"
    55 #include "FilterOperation.h"
    5645#include "Frame.h"
    5746#include "FrameSelection.h"
     
    8978#include "SharedStringHash.h"
    9079#include "StyleBuilder.h"
    91 #include "StyleColor.h"
    92 #include "StyleCachedImage.h"
    9380#include "StyleFontSizeFunctions.h"
    94 #include "StyleGeneratedImage.h"
    9581#include "StyleProperties.h"
    9682#include "StylePropertyShorthand.h"
     
    9884#include "StyleRule.h"
    9985#include "StyleSheetContents.h"
    100 #include "TransformFunctions.h"
    101 #include "TransformOperations.h"
    10286#include "UserAgentStyleSheets.h"
    10387#include "ViewportStyleResolver.h"
     
    129113    m_parentStyle = nullptr;
    130114    m_ownedParentStyle = nullptr;
    131     m_cssToLengthConversionData = CSSToLengthConversionData();
    132115}
    133116
     
    250233    else
    251234        m_rootElementStyle = documentElementStyle ? documentElementStyle : documentElement->renderStyle();
    252 
    253     updateConversionData();
    254 }
    255 
    256 inline void StyleResolver::State::updateConversionData()
    257 {
    258     m_cssToLengthConversionData = CSSToLengthConversionData(m_style.get(), m_rootElementStyle, m_element ? m_element->document().renderView() : nullptr);
    259235}
    260236
     
    262238{
    263239    m_style = WTFMove(style);
    264     updateConversionData();
    265240}
    266241
     
    12741249    builder.applyLowPriorityProperties();
    12751250
     1251    for (auto& contentAttribute : builder.state().registeredContentAttributes())
     1252        ruleSets().mutableFeatures().registerContentAttribute(contentAttribute);
     1253
    12761254    if (cacheItem || !cacheHash)
    12771255        return;
     
    12991277}
    13001278
    1301 RefPtr<StyleImage> StyleResolver::styleImage(CSSValue& value)
    1302 {
    1303     if (is<CSSImageGeneratorValue>(value)) {
    1304         if (is<CSSGradientValue>(value))
    1305             return StyleGeneratedImage::create(downcast<CSSGradientValue>(value).gradientWithStylesResolved(*this));
    1306 
    1307         if (is<CSSFilterImageValue>(value)) {
    1308             // FilterImage needs to calculate FilterOperations.
    1309             downcast<CSSFilterImageValue>(value).createFilterOperations(this);
    1310         }
    1311         return StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(value));
    1312     }
    1313 
    1314     if (is<CSSImageValue>(value) || is<CSSImageSetValue>(value) || is<CSSCursorImageValue>(value))
    1315         return StyleCachedImage::create(value);
    1316 
    1317     return nullptr;
    1318 }
    1319 
    13201279void StyleResolver::initializeFontStyle()
    13211280{
     
    13331292}
    13341293
    1335 bool StyleResolver::colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue& value)
    1336 {
    1337     switch (value.valueID()) {
    1338     case CSSValueWebkitText:
    1339     case CSSValueWebkitLink:
    1340     case CSSValueWebkitActivelink:
    1341     case CSSValueCurrentcolor:
    1342         return true;
    1343     default:
    1344         return false;
    1345     }
    1346 }
    1347 
    1348 Color StyleResolver::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const
    1349 {
    1350     if (value.isRGBColor())
    1351         return value.color();
    1352 
    1353     auto identifier = value.valueID();
    1354     switch (identifier) {
    1355     case CSSValueWebkitText:
    1356         return document().textColor();
    1357     case CSSValueWebkitLink:
    1358         return (m_state.element()->isLink() && forVisitedLink) ? document().visitedLinkColor() : document().linkColor();
    1359     case CSSValueWebkitActivelink:
    1360         return document().activeLinkColor();
    1361     case CSSValueWebkitFocusRingColor:
    1362         return RenderTheme::singleton().focusRingColor(document().styleColorOptions(m_state.style()));
    1363     case CSSValueCurrentcolor:
    1364         // Color is an inherited property so depending on it effectively makes the property inherited.
    1365         // FIXME: Setting the flag as a side effect of calling this function is a bit oblique. Can we do better?
    1366         m_state.style()->setHasExplicitlyInheritedProperties();
    1367         return m_state.style()->color();
    1368     default:
    1369         return StyleColor::colorFromKeyword(identifier, document().styleColorOptions(m_state.style()));
    1370     }
    1371 }
    1372 
    13731294void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExpression& expression, bool result)
    13741295{
     
    14161337}
    14171338
    1418 static FilterOperation::OperationType filterOperationForType(CSSValueID type)
    1419 {
    1420     switch (type) {
    1421     case CSSValueUrl:
    1422         return FilterOperation::REFERENCE;
    1423     case CSSValueGrayscale:
    1424         return FilterOperation::GRAYSCALE;
    1425     case CSSValueSepia:
    1426         return FilterOperation::SEPIA;
    1427     case CSSValueSaturate:
    1428         return FilterOperation::SATURATE;
    1429     case CSSValueHueRotate:
    1430         return FilterOperation::HUE_ROTATE;
    1431     case CSSValueInvert:
    1432         return FilterOperation::INVERT;
    1433     case CSSValueAppleInvertLightness:
    1434         return FilterOperation::APPLE_INVERT_LIGHTNESS;
    1435     case CSSValueOpacity:
    1436         return FilterOperation::OPACITY;
    1437     case CSSValueBrightness:
    1438         return FilterOperation::BRIGHTNESS;
    1439     case CSSValueContrast:
    1440         return FilterOperation::CONTRAST;
    1441     case CSSValueBlur:
    1442         return FilterOperation::BLUR;
    1443     case CSSValueDropShadow:
    1444         return FilterOperation::DROP_SHADOW;
    1445     default:
    1446         break;
    1447     }
    1448     ASSERT_NOT_REACHED();
    1449     return FilterOperation::NONE;
    1450 }
    1451 
    1452 bool StyleResolver::createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations)
    1453 {
    1454     State& state = m_state;
    1455     ASSERT(outOperations.isEmpty());
    1456 
    1457     if (is<CSSPrimitiveValue>(inValue)) {
    1458         auto& primitiveValue = downcast<CSSPrimitiveValue>(inValue);
    1459         if (primitiveValue.valueID() == CSSValueNone)
    1460             return true;
    1461     }
    1462 
    1463     if (!is<CSSValueList>(inValue))
    1464         return false;
    1465 
    1466     FilterOperations operations;
    1467     for (auto& currentValue : downcast<CSSValueList>(inValue)) {
    1468 
    1469         if (is<CSSPrimitiveValue>(currentValue)) {
    1470             auto& primitiveValue = downcast<CSSPrimitiveValue>(currentValue.get());
    1471             if (!primitiveValue.isURI())
    1472                 continue;
    1473 
    1474             String cssUrl = primitiveValue.stringValue();
    1475             URL url = document().completeURL(cssUrl);
    1476 
    1477             auto operation = ReferenceFilterOperation::create(cssUrl, url.fragmentIdentifier());
    1478             operations.operations().append(WTFMove(operation));
    1479             continue;
    1480         }
    1481 
    1482         if (!is<CSSFunctionValue>(currentValue))
    1483             continue;
    1484 
    1485         auto& filterValue = downcast<CSSFunctionValue>(currentValue.get());
    1486         FilterOperation::OperationType operationType = filterOperationForType(filterValue.name());
    1487 
    1488         // Check that all parameters are primitive values, with the
    1489         // exception of drop shadow which has a CSSShadowValue parameter.
    1490         const CSSPrimitiveValue* firstValue = nullptr;
    1491         if (operationType != FilterOperation::DROP_SHADOW) {
    1492             bool haveNonPrimitiveValue = false;
    1493             for (unsigned j = 0; j < filterValue.length(); ++j) {
    1494                 if (!is<CSSPrimitiveValue>(*filterValue.itemWithoutBoundsCheck(j))) {
    1495                     haveNonPrimitiveValue = true;
    1496                     break;
    1497                 }
    1498             }
    1499             if (haveNonPrimitiveValue)
    1500                 continue;
    1501             if (filterValue.length())
    1502                 firstValue = downcast<CSSPrimitiveValue>(filterValue.itemWithoutBoundsCheck(0));
    1503         }
    1504 
    1505         switch (operationType) {
    1506         case FilterOperation::GRAYSCALE:
    1507         case FilterOperation::SEPIA:
    1508         case FilterOperation::SATURATE: {
    1509             double amount = 1;
    1510             if (filterValue.length() == 1) {
    1511                 amount = firstValue->doubleValue();
    1512                 if (firstValue->isPercentage())
    1513                     amount /= 100;
    1514             }
    1515 
    1516             operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType));
    1517             break;
    1518         }
    1519         case FilterOperation::HUE_ROTATE: {
    1520             double angle = 0;
    1521             if (filterValue.length() == 1)
    1522                 angle = firstValue->computeDegrees();
    1523 
    1524             operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType));
    1525             break;
    1526         }
    1527         case FilterOperation::INVERT:
    1528         case FilterOperation::BRIGHTNESS:
    1529         case FilterOperation::CONTRAST:
    1530         case FilterOperation::OPACITY: {
    1531             double amount = 1;
    1532             if (filterValue.length() == 1) {
    1533                 amount = firstValue->doubleValue();
    1534                 if (firstValue->isPercentage())
    1535                     amount /= 100;
    1536             }
    1537 
    1538             operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType));
    1539             break;
    1540         }
    1541         case FilterOperation::APPLE_INVERT_LIGHTNESS: {
    1542             operations.operations().append(InvertLightnessFilterOperation::create());
    1543             break;
    1544         }
    1545         case FilterOperation::BLUR: {
    1546             Length stdDeviation = Length(0, Fixed);
    1547             if (filterValue.length() >= 1)
    1548                 stdDeviation = convertToFloatLength(firstValue, state.cssToLengthConversionData());
    1549             if (stdDeviation.isUndefined())
    1550                 return false;
    1551 
    1552             operations.operations().append(BlurFilterOperation::create(stdDeviation));
    1553             break;
    1554         }
    1555         case FilterOperation::DROP_SHADOW: {
    1556             if (filterValue.length() != 1)
    1557                 return false;
    1558 
    1559             const auto* cssValue = filterValue.itemWithoutBoundsCheck(0);
    1560             if (!is<CSSShadowValue>(cssValue))
    1561                 continue;
    1562 
    1563             const auto& item = downcast<CSSShadowValue>(*cssValue);
    1564             int x = item.x->computeLength<int>(state.cssToLengthConversionData());
    1565             int y = item.y->computeLength<int>(state.cssToLengthConversionData());
    1566             IntPoint location(x, y);
    1567             int blur = item.blur ? item.blur->computeLength<int>(state.cssToLengthConversionData()) : 0;
    1568             Color color;
    1569             if (item.color)
    1570                 color = colorFromPrimitiveValue(*item.color);
    1571 
    1572             operations.operations().append(DropShadowFilterOperation::create(location, blur, color.isValid() ? color : Color::transparent));
    1573             break;
    1574         }
    1575         default:
    1576             ASSERT_NOT_REACHED();
    1577             break;
    1578         }
    1579     }
    1580 
    1581     outOperations = operations;
    1582     return true;
    1583 }
    1584 
    15851339} // namespace WebCore
  • trunk/Source/WebCore/css/StyleResolver.h

    r251864 r251916  
    2323
    2424#include "CSSSelector.h"
    25 #include "CSSToLengthConversionData.h"
    26 #include "CSSToStyleMap.h"
    2725#include "DocumentRuleSets.h"
    2826#include "ElementRuleCollector.h"
     
    160158    void initializeFontStyle();
    161159
    162     static bool colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue&);
    163     Color colorFromPrimitiveValue(const CSSPrimitiveValue&, bool forVisitedLink = false) const;
    164 
    165160    bool hasSelectorForId(const AtomString&) const;
    166161    bool hasSelectorForAttribute(const Element&, const AtomString&) const;
     
    191186    void clearCachedPropertiesAffectedByViewportUnits();
    192187
    193     bool createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations);
    194 
    195188private:
    196189    void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*);
    197190    void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&);
    198    
    199     void adjustStyleForInterCharacterRuby();
    200    
     191       
    201192    enum ShouldUseMatchedPropertiesCache { DoNotUseMatchedPropertiesCache = 0, UseMatchedPropertiesCache };
    202193    void applyMatchedProperties(const MatchResult&, const Element&, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache);
     
    234225        const Color& backgroundColor() const { return m_backgroundColor; }
    235226
    236         const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; }
    237 
    238227        const SelectorFilter* selectorFilter() const { return m_selectorFilter; }
    239228       
    240229    private:
    241         void updateConversionData();
    242 
    243230        const Element* m_element { nullptr };
    244231        std::unique_ptr<RenderStyle> m_style;
     
    253240        Color m_backgroundColor;
    254241
    255         CSSToLengthConversionData m_cssToLengthConversionData;
    256 
    257242        bool m_hasUAAppearance { false };
    258243    };
     
    261246    const State& state() const { return m_state; }
    262247
    263     RefPtr<StyleImage> styleImage(CSSValue&);
    264 
    265248    InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; }
    266249
     
    269252private:
    270253    void cacheBorderAndBackground();
    271 
    272     void applySVGProperty(CSSPropertyID, CSSValue*);
    273254
    274255    static unsigned computeMatchedPropertiesHash(const MatchResult&);
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r251110 r251916  
    6363#include "SearchInputType.h"
    6464#include "Settings.h"
    65 #include "StyleResolver.h"
     65#include "StyleGeneratedImage.h"
    6666#include "TextControlInnerElements.h"
    6767#include <wtf/IsoMallocInlines.h>
     
    20672067    gradient->addStop(firstStop);
    20682068    gradient->addStop(secondStop);
     2069    gradient->resolveRGBColors();
     2070
    20692071    return gradient;
    20702072}
     
    20892091        textBlockStyle.setColor({ 0.0f, 0.0f, 0.0f, 0.6f });
    20902092        textBlockStyle.setTextOverflow(TextOverflow::Clip);
    2091         textBlockStyle.setMaskImage(styleResolver().styleImage(autoFillStrongPasswordMaskImage()));
     2093        textBlockStyle.setMaskImage(StyleGeneratedImage::create(autoFillStrongPasswordMaskImage()));
    20922094        // A stacking context is needed for the mask.
    20932095        if (textBlockStyle.hasAutoZIndex())
  • trunk/Source/WebCore/style/StyleBuilder.cpp

    r251864 r251916  
    3535#include "StyleBuilderGenerated.h"
    3636#include "StyleFontSizeFunctions.h"
     37#include "StyleResolver.h"
    3738
    3839namespace WebCore {
     
    4849Builder::Builder(StyleResolver& resolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties)
    4950    : m_cascade(matchResult, cascadeLevels, includedProperties, directionFromStyle(*resolver.style()))
    50     , m_state(*this, resolver)
    51 {
     51    , m_state(*this, *resolver.style(), *resolver.parentStyle(), resolver.rootElementStyle(), resolver.document(), resolver.element())
     52{
     53    ASSERT(resolver.style());
     54    ASSERT(resolver.parentStyle());
    5255}
    5356
  • trunk/Source/WebCore/style/StyleBuilderCustom.h

    r251864 r251916  
    220220        builderState.setZoom(RenderStyle::initialZoom());
    221221    } else if (primitiveValue.valueID() == CSSValueDocument) {
    222         float docZoom = builderState.rootElementStyle().zoom();
     222        float docZoom = builderState.rootElementStyle() ? builderState.rootElementStyle()->zoom() : RenderStyle::initialZoom();
    223223        builderState.setEffectiveZoom(docZoom);
    224224        builderState.setZoom(docZoom);
     
    13211321        if (is<CSSImageGeneratorValue>(item)) {
    13221322            if (is<CSSGradientValue>(item))
    1323                 builderState.style().setContent(StyleGeneratedImage::create(downcast<CSSGradientValue>(item.get()).gradientWithStylesResolved(builderState.styleResolver())), didSet);
     1323                builderState.style().setContent(StyleGeneratedImage::create(downcast<CSSGradientValue>(item.get()).gradientWithStylesResolved(builderState)), didSet);
    13241324            else
    13251325                builderState.style().setContent(StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(item.get())), didSet);
     
    13541354            didSet = true;
    13551355            // Register the fact that the attribute value affects the style.
    1356             builderState.styleResolver().ruleSets().mutableFeatures().registerContentAttribute(attr.localName());
     1356            builderState.registerContentAttribute(attr.localName());
    13571357        } else if (contentValue.isCounter()) {
    13581358            auto* counterValue = contentValue.counterValue();
     
    16121612        fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize || !(primitiveValue.isPercentage() || primitiveValue.isFontRelativeLength()));
    16131613        if (primitiveValue.isLength()) {
    1614             size = primitiveValue.computeLength<float>(CSSToLengthConversionData(&builderState.parentStyle(), &builderState.rootElementStyle(), builderState.document().renderView(), 1.0f, true));
     1614            size = primitiveValue.computeLength<float>(CSSToLengthConversionData(&builderState.parentStyle(), builderState.rootElementStyle(), builderState.document().renderView(), 1.0f, true));
    16151615            if (primitiveValue.isViewportPercentageLength())
    16161616                builderState.style().setHasViewportUnits();
     
    17481748
    17491749        // Register the fact that the attribute value affects the style.
    1750         builderState.styleResolver().ruleSets().mutableFeatures().registerContentAttribute(attr.localName());
     1750        builderState.registerContentAttribute(attr.localName());
    17511751    } else
    17521752        builderState.style().setContentAltText(emptyAtom());
  • trunk/Source/WebCore/style/StyleBuilderState.cpp

    r251864 r251916  
    3131#include "StyleBuilderState.h"
    3232
     33#include "CSSCursorImageValue.h"
     34#include "CSSFilterImageValue.h"
     35#include "CSSFunctionValue.h"
     36#include "CSSGradientValue.h"
     37#include "CSSImageSetValue.h"
     38#include "CSSImageValue.h"
     39#include "CSSShadowValue.h"
     40#include "RenderTheme.h"
    3341#include "SVGElement.h"
    3442#include "SVGSVGElement.h"
    3543#include "StyleBuilder.h"
    36 #include "StyleResolver.h"
     44#include "StyleCachedImage.h"
     45#include "StyleGeneratedImage.h"
     46#include "TransformFunctions.h"
    3747
    3848namespace WebCore {
    3949namespace Style {
    4050
    41 BuilderState::BuilderState(Builder& builder, StyleResolver& styleResolver)
     51BuilderState::BuilderState(Builder& builder, RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* rootElementStyle, const Document& document, const Element* element)
    4252    : m_builder(builder)
    4353    , m_styleMap(*this)
    44     , m_cssToLengthConversionData(styleResolver.state().cssToLengthConversionData())
    45     , m_styleResolver(styleResolver)
    46     , m_style(*styleResolver.style())
    47     , m_parentStyle(*styleResolver.parentStyle())
    48     , m_rootElementStyle(styleResolver.rootElementStyle() ? *styleResolver.rootElementStyle() : RenderStyle::defaultStyle())
    49     , m_document(m_styleResolver.document())
    50     , m_element(m_styleResolver.element())
    51 {
    52     ASSERT(styleResolver.style());
    53     ASSERT(styleResolver.parentStyle());
     54    , m_style(style)
     55    , m_parentStyle(parentStyle)
     56    , m_rootElementStyle(rootElementStyle)
     57    , m_cssToLengthConversionData(&style, rootElementStyle, document.renderView())
     58    , m_document(document)
     59    , m_element(element)
     60{
    5461}
    5562
     
    7481RefPtr<StyleImage> BuilderState::createStyleImage(CSSValue& value)
    7582{
    76     return m_styleResolver.styleImage(value);
    77 }
    78 
    79 bool BuilderState::createFilterOperations(const CSSValue& value, FilterOperations& outOperations)
    80 {
    81     return m_styleResolver.createFilterOperations(value, outOperations);
     83    if (is<CSSImageGeneratorValue>(value)) {
     84        if (is<CSSGradientValue>(value))
     85            return StyleGeneratedImage::create(downcast<CSSGradientValue>(value).gradientWithStylesResolved(*this));
     86
     87        if (is<CSSFilterImageValue>(value)) {
     88            // FilterImage needs to calculate FilterOperations.
     89            downcast<CSSFilterImageValue>(value).createFilterOperations(*this);
     90        }
     91        return StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(value));
     92    }
     93
     94    if (is<CSSImageValue>(value) || is<CSSImageSetValue>(value) || is<CSSCursorImageValue>(value))
     95        return StyleCachedImage::create(value);
     96
     97    return nullptr;
     98}
     99
     100static FilterOperation::OperationType filterOperationForType(CSSValueID type)
     101{
     102    switch (type) {
     103    case CSSValueUrl:
     104        return FilterOperation::REFERENCE;
     105    case CSSValueGrayscale:
     106        return FilterOperation::GRAYSCALE;
     107    case CSSValueSepia:
     108        return FilterOperation::SEPIA;
     109    case CSSValueSaturate:
     110        return FilterOperation::SATURATE;
     111    case CSSValueHueRotate:
     112        return FilterOperation::HUE_ROTATE;
     113    case CSSValueInvert:
     114        return FilterOperation::INVERT;
     115    case CSSValueAppleInvertLightness:
     116        return FilterOperation::APPLE_INVERT_LIGHTNESS;
     117    case CSSValueOpacity:
     118        return FilterOperation::OPACITY;
     119    case CSSValueBrightness:
     120        return FilterOperation::BRIGHTNESS;
     121    case CSSValueContrast:
     122        return FilterOperation::CONTRAST;
     123    case CSSValueBlur:
     124        return FilterOperation::BLUR;
     125    case CSSValueDropShadow:
     126        return FilterOperation::DROP_SHADOW;
     127    default:
     128        break;
     129    }
     130    ASSERT_NOT_REACHED();
     131    return FilterOperation::NONE;
     132}
     133
     134bool BuilderState::createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations)
     135{
     136    // FIXME: Move this code somewhere else.
     137
     138    ASSERT(outOperations.isEmpty());
     139
     140    if (is<CSSPrimitiveValue>(inValue)) {
     141        auto& primitiveValue = downcast<CSSPrimitiveValue>(inValue);
     142        if (primitiveValue.valueID() == CSSValueNone)
     143            return true;
     144    }
     145
     146    if (!is<CSSValueList>(inValue))
     147        return false;
     148
     149    FilterOperations operations;
     150    for (auto& currentValue : downcast<CSSValueList>(inValue)) {
     151
     152        if (is<CSSPrimitiveValue>(currentValue)) {
     153            auto& primitiveValue = downcast<CSSPrimitiveValue>(currentValue.get());
     154            if (!primitiveValue.isURI())
     155                continue;
     156
     157            String cssUrl = primitiveValue.stringValue();
     158            URL url = document().completeURL(cssUrl);
     159
     160            auto operation = ReferenceFilterOperation::create(cssUrl, url.fragmentIdentifier());
     161            operations.operations().append(WTFMove(operation));
     162            continue;
     163        }
     164
     165        if (!is<CSSFunctionValue>(currentValue))
     166            continue;
     167
     168        auto& filterValue = downcast<CSSFunctionValue>(currentValue.get());
     169        FilterOperation::OperationType operationType = filterOperationForType(filterValue.name());
     170
     171        // Check that all parameters are primitive values, with the
     172        // exception of drop shadow which has a CSSShadowValue parameter.
     173        const CSSPrimitiveValue* firstValue = nullptr;
     174        if (operationType != FilterOperation::DROP_SHADOW) {
     175            bool haveNonPrimitiveValue = false;
     176            for (unsigned j = 0; j < filterValue.length(); ++j) {
     177                if (!is<CSSPrimitiveValue>(*filterValue.itemWithoutBoundsCheck(j))) {
     178                    haveNonPrimitiveValue = true;
     179                    break;
     180                }
     181            }
     182            if (haveNonPrimitiveValue)
     183                continue;
     184            if (filterValue.length())
     185                firstValue = downcast<CSSPrimitiveValue>(filterValue.itemWithoutBoundsCheck(0));
     186        }
     187
     188        switch (operationType) {
     189        case FilterOperation::GRAYSCALE:
     190        case FilterOperation::SEPIA:
     191        case FilterOperation::SATURATE: {
     192            double amount = 1;
     193            if (filterValue.length() == 1) {
     194                amount = firstValue->doubleValue();
     195                if (firstValue->isPercentage())
     196                    amount /= 100;
     197            }
     198
     199            operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType));
     200            break;
     201        }
     202        case FilterOperation::HUE_ROTATE: {
     203            double angle = 0;
     204            if (filterValue.length() == 1)
     205                angle = firstValue->computeDegrees();
     206
     207            operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType));
     208            break;
     209        }
     210        case FilterOperation::INVERT:
     211        case FilterOperation::BRIGHTNESS:
     212        case FilterOperation::CONTRAST:
     213        case FilterOperation::OPACITY: {
     214            double amount = 1;
     215            if (filterValue.length() == 1) {
     216                amount = firstValue->doubleValue();
     217                if (firstValue->isPercentage())
     218                    amount /= 100;
     219            }
     220
     221            operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType));
     222            break;
     223        }
     224        case FilterOperation::APPLE_INVERT_LIGHTNESS: {
     225            operations.operations().append(InvertLightnessFilterOperation::create());
     226            break;
     227        }
     228        case FilterOperation::BLUR: {
     229            Length stdDeviation = Length(0, Fixed);
     230            if (filterValue.length() >= 1)
     231                stdDeviation = convertToFloatLength(firstValue, cssToLengthConversionData());
     232            if (stdDeviation.isUndefined())
     233                return false;
     234
     235            operations.operations().append(BlurFilterOperation::create(stdDeviation));
     236            break;
     237        }
     238        case FilterOperation::DROP_SHADOW: {
     239            if (filterValue.length() != 1)
     240                return false;
     241
     242            const auto* cssValue = filterValue.itemWithoutBoundsCheck(0);
     243            if (!is<CSSShadowValue>(cssValue))
     244                continue;
     245
     246            const auto& item = downcast<CSSShadowValue>(*cssValue);
     247            int x = item.x->computeLength<int>(cssToLengthConversionData());
     248            int y = item.y->computeLength<int>(cssToLengthConversionData());
     249            IntPoint location(x, y);
     250            int blur = item.blur ? item.blur->computeLength<int>(cssToLengthConversionData()) : 0;
     251            Color color;
     252            if (item.color)
     253                color = colorFromPrimitiveValue(*item.color);
     254
     255            operations.operations().append(DropShadowFilterOperation::create(location, blur, color.isValid() ? color : Color::transparent));
     256            break;
     257        }
     258        default:
     259            ASSERT_NOT_REACHED();
     260            break;
     261        }
     262    }
     263
     264    outOperations = operations;
     265    return true;
     266}
     267
     268bool BuilderState::isColorFromPrimitiveValueDerivedFromElement(const CSSPrimitiveValue& value)
     269{
     270    switch (value.valueID()) {
     271    case CSSValueWebkitText:
     272    case CSSValueWebkitLink:
     273    case CSSValueWebkitActivelink:
     274    case CSSValueCurrentcolor:
     275        return true;
     276    default:
     277        return false;
     278    }
    82279}
    83280
    84281Color BuilderState::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const
    85282{
    86     return m_styleResolver.colorFromPrimitiveValue(value, forVisitedLink);
     283    if (value.isRGBColor())
     284        return value.color();
     285
     286    auto identifier = value.valueID();
     287    switch (identifier) {
     288    case CSSValueWebkitText:
     289        return document().textColor();
     290    case CSSValueWebkitLink:
     291        return (element() && element()->isLink() && forVisitedLink) ? document().visitedLinkColor() : document().linkColor();
     292    case CSSValueWebkitActivelink:
     293        return document().activeLinkColor();
     294    case CSSValueWebkitFocusRingColor:
     295        return RenderTheme::singleton().focusRingColor(document().styleColorOptions(&m_style));
     296    case CSSValueCurrentcolor:
     297        // Color is an inherited property so depending on it effectively makes the property inherited.
     298        // FIXME: Setting the flag as a side effect of calling this function is a bit oblique. Can we do better?
     299        m_style.setHasExplicitlyInheritedProperties();
     300        return m_style.color();
     301    default:
     302        return StyleColor::colorFromKeyword(identifier, document().styleColorOptions(&m_style));
     303    }
     304}
     305
     306void BuilderState::registerContentAttribute(const AtomString& attributeLocalName)
     307{
     308    if (style().styleType() == PseudoId::Before || style().styleType() == PseudoId::After)
     309        m_registeredContentAttributes.append(attributeLocalName);
    87310}
    88311
  • trunk/Source/WebCore/style/StyleBuilderState.h

    r251864 r251916  
    4444class BuilderState {
    4545public:
    46     BuilderState(Builder&, StyleResolver&);
     46    BuilderState(Builder&, RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* rootElementStyle, const Document&, const Element*);
    4747
    4848    Builder& builder() { return m_builder; }
    49     StyleResolver& styleResolver() { return m_styleResolver; }
    5049
    5150    RenderStyle& style() { return m_style; }
    5251    const RenderStyle& parentStyle() const { return m_parentStyle; }
    53     const RenderStyle& rootElementStyle() const { return m_rootElementStyle; }
     52    const RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
    5453
    5554    const Document& document() const { return m_document.get(); }
     
    7978    RefPtr<StyleImage> createStyleImage(CSSValue&);
    8079    bool createFilterOperations(const CSSValue&, FilterOperations& outOperations);
     80
     81    static bool isColorFromPrimitiveValueDerivedFromElement(const CSSPrimitiveValue&);
    8182    Color colorFromPrimitiveValue(const CSSPrimitiveValue&, bool forVisitedLink = false) const;
     83
     84    const Vector<AtomString>& registeredContentAttributes() const { return m_registeredContentAttributes; }
     85    void registerContentAttribute(const AtomString& attributeLocalName);
    8286
    8387    const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; }
     
    100104
    101105    CSSToStyleMap m_styleMap;
    102     CSSToLengthConversionData m_cssToLengthConversionData;
    103 
    104     // FIXME: Remove.
    105     StyleResolver& m_styleResolver;
    106106
    107107    RenderStyle& m_style;
    108108    const RenderStyle& m_parentStyle;
    109     const RenderStyle& m_rootElementStyle;
     109    const RenderStyle* m_rootElementStyle;
     110
     111    const CSSToLengthConversionData m_cssToLengthConversionData;
    110112
    111113    Ref<const Document> m_document;
     
    122124
    123125    bool m_fontDirty { false };
     126    Vector<AtomString> m_registeredContentAttributes;
    124127};
    125128
Note: See TracChangeset for help on using the changeset viewer.