Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (216116 => 216117)
--- trunk/Source/WebCore/CMakeLists.txt 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/CMakeLists.txt 2017-05-03 14:04:21 UTC (rev 216117)
@@ -1393,7 +1393,6 @@
css/SelectorChecker.cpp
css/SelectorFilter.cpp
css/StyleColor.cpp
- css/StyleInvalidationAnalysis.cpp
css/StyleMedia.cpp
css/StyleProperties.cpp
css/StylePropertyShorthand.cpp
@@ -2735,6 +2734,7 @@
style/RenderTreeUpdater.cpp
style/StyleChange.cpp
style/StyleFontSizeFunctions.cpp
+ style/StyleInvalidator.cpp
style/StylePendingResources.cpp
style/StyleRelations.cpp
style/StyleResolveForDocument.cpp
Modified: trunk/Source/WebCore/ChangeLog (216116 => 216117)
--- trunk/Source/WebCore/ChangeLog 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/ChangeLog 2017-05-03 14:04:21 UTC (rev 216117)
@@ -1,3 +1,38 @@
+2017-05-03 Antti Koivisto <an...@apple.com>
+
+ Rename StyleInvalidationAnalysis to Style::Invalidator
+ https://bugs.webkit.org/show_bug.cgi?id=171601
+
+ Reviewed by Žan Doberšek.
+
+ Also move it to the 'style' directory.
+
+ * CMakeLists.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * css/StyleInvalidationAnalysis.cpp: Removed.
+ * css/StyleInvalidationAnalysis.h: Removed.
+ * dom/ExtensionStyleSheets.cpp:
+ * style/AttributeChangeInvalidation.cpp:
+ (WebCore::Style::AttributeChangeInvalidation::invalidateDescendants):
+ * style/ClassChangeInvalidation.cpp:
+ (WebCore::Style::ClassChangeInvalidation::invalidateDescendantStyle):
+ * style/StyleInvalidator.cpp: Copied from Source/WebCore/css/StyleInvalidationAnalysis.cpp.
+ (WebCore::Style::Invalidator::Invalidator):
+ (WebCore::Style::Invalidator::invalidateIfNeeded):
+ (WebCore::Style::Invalidator::invalidateStyleForTree):
+ (WebCore::Style::Invalidator::invalidateStyle):
+ (WebCore::shouldDirtyAllStyle): Deleted.
+ (WebCore::StyleInvalidationAnalysis::StyleInvalidationAnalysis): Deleted.
+ (WebCore::StyleInvalidationAnalysis::invalidateIfNeeded): Deleted.
+ (WebCore::StyleInvalidationAnalysis::invalidateStyleForTree): Deleted.
+ (WebCore::StyleInvalidationAnalysis::invalidateStyle): Deleted.
+ * style/StyleInvalidator.h: Copied from Source/WebCore/css/StyleInvalidationAnalysis.h.
+ (WebCore::StyleInvalidationAnalysis::dirtiesAllStyle): Deleted.
+ (WebCore::StyleInvalidationAnalysis::hasShadowPseudoElementRulesInAuthorSheet): Deleted.
+ * style/StyleScope.cpp:
+ (WebCore::Style::Scope::resolver):
+ (WebCore::Style::Scope::analyzeStyleSheetChange):
+
2017-05-02 Andrew Gold <ag...@apple.com>
Typo in AVAudioSessionCaptureDeviceManager.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (216116 => 216117)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-05-03 14:04:21 UTC (rev 216117)
@@ -6749,8 +6749,8 @@
E46A2B1C17CA65B9000DBCD8 /* TypedElementDescendantIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A2B1B17CA65B9000DBCD8 /* TypedElementDescendantIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
E46A2B1E17CA76B1000DBCD8 /* ElementChildIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */; settings = {ATTRIBUTES = (Private, ); }; };
E46B41F91CB24E70008F11DE /* NoEventDispatchAssertion.h in Headers */ = {isa = PBXBuildFile; fileRef = E46B41F81CB24E70008F11DE /* NoEventDispatchAssertion.h */; settings = {ATTRIBUTES = (Private, ); }; };
- E47127CA163438A100ED6F5A /* StyleInvalidationAnalysis.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47A97CE163059FC005DCD99 /* StyleInvalidationAnalysis.cpp */; };
- E47127CB163438AE00ED6F5A /* StyleInvalidationAnalysis.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A97CF163059FC005DCD99 /* StyleInvalidationAnalysis.h */; };
+ E47127CA163438A100ED6F5A /* StyleInvalidator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47A97CE163059FC005DCD99 /* StyleInvalidator.cpp */; };
+ E47127CB163438AE00ED6F5A /* StyleInvalidator.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A97CF163059FC005DCD99 /* StyleInvalidator.h */; };
E4778B7F115A581A00B5D372 /* JSCustomEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */; };
E4778B80115A581A00B5D372 /* JSCustomEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E4778B7E115A581A00B5D372 /* JSCustomEvent.h */; };
E47A3AC31C5EABBE00CCBFA7 /* StyleSharingResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */; };
@@ -15293,8 +15293,8 @@
E4778B7E115A581A00B5D372 /* JSCustomEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomEvent.h; sourceTree = "<group>"; };
E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSharingResolver.cpp; sourceTree = "<group>"; };
E47A3AC41C5EAC7900CCBFA7 /* StyleSharingResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSharingResolver.h; sourceTree = "<group>"; };
- E47A97CE163059FC005DCD99 /* StyleInvalidationAnalysis.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleInvalidationAnalysis.cpp; sourceTree = "<group>"; };
- E47A97CF163059FC005DCD99 /* StyleInvalidationAnalysis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleInvalidationAnalysis.h; sourceTree = "<group>"; };
+ E47A97CE163059FC005DCD99 /* StyleInvalidator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleInvalidator.cpp; sourceTree = "<group>"; };
+ E47A97CF163059FC005DCD99 /* StyleInvalidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleInvalidator.h; sourceTree = "<group>"; };
E47B4BE60E71241600038854 /* CachedResourceHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedResourceHandle.h; sourceTree = "<group>"; };
E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedResourceHandle.cpp; sourceTree = "<group>"; };
E47E276416036ED200EE2AFB /* ExtensionStyleSheets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtensionStyleSheets.h; sourceTree = "<group>"; };
@@ -24749,6 +24749,8 @@
E401E0A31C3C0B8300F34D10 /* StyleChange.h */,
E4D58EB617B4ED8900CBDCA8 /* StyleFontSizeFunctions.cpp */,
E4D58EB717B4ED8900CBDCA8 /* StyleFontSizeFunctions.h */,
+ E47A97CE163059FC005DCD99 /* StyleInvalidator.cpp */,
+ E47A97CF163059FC005DCD99 /* StyleInvalidator.h */,
E4DACE6B1D12E1160075980F /* StylePendingResources.cpp */,
E4DACE691D12E10B0075980F /* StylePendingResources.h */,
E461802E1C8DD4D20026C02C /* StyleRelations.cpp */,
@@ -25058,8 +25060,6 @@
835D363619FF6193004C93AB /* StyleBuilderCustom.h */,
941827881D8B242200492764 /* StyleColor.cpp */,
941827891D8B242200492764 /* StyleColor.h */,
- E47A97CE163059FC005DCD99 /* StyleInvalidationAnalysis.cpp */,
- E47A97CF163059FC005DCD99 /* StyleInvalidationAnalysis.h */,
0FF5026E102BA9660066F39A /* StyleMedia.cpp */,
0FF5026F102BA96A0066F39A /* StyleMedia.h */,
0FF50270102BA96A0066F39A /* StyleMedia.idl */,
@@ -29345,7 +29345,7 @@
A110DB9B14F5DF7700A03B93 /* StyleGridItemData.h in Headers */,
BCEF43CF0E673DA1001C1287 /* StyleImage.h in Headers */,
BC2273040E82F1E600E7F975 /* StyleInheritedData.h in Headers */,
- E47127CB163438AE00ED6F5A /* StyleInvalidationAnalysis.h in Headers */,
+ E47127CB163438AE00ED6F5A /* StyleInvalidator.h in Headers */,
BC5EB72A0E81DE8100B25965 /* StyleMarqueeData.h in Headers */,
0FF50272102BA96A0066F39A /* StyleMedia.h in Headers */,
BC5EB74E0E81E06700B25965 /* StyleMultiColData.h in Headers */,
@@ -33163,7 +33163,7 @@
A10DC76A14747BAB005E2471 /* StyleGridData.cpp in Sources */,
A110DB9D14F5DF8700A03B93 /* StyleGridItemData.cpp in Sources */,
BC2273030E82F1E600E7F975 /* StyleInheritedData.cpp in Sources */,
- E47127CA163438A100ED6F5A /* StyleInvalidationAnalysis.cpp in Sources */,
+ E47127CA163438A100ED6F5A /* StyleInvalidator.cpp in Sources */,
BC5EB7290E81DE8100B25965 /* StyleMarqueeData.cpp in Sources */,
0FF50271102BA96A0066F39A /* StyleMedia.cpp in Sources */,
BC5EB74D0E81E06700B25965 /* StyleMultiColData.cpp in Sources */,
Deleted: trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp (216116 => 216117)
--- trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp 2017-05-03 14:04:21 UTC (rev 216117)
@@ -1,207 +0,0 @@
-/*
- * Copyright (C) 2012, 2014 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. ``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
- * 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 "StyleInvalidationAnalysis.h"
-
-#include "CSSSelectorList.h"
-#include "Document.h"
-#include "ElementIterator.h"
-#include "ElementRuleCollector.h"
-#include "HTMLSlotElement.h"
-#include "SelectorFilter.h"
-#include "ShadowRoot.h"
-#include "StyleRuleImport.h"
-#include "StyleSheetContents.h"
-
-namespace WebCore {
-
-static bool shouldDirtyAllStyle(const Vector<RefPtr<StyleRuleBase>>& rules)
-{
- for (auto& rule : rules) {
- if (is<StyleRuleMedia>(*rule)) {
- const auto* childRules = downcast<StyleRuleMedia>(*rule).childRulesWithoutDeferredParsing();
- if (childRules && shouldDirtyAllStyle(*childRules))
- return true;
- continue;
- }
- // FIXME: At least font faces don't need full recalc in all cases.
- if (!is<StyleRule>(*rule))
- return true;
- }
- return false;
-}
-
-static bool shouldDirtyAllStyle(const StyleSheetContents& sheet)
-{
- for (auto& import : sheet.importRules()) {
- if (!import->styleSheet())
- continue;
- if (shouldDirtyAllStyle(*import->styleSheet()))
- return true;
- }
- if (shouldDirtyAllStyle(sheet.childRules()))
- return true;
- return false;
-}
-
-static bool shouldDirtyAllStyle(const Vector<StyleSheetContents*>& sheets)
-{
- for (auto& sheet : sheets) {
- if (shouldDirtyAllStyle(*sheet))
- return true;
- }
- return false;
-}
-
-StyleInvalidationAnalysis::StyleInvalidationAnalysis(const Vector<StyleSheetContents*>& sheets, const MediaQueryEvaluator& mediaQueryEvaluator)
- : m_ownedRuleSet(std::make_unique<RuleSet>())
- , m_ruleSet(*m_ownedRuleSet)
- , m_dirtiesAllStyle(shouldDirtyAllStyle(sheets))
-{
- if (m_dirtiesAllStyle)
- return;
-
- m_ownedRuleSet->disableAutoShrinkToFit();
- for (auto& sheet : sheets)
- m_ownedRuleSet->addRulesFromSheet(*sheet, mediaQueryEvaluator);
-
- m_hasShadowPseudoElementRulesInAuthorSheet = m_ruleSet.hasShadowPseudoElementRules();
-}
-
-StyleInvalidationAnalysis::StyleInvalidationAnalysis(const RuleSet& ruleSet)
- : m_ruleSet(ruleSet)
- , m_hasShadowPseudoElementRulesInAuthorSheet(ruleSet.hasShadowPseudoElementRules())
-{
-}
-
-StyleInvalidationAnalysis::CheckDescendants StyleInvalidationAnalysis::invalidateIfNeeded(Element& element, const SelectorFilter* filter)
-{
- if (m_hasShadowPseudoElementRulesInAuthorSheet) {
- // FIXME: This could do actual rule matching too.
- if (element.shadowRoot())
- element.invalidateStyleForSubtree();
- }
-
- bool shouldCheckForSlots = !m_ruleSet.slottedPseudoElementRules().isEmpty() && !m_didInvalidateHostChildren;
- if (shouldCheckForSlots && is<HTMLSlotElement>(element)) {
- auto* containingShadowRoot = element.containingShadowRoot();
- if (containingShadowRoot && containingShadowRoot->host()) {
- for (auto& possiblySlotted : childrenOfType<Element>(*containingShadowRoot->host()))
- possiblySlotted.invalidateStyle();
- }
- // No need to do this again.
- m_didInvalidateHostChildren = true;
- }
-
- switch (element.styleValidity()) {
- case Style::Validity::Valid: {
- ElementRuleCollector ruleCollector(element, m_ruleSet, filter);
- ruleCollector.setMode(SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements);
- ruleCollector.matchAuthorRules(false);
-
- if (ruleCollector.hasMatchedRules())
- element.invalidateStyle();
- return CheckDescendants::Yes;
- }
- case Style::Validity::ElementInvalid:
- return CheckDescendants::Yes;
- case Style::Validity::SubtreeInvalid:
- case Style::Validity::SubtreeAndRenderersInvalid:
- if (shouldCheckForSlots)
- return CheckDescendants::Yes;
- return CheckDescendants::No;
- }
- ASSERT_NOT_REACHED();
- return CheckDescendants::Yes;
-}
-
-void StyleInvalidationAnalysis::invalidateStyleForTree(Element& root, SelectorFilter* filter)
-{
- if (invalidateIfNeeded(root, filter) == CheckDescendants::No)
- return;
-
- Vector<Element*, 20> parentStack;
- Element* previousElement = &root;
- auto descendants = descendantsOfType<Element>(root);
- for (auto it = descendants.begin(), end = descendants.end(); it != end;) {
- auto& descendant = *it;
- auto* parent = descendant.parentElement();
- if (parentStack.isEmpty() || parentStack.last() != parent) {
- if (parent == previousElement) {
- parentStack.append(parent);
- if (filter)
- filter->pushParent(parent);
- } else {
- while (parentStack.last() != parent) {
- parentStack.removeLast();
- if (filter)
- filter->popParent();
- }
- }
- }
- previousElement = &descendant;
-
- if (invalidateIfNeeded(descendant, filter) == CheckDescendants::Yes)
- it.traverseNext();
- else
- it.traverseNextSkippingChildren();
- }
-}
-
-void StyleInvalidationAnalysis::invalidateStyle(Document& document)
-{
- ASSERT(!m_dirtiesAllStyle);
-
- Element* documentElement = document.documentElement();
- if (!documentElement)
- return;
-
- SelectorFilter filter;
- invalidateStyleForTree(*documentElement, &filter);
-}
-
-void StyleInvalidationAnalysis::invalidateStyle(ShadowRoot& shadowRoot)
-{
- ASSERT(!m_dirtiesAllStyle);
-
- if (!m_ruleSet.hostPseudoClassRules().isEmpty() && shadowRoot.host())
- shadowRoot.host()->invalidateStyle();
-
- for (auto& child : childrenOfType<Element>(shadowRoot)) {
- SelectorFilter filter;
- invalidateStyleForTree(child, &filter);
- }
-}
-
-void StyleInvalidationAnalysis::invalidateStyle(Element& element)
-{
- ASSERT(!m_dirtiesAllStyle);
-
- // Don't use SelectorFilter as the rule sets here tend to be small and the filter would have setup cost deep in the tree.
- invalidateStyleForTree(element, nullptr);
-}
-
-}
Deleted: trunk/Source/WebCore/css/StyleInvalidationAnalysis.h (216116 => 216117)
--- trunk/Source/WebCore/css/StyleInvalidationAnalysis.h 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/css/StyleInvalidationAnalysis.h 2017-05-03 14:04:21 UTC (rev 216117)
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2012, 2014 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. ``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
- * 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.
- */
-
-#pragma once
-
-#include <wtf/text/AtomicStringImpl.h>
-
-namespace WebCore {
-
-class Document;
-class Element;
-class MediaQueryEvaluator;
-class RuleSet;
-class SelectorFilter;
-class ShadowRoot;
-class StyleSheetContents;
-
-class StyleInvalidationAnalysis {
-public:
- StyleInvalidationAnalysis(const Vector<StyleSheetContents*>&, const MediaQueryEvaluator&);
- StyleInvalidationAnalysis(const RuleSet&);
-
- bool dirtiesAllStyle() const { return m_dirtiesAllStyle; }
- bool hasShadowPseudoElementRulesInAuthorSheet() const { return m_hasShadowPseudoElementRulesInAuthorSheet; }
- void invalidateStyle(Document&);
- void invalidateStyle(ShadowRoot&);
- void invalidateStyle(Element&);
-
-private:
- enum class CheckDescendants { Yes, No };
- CheckDescendants invalidateIfNeeded(Element&, const SelectorFilter*);
- void invalidateStyleForTree(Element&, SelectorFilter*);
-
- std::unique_ptr<RuleSet> m_ownedRuleSet;
- const RuleSet& m_ruleSet;
- bool m_dirtiesAllStyle { false };
- bool m_hasShadowPseudoElementRulesInAuthorSheet { false };
- bool m_didInvalidateHostChildren { false };
-};
-
-} // namespace WebCore
Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (216116 => 216117)
--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp 2017-05-03 14:04:21 UTC (rev 216117)
@@ -36,7 +36,7 @@
#include "ProcessingInstruction.h"
#include "SVGStyleElement.h"
#include "Settings.h"
-#include "StyleInvalidationAnalysis.h"
+#include "StyleInvalidator.h"
#include "StyleResolver.h"
#include "StyleScope.h"
#include "StyleSheetContents.h"
Modified: trunk/Source/WebCore/style/AttributeChangeInvalidation.cpp (216116 => 216117)
--- trunk/Source/WebCore/style/AttributeChangeInvalidation.cpp 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/style/AttributeChangeInvalidation.cpp 2017-05-03 14:04:21 UTC (rev 216117)
@@ -29,7 +29,7 @@
#include "DocumentRuleSets.h"
#include "ElementIterator.h"
#include "ShadowRoot.h"
-#include "StyleInvalidationAnalysis.h"
+#include "StyleInvalidator.h"
#include "StyleResolver.h"
#include "StyleScope.h"
@@ -116,8 +116,8 @@
{
if (!m_descendantInvalidationRuleSet)
return;
- StyleInvalidationAnalysis invalidationAnalysis(*m_descendantInvalidationRuleSet);
- invalidationAnalysis.invalidateStyle(m_element);
+ Invalidator invalidator(*m_descendantInvalidationRuleSet);
+ invalidator.invalidateStyle(m_element);
}
}
Modified: trunk/Source/WebCore/style/ClassChangeInvalidation.cpp (216116 => 216117)
--- trunk/Source/WebCore/style/ClassChangeInvalidation.cpp 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/style/ClassChangeInvalidation.cpp 2017-05-03 14:04:21 UTC (rev 216117)
@@ -30,7 +30,7 @@
#include "ElementChildIterator.h"
#include "ShadowRoot.h"
#include "SpaceSplitString.h"
-#include "StyleInvalidationAnalysis.h"
+#include "StyleInvalidator.h"
#include "StyleResolver.h"
#include "StyleScope.h"
#include <wtf/BitVector.h>
@@ -149,8 +149,8 @@
void ClassChangeInvalidation::invalidateDescendantStyle()
{
for (auto* ancestorClassRules : m_descendantInvalidationRuleSets) {
- StyleInvalidationAnalysis invalidationAnalysis(*ancestorClassRules);
- invalidationAnalysis.invalidateStyle(m_element);
+ Invalidator invalidator(*ancestorClassRules);
+ invalidator.invalidateStyle(m_element);
}
}
Copied: trunk/Source/WebCore/style/StyleInvalidator.cpp (from rev 216116, trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp) (0 => 216117)
--- trunk/Source/WebCore/style/StyleInvalidator.cpp (rev 0)
+++ trunk/Source/WebCore/style/StyleInvalidator.cpp 2017-05-03 14:04:21 UTC (rev 216117)
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2012, 2014, 2017 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. ``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
+ * 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 "StyleInvalidator.h"
+
+#include "CSSSelectorList.h"
+#include "Document.h"
+#include "ElementIterator.h"
+#include "ElementRuleCollector.h"
+#include "HTMLSlotElement.h"
+#include "SelectorFilter.h"
+#include "ShadowRoot.h"
+#include "StyleRuleImport.h"
+#include "StyleSheetContents.h"
+
+namespace WebCore {
+namespace Style {
+
+static bool shouldDirtyAllStyle(const Vector<RefPtr<StyleRuleBase>>& rules)
+{
+ for (auto& rule : rules) {
+ if (is<StyleRuleMedia>(*rule)) {
+ const auto* childRules = downcast<StyleRuleMedia>(*rule).childRulesWithoutDeferredParsing();
+ if (childRules && shouldDirtyAllStyle(*childRules))
+ return true;
+ continue;
+ }
+ // FIXME: At least font faces don't need full recalc in all cases.
+ if (!is<StyleRule>(*rule))
+ return true;
+ }
+ return false;
+}
+
+static bool shouldDirtyAllStyle(const StyleSheetContents& sheet)
+{
+ for (auto& import : sheet.importRules()) {
+ if (!import->styleSheet())
+ continue;
+ if (shouldDirtyAllStyle(*import->styleSheet()))
+ return true;
+ }
+ if (shouldDirtyAllStyle(sheet.childRules()))
+ return true;
+ return false;
+}
+
+static bool shouldDirtyAllStyle(const Vector<StyleSheetContents*>& sheets)
+{
+ for (auto& sheet : sheets) {
+ if (shouldDirtyAllStyle(*sheet))
+ return true;
+ }
+ return false;
+}
+
+Invalidator::Invalidator(const Vector<StyleSheetContents*>& sheets, const MediaQueryEvaluator& mediaQueryEvaluator)
+ : m_ownedRuleSet(std::make_unique<RuleSet>())
+ , m_ruleSet(*m_ownedRuleSet)
+ , m_dirtiesAllStyle(shouldDirtyAllStyle(sheets))
+{
+ if (m_dirtiesAllStyle)
+ return;
+
+ m_ownedRuleSet->disableAutoShrinkToFit();
+ for (auto& sheet : sheets)
+ m_ownedRuleSet->addRulesFromSheet(*sheet, mediaQueryEvaluator);
+
+ m_hasShadowPseudoElementRulesInAuthorSheet = m_ruleSet.hasShadowPseudoElementRules();
+}
+
+Invalidator::Invalidator(const RuleSet& ruleSet)
+ : m_ruleSet(ruleSet)
+ , m_hasShadowPseudoElementRulesInAuthorSheet(ruleSet.hasShadowPseudoElementRules())
+{
+}
+
+Invalidator::CheckDescendants Invalidator::invalidateIfNeeded(Element& element, const SelectorFilter* filter)
+{
+ if (m_hasShadowPseudoElementRulesInAuthorSheet) {
+ // FIXME: This could do actual rule matching too.
+ if (element.shadowRoot())
+ element.invalidateStyleForSubtree();
+ }
+
+ bool shouldCheckForSlots = !m_ruleSet.slottedPseudoElementRules().isEmpty() && !m_didInvalidateHostChildren;
+ if (shouldCheckForSlots && is<HTMLSlotElement>(element)) {
+ auto* containingShadowRoot = element.containingShadowRoot();
+ if (containingShadowRoot && containingShadowRoot->host()) {
+ for (auto& possiblySlotted : childrenOfType<Element>(*containingShadowRoot->host()))
+ possiblySlotted.invalidateStyle();
+ }
+ // No need to do this again.
+ m_didInvalidateHostChildren = true;
+ }
+
+ switch (element.styleValidity()) {
+ case Style::Validity::Valid: {
+ ElementRuleCollector ruleCollector(element, m_ruleSet, filter);
+ ruleCollector.setMode(SelectorChecker::Mode::CollectingRulesIgnoringVirtualPseudoElements);
+ ruleCollector.matchAuthorRules(false);
+
+ if (ruleCollector.hasMatchedRules())
+ element.invalidateStyle();
+ return CheckDescendants::Yes;
+ }
+ case Style::Validity::ElementInvalid:
+ return CheckDescendants::Yes;
+ case Style::Validity::SubtreeInvalid:
+ case Style::Validity::SubtreeAndRenderersInvalid:
+ if (shouldCheckForSlots)
+ return CheckDescendants::Yes;
+ return CheckDescendants::No;
+ }
+ ASSERT_NOT_REACHED();
+ return CheckDescendants::Yes;
+}
+
+void Invalidator::invalidateStyleForTree(Element& root, SelectorFilter* filter)
+{
+ if (invalidateIfNeeded(root, filter) == CheckDescendants::No)
+ return;
+
+ Vector<Element*, 20> parentStack;
+ Element* previousElement = &root;
+ auto descendants = descendantsOfType<Element>(root);
+ for (auto it = descendants.begin(), end = descendants.end(); it != end;) {
+ auto& descendant = *it;
+ auto* parent = descendant.parentElement();
+ if (parentStack.isEmpty() || parentStack.last() != parent) {
+ if (parent == previousElement) {
+ parentStack.append(parent);
+ if (filter)
+ filter->pushParent(parent);
+ } else {
+ while (parentStack.last() != parent) {
+ parentStack.removeLast();
+ if (filter)
+ filter->popParent();
+ }
+ }
+ }
+ previousElement = &descendant;
+
+ if (invalidateIfNeeded(descendant, filter) == CheckDescendants::Yes)
+ it.traverseNext();
+ else
+ it.traverseNextSkippingChildren();
+ }
+}
+
+void Invalidator::invalidateStyle(Document& document)
+{
+ ASSERT(!m_dirtiesAllStyle);
+
+ Element* documentElement = document.documentElement();
+ if (!documentElement)
+ return;
+
+ SelectorFilter filter;
+ invalidateStyleForTree(*documentElement, &filter);
+}
+
+void Invalidator::invalidateStyle(ShadowRoot& shadowRoot)
+{
+ ASSERT(!m_dirtiesAllStyle);
+
+ if (!m_ruleSet.hostPseudoClassRules().isEmpty() && shadowRoot.host())
+ shadowRoot.host()->invalidateStyle();
+
+ for (auto& child : childrenOfType<Element>(shadowRoot)) {
+ SelectorFilter filter;
+ invalidateStyleForTree(child, &filter);
+ }
+}
+
+void Invalidator::invalidateStyle(Element& element)
+{
+ ASSERT(!m_dirtiesAllStyle);
+
+ // Don't use SelectorFilter as the rule sets here tend to be small and the filter would have setup cost deep in the tree.
+ invalidateStyleForTree(element, nullptr);
+}
+
+}
+}
Copied: trunk/Source/WebCore/style/StyleInvalidator.h (from rev 216116, trunk/Source/WebCore/css/StyleInvalidationAnalysis.h) (0 => 216117)
--- trunk/Source/WebCore/style/StyleInvalidator.h (rev 0)
+++ trunk/Source/WebCore/style/StyleInvalidator.h 2017-05-03 14:04:21 UTC (rev 216117)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2012, 2014, 2017 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. ``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
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/text/AtomicStringImpl.h>
+
+namespace WebCore {
+
+class Document;
+class Element;
+class MediaQueryEvaluator;
+class RuleSet;
+class SelectorFilter;
+class ShadowRoot;
+class StyleSheetContents;
+
+namespace Style {
+
+class Invalidator {
+public:
+ Invalidator(const Vector<StyleSheetContents*>&, const MediaQueryEvaluator&);
+ Invalidator(const RuleSet&);
+
+ bool dirtiesAllStyle() const { return m_dirtiesAllStyle; }
+ bool hasShadowPseudoElementRulesInAuthorSheet() const { return m_hasShadowPseudoElementRulesInAuthorSheet; }
+ void invalidateStyle(Document&);
+ void invalidateStyle(ShadowRoot&);
+ void invalidateStyle(Element&);
+
+private:
+ enum class CheckDescendants { Yes, No };
+ CheckDescendants invalidateIfNeeded(Element&, const SelectorFilter*);
+ void invalidateStyleForTree(Element&, SelectorFilter*);
+
+ std::unique_ptr<RuleSet> m_ownedRuleSet;
+ const RuleSet& m_ruleSet;
+ bool m_dirtiesAllStyle { false };
+ bool m_hasShadowPseudoElementRulesInAuthorSheet { false };
+ bool m_didInvalidateHostChildren { false };
+};
+
+}
+}
Modified: trunk/Source/WebCore/style/StyleScope.cpp (216116 => 216117)
--- trunk/Source/WebCore/style/StyleScope.cpp 2017-05-03 12:47:38 UTC (rev 216116)
+++ trunk/Source/WebCore/style/StyleScope.cpp 2017-05-03 14:04:21 UTC (rev 216117)
@@ -42,7 +42,7 @@
#include "SVGStyleElement.h"
#include "Settings.h"
#include "ShadowRoot.h"
-#include "StyleInvalidationAnalysis.h"
+#include "StyleInvalidator.h"
#include "StyleResolver.h"
#include "StyleSheetContents.h"
#include "StyleSheetList.h"
@@ -403,14 +403,14 @@
if (!m_document.bodyOrFrameset() || m_document.hasNodesWithNonFinalStyle() || m_document.hasNodesWithMissingStyle())
return styleResolverUpdateType;
- StyleInvalidationAnalysis invalidationAnalysis(addedSheets, styleResolver.mediaQueryEvaluator());
- if (invalidationAnalysis.dirtiesAllStyle())
+ Invalidator invalidator(addedSheets, styleResolver.mediaQueryEvaluator());
+ if (invalidator.dirtiesAllStyle())
return styleResolverUpdateType;
if (m_shadowRoot)
- invalidationAnalysis.invalidateStyle(*m_shadowRoot);
+ invalidator.invalidateStyle(*m_shadowRoot);
else
- invalidationAnalysis.invalidateStyle(m_document);
+ invalidator.invalidateStyle(m_document);
requiresFullStyleRecalc = false;