Remove tracking of pending sheets.

I was going to remove all this anyway since we don't need it in sky, all sheets
are local and there's no concept of a pending sheet now.

I also removed the dirty bit I added to StyleSheetCollection. The bit
is not correct and is preventing us from correctly processing sheets and
invalidating style. I'll add it back later when I understand how to add
the dirty bit correctly.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/846183002
This commit is contained in:
Elliott Sprehn 2015-01-12 18:15:23 -08:00
parent f97bad962e
commit 7fd0df2238
10 changed files with 44 additions and 131 deletions

View File

@ -131,19 +131,6 @@ StyleResolver::StyleResolver(Document& document)
}
}
void StyleResolver::lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >& styleSheets)
{
unsigned size = styleSheets.size();
for (unsigned i = firstNew; i < size; ++i)
m_pendingStyleSheets.add(styleSheets[i].get());
}
void StyleResolver::removePendingAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& 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<RawPtr<CSSStyleSheet>, 16>::iterator it = m_pendingStyleSheets.begin(); it != m_pendingStyleSheets.end(); ++it)
appendCSSStyleSheet(*it);
m_pendingStyleSheets.clear();
finishAppendAuthorStyleSheets();
}
void StyleResolver::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet> >& 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<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
{
ASSERT(document().frame());
ASSERT(document().settings());
ASSERT(!hasPendingAuthorStyleSheets());
didAccess();
@ -356,7 +318,6 @@ PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* element, const
{
ASSERT(document().frame());
ASSERT(document().settings());
ASSERT(!hasPendingAuthorStyleSheets());
if (element == document().documentElement())
document().setDirectionSetOnDocumentElement(false);

View File

@ -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<RefPtr<CSSStyleSheet> >&);
void finishAppendAuthorStyleSheets();
void lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >&);
void removePendingAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&);
void appendPendingAuthorStyleSheets();
bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size() > 0; }
void styleTreeResolveScopedKeyframesRules(const Element*, Vector<RawPtr<ScopedStyleResolver>, 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<Document> m_document;
ListHashSet<RawPtr<CSSStyleSheet>, 16> m_pendingStyleSheets;
bool m_printMediaType;
StyleResourceLoader m_styleResourceLoader;

View File

@ -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)

View File

@ -528,7 +528,6 @@ public:
void didLoadAllParserBlockingResources();
void didRemoveAllPendingStylesheet();
void clearStyleResolver();
bool inStyleRecalc() const { return m_lifecycle.state() == DocumentLifecycle::InStyleRecalc; }

View File

@ -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<CSSStyleSheet> 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);
}

View File

@ -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<Document> m_document;

View File

@ -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<RefPtr<CSSStyleSheet>>& sheets)
@ -70,15 +67,10 @@ void StyleSheetCollection::collectStyleSheets(Vector<RefPtr<CSSStyleSheet>>& she
void StyleSheetCollection::updateActiveStyleSheets(StyleResolver& resolver)
{
if (!m_needsUpdate)
return;
Vector<RefPtr<CSSStyleSheet>> 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<CSSStyleSheet>& sheet : m_activeAuthorStyleSheets)
resolver.appendCSSStyleSheet(sheet.get());
}
}

View File

@ -68,8 +68,6 @@ private:
TreeScope& m_treeScope;
DocumentOrderedList m_styleSheetCandidateNodes;
Vector<RefPtr<CSSStyleSheet>> m_activeAuthorStyleSheets;
bool m_needsUpdate;
};
}

View File

@ -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!"

14
tests/lowlevel/home.sky Normal file
View File

@ -0,0 +1,14 @@
<div>
<style>
.h1 { font-size: 2em; margin: 1em; }
.p { margin: 0.5em 1em; color: #bcd8f5; font-weight: 900; }
</style>
<div class="h1">about:blank</div>
<div class="p">Welcome to Sky!</div>
<script>
// Don't use dump-as-render-tree.sky, we want a test with no imports.
window.addEventListener('load', function() {
internals.notifyTestComplete(internals.renderTreeAsText());
});
</script>
</div>