Title: [131929] trunk/Source/WebCore
Revision
131929
Author
[email protected]
Date
2012-10-19 12:18:09 -0700 (Fri, 19 Oct 2012)

Log Message

Maintain a list of active CSS stylesheets
https://bugs.webkit.org/show_bug.cgi?id=99843

Reviewed by Andreas Kling.

Currently we maintain a per-document list of stylesheets that matches what is returned by the StyleSheetList DOM API. 
This list contains both CSS and XSLT stylesheets which internally have basically nothing in common. Maintaining 
a list of active CSS stylesheets separately simplifies code in number of places.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::addStylesheetsFromSeamlessParents):
(WebCore::StyleResolver::appendAuthorStyleSheets):
(WebCore::collectCSSOMWrappers):
* css/StyleResolver.h:
(StyleResolver):
* css/StyleSheetList.cpp:
(WebCore::StyleSheetList::styleSheets):
(WebCore::StyleSheetList::detachFromDocument):
* dom/Document.cpp:
(WebCore::Document::setCompatibilityMode):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):
(WebCore::styleSheetsUseRemUnits):
(WebCore::filterEnabledCSSStyleSheets):
(WebCore):
(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
(WebCore::DocumentStyleSheetCollection::reportMemoryUsage):
* dom/DocumentStyleSheetCollection.h:
(WebCore::DocumentStyleSheetCollection::styleSheetsForStyleSheetList):
(DocumentStyleSheetCollection):
(WebCore::DocumentStyleSheetCollection::activeAuthorStyleSheets):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (131928 => 131929)


--- trunk/Source/WebCore/ChangeLog	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/ChangeLog	2012-10-19 19:18:09 UTC (rev 131929)
@@ -1,3 +1,38 @@
+2012-10-19  Antti Koivisto  <[email protected]>
+
+        Maintain a list of active CSS stylesheets
+        https://bugs.webkit.org/show_bug.cgi?id=99843
+
+        Reviewed by Andreas Kling.
+
+        Currently we maintain a per-document list of stylesheets that matches what is returned by the StyleSheetList DOM API. 
+        This list contains both CSS and XSLT stylesheets which internally have basically nothing in common. Maintaining 
+        a list of active CSS stylesheets separately simplifies code in number of places.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::StyleResolver):
+        (WebCore::StyleResolver::addStylesheetsFromSeamlessParents):
+        (WebCore::StyleResolver::appendAuthorStyleSheets):
+        (WebCore::collectCSSOMWrappers):
+        * css/StyleResolver.h:
+        (StyleResolver):
+        * css/StyleSheetList.cpp:
+        (WebCore::StyleSheetList::styleSheets):
+        (WebCore::StyleSheetList::detachFromDocument):
+        * dom/Document.cpp:
+        (WebCore::Document::setCompatibilityMode):
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):
+        (WebCore::styleSheetsUseRemUnits):
+        (WebCore::filterEnabledCSSStyleSheets):
+        (WebCore):
+        (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
+        (WebCore::DocumentStyleSheetCollection::reportMemoryUsage):
+        * dom/DocumentStyleSheetCollection.h:
+        (WebCore::DocumentStyleSheetCollection::styleSheetsForStyleSheetList):
+        (DocumentStyleSheetCollection):
+        (WebCore::DocumentStyleSheetCollection::activeAuthorStyleSheets):
+
 2012-09-08  Alpha Lam  <[email protected]>
 
         [chromium] Implement deferred image decoding

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (131928 => 131929)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-10-19 19:18:09 UTC (rev 131929)
@@ -337,7 +337,7 @@
 #endif
 
     addStylesheetsFromSeamlessParents();
-    appendAuthorStylesheets(0, styleSheetCollection->authorStyleSheets());
+    appendAuthorStyleSheets(0, styleSheetCollection->activeAuthorStyleSheets());
 }
 
 void StyleResolver::addStylesheetsFromSeamlessParents()
@@ -345,14 +345,14 @@
     // Build a list of stylesheet lists from our ancestors, and walk that
     // list in reverse order so that the root-most sheets are appended first.
     Document* childDocument = document();
-    Vector<const Vector<RefPtr<StyleSheet> >* > ancestorSheets;
+    Vector<const Vector<RefPtr<CSSStyleSheet> >* > ancestorSheets;
     while (HTMLIFrameElement* parentIFrame = childDocument->seamlessParentIFrame()) {
         Document* parentDocument = parentIFrame->document();
-        ancestorSheets.append(&parentDocument->styleSheetCollection()->authorStyleSheets());
+        ancestorSheets.append(&parentDocument->styleSheetCollection()->activeAuthorStyleSheets());
         childDocument = parentDocument;
     }
     for (int i = ancestorSheets.size() - 1; i >= 0; i--)
-        appendAuthorStylesheets(0, *ancestorSheets[i]);
+        appendAuthorStyleSheets(0, *ancestorSheets[i]);
 }
 
 void StyleResolver::addAuthorRulesAndCollectUserRulesFromSheets(const Vector<RefPtr<CSSStyleSheet> >* userSheets, RuleSet& userStyle)
@@ -405,17 +405,14 @@
     m_authorStyle->disableAutoShrinkToFit();
 }
 
-void StyleResolver::appendAuthorStylesheets(unsigned firstNew, const Vector<RefPtr<StyleSheet> >& stylesheets)
+void StyleResolver::appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >& styleSheets)
 {
     // This handles sheets added to the end of the stylesheet list only. In other cases the style resolver
     // needs to be reconstructed. To handle insertions too the rule order numbers would need to be updated.
-    unsigned size = stylesheets.size();
+    unsigned size = styleSheets.size();
     for (unsigned i = firstNew; i < size; ++i) {
-        if (!stylesheets[i]->isCSSStyleSheet())
-            continue;
-        CSSStyleSheet* cssSheet = static_cast<CSSStyleSheet*>(stylesheets[i].get());
-        if (cssSheet->disabled())
-            continue;
+        CSSStyleSheet* cssSheet = styleSheets[i].get();
+        ASSERT(!cssSheet->disabled());
         if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries(), this))
             continue;
         StyleSheetContents* sheet = cssSheet->contents();
@@ -2608,13 +2605,10 @@
 
 static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, DocumentStyleSheetCollection* styleSheetCollection)
 {
-    const Vector<RefPtr<StyleSheet> >& styleSheets = styleSheetCollection->authorStyleSheets();
-    for (unsigned i = 0; i < styleSheets.size(); ++i) {
-        StyleSheet* styleSheet = styleSheets[i].get();
-        if (!styleSheet->isCSSStyleSheet())
-            continue;
-        collectCSSOMWrappers(wrapperMap, static_cast<CSSStyleSheet*>(styleSheet));
-    }
+    const Vector<RefPtr<CSSStyleSheet> >& styleSheets = styleSheetCollection->activeAuthorStyleSheets();
+    for (unsigned i = 0; i < styleSheets.size(); ++i)
+        collectCSSOMWrappers(wrapperMap, styleSheets[i].get());
+
     collectCSSOMWrappers(wrapperMap, styleSheetCollection->pageUserSheet());
     {
         const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets = styleSheetCollection->pageGroupUserSheets();

Modified: trunk/Source/WebCore/css/StyleResolver.h (131928 => 131929)


--- trunk/Source/WebCore/css/StyleResolver.h	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/css/StyleResolver.h	2012-10-19 19:18:09 UTC (rev 131929)
@@ -163,7 +163,7 @@
     bool hasParentNode() const { return m_parentNode; }
 
     void resetAuthorStyle();
-    void appendAuthorStylesheets(unsigned firstNew, const Vector<RefPtr<StyleSheet> >&);
+    void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >&);
     
     // Find the ids or classes the selectors on a stylesheet are scoped to. The selectors only apply to elements in subtrees where the root element matches the scope.
     static bool determineStylesheetSelectorScopes(StyleSheetContents*, HashSet<AtomicStringImpl*>& idScopes, HashSet<AtomicStringImpl*>& classScopes);

Modified: trunk/Source/WebCore/css/StyleSheetList.cpp (131928 => 131929)


--- trunk/Source/WebCore/css/StyleSheetList.cpp	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/css/StyleSheetList.cpp	2012-10-19 19:18:09 UTC (rev 131929)
@@ -45,12 +45,12 @@
 {
     if (!m_document)
         return m_detachedStyleSheets;
-    return m_document->styleSheetCollection()->authorStyleSheets();
+    return m_document->styleSheetCollection()->styleSheetsForStyleSheetList();
 }
 
 void StyleSheetList::detachFromDocument()
 {
-    m_detachedStyleSheets = m_document->styleSheetCollection()->authorStyleSheets();
+    m_detachedStyleSheets = m_document->styleSheetCollection()->styleSheetsForStyleSheetList();
     m_document = 0;
 }
 

Modified: trunk/Source/WebCore/dom/Document.cpp (131928 => 131929)


--- trunk/Source/WebCore/dom/Document.cpp	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-10-19 19:18:09 UTC (rev 131929)
@@ -797,7 +797,7 @@
 {
     if (m_compatibilityModeLocked || mode == m_compatibilityMode)
         return;
-    ASSERT(m_styleSheetCollection->authorStyleSheets().isEmpty());
+    ASSERT(m_styleSheetCollection->activeAuthorStyleSheets().isEmpty());
     bool wasInQuirksMode = inQuirksMode();
     m_compatibilityMode = mode;
     selectorQueryCache()->invalidate();

Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp (131928 => 131929)


--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp	2012-10-19 19:18:09 UTC (rev 131929)
@@ -374,7 +374,7 @@
     return false;
 }
 
-void DocumentStyleSheetCollection::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector<RefPtr<StyleSheet> >& newStylesheets, StyleResolverUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc)
+void DocumentStyleSheetCollection::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolverUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc)
 {
     styleResolverUpdateType = Reconstruct;
     requiresFullStyleRecalc = true;
@@ -398,15 +398,15 @@
         return;
 
     // Find out which stylesheets are new.
-    unsigned oldStylesheetCount = m_authorStyleSheets.size();
+    unsigned oldStylesheetCount = m_activeAuthorStyleSheets.size();
     if (newStylesheetCount < oldStylesheetCount)
         return;
-    Vector<StyleSheet*> addedSheets;
+    Vector<CSSStyleSheet*> addedSheets;
     unsigned newIndex = 0;
     for (unsigned oldIndex = 0; oldIndex < oldStylesheetCount; ++oldIndex) {
         if (newIndex >= newStylesheetCount)
             return;
-        while (m_authorStyleSheets[oldIndex] != newStylesheets[newIndex]) {
+        while (m_activeAuthorStyleSheets[oldIndex] != newStylesheets[newIndex]) {
             addedSheets.append(newStylesheets[newIndex].get());
             ++newIndex;
             if (newIndex == newStylesheetCount)
@@ -427,27 +427,32 @@
     if (!m_document->body() || m_document->hasNodesWithPlaceholderStyle())
         return;
     for (unsigned i = 0; i < addedSheets.size(); ++i) {
-        if (!addedSheets[i]->isCSSStyleSheet())
-            return;
-        if (addedSheets[i]->disabled())
-            continue;
         if (testAddedStyleSheetRequiresStyleRecalc(static_cast<CSSStyleSheet*>(addedSheets[i])->contents()))
             return;
     }
     requiresFullStyleRecalc = false;
 }
 
-static bool styleSheetsUseRemUnits(const Vector<RefPtr<StyleSheet> >& sheets)
+static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
 {
     for (unsigned i = 0; i < sheets.size(); ++i) {
-        if (!sheets[i]->isCSSStyleSheet())
-            continue;
-        if (static_cast<CSSStyleSheet*>(sheets[i].get())->contents()->usesRemUnits())
+        if (sheets[i]->contents()->usesRemUnits())
             return true;
     }
     return false;
 }
 
+static void filterEnabledCSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets)
+{
+    for (unsigned i = 0; i < sheets.size(); ++i) {
+        if (!sheets[i]->isCSSStyleSheet())
+            continue;
+        if (sheets[i]->disabled())
+            continue;
+        result.append(static_cast<CSSStyleSheet*>(sheets[i].get()));
+    }
+}
+
 bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag)
 {
     if (m_document->inStyleRecalc()) {
@@ -462,12 +467,15 @@
     if (!m_document->renderer() || !m_document->attached())
         return false;
 
-    Vector<RefPtr<StyleSheet> > newStylesheets;
-    collectActiveStyleSheets(newStylesheets);
+    Vector<RefPtr<StyleSheet> > activeStyleSheets;
+    collectActiveStyleSheets(activeStyleSheets);
 
+    Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
+    filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
+
     StyleResolverUpdateType styleResolverUpdateType;
     bool requiresFullStyleRecalc;
-    analyzeStyleSheetChange(updateFlag, newStylesheets, styleResolverUpdateType, requiresFullStyleRecalc);
+    analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
 
     if (styleResolverUpdateType == Reconstruct)
         m_document->clearStyleResolver();
@@ -475,16 +483,17 @@
         StyleResolver* styleResolver = m_document->styleResolver();
         if (styleResolverUpdateType == Reset) {
             styleResolver->resetAuthorStyle();
-            styleResolver->appendAuthorStylesheets(0, newStylesheets);
+            styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
         } else {
             ASSERT(styleResolverUpdateType == Additive);
-            styleResolver->appendAuthorStylesheets(m_authorStyleSheets.size(), newStylesheets);
+            styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), activeCSSStyleSheets);
         }
         resetCSSFeatureFlags();
     }
-    m_authorStyleSheets.swap(newStylesheets);
+    m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
+    m_styleSheetsForStyleSheetList.swap(activeStyleSheets);
 
-    m_usesRemUnits = styleSheetsUseRemUnits(m_authorStyleSheets);
+    m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
     m_needsUpdateActiveStylesheetsOnStyleRecalc = false;
 
     m_document->notifySeamlessChildDocumentsOfStylesheetUpdate();
@@ -498,7 +507,8 @@
     info.addMember(m_pageUserSheet);
     info.addMember(m_pageGroupUserSheets);
     info.addMember(m_userSheets);
-    info.addMember(m_authorStyleSheets);
+    info.addMember(m_activeAuthorStyleSheets);
+    info.addMember(m_styleSheetsForStyleSheetList);
     info.addListHashSet(m_styleSheetCandidateNodes);
     info.addMember(m_preferredStylesheetSetName);
     info.addMember(m_selectedStylesheetSetName);

Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h (131928 => 131929)


--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h	2012-10-19 19:06:59 UTC (rev 131928)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h	2012-10-19 19:18:09 UTC (rev 131929)
@@ -49,8 +49,10 @@
     DocumentStyleSheetCollection(Document*);
     ~DocumentStyleSheetCollection();
 
-    const Vector<RefPtr<StyleSheet> >& authorStyleSheets() { return m_authorStyleSheets; }
+    const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() { return m_styleSheetsForStyleSheetList; }
 
+    const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() { return m_activeAuthorStyleSheets; }
+
     CSSStyleSheet* pageUserSheet();
     const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
     const Vector<RefPtr<CSSStyleSheet> >* documentUserSheets() const { return m_userSheets.get(); }
@@ -107,11 +109,12 @@
         Reset,
         Additive
     };
-    void analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<StyleSheet> >& newStylesheets, StyleResolverUpdateType&, bool& requiresFullStyleRecalc);
+    void analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolverUpdateType&, bool& requiresFullStyleRecalc);
 
     Document* m_document;
 
-    Vector<RefPtr<StyleSheet> > m_authorStyleSheets;
+    Vector<RefPtr<StyleSheet> > m_styleSheetsForStyleSheetList;
+    Vector<RefPtr<CSSStyleSheet> > m_activeAuthorStyleSheets;
 
     // Track the number of currently loading top-level stylesheets needed for rendering.
     // Sheets loaded using the @import directive are not included in this count.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to