Changeset 207669 in webkit
- Timestamp:
- Oct 21, 2016 6:36:45 AM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207667 r207669 1 2016-10-21 Antti Koivisto <antti@apple.com> 2 3 Style resolver should be updated lazily 4 https://bugs.webkit.org/show_bug.cgi?id=163721 5 6 Reviewed by Andreas Kling. 7 8 Currently when stylesheets change in some way we generally update style resolvers and 9 invalidate style immediately. We should do this lazily to avoid unnecessary work. 10 11 Also improve naming of the stylesheet invalidation functions and use more optimal functions in some places. 12 13 * css/CSSComputedStyleDeclaration.cpp: 14 (WebCore::updateStyleIfNeededForNode): 15 * css/CSSStyleSheet.cpp: 16 (WebCore::CSSStyleSheet::didMutateRules): 17 (WebCore::CSSStyleSheet::didMutate): 18 (WebCore::CSSStyleSheet::setDisabled): 19 * css/StyleResolver.cpp: 20 (WebCore::StyleResolver::StyleResolver): 21 22 Initialize root style font with null font selector. 23 This avoids hitting a CSSFontSelector assert in fast/media/mq-relative-constraints-08.html where 24 media query evaluation requires font information before it is ready. 25 Exposed by increased laziness in this patch. 26 27 * dom/Document.cpp: 28 (WebCore::Document::setContentLanguage): 29 (WebCore::Document::updateLayoutIgnorePendingStylesheets): 30 (WebCore::Document::isPageBoxVisible): 31 (WebCore::Document::pageSizeAndMarginsInPixels): 32 (WebCore::Document::processHttpEquiv): 33 (WebCore::Document::setSelectedStylesheetSet): 34 (WebCore::Document::didInsertInDocumentShadowRoot): 35 (WebCore::Document::didRemoveInDocumentShadowRoot): 36 * dom/Document.h: 37 (WebCore::Document::inDocumentShadowRoots): 38 39 Track all shadow roots in the document. This allows us to find and flush style scopes cheaply. 40 41 * dom/Element.cpp: 42 (WebCore::Element::computedStyle): 43 * dom/ExtensionStyleSheets.cpp: 44 (WebCore::ExtensionStyleSheets::ExtensionStyleSheets): 45 (WebCore::ExtensionStyleSheets::clearPageUserSheet): 46 (WebCore::ExtensionStyleSheets::updatePageUserSheet): 47 (WebCore::ExtensionStyleSheets::invalidateInjectedStyleSheetCache): 48 (WebCore::ExtensionStyleSheets::addUserStyleSheet): 49 (WebCore::ExtensionStyleSheets::addAuthorStyleSheetForTesting): 50 (WebCore::ExtensionStyleSheets::addDisplayNoneSelector): 51 (WebCore::ExtensionStyleSheets::maybeAddContentExtensionSheet): 52 (WebCore::ExtensionStyleSheets::styleResolverChangedTimerFired): Deleted. 53 54 Since updates are now done lazily we don't need a special timer for extension stylesheets. 55 56 * dom/ExtensionStyleSheets.h: 57 * dom/ProcessingInstruction.cpp: 58 (WebCore::ProcessingInstruction::checkStyleSheet): 59 (WebCore::ProcessingInstruction::sheetLoaded): 60 (WebCore::ProcessingInstruction::removedFrom): 61 * dom/ShadowRoot.cpp: 62 (WebCore::ShadowRoot::ShadowRoot): 63 (WebCore::ShadowRoot::insertedInto): 64 (WebCore::ShadowRoot::removedFrom): 65 (WebCore::ShadowRoot::styleScope): 66 * dom/ShadowRoot.h: 67 * html/HTMLLinkElement.cpp: 68 (WebCore::HTMLLinkElement::setDisabledState): 69 (WebCore::HTMLLinkElement::parseAttribute): 70 (WebCore::HTMLLinkElement::process): 71 (WebCore::HTMLLinkElement::removePendingSheet): 72 * html/HTMLStyleElement.cpp: 73 (WebCore::HTMLStyleElement::parseAttribute): 74 * inspector/InspectorCSSAgent.cpp: 75 (WebCore::InspectorCSSAgent::createInspectorStyleSheetForDocument): 76 (WebCore::InspectorCSSAgent::forcePseudoState): 77 (WebCore::InspectorCSSAgent::resetPseudoStates): 78 * inspector/InspectorPageAgent.cpp: 79 (WebCore::InspectorPageAgent::setEmulatedMedia): 80 * page/Frame.cpp: 81 (WebCore::Frame::setPrinting): 82 * page/FrameView.cpp: 83 (WebCore::FrameView::layout): 84 (WebCore::FrameView::setPagination): 85 (WebCore::FrameView::setViewportSizeForCSSViewportUnits): 86 * page/Page.cpp: 87 (WebCore::Page::setViewMode): 88 (WebCore::Page::setNeedsRecalcStyleInAllFrames): 89 (WebCore::Page::invalidateInjectedStyleSheetCacheInAllFrames): 90 * style/StyleScope.cpp: 91 (WebCore::Style::Scope::setPreferredStylesheetSetName): 92 (WebCore::Style::Scope::setSelectedStylesheetSetName): 93 (WebCore::Style::Scope::removePendingSheet): 94 (WebCore::Style::Scope::removeStyleSheetCandidateNode): 95 (WebCore::Style::Scope::activeStyleSheetsForInspector): 96 (WebCore::Style::Scope::flushPendingUpdate): 97 98 Also flush descendant shadow roots. 99 100 (WebCore::Style::Scope::scheduleUpdate): 101 (WebCore::Style::Scope::didChangeActiveStyleSheetCandidates): 102 103 Make lazy. 104 105 (WebCore::Style::Scope::didChangeStyleSheetContents): 106 107 Make lazy. 108 109 (WebCore::Style::Scope::didChangeStyleSheetEnvironment): 110 111 Environment changes also affect author shadow roots. 112 113 (WebCore::Style::Scope::styleSheetsForStyleSheetList): 114 (WebCore::Style::Scope::scheduleActiveSetUpdate): Deleted. 115 (WebCore::Style::Scope::didChangeCandidatesForActiveSet): Deleted. 116 (WebCore::Style::Scope::didChangeContentsOrInterpretation): Deleted. 117 118 Improved naming of these and split didChangeContentsOrInterpretation into two separate functions. 119 120 * style/StyleScope.h: 121 (WebCore::Style::Scope::styleSheetsForStyleSheetList): Deleted. 122 (WebCore::Style::Scope::setPreferredStylesheetSetName): Deleted. 123 (WebCore::Style::Scope::setSelectedStylesheetSetName): Deleted. 124 * svg/SVGFontFaceElement.cpp: 125 (WebCore::SVGFontFaceElement::rebuildFontFace): 126 (WebCore::SVGFontFaceElement::removedFrom): 127 * testing/Internals.cpp: 128 (WebCore::Internals::resetToConsistentState): 129 130 Ensure that cationsStyleSheetOverride really becomes empty. Some tests rely on not having suprise 131 inserted stylesheets. Previously this was racy and the patch affected order of things. 132 133 (WebCore::Internals::styleChangeType): 134 * xml/XMLTreeViewer.cpp: 135 (WebCore::XMLTreeViewer::transformDocumentToTreeView): 136 * xml/parser/XMLDocumentParser.cpp: 137 (WebCore::XMLDocumentParser::end): 138 * xml/parser/XMLDocumentParserLibxml2.cpp: 139 (WebCore::XMLDocumentParser::doEnd): 140 1 141 2016-10-21 Xabier Rodriguez Calvar <calvaris@igalia.com> and Adam Bergkvist <adam.bergkvist@ericsson.com> 2 142 -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r207630 r207669 2355 2355 } 2356 2356 2357 static inlinebool updateStyleIfNeededForNode(const Node& node)2357 static bool updateStyleIfNeededForNode(const Node& node) 2358 2358 { 2359 2359 Document& document = node.document(); 2360 2361 document.styleScope().flushPendingUpdate(); 2362 2360 2363 if (!document.hasPendingForcedStyleRecalc() && !(document.childNeedsStyleRecalc() && nodeOrItsAncestorNeedsStyleRecalc(node))) 2361 2364 return false; -
trunk/Source/WebCore/css/CSSFontSelector.cpp
r207396 r207669 281 281 FontRanges CSSFontSelector::fontRangesForFamily(const FontDescription& fontDescription, const AtomicString& familyName) 282 282 { 283 ASSERT(!m_buildIsUnderway); // If this ASSERT() fires, it usually means you forgot a document.updateStyleIfNeeded() somewhere. 283 // If this ASSERT() fires, it usually means you forgot a document.updateStyleIfNeeded() somewhere. 284 ASSERT(!m_buildIsUnderway || m_isComputingRootStyleFont); 284 285 285 286 // FIXME: The spec (and Firefox) says user specified generic families (sans-serif etc.) should be resolved before the @font-face lookup too. -
trunk/Source/WebCore/css/CSSFontSelector.h
r205093 r207669 84 84 FontFaceSet& fontFaceSet(); 85 85 86 void setIsComputingRootStyleFont(bool value) { m_isComputingRootStyleFont = value; } 87 86 88 private: 87 89 explicit CSSFontSelector(Document&); … … 113 115 bool m_creatingFont { false }; 114 116 bool m_buildIsUnderway { false }; 117 bool m_isComputingRootStyleFont { false }; 115 118 }; 116 119 -
trunk/Source/WebCore/css/CSSStyleSheet.cpp
r207396 r207669 181 181 return; 182 182 } 183 scope-> scheduleActiveSetUpdate();183 scope->didChangeActiveStyleSheetCandidates(); 184 184 return; 185 185 } 186 186 187 scope->didChange ContentsOrInterpretation();187 scope->didChangeStyleSheetContents(); 188 188 189 189 m_mutatedRules = true; … … 195 195 if (!scope) 196 196 return; 197 scope->didChange ContentsOrInterpretation();197 scope->didChangeStyleSheetContents(); 198 198 } 199 199 … … 218 218 m_isDisabled = disabled; 219 219 220 didMutate(); 220 if (auto* scope = styleScope()) 221 scope->didChangeActiveStyleSheetCandidates(); 221 222 } 222 223 -
trunk/Source/WebCore/css/StyleResolver.cpp
r207539 r207669 269 269 m_mediaQueryEvaluator = MediaQueryEvaluator { "all" }; 270 270 271 if (root) 271 if (root) { 272 272 m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), MatchOnlyUserAgentRules).renderStyle; 273 // Turn off assertion against font lookups during style resolver initialization. We may need root style font for media queries. 274 m_document.fontSelector().setIsComputingRootStyleFont(true); 275 m_rootDefaultStyle->fontCascade().update(&m_document.fontSelector()); 276 m_rootDefaultStyle->fontCascade().primaryFont(); 277 m_document.fontSelector().setIsComputingRootStyleFont(false); 278 } 273 279 274 280 if (m_rootDefaultStyle && view) -
trunk/Source/WebCore/dom/Document.cpp
r207620 r207669 1357 1357 1358 1358 // Recalculate style so language is used when selecting the initial font. 1359 m_styleScope->didChange ContentsOrInterpretation();1359 m_styleScope->didChangeStyleSheetEnvironment(); 1360 1360 } 1361 1361 … … 1966 1966 if (bodyElement && !bodyElement->renderer() && m_pendingSheetLayout == NoLayoutWithPendingSheets) { 1967 1967 m_pendingSheetLayout = DidLayoutWithPendingSheets; 1968 styleScope().didChange ContentsOrInterpretation();1968 styleScope().didChangeActiveStyleSheetCandidates(); 1969 1969 recalcStyle(Style::Force); 1970 1970 } else if (m_hasNodesWithPlaceholderStyle) … … 2103 2103 bool Document::isPageBoxVisible(int pageIndex) 2104 2104 { 2105 updateStyleIfNeeded(); 2105 2106 std::unique_ptr<RenderStyle> pageStyle(styleScope().resolver().styleForPage(pageIndex)); 2106 2107 return pageStyle->visibility() != HIDDEN; // display property doesn't apply to @page. … … 2109 2110 void Document::pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, int& marginLeft) 2110 2111 { 2112 updateStyleIfNeeded(); 2111 2113 std::unique_ptr<RenderStyle> style = styleScope().resolver().styleForPage(pageIndex); 2112 2114 … … 3162 3164 styleScope().setSelectedStylesheetSetName(content); 3163 3165 styleScope().setPreferredStylesheetSetName(content); 3164 styleScope().didChangeContentsOrInterpretation();3165 3166 break; 3166 3167 … … 3472 3473 { 3473 3474 styleScope().setSelectedStylesheetSetName(aString); 3474 styleScope().didChangeContentsOrInterpretation();3475 3475 } 3476 3476 … … 7044 7044 } 7045 7045 7046 void Document::didInsertInDocumentShadowRoot(ShadowRoot& shadowRoot) 7047 { 7048 ASSERT(shadowRoot.inDocument()); 7049 m_inDocumentShadowRoots.add(&shadowRoot); 7050 } 7051 7052 void Document::didRemoveInDocumentShadowRoot(ShadowRoot& shadowRoot) 7053 { 7054 ASSERT(m_inDocumentShadowRoots.contains(&shadowRoot)); 7055 m_inDocumentShadowRoots.remove(&shadowRoot); 7056 } 7057 7046 7058 } // namespace WebCore -
trunk/Source/WebCore/dom/Document.h
r207541 r207669 1297 1297 DOMSelection* getSelection(); 1298 1298 1299 void didInsertInDocumentShadowRoot(ShadowRoot&); 1300 void didRemoveInDocumentShadowRoot(ShadowRoot&); 1301 const HashSet<ShadowRoot*>& inDocumentShadowRoots() const { return m_inDocumentShadowRoots; } 1302 1299 1303 protected: 1300 1304 enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 }; … … 1738 1742 MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying }; 1739 1743 1744 HashSet<ShadowRoot*> m_inDocumentShadowRoots; 1745 1740 1746 #if ENABLE(WIRELESS_PLAYBACK_TARGET) 1741 1747 typedef HashMap<uint64_t, WebCore::MediaPlaybackTargetClient*> TargetIdToClientMap; -
trunk/Source/WebCore/dom/Element.cpp
r207544 r207669 2703 2703 const RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier) 2704 2704 { 2705 if (!inDocument()) 2706 return nullptr; 2707 2705 2708 if (PseudoElement* pseudoElement = beforeOrAfterPseudoElement(*this, pseudoElementSpecifier)) 2706 2709 return pseudoElement->computedStyle(); 2707 2710 2708 2711 auto* style = existingComputedStyle(); 2709 if (!style) { 2710 if (!inDocument()) 2711 return nullptr; 2712 if (!style) 2712 2713 style = &resolveComputedStyle(); 2713 }2714 2714 2715 2715 if (pseudoElementSpecifier) { -
trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp
r207339 r207669 56 56 ExtensionStyleSheets::ExtensionStyleSheets(Document& document) 57 57 : m_document(document) 58 , m_styleResolverChangedTimer(*this, &ExtensionStyleSheets::styleResolverChangedTimerFired)59 58 { 60 59 } … … 93 92 if (m_pageUserSheet) { 94 93 m_pageUserSheet = nullptr; 95 m_document.styleScope().didChange ContentsOrInterpretation();94 m_document.styleScope().didChangeStyleSheetEnvironment(); 96 95 } 97 96 } … … 101 100 clearPageUserSheet(); 102 101 if (pageUserSheet()) 103 m_document.styleScope().didChange ContentsOrInterpretation();102 m_document.styleScope().didChangeStyleSheetEnvironment(); 104 103 } 105 104 … … 155 154 void ExtensionStyleSheets::invalidateInjectedStyleSheetCache() 156 155 { 157 if (!m_injectedStyleSheetCacheValid)158 return;159 156 m_injectedStyleSheetCacheValid = false; 160 if (m_injectedUserStyleSheets.isEmpty() && m_injectedAuthorStyleSheets.isEmpty()) 161 return; 162 m_document.styleScope().didChangeContentsOrInterpretation(); 157 m_document.styleScope().didChangeStyleSheetEnvironment(); 163 158 } 164 159 … … 167 162 ASSERT(userSheet.get().isUserStyleSheet()); 168 163 m_userStyleSheets.append(CSSStyleSheet::create(WTFMove(userSheet), m_document)); 169 m_document.styleScope().didChange ContentsOrInterpretation();164 m_document.styleScope().didChangeStyleSheetEnvironment(); 170 165 } 171 166 … … 174 169 ASSERT(!authorSheet.get().isUserStyleSheet()); 175 170 m_authorStyleSheetsForTesting.append(CSSStyleSheet::create(WTFMove(authorSheet), m_document)); 176 m_document.styleScope().didChange ContentsOrInterpretation();171 m_document.styleScope().didChangeStyleSheetEnvironment(); 177 172 } 178 173 … … 187 182 188 183 if (result.iterator->value->addDisplayNoneSelector(selector, selectorID)) 189 m_ styleResolverChangedTimer.startOneShot(0);184 m_document.styleScope().didChangeStyleSheetEnvironment(); 190 185 } 191 186 … … 200 195 m_contentExtensionSheets.set(identifier, &cssSheet.get()); 201 196 m_userStyleSheets.append(adoptRef(cssSheet.leakRef())); 202 m_styleResolverChangedTimer.startOneShot(0); 197 m_document.styleScope().didChangeStyleSheetEnvironment(); 198 203 199 } 204 200 #endif // ENABLE(CONTENT_EXTENSIONS) 205 206 void ExtensionStyleSheets::styleResolverChangedTimerFired()207 {208 m_document.styleScope().didChangeContentsOrInterpretation();209 }210 201 211 202 void ExtensionStyleSheets::detachFromDocument() -
trunk/Source/WebCore/dom/ExtensionStyleSheets.h
r204466 r207669 78 78 79 79 private: 80 void styleResolverChangedTimerFired();81 82 80 Document& m_document; 83 81 … … 95 93 HashMap<String, RefPtr<ContentExtensions::ContentExtensionStyleSheet>> m_contentExtensionSelectorSheets; 96 94 #endif 97 98 Timer m_styleResolverChangedTimer;99 95 }; 100 96 -
trunk/Source/WebCore/dom/ProcessingInstruction.cpp
r207053 r207669 157 157 m_loading = false; 158 158 document().styleScope().removePendingSheet(); 159 #if ENABLE(XSLT) 160 if (m_isXSL) 161 document().styleScope().flushPendingUpdate(); 162 #endif 159 163 } 160 164 } … … 175 179 if (!isLoading()) { 176 180 document().styleScope().removePendingSheet(); 181 #if ENABLE(XSLT) 182 if (m_isXSL) 183 document().styleScope().flushPendingUpdate(); 184 #endif 177 185 return true; 178 186 } … … 273 281 } 274 282 275 // If we're in document teardown, then we don't need to do any notification of our sheet's removal. 276 if (document().hasLivingRenderTree()) 277 document().styleScope().didChangeContentsOrInterpretation(); 283 document().styleScope().didChangeActiveStyleSheetCandidates(); 278 284 } 279 285 -
trunk/Source/WebCore/dom/ShadowRoot.cpp
r207458 r207669 53 53 , TreeScope(*this, document) 54 54 , m_type(type) 55 , m_styleScope(std::make_unique<Style::Scope>(*this)) 55 56 { 56 57 } … … 61 62 , TreeScope(*this, document) 62 63 , m_type(Mode::UserAgent) 64 , m_styleScope(std::make_unique<Style::Scope>(*this)) 63 65 , m_slotAssignment(WTFMove(slotAssignment)) 64 66 { … … 80 82 } 81 83 84 Node::InsertionNotificationRequest ShadowRoot::insertedInto(ContainerNode& insertionPoint) 85 { 86 auto result = DocumentFragment::insertedInto(insertionPoint); 87 if (inDocument()) 88 document().didInsertInDocumentShadowRoot(*this); 89 return result; 90 } 91 92 void ShadowRoot::removedFrom(ContainerNode& insertionPoint) 93 { 94 if (inDocument()) 95 document().didRemoveInDocumentShadowRoot(*this); 96 DocumentFragment::removedFrom(insertionPoint); 97 } 98 82 99 Style::Scope& ShadowRoot::styleScope() 83 100 { 84 if (!m_styleScope)85 m_styleScope = std::make_unique<Style::Scope>(*this);86 101 return *m_styleScope; 87 102 } -
trunk/Source/WebCore/dom/ShadowRoot.h
r206951 r207669 105 105 Ref<Node> cloneNodeInternal(Document&, CloningOperation) override; 106 106 107 Node::InsertionNotificationRequest insertedInto(ContainerNode& insertionPoint) override; 108 void removedFrom(ContainerNode& insertionPoint) override; 109 107 110 bool m_resetStyleInheritance { false }; 108 111 Mode m_type { Mode::UserAgent }; -
trunk/Source/WebCore/html/HTMLLinkElement.cpp
r207458 r207669 141 141 process(); 142 142 else 143 document().styleScope().didChange ContentsOrInterpretation();143 document().styleScope().didChangeActiveStyleSheetCandidates(); 144 144 } 145 145 } … … 177 177 process(); 178 178 if (m_sheet && !isDisabled()) 179 document().styleScope().didChange ContentsOrInterpretation();179 document().styleScope().didChangeActiveStyleSheetCandidates(); 180 180 return; 181 181 } … … 284 284 // we no longer contain a stylesheet, e.g. perhaps rel or type was changed 285 285 clearSheet(); 286 document().styleScope().didChange ContentsOrInterpretation();286 document().styleScope().didChangeActiveStyleSheetCandidates(); 287 287 } 288 288 } … … 558 558 if (type == InactiveSheet) { 559 559 // Document just needs to know about the sheet for exposure through document.styleSheets 560 document().styleScope().didChange CandidatesForActiveSet();560 document().styleScope().didChangeActiveStyleSheetCandidates(); 561 561 return; 562 562 } -
trunk/Source/WebCore/html/HTMLStyleElement.cpp
r206917 r207669 78 78 sheet()->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(value)); 79 79 if (auto* scope = m_styleSheetOwner.styleScope()) 80 scope->didChange ContentsOrInterpretation();80 scope->didChangeStyleSheetContents(); 81 81 } else 82 82 m_styleSheetOwner.childrenChanged(*this); -
trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp
r206917 r207669 798 798 ExceptionCode ec = 0; 799 799 targetNode->appendChild(styleElement, ec); 800 document.styleScope().flushPendingUpdate(); 800 801 m_creatingViaInspectorStyleSheet = false; 801 802 if (ec) … … 890 891 else 891 892 m_nodeIdToForcedPseudoState.remove(nodeId); 892 element->document().styleScope().didChange ContentsOrInterpretation();893 element->document().styleScope().didChangeStyleSheetEnvironment(); 893 894 } 894 895 … … 1190 1191 m_nodeIdToForcedPseudoState.clear(); 1191 1192 for (auto& document : documentsToChange) 1192 document->styleScope().didChange ContentsOrInterpretation();1193 document->styleScope().didChangeStyleSheetEnvironment(); 1193 1194 } 1194 1195 -
trunk/Source/WebCore/inspector/InspectorPageAgent.cpp
r206917 r207669 1003 1003 Document* document = m_page.mainFrame().document(); 1004 1004 if (document) { 1005 document->styleScope().didChange ContentsOrInterpretation();1005 document->styleScope().didChangeStyleSheetEnvironment(); 1006 1006 document->updateLayout(); 1007 1007 } -
trunk/Source/WebCore/page/Frame.cpp
r207620 r207669 645 645 view()->adjustMediaTypeForPrinting(printing); 646 646 647 m_doc->styleScope().didChange ContentsOrInterpretation();647 m_doc->styleScope().didChangeStyleSheetEnvironment(); 648 648 if (shouldUsePrintingLayout()) { 649 649 view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize); -
trunk/Source/WebCore/page/FrameView.cpp
r206951 r207669 1336 1336 if (!styleResolver || styleResolver->hasMediaQueriesAffectedByViewportChange()) { 1337 1337 LOG(Layout, " hasMediaQueriesAffectedByViewportChange, enqueueing style recalc"); 1338 document.styleScope().didChange ContentsOrInterpretation();1338 document.styleScope().didChangeStyleSheetEnvironment(); 1339 1339 // FIXME: This instrumentation event is not strictly accurate since cached media query results do not persist across StyleResolver rebuilds. 1340 1340 InspectorInstrumentation::mediaQueryResultChanged(document); … … 3533 3533 m_pagination = pagination; 3534 3534 3535 frame().document()->styleScope().didChange ContentsOrInterpretation();3535 frame().document()->styleScope().didChangeStyleSheetEnvironment(); 3536 3536 } 3537 3537 … … 4999 4999 m_hasOverrideViewportSize = true; 5000 5000 5001 if (Document* document = frame().document()) { 5002 // FIXME: this should probably be updateViewportUnitsOnResize(), but synchronously 5003 // dirtying style here causes assertions on iOS (rdar://problem/19998166). 5004 document->styleScope().didChangeContentsOrInterpretation(); 5005 } 5001 if (Document* document = frame().document()) 5002 document->styleScope().didChangeStyleSheetEnvironment(); 5006 5003 } 5007 5004 -
trunk/Source/WebCore/page/Page.cpp
r207620 r207669 425 425 426 426 if (m_mainFrame->document()) 427 m_mainFrame->document()->styleScope().didChange ContentsOrInterpretation();427 m_mainFrame->document()->styleScope().didChangeStyleSheetEnvironment(); 428 428 } 429 429 #endif // ENABLE(VIEW_MODE_CSS_MEDIA) … … 501 501 void Page::setNeedsRecalcStyleInAllFrames() 502 502 { 503 // FIXME: Figure out what this function is actually trying to add in different call sites. 503 504 for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) { 504 505 if (Document* document = frame->document()) 505 document->styleScope().didChange ContentsOrInterpretation();506 document->styleScope().didChangeStyleSheetEnvironment(); 506 507 } 507 508 } … … 1160 1161 continue; 1161 1162 document->extensionStyleSheets().invalidateInjectedStyleSheetCache(); 1162 document->styleScope().didChangeContentsOrInterpretation();1163 1163 } 1164 1164 } -
trunk/Source/WebCore/style/StyleScope.cpp
r207458 r207669 72 72 } 73 73 74 Scope::~Scope() 75 { 76 } 77 74 78 bool Scope::shouldUseSharedUserAgentShadowTreeStyleResolver() const 75 79 { … … 121 125 } 122 126 127 void Scope::setPreferredStylesheetSetName(const String& name) 128 { 129 if (m_preferredStylesheetSetName == name) 130 return; 131 m_preferredStylesheetSetName = name; 132 didChangeActiveStyleSheetCandidates(); 133 } 134 135 void Scope::setSelectedStylesheetSetName(const String& name) 136 { 137 if (m_selectedStylesheetSetName == name) 138 return; 139 m_selectedStylesheetSetName = name; 140 didChangeActiveStyleSheetCandidates(); 141 } 142 123 143 // This method is called whenever a top-level stylesheet has finished loading. 124 144 void Scope::removePendingSheet(RemovePendingSheetNotificationType notification) … … 142 162 } 143 163 144 didChange CandidatesForActiveSet();164 didChangeActiveStyleSheetCandidates(); 145 165 146 166 if (!m_shadowRoot) … … 184 204 { 185 205 if (m_styleSheetCandidateNodes.remove(&node)) 186 scheduleActiveSetUpdate();206 didChangeActiveStyleSheetCandidates(); 187 207 } 188 208 … … 339 359 void Scope::updateActiveStyleSheets(UpdateType updateType) 340 360 { 341 ASSERT(!m_pendingUpdateType); 361 ASSERT(!m_pendingUpdate); 362 363 if (!m_document.hasLivingRenderTree()) 364 return; 342 365 343 366 if (m_document.inStyleRecalc() || m_document.inRenderTreeUpdate()) { … … 345 368 // Crash stacks indicate we can get here when a resource load fails synchronously (for example due to content blocking). 346 369 // FIXME: These kind of cases should be eliminated and this path replaced by an assert. 347 m_pendingUpdate Type= UpdateType::ContentsOrInterpretation;370 m_pendingUpdate = UpdateType::ContentsOrInterpretation; 348 371 m_document.scheduleForcedStyleRecalc(); 349 return;350 }351 352 if (!m_document.hasLivingRenderTree()) {353 clearResolver();354 372 return; 355 373 } … … 419 437 } 420 438 421 const Vector<RefPtr<CSSStyleSheet>> Scope::activeStyleSheetsForInspector() const439 const Vector<RefPtr<CSSStyleSheet>> Scope::activeStyleSheetsForInspector() 422 440 { 423 441 Vector<RefPtr<CSSStyleSheet>> result; … … 452 470 void Scope::flushPendingUpdate() 453 471 { 454 if (!m_pendingUpdateType) 455 return; 456 auto updateType = *m_pendingUpdateType; 472 if (!m_shadowRoot) { 473 for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots()) 474 descendantShadowRoot->styleScope().flushPendingUpdate(); 475 } 476 if (!m_pendingUpdate) 477 return; 478 auto updateType = *m_pendingUpdate; 457 479 458 480 clearPendingUpdate(); … … 464 486 { 465 487 m_pendingUpdateTimer.stop(); 466 m_pendingUpdateType = { }; 467 } 468 469 void Scope::scheduleActiveSetUpdate() 470 { 471 if (m_shadowRoot) { 472 // FIXME: We need to flush updates recursively to support asynchronous updates in shadow trees. 473 didChangeCandidatesForActiveSet(); 474 return; 475 } 488 m_pendingUpdate = { }; 489 } 490 491 void Scope::scheduleUpdate(UpdateType update) 492 { 493 if (!m_pendingUpdate || *m_pendingUpdate < update) 494 m_pendingUpdate = update; 495 476 496 if (m_pendingUpdateTimer.isActive()) 477 497 return; 478 if (!m_pendingUpdateType)479 m_pendingUpdateType = UpdateType::ActiveSet;480 498 m_pendingUpdateTimer.startOneShot(0); 481 499 } 482 500 483 void Scope::didChangeCandidatesForActiveSet() 484 { 485 auto updateType = m_pendingUpdateType.valueOr(UpdateType::ActiveSet); 486 clearPendingUpdate(); 487 updateActiveStyleSheets(updateType); 488 } 489 490 void Scope::didChangeContentsOrInterpretation() 491 { 492 clearPendingUpdate(); 493 updateActiveStyleSheets(UpdateType::ContentsOrInterpretation); 501 void Scope::didChangeActiveStyleSheetCandidates() 502 { 503 scheduleUpdate(UpdateType::ActiveSet); 504 } 505 506 void Scope::didChangeStyleSheetContents() 507 { 508 scheduleUpdate(UpdateType::ContentsOrInterpretation); 509 } 510 511 void Scope::didChangeStyleSheetEnvironment() 512 { 513 if (!m_shadowRoot) { 514 for (auto* descendantShadowRoot : m_document.inDocumentShadowRoots()) { 515 // Stylesheets is author shadow roots are are potentially affected. 516 if (descendantShadowRoot->mode() != ShadowRoot::Mode::UserAgent) 517 descendantShadowRoot->styleScope().scheduleUpdate(UpdateType::ContentsOrInterpretation); 518 } 519 } 520 scheduleUpdate(UpdateType::ContentsOrInterpretation); 494 521 } 495 522 … … 499 526 } 500 527 501 } 502 } 528 const Vector<RefPtr<StyleSheet>>& Scope::styleSheetsForStyleSheetList() 529 { 530 // FIXME: StyleSheetList content should be updated separately from style resolver updates. 531 flushPendingUpdate(); 532 return m_styleSheetsForStyleSheetList; 533 } 534 535 } 536 } -
trunk/Source/WebCore/style/StyleScope.h
r207280 r207669 57 57 explicit Scope(ShadowRoot&); 58 58 59 ~Scope(); 60 59 61 const Vector<RefPtr<CSSStyleSheet>>& activeStyleSheets() const { return m_activeStyleSheets; } 60 62 61 const Vector<RefPtr<StyleSheet>>& styleSheetsForStyleSheetList() const { return m_styleSheetsForStyleSheetList; }62 const Vector<RefPtr<CSSStyleSheet>> activeStyleSheetsForInspector() const;63 const Vector<RefPtr<StyleSheet>>& styleSheetsForStyleSheetList(); 64 const Vector<RefPtr<CSSStyleSheet>> activeStyleSheetsForInspector(); 63 65 64 66 void addStyleSheetCandidateNode(Node&, bool createdByParser); … … 67 69 String preferredStylesheetSetName() const { return m_preferredStylesheetSetName; } 68 70 String selectedStylesheetSetName() const { return m_selectedStylesheetSetName; } 69 void setPreferredStylesheetSetName(const String& name) { m_preferredStylesheetSetName = name; }70 void setSelectedStylesheetSetName(const String& name) { m_selectedStylesheetSetName = name; }71 void setPreferredStylesheetSetName(const String&); 72 void setSelectedStylesheetSetName(const String&); 71 73 72 74 void addPendingSheet() { m_pendingStyleSheetCount++; } … … 83 85 bool activeStyleSheetsContains(const CSSStyleSheet*) const; 84 86 85 void didChangeCandidatesForActiveSet(); 86 void scheduleActiveSetUpdate(); 87 WEBCORE_EXPORT void didChangeContentsOrInterpretation(); 87 // This is called when some stylesheet becomes newly enabled or disabled. 88 void didChangeActiveStyleSheetCandidates(); 89 // This is called when contents of a stylesheet is mutated. 90 void didChangeStyleSheetContents(); 91 // This is called when the environment where we intrepret the stylesheets changes (for example switching to printing). 92 // The change is assumed to potentially affect all author and user stylesheets including shadow roots. 93 WEBCORE_EXPORT void didChangeStyleSheetEnvironment(); 88 94 89 bool hasPendingUpdate() const { return !!m_pendingUpdate Type; }90 void flushPendingUpdate();95 bool hasPendingUpdate() const { return !!m_pendingUpdate; } 96 WEBCORE_EXPORT void flushPendingUpdate(); 91 97 92 98 StyleResolver& resolver(); … … 101 107 enum class UpdateType { ActiveSet, ContentsOrInterpretation }; 102 108 void updateActiveStyleSheets(UpdateType); 109 void scheduleUpdate(UpdateType); 103 110 104 111 void collectActiveStyleSheets(Vector<RefPtr<StyleSheet>>&); … … 134 141 bool m_didUpdateActiveStyleSheets { false }; 135 142 136 Optional<UpdateType> m_pendingUpdate Type;143 Optional<UpdateType> m_pendingUpdate; 137 144 138 145 ListHashSet<Node*> m_styleSheetCandidateNodes; -
trunk/Source/WebCore/svg/SVGFontFaceElement.cpp
r206917 r207669 268 268 } 269 269 270 document().styleScope().didChange ContentsOrInterpretation();270 document().styleScope().didChangeStyleSheetEnvironment(); 271 271 } 272 272 … … 293 293 m_fontFaceRule->mutableProperties().clear(); 294 294 295 document().styleScope().didChange ContentsOrInterpretation();295 document().styleScope().didChangeStyleSheetEnvironment(); 296 296 } else 297 297 ASSERT(!m_fontElement); -
trunk/Source/WebCore/testing/Internals.cpp
r207521 r207669 119 119 #include "SpellChecker.h" 120 120 #include "StaticNodeList.h" 121 #include "StyleScope.h" 121 122 #include "StyleSheetContents.h" 122 123 #include "TextIterator.h" … … 382 383 WebCore::Settings::setUsesMockScrollAnimator(false); 383 384 #if ENABLE(VIDEO_TRACK) 385 page.group().captionPreferences().setTestingMode(true); 384 386 page.group().captionPreferences().setCaptionsStyleSheetOverride(emptyString()); 385 387 page.group().captionPreferences().setTestingMode(false); … … 502 504 String Internals::styleChangeType(Node& node) 503 505 { 506 node.document().styleScope().flushPendingUpdate(); 507 504 508 return styleValidityToToString(node.styleValidity()); 505 509 } -
trunk/Source/WebCore/xml/XMLTreeViewer.cpp
r206917 r207669 65 65 auto text = m_document.createTextNode(cssString); 66 66 m_document.getElementById(String(ASCIILiteral("xml-viewer-style")))->appendChild(text, IGNORE_EXCEPTION); 67 m_document.styleScope().didChange ContentsOrInterpretation();67 m_document.styleScope().didChangeActiveStyleSheetCandidates(); 68 68 } 69 69 -
trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp
r206917 r207669 201 201 else { 202 202 updateLeafTextNode(); 203 document()->styleScope().didChange ContentsOrInterpretation();203 document()->styleScope().didChangeActiveStyleSheetCandidates(); 204 204 } 205 205 -
trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
r206917 r207669 1388 1388 1389 1389 document()->setParsing(false); // Make the document think it's done, so it will apply XSL stylesheets. 1390 document()->styleScope().didChange ContentsOrInterpretation();1390 document()->styleScope().didChangeActiveStyleSheetCandidates(); 1391 1391 1392 1392 // styleResolverChanged() call can detach the parser and null out its document. -
trunk/Source/WebKit/mac/WebView/WebHTMLView.mm
r207483 r207669 3613 3613 3614 3614 if (Frame* coreFrame = core([self _frame])) { 3615 coreFrame->document()->styleScope().didChange ContentsOrInterpretation();3615 coreFrame->document()->styleScope().didChangeStyleSheetEnvironment(); 3616 3616 coreFrame->document()->updateStyleIfNeeded(); 3617 3617 } … … 5025 5025 document->setPaginatedForScreen(_private->paginateScreenContent); 5026 5026 document->setPrinting(_private->printing); 5027 document->styleScope().didChange ContentsOrInterpretation();5027 document->styleScope().didChangeStyleSheetEnvironment(); 5028 5028 } 5029 5029 }
Note: See TracChangeset
for help on using the changeset viewer.