Title: [195465] trunk/Source/WebCore
Revision
195465
Author
[email protected]
Date
2016-01-22 12:00:34 -0800 (Fri, 22 Jan 2016)

Log Message

Style resolver initialization cleanups
https://bugs.webkit.org/show_bug.cgi?id=153356

Reviewed by Simon Fraser.

    Simplify StyleResolver::State initialization.
    Also use more references and other cleanups.

* css/MediaQueryMatcher.cpp:
(WebCore::MediaQueryMatcher::prepareEvaluator):
* css/StyleMedia.cpp:
(WebCore::StyleMedia::matchMedium):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::State::clear):
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::classNamesAffectedByRules):
(WebCore::StyleResolver::State::State):

    Initialize State using a constructor instead of bunch of construction functions.
    Remove m_styledElement field which is just a casted version of m_element.

(WebCore::StyleResolver::State::updateConversionData):
(WebCore::StyleResolver::State::setStyle):
(WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes):
(WebCore::StyleResolver::canShareStyleWithElement):
(WebCore::StyleResolver::locateSharedStyle):
(WebCore::isAtShadowBoundary):
(WebCore::StyleResolver::styleForElement):
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::keyframeStylesForAnimation):
(WebCore::StyleResolver::pseudoStyleForElement):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::pseudoStyleRulesForElement):
(WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits):
(WebCore::isCacheableInMatchedPropertiesCache):

    Disallow caching of document element style entirely because the writing-mode and direction properties have special handling.
    The existing check wasn't robust.

(WebCore::extractDirectionAndWritingMode):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::applyPropertyToStyle):
(WebCore::StyleResolver::State::initElement): Deleted.
(WebCore::StyleResolver::initElement): Deleted.
(WebCore::StyleResolver::State::initForStyleResolve): Deleted.
* css/StyleResolver.h:
(WebCore::StyleResolver::mediaQueryEvaluator):
(WebCore::StyleResolver::State::State):
(WebCore::StyleResolver::State::document):
(WebCore::StyleResolver::State::element):
(WebCore::StyleResolver::State::style):
(WebCore::StyleResolver::State::takeStyle):
(WebCore::StyleResolver::State::styledElement): Deleted.
* dom/Element.cpp:
(WebCore::Element::resolveStyle):
* page/animation/KeyframeAnimation.cpp:
(WebCore::KeyframeAnimation::KeyframeAnimation):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::getUncachedPseudoStyle):
(WebCore::RenderElement::containingBlockForFixedPosition):
* rendering/RenderNamedFlowFragment.cpp:
(WebCore::RenderNamedFlowFragment::computeStyleInRegion):
* style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::styleForElement):
* svg/SVGElement.cpp:
(WebCore::SVGElement::customStyleForRenderer):
(WebCore::SVGElement::computedStyle):
(WebCore::addQualifiedName):
* svg/SVGElementRareData.h:
(WebCore::SVGElementRareData::ensureAnimatedSMILStyleProperties):
(WebCore::SVGElementRareData::overrideComputedStyle):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (195464 => 195465)


--- trunk/Source/WebCore/ChangeLog	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/ChangeLog	2016-01-22 20:00:34 UTC (rev 195465)
@@ -1,3 +1,77 @@
+2016-01-22  Antti Koivisto  <[email protected]>
+
+        Style resolver initialization cleanups
+        https://bugs.webkit.org/show_bug.cgi?id=153356
+
+        Reviewed by Simon Fraser.
+
+            Simplify StyleResolver::State initialization.
+            Also use more references and other cleanups.
+
+        * css/MediaQueryMatcher.cpp:
+        (WebCore::MediaQueryMatcher::prepareEvaluator):
+        * css/StyleMedia.cpp:
+        (WebCore::StyleMedia::matchMedium):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::State::clear):
+        (WebCore::StyleResolver::StyleResolver):
+        (WebCore::StyleResolver::classNamesAffectedByRules):
+        (WebCore::StyleResolver::State::State):
+
+            Initialize State using a constructor instead of bunch of construction functions.
+            Remove m_styledElement field which is just a casted version of m_element.
+
+        (WebCore::StyleResolver::State::updateConversionData):
+        (WebCore::StyleResolver::State::setStyle):
+        (WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes):
+        (WebCore::StyleResolver::canShareStyleWithElement):
+        (WebCore::StyleResolver::locateSharedStyle):
+        (WebCore::isAtShadowBoundary):
+        (WebCore::StyleResolver::styleForElement):
+        (WebCore::StyleResolver::styleForKeyframe):
+        (WebCore::StyleResolver::keyframeStylesForAnimation):
+        (WebCore::StyleResolver::pseudoStyleForElement):
+        (WebCore::StyleResolver::styleForPage):
+        (WebCore::StyleResolver::pseudoStyleRulesForElement):
+        (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits):
+        (WebCore::isCacheableInMatchedPropertiesCache):
+
+            Disallow caching of document element style entirely because the writing-mode and direction properties have special handling.
+            The existing check wasn't robust.
+
+        (WebCore::extractDirectionAndWritingMode):
+        (WebCore::StyleResolver::applyMatchedProperties):
+        (WebCore::StyleResolver::applyPropertyToStyle):
+        (WebCore::StyleResolver::State::initElement): Deleted.
+        (WebCore::StyleResolver::initElement): Deleted.
+        (WebCore::StyleResolver::State::initForStyleResolve): Deleted.
+        * css/StyleResolver.h:
+        (WebCore::StyleResolver::mediaQueryEvaluator):
+        (WebCore::StyleResolver::State::State):
+        (WebCore::StyleResolver::State::document):
+        (WebCore::StyleResolver::State::element):
+        (WebCore::StyleResolver::State::style):
+        (WebCore::StyleResolver::State::takeStyle):
+        (WebCore::StyleResolver::State::styledElement): Deleted.
+        * dom/Element.cpp:
+        (WebCore::Element::resolveStyle):
+        * page/animation/KeyframeAnimation.cpp:
+        (WebCore::KeyframeAnimation::KeyframeAnimation):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::getUncachedPseudoStyle):
+        (WebCore::RenderElement::containingBlockForFixedPosition):
+        * rendering/RenderNamedFlowFragment.cpp:
+        (WebCore::RenderNamedFlowFragment::computeStyleInRegion):
+        * style/StyleTreeResolver.cpp:
+        (WebCore::Style::TreeResolver::styleForElement):
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::customStyleForRenderer):
+        (WebCore::SVGElement::computedStyle):
+        (WebCore::addQualifiedName):
+        * svg/SVGElementRareData.h:
+        (WebCore::SVGElementRareData::ensureAnimatedSMILStyleProperties):
+        (WebCore::SVGElementRareData::overrideComputedStyle):
+
 2016-01-22  Chris Fleizach  <[email protected]>
 
         AX: <code> group and friends should have a custom subrole

Modified: trunk/Source/WebCore/css/MediaQueryMatcher.cpp (195464 => 195465)


--- trunk/Source/WebCore/css/MediaQueryMatcher.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/css/MediaQueryMatcher.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -85,7 +85,7 @@
     if (!documentElement)
         return nullptr;
 
-    RefPtr<RenderStyle> rootStyle = m_document->ensureStyleResolver().styleForElement(documentElement, m_document->renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
+    RefPtr<RenderStyle> rootStyle = m_document->ensureStyleResolver().styleForElement(*documentElement, m_document->renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
 
     return std::make_unique<MediaQueryEvaluator>(mediaType(), m_document->frame(), rootStyle.get());
 }

Modified: trunk/Source/WebCore/css/StyleMedia.cpp (195464 => 195465)


--- trunk/Source/WebCore/css/StyleMedia.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/css/StyleMedia.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -61,7 +61,7 @@
     if (!documentElement)
         return false;
 
-    RefPtr<RenderStyle> rootStyle = document->ensureStyleResolver().styleForElement(documentElement, document->renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
+    RefPtr<RenderStyle> rootStyle = document->ensureStyleResolver().styleForElement(*documentElement, document->renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
 
     RefPtr<MediaQuerySet> media = MediaQuerySet::create();
     if (!media->parse(query))

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (195464 => 195465)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -191,7 +191,6 @@
 inline void StyleResolver::State::clear()
 {
     m_element = nullptr;
-    m_styledElement = nullptr;
     m_parentStyle = nullptr;
     m_regionForStyling = nullptr;
     m_pendingImageProperties.clear();
@@ -265,7 +264,7 @@
         m_medium = std::make_unique<MediaQueryEvaluator>("all");
 
     if (root)
-        m_rootDefaultStyle = styleForElement(root, m_document.renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
+        m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), DisallowStyleSharing, MatchOnlyUserAgentRules);
 
     if (m_rootDefaultStyle && view)
         m_medium = std::make_unique<MediaQueryEvaluator>(view->mediaType(), &view->frame(), m_rootDefaultStyle.get());
@@ -342,56 +341,29 @@
     return false;
 }
 
-inline void StyleResolver::State::updateConversionData()
+StyleResolver::State::State(Element& element, RenderStyle* parentStyle, const RenderRegion* regionForStyling, const SelectorFilter* selectorFilter)
+    : m_element(&element)
+    , m_parentStyle(parentStyle)
+    , m_regionForStyling(regionForStyling)
+    , m_elementLinkState(element.document().visitedLinkState().determineLinkState(element))
+    , m_selectorFilter(selectorFilter)
 {
-    m_cssToLengthConversionData = CSSToLengthConversionData(m_style.get(), m_rootElementStyle, m_element ? document().renderView() : nullptr);
-}
+    bool resetStyleInheritance = hasShadowRootParent(element) && downcast<ShadowRoot>(element.parentNode())->resetStyleInheritance();
+    if (resetStyleInheritance)
+        m_parentStyle = nullptr;
 
-inline void StyleResolver::State::initElement(Element* element)
-{
-    m_element = element;
-    m_styledElement = element && is<StyledElement>(*element) ? downcast<StyledElement>(element) : nullptr;
-    m_elementLinkState = element ? element->document().visitedLinkState().determineLinkState(*element) : NotInsideLink;
+    auto& document = element.document();
+    auto* documentElement = document.documentElement();
+    m_rootElementStyle = (!documentElement || documentElement == &element) ? document.renderStyle() : documentElement->renderStyle();
+
     updateConversionData();
 }
 
-inline void StyleResolver::initElement(Element* e)
+inline void StyleResolver::State::updateConversionData()
 {
-    if (m_state.element() != e) {
-        m_state.initElement(e);
-        if (e && e == e->document().documentElement()) {
-            e->document().setDirectionSetOnDocumentElement(false);
-            e->document().setWritingModeSetOnDocumentElement(false);
-        }
-    }
+    m_cssToLengthConversionData = CSSToLengthConversionData(m_style.get(), m_rootElementStyle, m_element ? document().renderView() : nullptr);
 }
 
-inline void StyleResolver::State::initForStyleResolve(Document& document, Element* e, RenderStyle* parentStyle, const RenderRegion* regionForStyling, const SelectorFilter* selectorFilter)
-{
-    m_regionForStyling = regionForStyling;
-
-    if (e) {
-        bool resetStyleInheritance = hasShadowRootParent(*e) && downcast<ShadowRoot>(*e->parentNode()).resetStyleInheritance();
-        m_parentStyle = resetStyleInheritance ? nullptr : parentStyle;
-    } else
-        m_parentStyle = parentStyle;
-
-    Node* docElement = e ? e->document().documentElement() : nullptr;
-    RenderStyle* docStyle = document.renderStyle();
-    m_rootElementStyle = docElement && e != docElement ? docElement->renderStyle() : docStyle;
-
-    m_style = nullptr;
-    m_pendingImageProperties.clear();
-    m_fontDirty = false;
-    
-    m_authorRollback = nullptr;
-    m_userRollback = nullptr;
-
-    m_selectorFilter = selectorFilter;
-
-    updateConversionData();
-}
-
 inline void StyleResolver::State::setStyle(Ref<RenderStyle>&& style)
 {
     m_style = WTFMove(style);
@@ -524,7 +496,7 @@
     } else
         return false;
 
-    if (state.styledElement()->presentationAttributeStyle() != sharingCandidate.presentationAttributeStyle())
+    if (downcast<StyledElement>(*state.element()).presentationAttributeStyle() != sharingCandidate.presentationAttributeStyle())
         return false;
 
     if (state.element()->hasTagName(progressTag)) {
@@ -568,7 +540,7 @@
         return false;
     if (!sharingCandidateHasIdenticalStyleAffectingAttributes(element))
         return false;
-    if (element.additionalPresentationAttributeStyle() != state.styledElement()->additionalPresentationAttributeStyle())
+    if (element.additionalPresentationAttributeStyle() != downcast<StyledElement>(*state.element()).additionalPresentationAttributeStyle())
         return false;
     if (element.affectsNextSiblingElementStyle() || element.styleIsAffectedByPreviousSibling())
         return false;
@@ -645,18 +617,19 @@
 RenderStyle* StyleResolver::locateSharedStyle()
 {
     State& state = m_state;
-    if (!state.styledElement() || !state.parentStyle())
+    if (!is<StyledElement>(state.element()) || !state.parentStyle())
         return nullptr;
+    auto& styledElement = downcast<StyledElement>(*state.element());
 
     // If the element has inline style it is probably unique.
-    if (state.styledElement()->inlineStyle())
+    if (styledElement.inlineStyle())
         return nullptr;
-    if (state.styledElement()->isSVGElement() && downcast<SVGElement>(*state.styledElement()).animatedSMILStyleProperties())
+    if (styledElement.isSVGElement() && downcast<SVGElement>(styledElement).animatedSMILStyleProperties())
         return nullptr;
     // Ids stop style sharing if they show up in the stylesheets.
-    if (state.styledElement()->hasID() && m_ruleSets.features().idsInRules.contains(state.styledElement()->idForStyleResolution().impl()))
+    if (styledElement.hasID() && m_ruleSets.features().idsInRules.contains(styledElement.idForStyleResolution().impl()))
         return nullptr;
-    if (parentElementPreventsSharing(state.element()->parentElement()))
+    if (parentElementPreventsSharing(styledElement.parentElement()))
         return nullptr;
     if (state.element() == state.document().cssTarget())
         return nullptr;
@@ -671,7 +644,7 @@
     unsigned count = 0;
     unsigned visitedNodeCount = 0;
     StyledElement* shareElement = nullptr;
-    Node* cousinList = state.styledElement()->previousSibling();
+    Node* cousinList = styledElement.previousSibling();
     while (cousinList) {
         shareElement = findSiblingForStyleSharing(cousinList, count);
         if (shareElement)
@@ -690,7 +663,7 @@
     if (styleSharingCandidateMatchesRuleSet(m_ruleSets.uncommonAttribute()))
         return nullptr;
     // Tracking child index requires unique style for each node. This may get set by the sibling rule match above.
-    if (parentElementPreventsSharing(state.element()->parentElement()))
+    if (parentElementPreventsSharing(styledElement.parentElement()))
         return nullptr;
     return shareElement->renderStyle();
 }
@@ -703,27 +676,33 @@
     return parentNode && parentNode->isShadowRoot();
 }
 
-Ref<RenderStyle> StyleResolver::styleForElement(Element* element, RenderStyle* defaultParent,
+Ref<RenderStyle> StyleResolver::styleForElement(Element& element, RenderStyle* parentStyle,
     StyleSharingBehavior sharingBehavior, RuleMatchingBehavior matchingBehavior, const RenderRegion* regionForStyling, const SelectorFilter* selectorFilter)
 {
     RELEASE_ASSERT(!m_inLoadPendingImages);
 
     // Once an element has a renderer, we don't try to destroy it, since otherwise the renderer
     // will vanish if a style recalc happens during loading.
-    if (sharingBehavior == AllowStyleSharing && !element->document().haveStylesheetsLoaded() && !element->renderer()) {
+    if (sharingBehavior == AllowStyleSharing && !m_document.haveStylesheetsLoaded() && !element.renderer()) {
         if (!s_styleNotYetAvailable) {
             s_styleNotYetAvailable = &RenderStyle::create().leakRef();
             s_styleNotYetAvailable->setDisplay(NONE);
-            s_styleNotYetAvailable->fontCascade().update(&document().fontSelector());
+            s_styleNotYetAvailable->fontCascade().update(&m_document.fontSelector());
         }
-        element->document().setHasNodesWithPlaceholderStyle();
+        m_document.setHasNodesWithPlaceholderStyle();
         return *s_styleNotYetAvailable;
     }
 
+    m_state = State(element, parentStyle, regionForStyling, selectorFilter);
     State& state = m_state;
-    initElement(element);
-    state.initForStyleResolve(document(), element, defaultParent, regionForStyling, selectorFilter);
 
+    if (&element == m_document.documentElement() && matchingBehavior == MatchAllRules) {
+        // These bits may be set when resolving document element style.
+        // FIXME: Style resolver shouldn't mutate document.
+        m_document.setDirectionSetOnDocumentElement(false);
+        m_document.setWritingModeSetOnDocumentElement(false);
+    }
+
     if (sharingBehavior == AllowStyleSharing) {
         if (RenderStyle* sharedStyle = locateSharedStyle()) {
             state.clear();
@@ -733,17 +712,17 @@
 
     if (state.parentStyle()) {
         state.setStyle(RenderStyle::create());
-        state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
+        state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(&element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
     } else {
         state.setStyle(defaultStyleForElement());
         state.setParentStyle(RenderStyle::clone(state.style()));
     }
 
-    if (element->isLink()) {
+    if (element.isLink()) {
         state.style()->setIsLink(true);
         EInsideLink linkState = state.elementLinkState();
         if (linkState != NotInsideLink) {
-            bool forceVisited = InspectorInstrumentation::forcePseudoState(*element, CSSSelector::PseudoClassVisited);
+            bool forceVisited = InspectorInstrumentation::forcePseudoState(element, CSSSelector::PseudoClassVisited);
             if (forceVisited)
                 linkState = InsideVisitedLink;
         }
@@ -751,11 +730,11 @@
     }
 
     bool needsCollection = false;
-    CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(*element, needsCollection);
+    CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(element, needsCollection);
     if (needsCollection)
         m_ruleSets.collectFeatures();
 
-    ElementRuleCollector collector(*element, state.style(), m_ruleSets, m_state.selectorFilter());
+    ElementRuleCollector collector(element, state.style(), m_ruleSets, m_state.selectorFilter());
     collector.setRegionForStyling(regionForStyling);
     collector.setMedium(m_medium.get());
 
@@ -767,7 +746,7 @@
     applyMatchedProperties(collector.matchedResult(), element);
 
     // Clean up our style object's display and text decorations (among other fixups).
-    adjustRenderStyle(*state.style(), *state.parentStyle(), element);
+    adjustRenderStyle(*state.style(), *state.parentStyle(), &element);
 
     if (state.style()->hasViewportUnits())
         document().setHasStyleWithViewportUnits();
@@ -836,12 +815,12 @@
     return state.takeStyle();
 }
 
-void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* elementStyle, KeyframeList& list)
+void StyleResolver::keyframeStylesForAnimation(Element& element, const RenderStyle* elementStyle, KeyframeList& list)
 {
     list.clear();
 
     // Get the keyframesRule for this name
-    if (!e || list.animationName().isEmpty())
+    if (list.animationName().isEmpty())
         return;
 
     m_keyframesRuleMap.checkConsistency();
@@ -856,8 +835,7 @@
     const Vector<RefPtr<StyleKeyframe>>& keyframes = keyframesRule->keyframes();
     for (unsigned i = 0; i < keyframes.size(); ++i) {
         // Apply the declaration to the style. This is a simplified version of the logic in styleForElement
-        initElement(e);
-        m_state.initForStyleResolve(document(), e, nullptr);
+        m_state = State(element, nullptr);
 
         const StyleKeyframe* keyframe = keyframes[i].get();
 
@@ -897,18 +875,12 @@
     }
 }
 
-PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* element, const PseudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle)
+PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element& element, const PseudoStyleRequest& pseudoStyleRequest, RenderStyle& parentStyle)
 {
-    ASSERT(parentStyle);
-    if (!element)
-        return nullptr;
+    m_state = State(element, &parentStyle);
 
     State& state = m_state;
 
-    initElement(element);
-
-    state.initForStyleResolve(document(), element, parentStyle);
-
     if (m_state.parentStyle()) {
         state.setStyle(RenderStyle::create());
         state.style()->inheritFrom(m_state.parentStyle());
@@ -921,7 +893,7 @@
     // those rules.
 
     // Check UA, user and author rules.
-    ElementRuleCollector collector(*element, m_state.style(), m_ruleSets, m_state.selectorFilter());
+    ElementRuleCollector collector(element, m_state.style(), m_ruleSets, m_state.selectorFilter());
     collector.setPseudoStyleRequest(pseudoStyleRequest);
     collector.setMedium(m_medium.get());
     collector.matchUARules();
@@ -955,8 +927,12 @@
 {
     RELEASE_ASSERT(!m_inLoadPendingImages);
 
-    m_state.initForStyleResolve(m_document, m_document.documentElement(), m_document.renderStyle());
+    auto* documentElement = m_document.documentElement();
+    if (!documentElement)
+        return RenderStyle::create();
 
+    m_state = State(*documentElement, m_document.renderStyle());
+
     m_state.setStyle(RenderStyle::create());
     m_state.style()->inheritFrom(m_state.rootElementStyle());
 
@@ -1397,10 +1373,9 @@
     if (!element || !element->document().haveStylesheetsLoaded())
         return Vector<RefPtr<StyleRule>>();
 
-    initElement(element);
-    m_state.initForStyleResolve(document(), element, nullptr);
+    m_state = State(*element, nullptr);
 
-    ElementRuleCollector collector(*element, m_state.style(), m_ruleSets, m_state.selectorFilter());
+    ElementRuleCollector collector(*element, nullptr, m_ruleSets, m_state.selectorFilter());
     collector.setMode(SelectorChecker::Mode::CollectingRules);
     collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
     collector.setMedium(m_medium.get());
@@ -1555,10 +1530,11 @@
         m_matchedPropertiesCache.remove(key);
 }
 
-static bool isCacheableInMatchedPropertiesCache(const Element* element, const RenderStyle* style, const RenderStyle* parentStyle)
+static bool isCacheableInMatchedPropertiesCache(const Element& element, const RenderStyle* style, const RenderStyle* parentStyle)
 {
-    // FIXME: CSSPropertyWebkitWritingMode modifies state when applying to document element. We can't skip the applying by caching.
-    if (element == element->document().documentElement() && element->document().writingModeSetOnDocumentElement())
+    // FIXME: Writing mode and direction properties modify state when applying to document element by calling
+    // Document::setWritingMode/DirectionSetOnDocumentElement. We can't skip the applying by caching.
+    if (&element == element.document().documentElement())
         return false;
     if (style->unique() || (style->styleType() != NOPSEUDO && parentStyle->unique()))
         return false;
@@ -1607,9 +1583,8 @@
     }
 }
 
-void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element* element, ShouldUseMatchedPropertiesCache shouldUseMatchedPropertiesCache)
+void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, ShouldUseMatchedPropertiesCache shouldUseMatchedPropertiesCache)
 {
-    ASSERT(element);
     State& state = m_state;
     unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult.matchedProperties().data(), matchResult.matchedProperties().size()) : 0;
     bool applyInheritedOnly = false;
@@ -1620,7 +1595,7 @@
         // style declarations. We then only need to apply the inherited properties, if any, as their values can depend on the 
         // element context. This is fast and saves memory by reusing the style data structures.
         state.style()->copyNonInheritedFrom(cacheItem->renderStyle.get());
-        if (state.parentStyle()->inheritedDataShared(cacheItem->parentRenderStyle.get()) && !isAtShadowBoundary(element)) {
+        if (state.parentStyle()->inheritedDataShared(cacheItem->parentRenderStyle.get()) && !isAtShadowBoundary(&element)) {
             EInsideLink linkStatus = state.style()->insideLink();
             // If the cache item parent style has identical inherited properties to the current parent style then the
             // resulting style will be identical too. We copy the inherited properties over from the cache and are done.
@@ -1706,15 +1681,15 @@
     
     if (cacheItem || !cacheHash)
         return;
-    if (!isCacheableInMatchedPropertiesCache(state.element(), state.style(), state.parentStyle()))
+    if (!isCacheableInMatchedPropertiesCache(*state.element(), state.style(), state.parentStyle()))
         return;
     addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);
 }
 
 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, RenderStyle* style)
 {
-    initElement(nullptr);
-    m_state.initForStyleResolve(document(), nullptr, style);
+    m_state = State();
+    m_state.setParentStyle(*style);
     m_state.setStyle(*style);
     applyPropertyToCurrentStyle(id, value);
 }

Modified: trunk/Source/WebCore/css/StyleResolver.h (195464 => 195465)


--- trunk/Source/WebCore/css/StyleResolver.h	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/css/StyleResolver.h	2016-01-22 20:00:34 UTC (rev 195465)
@@ -135,12 +135,12 @@
     StyleResolver(Document&);
     ~StyleResolver();
 
-    Ref<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle, StyleSharingBehavior = AllowStyleSharing,
+    Ref<RenderStyle> styleForElement(Element&, RenderStyle* parentStyle, StyleSharingBehavior = AllowStyleSharing,
         RuleMatchingBehavior = MatchAllRules, const RenderRegion* regionForStyling = nullptr, const SelectorFilter* = nullptr);
 
-    void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList&);
+    void keyframeStylesForAnimation(Element&, const RenderStyle*, KeyframeList&);
 
-    PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleRequest&, RenderStyle* parentStyle);
+    PassRefPtr<RenderStyle> pseudoStyleForElement(Element&, const PseudoStyleRequest&, RenderStyle& parentStyle);
 
     Ref<RenderStyle> styleForPage(int pageIndex);
     Ref<RenderStyle> defaultStyleForElement();
@@ -160,7 +160,6 @@
     const MediaQueryEvaluator& mediaQueryEvaluator() const { return *m_medium; }
 
 private:
-    void initElement(Element*);
     RenderStyle* locateSharedStyle();
     bool styleSharingCandidateMatchesRuleSet(RuleSet*);
     Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
@@ -333,7 +332,7 @@
     bool fastRejectSelector(const RuleData&) const;
 
     enum ShouldUseMatchedPropertiesCache { DoNotUseMatchedPropertiesCache = 0, UseMatchedPropertiesCache };
-    void applyMatchedProperties(const MatchResult&, const Element*, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache);
+    void applyMatchedProperties(const MatchResult&, const Element&, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache);
 
     void applyCascadedProperties(CascadedProperties&, int firstProperty, int lastProperty, const MatchResult*);
     void cascadeMatches(CascadedProperties&, const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
@@ -359,33 +358,16 @@
     typedef HashMap<CSSPropertyID, RefPtr<CSSValue>> PendingImagePropertyMap;
 
     class State {
-        WTF_MAKE_NONCOPYABLE(State);
     public:
-        State()
-            : m_element(nullptr)
-            , m_styledElement(nullptr)
-            , m_parentStyle(nullptr)
-            , m_rootElementStyle(nullptr)
-            , m_regionForStyling(nullptr)
-            , m_elementLinkState(NotInsideLink)
-            , m_elementAffectedByClassRules(false)
-            , m_applyPropertyToRegularStyle(true)
-            , m_applyPropertyToVisitedLinkStyle(false)
-            , m_fontDirty(false)
-            , m_fontSizeHasViewportUnits(false)
-            , m_hasUAAppearance(false)
-            , m_backgroundData(BackgroundFillLayer)
-        {
-        }
+        State() { }
+        State(Element&, RenderStyle* parentStyle, const RenderRegion* regionForStyling = nullptr, const SelectorFilter* = nullptr);
 
     public:
-        void initElement(Element*);
-        void initForStyleResolve(Document&, Element*, RenderStyle* parentStyle, const RenderRegion* regionForStyling = nullptr, const SelectorFilter* = nullptr);
         void clear();
 
         Document& document() const { return m_element->document(); }
         Element* element() const { return m_element; }
-        StyledElement* styledElement() const { return m_styledElement; }
+
         void setStyle(Ref<RenderStyle>&&);
         RenderStyle* style() const { return m_style.get(); }
         Ref<RenderStyle> takeStyle() { return m_style.releaseNonNull(); }
@@ -444,34 +426,28 @@
     private:
         void updateConversionData();
 
-        Element* m_element;
+        Element* m_element { nullptr };
         RefPtr<RenderStyle> m_style;
-        StyledElement* m_styledElement;
         RefPtr<RenderStyle> m_parentStyle;
-        RenderStyle* m_rootElementStyle;
+        RenderStyle* m_rootElementStyle { nullptr };
 
-        // Required to ASSERT in applyProperties.
-        const RenderRegion* m_regionForStyling;
+        const RenderRegion* m_regionForStyling { nullptr };
         
-        EInsideLink m_elementLinkState;
+        EInsideLink m_elementLinkState { NotInsideLink };
 
-        bool m_elementAffectedByClassRules;
+        bool m_elementAffectedByClassRules { false };
+        bool m_applyPropertyToRegularStyle { true };
+        bool m_applyPropertyToVisitedLinkStyle { false };
+        bool m_fontDirty { false };
+        bool m_fontSizeHasViewportUnits { false };
+        bool m_hasUAAppearance { false };
 
-        bool m_applyPropertyToRegularStyle;
-        bool m_applyPropertyToVisitedLinkStyle;
-
-        PendingImagePropertyMap m_pendingImageProperties;
-
-        Vector<RefPtr<ReferenceFilterOperation>> m_filtersWithPendingSVGDocuments;
-
-        bool m_fontDirty;
-        bool m_fontSizeHasViewportUnits;
-
-        bool m_hasUAAppearance;
         BorderData m_borderData;
-        FillLayer m_backgroundData;
+        FillLayer m_backgroundData { BackgroundFillLayer };
         Color m_backgroundColor;
 
+        PendingImagePropertyMap m_pendingImageProperties;
+        Vector<RefPtr<ReferenceFilterOperation>> m_filtersWithPendingSVGDocuments;
         CSSToLengthConversionData m_cssToLengthConversionData;
         
         CascadeLevel m_cascadeLevel { UserAgentLevel };

Modified: trunk/Source/WebCore/dom/Element.cpp (195464 => 195465)


--- trunk/Source/WebCore/dom/Element.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -1404,7 +1404,7 @@
 
 Ref<RenderStyle> Element::resolveStyle(RenderStyle* parentStyle)
 {
-    return styleResolver().styleForElement(this, parentStyle);
+    return styleResolver().styleForElement(*this, parentStyle);
 }
 
 // Returns true is the given attribute is an event handler.

Modified: trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp (195464 => 195465)


--- trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -49,7 +49,7 @@
 {
     // Get the keyframe RenderStyles
     if (m_object && m_object->element())
-        m_object->element()->styleResolver().keyframeStylesForAnimation(m_object->element(), unanimatedStyle, m_keyframes);
+        m_object->element()->styleResolver().keyframeStylesForAnimation(*m_object->element(), unanimatedStyle, m_keyframes);
 
     // Update the m_transformFunctionListValid flag based on whether the function lists in the keyframes match.
     validateTransformFunctionList();

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (195464 => 195465)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -1590,12 +1590,12 @@
     auto& styleResolver = element()->styleResolver();
 
     if (pseudoStyleRequest.pseudoId == FIRST_LINE_INHERITED) {
-        RefPtr<RenderStyle> result = styleResolver.styleForElement(element(), parentStyle, DisallowStyleSharing);
+        RefPtr<RenderStyle> result = styleResolver.styleForElement(*element(), parentStyle, DisallowStyleSharing);
         result->setStyleType(FIRST_LINE_INHERITED);
         return result.release();
     }
 
-    return styleResolver.pseudoStyleForElement(element(), pseudoStyleRequest, parentStyle);
+    return styleResolver.pseudoStyleForElement(*element(), pseudoStyleRequest, *parentStyle);
 }
 
 RenderBlock* RenderElement::containingBlockForFixedPosition() const

Modified: trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp (195464 => 195465)


--- trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowFragment.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -352,7 +352,7 @@
     ASSERT(!renderer.isAnonymous());
 
     // FIXME: Region styling fails for pseudo-elements because the renderers don't have a node.
-    RefPtr<RenderStyle> renderObjectRegionStyle = renderer.element()->styleResolver().styleForElement(renderer.element(), &parentStyle, DisallowStyleSharing, MatchAllRules, this);
+    RefPtr<RenderStyle> renderObjectRegionStyle = renderer.element()->styleResolver().styleForElement(*renderer.element(), &parentStyle, DisallowStyleSharing, MatchAllRules, this);
 
     return renderObjectRegionStyle.release();
 }

Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (195464 => 195465)


--- trunk/Source/WebCore/style/StyleTreeResolver.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -127,7 +127,7 @@
         if (RefPtr<RenderStyle> style = element.customStyleForRenderer(inheritedStyle))
             return style.releaseNonNull();
     }
-    return m_styleResolver.styleForElement(&element, &inheritedStyle, AllowStyleSharing, MatchAllRules, nullptr, &m_selectorFilter);
+    return m_styleResolver.styleForElement(element, &inheritedStyle, AllowStyleSharing, MatchAllRules, nullptr, &m_selectorFilter);
 }
 
 #if ENABLE(CSS_REGIONS)

Modified: trunk/Source/WebCore/svg/SVGElement.cpp (195464 => 195465)


--- trunk/Source/WebCore/svg/SVGElement.cpp	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/svg/SVGElement.cpp	2016-01-22 20:00:34 UTC (rev 195465)
@@ -793,7 +793,7 @@
 {
     // If the element is in a <use> tree we get the style from the definition tree.
     if (auto* styleElement = this->correspondingElement())
-        return styleElement->styleResolver().styleForElement(styleElement, &parentStyle, DisallowStyleSharing);
+        return styleElement->styleResolver().styleForElement(*styleElement, &parentStyle, DisallowStyleSharing);
 
     return resolveStyle(&parentStyle);
 }
@@ -827,7 +827,7 @@
             parentStyle = &renderer->style();
     }
 
-    return m_svgRareData->overrideComputedStyle(this, parentStyle);
+    return m_svgRareData->overrideComputedStyle(*this, parentStyle);
 }
 
 static void addQualifiedName(HashMap<AtomicString, QualifiedName>& map, const QualifiedName& name)

Modified: trunk/Source/WebCore/svg/SVGElementRareData.h (195464 => 195465)


--- trunk/Source/WebCore/svg/SVGElementRareData.h	2016-01-22 19:44:54 UTC (rev 195464)
+++ trunk/Source/WebCore/svg/SVGElementRareData.h	2016-01-22 20:00:34 UTC (rev 195465)
@@ -65,14 +65,13 @@
         return *m_animatedSMILStyleProperties;
     }
 
-    RenderStyle* overrideComputedStyle(Element* element, RenderStyle* parentStyle)
+    RenderStyle* overrideComputedStyle(Element& element, RenderStyle* parentStyle)
     {
-        ASSERT(element);
         if (!m_useOverrideComputedStyle)
             return 0;
         if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
             // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
-            m_overrideComputedStyle = element->styleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
+            m_overrideComputedStyle = element.styleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
             m_needsOverrideComputedStyleUpdate = false;
         }
         ASSERT(m_overrideComputedStyle);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to