Changeset 251864 in webkit


Ignore:
Timestamp:
Oct 31, 2019 11:55:34 AM (4 years ago)
Author:
Antti Koivisto
Message:

Introduce Style::Builder
https://bugs.webkit.org/show_bug.cgi?id=203682

Reviewed by Zalan Bujtas.

Encapsulate the style building step into a new Builder class. It owns the cascade and the style building state.

Move tha applying code from StyleResolver and PropertyCascade there.
Move a bunch of font related state from StyleResolver::State to BuilderState.

  • DerivedSources-output.xcfilelist:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSVariableReferenceValue.cpp:

(WebCore::resolveVariableReference):

  • css/DOMCSSRegisterCustomProperty.cpp:

(WebCore::DOMCSSRegisterCustomProperty::registerProperty):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::applyPropertyToCurrentStyle):
(WebCore::StyleResolver::initializeFontStyle):
(WebCore::StyleResolver::adjustStyleForInterCharacterRuby): Deleted.
(WebCore::checkForOrientationChange): Deleted.
(WebCore::StyleResolver::updateFont): Deleted.
(WebCore::StyleResolver::useSVGZoomRules const): Deleted.
(WebCore::StyleResolver::useSVGZoomRulesForLength const): Deleted.
(WebCore::StyleResolver::checkForTextSizeAdjust): Deleted.
(WebCore::StyleResolver::checkForZoomChange): Deleted.
(WebCore::StyleResolver::checkForGenericFamilyChange): Deleted.
(WebCore::StyleResolver::setFontSize): Deleted.

  • css/StyleResolver.h:

(WebCore::StyleResolver::State::setFontSizeHasViewportUnits): Deleted.
(WebCore::StyleResolver::State::fontSizeHasViewportUnits const): Deleted.
(WebCore::StyleResolver::State::useSVGZoomRules const): Deleted.

  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseValueWithVariableReferences):

  • css/parser/CSSPropertyParser.cpp:
  • style/PropertyCascade.cpp:

(WebCore::Style::PropertyCascade::PropertyCascade):
(WebCore::Style::PropertyCascade::set):
(WebCore::Style::PropertyCascade::propertyCascadeForRollback const):
(WebCore::Style::PropertyCascade::resolveDirectionAndWritingMode const):
(WebCore::Style::PropertyCascade::applyDeferredProperties): Deleted.
(WebCore::Style::PropertyCascade::applyProperties): Deleted.
(WebCore::Style::PropertyCascade::applyPropertiesImpl): Deleted.
(WebCore::Style::PropertyCascade::applyCustomProperties): Deleted.
(WebCore::Style::PropertyCascade::applyCustomProperty): Deleted.
(WebCore::Style::PropertyCascade::propertyCascadeForRollback): Deleted.
(WebCore::Style::PropertyCascade::applyProperty): Deleted.
(WebCore::Style::PropertyCascade::resolveValue): Deleted.
(WebCore::Style::PropertyCascade::resolvedVariableValue): Deleted.
(WebCore::Style::PropertyCascade::resolveDirectionAndWritingMode): Deleted.

  • style/PropertyCascade.h:

(WebCore::Style::PropertyCascade::deferredProperties const):
(WebCore::Style::PropertyCascade::customProperties const):
(WebCore::Style::PropertyCascade::direction const):
(WebCore::Style::PropertyCascade::builderState): Deleted.

  • style/StyleBuilder.cpp: Added.

(WebCore::Style::directionFromStyle):
(WebCore::Style::Builder::Builder):
(WebCore::Style::Builder::applyAllProperties):
(WebCore::Style::Builder::applyHighPriorityProperties):
(WebCore::Style::Builder::applyLowPriorityProperties):
(WebCore::Style::Builder::applyPropertyValue):
(WebCore::Style::Builder::applyDeferredProperties):
(WebCore::Style::Builder::applyProperties):
(WebCore::Style::Builder::applyPropertiesImpl):
(WebCore::Style::Builder::applyCustomProperties):
(WebCore::Style::Builder::applyCustomProperty):
(WebCore::Style::Builder::applyCascadeProperty):
(WebCore::Style::Builder::applyProperty):
(WebCore::Style::Builder::resolveValue):
(WebCore::Style::Builder::resolvedVariableValue):

  • style/StyleBuilder.h: Added.

(WebCore::Style::Builder::applyProperty):
(WebCore::Style::Builder::state):

  • style/StyleBuilderCustom.h:

(WebCore::Style::BuilderCustom::applyValueFontSize):

  • style/StyleBuilderState.cpp:

(WebCore::Style::BuilderState::BuilderState):
(WebCore::Style::BuilderState::useSVGZoomRules const):
(WebCore::Style::BuilderState::useSVGZoomRulesForLength const):
(WebCore::Style::BuilderState::adjustStyleForInterCharacterRuby):
(WebCore::Style::BuilderState::updateFont):
(WebCore::Style::BuilderState::updateFontForTextSizeAdjust):
(WebCore::Style::BuilderState::updateFontForZoomChange):
(WebCore::Style::BuilderState::updateFontForGenericFamilyChange):
(WebCore::Style::BuilderState::updateFontForOrientationChange):
(WebCore::Style::BuilderState::setFontSize):

  • style/StyleBuilderState.h:

(WebCore::Style::BuilderState::builder):
(WebCore::Style::BuilderState::setFontDirty):
(WebCore::Style::BuilderState::cascade): Deleted.
(WebCore::Style::BuilderState::clearFontDirty): Deleted.

Location:
trunk/Source/WebCore
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251862 r251864  
     12019-10-31  Antti Koivisto  <antti@apple.com>
     2
     3        Introduce Style::Builder
     4        https://bugs.webkit.org/show_bug.cgi?id=203682
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Encapsulate the style building step into a new Builder class. It owns the cascade and the style building state.
     9
     10        Move tha applying code from StyleResolver and PropertyCascade there.
     11        Move a bunch of font related state from StyleResolver::State to BuilderState.
     12
     13        * DerivedSources-output.xcfilelist:
     14        * Sources.txt:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * css/CSSVariableReferenceValue.cpp:
     17        (WebCore::resolveVariableReference):
     18        * css/DOMCSSRegisterCustomProperty.cpp:
     19        (WebCore::DOMCSSRegisterCustomProperty::registerProperty):
     20        * css/StyleResolver.cpp:
     21        (WebCore::StyleResolver::styleForKeyframe):
     22        (WebCore::StyleResolver::styleForPage):
     23        (WebCore::StyleResolver::applyMatchedProperties):
     24        (WebCore::StyleResolver::applyPropertyToCurrentStyle):
     25        (WebCore::StyleResolver::initializeFontStyle):
     26        (WebCore::StyleResolver::adjustStyleForInterCharacterRuby): Deleted.
     27        (WebCore::checkForOrientationChange): Deleted.
     28        (WebCore::StyleResolver::updateFont): Deleted.
     29        (WebCore::StyleResolver::useSVGZoomRules const): Deleted.
     30        (WebCore::StyleResolver::useSVGZoomRulesForLength const): Deleted.
     31        (WebCore::StyleResolver::checkForTextSizeAdjust): Deleted.
     32        (WebCore::StyleResolver::checkForZoomChange): Deleted.
     33        (WebCore::StyleResolver::checkForGenericFamilyChange): Deleted.
     34        (WebCore::StyleResolver::setFontSize): Deleted.
     35        * css/StyleResolver.h:
     36        (WebCore::StyleResolver::State::setFontSizeHasViewportUnits): Deleted.
     37        (WebCore::StyleResolver::State::fontSizeHasViewportUnits const): Deleted.
     38        (WebCore::StyleResolver::State::useSVGZoomRules const): Deleted.
     39        * css/parser/CSSParser.cpp:
     40        (WebCore::CSSParser::parseValueWithVariableReferences):
     41        * css/parser/CSSPropertyParser.cpp:
     42        * style/PropertyCascade.cpp:
     43        (WebCore::Style::PropertyCascade::PropertyCascade):
     44        (WebCore::Style::PropertyCascade::set):
     45        (WebCore::Style::PropertyCascade::propertyCascadeForRollback const):
     46        (WebCore::Style::PropertyCascade::resolveDirectionAndWritingMode const):
     47        (WebCore::Style::PropertyCascade::applyDeferredProperties): Deleted.
     48        (WebCore::Style::PropertyCascade::applyProperties): Deleted.
     49        (WebCore::Style::PropertyCascade::applyPropertiesImpl): Deleted.
     50        (WebCore::Style::PropertyCascade::applyCustomProperties): Deleted.
     51        (WebCore::Style::PropertyCascade::applyCustomProperty): Deleted.
     52        (WebCore::Style::PropertyCascade::propertyCascadeForRollback): Deleted.
     53        (WebCore::Style::PropertyCascade::applyProperty): Deleted.
     54        (WebCore::Style::PropertyCascade::resolveValue): Deleted.
     55        (WebCore::Style::PropertyCascade::resolvedVariableValue): Deleted.
     56        (WebCore::Style::PropertyCascade::resolveDirectionAndWritingMode): Deleted.
     57        * style/PropertyCascade.h:
     58        (WebCore::Style::PropertyCascade::deferredProperties const):
     59        (WebCore::Style::PropertyCascade::customProperties const):
     60        (WebCore::Style::PropertyCascade::direction const):
     61        (WebCore::Style::PropertyCascade::builderState): Deleted.
     62        * style/StyleBuilder.cpp: Added.
     63        (WebCore::Style::directionFromStyle):
     64        (WebCore::Style::Builder::Builder):
     65        (WebCore::Style::Builder::applyAllProperties):
     66        (WebCore::Style::Builder::applyHighPriorityProperties):
     67        (WebCore::Style::Builder::applyLowPriorityProperties):
     68        (WebCore::Style::Builder::applyPropertyValue):
     69        (WebCore::Style::Builder::applyDeferredProperties):
     70        (WebCore::Style::Builder::applyProperties):
     71        (WebCore::Style::Builder::applyPropertiesImpl):
     72        (WebCore::Style::Builder::applyCustomProperties):
     73        (WebCore::Style::Builder::applyCustomProperty):
     74        (WebCore::Style::Builder::applyCascadeProperty):
     75        (WebCore::Style::Builder::applyProperty):
     76        (WebCore::Style::Builder::resolveValue):
     77        (WebCore::Style::Builder::resolvedVariableValue):
     78        * style/StyleBuilder.h: Added.
     79        (WebCore::Style::Builder::applyProperty):
     80        (WebCore::Style::Builder::state):
     81        * style/StyleBuilderCustom.h:
     82        (WebCore::Style::BuilderCustom::applyValueFontSize):
     83        * style/StyleBuilderState.cpp:
     84        (WebCore::Style::BuilderState::BuilderState):
     85        (WebCore::Style::BuilderState::useSVGZoomRules const):
     86        (WebCore::Style::BuilderState::useSVGZoomRulesForLength const):
     87        (WebCore::Style::BuilderState::adjustStyleForInterCharacterRuby):
     88        (WebCore::Style::BuilderState::updateFont):
     89        (WebCore::Style::BuilderState::updateFontForTextSizeAdjust):
     90        (WebCore::Style::BuilderState::updateFontForZoomChange):
     91        (WebCore::Style::BuilderState::updateFontForGenericFamilyChange):
     92        (WebCore::Style::BuilderState::updateFontForOrientationChange):
     93        (WebCore::Style::BuilderState::setFontSize):
     94        * style/StyleBuilderState.h:
     95        (WebCore::Style::BuilderState::builder):
     96        (WebCore::Style::BuilderState::setFontDirty):
     97        (WebCore::Style::BuilderState::cascade): Deleted.
     98        (WebCore::Style::BuilderState::clearFontDirty): Deleted.
     99
    11002019-10-31  Alex Christensen  <achristensen@webkit.org>
    2101
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r251850 r251864  
    21502150$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/Settings.h
    21512151$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StreamInternalsBuiltins.h
     2152$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StyleBuilder.cpp
    21522153$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StyleBuilderGenerated.cpp
    21532154$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StylePropertyShorthandFunctions.cpp
  • trunk/Source/WebCore/Sources.txt

    r251841 r251864  
    23462346style/InlineTextBoxStyle.cpp
    23472347style/PropertyCascade.cpp
     2348style/StyleBuilder.cpp
    23482349style/StyleBuilderState.cpp
    23492350style/StyleChange.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r251841 r251864  
    48444844                E4ABABF52368C6EF00FA4345 /* CascadeLevel.h in Headers */ = {isa = PBXBuildFile; fileRef = E4ABABF42368C6EF00FA4345 /* CascadeLevel.h */; };
    48454845                E4ABAC04236AE95900FA4345 /* StyleBuilderGenerated.h in Headers */ = {isa = PBXBuildFile; fileRef = E4ABAC02236AE95800FA4345 /* StyleBuilderGenerated.h */; };
     4846                E4ABAC06236B016D00FA4345 /* StyleBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E4ABAC05236B016C00FA4345 /* StyleBuilder.h */; };
    48464847                E4AE7C1617D1BB950009FB31 /* ElementIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1517D1BB950009FB31 /* ElementIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    48474848                E4AE7C1A17D232350009FB31 /* ElementAncestorIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1518115182                E4ABABF42368C6EF00FA4345 /* CascadeLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CascadeLevel.h; sourceTree = "<group>"; };
    1518215183                E4ABAC02236AE95800FA4345 /* StyleBuilderGenerated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilderGenerated.h; sourceTree = "<group>"; };
     15184                E4ABAC05236B016C00FA4345 /* StyleBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilder.h; sourceTree = "<group>"; };
     15185                E4ABAC07236B018100FA4345 /* StyleBuilder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StyleBuilder.cpp; sourceTree = "<group>"; };
    1518315186                E4AE7C1517D1BB950009FB31 /* ElementIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIterator.h; sourceTree = "<group>"; };
    1518415187                E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAncestorIterator.h; sourceTree = "<group>"; };
     
    2695926962                                E4ABABE52361A34200FA4345 /* PropertyCascade.cpp */,
    2696026963                                E4ABABE22361A32900FA4345 /* PropertyCascade.h */,
     26964                                E4ABAC07236B018100FA4345 /* StyleBuilder.cpp */,
     26965                                E4ABAC05236B016C00FA4345 /* StyleBuilder.h */,
    2696126966                                83B9687919F8AB83004EF7AF /* StyleBuilderConverter.h */,
    2696226967                                835D363619FF6193004C93AB /* StyleBuilderCustom.h */,
     
    3057330578                                93A806201E03B585008A1F26 /* JSLongRange.h in Headers */,
    3057430579                                CDAB6D2E17C814EE00C60B34 /* JSMediaControlsHost.h in Headers */,
     30580                                E4ABAC06236B016D00FA4345 /* StyleBuilder.h in Headers */,
    3057530581                                159741DB1B7D140100201C92 /* JSMediaDeviceInfo.h in Headers */,
    3057630582                                15739BBB1B42012D00D258C1 /* JSMediaDevices.h in Headers */,
  • trunk/Source/WebCore/css/CSSVariableReferenceValue.cpp

    r251796 r251864  
    3131#include "CSSVariableReferenceValue.h"
    3232
    33 #include "PropertyCascade.h"
    3433#include "RenderStyle.h"
     34#include "StyleBuilder.h"
    3535#include "StyleResolver.h"
    3636
     
    6868
    6969    // Apply this variable first, in case it is still unresolved
    70     builderState.cascade().applyCustomProperty(variableName);
     70    builderState.builder().applyCustomProperty(variableName);
    7171
    7272    // Apply fallback to detect cycles
  • trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp

    r251796 r251864  
    3434#include "DOMCSSNamespace.h"
    3535#include "Document.h"
    36 #include "PropertyCascade.h"
     36#include "StyleBuilder.h"
    3737#include "StyleBuilderConverter.h"
    3838#include <wtf/text/WTFString.h>
     
    6161
    6262        MatchResult matchResult;
    63         Style::PropertyCascade dummyCascade(styleResolver, matchResult, { });
    64         initialValue = CSSPropertyParser::parseTypedCustomPropertyValue(descriptor.name, descriptor.syntax, tokenizer.tokenRange(), dummyCascade.builderState(), strictCSSParserContext());
     63        Style::Builder dummyBuilder(styleResolver, matchResult, { });
     64        initialValue = CSSPropertyParser::parseTypedCustomPropertyValue(descriptor.name, descriptor.syntax, tokenizer.tokenRange(), dummyBuilder.state(), strictCSSParserContext());
    6565
    6666        if (!initialValue || !initialValue->isResolved())
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r251796 r251864  
    33 * Copyright (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
    44 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
    5  * Copyright (C) 2005-2014 Apple Inc. All rights reserved.
     5 * Copyright (C) 2005-2019 Apple Inc. All rights reserved.
    66 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
    77 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
     
    3333#include "CSSCalculationValue.h"
    3434#include "CSSCursorImageValue.h"
    35 #include "CSSCustomPropertyValue.h"
    3635#include "CSSDefaultStyleSheets.h"
    3736#include "CSSFilterImageValue.h"
     
    5251#include "CSSStyleSheet.h"
    5352#include "CSSValueList.h"
    54 #include "CSSValuePool.h"
    5553#include "CachedResourceLoader.h"
    5654#include "ElementRuleCollector.h"
     
    7472#include "NodeRenderStyle.h"
    7573#include "PageRuleCollector.h"
    76 #include "PaintWorkletGlobalScope.h"
    7774#include "Pair.h"
    78 #include "PropertyCascade.h"
    7975#include "Quirks.h"
    8076#include "RenderScrollbar.h"
     
    8884#include "SVGFontFaceElement.h"
    8985#include "SVGNames.h"
    90 #include "SVGSVGElement.h"
    9186#include "SVGURIReference.h"
    9287#include "Settings.h"
    9388#include "ShadowRoot.h"
    9489#include "SharedStringHash.h"
     90#include "StyleBuilder.h"
    9591#include "StyleColor.h"
    9692#include "StyleCachedImage.h"
     
    118114using namespace HTMLNames;
    119115
    120 static const CSSPropertyID firstLowPriorityProperty = static_cast<CSSPropertyID>(lastHighPriorityProperty + 1);
    121 
    122116inline void StyleResolver::State::cacheBorderAndBackground()
    123117{
     
    364358    state.setParentStyle(RenderStyle::clonePtr(*elementStyle));
    365359
    366     Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author });
    367 
    368     cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
    369 
    370     // If our font got dirtied, update it now.
    371     updateFont(cascade);
    372 
    373     // Now resolve remaining custom properties and the rest, in any order
    374     cascade.applyCustomProperties();
    375 
    376     cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty);
    377 
    378     // If our font got dirtied by one of the non-essential font props, update it a second time.
    379     updateFont(cascade);
    380 
    381     cascade.applyDeferredProperties();
     360    Style::Builder builder(*this, result, { Style::CascadeLevel::Author });
     361    builder.applyAllProperties();
    382362
    383363    adjustRenderStyle(*state.style(), *state.parentStyle(), nullptr, nullptr);
     
    564544    auto& result = collector.matchResult();
    565545
    566     Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author });
    567 
    568     cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
    569 
    570     // If our font got dirtied, update it now.
    571     updateFont(cascade);
    572 
    573     // Now resolve remaining custom properties and the rest, in any order
    574     cascade.applyCustomProperties();
    575 
    576     cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty);
    577 
    578     cascade.applyDeferredProperties();
     546    Style::Builder builder(*this, result, { Style::CascadeLevel::Author });
     547    builder.applyAllProperties();
    579548
    580549    // Now return the style.
     
    679648}
    680649#endif
    681 
    682 void StyleResolver::adjustStyleForInterCharacterRuby()
    683 {
    684     RenderStyle* style = m_state.style();
    685     if (style->rubyPosition() != RubyPosition::InterCharacter || !m_state.element() || !m_state.element()->hasTagName(rtTag))
    686         return;
    687     style->setTextAlign(TextAlignMode::Center);
    688     if (style->isHorizontalWritingMode())
    689         style->setWritingMode(LeftToRightWritingMode);
    690 }
    691650
    692651static bool hasEffectiveDisplayNoneForDisplayContents(const Element& element)
     
    11421101}
    11431102
    1144 static void checkForOrientationChange(RenderStyle& style)
    1145 {
    1146     auto [fontOrientation, glyphOrientation] = style.fontAndGlyphOrientation();
    1147 
    1148     const auto& fontDescription = style.fontDescription();
    1149     if (fontDescription.orientation() == fontOrientation && fontDescription.nonCJKGlyphOrientation() == glyphOrientation)
    1150         return;
    1151 
    1152     auto newFontDescription = fontDescription;
    1153     newFontDescription.setNonCJKGlyphOrientation(glyphOrientation);
    1154     newFontDescription.setOrientation(fontOrientation);
    1155     style.setFontDescription(WTFMove(newFontDescription));
    1156 }
    1157 
    1158 void StyleResolver::updateFont(Style::PropertyCascade& cascade)
    1159 {
    1160     auto& style = *m_state.style();
    1161     if (!cascade.builderState().fontDirty() && style.fontCascade().fonts())
    1162         return;
    1163 
    1164 #if ENABLE(TEXT_AUTOSIZING)
    1165     checkForTextSizeAdjust(style);
    1166 #endif
    1167     checkForGenericFamilyChange(style, m_state.parentStyle());
    1168     checkForZoomChange(style, m_state.parentStyle());
    1169     checkForOrientationChange(style);
    1170     style.fontCascade().update(&document().fontSelector());
    1171     if (m_state.fontSizeHasViewportUnits())
    1172         style.setHasViewportUnits(true);
    1173 
    1174     cascade.builderState().clearFontDirty();
    1175 }
    11761103
    11771104Vector<RefPtr<StyleRule>> StyleResolver::styleRulesForElement(const Element* element, unsigned rulesToInclude)
     
    13261253        // If so, we cache the border and background styles so that RenderTheme::adjustStyle()
    13271254        // can look at them later to figure out if this is a styled form control or not.
    1328         Style::PropertyCascade cascade(*this, matchResult, { Style::CascadeLevel::UserAgent }, includedProperties);
    1329 
    1330         cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition);
    1331         adjustStyleForInterCharacterRuby();
    1332 
    1333 #if ENABLE(DARK_MODE_CSS)
    1334         // Supported color schemes can affect resolved colors, so we need to apply that property before any color properties.
    1335         cascade.applyProperties(CSSPropertyColorScheme, CSSPropertyColorScheme);
    1336 #endif
    1337 
    1338         cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
    1339 
    1340         // If our font got dirtied, update it now.
    1341         updateFont(cascade);
    1342 
    1343         // Now resolve remaining custom properties and the rest, in any order
    1344         cascade.applyCustomProperties();
    1345 
    1346         cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty);
     1255        Style::Builder builder(*this, matchResult, { Style::CascadeLevel::UserAgent }, includedProperties);
     1256        builder.applyAllProperties();
    13471257
    13481258        state.cacheBorderAndBackground();
    13491259    }
    13501260
    1351     Style::PropertyCascade cascade(*this, matchResult, Style::allCascadeLevels(), includedProperties);
    1352 
    1353     cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition);
    1354     adjustStyleForInterCharacterRuby();
    1355 
    1356 #if ENABLE(DARK_MODE_CSS)
    1357     // Supported color schemes can affect resolved colors, so we need to apply that property before any color properties.
    1358     cascade.applyProperties(CSSPropertyColorScheme, CSSPropertyColorScheme);
    1359 #endif
    1360 
    1361     cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty);
     1261    Style::Builder builder(*this, matchResult, Style::allCascadeLevels(), includedProperties);
     1262
     1263    // High priority properties may affect resolution of other properties (they are mostly font related).
     1264    builder.applyHighPriorityProperties();
    13621265
    13631266    // If the effective zoom value changes, we can't use the matched properties cache. Start over.
     
    13651268        return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);
    13661269
    1367     // If our font got dirtied, update it now.
    1368     updateFont(cascade);
    1369 
    13701270    // If the font changed, we can't use the matched properties cache. Start over.
    13711271    if (cacheItem && cacheItem->renderStyle->fontDescription() != state.style()->fontDescription())
    13721272        return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);
    13731273
    1374     // Now resolve remaining custom properties and the rest, in any order
    1375     cascade.applyCustomProperties();
    1376 
    1377     cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty);
    1378 
    1379     // Finally, some properties must be applied in the order they were parsed.
    1380     // There are some CSS properties that affect the same RenderStyle values,
    1381     // so to preserve behavior, we queue them up during cascade and flush here.
    1382     cascade.applyDeferredProperties();
    1383 
    1384     ASSERT(!cascade.builderState().fontDirty());
     1274    builder.applyLowPriorityProperties();
    13851275
    13861276    if (cacheItem || !cacheHash)
     
    14051295
    14061296    MatchResult matchResult;
    1407     Style::PropertyCascade cascade(*this, matchResult, { });
    1408     cascade.applyProperty(id, *value);
    1409     updateFont(cascade);
    1410 }
    1411 
    1412 // SVG handles zooming in a different way compared to CSS. The whole document is scaled instead
    1413 // of each individual length value in the render style / tree. CSSPrimitiveValue::computeLength*()
    1414 // multiplies each resolved length with the zoom multiplier - so for SVG we need to disable that.
    1415 // Though all CSS values that can be applied to outermost <svg> elements (width/height/border/padding...)
    1416 // need to respect the scaling. RenderBox (the parent class of RenderSVGRoot) grabs values like
    1417 // width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale,
    1418 // if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific
    1419 // properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size).
    1420 bool StyleResolver::useSVGZoomRules() const
    1421 {
    1422     return m_state.element() && m_state.element()->isSVGElement();
    1423 }
    1424 
    1425 // Scale with/height properties on inline SVG root.
    1426 bool StyleResolver::useSVGZoomRulesForLength() const
    1427 {
    1428     return is<SVGElement>(m_state.element()) && !(is<SVGSVGElement>(*m_state.element()) && m_state.element()->parentNode());
     1297    Style::Builder builder(*this, matchResult, { });
     1298    builder.applyPropertyValue(id, *value);
    14291299}
    14301300
     
    14461316
    14471317    return nullptr;
    1448 }
    1449 
    1450 #if ENABLE(TEXT_AUTOSIZING)
    1451 void StyleResolver::checkForTextSizeAdjust(RenderStyle& style)
    1452 {
    1453     if (style.textSizeAdjust().isAuto()
    1454         || !settings().textAutosizingEnabled()
    1455         || (settings().textAutosizingUsesIdempotentMode() && !style.textSizeAdjust().isNone()))
    1456         return;
    1457 
    1458     auto newFontDescription = style.fontDescription();
    1459     if (!style.textSizeAdjust().isNone())
    1460         newFontDescription.setComputedSize(newFontDescription.specifiedSize() * style.textSizeAdjust().multiplier());
    1461     else
    1462         newFontDescription.setComputedSize(newFontDescription.specifiedSize());
    1463     style.setFontDescription(WTFMove(newFontDescription));
    1464 }
    1465 #endif
    1466 
    1467 void StyleResolver::checkForZoomChange(RenderStyle& style, const RenderStyle* parentStyle)
    1468 {
    1469     if (!parentStyle)
    1470         return;
    1471 
    1472     if (style.effectiveZoom() == parentStyle->effectiveZoom() && style.textZoom() == parentStyle->textZoom())
    1473         return;
    1474 
    1475     const auto& childFont = style.fontDescription();
    1476     auto newFontDescription = childFont;
    1477     setFontSize(newFontDescription, childFont.specifiedSize());
    1478     style.setFontDescription(WTFMove(newFontDescription));
    1479 }
    1480 
    1481 void StyleResolver::checkForGenericFamilyChange(RenderStyle& style, const RenderStyle* parentStyle)
    1482 {
    1483     const auto& childFont = style.fontDescription();
    1484 
    1485     if (childFont.isAbsoluteSize() || !parentStyle)
    1486         return;
    1487 
    1488     const auto& parentFont = parentStyle->fontDescription();
    1489     if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())
    1490         return;
    1491     // We know the parent is monospace or the child is monospace, and that font
    1492     // size was unspecified. We want to scale our font size as appropriate.
    1493     // If the font uses a keyword size, then we refetch from the table rather than
    1494     // multiplying by our scale factor.
    1495     float size;
    1496     if (CSSValueID sizeIdentifier = childFont.keywordSizeAsIdentifier())
    1497         size = Style::fontSizeForKeyword(sizeIdentifier, childFont.useFixedDefaultSize(), document());
    1498     else {
    1499         float fixedScaleFactor = (settings().defaultFixedFontSize() && settings().defaultFontSize())
    1500             ? static_cast<float>(settings().defaultFixedFontSize()) / settings().defaultFontSize()
    1501             : 1;
    1502         size = parentFont.useFixedDefaultSize() ?
    1503                 childFont.specifiedSize() / fixedScaleFactor :
    1504                 childFont.specifiedSize() * fixedScaleFactor;
    1505     }
    1506 
    1507     auto newFontDescription = childFont;
    1508     setFontSize(newFontDescription, size);
    1509     style.setFontDescription(WTFMove(newFontDescription));
    15101318}
    15111319
     
    15161324    fontDescription.setOneFamily(standardFamily);
    15171325    fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
    1518     setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueMedium, false, document()));
     1326
     1327    auto size = Style::fontSizeForKeyword(CSSValueMedium, false, document());
     1328    fontDescription.setSpecifiedSize(size);
     1329    fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), is<SVGElement>(m_state.element()), m_state.style(), document()));
     1330
    15191331    fontDescription.setShouldAllowUserInstalledFonts(settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No);
    15201332    style()->setFontDescription(WTFMove(fontDescription));
    1521 }
    1522 
    1523 void StyleResolver::setFontSize(FontCascadeDescription& fontDescription, float size)
    1524 {
    1525     fontDescription.setSpecifiedSize(size);
    1526     fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules(), m_state.style(), document()));
    15271333}
    15281334
  • trunk/Source/WebCore/css/StyleResolver.h

    r251796 r251864  
    6464class MediaQueryEvaluator;
    6565class Node;
    66 class RenderScrollbar;
    6766class RuleData;
    6867class RuleSet;
     
    8180class StyledElement;
    8281class SVGElement;
    83 class SVGSVGElement;
    8482class ViewportStyleResolver;
    8583struct ResourceLoaderOptions;
    86 
    87 namespace Style {
    88 class PropertyCascade;
    89 }
    9084
    9185// MatchOnlyUserAgentRules is used in media queries, where relative units
     
    164158    void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*);
    165159
    166     void updateFont(Style::PropertyCascade&);
    167160    void initializeFontStyle();
    168 
    169     void setFontSize(FontCascadeDescription&, float size);
    170 
    171     bool useSVGZoomRules() const;
    172     bool useSVGZoomRulesForLength() const;
    173161
    174162    static bool colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue&);
     
    206194
    207195private:
    208     // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
    209     void checkForGenericFamilyChange(RenderStyle&, const RenderStyle* parentStyle);
    210     void checkForZoomChange(RenderStyle&, const RenderStyle* parentStyle);
    211 #if ENABLE(TEXT_AUTOSIZING)
    212     void checkForTextSizeAdjust(RenderStyle&);
    213 #endif
    214 
    215196    void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*);
    216197    void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&);
     
    247228        const RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
    248229
    249         void setFontSizeHasViewportUnits(bool hasViewportUnits) { m_fontSizeHasViewportUnits = hasViewportUnits; }
    250         bool fontSizeHasViewportUnits() const { return m_fontSizeHasViewportUnits; }
    251 
    252230        void cacheBorderAndBackground();
    253231        bool hasUAAppearance() const { return m_hasUAAppearance; }
     
    256234        const Color& backgroundColor() const { return m_backgroundColor; }
    257235
    258         bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }
    259 
    260236        const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; }
    261237
     
    279255        CSSToLengthConversionData m_cssToLengthConversionData;
    280256
    281         bool m_fontSizeHasViewportUnits { false };
    282257        bool m_hasUAAppearance { false };
    283258    };
  • trunk/Source/WebCore/css/parser/CSSParser.cpp

    r251796 r251864  
    4343#include "Element.h"
    4444#include "Page.h"
    45 #include "PropertyCascade.h"
    4645#include "RenderStyle.h"
    4746#include "RenderTheme.h"
    4847#include "Settings.h"
     48#include "StyleBuilder.h"
    4949#include "StyleColor.h"
    5050#include "StyleResolver.h"
     
    235235
    236236    for (auto id : dependencies)
    237         builderState.cascade().applyProperties(id, id);
     237        builderState.builder().applyProperty(id);
    238238
    239239    return CSSPropertyParser::parseTypedCustomPropertyValue(name, syntax, resolvedData->tokens(), builderState, m_context);
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r251841 r251864  
    6868// FIXME-NEWPARSER: Replace Pair and Rect with actual CSSValue subclasses (CSSValuePair and CSSQuadValue).
    6969#include "Pair.h"
    70 #include "PropertyCascade.h"
    7170#include "Rect.h"
    7271#include "RenderTheme.h"
     
    7473#include "SVGPathByteStream.h"
    7574#include "SVGPathUtilities.h"
     75#include "StyleBuilder.h"
    7676#include "StyleBuilderConverter.h"
    7777#include "StylePropertyShorthand.h"
  • trunk/Source/WebCore/style/PropertyCascade.cpp

    r251841 r251864  
    3333#include "StyleBuilderGenerated.h"
    3434#include "StylePropertyShorthand.h"
    35 #include "StyleResolver.h"
    3635
    3736namespace WebCore {
     
    174173#endif
    175174
    176 PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, IncludedProperties includedProperties)
     175PropertyCascade::PropertyCascade(const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, IncludedProperties includedProperties, Direction direction)
    177176    : m_matchResult(matchResult)
    178177    , m_includedProperties(includedProperties)
    179     , m_builderState(std::in_place, *this, styleResolver)
    180 {
    181     // Directional properties (*-before/after) are aliases that depend on the TextDirection and WritingMode.
    182     // These must be resolved before we can begin building the property cascade.
    183     resolveDirectionAndWritingMode();
    184 
     178    , m_direction(resolveDirectionAndWritingMode(direction))
     179{
    185180    buildCascade(cascadeLevels);
    186181}
    187182
    188183PropertyCascade::PropertyCascade(const PropertyCascade& parent, OptionSet<CascadeLevel> cascadeLevels)
    189     :  m_matchResult(parent.m_matchResult)
     184    : m_matchResult(parent.m_matchResult)
    190185    , m_includedProperties(parent.m_includedProperties)
    191186    , m_direction(parent.m_direction)
    192     , m_writingMode(parent.m_writingMode)
    193187{
    194188    buildCascade(cascadeLevels);
     
    231225{
    232226    if (CSSProperty::isDirectionAwareProperty(id))
    233         id = CSSProperty::resolveDirectionAwareProperty(id, m_direction, m_writingMode);
     227        id = CSSProperty::resolveDirectionAwareProperty(id, m_direction.textDirection, m_direction.writingMode);
    234228
    235229    ASSERT(!shouldApplyPropertyInParseOrder(id));
     
    378372}
    379373
    380 void PropertyCascade::applyDeferredProperties()
    381 {
    382     for (auto& property : m_deferredProperties)
    383         applyProperty(property);
    384 }
    385 
    386 void PropertyCascade::applyProperties(int firstProperty, int lastProperty)
    387 {
    388     if (LIKELY(m_customProperties.isEmpty()))
    389         return applyPropertiesImpl<CustomPropertyCycleTracking::Disabled>(firstProperty, lastProperty);
    390 
    391     return applyPropertiesImpl<CustomPropertyCycleTracking::Enabled>(firstProperty, lastProperty);
    392 }
    393 
    394 template<PropertyCascade::CustomPropertyCycleTracking trackCycles>
    395 inline void PropertyCascade::applyPropertiesImpl(int firstProperty, int lastProperty)
    396 {
    397     for (int id = firstProperty; id <= lastProperty; ++id) {
    398         CSSPropertyID propertyID = static_cast<CSSPropertyID>(id);
    399         if (!hasProperty(propertyID))
    400             continue;
    401         ASSERT(propertyID != CSSPropertyCustom);
    402         auto& property = m_properties[propertyID];
    403 
    404         if (trackCycles == CustomPropertyCycleTracking::Enabled) {
    405             if (UNLIKELY(builderState().m_inProgressProperties.get(propertyID))) {
    406                 // We are in a cycle (eg. setting font size using registered custom property value containing em).
    407                 // So this value should be unset.
    408                 builderState().m_appliedProperties.set(propertyID);
    409                 // This property is in a cycle, and only the root of the call stack will have firstProperty != lastProperty.
    410                 ASSERT(firstProperty == lastProperty);
    411                 continue;
    412             }
    413             auto& builderState = *m_builderState;
    414             builderState.m_inProgressProperties.set(propertyID);
    415             applyProperty(property);
    416             builderState.m_appliedProperties.set(propertyID);
    417             builderState.m_inProgressProperties.set(propertyID, false);
    418             continue;
    419         }
    420 
    421         // If we don't have any custom properties, then there can't be any cycles.
    422         applyProperty(property);
    423     }
    424 }
    425 
    426 void PropertyCascade::applyCustomProperties()
    427 {
    428     for (auto& name : m_customProperties.keys())
    429         applyCustomProperty(name);
    430 }
    431 
    432 void PropertyCascade::applyCustomProperty(const String& name)
    433 {
    434     auto& builderState = *m_builderState;
    435     if (builderState.m_appliedCustomProperties.contains(name) || !m_customProperties.contains(name))
    436         return;
    437 
    438     auto property = customProperty(name);
    439     bool inCycle = builderState.m_inProgressPropertiesCustom.contains(name);
    440 
    441     for (auto index : { SelectorChecker::MatchDefault, SelectorChecker::MatchLink, SelectorChecker::MatchVisited }) {
    442         if (!property.cssValue[index])
    443             continue;
    444         if (index != SelectorChecker::MatchDefault && builderState.style().insideLink() == InsideLink::NotInside)
    445             continue;
    446 
    447         Ref<CSSCustomPropertyValue> valueToApply = CSSCustomPropertyValue::create(downcast<CSSCustomPropertyValue>(*property.cssValue[index]));
    448 
    449         if (inCycle) {
    450             builderState.m_appliedCustomProperties.add(name); // Make sure we do not try to apply this property again while resolving it.
    451             valueToApply = CSSCustomPropertyValue::createWithID(name, CSSValueInvalid);
    452         }
    453 
    454         builderState.m_inProgressPropertiesCustom.add(name);
    455 
    456         if (WTF::holds_alternative<Ref<CSSVariableReferenceValue>>(valueToApply->value())) {
    457             RefPtr<CSSValue> parsedValue = resolvedVariableValue(CSSPropertyCustom, valueToApply.get());
    458 
    459             if (builderState.m_appliedCustomProperties.contains(name))
    460                 return; // There was a cycle and the value was reset, so bail.
    461 
    462             if (!parsedValue)
    463                 parsedValue = CSSCustomPropertyValue::createWithID(name, CSSValueUnset);
    464 
    465             valueToApply = downcast<CSSCustomPropertyValue>(*parsedValue);
    466         }
    467 
    468         if (builderState.m_inProgressPropertiesCustom.contains(name)) {
    469             builderState.m_linkMatch = index;
    470             applyProperty(CSSPropertyCustom, valueToApply.get(), index);
    471         }
    472     }
    473 
    474     builderState.m_linkMatch = SelectorChecker::MatchDefault;
    475     builderState.m_inProgressPropertiesCustom.remove(name);
    476     builderState.m_appliedCustomProperties.add(name);
    477 
    478     for (auto index : { SelectorChecker::MatchDefault, SelectorChecker::MatchLink, SelectorChecker::MatchVisited }) {
    479         if (!property.cssValue[index])
    480             continue;
    481         if (index != SelectorChecker::MatchDefault && builderState.style().insideLink() == InsideLink::NotInside)
    482             continue;
    483 
    484         Ref<CSSCustomPropertyValue> valueToApply = CSSCustomPropertyValue::create(downcast<CSSCustomPropertyValue>(*property.cssValue[index]));
    485 
    486         if (inCycle && WTF::holds_alternative<Ref<CSSVariableReferenceValue>>(valueToApply->value())) {
    487             // Resolve this value so that we reset its dependencies.
    488             resolvedVariableValue(CSSPropertyCustom, valueToApply.get());
    489         }
    490     }
    491 }
    492 
    493 const PropertyCascade* PropertyCascade::propertyCascadeForRollback(CascadeLevel cascadeLevel)
     374const PropertyCascade* PropertyCascade::propertyCascadeForRollback(CascadeLevel cascadeLevel) const
    494375{
    495376    switch (cascadeLevel) {
     
    515396}
    516397
    517 inline void PropertyCascade::applyProperty(const Property& property)
    518 {
    519     auto& builderState = *m_builderState;
    520     builderState.m_cascadeLevel = property.level;
    521     builderState.m_styleScopeOrdinal = property.styleScopeOrdinal;
    522 
    523     auto applyWithLinkMatch = [&](SelectorChecker::LinkMatchMask linkMatch) {
    524         if (property.cssValue[linkMatch]) {
    525             builderState.m_linkMatch = linkMatch;
    526             applyProperty(property.id, *property.cssValue[linkMatch], linkMatch);
    527         }
    528     };
    529 
    530     applyWithLinkMatch(SelectorChecker::MatchDefault);
    531 
    532     if (builderState.style().insideLink() == InsideLink::NotInside)
    533         return;
    534 
    535     applyWithLinkMatch(SelectorChecker::MatchLink);
    536     applyWithLinkMatch(SelectorChecker::MatchVisited);
    537 
    538     builderState.m_linkMatch = SelectorChecker::MatchDefault;
    539 }
    540 
    541 void PropertyCascade::applyProperty(CSSPropertyID id, CSSValue& value, SelectorChecker::LinkMatchMask linkMatchMask)
    542 {
    543     ASSERT_WITH_MESSAGE(!isShorthandCSSProperty(id), "Shorthand property id = %d wasn't expanded at parsing time", id);
    544 
    545     auto valueToApply = resolveValue(id, value);
    546 
    547     if (CSSProperty::isDirectionAwareProperty(id)) {
    548         CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, m_direction, m_writingMode);
    549         ASSERT(newId != id);
    550         return applyProperty(newId, valueToApply.get(), linkMatchMask);
    551     }
    552 
    553     auto& builderState = *m_builderState;
    554 
    555     CSSCustomPropertyValue* customPropertyValue = nullptr;
    556     CSSValueID customPropertyValueID = CSSValueInvalid;
    557     CSSRegisteredCustomProperty* customPropertyRegistered = nullptr;
    558 
    559     if (id == CSSPropertyCustom) {
    560         customPropertyValue = downcast<CSSCustomPropertyValue>(valueToApply.ptr());
    561         ASSERT(customPropertyValue->isResolved());
    562         if (WTF::holds_alternative<CSSValueID>(customPropertyValue->value()))
    563             customPropertyValueID = WTF::get<CSSValueID>(customPropertyValue->value());
    564         auto& name = customPropertyValue->name();
    565         customPropertyRegistered = builderState.document().getCSSRegisteredCustomPropertySet().get(name);
    566     }
    567 
    568     bool isInherit = valueToApply->isInheritedValue() || customPropertyValueID == CSSValueInherit;
    569     bool isInitial = valueToApply->isInitialValue() || customPropertyValueID == CSSValueInitial;
    570 
    571     bool isUnset = valueToApply->isUnsetValue() || customPropertyValueID == CSSValueUnset;
    572     bool isRevert = valueToApply->isRevertValue() || customPropertyValueID == CSSValueRevert;
    573 
    574     if (isRevert) {
    575         if (auto* rollback = propertyCascadeForRollback(builderState.m_cascadeLevel)) {
    576             // With the rollback cascade built, we need to obtain the property and apply it. If the property is
    577             // not present, then we behave like "unset." Otherwise we apply the property instead of
    578             // our own.
    579             if (customPropertyValue) {
    580                 if (customPropertyRegistered && customPropertyRegistered->inherits && rollback->hasCustomProperty(customPropertyValue->name())) {
    581                     auto property = rollback->customProperty(customPropertyValue->name());
    582                     if (property.cssValue[linkMatchMask])
    583                         applyProperty(property.id, *property.cssValue[linkMatchMask], linkMatchMask);
    584                     return;
    585                 }
    586             } else if (rollback->hasProperty(id)) {
    587                 auto& property = rollback->property(id);
    588                 if (property.cssValue[linkMatchMask])
    589                     applyProperty(property.id, *property.cssValue[linkMatchMask], linkMatchMask);
    590                 return;
    591             }
    592         }
    593 
    594         isUnset = true;
    595     }
    596 
    597     if (isUnset) {
    598         if (CSSProperty::isInheritedProperty(id))
    599             isInherit = true;
    600         else
    601             isInitial = true;
    602     }
    603 
    604     ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit
    605 
    606     if (builderState.applyPropertyToVisitedLinkStyle() && !isValidVisitedLinkProperty(id)) {
    607         // Limit the properties that can be applied to only the ones honored by :visited.
    608         return;
    609     }
    610 
    611     if (isInherit && !CSSProperty::isInheritedProperty(id))
    612         builderState.style().setHasExplicitlyInheritedProperties();
    613 
    614 #if ENABLE(CSS_PAINTING_API)
    615     if (is<CSSPaintImageValue>(valueToApply)) {
    616         auto& name = downcast<CSSPaintImageValue>(valueToApply.get()).name();
    617         if (auto* paintWorklet = const_cast<Document&>(builderState.document()).paintWorkletGlobalScopeForName(name)) {
    618             auto locker = holdLock(paintWorklet->paintDefinitionLock());
    619             if (auto* registration = paintWorklet->paintDefinitionMap().get(name)) {
    620                 for (auto& property : registration->inputProperties)
    621                     builderState.style().addCustomPaintWatchProperty(property);
    622             }
    623         }
    624     }
    625 #endif
    626 
    627     BuilderGenerated::applyProperty(id, builderState, valueToApply.get(), isInitial, isInherit, customPropertyRegistered);
    628 }
    629 
    630 Ref<CSSValue> PropertyCascade::resolveValue(CSSPropertyID propertyID, CSSValue& value)
    631 {
    632     if (!value.hasVariableReferences())
    633         return value;
    634    
    635     auto variableValue = resolvedVariableValue(propertyID, value);
    636     // If the cascade has already applied this id, then we detected a cycle, and this value should be unset.
    637     if (!variableValue || builderState().m_appliedProperties.get(propertyID)) {
    638         if (CSSProperty::isInheritedProperty(propertyID))
    639             return CSSValuePool::singleton().createInheritedValue();
    640         return CSSValuePool::singleton().createExplicitInitialValue();
    641     }
    642 
    643     return *variableValue;
    644 }
    645 
    646 RefPtr<CSSValue> PropertyCascade::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value)
    647 {
    648     CSSParser parser(builderState().document());
    649     return parser.parseValueWithVariableReferences(propID, value, builderState());
    650 }
    651 
    652 void PropertyCascade::resolveDirectionAndWritingMode()
    653 {
    654     auto& style = builderState().style();
    655 
    656     m_direction = style.direction();
    657     m_writingMode = style.writingMode();
     398PropertyCascade::Direction PropertyCascade::resolveDirectionAndWritingMode(Direction inheritedDirection) const
     399{
     400    Direction result = inheritedDirection;
    658401
    659402    bool hadImportantWritingMode = false;
     
    669412                case CSSPropertyWritingMode:
    670413                    if (!hadImportantWritingMode || property.isImportant()) {
    671                         m_writingMode = downcast<CSSPrimitiveValue>(*property.value());
     414                        result.writingMode = downcast<CSSPrimitiveValue>(*property.value());
    672415                        hadImportantWritingMode = property.isImportant();
    673416                    }
     
    675418                case CSSPropertyDirection:
    676419                    if (!hadImportantDirection || property.isImportant()) {
    677                         m_direction = downcast<CSSPrimitiveValue>(*property.value());
     420                        result.textDirection = downcast<CSSPrimitiveValue>(*property.value());
    678421                        hadImportantDirection = property.isImportant();
    679422                    }
     
    685428        }
    686429    }
    687 }
    688 
    689 }
    690 }
     430
     431    return result;
     432}
     433
     434}
     435}
  • trunk/Source/WebCore/style/PropertyCascade.h

    r251796 r251864  
    4141public:
    4242    enum IncludedProperties { All, InheritedOnly };
    43     PropertyCascade(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties = IncludedProperties::All);
     43
     44    struct Direction {
     45        TextDirection textDirection;
     46        WritingMode writingMode;
     47    };
     48
     49    PropertyCascade(const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties, Direction);
    4450    PropertyCascade(const PropertyCascade&, OptionSet<CascadeLevel>);
    4551
     
    5965    Property customProperty(const String&) const;
    6066
    61     void applyProperties(int firstProperty, int lastProperty);
    62     void applyDeferredProperties();
    63     void applyCustomProperties();
    64     void applyCustomProperty(const String& name);
    65     void applyProperty(CSSPropertyID, CSSValue&, SelectorChecker::LinkMatchMask = SelectorChecker::MatchDefault);
     67    const Vector<Property, 8>& deferredProperties() const { return m_deferredProperties; }
     68    const HashMap<AtomString, Property>& customProperties() const { return m_customProperties; }
    6669
    67     BuilderState& builderState() { return *m_builderState; }
     70    Direction direction() const { return m_direction; }
     71
     72    const PropertyCascade* propertyCascadeForRollback(CascadeLevel) const;
    6873
    6974private:
     
    7782    static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
    7883
    79     const PropertyCascade* propertyCascadeForRollback(CascadeLevel);
    80 
    81     enum CustomPropertyCycleTracking { Enabled = 0, Disabled };
    82     template<CustomPropertyCycleTracking trackCycles>
    83     void applyPropertiesImpl(int firstProperty, int lastProperty);
    84     void applyProperty(const Property&);
    85 
    86     Ref<CSSValue> resolveValue(CSSPropertyID, CSSValue&);
    87     RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSValue&);
    88 
    89     void resolveDirectionAndWritingMode();
     84    Direction resolveDirectionAndWritingMode(Direction inheritedDirection) const;
    9085
    9186    const MatchResult& m_matchResult;
    9287    const IncludedProperties m_includedProperties;
    93 
    94     TextDirection m_direction;
    95     WritingMode m_writingMode;
     88    const Direction m_direction;
    9689
    9790    Property m_properties[numCSSProperties + 2];
     
    10194    HashMap<AtomString, Property> m_customProperties;
    10295
    103     std::unique_ptr<const PropertyCascade> m_authorRollbackCascade;
    104     std::unique_ptr<const PropertyCascade> m_userRollbackCascade;
    105 
    106     Optional<BuilderState> m_builderState;
     96    mutable std::unique_ptr<const PropertyCascade> m_authorRollbackCascade;
     97    mutable std::unique_ptr<const PropertyCascade> m_userRollbackCascade;
    10798};
    10899
  • trunk/Source/WebCore/style/StyleBuilderCustom.h

    r251841 r251864  
    16131613        if (primitiveValue.isLength()) {
    16141614            size = primitiveValue.computeLength<float>(CSSToLengthConversionData(&builderState.parentStyle(), &builderState.rootElementStyle(), builderState.document().renderView(), 1.0f, true));
    1615             builderState.styleResolver().state().setFontSizeHasViewportUnits(primitiveValue.isViewportPercentageLength());
     1615            if (primitiveValue.isViewportPercentageLength())
     1616                builderState.style().setHasViewportUnits();
    16161617        } else if (primitiveValue.isPercentage())
    16171618            size = (primitiveValue.floatValue() * parentSize) / 100.0f;
  • trunk/Source/WebCore/style/StyleBuilderState.cpp

    r251796 r251864  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
     3 * Copyright (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
     4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
     5 * Copyright (C) 2005-2019 Apple Inc. All rights reserved.
     6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
     7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
     8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
     9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
     10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
     11 * Copyright (C) 2012, 2013 Google Inc. All rights reserved.
     12 * Copyright (C) 2014 Igalia S.L.
    313 *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
    10  *    notice, this list of conditions and the following disclaimer in the
    11  *    documentation and/or other materials provided with the distribution.
     14 * This library is free software; you can redistribute it and/or
     15 * modify it under the terms of the GNU Library General Public
     16 * License as published by the Free Software Foundation; either
     17 * version 2 of the License, or (at your option) any later version.
    1218 *
    13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
    14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
    17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    23  * THE POSSIBILITY OF SUCH DAMAGE.
     19 * This library is distributed in the hope that it will be useful,
     20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     22 * Library General Public License for more details.
     23 *
     24 * You should have received a copy of the GNU Library General Public License
     25 * along with this library; see the file COPYING.LIB.  If not, write to
     26 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     27 * Boston, MA 02110-1301, USA.
    2428 */
    2529
     
    2731#include "StyleBuilderState.h"
    2832
     33#include "SVGElement.h"
     34#include "SVGSVGElement.h"
     35#include "StyleBuilder.h"
    2936#include "StyleResolver.h"
    3037
     
    3239namespace Style {
    3340
    34 BuilderState::BuilderState(PropertyCascade& cascade, StyleResolver& styleResolver)
    35     : m_cascade(cascade)
     41BuilderState::BuilderState(Builder& builder, StyleResolver& styleResolver)
     42    : m_builder(builder)
    3643    , m_styleMap(*this)
    3744    , m_cssToLengthConversionData(styleResolver.state().cssToLengthConversionData())
     
    4754}
    4855
     56// SVG handles zooming in a different way compared to CSS. The whole document is scaled instead
     57// of each individual length value in the render style / tree. CSSPrimitiveValue::computeLength*()
     58// multiplies each resolved length with the zoom multiplier - so for SVG we need to disable that.
     59// Though all CSS values that can be applied to outermost <svg> elements (width/height/border/padding...)
     60// need to respect the scaling. RenderBox (the parent class of RenderSVGRoot) grabs values like
     61// width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale,
     62// if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific
     63// properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size).
    4964bool BuilderState::useSVGZoomRules() const
    5065{
    51     return m_styleResolver.useSVGZoomRules();
     66    return is<SVGElement>(element());
    5267}
    5368
    5469bool BuilderState::useSVGZoomRulesForLength() const
    5570{
    56     return m_styleResolver.useSVGZoomRulesForLength();
     71    return is<SVGElement>(element()) && !(is<SVGSVGElement>(*element()) && element()->parentNode());
    5772}
    5873
     
    7287}
    7388
    74 void BuilderState::setFontSize(FontCascadeDescription& description, float size)
     89void BuilderState::adjustStyleForInterCharacterRuby()
    7590{
    76     m_styleResolver.setFontSize(description, size);
     91    if (m_style.rubyPosition() != RubyPosition::InterCharacter || !element() || !element()->hasTagName(HTMLNames::rtTag))
     92        return;
     93
     94    m_style.setTextAlign(TextAlignMode::Center);
     95    if (m_style.isHorizontalWritingMode())
     96        m_style.setWritingMode(LeftToRightWritingMode);
     97}
     98
     99void BuilderState::updateFont()
     100{
     101    if (!m_fontDirty && m_style.fontCascade().fonts())
     102        return;
     103
     104#if ENABLE(TEXT_AUTOSIZING)
     105    updateFontForTextSizeAdjust();
     106#endif
     107    updateFontForGenericFamilyChange();
     108    updateFontForZoomChange();
     109    updateFontForOrientationChange();
     110
     111    m_style.fontCascade().update(&const_cast<Document&>(document()).fontSelector());
     112
     113    m_fontDirty = false;
     114}
     115
     116#if ENABLE(TEXT_AUTOSIZING)
     117void BuilderState::updateFontForTextSizeAdjust()
     118{
     119    if (m_style.textSizeAdjust().isAuto()
     120        || !document().settings().textAutosizingEnabled()
     121        || (document().settings().textAutosizingUsesIdempotentMode() && !m_style.textSizeAdjust().isNone()))
     122        return;
     123
     124    auto newFontDescription = m_style.fontDescription();
     125    if (!m_style.textSizeAdjust().isNone())
     126        newFontDescription.setComputedSize(newFontDescription.specifiedSize() * m_style.textSizeAdjust().multiplier());
     127    else
     128        newFontDescription.setComputedSize(newFontDescription.specifiedSize());
     129
     130    m_style.setFontDescription(WTFMove(newFontDescription));
     131}
     132#endif
     133
     134void BuilderState::updateFontForZoomChange()
     135{
     136    if (m_style.effectiveZoom() == m_parentStyle.effectiveZoom() && m_style.textZoom() == m_parentStyle.textZoom())
     137        return;
     138
     139    const auto& childFont = m_style.fontDescription();
     140    auto newFontDescription = childFont;
     141    setFontSize(newFontDescription, childFont.specifiedSize());
     142
     143    m_style.setFontDescription(WTFMove(newFontDescription));
     144}
     145
     146void BuilderState::updateFontForGenericFamilyChange()
     147{
     148    const auto& childFont = m_style.fontDescription();
     149
     150    if (childFont.isAbsoluteSize())
     151        return;
     152
     153    const auto& parentFont = m_parentStyle.fontDescription();
     154    if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())
     155        return;
     156
     157    // We know the parent is monospace or the child is monospace, and that font
     158    // size was unspecified. We want to scale our font size as appropriate.
     159    // If the font uses a keyword size, then we refetch from the table rather than
     160    // multiplying by our scale factor.
     161    float size = [&] {
     162        if (CSSValueID sizeIdentifier = childFont.keywordSizeAsIdentifier())
     163            return Style::fontSizeForKeyword(sizeIdentifier, childFont.useFixedDefaultSize(), document());
     164
     165        auto fixedSize =  document().settings().defaultFixedFontSize();
     166        auto defaultSize =  document().settings().defaultFontSize();
     167        float fixedScaleFactor = (fixedSize && defaultSize) ? static_cast<float>(fixedSize) / defaultSize : 1;
     168        return parentFont.useFixedDefaultSize() ? childFont.specifiedSize() / fixedScaleFactor : childFont.specifiedSize() * fixedScaleFactor;
     169    }();
     170
     171    auto newFontDescription = childFont;
     172    setFontSize(newFontDescription, size);
     173    m_style.setFontDescription(WTFMove(newFontDescription));
     174}
     175
     176void BuilderState::updateFontForOrientationChange()
     177{
     178    auto [fontOrientation, glyphOrientation] = m_style.fontAndGlyphOrientation();
     179
     180    const auto& fontDescription = m_style.fontDescription();
     181    if (fontDescription.orientation() == fontOrientation && fontDescription.nonCJKGlyphOrientation() == glyphOrientation)
     182        return;
     183
     184    auto newFontDescription = fontDescription;
     185    newFontDescription.setNonCJKGlyphOrientation(glyphOrientation);
     186    newFontDescription.setOrientation(fontOrientation);
     187    m_style.setFontDescription(WTFMove(newFontDescription));
     188}
     189
     190void BuilderState::setFontSize(FontCascadeDescription& fontDescription, float size)
     191{
     192    fontDescription.setSpecifiedSize(size);
     193    fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules(), &style(), document()));
    77194}
    78195
  • trunk/Source/WebCore/style/StyleBuilderState.h

    r251796 r251864  
    4040namespace Style {
    4141
    42 class PropertyCascade;
     42class Builder;
    4343
    4444class BuilderState {
    4545public:
    46     BuilderState(PropertyCascade&, StyleResolver&);
     46    BuilderState(Builder&, StyleResolver&);
    4747
    48     PropertyCascade& cascade() { return m_cascade; }
     48    Builder& builder() { return m_builder; }
    4949    StyleResolver& styleResolver() { return m_styleResolver; }
    5050
     
    6565    bool fontDirty() const { return m_fontDirty; }
    6666    void setFontDirty() { m_fontDirty = true; }
    67     void clearFontDirty() { m_fontDirty = false; }
    6867
    6968    const FontCascadeDescription& fontDescription() { return m_style.fontDescription(); }
     
    8685
    8786private:
    88     friend class PropertyCascade;
     87    friend class Builder;
    8988
    90     PropertyCascade& m_cascade;
     89    void adjustStyleForInterCharacterRuby();
     90
     91    void updateFont();
     92#if ENABLE(TEXT_AUTOSIZING)
     93    void updateFontForTextSizeAdjust();
     94#endif
     95    void updateFontForZoomChange();
     96    void updateFontForGenericFamilyChange();
     97    void updateFontForOrientationChange();
     98
     99    Builder& m_builder;
    91100
    92101    CSSToStyleMap m_styleMap;
Note: See TracChangeset for help on using the changeset viewer.