Changeset 213515 in webkit
- Timestamp:
- Mar 7, 2017, 8:54:56 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r213514 r213515 1 2017-03-07 Antti Koivisto <antti@apple.com> 2 3 Differentiate between pending head and body stylesheets in Style::Scope 4 https://bugs.webkit.org/show_bug.cgi?id=169277 5 6 Reviewed by Andreas Kling. 7 8 Split pending stylesheet node set into separate sets for head and body elements and processing instructions. 9 10 This tightens typing and will also be useful later. 11 12 * style/StyleScope.cpp: 13 (WebCore::Style::Scope::~Scope): 14 (WebCore::Style::Scope::addPendingSheet): 15 (WebCore::Style::Scope::removePendingSheet): 16 (WebCore::Style::Scope::didRemovePendingStylesheet): 17 (WebCore::Style::Scope::hasPendingSheet): 18 (WebCore::Style::Scope::hasPendingSheetInBody): 19 (WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet): Deleted. 20 * style/StyleScope.h: 21 (WebCore::Style::Scope::hasPendingSheet): Deleted. 22 (WebCore::Style::Scope::hasPendingSheets): Deleted. 23 * style/StyleTreeResolver.cpp: 24 (WebCore::Style::hasLoadingStylesheet): 25 26 Just test for body stylesheets. 27 28 (WebCore::Style::TreeResolver::resolve): 29 30 Treat all before-body stylesheets uniformly. 31 1 32 2017-03-07 Antoine Quint <graouts@apple.com> 2 33 -
trunk/Source/WebCore/style/StyleScope.cpp
r213446 r213515 33 33 #include "ElementChildIterator.h" 34 34 #include "ExtensionStyleSheets.h" 35 #include "HTMLHeadElement.h" 35 36 #include "HTMLIFrameElement.h" 36 37 #include "HTMLLinkElement.h" … … 73 74 Scope::~Scope() 74 75 { 75 ASSERT( m_nodesWithPendingSheets.isEmpty());76 ASSERT(!hasPendingSheets()); 76 77 } 77 78 … … 173 174 } 174 175 175 void Scope::addPendingSheet(const Node& node) 176 { 177 ASSERT(!m_nodesWithPendingSheets.contains(&node)); 178 179 m_nodesWithPendingSheets.add(&node); 176 177 void Scope::addPendingSheet(const Element& element) 178 { 179 ASSERT(!hasPendingSheet(element)); 180 181 bool isInHead = ancestorsOfType<HTMLHeadElement>(element).first(); 182 if (isInHead) 183 m_elementsInHeadWithPendingSheets.add(&element); 184 else 185 m_elementsInBodyWithPendingSheets.add(&element); 180 186 } 181 187 182 188 // This method is called whenever a top-level stylesheet has finished loading. 183 void Scope::removePendingSheet(const Node& node) 184 { 185 ASSERT(m_nodesWithPendingSheets.contains(&node)); 186 187 m_nodesWithPendingSheets.remove(&node); 188 if (!m_nodesWithPendingSheets.isEmpty()) 189 void Scope::removePendingSheet(const Element& element) 190 { 191 ASSERT(hasPendingSheet(element)); 192 193 if (!m_elementsInHeadWithPendingSheets.remove(&element)) 194 m_elementsInBodyWithPendingSheets.remove(&element); 195 196 didRemovePendingStylesheet(); 197 } 198 199 void Scope::addPendingSheet(const ProcessingInstruction& processingInstruction) 200 { 201 ASSERT(!m_processingInstructionsWithPendingSheets.contains(&processingInstruction)); 202 203 m_processingInstructionsWithPendingSheets.add(&processingInstruction); 204 } 205 206 void Scope::removePendingSheet(const ProcessingInstruction& processingInstruction) 207 { 208 ASSERT(m_processingInstructionsWithPendingSheets.contains(&processingInstruction)); 209 210 m_processingInstructionsWithPendingSheets.remove(&processingInstruction); 211 212 didRemovePendingStylesheet(); 213 } 214 215 void Scope::didRemovePendingStylesheet() 216 { 217 if (hasPendingSheets()) 189 218 return; 190 219 … … 195 224 } 196 225 197 bool Scope::hasProcessingInstructionWithPendingSheet() 198 { 199 ASSERT(!m_shadowRoot); 200 201 for (auto* child = m_document.firstChild(); child; child = child->nextSibling()) { 202 if (is<Element>(*child)) 203 return false; 204 if (m_nodesWithPendingSheets.contains(child)) { 205 ASSERT(is<ProcessingInstruction>(*child)); 206 return true; 207 } 208 } 209 return false; 226 bool Scope::hasPendingSheet(const Element& element) const 227 { 228 return m_elementsInHeadWithPendingSheets.contains(&element) || hasPendingSheetInBody(element); 229 } 230 231 bool Scope::hasPendingSheetInBody(const Element& element) const 232 { 233 return m_elementsInBodyWithPendingSheets.contains(&element); 210 234 } 211 235 -
trunk/Source/WebCore/style/StyleScope.h
r213446 r213515 44 44 class Element; 45 45 class Node; 46 class ProcessingInstruction; 46 47 class StyleResolver; 47 48 class StyleSheet; … … 83 84 void setSelectedStylesheetSetName(const String&); 84 85 85 void addPendingSheet(const Node&); 86 void removePendingSheet(const Node&); 87 bool hasPendingSheet(const Node& node) const { return m_nodesWithPendingSheets.contains(&node); } 88 bool hasProcessingInstructionWithPendingSheet(); 89 bool hasPendingSheets() const { return !m_nodesWithPendingSheets.isEmpty(); } 86 void addPendingSheet(const Element&); 87 void removePendingSheet(const Element&); 88 void addPendingSheet(const ProcessingInstruction&); 89 void removePendingSheet(const ProcessingInstruction&); 90 bool hasPendingSheets() const; 91 bool hasPendingSheetsBeforeBody() const; 92 bool hasPendingSheetsInBody() const; 93 bool hasPendingSheet(const Element&) const; 94 bool hasPendingSheetInBody(const Element&) const; 90 95 91 96 bool usesStyleBasedEditability() { return m_usesStyleBasedEditability; } … … 116 121 bool shouldUseSharedUserAgentShadowTreeStyleResolver() const; 117 122 123 void didRemovePendingStylesheet(); 124 118 125 enum class UpdateType { ActiveSet, ContentsOrInterpretation }; 119 126 void updateActiveStyleSheets(UpdateType); … … 144 151 Vector<RefPtr<CSSStyleSheet>> m_activeStyleSheets; 145 152 146 147 153 Timer m_pendingUpdateTimer; 148 154 … … 153 159 // We use this count of pending sheets to detect when we can begin attaching 154 160 // elements and when it is safe to execute scripts. 155 HashSet<const Node*> m_nodesWithPendingSheets; 161 HashSet<const ProcessingInstruction*> m_processingInstructionsWithPendingSheets; 162 HashSet<const Element*> m_elementsInHeadWithPendingSheets; 163 HashSet<const Element*> m_elementsInBodyWithPendingSheets; 156 164 157 165 bool m_didUpdateActiveStyleSheets { false }; … … 168 176 bool m_isUpdatingStyleResolver { false }; 169 177 }; 178 179 inline bool Scope::hasPendingSheets() const 180 { 181 return hasPendingSheetsBeforeBody() || !m_elementsInBodyWithPendingSheets.isEmpty(); 182 } 183 184 inline bool Scope::hasPendingSheetsBeforeBody() const 185 { 186 return !m_elementsInHeadWithPendingSheets.isEmpty() || !m_processingInstructionsWithPendingSheets.isEmpty(); 187 } 188 189 inline bool Scope::hasPendingSheetsInBody() const 190 { 191 return !m_elementsInBodyWithPendingSheets.isEmpty(); 192 } 170 193 171 194 inline void Scope::flushPendingUpdate() -
trunk/Source/WebCore/style/StyleTreeResolver.cpp
r213446 r213515 362 362 static bool hasLoadingStylesheet(const Style::Scope& styleScope, const Element& element, bool checkDescendants) 363 363 { 364 if (!styleScope.hasPendingSheets ())364 if (!styleScope.hasPendingSheetsInBody()) 365 365 return false; 366 if (styleScope.hasPendingSheet (element))366 if (styleScope.hasPendingSheetInBody(element)) 367 367 return true; 368 368 if (!checkDescendants) 369 369 return false; 370 370 for (auto& descendant : descendantsOfType<Element>(element)) { 371 if (styleScope.hasPendingSheet (descendant))371 if (styleScope.hasPendingSheetInBody(descendant)) 372 372 return true; 373 373 }; … … 483 483 return nullptr; 484 484 485 m_didSeePendingStylesheet = m_document.styleScope().hasP rocessingInstructionWithPendingSheet();485 m_didSeePendingStylesheet = m_document.styleScope().hasPendingSheetsBeforeBody(); 486 486 487 487 m_update = std::make_unique<Update>(m_document);
Note:
See TracChangeset
for help on using the changeset viewer.