#include "config.h"
#include "core/dom/ShadowTreeStyleSheetCollection.h"
-#include "HTMLNames.h"
+#include "core/HTMLNames.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/resolver/StyleResolver.h"
-#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/StyleEngine.h"
+#include "core/dom/StyleSheetCandidate.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/html/HTMLStyleElement.h"
-#include "core/page/Settings.h"
-namespace WebCore {
+namespace blink {
using namespace HTMLNames;
ShadowTreeStyleSheetCollection::ShadowTreeStyleSheetCollection(ShadowRoot& shadowRoot)
- : StyleSheetCollection(shadowRoot)
+ : TreeScopeStyleSheetCollection(shadowRoot)
{
}
-void ShadowTreeStyleSheetCollection::collectStyleSheets(StyleEngine* collections, Vector<RefPtr<StyleSheet> >& styleSheets, Vector<RefPtr<CSSStyleSheet> >& activeSheets)
+void ShadowTreeStyleSheetCollection::collectStyleSheets(StyleEngine* engine, StyleSheetCollection& collection)
{
- if (document()->settings() && !document()->settings()->authorAndUserStylesEnabled())
- return;
+ for (Node* n : m_styleSheetCandidateNodes) {
+ StyleSheetCandidate candidate(*n);
+ ASSERT(!candidate.isXSL());
- DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin();
- DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end();
- for (DocumentOrderedList::iterator it = begin; it != end; ++it) {
- Node* node = *it;
- StyleSheet* sheet = 0;
- CSSStyleSheet* activeSheet = 0;
-
- if (!node->isHTMLElement() || !node->hasTagName(styleTag))
+ if (!candidate.isCSSStyle())
continue;
- Element* element = toElement(node);
- AtomicString title = element->getAttribute(titleAttr);
- bool enabledViaScript = false;
-
- sheet = toHTMLStyleElement(node)->sheet();
- if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
- activeSheet = static_cast<CSSStyleSheet*>(sheet);
+ StyleSheet* sheet = candidate.sheet();
+ if (!sheet)
+ continue;
// FIXME: clarify how PREFERRED or ALTERNATE works in shadow trees.
// Should we set preferred/selected stylesheets name in shadow trees and
// use the name in document?
- AtomicString rel = element->getAttribute(relAttr);
- if (!enabledViaScript && sheet && !title.isEmpty()) {
- if (collections->preferredStylesheetSetName().isEmpty()) {
- if (element->hasLocalName(styleTag) || !rel.contains("alternate")) {
- collections->setPreferredStylesheetSetName(title);
- collections->setSelectedStylesheetSetName(title);
- }
- }
- if (title != collections->preferredStylesheetSetName())
- activeSheet = 0;
- }
+ if (candidate.hasPreferrableName(engine->preferredStylesheetSetName()))
+ engine->selectStylesheetSetName(candidate.title());
- if (rel.contains("alternate") && title.isEmpty())
- activeSheet = 0;
-
- if (sheet)
- styleSheets.append(sheet);
- if (activeSheet)
- activeSheets.append(activeSheet);
+ collection.appendSheetForList(sheet);
+ if (candidate.canBeActivated(engine->preferredStylesheetSetName()))
+ collection.appendActiveStyleSheet(toCSSStyleSheet(sheet));
}
}
-bool ShadowTreeStyleSheetCollection::updateActiveStyleSheets(StyleEngine* collections, StyleResolverUpdateMode updateMode)
+void ShadowTreeStyleSheetCollection::updateActiveStyleSheets(StyleEngine* engine, StyleResolverUpdateMode updateMode)
{
- Vector<RefPtr<StyleSheet> > styleSheets;
- Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
- collectStyleSheets(collections, styleSheets, activeCSSStyleSheets);
-
- bool requiresFullStyleRecalc = true;
+ StyleSheetCollection collection;
+ collectStyleSheets(engine, collection);
- StyleResolverUpdateType styleResolverUpdateType;
- analyzeStyleSheetChange(updateMode, activeAuthorStyleSheets(), activeCSSStyleSheets, styleResolverUpdateType, requiresFullStyleRecalc);
+ StyleSheetChange change;
+ analyzeStyleSheetChange(updateMode, collection, change);
- if (StyleResolver* styleResolver = document()->styleResolverIfExists()) {
- // FIXME: We might have already had styles in child treescope. In this case, we cannot use buildScopedStyleTreeInDocumentOrder.
- // Need to change "false" to some valid condition.
- styleResolver->setBuildScopedStyleTreeInDocumentOrder(false);
- if (styleResolverUpdateType == Reset || styleResolverUpdateType == Reconstruct) {
+ if (StyleResolver* styleResolver = engine->resolver()) {
+ if (change.styleResolverUpdateType != Additive) {
// We should not destroy StyleResolver when we find any stylesheet update in a shadow tree.
// In this case, we will reset rulesets created from style elements in the shadow tree.
- resetAllRuleSetsInTreeScope(styleResolver);
- styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
+ styleResolver->resetAuthorStyle(treeScope());
+ styleResolver->removePendingAuthorStyleSheets(m_activeAuthorStyleSheets);
+ styleResolver->lazyAppendAuthorStyleSheets(0, collection.activeAuthorStyleSheets());
} else {
- ASSERT(styleResolverUpdateType == Additive);
- styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), activeCSSStyleSheets);
+ styleResolver->lazyAppendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), collection.activeAuthorStyleSheets());
}
}
- if (requiresFullStyleRecalc)
- toShadowRoot(m_treeScope.rootNode())->host()->setNeedsStyleRecalc();
+ if (change.requiresFullStyleRecalc)
+ toShadowRoot(treeScope().rootNode()).host()->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::ActiveStylesheetsUpdate));
- m_scopingNodesForStyleScoped.didRemoveScopingNodes();
- m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
- m_styleSheetsForStyleSheetList.swap(styleSheets);
+ collection.swap(*this);
updateUsesRemUnits();
-
- return requiresFullStyleRecalc;
}
}