Changeset 201799 in webkit
- Timestamp:
- Jun 8, 2016 1:00:22 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r201798 r201799 1 2016-06-08 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Extend CSSFontSelector's lifetime to be longer than the Document's lifetime 4 https://bugs.webkit.org/show_bug.cgi?id=154101 5 6 Reviewed by Darin Adler. 7 8 Rather than destroying the Document's CSSFontSelector, instead, the object should 9 live for the lifetime of the document, and it should instead be asked to clear its 10 contents. 11 12 This is important for the CSS Font Loading API, where the identity of objects the 13 CSSFontSelector references needs to persist throughout the lifetime of the 14 Document. This patch represents the first step to implementing this correctly. 15 The second step is for the CSSFontSelector to perform a diff instead of a 16 wholesale clear of its contents. Once this is done, font loading objects can 17 survive through a call to Document::clearStyleResolver(). 18 19 This patch gives the CSSFontSelector two states: building underway and building not 20 underway. The state is building underway in between calls to clearStyleResolver() 21 and when the style resolver gets built back up. Otherwise, the state is building 22 not underway. Because of this new design, creation of all FontFace objects can be 23 postponed until a state transition from building underway to building not underway. 24 A subsequent patch will perform the diff at this point. An ASSERT() makes sure that 25 we never service a font lookup request while Building. 26 27 No new tests because there is no behavior change. 28 29 * css/CSSFontFaceSet.cpp: 30 (WebCore::CSSFontFaceSet::clear): 31 * css/CSSFontSelector.cpp: 32 (WebCore::CSSFontSelector::buildStarted): 33 (WebCore::CSSFontSelector::buildCompleted): 34 (WebCore::CSSFontSelector::addFontFaceRule): 35 (WebCore::CSSFontSelector::fontRangesForFamily): 36 (WebCore::CSSFontSelector::CSSFontSelector): Deleted. 37 (WebCore::CSSFontSelector::clearDocument): Deleted. 38 * css/CSSFontSelector.h: 39 * css/StyleResolver.cpp: 40 (WebCore::StyleResolver::appendAuthorStyleSheets): 41 * dom/Document.cpp: 42 (WebCore::Document::Document): 43 (WebCore::Document::~Document): 44 (WebCore::Document::clearStyleResolver): 45 (WebCore::Document::fontSelector): Deleted. 46 * dom/Document.h: 47 (WebCore::Document::fontSelector): 48 1 49 2016-06-08 Adam Bergkvist <adam.bergkvist@ericsson.com> 2 50 -
trunk/Source/WebCore/css/CSSFontFaceSet.cpp
r201290 r201799 245 245 m_locallyInstalledFacesLookupTable.clear(); 246 246 m_cache.clear(); 247 m_facesPartitionIndex = 0; 248 m_status = Status::Loaded; 247 249 } 248 250 -
trunk/Source/WebCore/css/CSSFontSelector.cpp
r201596 r201799 72 72 , m_version(0) 73 73 { 74 // FIXME: An old comment used to say there was no need to hold a reference to m_document75 // because "we are guaranteed to be destroyed before the document". But there does not76 // seem to be any such guarantee.77 78 74 ASSERT(m_document); 79 75 FontCache::singleton().addClient(*this); … … 103 99 } 104 100 101 void CSSFontSelector::buildStarted() 102 { 103 m_buildIsUnderway = true; 104 ++m_version; 105 } 106 107 void CSSFontSelector::buildCompleted() 108 { 109 if (!m_buildIsUnderway) 110 return; 111 112 m_buildIsUnderway = false; 113 114 m_cssFontFaceSet->clear(); 115 116 for (auto& item : m_stagingArea) 117 addFontFaceRule(item.styleRuleFontFace, item.isInitiatingElementInUserAgentShadowTree); 118 m_stagingArea.clear(); 119 } 120 105 121 void CSSFontSelector::addFontFaceRule(StyleRuleFontFace& fontFaceRule, bool isInitiatingElementInUserAgentShadowTree) 106 122 { 123 if (m_buildIsUnderway) { 124 m_stagingArea.append({fontFaceRule, isInitiatingElementInUserAgentShadowTree}); 125 return; 126 } 127 107 128 const StyleProperties& style = fontFaceRule.properties(); 108 129 RefPtr<CSSValue> fontFamily = style.getPropertyCSSValue(CSSPropertyFontFamily); … … 236 257 FontRanges CSSFontSelector::fontRangesForFamily(const FontDescription& fontDescription, const AtomicString& familyName) 237 258 { 259 ASSERT(!m_buildIsUnderway); // If this ASSERT() fires, it usually means you forgot a document.updateStyleIfNeeded() somewhere. 260 238 261 // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too. 239 262 bool resolveGenericFamilyFirst = familyName == standardFamily; … … 269 292 m_document = nullptr; 270 293 271 // FIXME: This object should outlive the Document.272 294 m_cssFontFaceSet->clear(); 273 295 m_clients.clear(); -
trunk/Source/WebCore/css/CSSFontSelector.h
r201596 r201799 66 66 67 67 void clearDocument(); 68 void buildStarted(); 69 void buildCompleted(); 68 70 69 71 void addFontFaceRule(StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree); … … 92 94 void beginLoadTimerFired(); 93 95 96 struct PendingFontFaceRule { 97 StyleRuleFontFace& styleRuleFontFace; 98 bool isInitiatingElementInUserAgentShadowTree; 99 }; 100 Vector<PendingFontFaceRule> m_stagingArea; 101 94 102 Document* m_document; 95 103 RefPtr<FontFaceSet> m_fontFaceSet; … … 103 111 unsigned m_version; 104 112 bool m_creatingFont { false }; 113 bool m_buildIsUnderway { false }; 105 114 }; 106 115 -
trunk/Source/WebCore/css/SourceSizeList.cpp
r201441 r201799 48 48 if (!primitiveValue.isLength()) 49 49 return defaultLength(style, renderer); 50 51 // Because we evaluate "sizes" at parse time (before style has been resolved), the font metrics used for these specific units 52 // are not available. The font selector's internal consistency isn't guaranteed just yet, so we can just temporarily clear 53 // the pointer to it for the duration of the unit evaluation. This is acceptible because the style always comes from the 54 // RenderView, which has its font information hardcoded in resolveForDocument() to be -webkit-standard, whose operations 55 // don't require a font selector. 56 if (!primitiveValue.isCalculated() && (primitiveValue.primitiveType() == CSSPrimitiveValue::CSS_EXS || primitiveValue.primitiveType() == CSSPrimitiveValue::CSS_CHS)) { 57 RefPtr<FontSelector> fontSelector = style.fontCascade().fontSelector(); 58 style.fontCascade().update(nullptr); 59 float result = primitiveValue.computeLength<float>(conversionData); 60 style.fontCascade().update(fontSelector.get()); 61 return result; 62 } 63 50 64 return primitiveValue.computeLength<float>(conversionData); 51 65 } -
trunk/Source/WebCore/css/StyleResolver.cpp
r201498 r201799 297 297 { 298 298 m_ruleSets.appendAuthorStyleSheets(styleSheets, &m_mediaQueryEvaluator, m_inspectorCSSOMWrappers, this); 299 300 document().fontSelector().buildCompleted(); 301 299 302 if (auto renderView = document().renderView()) 300 303 renderView->style().fontCascade().update(&document().fontSelector()); -
trunk/Source/WebCore/dom/Document.cpp
r201782 r201799 530 530 #endif 531 531 , m_templateDocumentHost(nullptr) 532 , m_fontSelector(CSSFontSelector::create(*this)) 532 533 #if ENABLE(WEB_REPLAY) 533 534 , m_inputCursor(EmptyInputCursor::create()) … … 563 564 initSecurityContext(); 564 565 initDNSPrefetch(); 566 567 m_fontSelector->registerForInvalidationCallbacks(*this); 565 568 566 569 for (auto& nodeListAndCollectionCount : m_nodeListAndCollectionCounts) … … 638 641 639 642 clearStyleResolver(); // We need to destroy CSSFontSelector before destroying m_cachedResourceLoader. 643 m_fontSelector->clearDocument(); 644 m_fontSelector->unregisterForInvalidationCallbacks(*this); 640 645 641 646 // It's possible for multiple Documents to end up referencing the same CachedResourceLoader (e.g., SVGImages … … 2209 2214 } 2210 2215 2211 CSSFontSelector& Document::fontSelector()2212 {2213 if (!m_fontSelector) {2214 m_fontSelector = CSSFontSelector::create(*this);2215 m_fontSelector->registerForInvalidationCallbacks(*this);2216 }2217 return *m_fontSelector;2218 }2219 2220 2216 void Document::clearStyleResolver() 2221 2217 { … … 2223 2219 m_userAgentShadowTreeStyleResolver = nullptr; 2224 2220 2225 // FIXME: It would be better if the FontSelector could survive this operation. 2226 if (m_fontSelector) { 2227 m_fontSelector->clearDocument(); 2228 m_fontSelector->unregisterForInvalidationCallbacks(*this); 2229 m_fontSelector = nullptr; 2230 } 2221 m_fontSelector->buildStarted(); 2231 2222 } 2232 2223 -
trunk/Source/WebCore/dom/Document.h
r201739 r201799 505 505 StyleResolver& userAgentShadowTreeStyleResolver(); 506 506 507 CSSFontSelector& fontSelector() ;507 CSSFontSelector& fontSelector() { return m_fontSelector; } 508 508 509 509 void notifyRemovePendingSheetIfNeeded(); … … 1737 1737 #endif 1738 1738 1739 Ref Ptr<CSSFontSelector> m_fontSelector;1739 Ref<CSSFontSelector> m_fontSelector; 1740 1740 1741 1741 #if ENABLE(WEB_REPLAY) -
trunk/Source/WebCore/style/StyleTreeResolver.cpp
r201673 r201799 493 493 494 494 Element* documentElement = m_document.documentElement(); 495 if (!documentElement) 495 if (!documentElement) { 496 m_document.ensureStyleResolver(); 496 497 return nullptr; 498 } 497 499 if (change != Force && !documentElement->childNeedsStyleRecalc() && !documentElement->needsStyleRecalc()) 498 500 return nullptr;
Note: See TracChangeset
for help on using the changeset viewer.