Title: [213515] trunk/Source/WebCore
Revision
213515
Author
[email protected]
Date
2017-03-07 08:54:56 -0800 (Tue, 07 Mar 2017)

Log Message

Differentiate between pending head and body stylesheets in Style::Scope
https://bugs.webkit.org/show_bug.cgi?id=169277

Reviewed by Andreas Kling.

Split pending stylesheet node set into separate sets for head and body elements and processing instructions.

This tightens typing and will also be useful later.

* style/StyleScope.cpp:
(WebCore::Style::Scope::~Scope):
(WebCore::Style::Scope::addPendingSheet):
(WebCore::Style::Scope::removePendingSheet):
(WebCore::Style::Scope::didRemovePendingStylesheet):
(WebCore::Style::Scope::hasPendingSheet):
(WebCore::Style::Scope::hasPendingSheetInBody):
(WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet): Deleted.
* style/StyleScope.h:
(WebCore::Style::Scope::hasPendingSheet): Deleted.
(WebCore::Style::Scope::hasPendingSheets): Deleted.
* style/StyleTreeResolver.cpp:
(WebCore::Style::hasLoadingStylesheet):

    Just test for body stylesheets.

(WebCore::Style::TreeResolver::resolve):

    Treat all before-body stylesheets uniformly.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (213514 => 213515)


--- trunk/Source/WebCore/ChangeLog	2017-03-07 16:23:30 UTC (rev 213514)
+++ trunk/Source/WebCore/ChangeLog	2017-03-07 16:54:56 UTC (rev 213515)
@@ -1,3 +1,34 @@
+2017-03-07  Antti Koivisto  <[email protected]>
+
+        Differentiate between pending head and body stylesheets in Style::Scope
+        https://bugs.webkit.org/show_bug.cgi?id=169277
+
+        Reviewed by Andreas Kling.
+
+        Split pending stylesheet node set into separate sets for head and body elements and processing instructions.
+
+        This tightens typing and will also be useful later.
+
+        * style/StyleScope.cpp:
+        (WebCore::Style::Scope::~Scope):
+        (WebCore::Style::Scope::addPendingSheet):
+        (WebCore::Style::Scope::removePendingSheet):
+        (WebCore::Style::Scope::didRemovePendingStylesheet):
+        (WebCore::Style::Scope::hasPendingSheet):
+        (WebCore::Style::Scope::hasPendingSheetInBody):
+        (WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet): Deleted.
+        * style/StyleScope.h:
+        (WebCore::Style::Scope::hasPendingSheet): Deleted.
+        (WebCore::Style::Scope::hasPendingSheets): Deleted.
+        * style/StyleTreeResolver.cpp:
+        (WebCore::Style::hasLoadingStylesheet):
+
+            Just test for body stylesheets.
+
+        (WebCore::Style::TreeResolver::resolve):
+
+            Treat all before-body stylesheets uniformly.
+
 2017-03-07  Antoine Quint  <[email protected]>
 
         [Modern Media Controls] Setting a valid source after an invalid one retains the invalid placard

Modified: trunk/Source/WebCore/style/StyleScope.cpp (213514 => 213515)


--- trunk/Source/WebCore/style/StyleScope.cpp	2017-03-07 16:23:30 UTC (rev 213514)
+++ trunk/Source/WebCore/style/StyleScope.cpp	2017-03-07 16:54:56 UTC (rev 213515)
@@ -32,6 +32,7 @@
 #include "Element.h"
 #include "ElementChildIterator.h"
 #include "ExtensionStyleSheets.h"
+#include "HTMLHeadElement.h"
 #include "HTMLIFrameElement.h"
 #include "HTMLLinkElement.h"
 #include "HTMLSlotElement.h"
@@ -72,7 +73,7 @@
 
 Scope::~Scope()
 {
-    ASSERT(m_nodesWithPendingSheets.isEmpty());
+    ASSERT(!hasPendingSheets());
 }
 
 bool Scope::shouldUseSharedUserAgentShadowTreeStyleResolver() const
@@ -172,20 +173,48 @@
     didChangeActiveStyleSheetCandidates();
 }
 
-void Scope::addPendingSheet(const Node& node)
+
+void Scope::addPendingSheet(const Element& element)
 {
-    ASSERT(!m_nodesWithPendingSheets.contains(&node));
+    ASSERT(!hasPendingSheet(element));
 
-    m_nodesWithPendingSheets.add(&node);
+    bool isInHead = ancestorsOfType<HTMLHeadElement>(element).first();
+    if (isInHead)
+        m_elementsInHeadWithPendingSheets.add(&element);
+    else
+        m_elementsInBodyWithPendingSheets.add(&element);
 }
 
 // This method is called whenever a top-level stylesheet has finished loading.
-void Scope::removePendingSheet(const Node& node)
+void Scope::removePendingSheet(const Element& element)
 {
-    ASSERT(m_nodesWithPendingSheets.contains(&node));
+    ASSERT(hasPendingSheet(element));
 
-    m_nodesWithPendingSheets.remove(&node);
-    if (!m_nodesWithPendingSheets.isEmpty())
+    if (!m_elementsInHeadWithPendingSheets.remove(&element))
+        m_elementsInBodyWithPendingSheets.remove(&element);
+
+    didRemovePendingStylesheet();
+}
+
+void Scope::addPendingSheet(const ProcessingInstruction& processingInstruction)
+{
+    ASSERT(!m_processingInstructionsWithPendingSheets.contains(&processingInstruction));
+
+    m_processingInstructionsWithPendingSheets.add(&processingInstruction);
+}
+
+void Scope::removePendingSheet(const ProcessingInstruction& processingInstruction)
+{
+    ASSERT(m_processingInstructionsWithPendingSheets.contains(&processingInstruction));
+
+    m_processingInstructionsWithPendingSheets.remove(&processingInstruction);
+
+    didRemovePendingStylesheet();
+}
+
+void Scope::didRemovePendingStylesheet()
+{
+    if (hasPendingSheets())
         return;
 
     didChangeActiveStyleSheetCandidates();
@@ -194,19 +223,14 @@
         m_document.didRemoveAllPendingStylesheet();
 }
 
-bool Scope::hasProcessingInstructionWithPendingSheet()
+bool Scope::hasPendingSheet(const Element& element) const
 {
-    ASSERT(!m_shadowRoot);
+    return m_elementsInHeadWithPendingSheets.contains(&element) || hasPendingSheetInBody(element);
+}
 
-    for (auto* child = m_document.firstChild(); child; child = child->nextSibling()) {
-        if (is<Element>(*child))
-            return false;
-        if (m_nodesWithPendingSheets.contains(child)) {
-            ASSERT(is<ProcessingInstruction>(*child));
-            return true;
-        }
-    }
-    return false;
+bool Scope::hasPendingSheetInBody(const Element& element) const
+{
+    return m_elementsInBodyWithPendingSheets.contains(&element);
 }
 
 void Scope::addStyleSheetCandidateNode(Node& node, bool createdByParser)

Modified: trunk/Source/WebCore/style/StyleScope.h (213514 => 213515)


--- trunk/Source/WebCore/style/StyleScope.h	2017-03-07 16:23:30 UTC (rev 213514)
+++ trunk/Source/WebCore/style/StyleScope.h	2017-03-07 16:54:56 UTC (rev 213515)
@@ -43,6 +43,7 @@
 class Document;
 class Element;
 class Node;
+class ProcessingInstruction;
 class StyleResolver;
 class StyleSheet;
 class StyleSheetContents;
@@ -82,11 +83,15 @@
     void setPreferredStylesheetSetName(const String&);
     void setSelectedStylesheetSetName(const String&);
 
-    void addPendingSheet(const Node&);
-    void removePendingSheet(const Node&);
-    bool hasPendingSheet(const Node& node) const { return m_nodesWithPendingSheets.contains(&node); }
-    bool hasProcessingInstructionWithPendingSheet();
-    bool hasPendingSheets() const { return !m_nodesWithPendingSheets.isEmpty(); }
+    void addPendingSheet(const Element&);
+    void removePendingSheet(const Element&);
+    void addPendingSheet(const ProcessingInstruction&);
+    void removePendingSheet(const ProcessingInstruction&);
+    bool hasPendingSheets() const;
+    bool hasPendingSheetsBeforeBody() const;
+    bool hasPendingSheetsInBody() const;
+    bool hasPendingSheet(const Element&) const;
+    bool hasPendingSheetInBody(const Element&) const;
 
     bool usesStyleBasedEditability() { return m_usesStyleBasedEditability; }
 
@@ -115,6 +120,8 @@
 private:
     bool shouldUseSharedUserAgentShadowTreeStyleResolver() const;
 
+    void didRemovePendingStylesheet();
+
     enum class UpdateType { ActiveSet, ContentsOrInterpretation };
     void updateActiveStyleSheets(UpdateType);
     void scheduleUpdate(UpdateType);
@@ -143,7 +150,6 @@
     Vector<RefPtr<StyleSheet>> m_styleSheetsForStyleSheetList;
     Vector<RefPtr<CSSStyleSheet>> m_activeStyleSheets;
 
-
     Timer m_pendingUpdateTimer;
 
     mutable std::unique_ptr<HashSet<const CSSStyleSheet*>> m_weakCopyOfActiveStyleSheetListForFastLookup;
@@ -152,7 +158,9 @@
     // Sheets loaded using the @import directive are not included in this count.
     // We use this count of pending sheets to detect when we can begin attaching
     // elements and when it is safe to execute scripts.
-    HashSet<const Node*> m_nodesWithPendingSheets;
+    HashSet<const ProcessingInstruction*> m_processingInstructionsWithPendingSheets;
+    HashSet<const Element*> m_elementsInHeadWithPendingSheets;
+    HashSet<const Element*> m_elementsInBodyWithPendingSheets;
 
     bool m_didUpdateActiveStyleSheets { false };
 
@@ -168,6 +176,21 @@
     bool m_isUpdatingStyleResolver { false };
 };
 
+inline bool Scope::hasPendingSheets() const
+{
+    return hasPendingSheetsBeforeBody() || !m_elementsInBodyWithPendingSheets.isEmpty();
+}
+
+inline bool Scope::hasPendingSheetsBeforeBody() const
+{
+    return !m_elementsInHeadWithPendingSheets.isEmpty() || !m_processingInstructionsWithPendingSheets.isEmpty();
+}
+
+inline bool Scope::hasPendingSheetsInBody() const
+{
+    return !m_elementsInBodyWithPendingSheets.isEmpty();
+}
+
 inline void Scope::flushPendingUpdate()
 {
     if (m_hasDescendantWithPendingUpdate)

Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (213514 => 213515)


--- trunk/Source/WebCore/style/StyleTreeResolver.cpp	2017-03-07 16:23:30 UTC (rev 213514)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp	2017-03-07 16:54:56 UTC (rev 213515)
@@ -361,14 +361,14 @@
 
 static bool hasLoadingStylesheet(const Style::Scope& styleScope, const Element& element, bool checkDescendants)
 {
-    if (!styleScope.hasPendingSheets())
+    if (!styleScope.hasPendingSheetsInBody())
         return false;
-    if (styleScope.hasPendingSheet(element))
+    if (styleScope.hasPendingSheetInBody(element))
         return true;
     if (!checkDescendants)
         return false;
     for (auto& descendant : descendantsOfType<Element>(element)) {
-        if (styleScope.hasPendingSheet(descendant))
+        if (styleScope.hasPendingSheetInBody(descendant))
             return true;
     };
     return false;
@@ -482,7 +482,7 @@
     if (!documentElement->childNeedsStyleRecalc() && !documentElement->needsStyleRecalc())
         return nullptr;
 
-    m_didSeePendingStylesheet = m_document.styleScope().hasProcessingInstructionWithPendingSheet();
+    m_didSeePendingStylesheet = m_document.styleScope().hasPendingSheetsBeforeBody();
 
     m_update = std::make_unique<Update>(m_document);
     m_scopeStack.append(adoptRef(*new Scope(m_document)));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to