Changeset 251632 in webkit
- Timestamp:
- Oct 26, 2019, 5:47:05 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
css/StyleResolver.cpp (modified) (7 diffs)
-
style/PropertyCascade.cpp (modified) (13 diffs)
-
style/PropertyCascade.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251630 r251632 1 2019-10-26 Antti Koivisto <antti@apple.com> 2 3 Build cascade in PropertyCascade constructor 4 https://bugs.webkit.org/show_bug.cgi?id=203455 5 6 Reviewed by Zalan Bujtas. 7 8 Instead of calling addNormalMatches/addImportantMatches several times, clients now simply 9 pass the desired cascade levels to the constructor. 10 11 * css/StyleResolver.cpp: 12 (WebCore::StyleResolver::styleForKeyframe): 13 (WebCore::StyleResolver::styleForPage): 14 (WebCore::StyleResolver::applyMatchedProperties): 15 (WebCore::StyleResolver::applyPropertyToCurrentStyle): 16 * style/PropertyCascade.cpp: 17 (WebCore::Style::PropertyCascade::PropertyCascade): 18 (WebCore::Style::PropertyCascade::addMatch): 19 (WebCore::Style::PropertyCascade::addNormalMatches): 20 21 Return if there were any important matches so we may skip the step later. 22 23 (WebCore::Style::PropertyCascade::addImportantMatches): 24 (WebCore::Style::PropertyCascade::applyDeferredProperties): 25 (WebCore::Style::PropertyCascade::applyPropertiesImpl): 26 (WebCore::Style::PropertyCascade::propertyCascadeForRollback): 27 (WebCore::Style::PropertyCascade::applyProperty): 28 (WebCore::Style::PropertyCascade::Property::apply): Deleted. 29 30 Also make this PropertyCascade::applyProperty 31 32 * style/PropertyCascade.h: 33 1 34 2019-10-26 Chris Lord <clord@igalia.com> 2 35 -
trunk/Source/WebCore/css/StyleResolver.cpp
r251611 r251632 373 373 extractDirectionAndWritingMode(*state.style(), result, direction, writingMode); 374 374 375 // We don't need to bother with !important. Since there is only ever one 376 // decl, there's nothing to override. So just add the first properties. 377 Style::PropertyCascade cascade(*this, result, direction, writingMode); 378 cascade.addNormalMatches(Style::CascadeLevel::Author); 375 Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }, direction, writingMode); 379 376 380 377 cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty); … … 580 577 extractDirectionAndWritingMode(*m_state.style(), result, direction, writingMode); 581 578 582 Style::PropertyCascade cascade(*this, result, direction, writingMode); 583 cascade.addNormalMatches(Style::CascadeLevel::Author); 579 Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }, direction, writingMode); 584 580 585 581 cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty); … … 1350 1346 State& state = m_state; 1351 1347 unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult) : 0; 1352 bool applyInheritedOnly = false; 1348 auto includedProperties = Style::PropertyCascade::IncludedProperties::All; 1349 1353 1350 const MatchedPropertiesCacheItem* cacheItem = nullptr; 1354 1351 if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult)) … … 1368 1365 return; 1369 1366 } 1370 applyInheritedOnly = true;1367 includedProperties = Style::PropertyCascade::IncludedProperties::InheritedOnly; 1371 1368 } 1372 1369 … … 1382 1379 // If so, we cache the border and background styles so that RenderTheme::adjustStyle() 1383 1380 // can look at them later to figure out if this is a styled form control or not. 1384 Style::PropertyCascade cascade(*this, matchResult, direction, writingMode); 1385 cascade.addNormalMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly); 1386 cascade.addImportantMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly); 1381 Style::PropertyCascade cascade(*this, matchResult, { Style::CascadeLevel::UserAgent }, direction, writingMode, includedProperties); 1387 1382 1388 1383 cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition); … … 1407 1402 } 1408 1403 1409 Style::PropertyCascade cascade(*this, matchResult, direction, writingMode); 1410 cascade.addNormalMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly); 1411 cascade.addNormalMatches(Style::CascadeLevel::User, applyInheritedOnly); 1412 cascade.addNormalMatches(Style::CascadeLevel::Author, applyInheritedOnly); 1413 cascade.addImportantMatches(Style::CascadeLevel::Author, applyInheritedOnly); 1414 cascade.addImportantMatches(Style::CascadeLevel::User, applyInheritedOnly); 1415 cascade.addImportantMatches(Style::CascadeLevel::UserAgent, applyInheritedOnly); 1404 Style::PropertyCascade cascade(*this, matchResult, Style::allCascadeLevels(), direction, writingMode, includedProperties); 1416 1405 1417 1406 cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition); … … 1466 1455 { 1467 1456 MatchResult matchResult; 1468 Style::PropertyCascade cascade(*this, matchResult, { }, { } );1457 Style::PropertyCascade cascade(*this, matchResult, { }, { }, { }); 1469 1458 if (value) 1470 1459 applyProperty(id, value, cascade); -
trunk/Source/WebCore/style/PropertyCascade.cpp
r251611 r251632 141 141 #endif 142 142 143 PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, TextDirection direction, WritingMode writingMode)143 PropertyCascade::PropertyCascade(StyleResolver& styleResolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, TextDirection direction, WritingMode writingMode, IncludedProperties includedProperties) 144 144 : m_styleResolver(styleResolver) 145 145 , m_matchResult(matchResult) 146 , m_includedProperties(includedProperties) 146 147 , m_direction(direction) 147 148 , m_writingMode(writingMode) 148 149 { 150 OptionSet<CascadeLevel> cascadeLevelsWithImportant; 151 152 for (auto cascadeLevel : cascadeLevels) { 153 bool hasImportant = addNormalMatches(cascadeLevel); 154 if (hasImportant) 155 cascadeLevelsWithImportant.add(cascadeLevel); 156 } 157 158 for (auto cascadeLevel : { CascadeLevel::Author, CascadeLevel::User, CascadeLevel::UserAgent }) { 159 if (!cascadeLevelsWithImportant.contains(cascadeLevel)) 160 continue; 161 addImportantMatches(cascadeLevel); 162 } 149 163 } 150 164 … … 210 224 211 225 212 void PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool isImportant, bool inheritedOnly)226 bool PropertyCascade::addMatch(const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel, bool important) 213 227 { 214 228 auto& styleProperties = *matchedProperties.properties; 215 229 auto propertyWhitelistType = static_cast<PropertyWhitelistType>(matchedProperties.whitelistType); 230 bool hasImportantProperties = false; 216 231 217 232 for (unsigned i = 0, count = styleProperties.propertyCount(); i < count; ++i) { 218 233 auto current = styleProperties.propertyAt(i); 219 if (isImportant != current.isImportant()) 220 continue; 221 if (inheritedOnly && !current.isInherited()) { 234 235 if (current.isImportant()) 236 hasImportantProperties = true; 237 if (important != current.isImportant()) 238 continue; 239 240 if (m_includedProperties == IncludedProperties::InheritedOnly && !current.isInherited()) { 222 241 // Inherited only mode is used after matched properties cache hit. 223 242 // A match with a value that is explicitly inherited should never have been cached. … … 239 258 set(propertyID, *current.value(), matchedProperties.linkMatchType, cascadeLevel, matchedProperties.styleScopeOrdinal); 240 259 } 260 261 return hasImportantProperties; 241 262 } 242 263 … … 252 273 } 253 274 254 void PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel, bool inheritedOnly) 255 { 275 bool PropertyCascade::addNormalMatches(CascadeLevel cascadeLevel) 276 { 277 bool hasImportant = false; 256 278 for (auto& matchedDeclarations : declarationsForCascadeLevel(m_matchResult, cascadeLevel)) 257 addMatch(matchedDeclarations, cascadeLevel, false, inheritedOnly); 279 hasImportant |= addMatch(matchedDeclarations, cascadeLevel, false); 280 281 return hasImportant; 258 282 } 259 283 … … 267 291 } 268 292 269 void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel , bool inheritedOnly)293 void PropertyCascade::addImportantMatches(CascadeLevel cascadeLevel) 270 294 { 271 295 struct IndexAndOrdinal { … … 302 326 303 327 for (auto& match : importantMatches) 304 addMatch(matchedDeclarations[match.index], cascadeLevel, true , inheritedOnly);328 addMatch(matchedDeclarations[match.index], cascadeLevel, true); 305 329 } 306 330 … … 308 332 { 309 333 for (auto& property : m_deferredProperties) 310 property.apply(*this);334 applyProperty(property); 311 335 } 312 336 … … 340 364 341 365 m_applyState.inProgressProperties.set(propertyID); 342 property.apply(*this);366 applyProperty(property); 343 367 m_applyState.appliedProperties.set(propertyID); 344 368 m_applyState.inProgressProperties.set(propertyID, false); … … 347 371 348 372 // If we don't have any custom properties, then there can't be any cycles. 349 property.apply(*this);373 applyProperty(property); 350 374 } 351 375 } … … 434 458 case CascadeLevel::Author: 435 459 if (!m_authorRollbackCascade) { 436 m_authorRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, m_direction, m_writingMode); 437 438 // This special rollback cascade contains UA rules and user rules but no author rules. 439 m_authorRollbackCascade->addNormalMatches(CascadeLevel::UserAgent, false); 440 m_authorRollbackCascade->addNormalMatches(CascadeLevel::User, false); 441 m_authorRollbackCascade->addImportantMatches(CascadeLevel::User, false); 442 m_authorRollbackCascade->addImportantMatches(CascadeLevel::UserAgent, false); 460 auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent, CascadeLevel::User }; 461 m_authorRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties); 443 462 } 444 463 return m_authorRollbackCascade.get(); … … 446 465 case CascadeLevel::User: 447 466 if (!m_userRollbackCascade) { 448 m_userRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, m_direction, m_writingMode); 449 450 // This special rollback cascade contains only UA rules. 451 m_userRollbackCascade->addNormalMatches(CascadeLevel::UserAgent, false); 452 m_userRollbackCascade->addImportantMatches(CascadeLevel::UserAgent, false); 467 auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent }; 468 m_userRollbackCascade = makeUnique<PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties); 453 469 } 454 470 return m_userRollbackCascade.get(); … … 461 477 } 462 478 463 void PropertyCascade::Property::apply(PropertyCascade& cascade) 464 { 465 auto& resolver = cascade.styleResolver(); 466 StyleResolver::State& state = resolver.state(); 467 state.setCascadeLevel(level); 468 state.setStyleScopeOrdinal(styleScopeOrdinal); 469 470 if (cssValue[SelectorChecker::MatchDefault]) { 479 inline void PropertyCascade::applyProperty(const Property& property) 480 { 481 StyleResolver::State& state = m_styleResolver.state(); 482 state.setCascadeLevel(property.level); 483 state.setStyleScopeOrdinal(property.styleScopeOrdinal); 484 485 if (property.cssValue[SelectorChecker::MatchDefault]) { 471 486 state.setApplyPropertyToRegularStyle(true); 472 487 state.setApplyPropertyToVisitedLinkStyle(false); 473 resolver.applyProperty(id, cssValue[SelectorChecker::MatchDefault], cascade, SelectorChecker::MatchDefault);488 m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchDefault], *this, SelectorChecker::MatchDefault); 474 489 } 475 490 … … 477 492 return; 478 493 479 if ( cssValue[SelectorChecker::MatchLink]) {494 if (property.cssValue[SelectorChecker::MatchLink]) { 480 495 state.setApplyPropertyToRegularStyle(true); 481 496 state.setApplyPropertyToVisitedLinkStyle(false); 482 resolver.applyProperty(id, cssValue[SelectorChecker::MatchLink], cascade, SelectorChecker::MatchLink);483 } 484 485 if ( cssValue[SelectorChecker::MatchVisited]) {497 m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchLink], *this, SelectorChecker::MatchLink); 498 } 499 500 if (property.cssValue[SelectorChecker::MatchVisited]) { 486 501 state.setApplyPropertyToRegularStyle(false); 487 502 state.setApplyPropertyToVisitedLinkStyle(true); 488 resolver.applyProperty(id, cssValue[SelectorChecker::MatchVisited], cascade, SelectorChecker::MatchVisited);503 m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchVisited], *this, SelectorChecker::MatchVisited); 489 504 } 490 505 -
trunk/Source/WebCore/style/PropertyCascade.h
r251611 r251632 37 37 38 38 enum class CascadeLevel : uint8_t { 39 UserAgent ,40 User ,41 Author 39 UserAgent = 1 << 0, 40 User = 1 << 1, 41 Author = 1 << 2 42 42 }; 43 44 static constexpr OptionSet<CascadeLevel> allCascadeLevels() { return { Style::CascadeLevel::UserAgent, Style::CascadeLevel::User, Style::CascadeLevel::Author }; } 43 45 44 46 class PropertyCascade { 45 47 WTF_MAKE_FAST_ALLOCATED; 46 48 public: 47 PropertyCascade(StyleResolver&, const MatchResult&, TextDirection, WritingMode); 49 enum IncludedProperties { All, InheritedOnly }; 50 PropertyCascade(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, TextDirection, WritingMode, IncludedProperties = IncludedProperties::All); 48 51 ~PropertyCascade(); 49 52 … … 51 54 52 55 struct Property { 53 void apply(PropertyCascade&);54 55 56 CSSPropertyID id; 56 57 CascadeLevel level; … … 65 66 Property customProperty(const String&) const; 66 67 67 void addNormalMatches(CascadeLevel, bool inheritedOnly = false);68 void addImportantMatches(CascadeLevel, bool inheritedOnly = false);69 70 68 bool hasAppliedProperty(CSSPropertyID) const; 71 69 … … 79 77 80 78 private: 81 void addMatch(const MatchedProperties&, CascadeLevel, bool isImportant, bool inheritedOnly); 79 bool addNormalMatches(CascadeLevel); 80 void addImportantMatches(CascadeLevel); 81 bool addMatch(const MatchedProperties&, CascadeLevel, bool important); 82 82 83 void set(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal); 83 84 void setDeferred(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal); … … 87 88 template<CustomPropertyCycleTracking trackCycles> 88 89 void applyPropertiesImpl(int firstProperty, int lastProperty); 90 void applyProperty(const Property&); 89 91 90 92 StyleResolver& m_styleResolver; 91 93 const MatchResult& m_matchResult; 94 IncludedProperties m_includedProperties; 92 95 93 96 TextDirection m_direction;
Note:
See TracChangeset
for help on using the changeset viewer.