Changeset 153641 in webkit
- Timestamp:
- Aug 2, 2013, 2:15:43 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r153640 r153641 1 2013-08-01 Andreas Kling <akling@apple.com> 2 3 Removing an empty style sheet shouldn't trigger style recalc. 4 <http://webkit.org/b/119248> 5 <rdar://problem/14629045> 6 7 Reviewed by Antti Koivisto. 8 9 Teach DocumentStyleSheetCollection to filter out empty style sheets when deciding whether 10 or not to trigger a style recalc. We can then be clever when an empty style sheet is removed 11 from the document, and avoid causing extra work. 12 13 Some pages use this pattern: 14 15 (1) Create a <style> element. 16 (2) Add it to the document's <head> element. 17 (3) Insert some CSS as a text child of the <style> element. 18 19 Since the <style> element is already inside the document at (3), we had to treat this as an 20 old style sheet being removed, even though it was just an empty sheet of nothing. 21 22 With this patch, Document gains enough smarts to know that removing/adding an empty sheet 23 won't affect layout/rendering in any meaningful way, thus a style recalc can be avoided. 24 25 * dom/Document.h: 26 * dom/Document.cpp: 27 (WebCore::Document::styleResolverChanged): 28 29 Add a DeferRecalcStyleIfNeeded mode to styleResolverChanged(). 30 31 * css/CSSStyleSheet.h: 32 * css/CSSStyleSheet.cpp: 33 (WebCore::CSSStyleSheet::clearOwnerNode): 34 35 Use DeferRecalcStyleIfNeeded when saying bye from a CSSStyleSheet and let Document decide 36 if removing the sheet should trigger style recalc instead of always assuming it should. 37 38 * dom/DocumentStyleSheetCollection.cpp: 39 (WebCore::filterEnabledNonemptyCSSStyleSheets): 40 (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets): 41 42 Exclude empty sheets from the activeAuthorStyleSheets() collection. They are still 43 visible through CSSOM's document.styleSheets. 44 1 45 2013-08-02 Zalan Bujtas <zalan@apple.com> 2 46 -
trunk/Source/WebCore/css/CSSStyleSheet.cpp
r152353 r153641 164 164 } 165 165 166 void CSSStyleSheet::clearOwnerNode() 167 { 168 Document* owner = ownerDocument(); 169 m_ownerNode = 0; 170 if (!owner) 171 return; 172 owner->styleResolverChanged(DeferRecalcStyleIfNeeded); 173 } 174 166 175 void CSSStyleSheet::reattachChildRuleCSSOMWrappers() 167 176 { -
trunk/Source/WebCore/css/CSSStyleSheet.h
r153566 r153641 75 75 CSSRule* item(unsigned index); 76 76 77 virtual void clearOwnerNode() OVERRIDE { didMutate(); m_ownerNode = 0; }77 virtual void clearOwnerNode() OVERRIDE; 78 78 virtual CSSImportRule* ownerRule() const OVERRIDE { return m_ownerRule; } 79 79 virtual KURL baseURL() const OVERRIDE; -
trunk/Source/WebCore/dom/Document.cpp
r153407 r153641 3156 3156 #endif 3157 3157 3158 DocumentStyleSheetCollection::UpdateFlag styleSheetUpdate = (updateFlag == RecalcStyleIfNeeded )3158 DocumentStyleSheetCollection::UpdateFlag styleSheetUpdate = (updateFlag == RecalcStyleIfNeeded || updateFlag == DeferRecalcStyleIfNeeded) 3159 3159 ? DocumentStyleSheetCollection::OptimizedUpdate 3160 3160 : DocumentStyleSheetCollection::FullUpdate; … … 3163 3163 if (updateFlag == DeferRecalcStyle) { 3164 3164 scheduleForcedStyleRecalc(); 3165 return; 3166 } 3167 3168 if (updateFlag == DeferRecalcStyleIfNeeded) { 3169 if (stylesheetChangeRequiresStyleRecalc) 3170 scheduleForcedStyleRecalc(); 3165 3171 return; 3166 3172 } -
trunk/Source/WebCore/dom/Document.h
r151980 r153641 198 198 }; 199 199 200 enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded };200 enum StyleResolverUpdateFlag { RecalcStyleImmediately, DeferRecalcStyle, RecalcStyleIfNeeded, DeferRecalcStyleIfNeeded }; 201 201 202 202 enum NodeListInvalidationType { -
trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp
r152290 r153641 428 428 } 429 429 430 static void filterEnabled CSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets)430 static void filterEnabledNonemptyCSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets) 431 431 { 432 432 for (unsigned i = 0; i < sheets.size(); ++i) { … … 435 435 if (sheets[i]->disabled()) 436 436 continue; 437 result.append(static_cast<CSSStyleSheet*>(sheets[i].get())); 437 CSSStyleSheet* sheet = static_cast<CSSStyleSheet*>(sheets[i].get()); 438 if (!sheet->length()) 439 continue; 440 result.append(sheet); 438 441 } 439 442 } … … 468 471 activeCSSStyleSheets.appendVector(documentAuthorStyleSheets()); 469 472 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_document); 470 filterEnabled CSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);473 filterEnabledNonemptyCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets); 471 474 472 475 StyleResolverUpdateType styleResolverUpdateType;
Note:
See TracChangeset
for help on using the changeset viewer.