Title: [196470] trunk/Source/WebCore
Revision
196470
Author
[email protected]
Date
2016-02-12 07:05:12 -0800 (Fri, 12 Feb 2016)

Log Message

Factor class change style invalidation code into a class
https://bugs.webkit.org/show_bug.cgi?id=154163

Reviewed by Andreas Kling.

Factor this piece of functionality out of Element and into ClassChangeInvalidation class.

* CMakeLists.txt:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/Element.cpp:
(WebCore::classStringHasClassName):
(WebCore::Element::classAttributeChanged):
(WebCore::collectClasses): Deleted.
(WebCore::computeClassChange): Deleted.
(WebCore::invalidateStyleForClassChange): Deleted.
* style/ClassChangeInvalidation.cpp: Added.
(WebCore::Style::ClassChangeInvalidation::computeClassChange):
(WebCore::Style::ClassChangeInvalidation::invalidateStyle):
* style/ClassChangeInvalidation.h: Added.
(WebCore::Style::ClassChangeInvalidation::needsInvalidation):
(WebCore::Style::ClassChangeInvalidation::ClassChangeInvalidation):
(WebCore::Style::ClassChangeInvalidation::~ClassChangeInvalidation):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (196469 => 196470)


--- trunk/Source/WebCore/CMakeLists.txt	2016-02-12 13:52:07 UTC (rev 196469)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-02-12 15:05:12 UTC (rev 196470)
@@ -2621,6 +2621,7 @@
     storage/StorageMap.cpp
     storage/StorageNamespaceProvider.cpp
 
+    style/ClassChangeInvalidation.cpp
     style/InlineTextBoxStyle.cpp
     style/RenderTreePosition.cpp
     style/StyleChange.cpp

Modified: trunk/Source/WebCore/ChangeLog (196469 => 196470)


--- trunk/Source/WebCore/ChangeLog	2016-02-12 13:52:07 UTC (rev 196469)
+++ trunk/Source/WebCore/ChangeLog	2016-02-12 15:05:12 UTC (rev 196470)
@@ -1,3 +1,29 @@
+2016-02-12  Antti Koivisto  <[email protected]>
+
+        Factor class change style invalidation code into a class
+        https://bugs.webkit.org/show_bug.cgi?id=154163
+
+        Reviewed by Andreas Kling.
+
+        Factor this piece of functionality out of Element and into ClassChangeInvalidation class.
+
+        * CMakeLists.txt:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/Element.cpp:
+        (WebCore::classStringHasClassName):
+        (WebCore::Element::classAttributeChanged):
+        (WebCore::collectClasses): Deleted.
+        (WebCore::computeClassChange): Deleted.
+        (WebCore::invalidateStyleForClassChange): Deleted.
+        * style/ClassChangeInvalidation.cpp: Added.
+        (WebCore::Style::ClassChangeInvalidation::computeClassChange):
+        (WebCore::Style::ClassChangeInvalidation::invalidateStyle):
+        * style/ClassChangeInvalidation.h: Added.
+        (WebCore::Style::ClassChangeInvalidation::needsInvalidation):
+        (WebCore::Style::ClassChangeInvalidation::ClassChangeInvalidation):
+        (WebCore::Style::ClassChangeInvalidation::~ClassChangeInvalidation):
+
 2016-02-12  Csaba Osztrogonác  <[email protected]>
 
         GCC buildfix in Source/WebCore/svg/SVGToOTFFontConversion.cpp

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (196469 => 196470)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2016-02-12 13:52:07 UTC (rev 196469)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2016-02-12 15:05:12 UTC (rev 196470)
@@ -19225,6 +19225,7 @@
     <ClCompile Include="..\storage\StorageEventDispatcher.cpp" />
     <ClCompile Include="..\storage\StorageMap.cpp" />
     <ClCompile Include="..\storage\StorageNamespaceProvider.cpp" />
+    <ClCompile Include="..\style\ClassChangeInvalidation.cpp" />
     <ClCompile Include="..\style\InlineTextBoxStyle.cpp" />
     <ClCompile Include="..\style\RenderTreePosition.cpp" />
     <ClCompile Include="..\style\StyleChange.cpp" />
@@ -22791,6 +22792,7 @@
     <ClInclude Include="..\storage\StorageMap.h" />
     <ClInclude Include="..\storage\StorageNamespace.h" />
     <ClInclude Include="..\storage\StorageNamespaceProvider.h" />
+    <ClInclude Include="..\style\ClassChangeInvalidation.h" />
     <ClInclude Include="..\style\InlineTextBoxStyle.h" />
     <ClInclude Include="..\style\RenderTreePosition.h" />
     <ClInclude Include="..\style\StyleChange.h" />

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (196469 => 196470)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-02-12 13:52:07 UTC (rev 196469)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-02-12 15:05:12 UTC (rev 196470)
@@ -6617,6 +6617,8 @@
 		E49BDA0B131FD3E5003C56F0 /* CSSValuePool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49BDA0A131FD3E5003C56F0 /* CSSValuePool.cpp */; };
 		E4A007831B820EC8002C5A6E /* DataURLDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A007821B820EC8002C5A6E /* DataURLDecoder.h */; };
 		E4A007851B820ED3002C5A6E /* DataURLDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A007841B820ED3002C5A6E /* DataURLDecoder.cpp */; };
+		E4A814D41C6DEC4000BF85AC /* ClassChangeInvalidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A814D31C6DEC4000BF85AC /* ClassChangeInvalidation.h */; };
+		E4A814D61C6DEE8D00BF85AC /* ClassChangeInvalidation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4A814D51C6DEE8D00BF85AC /* ClassChangeInvalidation.cpp */; };
 		E4AE7C1617D1BB950009FB31 /* ElementIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1517D1BB950009FB31 /* ElementIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E4AE7C1A17D232350009FB31 /* ElementAncestorIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E4AFCFA50DAF29A300F5F55C /* UnitBezier.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AFCFA40DAF29A300F5F55C /* UnitBezier.h */; };
@@ -14601,6 +14603,8 @@
 		E49BDA0A131FD3E5003C56F0 /* CSSValuePool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSValuePool.cpp; sourceTree = "<group>"; };
 		E4A007821B820EC8002C5A6E /* DataURLDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataURLDecoder.h; sourceTree = "<group>"; };
 		E4A007841B820ED3002C5A6E /* DataURLDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataURLDecoder.cpp; sourceTree = "<group>"; };
+		E4A814D31C6DEC4000BF85AC /* ClassChangeInvalidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClassChangeInvalidation.h; sourceTree = "<group>"; };
+		E4A814D51C6DEE8D00BF85AC /* ClassChangeInvalidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClassChangeInvalidation.cpp; sourceTree = "<group>"; };
 		E4AE7C1517D1BB950009FB31 /* ElementIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIterator.h; sourceTree = "<group>"; };
 		E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAncestorIterator.h; sourceTree = "<group>"; };
 		E4AFCFA40DAF29A300F5F55C /* UnitBezier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnitBezier.h; sourceTree = "<group>"; };
@@ -23377,6 +23381,8 @@
 		E4763D4A17B2704900D35206 /* style */ = {
 			isa = PBXGroup;
 			children = (
+				E4A814D51C6DEE8D00BF85AC /* ClassChangeInvalidation.cpp */,
+				E4A814D31C6DEC4000BF85AC /* ClassChangeInvalidation.h */,
 				1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */,
 				1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */,
 				5824ABA81AE849C8009074B7 /* RenderTreePosition.cpp */,
@@ -25928,6 +25934,7 @@
 				B2C3DA6C0D006CD600EF6F26 /* GlyphBuffer.h in Headers */,
 				C5D4AA7A116BAFB60069CA93 /* GlyphMetricsMap.h in Headers */,
 				0873B86B136064EA00A522C2 /* GlyphPage.h in Headers */,
+				E4A814D41C6DEC4000BF85AC /* ClassChangeInvalidation.h in Headers */,
 				BC53C5F50DA56B920021EB5D /* Gradient.h in Headers */,
 				B22279640D00BF220071B782 /* GradientAttributes.h in Headers */,
 				2D481F04146B5C6B00AA7834 /* GradientImage.h in Headers */,
@@ -30202,6 +30209,7 @@
 				511EF2C717F0FD3500E4FA16 /* JSIDBObjectStore.cpp in Sources */,
 				511EF2D117F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp in Sources */,
 				511EF2C817F0FD3500E4FA16 /* JSIDBOpenDBRequest.cpp in Sources */,
+				E4A814D61C6DEE8D00BF85AC /* ClassChangeInvalidation.cpp in Sources */,
 				511EF2C917F0FD3500E4FA16 /* JSIDBRequest.cpp in Sources */,
 				511EF2CA17F0FD3500E4FA16 /* JSIDBTransaction.cpp in Sources */,
 				511EF2CB17F0FD3500E4FA16 /* JSIDBVersionChangeEvent.cpp in Sources */,

Modified: trunk/Source/WebCore/dom/Element.cpp (196469 => 196470)


--- trunk/Source/WebCore/dom/Element.cpp	2016-02-12 13:52:07 UTC (rev 196469)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-02-12 15:05:12 UTC (rev 196470)
@@ -31,6 +31,7 @@
 #include "CSSParser.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
+#include "ClassChangeInvalidation.h"
 #include "ClientRect.h"
 #include "ClientRectList.h"
 #include "ComposedTreeAncestorIterator.h"
@@ -76,7 +77,6 @@
 #include "ScrollLatchingState.h"
 #include "SelectorQuery.h"
 #include "Settings.h"
-#include "StyleInvalidationAnalysis.h"
 #include "StyleProperties.h"
 #include "StyleResolver.h"
 #include "StyleTreeResolver.h"
@@ -1299,91 +1299,6 @@
     return classStringHasClassName(newClassString.characters16(), length);
 }
 
-static Vector<AtomicStringImpl*, 4> collectClasses(const SpaceSplitString& classes)
-{
-    Vector<AtomicStringImpl*, 4> result;
-    result.reserveCapacity(classes.size());
-    for (unsigned i = 0; i < classes.size(); ++i)
-        result.uncheckedAppend(classes[i].impl());
-    return result;
-}
-
-struct ClassChange {
-    Vector<AtomicStringImpl*, 4> added;
-    Vector<AtomicStringImpl*, 4> removed;
-};
-
-static ClassChange computeClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses)
-{
-    ClassChange classChange;
-
-    unsigned oldSize = oldClasses.size();
-    unsigned newSize = newClasses.size();
-
-    if (!oldSize) {
-        classChange.added = collectClasses(newClasses);
-        return classChange;
-    }
-    if (!newSize) {
-        classChange.removed = collectClasses(oldClasses);
-        return classChange;
-    }
-
-    BitVector remainingClassBits;
-    remainingClassBits.ensureSize(oldSize);
-    // Class vectors tend to be very short. This is faster than using a hash table.
-    for (unsigned i = 0; i < newSize; ++i) {
-        bool foundFromBoth = false;
-        for (unsigned j = 0; j < oldSize; ++j) {
-            if (newClasses[i] == oldClasses[j]) {
-                remainingClassBits.quickSet(j);
-                foundFromBoth = true;
-            }
-        }
-        if (foundFromBoth)
-            continue;
-        classChange.added.append(newClasses[i].impl());
-    }
-    for (unsigned i = 0; i < oldSize; ++i) {
-        // If the bit is not set the the corresponding class has been removed.
-        if (remainingClassBits.quickGet(i))
-            continue;
-        classChange.removed.append(oldClasses[i].impl());
-    }
-
-    return classChange;
-}
-
-static void invalidateStyleForClassChange(Element& element, const Vector<AtomicStringImpl*, 4>& changedClasses, const DocumentRuleSets& ruleSets)
-{
-    Vector<AtomicStringImpl*, 4> changedClassesAffectingStyle;
-    for (auto* changedClass : changedClasses) {
-        if (ruleSets.features().classesInRules.contains(changedClass))
-            changedClassesAffectingStyle.append(changedClass);
-    };
-
-    if (changedClassesAffectingStyle.isEmpty())
-        return;
-
-    if (element.shadowRoot() && ruleSets.authorStyle()->hasShadowPseudoElementRules()) {
-        element.setNeedsStyleRecalc(FullStyleChange);
-        return;
-    }
-
-    element.setNeedsStyleRecalc(InlineStyleChange);
-
-    if (!element.firstElementChild())
-        return;
-
-    for (auto* changedClass : changedClassesAffectingStyle) {
-        auto* ancestorClassRules = ruleSets.ancestorClassRules(changedClass);
-        if (!ancestorClassRules)
-            continue;
-        StyleInvalidationAnalysis invalidationAnalysis(*ancestorClassRules);
-        invalidationAnalysis.invalidateStyle(element);
-    }
-}
-
 void Element::classAttributeChanged(const AtomicString& newClassString)
 {
     // Note: We'll need ElementData, but it doesn't have to be UniqueElementData.
@@ -1395,24 +1310,11 @@
 
     auto oldClassNames = elementData()->classNames();
     auto newClassNames = newStringHasClasses ? SpaceSplitString(newClassString, shouldFoldCase) : SpaceSplitString();
-
-    StyleResolver* styleResolver = document().styleResolverIfExists();
-    bool shouldInvalidateStyle = inRenderedDocument() && styleResolver && styleChangeType() < FullStyleChange;
-
-    ClassChange classChange;
-    if (shouldInvalidateStyle) {
-        classChange = computeClassChange(oldClassNames, newClassNames);
-        if (!classChange.removed.isEmpty())
-            invalidateStyleForClassChange(*this, classChange.removed, styleResolver->ruleSets());
+    {
+        Style::ClassChangeInvalidation styleInvalidation(*this, oldClassNames, newClassNames);
+        elementData()->setClassNames(newClassNames);
     }
 
-    elementData()->setClassNames(newClassNames);
-
-    if (shouldInvalidateStyle) {
-        if (!classChange.added.isEmpty())
-            invalidateStyleForClassChange(*this, classChange.added, styleResolver->ruleSets());
-    }
-
     if (hasRareData()) {
         if (auto* classList = elementRareData()->classList())
             classList->attributeValueChanged(newClassString);

Added: trunk/Source/WebCore/style/ClassChangeInvalidation.cpp (0 => 196470)


--- trunk/Source/WebCore/style/ClassChangeInvalidation.cpp	                        (rev 0)
+++ trunk/Source/WebCore/style/ClassChangeInvalidation.cpp	2016-02-12 15:05:12 UTC (rev 196470)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ClassChangeInvalidation.h"
+
+#include "DocumentRuleSets.h"
+#include "ElementChildIterator.h"
+#include "SpaceSplitString.h"
+#include "StyleInvalidationAnalysis.h"
+
+namespace WebCore {
+namespace Style {
+
+auto ClassChangeInvalidation::collectClasses(const SpaceSplitString& classes) -> ClassChangeVector
+{
+    ClassChangeVector result;
+    result.reserveCapacity(classes.size());
+    for (unsigned i = 0; i < classes.size(); ++i)
+        result.uncheckedAppend(classes[i].impl());
+    return result;
+}
+
+void ClassChangeInvalidation::computeClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses)
+{
+    unsigned oldSize = oldClasses.size();
+    unsigned newSize = newClasses.size();
+
+    if (!oldSize) {
+        m_addedClasses = collectClasses(newClasses);
+        return;
+    }
+    if (!newSize) {
+        m_removedClasses = collectClasses(oldClasses);
+        return;
+    }
+
+    BitVector remainingClassBits;
+    remainingClassBits.ensureSize(oldSize);
+    // Class vectors tend to be very short. This is faster than using a hash table.
+    for (unsigned i = 0; i < newSize; ++i) {
+        bool foundFromBoth = false;
+        for (unsigned j = 0; j < oldSize; ++j) {
+            if (newClasses[i] == oldClasses[j]) {
+                remainingClassBits.quickSet(j);
+                foundFromBoth = true;
+            }
+        }
+        if (foundFromBoth)
+            continue;
+        m_addedClasses.append(newClasses[i].impl());
+    }
+    for (unsigned i = 0; i < oldSize; ++i) {
+        // If the bit is not set the the corresponding class has been removed.
+        if (remainingClassBits.quickGet(i))
+            continue;
+        m_removedClasses.append(oldClasses[i].impl());
+    }
+}
+
+void ClassChangeInvalidation::invalidateStyle(const ClassChangeVector& changedClasses)
+{
+    auto& ruleSets = m_element.styleResolver().ruleSets();
+
+    Vector<AtomicStringImpl*, 4> changedClassesAffectingStyle;
+    for (auto* changedClass : changedClasses) {
+        if (ruleSets.features().classesInRules.contains(changedClass))
+            changedClassesAffectingStyle.append(changedClass);
+    };
+
+    if (changedClassesAffectingStyle.isEmpty())
+        return;
+
+    if (m_element.shadowRoot() && ruleSets.authorStyle()->hasShadowPseudoElementRules()) {
+        m_element.setNeedsStyleRecalc(FullStyleChange);
+        return;
+    }
+
+    m_element.setNeedsStyleRecalc(InlineStyleChange);
+
+    if (!childrenOfType<Element>(m_element).first())
+        return;
+
+    for (auto* changedClass : changedClassesAffectingStyle) {
+        auto* ancestorClassRules = ruleSets.ancestorClassRules(changedClass);
+        if (!ancestorClassRules)
+            continue;
+        StyleInvalidationAnalysis invalidationAnalysis(*ancestorClassRules);
+        invalidationAnalysis.invalidateStyle(m_element);
+    }
+}
+
+}
+}

Added: trunk/Source/WebCore/style/ClassChangeInvalidation.h (0 => 196470)


--- trunk/Source/WebCore/style/ClassChangeInvalidation.h	                        (rev 0)
+++ trunk/Source/WebCore/style/ClassChangeInvalidation.h	2016-02-12 15:05:12 UTC (rev 196470)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ClassChangeInvalidation_h
+#define ClassChangeInvalidation_h
+
+#include "Document.h"
+#include "Element.h"
+#include "StyleResolver.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class DocumentRuleSets;
+class SpaceSplitString;
+
+namespace Style {
+
+class ClassChangeInvalidation {
+public:
+    ClassChangeInvalidation(Element&, const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses);
+    ~ClassChangeInvalidation();
+
+private:
+    using ClassChangeVector = Vector<AtomicStringImpl*, 4>;
+
+    static bool needsInvalidation(const Element&);
+    void computeClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses);
+    void invalidateStyle(const ClassChangeVector&);
+
+    static ClassChangeVector collectClasses(const SpaceSplitString&);
+
+    const bool m_isEnabled;
+    Element& m_element;
+
+    ClassChangeVector m_addedClasses;
+    ClassChangeVector m_removedClasses;
+};
+
+inline bool ClassChangeInvalidation::needsInvalidation(const Element& element)
+{
+    if (!element.inRenderedDocument())
+        return false;
+    if (element.styleChangeType() >= FullStyleChange)
+        return false;
+    if (!element.document().styleResolverIfExists() && &element.treeScope() == &element.document())
+        return false;
+    return true;
+}
+
+inline ClassChangeInvalidation::ClassChangeInvalidation(Element& element, const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses)
+    : m_isEnabled(needsInvalidation(element))
+    , m_element(element)
+
+{
+    if (!m_isEnabled)
+        return;
+    computeClassChange(oldClasses, newClasses);
+    invalidateStyle(m_removedClasses);
+}
+
+inline ClassChangeInvalidation::~ClassChangeInvalidation()
+{
+    if (!m_isEnabled)
+        return;
+    invalidateStyle(m_addedClasses);
+}
+    
+}
+}
+
+#endif
+
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to