Title: [135271] trunk/Source/WebCore
Revision
135271
Author
an...@apple.com
Date
2012-11-20 03:36:58 -0800 (Tue, 20 Nov 2012)

Log Message

Collect user style sheets in DocumentStyleSheetCollection
https://bugs.webkit.org/show_bug.cgi?id=102683

Reviewed by Andreas Kling.

Move the user stylesheet collection logic from StyleResolver to DocumentStyleSheetCollection.
        
* css/StyleResolver.cpp:
(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::collectRulesFromUserStyleSheets):
(WebCore::collectCSSOMWrappers):
* css/StyleResolver.h:
(StyleResolver):
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::~DocumentStyleSheetCollection):
(WebCore::DocumentStyleSheetCollection::pageUserStyleSheet):
(WebCore::DocumentStyleSheetCollection::clearPageUserStyleSheet):
(WebCore::DocumentStyleSheetCollection::updatePageUserStyleSheet):
(WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):
(WebCore::collectActiveStyleSheetsFromSeamlessParents):
(WebCore::DocumentStyleSheetCollection::updateStyleResolver):
        
    Factor the StyleResolver updating code to function.

(WebCore):
(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
        
    Collect the user style sheets. Some renaming and other minor refactoring.

(WebCore::DocumentStyleSheetCollection::reportMemoryUsage):
* dom/DocumentStyleSheetCollection.h:
(WebCore::DocumentStyleSheetCollection::activeUserStyleSheets):
        
    Add activeUserStyleSheets vector that contains all user stylesheets from different sources,
    similar to activeAuthorStyleSheets.

(DocumentStyleSheetCollection):
(WebCore::DocumentStyleSheetCollection::documentUserStyleSheets):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135270 => 135271)


--- trunk/Source/WebCore/ChangeLog	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/ChangeLog	2012-11-20 11:36:58 UTC (rev 135271)
@@ -1,3 +1,44 @@
+2012-11-19  Antti Koivisto  <an...@apple.com>
+
+        Collect user style sheets in DocumentStyleSheetCollection
+        https://bugs.webkit.org/show_bug.cgi?id=102683
+
+        Reviewed by Andreas Kling.
+
+        Move the user stylesheet collection logic from StyleResolver to DocumentStyleSheetCollection.
+        
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::StyleResolver):
+        (WebCore::StyleResolver::collectRulesFromUserStyleSheets):
+        (WebCore::collectCSSOMWrappers):
+        * css/StyleResolver.h:
+        (StyleResolver):
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::~DocumentStyleSheetCollection):
+        (WebCore::DocumentStyleSheetCollection::pageUserStyleSheet):
+        (WebCore::DocumentStyleSheetCollection::clearPageUserStyleSheet):
+        (WebCore::DocumentStyleSheetCollection::updatePageUserStyleSheet):
+        (WebCore::DocumentStyleSheetCollection::analyzeStyleSheetChange):
+        (WebCore::collectActiveStyleSheetsFromSeamlessParents):
+        (WebCore::DocumentStyleSheetCollection::updateStyleResolver):
+        
+            Factor the StyleResolver updating code to function.
+
+        (WebCore):
+        (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
+        
+            Collect the user style sheets. Some renaming and other minor refactoring.
+
+        (WebCore::DocumentStyleSheetCollection::reportMemoryUsage):
+        * dom/DocumentStyleSheetCollection.h:
+        (WebCore::DocumentStyleSheetCollection::activeUserStyleSheets):
+        
+            Add activeUserStyleSheets vector that contains all user stylesheets from different sources,
+            similar to activeAuthorStyleSheets.
+
+        (DocumentStyleSheetCollection):
+        (WebCore::DocumentStyleSheetCollection::documentUserStyleSheets):
+
 2012-11-20  Elliott Sprehn  <espr...@chromium.org>
 
         Remove unneeded optimization in Element::isInTopLayer

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (135270 => 135271)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-11-20 11:36:58 UTC (rev 135271)
@@ -297,17 +297,8 @@
             loadFullDefaultStyle();
     }
 
-    // construct document root element default style. this is needed
-    // to evaluate media queries that contain relative constraints, like "screen and (max-width: 10em)"
-    // This is here instead of constructor, because when constructor is run,
-    // document doesn't have documentElement
-    // NOTE: this assumes that element that gets passed to styleForElement -call
-    // is always from the document that owns the style selector
     FrameView* view = document->view();
-    if (view)
-        m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType()));
-    else
-        m_medium = adoptPtr(new MediaQueryEvaluator("all"));
+    m_medium = adoptPtr(new MediaQueryEvaluator(view ? view->mediaType() : "all"));
 
     if (root)
         m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, MatchOnlyUserAgentRules);
@@ -317,15 +308,6 @@
 
     resetAuthorStyle();
 
-    DocumentStyleSheetCollection* styleSheetCollection = document->styleSheetCollection();
-    OwnPtr<RuleSet> tempUserStyle = RuleSet::create();
-    if (CSSStyleSheet* pageUserSheet = styleSheetCollection->pageUserSheet())
-        tempUserStyle->addRulesFromSheet(pageUserSheet->contents(), *m_medium, this);
-    collectRulesFromUserStyleSheets(styleSheetCollection->injectedUserStyleSheets(), *tempUserStyle);
-    collectRulesFromUserStyleSheets(styleSheetCollection->documentUserStyleSheets(), *tempUserStyle);
-    if (tempUserStyle->m_ruleCount > 0 || tempUserStyle->m_pageRules.size() > 0)
-        m_userStyle = tempUserStyle.release();
-
 #if ENABLE(SVG_FONTS)
     if (document->svgExtensions()) {
         const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document->svgExtensions()->svgFontFaceElements();
@@ -335,15 +317,20 @@
     }
 #endif
 
+    DocumentStyleSheetCollection* styleSheetCollection = document->styleSheetCollection();
+    collectRulesFromUserStyleSheets(styleSheetCollection->activeUserStyleSheets());
     appendAuthorStyleSheets(0, styleSheetCollection->activeAuthorStyleSheets());
 }
 
-void StyleResolver::collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& userSheets, RuleSet& userStyle)
+void StyleResolver::collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& userSheets)
 {
+    OwnPtr<RuleSet> userStyleRuleSet = RuleSet::create();
     for (unsigned i = 0; i < userSheets.size(); ++i) {
         ASSERT(userSheets[i]->contents()->isUserStyleSheet());
-        userStyle.addRulesFromSheet(userSheets[i]->contents(), *m_medium, this);
+        userStyleRuleSet->addRulesFromSheet(userSheets[i]->contents(), *m_medium, this);
     }
+    if (userStyleRuleSet->m_ruleCount > 0 || userStyleRuleSet->m_pageRules.size() > 0)
+        m_userStyle = userStyleRuleSet.release();
 }
 
 static PassOwnPtr<RuleSet> makeRuleSet(const Vector<RuleFeature>& rules)
@@ -2605,9 +2592,7 @@
 static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, DocumentStyleSheetCollection* styleSheetCollection)
 {
     collectCSSOMWrappers(wrapperMap, styleSheetCollection->activeAuthorStyleSheets());
-    collectCSSOMWrappers(wrapperMap, styleSheetCollection->pageUserSheet());
-    collectCSSOMWrappers(wrapperMap, styleSheetCollection->injectedUserStyleSheets());
-    collectCSSOMWrappers(wrapperMap, styleSheetCollection->documentUserStyleSheets());
+    collectCSSOMWrappers(wrapperMap, styleSheetCollection->activeUserStyleSheets());
 }
 
 CSSStyleRule* StyleResolver::ensureFullCSSOMWrapperForInspector(StyleRule* rule)

Modified: trunk/Source/WebCore/css/StyleResolver.h (135270 => 135271)


--- trunk/Source/WebCore/css/StyleResolver.h	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/css/StyleResolver.h	2012-11-20 11:36:58 UTC (rev 135271)
@@ -426,7 +426,7 @@
 private:
     static RenderStyle* s_styleNotYetAvailable;
 
-    void collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&, RuleSet& userStyle);
+    void collectRulesFromUserStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
 
     void cacheBorderAndBackground();
 

Modified: trunk/Source/WebCore/dom/Document.cpp (135270 => 135271)


--- trunk/Source/WebCore/dom/Document.cpp	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-11-20 11:36:58 UTC (rev 135271)
@@ -795,7 +795,7 @@
     selectorQueryCache()->invalidate();
     if (inQuirksMode() != wasInQuirksMode) {
         // All user stylesheets have to reparse using the different mode.
-        m_styleSheetCollection->clearPageUserSheet();
+        m_styleSheetCollection->clearPageUserStyleSheet();
         m_styleSheetCollection->invalidateInjectedStyleSheetCache();
     }
 }

Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp (135270 => 135271)


--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp	2012-11-20 11:36:58 UTC (rev 135271)
@@ -73,8 +73,8 @@
 
 DocumentStyleSheetCollection::~DocumentStyleSheetCollection()
 {
-    if (m_pageUserSheet)
-        m_pageUserSheet->clearOwnerNode();
+    if (m_pageUserStyleSheet)
+        m_pageUserStyleSheet->clearOwnerNode();
     for (unsigned i = 0; i < m_injectedUserStyleSheets.size(); ++i)
         m_injectedUserStyleSheets[i]->clearOwnerNode();
     for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i)
@@ -100,10 +100,10 @@
     m_usesBeforeAfterRules = styleResolver->usesBeforeAfterRules();
 }
 
-CSSStyleSheet* DocumentStyleSheetCollection::pageUserSheet()
+CSSStyleSheet* DocumentStyleSheetCollection::pageUserStyleSheet()
 {
-    if (m_pageUserSheet)
-        return m_pageUserSheet.get();
+    if (m_pageUserStyleSheet)
+        return m_pageUserStyleSheet.get();
     
     Page* owningPage = m_document->page();
     if (!owningPage)
@@ -114,24 +114,24 @@
         return 0;
     
     // Parse the sheet and cache it.
-    m_pageUserSheet = CSSStyleSheet::createInline(m_document, m_document->settings()->userStyleSheetLocation());
-    m_pageUserSheet->contents()->setIsUserStyleSheet(true);
-    m_pageUserSheet->contents()->parseString(userSheetText);
-    return m_pageUserSheet.get();
+    m_pageUserStyleSheet = CSSStyleSheet::createInline(m_document, m_document->settings()->userStyleSheetLocation());
+    m_pageUserStyleSheet->contents()->setIsUserStyleSheet(true);
+    m_pageUserStyleSheet->contents()->parseString(userSheetText);
+    return m_pageUserStyleSheet.get();
 }
 
-void DocumentStyleSheetCollection::clearPageUserSheet()
+void DocumentStyleSheetCollection::clearPageUserStyleSheet()
 {
-    if (m_pageUserSheet) {
-        m_pageUserSheet = 0;
-        m_document->styleResolverChanged(DeferRecalcStyle);
-    }
+    if (!m_pageUserStyleSheet)
+        return;
+    m_pageUserStyleSheet = 0;
+    m_document->styleResolverChanged(DeferRecalcStyle);
 }
 
-void DocumentStyleSheetCollection::updatePageUserSheet()
+void DocumentStyleSheetCollection::updatePageUserStyleSheet()
 {
-    clearPageUserSheet();
-    if (pageUserSheet())
+    clearPageUserStyleSheet();
+    if (pageUserStyleSheet())
         m_document->styleResolverChanged(RecalcStyleImmediately);
 }
 
@@ -428,7 +428,7 @@
     }
 }
 
-static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyleSheet> >& sheets, Document* document)
+static void collectActiveStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyleSheet> >& sheets, Document* document)
 {
     HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame();
     if (!seamlessParentIFrame)
@@ -436,6 +436,25 @@
     sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->activeAuthorStyleSheets());
 }
 
+void DocumentStyleSheetCollection::updateStyleResolver(StyleResolverUpdateType updateType, const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets)
+{
+    if (updateType == Reconstruct) {
+        m_document->clearStyleResolver();
+        return;
+    }
+    StyleResolver* styleResolver = m_document->styleResolver();
+    unsigned firstNewIndex;
+    if (updateType == Reset) {
+        styleResolver->resetAuthorStyle();
+        firstNewIndex = 0;
+    } else {
+        ASSERT(updateType == Additive);
+        firstNewIndex = m_activeAuthorStyleSheets.size();
+    }
+    styleResolver->appendAuthorStyleSheets(firstNewIndex, activeAuthorStyleSheets);
+    resetCSSFeatureFlags();
+}
+
 bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag)
 {
     if (m_document->inStyleRecalc()) {
@@ -450,33 +469,32 @@
     if (!m_document->renderer() || !m_document->attached())
         return false;
 
-    Vector<RefPtr<StyleSheet> > activeStyleSheets;
-    collectActiveStyleSheets(activeStyleSheets);
+    Vector<RefPtr<StyleSheet> > documentAuthorStyleSheets;
+    collectActiveStyleSheets(documentAuthorStyleSheets);
 
-    Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
-    activeCSSStyleSheets.append(injectedAuthorStyleSheets());
-    collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_document);
-    filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
+    Vector<RefPtr<CSSStyleSheet> > activeAuthorStyleSheets;
+    activeAuthorStyleSheets.append(injectedAuthorStyleSheets());
+    collectActiveStyleSheetsFromSeamlessParents(activeAuthorStyleSheets, m_document);
+    filterEnabledCSSStyleSheets(activeAuthorStyleSheets, documentAuthorStyleSheets);
 
+    Vector<RefPtr<CSSStyleSheet> > activeUserStyleSheets;
+    if (CSSStyleSheet* sheet = pageUserStyleSheet())
+        activeUserStyleSheets.append(sheet);
+    activeUserStyleSheets.append(injectedUserStyleSheets());
+    activeUserStyleSheets.append(documentUserStyleSheets());
+
+    if (activeUserStyleSheets != m_activeUserStyleSheets)
+        updateFlag = FullUpdate;
+
     StyleResolverUpdateType styleResolverUpdateType;
     bool requiresFullStyleRecalc;
-    analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
+    analyzeStyleSheetChange(updateFlag, activeAuthorStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
 
-    if (styleResolverUpdateType == Reconstruct)
-        m_document->clearStyleResolver();
-    else {
-        StyleResolver* styleResolver = m_document->styleResolver();
-        if (styleResolverUpdateType == Reset) {
-            styleResolver->resetAuthorStyle();
-            styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
-        } else {
-            ASSERT(styleResolverUpdateType == Additive);
-            styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), activeCSSStyleSheets);
-        }
-        resetCSSFeatureFlags();
-    }
-    m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
-    m_styleSheetsForStyleSheetList.swap(activeStyleSheets);
+    updateStyleResolver(styleResolverUpdateType, activeAuthorStyleSheets);
+    
+    m_activeAuthorStyleSheets.swap(activeAuthorStyleSheets);
+    m_activeUserStyleSheets.swap(activeUserStyleSheets);
+    m_styleSheetsForStyleSheetList.swap(documentAuthorStyleSheets);
 
     m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
     m_needsUpdateActiveStylesheetsOnStyleRecalc = false;
@@ -489,11 +507,12 @@
 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
-    info.addMember(m_pageUserSheet);
+    info.addMember(m_pageUserStyleSheet);
     info.addMember(m_injectedUserStyleSheets);
     info.addMember(m_injectedAuthorStyleSheets);
     info.addMember(m_userStyleSheets);
     info.addMember(m_activeAuthorStyleSheets);
+    info.addMember(m_activeUserStyleSheets);
     info.addMember(m_styleSheetsForStyleSheetList);
     info.addMember(m_styleSheetCandidateNodes);
     info.addMember(m_preferredStylesheetSetName);

Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h (135270 => 135271)


--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h	2012-11-20 11:36:58 UTC (rev 135271)
@@ -53,17 +53,13 @@
     const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() const { return m_styleSheetsForStyleSheetList; }
 
     const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() const { return m_activeAuthorStyleSheets; }
+    const Vector<RefPtr<CSSStyleSheet> >& activeUserStyleSheets() const { return m_activeUserStyleSheets; }
 
-    CSSStyleSheet* pageUserSheet();
-    const Vector<RefPtr<CSSStyleSheet> >& documentUserStyleSheets() const { return m_userStyleSheets; }
-    const Vector<RefPtr<CSSStyleSheet> >& injectedUserStyleSheets() const;
-    const Vector<RefPtr<CSSStyleSheet> >& injectedAuthorStyleSheets() const;
-
     void addStyleSheetCandidateNode(Node*, bool createdByParser);
     void removeStyleSheetCandidateNode(Node*);
 
-    void clearPageUserSheet();
-    void updatePageUserSheet();
+    void clearPageUserStyleSheet();
+    void updatePageUserStyleSheet();
     void invalidateInjectedStyleSheetCache();
     void updateInjectedStyleSheetCache() const;
 
@@ -113,11 +109,18 @@
         Additive
     };
     void analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolverUpdateType&, bool& requiresFullStyleRecalc);
+    void updateStyleResolver(StyleResolverUpdateType, const Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets);
 
+    CSSStyleSheet* pageUserStyleSheet();
+    const Vector<RefPtr<CSSStyleSheet> >& documentUserStyleSheets() const { return m_userStyleSheets; }
+    const Vector<RefPtr<CSSStyleSheet> >& injectedUserStyleSheets() const;
+    const Vector<RefPtr<CSSStyleSheet> >& injectedAuthorStyleSheets() const;
+
     Document* m_document;
 
     Vector<RefPtr<StyleSheet> > m_styleSheetsForStyleSheetList;
     Vector<RefPtr<CSSStyleSheet> > m_activeAuthorStyleSheets;
+    Vector<RefPtr<CSSStyleSheet> > m_activeUserStyleSheets;
 
     // Track the number of currently loading top-level stylesheets needed for rendering.
     // Sheets loaded using the @import directive are not included in this count.
@@ -125,7 +128,7 @@
     // elements and when it is safe to execute scripts.
     int m_pendingStylesheets;
 
-    RefPtr<CSSStyleSheet> m_pageUserSheet;
+    RefPtr<CSSStyleSheet> m_pageUserStyleSheet;
 
     mutable Vector<RefPtr<CSSStyleSheet> > m_injectedUserStyleSheets;
     mutable Vector<RefPtr<CSSStyleSheet> > m_injectedAuthorStyleSheets;

Modified: trunk/Source/WebCore/page/Page.cpp (135270 => 135271)


--- trunk/Source/WebCore/page/Page.cpp	2012-11-20 11:24:15 UTC (rev 135270)
+++ trunk/Source/WebCore/page/Page.cpp	2012-11-20 11:36:58 UTC (rev 135271)
@@ -852,7 +852,7 @@
 
     for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
         if (frame->document())
-            frame->document()->styleSheetCollection()->updatePageUserSheet();
+            frame->document()->styleSheetCollection()->updatePageUserStyleSheet();
     }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to