Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / StyleEngine.cpp
index 901bed5..1e9ff7b 100644 (file)
@@ -47,7 +47,7 @@
 #include "core/frame/Settings.h"
 #include "platform/URLPatternMatcher.h"
 
-namespace WebCore {
+namespace blink {
 
 using namespace HTMLNames;
 
@@ -56,11 +56,7 @@ StyleEngine::StyleEngine(Document& document)
     , m_isMaster(!document.importsController() || document.importsController()->master() == &document)
     , m_pendingStylesheets(0)
     , m_injectedStyleSheetCacheValid(false)
-#if ENABLE(OILPAN)
-    , m_documentStyleSheetCollection(new DocumentStyleSheetCollection(document))
-#else
-    , m_documentStyleSheetCollection(document)
-#endif
+    , m_documentStyleSheetCollection(DocumentStyleSheetCollection::create(document))
     , m_documentScopeDirty(true)
     , m_usesSiblingRules(false)
     , m_usesSiblingRulesOverride(false)
@@ -103,6 +99,9 @@ void StyleEngine::detachFromDocument()
     m_fontSelector.clear();
     m_resolver.clear();
     m_styleSheetCollectionMap.clear();
+    for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++it)
+        const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver();
+    m_scopedStyleResolvers.clear();
 }
 #endif
 
@@ -323,7 +322,7 @@ void StyleEngine::addXSLStyleSheet(ProcessingInstruction* node, bool createdByPa
     if (createdByParser || !m_xslStyleSheet) {
         needToUpdate = !m_xslStyleSheet;
     } else {
-        unsigned position = m_xslStyleSheet->compareDocumentPositionInternal(node, Node::TreatShadowTreesAsDisconnected);
+        unsigned position = m_xslStyleSheet->compareDocumentPosition(node, Node::TreatShadowTreesAsDisconnected);
         needToUpdate = position & Node::DOCUMENT_POSITION_FOLLOWING;
     }
 
@@ -455,6 +454,8 @@ const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> > StyleEngine::activeSt
 
 void StyleEngine::didRemoveShadowRoot(ShadowRoot* shadowRoot)
 {
+    if (shadowRoot->scopedStyleResolver())
+        removeScopedStyleResolver(shadowRoot->scopedStyleResolver());
     m_styleSheetCollectionMap.remove(shadowRoot);
 }
 
@@ -462,19 +463,15 @@ void StyleEngine::appendActiveAuthorStyleSheets()
 {
     ASSERT(isMaster());
 
-    m_resolver->setBuildScopedStyleTreeInDocumentOrder(true);
     m_resolver->appendAuthorStyleSheets(documentStyleSheetCollection()->activeAuthorStyleSheets());
 
     TreeScopeSet::iterator begin = m_activeTreeScopes.begin();
     TreeScopeSet::iterator end = m_activeTreeScopes.end();
     for (TreeScopeSet::iterator it = begin; it != end; ++it) {
-        if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it)) {
-            m_resolver->setBuildScopedStyleTreeInDocumentOrder(!collection->scopingNodesForStyleScoped());
+        if (TreeScopeStyleSheetCollection* collection = m_styleSheetCollectionMap.get(*it))
             m_resolver->appendAuthorStyleSheets(collection->activeAuthorStyleSheets());
-        }
     }
     m_resolver->finishAppendAuthorStyleSheets();
-    m_resolver->setBuildScopedStyleTreeInDocumentOrder(false);
 }
 
 void StyleEngine::createResolver()
@@ -486,6 +483,8 @@ void StyleEngine::createResolver()
     ASSERT(document().frame());
 
     m_resolver = adoptPtrWillBeNoop(new StyleResolver(*m_document));
+    addScopedStyleResolver(&m_document->ensureScopedStyleResolver());
+
     appendActiveAuthorStyleSheets();
     combineCSSFeatureFlags(m_resolver->ensureUpdatedRuleFeatureSet());
 }
@@ -494,6 +493,11 @@ void StyleEngine::clearResolver()
 {
     ASSERT(!document().inStyleRecalc());
     ASSERT(isMaster() || !m_resolver);
+
+    for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++it)
+        const_cast<TreeScope&>((*it)->treeScope()).clearScopedStyleResolver();
+    m_scopedStyleResolvers.clear();
+
     if (m_resolver)
         document().updateStyleInvalidationIfNeeded();
     m_resolver.clear();
@@ -557,9 +561,8 @@ void StyleEngine::resolverChanged(StyleResolverUpdateMode mode)
 
 void StyleEngine::clearFontCache()
 {
-    // We should not recreate FontSelector. Instead, clear fontFaceCache.
     if (m_fontSelector)
-        m_fontSelector->fontFaceCache()->clear();
+        m_fontSelector->fontFaceCache()->clearCSSConnected();
     if (m_resolver)
         m_resolver->invalidateMatchedPropertiesCache();
 }
@@ -673,6 +676,13 @@ void StyleEngine::removeSheet(StyleSheetContents* contents)
     m_sheetToTextCache.remove(contents);
 }
 
+void StyleEngine::collectScopedStyleFeaturesTo(RuleFeatureSet& features) const
+{
+    HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents;
+    for (ScopedStyleResolverSet::iterator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++it)
+        (*it)->collectFeaturesTo(features, visitedSharedStyleSheetContents);
+}
+
 void StyleEngine::fontsNeedUpdate(CSSFontSelector*)
 {
     if (!document().isActive())
@@ -685,16 +695,19 @@ void StyleEngine::fontsNeedUpdate(CSSFontSelector*)
 
 void StyleEngine::trace(Visitor* visitor)
 {
+#if ENABLE(OILPAN)
     visitor->trace(m_document);
     visitor->trace(m_injectedAuthorStyleSheets);
     visitor->trace(m_authorStyleSheets);
     visitor->trace(m_documentStyleSheetCollection);
     visitor->trace(m_styleSheetCollectionMap);
+    visitor->trace(m_scopedStyleResolvers);
     visitor->trace(m_resolver);
     visitor->trace(m_fontSelector);
     visitor->trace(m_textToSheetCache);
     visitor->trace(m_sheetToTextCache);
     visitor->trace(m_xslStyleSheet);
+#endif
     CSSFontSelectorClient::trace(visitor);
 }