Diff
Modified: trunk/Source/WebCore/ChangeLog (206360 => 206361)
--- trunk/Source/WebCore/ChangeLog 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/ChangeLog 2016-09-25 13:32:24 UTC (rev 206361)
@@ -1,3 +1,100 @@
+2016-09-25 Antti Koivisto <[email protected]>
+
+ AuthorStyleSheets shouldn't trigger synchronous style resolutions
+ https://bugs.webkit.org/show_bug.cgi?id=162532
+
+ Reviewed by Darin Adler.
+
+ AuthorStyleSheets::didChange() took four different enum values, two of which triggered
+ a synchronous style resolution. This is almost always unnecessary as any subsequent
+ call that requires up-to-date style or layout will perform it. In the few cases where
+ it is actually needed the client can just do it manually.
+
+ The patch also replaces the remaining two enum values with functions:
+
+ void didChangeCandidatesForActiveSet();
+ void didChangeContentsOrInterpretation();
+
+ The first indicates that the set of active stylesheets might have changed and needs to be recomputed.
+ The seconds one indicates that either the content of some stylesheet has changed or that the environment
+ where we interpret the sheets has somehow changed.
+
+ The existing "AsNeeded" values map to didChangeCandidatesForActiveSet() and the rest map to
+ didChangeContentsOrInterpretation(). This also makes it obvious that some call sites use the wrong value.
+ The patch doesn't address these cases.
+
+ * css/CSSStyleSheet.cpp:
+ (WebCore::CSSStyleSheet::didMutateRules):
+ (WebCore::CSSStyleSheet::didMutate):
+ (WebCore::CSSStyleSheet::clearOwnerNode):
+ * dom/AuthorStyleSheets.cpp:
+ (WebCore::AuthorStyleSheets::AuthorStyleSheets):
+ (WebCore::AuthorStyleSheets::analyzeStyleSheetChange):
+ (WebCore::AuthorStyleSheets::updateActiveStyleSheets):
+ (WebCore::AuthorStyleSheets::flushPendingChanges):
+ (WebCore::AuthorStyleSheets::scheduleActiveSetChange):
+ (WebCore::AuthorStyleSheets::didChange):
+ (WebCore::AuthorStyleSheets::pendingChangeTimerFired):
+ (WebCore::AuthorStyleSheets::flushPendingUpdates): Deleted.
+ (WebCore::AuthorStyleSheets::scheduleOptimizedUpdate): Deleted.
+ (WebCore::AuthorStyleSheets::optimizedUpdateTimerFired): Deleted.
+ * dom/AuthorStyleSheets.h:
+ (WebCore::AuthorStyleSheets::hasPendingUpdate):
+ * dom/Document.cpp:
+ (WebCore::Document::setContentLanguage):
+ (WebCore::Document::recalcStyle):
+ (WebCore::Document::updateStyleIfNeeded):
+ (WebCore::Document::updateLayoutIgnorePendingStylesheets):
+ (WebCore::Document::didRemoveAllPendingStylesheet):
+ (WebCore::Document::usesStyleBasedEditability):
+ (WebCore::Document::processHttpEquiv):
+ (WebCore::Document::setSelectedStylesheetSet):
+ * dom/ExtensionStyleSheets.cpp:
+ (WebCore::ExtensionStyleSheets::clearPageUserSheet):
+ (WebCore::ExtensionStyleSheets::updatePageUserSheet):
+ (WebCore::ExtensionStyleSheets::invalidateInjectedStyleSheetCache):
+ (WebCore::ExtensionStyleSheets::addUserStyleSheet):
+ (WebCore::ExtensionStyleSheets::addAuthorStyleSheetForTesting):
+ (WebCore::ExtensionStyleSheets::styleResolverChangedTimerFired):
+ * dom/InlineStyleSheetOwner.cpp:
+ (WebCore::InlineStyleSheetOwner::removedFromDocument):
+ * dom/ProcessingInstruction.cpp:
+ (WebCore::ProcessingInstruction::removedFrom):
+ * dom/ShadowRoot.cpp:
+ (WebCore::ShadowRoot::updateStyle):
+ * html/HTMLLinkElement.cpp:
+ (WebCore::HTMLLinkElement::setDisabledState):
+ (WebCore::HTMLLinkElement::parseAttribute):
+ (WebCore::HTMLLinkElement::process):
+ (WebCore::HTMLLinkElement::removedFrom):
+ (WebCore::HTMLLinkElement::removePendingSheet):
+ * html/HTMLStyleElement.cpp:
+ (WebCore::HTMLStyleElement::parseAttribute):
+ * inspector/InspectorCSSAgent.cpp:
+ (WebCore::InspectorCSSAgent::forcePseudoState):
+ (WebCore::InspectorCSSAgent::resetPseudoStates):
+ * inspector/InspectorPageAgent.cpp:
+ (WebCore::InspectorPageAgent::setEmulatedMedia):
+ * page/Frame.cpp:
+ (WebCore::Frame::setPrinting):
+ * page/FrameView.cpp:
+ (WebCore::FrameView::layout):
+ (WebCore::FrameView::setPagination):
+ (WebCore::FrameView::setViewportSizeForCSSViewportUnits):
+ * page/Page.cpp:
+ (WebCore::Page::setViewMode):
+ (WebCore::Page::setNeedsRecalcStyleInAllFrames):
+ (WebCore::Page::invalidateInjectedStyleSheetCacheInAllFrames):
+ * svg/SVGFontFaceElement.cpp:
+ (WebCore::SVGFontFaceElement::rebuildFontFace):
+ (WebCore::SVGFontFaceElement::removedFrom):
+ * xml/XMLTreeViewer.cpp:
+ (WebCore::XMLTreeViewer::transformDocumentToTreeView):
+ * xml/parser/XMLDocumentParser.cpp:
+ (WebCore::XMLDocumentParser::end):
+ * xml/parser/XMLDocumentParserLibxml2.cpp:
+ (WebCore::XMLDocumentParser::doEnd):
+
2016-09-24 Yusuke Suzuki <[email protected]>
Unreviewed, update results of DOM binding tests after r206354.
Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (206360 => 206361)
--- trunk/Source/WebCore/css/CSSStyleSheet.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -179,11 +179,11 @@
resolver->addKeyframeStyle(*insertedKeyframesRule);
return;
}
- owner->authorStyleSheets().scheduleOptimizedUpdate();
+ owner->authorStyleSheets().scheduleActiveSetUpdate();
return;
}
- owner->authorStyleSheets().didChange(DeferRecalcStyle);
+ owner->authorStyleSheets().didChangeContentsOrInterpretation();
m_mutatedRules = true;
}
@@ -193,7 +193,7 @@
Document* owner = ownerDocument();
if (!owner)
return;
- owner->authorStyleSheets().didChange(DeferRecalcStyle);
+ owner->authorStyleSheets().didChangeContentsOrInterpretation();
}
void CSSStyleSheet::clearOwnerNode()
@@ -202,7 +202,7 @@
m_ownerNode = 0;
if (!owner)
return;
- owner->authorStyleSheets().didChange(DeferRecalcStyleIfNeeded);
+ owner->authorStyleSheets().didChangeCandidatesForActiveSet();
}
void CSSStyleSheet::reattachChildRuleCSSOMWrappers()
Modified: trunk/Source/WebCore/dom/AuthorStyleSheets.cpp (206360 => 206361)
--- trunk/Source/WebCore/dom/AuthorStyleSheets.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/AuthorStyleSheets.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -57,7 +57,7 @@
AuthorStyleSheets::AuthorStyleSheets(Document& document)
: m_document(document)
- , m_optimizedUpdateTimer(*this, &AuthorStyleSheets::optimizedUpdateTimerFired)
+ , m_pendingUpdateTimer(*this, &AuthorStyleSheets::pendingUpdateTimerFired)
{
}
@@ -64,7 +64,7 @@
AuthorStyleSheets::AuthorStyleSheets(ShadowRoot& shadowRoot)
: m_document(shadowRoot.documentScope())
, m_shadowRoot(&shadowRoot)
- , m_optimizedUpdateTimer(*this, &AuthorStyleSheets::optimizedUpdateTimerFired)
+ , m_pendingUpdateTimer(*this, &AuthorStyleSheets::pendingUpdateTimerFired)
{
}
@@ -213,14 +213,12 @@
}
}
-AuthorStyleSheets::StyleResolverUpdateType AuthorStyleSheets::analyzeStyleSheetChange(UpdateFlag updateFlag, const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, bool& requiresFullStyleRecalc)
+AuthorStyleSheets::StyleResolverUpdateType AuthorStyleSheets::analyzeStyleSheetChange(const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, bool& requiresFullStyleRecalc)
{
requiresFullStyleRecalc = true;
unsigned newStylesheetCount = newStylesheets.size();
- if (updateFlag != OptimizedUpdate)
- return Reconstruct;
if (!m_document.styleResolverIfExists())
return Reconstruct;
@@ -282,20 +280,33 @@
}
}
-bool AuthorStyleSheets::updateActiveStyleSheets(UpdateFlag updateFlag)
+void AuthorStyleSheets::updateActiveStyleSheets(UpdateType updateType)
{
+ ASSERT(!m_pendingUpdateType);
+
if (m_document.inStyleRecalc() || m_document.inRenderTreeUpdate()) {
// Protect against deleting style resolver in the middle of a style resolution.
- // Crash stacks indicate we can get here when z resource load fails synchronously (for example due to content blocking).
+ // Crash stacks indicate we can get here when a resource load fails synchronously (for example due to content blocking).
// FIXME: These kind of cases should be eliminated and this path replaced by an assert.
- m_pendingUpdateType = FullUpdate;
+ m_pendingUpdateType = UpdateType::ContentsOrInterpretation;
m_document.scheduleForcedStyleRecalc();
- return false;
+ return;
+ }
+ if (!m_document.hasLivingRenderTree()) {
+ m_document.clearStyleResolver();
+ return;
}
- if (!m_document.hasLivingRenderTree())
- return false;
+ // Don't bother updating, since we haven't loaded all our style info yet
+ // and haven't calculated the style resolver for the first time.
+ if (!m_shadowRoot && !m_didUpdateActiveStyleSheets && m_pendingStyleSheetCount) {
+ m_document.clearStyleResolver();
+ return;
+ }
+
+ m_didUpdateActiveStyleSheets = true;
+
Vector<RefPtr<StyleSheet>> activeStyleSheets;
collectActiveStyleSheets(activeStyleSheets);
@@ -304,8 +315,10 @@
activeCSSStyleSheets.appendVector(m_document.extensionStyleSheets().authorStyleSheetsForTesting());
filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
- bool requiresFullStyleRecalc;
- auto styleResolverUpdateType = analyzeStyleSheetChange(updateFlag, activeCSSStyleSheets, requiresFullStyleRecalc);
+ bool requiresFullStyleRecalc = true;
+ StyleResolverUpdateType styleResolverUpdateType = Reconstruct;
+ if (updateType == UpdateType::ActiveSet)
+ styleResolverUpdateType = analyzeStyleSheetChange(activeCSSStyleSheets, requiresFullStyleRecalc);
updateStyleResolver(activeCSSStyleSheets, styleResolverUpdateType);
@@ -321,9 +334,13 @@
if (sheet->contents().usesStyleBasedEditability())
m_usesStyleBasedEditability = true;
}
- m_pendingUpdateType = NoUpdate;
- return requiresFullStyleRecalc;
+ if (requiresFullStyleRecalc) {
+ if (m_shadowRoot)
+ m_shadowRoot->setNeedsStyleRecalc();
+ else
+ m_document.scheduleForcedStyleRecalc();
+ }
}
void AuthorStyleSheets::updateStyleResolver(Vector<RefPtr<CSSStyleSheet>>& activeStyleSheets, StyleResolverUpdateType updateType)
@@ -386,64 +403,48 @@
return m_weakCopyOfActiveStyleSheetListForFastLookup->contains(sheet);
}
-void AuthorStyleSheets::flushPendingUpdates()
+void AuthorStyleSheets::flushPendingUpdate()
{
- if (m_pendingUpdateType == NoUpdate)
+ if (!m_pendingUpdateType)
return;
- updateActiveStyleSheets(m_pendingUpdateType);
+ auto updateType = *m_pendingUpdateType;
+
+ clearPendingUpdate();
+
+ updateActiveStyleSheets(updateType);
}
-void AuthorStyleSheets::scheduleOptimizedUpdate()
+void AuthorStyleSheets::clearPendingUpdate()
{
- if (m_optimizedUpdateTimer.isActive())
- return;
- if (m_pendingUpdateType == NoUpdate)
- m_pendingUpdateType = OptimizedUpdate;
- m_optimizedUpdateTimer.startOneShot(0);
+ m_pendingUpdateTimer.stop();
+ m_pendingUpdateType = { };
}
-void AuthorStyleSheets::didChange(StyleResolverUpdateFlag updateFlag)
+void AuthorStyleSheets::scheduleActiveSetUpdate()
{
- m_optimizedUpdateTimer.stop();
-
- // Don't bother updating, since we haven't loaded all our style info yet
- // and haven't calculated the style resolver for the first time.
- if (!m_document.hasLivingRenderTree() || (!m_shadowRoot && !m_didCalculateStyleResolver && m_pendingStyleSheetCount)) {
- m_document.clearStyleResolver();
+ if (m_pendingUpdateTimer.isActive())
return;
- }
- m_didCalculateStyleResolver = true;
+ if (!m_pendingUpdateType)
+ m_pendingUpdateType = UpdateType::ActiveSet;
+ m_pendingUpdateTimer.startOneShot(0);
+}
- auto styleSheetUpdate = (updateFlag == RecalcStyleIfNeeded || updateFlag == DeferRecalcStyleIfNeeded)
- ? AuthorStyleSheets::OptimizedUpdate
- : AuthorStyleSheets::FullUpdate;
- bool stylesheetChangeRequiresStyleRecalc = updateActiveStyleSheets(styleSheetUpdate);
+void AuthorStyleSheets::didChangeCandidatesForActiveSet()
+{
+ auto updateType = m_pendingUpdateType.valueOr(UpdateType::ActiveSet);
+ clearPendingUpdate();
+ updateActiveStyleSheets(updateType);
+}
- auto scheduleStyleRecalc = [&] {
- if (m_shadowRoot)
- m_shadowRoot->setNeedsStyleRecalc();
- else
- m_document.scheduleForcedStyleRecalc();
- };
-
- if (updateFlag == DeferRecalcStyle) {
- scheduleStyleRecalc();
- return;
- }
-
- if (updateFlag == DeferRecalcStyleIfNeeded) {
- if (stylesheetChangeRequiresStyleRecalc)
- scheduleStyleRecalc();
- return;
- }
-
- if (stylesheetChangeRequiresStyleRecalc)
- m_document.recalcStyle(Style::Force);
+void AuthorStyleSheets::didChangeContentsOrInterpretation()
+{
+ clearPendingUpdate();
+ updateActiveStyleSheets(UpdateType::ContentsOrInterpretation);
}
-void AuthorStyleSheets::optimizedUpdateTimerFired()
+void AuthorStyleSheets::pendingUpdateTimerFired()
{
- didChange(RecalcStyleIfNeeded);
+ flushPendingUpdate();
}
}
Modified: trunk/Source/WebCore/dom/AuthorStyleSheets.h (206360 => 206361)
--- trunk/Source/WebCore/dom/AuthorStyleSheets.h 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/AuthorStyleSheets.h 2016-09-25 13:32:24 UTC (rev 206361)
@@ -48,13 +48,6 @@
class ShadowRoot;
class TreeScope;
-enum StyleResolverUpdateFlag {
- RecalcStyleImmediately,
- DeferRecalcStyle,
- RecalcStyleIfNeeded,
- DeferRecalcStyleIfNeeded
-};
-
class AuthorStyleSheets {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -69,8 +62,6 @@
void addStyleSheetCandidateNode(Node&, bool createdByParser);
void removeStyleSheetCandidateNode(Node&);
- WEBCORE_EXPORT void didChange(StyleResolverUpdateFlag);
-
String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; }
String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; }
void setPreferredStylesheetSetName(const String& name) { m_preferredStylesheetSetName = name; }
@@ -91,13 +82,16 @@
bool activeStyleSheetsContains(const CSSStyleSheet*) const;
- void scheduleOptimizedUpdate();
- bool hasPendingUpdate() const { return m_optimizedUpdateTimer.isActive(); }
- void flushPendingUpdates();
+ void didChangeCandidatesForActiveSet();
+ void scheduleActiveSetUpdate();
+ WEBCORE_EXPORT void didChangeContentsOrInterpretation();
+ bool hasPendingUpdate() const { return !!m_pendingUpdateType; }
+ void flushPendingUpdate();
+
private:
- enum UpdateFlag { NoUpdate = 0, OptimizedUpdate, FullUpdate };
- bool updateActiveStyleSheets(UpdateFlag);
+ enum class UpdateType { ActiveSet, ContentsOrInterpretation };
+ void updateActiveStyleSheets(UpdateType);
void collectActiveStyleSheets(Vector<RefPtr<StyleSheet>>&);
@@ -106,10 +100,11 @@
Reset,
Additive
};
- StyleResolverUpdateType analyzeStyleSheetChange(UpdateFlag, const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, bool& requiresFullStyleRecalc);
+ StyleResolverUpdateType analyzeStyleSheetChange(const Vector<RefPtr<CSSStyleSheet>>& newStylesheets, bool& requiresFullStyleRecalc);
void updateStyleResolver(Vector<RefPtr<CSSStyleSheet>>&, StyleResolverUpdateType);
- void optimizedUpdateTimerFired();
+ void pendingUpdateTimerFired();
+ void clearPendingUpdate();
Document& m_document;
ShadowRoot* m_shadowRoot { nullptr };
@@ -117,7 +112,7 @@
Vector<RefPtr<StyleSheet>> m_styleSheetsForStyleSheetList;
Vector<RefPtr<CSSStyleSheet>> m_activeStyleSheets;
- Timer m_optimizedUpdateTimer;
+ Timer m_pendingUpdateTimer;
// This is a mirror of m_activeAuthorStyleSheets that gets populated on demand for activeStyleSheetsContains().
mutable std::unique_ptr<HashSet<const CSSStyleSheet*>> m_weakCopyOfActiveStyleSheetListForFastLookup;
@@ -127,9 +122,9 @@
// We use this count of pending sheets to detect when we can begin attaching
// elements and when it is safe to execute scripts.
int m_pendingStyleSheetCount { 0 };
- bool m_didCalculateStyleResolver { false };
+ bool m_didUpdateActiveStyleSheets { false };
- UpdateFlag m_pendingUpdateType { NoUpdate };
+ Optional<UpdateType> m_pendingUpdateType;
ListHashSet<Node*> m_styleSheetCandidateNodes;
Modified: trunk/Source/WebCore/dom/Document.cpp (206360 => 206361)
--- trunk/Source/WebCore/dom/Document.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -1355,7 +1355,7 @@
m_contentLanguage = language;
// Recalculate style so language is used when selecting the initial font.
- m_authorStyleSheets->didChange(DeferRecalcStyle);
+ m_authorStyleSheets->didChangeContentsOrInterpretation();
}
void Document::setXMLVersion(const String& version, ExceptionCode& ec)
@@ -1859,7 +1859,7 @@
// re-attaching our containing iframe, which when asked HTMLFrameElementBase::isURLAllowed
// hits a null-dereference due to security code always assuming the document has a SecurityOrigin.
- authorStyleSheets().flushPendingUpdates();
+ authorStyleSheets().flushPendingUpdate();
frameView.willRecalcStyle();
@@ -1959,13 +1959,12 @@
if (!view() || view()->isInRenderTreeLayout())
return;
- if (authorStyleSheets().hasPendingUpdate())
- authorStyleSheets().didChange(RecalcStyleIfNeeded);
+ authorStyleSheets().flushPendingUpdate();
if (!needsStyleRecalc())
return;
- recalcStyle(Style::NoChange);
+ recalcStyle();
}
void Document::updateLayout()
@@ -2014,7 +2013,8 @@
HTMLElement* bodyElement = bodyOrFrameset();
if (bodyElement && !bodyElement->renderer() && m_pendingSheetLayout == NoLayoutWithPendingSheets) {
m_pendingSheetLayout = DidLayoutWithPendingSheets;
- authorStyleSheets().didChange(RecalcStyleImmediately);
+ authorStyleSheets().didChangeContentsOrInterpretation();
+ recalcStyle(Style::Force);
} else if (m_hasNodesWithPlaceholderStyle)
// If new nodes have been added or style recalc has been done with style sheets still pending, some nodes
// may not have had their real style calculated yet. Normally this gets cleaned when style sheets arrive
@@ -3151,7 +3151,7 @@
{
m_needsNotifyRemoveAllPendingStylesheet = false;
- authorStyleSheets().didChange(DeferRecalcStyleIfNeeded);
+ authorStyleSheets().didChangeCandidatesForActiveSet();
if (m_pendingSheetLayout == DidLayoutWithPendingSheets) {
m_pendingSheetLayout = IgnoreLayoutWithPendingSheets;
@@ -3182,7 +3182,7 @@
ASSERT(!m_inStyleRecalc);
auto& authorSheets = const_cast<AuthorStyleSheets&>(authorStyleSheets());
- authorSheets.flushPendingUpdates();
+ authorSheets.flushPendingUpdate();
return authorSheets.usesStyleBasedEditability();
}
@@ -3226,7 +3226,7 @@
// -dwh
authorStyleSheets().setSelectedStylesheetSetName(content);
authorStyleSheets().setPreferredStylesheetSetName(content);
- authorStyleSheets().didChange(DeferRecalcStyle);
+ authorStyleSheets().didChangeContentsOrInterpretation();
break;
case HTTPHeaderName::Refresh: {
@@ -3530,7 +3530,7 @@
void Document::setSelectedStylesheetSet(const String& aString)
{
authorStyleSheets().setSelectedStylesheetSetName(aString);
- authorStyleSheets().didChange(DeferRecalcStyle);
+ authorStyleSheets().didChangeContentsOrInterpretation();
}
void Document::evaluateMediaQueryList()
Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (206360 => 206361)
--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -83,7 +83,7 @@
{
if (m_pageUserSheet) {
m_pageUserSheet = nullptr;
- m_document.authorStyleSheets().didChange(DeferRecalcStyle);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
}
@@ -91,7 +91,7 @@
{
clearPageUserSheet();
if (pageUserSheet())
- m_document.authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
const Vector<RefPtr<CSSStyleSheet>>& ExtensionStyleSheets::injectedUserStyleSheets() const
@@ -155,7 +155,7 @@
m_injectedStyleSheetCacheValid = false;
if (m_injectedUserStyleSheets.isEmpty() && m_injectedAuthorStyleSheets.isEmpty())
return;
- m_document.authorStyleSheets().didChange(DeferRecalcStyle);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
void ExtensionStyleSheets::addUserStyleSheet(Ref<StyleSheetContents>&& userSheet)
@@ -162,7 +162,7 @@
{
ASSERT(userSheet.get().isUserStyleSheet());
m_userStyleSheets.append(CSSStyleSheet::create(WTFMove(userSheet), m_document));
- m_document.authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
void ExtensionStyleSheets::addAuthorStyleSheetForTesting(Ref<StyleSheetContents>&& authorSheet)
@@ -169,7 +169,7 @@
{
ASSERT(!authorSheet.get().isUserStyleSheet());
m_authorStyleSheetsForTesting.append(CSSStyleSheet::create(WTFMove(authorSheet), m_document));
- m_document.authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
#if ENABLE(CONTENT_EXTENSIONS)
@@ -201,7 +201,7 @@
void ExtensionStyleSheets::styleResolverChangedTimerFired()
{
- m_document.authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
void ExtensionStyleSheets::detachFromDocument()
Modified: trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp (206360 => 206361)
--- trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -73,7 +73,7 @@
// If we're in document teardown, then we don't need to do any notification of our sheet's removal.
if (document.hasLivingRenderTree())
- document.authorStyleSheets().didChange(DeferRecalcStyle);
+ document.authorStyleSheets().didChangeContentsOrInterpretation();
}
void InlineStyleSheetOwner::clearDocumentData(Document&, Element& element)
Modified: trunk/Source/WebCore/dom/ProcessingInstruction.cpp (206360 => 206361)
--- trunk/Source/WebCore/dom/ProcessingInstruction.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/ProcessingInstruction.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -277,7 +277,7 @@
// If we're in document teardown, then we don't need to do any notification of our sheet's removal.
if (document().hasLivingRenderTree())
- document().authorStyleSheets().didChange(DeferRecalcStyle);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
}
void ProcessingInstruction::finishParsingChildren()
Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (206360 => 206361)
--- trunk/Source/WebCore/dom/ShadowRoot.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -111,7 +111,7 @@
if (!m_authorStyleSheets)
return;
// FIXME: Make optimized updated work.
- m_authorStyleSheets->didChange(DeferRecalcStyle);
+ m_authorStyleSheets->didChangeContentsOrInterpretation();
}
String ShadowRoot::innerHTML() const
Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (206360 => 206361)
--- trunk/Source/WebCore/html/HTMLLinkElement.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -140,7 +140,7 @@
if (!m_sheet && m_disabledState == EnabledViaScript)
process();
else
- document().authorStyleSheets().didChange(DeferRecalcStyle);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
}
}
@@ -176,7 +176,7 @@
m_media = value.string().convertToASCIILowercase();
process();
if (m_sheet && !isDisabled())
- document().authorStyleSheets().didChange(DeferRecalcStyle);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
return;
}
if (name == disabledAttr) {
@@ -283,7 +283,7 @@
} else if (m_sheet) {
// we no longer contain a stylesheet, e.g. perhaps rel or type was changed
clearSheet();
- document().authorStyleSheets().didChange(DeferRecalcStyle);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
}
}
@@ -330,7 +330,7 @@
removePendingSheet(RemovePendingSheetNotifyLater);
if (document().hasLivingRenderTree())
- document().authorStyleSheets().didChange(DeferRecalcStyleIfNeeded);
+ document().authorStyleSheets().didChangeCandidatesForActiveSet();
}
void HTMLLinkElement::finishParsingChildren()
@@ -555,7 +555,7 @@
if (type == InactiveSheet) {
// Document just needs to know about the sheet for exposure through document.styleSheets
- document().authorStyleSheets().didChange(DeferRecalcStyleIfNeeded);
+ document().authorStyleSheets().didChangeCandidatesForActiveSet();
return;
}
Modified: trunk/Source/WebCore/html/HTMLStyleElement.cpp (206360 => 206361)
--- trunk/Source/WebCore/html/HTMLStyleElement.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/html/HTMLStyleElement.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -78,7 +78,7 @@
if (sheet()) {
sheet()->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(value));
if (inDocument() && document().hasLivingRenderTree())
- document().authorStyleSheets().didChange(RecalcStyleImmediately);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
}
} else if (name == typeAttr)
m_styleSheetOwner.setContentType(value);
Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (206360 => 206361)
--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -889,7 +889,7 @@
m_nodeIdToForcedPseudoState.set(nodeId, forcedPseudoState);
else
m_nodeIdToForcedPseudoState.remove(nodeId);
- element->document().authorStyleSheets().didChange(RecalcStyleImmediately);
+ element->document().authorStyleSheets().didChangeContentsOrInterpretation();
}
void InspectorCSSAgent::getNamedFlowCollection(ErrorString& errorString, int documentNodeId, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::NamedFlow>>& result)
@@ -1189,7 +1189,7 @@
m_nodeIdToForcedPseudoState.clear();
for (auto& document : documentsToChange)
- document->authorStyleSheets().didChange(RecalcStyleImmediately);
+ document->authorStyleSheets().didChangeContentsOrInterpretation();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (206360 => 206361)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -1002,7 +1002,7 @@
m_emulatedMedia = media;
Document* document = m_page.mainFrame().document();
if (document) {
- document->authorStyleSheets().didChange(RecalcStyleImmediately);
+ document->authorStyleSheets().didChangeContentsOrInterpretation();
document->updateLayout();
}
}
Modified: trunk/Source/WebCore/page/Frame.cpp (206360 => 206361)
--- trunk/Source/WebCore/page/Frame.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/page/Frame.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -644,7 +644,7 @@
m_doc->setPrinting(printing);
view()->adjustMediaTypeForPrinting(printing);
- m_doc->authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_doc->authorStyleSheets().didChangeContentsOrInterpretation();
if (shouldUsePrintingLayout()) {
view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
} else {
Modified: trunk/Source/WebCore/page/FrameView.cpp (206360 => 206361)
--- trunk/Source/WebCore/page/FrameView.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/page/FrameView.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -1301,7 +1301,7 @@
StyleResolver* styleResolver = document.styleResolverIfExists();
if (!styleResolver || styleResolver->hasMediaQueriesAffectedByViewportChange()) {
LOG(Layout, " hasMediaQueriesAffectedByViewportChange, enqueueing style recalc");
- document.authorStyleSheets().didChange(DeferRecalcStyle);
+ document.authorStyleSheets().didChangeContentsOrInterpretation();
// FIXME: This instrumentation event is not strictly accurate since cached media query results do not persist across StyleResolver rebuilds.
InspectorInstrumentation::mediaQueryResultChanged(document);
} else
@@ -3496,7 +3496,7 @@
m_pagination = pagination;
- frame().document()->authorStyleSheets().didChange(DeferRecalcStyle);
+ frame().document()->authorStyleSheets().didChangeContentsOrInterpretation();
}
IntRect FrameView::windowClipRect() const
@@ -4965,7 +4965,7 @@
if (Document* document = frame().document()) {
// FIXME: this should probably be updateViewportUnitsOnResize(), but synchronously
// dirtying style here causes assertions on iOS (rdar://problem/19998166).
- document->authorStyleSheets().didChange(DeferRecalcStyle);
+ document->authorStyleSheets().didChangeContentsOrInterpretation();
}
}
Modified: trunk/Source/WebCore/page/Page.cpp (206360 => 206361)
--- trunk/Source/WebCore/page/Page.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/page/Page.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -424,7 +424,7 @@
m_mainFrame->view()->forceLayout();
if (m_mainFrame->document())
- m_mainFrame->document()->authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_mainFrame->document()->authorStyleSheets().didChangeContentsOrInterpretation();
}
#endif // ENABLE(VIEW_MODE_CSS_MEDIA)
@@ -502,7 +502,7 @@
{
for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (Document* document = frame->document())
- document->authorStyleSheets().didChange(DeferRecalcStyle);
+ document->authorStyleSheets().didChangeContentsOrInterpretation();
}
}
@@ -1163,7 +1163,7 @@
if (!document)
continue;
document->extensionStyleSheets().invalidateInjectedStyleSheetCache();
- document->authorStyleSheets().didChange(DeferRecalcStyle);
+ document->authorStyleSheets().didChangeContentsOrInterpretation();
}
}
Modified: trunk/Source/WebCore/svg/SVGFontFaceElement.cpp (206360 => 206361)
--- trunk/Source/WebCore/svg/SVGFontFaceElement.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/svg/SVGFontFaceElement.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -267,7 +267,7 @@
}
}
- document().authorStyleSheets().didChange(DeferRecalcStyle);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
}
Node::InsertionNotificationRequest SVGFontFaceElement::insertedInto(ContainerNode& rootParent)
@@ -292,7 +292,7 @@
document().accessSVGExtensions().unregisterSVGFontFaceElement(this);
m_fontFaceRule->mutableProperties().clear();
- document().authorStyleSheets().didChange(DeferRecalcStyle);
+ document().authorStyleSheets().didChangeContentsOrInterpretation();
} else
ASSERT(!m_fontElement);
}
Modified: trunk/Source/WebCore/xml/XMLTreeViewer.cpp (206360 => 206361)
--- trunk/Source/WebCore/xml/XMLTreeViewer.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/xml/XMLTreeViewer.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -64,7 +64,7 @@
String cssString = StringImpl::createWithoutCopying(XMLViewer_css, sizeof(XMLViewer_css));
auto text = m_document.createTextNode(cssString);
m_document.getElementById(String(ASCIILiteral("xml-viewer-style")))->appendChild(text, IGNORE_EXCEPTION);
- m_document.authorStyleSheets().didChange(RecalcStyleImmediately);
+ m_document.authorStyleSheets().didChangeContentsOrInterpretation();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp (206360 => 206361)
--- trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -200,7 +200,7 @@
insertErrorMessageBlock();
else {
updateLeafTextNode();
- document()->authorStyleSheets().didChange(RecalcStyleImmediately);
+ document()->authorStyleSheets().didChangeContentsOrInterpretation();
}
if (isParsing())
Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (206360 => 206361)
--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp 2016-09-25 13:32:24 UTC (rev 206361)
@@ -1387,7 +1387,7 @@
document()->setTransformSource(std::make_unique<TransformSource>(doc));
document()->setParsing(false); // Make the document think it's done, so it will apply XSL stylesheets.
- document()->authorStyleSheets().didChange(RecalcStyleImmediately);
+ document()->authorStyleSheets().didChangeContentsOrInterpretation();
// styleResolverChanged() call can detach the parser and null out its document.
// In that case, we just bail out.
Modified: trunk/Source/WebKit/mac/ChangeLog (206360 => 206361)
--- trunk/Source/WebKit/mac/ChangeLog 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebKit/mac/ChangeLog 2016-09-25 13:32:24 UTC (rev 206361)
@@ -1,3 +1,14 @@
+2016-09-25 Antti Koivisto <[email protected]>
+
+ AuthorStyleSheets shouldn't trigger synchronous style resolutions
+ https://bugs.webkit.org/show_bug.cgi?id=162532
+
+ Reviewed by Darin Adler.
+
+ * WebView/WebHTMLView.mm:
+ (-[WebHTMLView reapplyStyles]):
+ (-[WebHTMLView _setPrinting:minimumPageLogicalWidth:logicalHeight:originalPageWidth:originalPageHeight:maximumShrinkRatio:adjustViewSize:paginateScreenContent:]):
+
2016-09-24 Antti Koivisto <[email protected]>
Move stylesheet change logic from Document to AuthorStyleSheets
Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (206360 => 206361)
--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm 2016-09-25 07:01:35 UTC (rev 206360)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm 2016-09-25 13:32:24 UTC (rev 206361)
@@ -3611,10 +3611,12 @@
double start = CFAbsoluteTimeGetCurrent();
#endif
- if (Frame* coreFrame = core([self _frame]))
- coreFrame->document()->authorStyleSheets().didChange(RecalcStyleImmediately);
-
-#ifdef LOG_TIMES
+ if (Frame* coreFrame = core([self _frame])) {
+ coreFrame->document()->authorStyleSheets().didChangeContentsOrInterpretation();
+ coreFrame->document()->updateStyleIfNeeded();
+ }
+
+#ifdef LOG_TIMES
double thisTime = CFAbsoluteTimeGetCurrent() - start;
LOG(Timing, "%s apply style seconds = %f", [self URL], thisTime);
#endif
@@ -5005,7 +5007,7 @@
document->setPaginatedForScreen(_private->paginateScreenContent);
document->setPrinting(_private->printing);
- document->authorStyleSheets().didChange(RecalcStyleImmediately);
+ document->authorStyleSheets().didChangeContentsOrInterpretation();
}
}