Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(905)

Unified Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 201363002: DevTools: defer styles delta calculation to until the end of the task. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
index ae9418a15a0a7335583068b20701750f93e56d5c..b1ebd8d036fecfc652ef6f11e7e0e6f37ab772c8 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -435,7 +435,8 @@ void InspectorCSSAgent::reset()
{
m_idToInspectorStyleSheet.clear();
m_cssStyleSheetToInspectorStyleSheet.clear();
- m_frameToCSSStyleSheets.clear();
+ m_documentToCSSStyleSheets.clear();
+ m_invalidatedDocuments.clear();
m_nodeToInspectorStyleSheet.clear();
m_documentToViaInspectorStyleSheet.clear();
resetNonPersistentData();
@@ -490,10 +491,8 @@ void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback)
m_instrumentingAgents->setInspectorCSSAgent(this);
Vector<Document*> documents = m_domAgent->documents();
- for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) {
- Document* document = *it;
- updateActiveStyleSheetsForDocument(document, InitialFrontendLoad);
- }
+ for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it)
+ updateActiveStyleSheets(*it, InitialFrontendLoad);
if (callback)
callback->sendSuccess();
@@ -512,13 +511,17 @@ void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader)
return;
}
- updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
+ for (DocumentStyleSheets::iterator it = m_documentToCSSStyleSheets.begin(); it != m_documentToCSSStyleSheets.end(); ++it) {
+ Document* document = it->key;
+ if (!document->frame() || document->frame() == frame)
+ documentDisposed(document);
+ }
}
void InspectorCSSAgent::mediaQueryResultChanged()
{
- if (m_frontend)
- m_frontend->mediaQueryResultChanged();
+ validateFrontendStylesheets();
+ m_frontend->mediaQueryResultChanged();
}
void InspectorCSSAgent::willMutateRules()
@@ -555,36 +558,40 @@ void InspectorCSSAgent::didMutateStyle(CSSStyleDeclaration* style, bool isInline
}
}
+void InspectorCSSAgent::didProcessTask()
+{
+ validateFrontendStylesheets();
+}
+
void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document)
{
if (styleSheetEditInProgress())
return;
- updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh);
+ m_invalidatedDocuments.add(document);
+ if (m_creatingViaInspectorStyleSheet)
+ validateFrontendStylesheets();
}
-void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, StyleSheetsUpdateType styleSheetsUpdateType)
+void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsUpdateType styleSheetsUpdateType)
{
- LocalFrame* frame = document->frame();
- if (!frame)
- return;
Vector<CSSStyleSheet*> newSheetsVector;
collectAllDocumentStyleSheets(document, newSheetsVector);
- updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType);
+ setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType);
}
-void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType)
+void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType)
{
bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad;
- HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(frame);
- if (!frameCSSStyleSheets) {
- frameCSSStyleSheets = new HashSet<CSSStyleSheet*>();
- OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frameCSSStyleSheets);
- m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release());
+ HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets.get(document);
+ if (!documentCSSStyleSheets) {
+ documentCSSStyleSheets = new HashSet<CSSStyleSheet*>();
+ OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(documentCSSStyleSheets);
+ m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.release());
}
HashSet<CSSStyleSheet*> removedSheets;
- for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it != frameCSSStyleSheets->end(); ++it)
+ for (HashSet<CSSStyleSheet*>::iterator it = documentCSSStyleSheets->begin(); it != documentCSSStyleSheets->end(); ++it)
removedSheets.add(*it);
HashSet<CSSStyleSheet*> addedSheets;
@@ -606,7 +613,7 @@ void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<
if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) {
String id = unbindStyleSheet(inspectorStyleSheet.get());
- frameCSSStyleSheets->remove(cssStyleSheet);
+ documentCSSStyleSheets->remove(cssStyleSheet);
if (m_frontend && !isInitialFrontendLoad)
m_frontend->styleSheetRemoved(id);
}
@@ -617,19 +624,35 @@ void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector<
bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSheet.contains(cssStyleSheet);
if (isNew) {
InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet);
- frameCSSStyleSheets->add(cssStyleSheet);
+ documentCSSStyleSheets->add(cssStyleSheet);
if (m_frontend)
m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSheetInfo());
}
}
- if (frameCSSStyleSheets->isEmpty())
- m_frameToCSSStyleSheets.remove(frame);
+ if (documentCSSStyleSheets->isEmpty())
+ m_documentToCSSStyleSheets.remove(document);
+}
+
+void InspectorCSSAgent::validateFrontendStylesheets()
+{
+ if (!m_invalidatedDocuments.size())
+ return;
+ HashSet<Document*> invalidatedDocuments;
+ m_invalidatedDocuments.swap(&invalidatedDocuments);
+ for (HashSet<Document*>::iterator it = invalidatedDocuments.begin(); it != invalidatedDocuments.end(); ++it)
+ updateActiveStyleSheets(*it, ExistingFrontendRefresh);
+}
+
+void InspectorCSSAgent::documentDisposed(Document* document)
+{
+ m_invalidatedDocuments.remove(document);
+ setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
}
void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame)
{
- updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRefresh);
+ documentDisposed(frame->document());
}
bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoType pseudoType)
@@ -892,6 +915,8 @@ void InspectorCSSAgent::createStyleSheet(ErrorString* errorString, const String&
return;
}
+ updateActiveStyleSheets(document, ExistingFrontendRefresh);
+
*outStyleSheetId = inspectorStyleSheet->id();
}
@@ -1312,8 +1337,8 @@ void InspectorCSSAgent::didModifyDOMAttr(Element* element)
void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet)
{
- if (m_frontend)
- m_frontend->styleSheetChanged(styleSheet->id());
+ validateFrontendStylesheets();
+ m_frontend->styleSheetChanged(styleSheet->id());
}
void InspectorCSSAgent::willReparseStyleSheet()

Powered by Google App Engine
This is Rietveld 408576698