summaryrefslogtreecommitdiff
path: root/chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp217
1 files changed, 16 insertions, 201 deletions
diff --git a/chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp b/chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
index 5e24213368a..74ef2b1164a 100644
--- a/chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
+++ b/chromium/third_party/WebKit/Source/core/dom/DocumentStyleSheetCollection.cpp
@@ -37,8 +37,6 @@
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/ProcessingInstruction.h"
-#include "core/dom/ShadowTreeStyleSheetCollection.h"
-#include "core/dom/shadow/ShadowRoot.h"
#include "core/html/HTMLIFrameElement.h"
#include "core/html/HTMLLinkElement.h"
#include "core/html/HTMLStyleElement.h"
@@ -65,7 +63,6 @@ DocumentStyleSheetCollection::DocumentStyleSheetCollection(Document* document)
, m_usesBeforeAfterRulesOverride(false)
, m_usesRemUnits(false)
, m_collectionForDocument(document)
- , m_needsDocumentStyleSheetsUpdate(true)
{
}
@@ -83,55 +80,6 @@ DocumentStyleSheetCollection::~DocumentStyleSheetCollection()
m_authorStyleSheets[i]->clearOwnerNode();
}
-void DocumentStyleSheetCollection::insertTreeScopeInDocumentOrder(TreeScopeSet& treeScopes, TreeScope* treeScope)
-{
- if (treeScopes.isEmpty()) {
- treeScopes.add(treeScope);
- return;
- }
- if (treeScopes.contains(treeScope))
- return;
-
- TreeScopeSet::iterator begin = treeScopes.begin();
- TreeScopeSet::iterator end = treeScopes.end();
- TreeScopeSet::iterator it = end;
- TreeScope* followingTreeScope = 0;
- do {
- --it;
- TreeScope* n = *it;
- unsigned short position = n->comparePosition(treeScope);
- if (position & Node::DOCUMENT_POSITION_FOLLOWING) {
- treeScopes.insertBefore(followingTreeScope, treeScope);
- return;
- }
- followingTreeScope = n;
- } while (it != begin);
-
- treeScopes.insertBefore(followingTreeScope, treeScope);
-}
-
-StyleSheetCollection* DocumentStyleSheetCollection::ensureStyleSheetCollectionFor(TreeScope* treeScope)
-{
- if (treeScope == m_document)
- return &m_collectionForDocument;
-
- HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::AddResult result = m_styleSheetCollectionMap.add(treeScope, nullptr);
- if (result.isNewEntry)
- result.iterator->value = adoptPtr(new ShadowTreeStyleSheetCollection(toShadowRoot(treeScope)));
- return result.iterator->value.get();
-}
-
-StyleSheetCollection* DocumentStyleSheetCollection::styleSheetCollectionFor(TreeScope* treeScope)
-{
- if (treeScope == m_document)
- return &m_collectionForDocument;
-
- HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::iterator it = m_styleSheetCollectionMap.find(treeScope);
- if (it == m_styleSheetCollectionMap.end())
- return 0;
- return it->value.get();
-}
-
const Vector<RefPtr<StyleSheet> >& DocumentStyleSheetCollection::styleSheetsForStyleSheetList()
{
return m_collectionForDocument.styleSheetsForStyleSheetList();
@@ -142,19 +90,6 @@ const Vector<RefPtr<CSSStyleSheet> >& DocumentStyleSheetCollection::activeAuthor
return m_collectionForDocument.activeAuthorStyleSheets();
}
-void DocumentStyleSheetCollection::getActiveAuthorStyleSheets(Vector<const Vector<RefPtr<CSSStyleSheet> >*>& activeAuthorStyleSheets) const
-{
- activeAuthorStyleSheets.append(&m_collectionForDocument.activeAuthorStyleSheets());
-
- HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values begin = m_styleSheetCollectionMap.values().begin();
- HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values end = m_styleSheetCollectionMap.values().end();
- HashMap<TreeScope*, OwnPtr<StyleSheetCollection> >::const_iterator::Values it = begin;
- for (; it != end; ++it) {
- const StyleSheetCollection* collection = it->get();
- activeAuthorStyleSheets.append(&collection->activeAuthorStyleSheets());
- }
-}
-
void DocumentStyleSheetCollection::combineCSSFeatureFlags(const RuleFeatureSet& features)
{
// Delay resetting the flags until after next style recalc since unapplying the style may not work without these set (this is true at least with before/after).
@@ -253,7 +188,6 @@ void DocumentStyleSheetCollection::updateInjectedStyleSheetCache() const
void DocumentStyleSheetCollection::invalidateInjectedStyleSheetCache()
{
m_injectedStyleSheetCacheValid = false;
- m_needsDocumentStyleSheetsUpdate = true;
// FIXME: updateInjectedStyleSheetCache is called inside StyleSheetCollection::updateActiveStyleSheets
// and batch updates lots of sheets so we can't call addedStyleSheet() or removedStyleSheet().
m_document->styleResolverChanged(DeferRecalcStyle);
@@ -264,7 +198,6 @@ void DocumentStyleSheetCollection::addAuthorSheet(PassRefPtr<StyleSheetContents>
ASSERT(!authorSheet->isUserStyleSheet());
m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document));
m_document->addedStyleSheet(m_authorStyleSheets.last().get(), RecalcStyleImmediately);
- m_needsDocumentStyleSheetsUpdate = true;
}
void DocumentStyleSheetCollection::addUserSheet(PassRefPtr<StyleSheetContents> userSheet)
@@ -272,23 +205,16 @@ void DocumentStyleSheetCollection::addUserSheet(PassRefPtr<StyleSheetContents> u
ASSERT(userSheet->isUserStyleSheet());
m_userStyleSheets.append(CSSStyleSheet::create(userSheet, m_document));
m_document->addedStyleSheet(m_userStyleSheets.last().get(), RecalcStyleImmediately);
- m_needsDocumentStyleSheetsUpdate = true;
}
// This method is called whenever a top-level stylesheet has finished loading.
-void DocumentStyleSheetCollection::removePendingSheet(Node* styleSheetCandidateNode, RemovePendingSheetNotificationType notification)
+void DocumentStyleSheetCollection::removePendingSheet(RemovePendingSheetNotificationType notification)
{
// Make sure we knew this sheet was pending, and that our count isn't out of sync.
ASSERT(m_pendingStylesheets > 0);
m_pendingStylesheets--;
- TreeScope* treeScope = isHTMLStyleElement(styleSheetCandidateNode) ? styleSheetCandidateNode->treeScope() : m_document;
- if (treeScope == m_document)
- m_needsDocumentStyleSheetsUpdate = true;
- else
- m_dirtyTreeScopes.add(treeScope);
-
if (m_pendingStylesheets)
return;
@@ -304,59 +230,21 @@ void DocumentStyleSheetCollection::removePendingSheet(Node* styleSheetCandidateN
void DocumentStyleSheetCollection::addStyleSheetCandidateNode(Node* node, bool createdByParser)
{
- if (!node->inDocument())
- return;
-
- TreeScope* treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_document;
- ASSERT(isHTMLStyleElement(node) || treeScope == m_document);
-
- StyleSheetCollection* collection = ensureStyleSheetCollectionFor(treeScope);
- ASSERT(collection);
- collection->addStyleSheetCandidateNode(node, createdByParser);
-
- if (treeScope == m_document) {
- m_needsDocumentStyleSheetsUpdate = true;
- return;
- }
-
- insertTreeScopeInDocumentOrder(m_activeTreeScopes, treeScope);
- m_dirtyTreeScopes.add(treeScope);
+ m_collectionForDocument.addStyleSheetCandidateNode(node, createdByParser);
}
void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopingNode)
{
- TreeScope* treeScope = scopingNode ? scopingNode->treeScope() : m_document;
- ASSERT(isHTMLStyleElement(node) || treeScope == m_document);
-
- StyleSheetCollection* collection = styleSheetCollectionFor(treeScope);
- ASSERT(collection);
- collection->removeStyleSheetCandidateNode(node, scopingNode);
-
- if (treeScope == m_document) {
- m_needsDocumentStyleSheetsUpdate = true;
- return;
- }
- m_dirtyTreeScopes.add(treeScope);
- m_activeTreeScopes.remove(treeScope);
+ m_collectionForDocument.removeStyleSheetCandidateNode(node, scopingNode);
}
-void DocumentStyleSheetCollection::modifiedStyleSheetCandidateNode(Node* node)
+static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
{
- if (!node->inDocument())
- return;
-
- TreeScope* treeScope = isHTMLStyleElement(node) ? node->treeScope() : m_document;
- ASSERT(isHTMLStyleElement(node) || treeScope == m_document);
- if (treeScope == m_document) {
- m_needsDocumentStyleSheetsUpdate = true;
- return;
+ for (unsigned i = 0; i < sheets.size(); ++i) {
+ if (sheets[i]->contents()->usesRemUnits())
+ return true;
}
- m_dirtyTreeScopes.add(treeScope);
-}
-
-bool DocumentStyleSheetCollection::shouldUpdateShadowTreeStyleSheetCollection(StyleResolverUpdateMode updateMode)
-{
- return !m_dirtyTreeScopes.isEmpty() || updateMode == FullStyleUpdate;
+ return false;
}
bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMode updateMode)
@@ -372,91 +260,18 @@ bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMo
if (!m_document->renderer() || !m_document->attached())
return false;
- bool requiresFullStyleRecalc = false;
- if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate)
- requiresFullStyleRecalc = m_collectionForDocument.updateActiveStyleSheets(this, updateMode);
-
- if (shouldUpdateShadowTreeStyleSheetCollection(updateMode)) {
- TreeScopeSet treeScopes = updateMode == FullStyleUpdate ? m_activeTreeScopes : m_dirtyTreeScopes;
- HashSet<TreeScope*> treeScopesRemoved;
-
- for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end(); ++it) {
- TreeScope* treeScope = *it;
- ASSERT(treeScope != m_document);
- ShadowTreeStyleSheetCollection* collection = static_cast<ShadowTreeStyleSheetCollection*>(styleSheetCollectionFor(treeScope));
- ASSERT(collection);
- collection->updateActiveStyleSheets(this, updateMode);
- if (!collection->hasStyleSheetCandidateNodes())
- treeScopesRemoved.add(treeScope);
- }
- if (!treeScopesRemoved.isEmpty())
- for (HashSet<TreeScope*>::iterator it = treeScopesRemoved.begin(); it != treeScopesRemoved.end(); ++it)
- m_activeTreeScopes.remove(*it);
- m_dirtyTreeScopes.clear();
- }
-
- if (StyleResolver* styleResolver = m_document->styleResolverIfExists()) {
- styleResolver->finishAppendAuthorStyleSheets();
- resetCSSFeatureFlags(styleResolver->ruleFeatureSet());
- }
-
+ StyleSheetCollection::StyleResolverUpdateType styleResolverUpdateType;
+ bool requiresFullStyleRecalc = m_collectionForDocument.updateActiveStyleSheets(this, updateMode, styleResolverUpdateType);
m_needsUpdateActiveStylesheetsOnStyleRecalc = false;
- activeStyleSheetsUpdatedForInspector();
- m_usesRemUnits = m_collectionForDocument.usesRemUnits();
-
- if (m_needsDocumentStyleSheetsUpdate || updateMode == FullStyleUpdate) {
- m_document->notifySeamlessChildDocumentsOfStylesheetUpdate();
- m_needsDocumentStyleSheetsUpdate = false;
- }
-
- return requiresFullStyleRecalc;
-}
-
-void DocumentStyleSheetCollection::activeStyleSheetsUpdatedForInspector()
-{
- if (m_activeTreeScopes.isEmpty()) {
- InspectorInstrumentation::activeStyleSheetsUpdated(m_document, m_collectionForDocument.styleSheetsForStyleSheetList());
- return;
- }
- Vector<RefPtr<StyleSheet> > activeStyleSheets;
- activeStyleSheets.append(m_collectionForDocument.styleSheetsForStyleSheetList());
+ if (styleResolverUpdateType != StyleSheetCollection::Reconstruct)
+ resetCSSFeatureFlags(m_document->styleResolver()->ruleFeatureSet());
- TreeScopeSet::iterator begin = m_activeTreeScopes.begin();
- TreeScopeSet::iterator end = m_activeTreeScopes.end();
- for (TreeScopeSet::iterator it = begin; it != end; ++it) {
- if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it))
- activeStyleSheets.append(collection->styleSheetsForStyleSheetList());
- }
+ InspectorInstrumentation::activeStyleSheetsUpdated(m_document, m_collectionForDocument.styleSheetsForStyleSheetList());
+ m_usesRemUnits = styleSheetsUseRemUnits(m_collectionForDocument.activeAuthorStyleSheets());
+ m_document->notifySeamlessChildDocumentsOfStylesheetUpdate();
- // FIXME: Inspector needs a vector which has all active stylesheets.
- // However, creating such a large vector might cause performance regression.
- // Need to implement some smarter solution.
- InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSheets);
-}
-
-void DocumentStyleSheetCollection::didRemoveShadowRoot(ShadowRoot* shadowRoot)
-{
- m_styleSheetCollectionMap.remove(shadowRoot);
-}
-
-void DocumentStyleSheetCollection::appendActiveAuthorStyleSheets(StyleResolver* styleResolver)
-{
- ASSERT(styleResolver);
-
- styleResolver->setBuildScopedStyleTreeInDocumentOrder(true);
- styleResolver->appendAuthorStyleSheets(0, m_collectionForDocument.activeAuthorStyleSheets());
-
- TreeScopeSet::iterator begin = m_activeTreeScopes.begin();
- TreeScopeSet::iterator end = m_activeTreeScopes.end();
- for (TreeScopeSet::iterator it = begin; it != end; ++it) {
- if (StyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it)) {
- styleResolver->setBuildScopedStyleTreeInDocumentOrder(!collection->scopingNodesForStyleScoped());
- styleResolver->appendAuthorStyleSheets(0, collection->activeAuthorStyleSheets());
- }
- }
- styleResolver->finishAppendAuthorStyleSheets();
- styleResolver->setBuildScopedStyleTreeInDocumentOrder(false);
+ return requiresFullStyleRecalc;
}
}