Diff
Modified: branches/safari-537-branch/Source/WebCore/ChangeLog (153664 => 153665)
--- branches/safari-537-branch/Source/WebCore/ChangeLog 2013-08-02 20:10:27 UTC (rev 153664)
+++ branches/safari-537-branch/Source/WebCore/ChangeLog 2013-08-02 20:28:05 UTC (rev 153665)
@@ -1,5 +1,53 @@
2013-08-02 Lucas Forschler <[email protected]>
+ Merge r153641
+
+ 2013-08-01 Andreas Kling <[email protected]>
+
+ Removing an empty style sheet shouldn't trigger style recalc.
+ <http://webkit.org/b/119248>
+ <rdar://problem/14629045>
+
+ Reviewed by Antti Koivisto.
+
+ Teach DocumentStyleSheetCollection to filter out empty style sheets when deciding whether
+ or not to trigger a style recalc. We can then be clever when an empty style sheet is removed
+ from the document, and avoid causing extra work.
+
+ Some pages use this pattern:
+
+ (1) Create a <style> element.
+ (2) Add it to the document's <head> element.
+ (3) Insert some CSS as a text child of the <style> element.
+
+ Since the <style> element is already inside the document at (3), we had to treat this as an
+ old style sheet being removed, even though it was just an empty sheet of nothing.
+
+ With this patch, Document gains enough smarts to know that removing/adding an empty sheet
+ won't affect layout/rendering in any meaningful way, thus a style recalc can be avoided.
+
+ * dom/Document.h:
+ * dom/Document.cpp:
+ (WebCore::Document::styleResolverChanged):
+
+ Add a DeferRecalcStyleIfNeeded mode to styleResolverChanged().
+
+ * css/CSSStyleSheet.h:
+ * css/CSSStyleSheet.cpp:
+ (WebCore::CSSStyleSheet::clearOwnerNode):
+
+ Use DeferRecalcStyleIfNeeded when saying bye from a CSSStyleSheet and let Document decide
+ if removing the sheet should trigger style recalc instead of always assuming it should.
+
+ * dom/DocumentStyleSheetCollection.cpp:
+ (WebCore::filterEnabledNonemptyCSSStyleSheets):
+ (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets):
+
+ Exclude empty sheets from the activeAuthorStyleSheets() collection. They are still
+ visible through CSSOM's document.styleSheets.
+
+2013-08-02 Lucas Forschler <[email protected]>
+
Merge r153649
2013-08-02 Brady Eidson <[email protected]>
Modified: branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.cpp (153664 => 153665)
--- branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.cpp 2013-08-02 20:10:27 UTC (rev 153664)
+++ branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.cpp 2013-08-02 20:28:05 UTC (rev 153665)
@@ -162,6 +162,15 @@
owner->styleResolverChanged(DeferRecalcStyle);
}
+void CSSStyleSheet::clearOwnerNode()
+{
+ Document* owner = ownerDocument();
+ m_ownerNode = 0;
+ if (!owner)
+ return;
+ owner->styleResolverChanged(DeferRecalcStyleIfNeeded);
+}
+
void CSSStyleSheet::reattachChildRuleCSSOMWrappers()
{
for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
Modified: branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.h (153664 => 153665)
--- branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.h 2013-08-02 20:10:27 UTC (rev 153664)
+++ branches/safari-537-branch/Source/WebCore/css/CSSStyleSheet.h 2013-08-02 20:28:05 UTC (rev 153665)
@@ -74,7 +74,7 @@
unsigned length() const;
CSSRule* item(unsigned index);
- virtual void clearOwnerNode() OVERRIDE { didMutate(); m_ownerNode = 0; }
+ virtual void clearOwnerNode() OVERRIDE;
virtual CSSImportRule* ownerRule() const OVERRIDE { return m_ownerRule; }
virtual KURL baseURL() const OVERRIDE;
virtual bool isLoading() const OVERRIDE;
Modified: branches/safari-537-branch/Source/WebCore/dom/Document.cpp (153664 => 153665)
--- branches/safari-537-branch/Source/WebCore/dom/Document.cpp 2013-08-02 20:10:27 UTC (rev 153664)
+++ branches/safari-537-branch/Source/WebCore/dom/Document.cpp 2013-08-02 20:28:05 UTC (rev 153665)
@@ -3143,7 +3143,7 @@
printf("Beginning update of style selector at time %d.\n", elapsedTime());
#endif
- DocumentStyleSheetCollection::UpdateFlag styleSheetUpdate = (updateFlag == RecalcStyleIfNeeded)
+ DocumentStyleSheetCollection::UpdateFlag styleSheetUpdate = (updateFlag == RecalcStyleIfNeeded || updateFlag == DeferRecalcStyleIfNeeded)
? DocumentStyleSheetCollection::OptimizedUpdate
: DocumentStyleSheetCollection::FullUpdate;
bool stylesheetChangeRequiresStyleRecalc = m_styleSheetCollection->updateActiveStyleSheets(styleSheetUpdate);
@@ -3153,6 +3153,12 @@
return;
}
+ if (updateFlag == DeferRecalcStyleIfNeeded) {
+ if (stylesheetChangeRequiresStyleRecalc)
+ scheduleForcedStyleRecalc();
+ return;
+ }
+
if (didLayoutWithPendingStylesheets() && !m_styleSheetCollection->hasPendingSheets()) {
m_pendingSheetLayout = IgnoreLayoutWithPendingSheets;
if (renderer())
Modified: branches/safari-537-branch/Source/WebCore/dom/Document.h (153664 => 153665)
--- branches/safari-537-branch/Source/WebCore/dom/Document.h 2013-08-02 20:10:27 UTC (rev 153664)
+++ branches/safari-537-branch/Source/WebCore/dom/Document.h 2013-08-02 20:28:05 UTC (rev 153665)
@@ -196,7 +196,7 @@
PageshowEventPersisted = 1
};
-enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded };
+enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded, DeferRecalcStyleIfNeeded };
enum NodeListInvalidationType {
DoNotInvalidateOnAttributeChanges = 0,
Modified: branches/safari-537-branch/Source/WebCore/dom/DocumentStyleSheetCollection.cpp (153664 => 153665)
--- branches/safari-537-branch/Source/WebCore/dom/DocumentStyleSheetCollection.cpp 2013-08-02 20:10:27 UTC (rev 153664)
+++ branches/safari-537-branch/Source/WebCore/dom/DocumentStyleSheetCollection.cpp 2013-08-02 20:28:05 UTC (rev 153665)
@@ -425,14 +425,17 @@
return false;
}
-static void filterEnabledCSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets)
+static void filterEnabledNonemptyCSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets)
{
for (unsigned i = 0; i < sheets.size(); ++i) {
if (!sheets[i]->isCSSStyleSheet())
continue;
if (sheets[i]->disabled())
continue;
- result.append(static_cast<CSSStyleSheet*>(sheets[i].get()));
+ CSSStyleSheet* sheet = static_cast<CSSStyleSheet*>(sheets[i].get());
+ if (!sheet->length())
+ continue;
+ result.append(sheet);
}
}
@@ -465,7 +468,7 @@
activeCSSStyleSheets.appendVector(injectedAuthorStyleSheets());
activeCSSStyleSheets.appendVector(documentAuthorStyleSheets());
collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_document);
- filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
+ filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
StyleResolverUpdateType styleResolverUpdateType;
bool requiresFullStyleRecalc;