diff --git a/engine/core/css/resolver/StyleResolver.cpp b/engine/core/css/resolver/StyleResolver.cpp index 8cfc226f4cb..0372b347fd2 100644 --- a/engine/core/css/resolver/StyleResolver.cpp +++ b/engine/core/css/resolver/StyleResolver.cpp @@ -131,19 +131,6 @@ StyleResolver::StyleResolver(Document& document) } } -void StyleResolver::lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector >& styleSheets) -{ - unsigned size = styleSheets.size(); - for (unsigned i = firstNew; i < size; ++i) - m_pendingStyleSheets.add(styleSheets[i].get()); -} - -void StyleResolver::removePendingAuthorStyleSheets(const Vector >& styleSheets) -{ - for (unsigned i = 0; i < styleSheets.size(); ++i) - m_pendingStyleSheets.remove(styleSheets[i].get()); -} - void StyleResolver::appendCSSStyleSheet(CSSStyleSheet* cssSheet) { ASSERT(cssSheet); @@ -177,30 +164,6 @@ void StyleResolver::appendCSSStyleSheet(CSSStyleSheet* cssSheet) } } -void StyleResolver::appendPendingAuthorStyleSheets() -{ - for (ListHashSet, 16>::iterator it = m_pendingStyleSheets.begin(); it != m_pendingStyleSheets.end(); ++it) - appendCSSStyleSheet(*it); - - m_pendingStyleSheets.clear(); - finishAppendAuthorStyleSheets(); -} - -void StyleResolver::appendAuthorStyleSheets(const Vector >& 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(); - for (unsigned i = 0; i < size; ++i) - appendCSSStyleSheet(styleSheets[i].get()); -} - -void StyleResolver::finishAppendAuthorStyleSheets() -{ - if (document().renderView() && document().renderView()->style()) - document().renderView()->style()->font().update(document().styleEngine()->fontSelector()); -} - void StyleResolver::addToStyleSharingList(Element& element) { // Never add elements to the style sharing list if we're not in a recalcStyle, @@ -291,7 +254,6 @@ PassRefPtr StyleResolver::styleForElement(Element* element, RenderS { ASSERT(document().frame()); ASSERT(document().settings()); - ASSERT(!hasPendingAuthorStyleSheets()); didAccess(); @@ -356,7 +318,6 @@ PassRefPtr StyleResolver::styleForKeyframe(Element* element, const { ASSERT(document().frame()); ASSERT(document().settings()); - ASSERT(!hasPendingAuthorStyleSheets()); if (element == document().documentElement()) document().setDirectionSetOnDocumentElement(false); diff --git a/engine/core/css/resolver/StyleResolver.h b/engine/core/css/resolver/StyleResolver.h index ec98262eecb..2ebd0b2a744 100644 --- a/engine/core/css/resolver/StyleResolver.h +++ b/engine/core/css/resolver/StyleResolver.h @@ -100,16 +100,6 @@ public: // their dependency on Document* instead of grabbing one through StyleResolver. Document& document() { return *m_document; } - // FIXME: It could be better to call appendAuthorStyleSheets() directly after we factor StyleResolver further. - // https://bugs.webkit.org/show_bug.cgi?id=108890 - void appendAuthorStyleSheets(const Vector >&); - void finishAppendAuthorStyleSheets(); - - void lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector >&); - void removePendingAuthorStyleSheets(const Vector >&); - void appendPendingAuthorStyleSheets(); - bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size() > 0; } - void styleTreeResolveScopedKeyframesRules(const Element*, Vector, 8>&); // |properties| is an array with |count| elements. @@ -120,6 +110,8 @@ public: // FIXME: Rename to reflect the purpose, like didChangeFontSize or something. void invalidateMatchedPropertiesCache(); + void appendCSSStyleSheet(CSSStyleSheet*); + void notifyResizeForViewportUnits(); StyleSharingList& styleSharingList() { return m_styleSharingList; } @@ -143,8 +135,6 @@ private: void loadPendingResources(StyleResolverState&); - void appendCSSStyleSheet(CSSStyleSheet*); - void matchAuthorRules(Element*, ElementRuleCollector&); void matchAllRules(StyleResolverState&, ElementRuleCollector&); void matchUARules(ElementRuleCollector&); @@ -178,8 +168,6 @@ private: RawPtr m_document; - ListHashSet, 16> m_pendingStyleSheets; - bool m_printMediaType; StyleResourceLoader m_styleResourceLoader; diff --git a/engine/core/dom/Document.cpp b/engine/core/dom/Document.cpp index f2d6ac805db..7d9068547ac 100644 --- a/engine/core/dom/Document.cpp +++ b/engine/core/dom/Document.cpp @@ -1104,10 +1104,7 @@ void Document::updateStyle(StyleRecalcChange change) clearChildNeedsStyleRecalc(); - if (m_styleEngine->hasResolver()) { - StyleResolver& resolver = m_styleEngine->ensureResolver(); - resolver.clearStyleSharingList(); - } + m_styleEngine->resolver().clearStyleSharingList(); ASSERT(!needsStyleRecalc()); ASSERT(!childNeedsStyleRecalc()); @@ -1175,18 +1172,13 @@ StyleResolver* Document::styleResolver() const { if (!isActive()) return 0; - return m_styleEngine->resolver(); + return &m_styleEngine->resolver(); } StyleResolver& Document::ensureStyleResolver() const { ASSERT(isActive()); - return m_styleEngine->ensureResolver(); -} - -void Document::clearStyleResolver() -{ - m_styleEngine->clearResolver(); + return m_styleEngine->resolver(); } void Document::attach(const AttachContext& context) diff --git a/engine/core/dom/Document.h b/engine/core/dom/Document.h index d02dc770210..cb45790ccfc 100644 --- a/engine/core/dom/Document.h +++ b/engine/core/dom/Document.h @@ -528,7 +528,6 @@ public: void didLoadAllParserBlockingResources(); void didRemoveAllPendingStylesheet(); - void clearStyleResolver(); bool inStyleRecalc() const { return m_lifecycle.state() == DocumentLifecycle::InStyleRecalc; } diff --git a/engine/core/dom/StyleEngine.cpp b/engine/core/dom/StyleEngine.cpp index 18d33911636..20c7a0471f1 100644 --- a/engine/core/dom/StyleEngine.cpp +++ b/engine/core/dom/StyleEngine.cpp @@ -41,11 +41,13 @@ #include "sky/engine/core/html/HTMLStyleElement.h" #include "sky/engine/core/html/imports/HTMLImportsController.h" #include "sky/engine/core/page/Page.h" +#include "sky/engine/core/rendering/RenderView.h" namespace blink { StyleEngine::StyleEngine(Document& document) : m_document(&document) + , m_resolver(adoptPtr(new StyleResolver(*m_document))) , m_fontSelector(CSSFontSelector::create(&document)) { m_fontSelector->registerForInvalidationCallbacks(this); @@ -75,53 +77,26 @@ void StyleEngine::updateActiveStyleSheets() for (TreeScope* treeScope : m_activeTreeScopes) treeScope->styleSheets().updateActiveStyleSheets(*m_resolver); -} -void StyleEngine::appendActiveAuthorStyleSheets() -{ - for (TreeScope* treeScope : m_activeTreeScopes) - m_resolver->appendAuthorStyleSheets(treeScope->styleSheets().activeAuthorStyleSheets()); - - m_resolver->finishAppendAuthorStyleSheets(); -} - -void StyleEngine::createResolver() -{ - // It is a programming error to attempt to resolve style on a Document - // which is not in a frame. Code which hits this should have checked - // Document::isActive() before calling into code which could get here. - - ASSERT(m_document->frame()); - - m_resolver = adoptPtr(new StyleResolver(*m_document)); - - appendActiveAuthorStyleSheets(); -} - -void StyleEngine::clearResolver() -{ - ASSERT(!m_document->inStyleRecalc()); - m_resolver.clear(); + m_document->renderView()->style()->font().update(fontSelector()); } unsigned StyleEngine::resolverAccessCount() const { - return m_resolver ? m_resolver->accessCount() : 0; + return m_resolver->accessCount(); } void StyleEngine::resolverChanged() { if (!m_document->isActive()) return; - if (m_resolver) - updateActiveStyleSheets(); + updateActiveStyleSheets(); } void StyleEngine::clearFontCache() { m_fontSelector->fontFaceCache()->clearCSSConnected(); - if (m_resolver) - m_resolver->invalidateMatchedPropertiesCache(); + m_resolver->invalidateMatchedPropertiesCache(); } void StyleEngine::updateGenericFontFamilySettings() @@ -131,8 +106,7 @@ void StyleEngine::updateGenericFontFamilySettings() ASSERT(m_document->isActive()); m_fontSelector->updateGenericFontFamilySettings(*m_document); - if (m_resolver) - m_resolver->invalidateMatchedPropertiesCache(); + m_resolver->invalidateMatchedPropertiesCache(); } PassRefPtr StyleEngine::createSheet(Element* e, const String& text) @@ -170,8 +144,7 @@ void StyleEngine::removeSheet(StyleSheetContents* contents) void StyleEngine::fontsNeedUpdate(CSSFontSelector*) { - if (m_resolver) - m_resolver->invalidateMatchedPropertiesCache(); + m_resolver->invalidateMatchedPropertiesCache(); m_document->setNeedsStyleRecalc(SubtreeStyleChange); } diff --git a/engine/core/dom/StyleEngine.h b/engine/core/dom/StyleEngine.h index ed17f6fe89f..dedc91eb742 100644 --- a/engine/core/dom/StyleEngine.h +++ b/engine/core/dom/StyleEngine.h @@ -62,25 +62,7 @@ public: // FIXME(sky): Remove this and ::first-line. bool usesFirstLineRules() const { return false; } - void appendActiveAuthorStyleSheets(); - - StyleResolver* resolver() const - { - return m_resolver.get(); - } - - StyleResolver& ensureResolver() - { - if (!m_resolver) { - createResolver(); - } else if (m_resolver->hasPendingAuthorStyleSheets()) { - m_resolver->appendPendingAuthorStyleSheets(); - } - return *m_resolver.get(); - } - - bool hasResolver() const { return m_resolver.get(); } - void clearResolver(); + StyleResolver& resolver() { return *m_resolver; } CSSFontSelector* fontSelector() { return m_fontSelector.get(); } void clearFontCache(); @@ -101,7 +83,6 @@ private: explicit StyleEngine(Document&); void updateActiveStyleSheets(); - void createResolver(); RawPtr m_document; diff --git a/engine/core/dom/StyleSheetCollection.cpp b/engine/core/dom/StyleSheetCollection.cpp index 937b28fc668..383f17d2d5e 100644 --- a/engine/core/dom/StyleSheetCollection.cpp +++ b/engine/core/dom/StyleSheetCollection.cpp @@ -38,7 +38,6 @@ namespace blink { StyleSheetCollection::StyleSheetCollection(TreeScope& treeScope) : m_treeScope(treeScope) - , m_needsUpdate(true) { } @@ -50,13 +49,11 @@ void StyleSheetCollection::addStyleSheetCandidateNode(HTMLStyleElement& element) { ASSERT(element.inActiveDocument()); m_styleSheetCandidateNodes.add(&element); - m_needsUpdate = true; } void StyleSheetCollection::removeStyleSheetCandidateNode(HTMLStyleElement& element) { m_styleSheetCandidateNodes.remove(&element); - m_needsUpdate = true; } void StyleSheetCollection::collectStyleSheets(Vector>& sheets) @@ -70,15 +67,10 @@ void StyleSheetCollection::collectStyleSheets(Vector>& she void StyleSheetCollection::updateActiveStyleSheets(StyleResolver& resolver) { - if (!m_needsUpdate) - return; - Vector> candidateSheets; collectStyleSheets(candidateSheets); m_treeScope.scopedStyleResolver().resetAuthorStyle(); - resolver.removePendingAuthorStyleSheets(m_activeAuthorStyleSheets); - resolver.lazyAppendAuthorStyleSheets(0, candidateSheets); Node& root = m_treeScope.rootNode(); @@ -92,7 +84,9 @@ void StyleSheetCollection::updateActiveStyleSheets(StyleResolver& resolver) toShadowRoot(root).host()->setNeedsStyleRecalc(SubtreeStyleChange); m_activeAuthorStyleSheets.swap(candidateSheets); - m_needsUpdate = false; + + for (RefPtr& sheet : m_activeAuthorStyleSheets) + resolver.appendCSSStyleSheet(sheet.get()); } } diff --git a/engine/core/dom/StyleSheetCollection.h b/engine/core/dom/StyleSheetCollection.h index 7a10f95ae7d..65caed54dfa 100644 --- a/engine/core/dom/StyleSheetCollection.h +++ b/engine/core/dom/StyleSheetCollection.h @@ -68,8 +68,6 @@ private: TreeScope& m_treeScope; DocumentOrderedList m_styleSheetCandidateNodes; Vector> m_activeAuthorStyleSheets; - - bool m_needsUpdate; }; } diff --git a/tests/lowlevel/home-expected.txt b/tests/lowlevel/home-expected.txt new file mode 100644 index 00000000000..d5f7a8a0c4c --- /dev/null +++ b/tests/lowlevel/home-expected.txt @@ -0,0 +1,13 @@ +layer at (0,0) size 800x600 + RenderView {#document} at (0,0) size 800x600 +layer at (0,0) size 800x137 + RenderBlock {div} at (0,0) size 800x137 + RenderBlock {div} at (32,32) size 736x38 + RenderParagraph (anonymous) at (0,0) size 736x38 + RenderText {#text} at (0,0) size 191x38 + text run at (0,0) width 191: "about:blank" + RenderBlock {div} at (16,110) size 768x19 [color=#BCD8F5] + RenderParagraph (anonymous) at (0,0) size 768x19 + RenderText {#text} at (0,0) size 152x19 + text run at (0,0) width 152: "Welcome to Sky!" + diff --git a/tests/lowlevel/home.sky b/tests/lowlevel/home.sky new file mode 100644 index 00000000000..381d43caa48 --- /dev/null +++ b/tests/lowlevel/home.sky @@ -0,0 +1,14 @@ +
+ +
about:blank
+
Welcome to Sky!
+ +
\ No newline at end of file