Changeset 251636 in webkit
- Timestamp:
- Oct 26, 2019, 8:15:20 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
css/StyleResolver.cpp (modified) (4 diffs)
-
css/StyleResolver.h (modified) (1 diff)
-
style/PropertyCascade.cpp (modified) (11 diffs)
-
style/PropertyCascade.h (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251633 r251636 1 2019-10-26 Antti Koivisto <antti@apple.com> 2 3 Move StyleResolver::applyProperty to PropertyCascade 4 https://bugs.webkit.org/show_bug.cgi?id=203458 5 6 Reviewed by Zalan Bujtas. 7 8 Move the more of the property applying code out of StyleResolver. 9 10 * css/StyleResolver.cpp: 11 (WebCore::StyleResolver::applyPropertyToCurrentStyle): 12 (WebCore::isValidVisitedLinkProperty): Deleted. 13 (WebCore::StyleResolver::applyProperty): Deleted. 14 (WebCore::StyleResolver::resolvedVariableValue const): Deleted. 15 * css/StyleResolver.h: 16 * style/PropertyCascade.cpp: 17 (WebCore::Style::isValidVisitedLinkProperty): 18 (WebCore::Style::PropertyCascade::applyCustomProperty): 19 (WebCore::Style::PropertyCascade::propertyCascadeForRollback): 20 (WebCore::Style::PropertyCascade::applyProperty): 21 (WebCore::Style::PropertyCascade::resolveValue): 22 (WebCore::Style::PropertyCascade::resolvedVariableValue): 23 * style/PropertyCascade.h: 24 (WebCore::Style::PropertyCascade::property const): 25 (WebCore::Style::PropertyCascade::property): Deleted. 26 (WebCore::Style::PropertyCascade::hasAppliedProperty const): Deleted. 27 1 28 2019-10-26 Zalan Bujtas <zalan@apple.com> 2 29 -
trunk/Source/WebCore/css/StyleResolver.cpp
r251632 r251636 43 43 #include "CSSKeyframeRule.h" 44 44 #include "CSSKeyframesRule.h" 45 #include "CSSPaintImageValue.h"46 45 #include "CSSParser.h" 47 46 #include "CSSPrimitiveValueMappings.h" … … 94 93 #include "ShadowRoot.h" 95 94 #include "SharedStringHash.h" 96 #include "StyleBuilder.h"97 95 #include "StyleColor.h" 98 96 #include "StyleCachedImage.h" … … 1454 1452 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value) 1455 1453 { 1454 if (!value) 1455 return; 1456 1456 MatchResult matchResult; 1457 1457 Style::PropertyCascade cascade(*this, matchResult, { }, { }, { }); 1458 1458 if (value) 1459 applyProperty(id, value, cascade); 1460 } 1461 1462 inline bool isValidVisitedLinkProperty(CSSPropertyID id) 1463 { 1464 switch (id) { 1465 case CSSPropertyBackgroundColor: 1466 case CSSPropertyBorderLeftColor: 1467 case CSSPropertyBorderRightColor: 1468 case CSSPropertyBorderTopColor: 1469 case CSSPropertyBorderBottomColor: 1470 case CSSPropertyCaretColor: 1471 case CSSPropertyColor: 1472 case CSSPropertyOutlineColor: 1473 case CSSPropertyColumnRuleColor: 1474 case CSSPropertyTextDecorationColor: 1475 case CSSPropertyWebkitTextEmphasisColor: 1476 case CSSPropertyWebkitTextFillColor: 1477 case CSSPropertyWebkitTextStrokeColor: 1478 case CSSPropertyFill: 1479 case CSSPropertyStroke: 1480 case CSSPropertyStrokeColor: 1481 return true; 1482 default: 1483 break; 1484 } 1485 1486 return false; 1459 cascade.applyProperty(id, *value); 1487 1460 } 1488 1461 … … 1504 1477 { 1505 1478 return is<SVGElement>(m_state.element()) && !(is<SVGSVGElement>(*m_state.element()) && m_state.element()->parentNode()); 1506 }1507 1508 void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value, Style::PropertyCascade& cascade, SelectorChecker::LinkMatchMask linkMatchMask)1509 {1510 ASSERT_WITH_MESSAGE(!isShorthandCSSProperty(id), "Shorthand property id = %d wasn't expanded at parsing time", id);1511 1512 State& state = m_state;1513 1514 RefPtr<CSSValue> valueToApply = value;1515 if (value->hasVariableReferences()) {1516 valueToApply = resolvedVariableValue(id, *value, cascade);1517 // If the cascade has already applied this id, then we detected a cycle, and this value should be unset.1518 if (!valueToApply || cascade.hasAppliedProperty(id)) {1519 if (CSSProperty::isInheritedProperty(id))1520 valueToApply = CSSValuePool::singleton().createInheritedValue();1521 else1522 valueToApply = CSSValuePool::singleton().createExplicitInitialValue();1523 }1524 }1525 1526 if (CSSProperty::isDirectionAwareProperty(id)) {1527 CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, state.style()->direction(), state.style()->writingMode());1528 ASSERT(newId != id);1529 return applyProperty(newId, valueToApply.get(), cascade, linkMatchMask);1530 }1531 1532 CSSValue* valueToCheckForInheritInitial = valueToApply.get();1533 CSSCustomPropertyValue* customPropertyValue = nullptr;1534 CSSValueID customPropertyValueID = CSSValueInvalid;1535 1536 CSSRegisteredCustomProperty* customPropertyRegistered = nullptr;1537 1538 if (id == CSSPropertyCustom) {1539 customPropertyValue = &downcast<CSSCustomPropertyValue>(*valueToApply);1540 ASSERT(customPropertyValue->isResolved());1541 if (WTF::holds_alternative<CSSValueID>(customPropertyValue->value()))1542 customPropertyValueID = WTF::get<CSSValueID>(customPropertyValue->value());1543 auto& name = customPropertyValue->name();1544 customPropertyRegistered = document().getCSSRegisteredCustomPropertySet().get(name);1545 }1546 1547 bool isInherit = state.parentStyle() ? valueToCheckForInheritInitial->isInheritedValue() || customPropertyValueID == CSSValueInherit : false;1548 bool isInitial = valueToCheckForInheritInitial->isInitialValue() || customPropertyValueID == CSSValueInitial || (!state.parentStyle() && (valueToCheckForInheritInitial->isInheritedValue() || customPropertyValueID == CSSValueInherit));1549 1550 bool isUnset = valueToCheckForInheritInitial->isUnsetValue() || customPropertyValueID == CSSValueUnset;1551 bool isRevert = valueToCheckForInheritInitial->isRevertValue() || customPropertyValueID == CSSValueRevert;1552 1553 if (isRevert) {1554 if (state.cascadeLevel() == Style::CascadeLevel::UserAgent)1555 isUnset = true;1556 else {1557 auto* rollback = cascade.propertyCascadeForRollback(state.cascadeLevel());1558 ASSERT(rollback);1559 1560 // With the cascade built, we need to obtain the property and apply it. If the property is1561 // not present, then we behave like "unset." Otherwise we apply the property instead of1562 // our own.1563 if (customPropertyValue) {1564 if (customPropertyRegistered && customPropertyRegistered->inherits && rollback->hasCustomProperty(customPropertyValue->name())) {1565 auto property = rollback->customProperty(customPropertyValue->name());1566 if (property.cssValue[linkMatchMask])1567 applyProperty(property.id, property.cssValue[linkMatchMask], cascade, linkMatchMask);1568 return;1569 }1570 } else if (rollback->hasProperty(id)) {1571 auto& property = rollback->property(id);1572 if (property.cssValue[linkMatchMask])1573 applyProperty(property.id, property.cssValue[linkMatchMask], cascade, linkMatchMask);1574 return;1575 }1576 1577 isUnset = true;1578 }1579 }1580 1581 if (isUnset) {1582 if (CSSProperty::isInheritedProperty(id))1583 isInherit = true;1584 else1585 isInitial = true;1586 }1587 1588 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit1589 1590 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLinkStyle() || !isValidVisitedLinkProperty(id))) {1591 // Limit the properties that can be applied to only the ones honored by :visited.1592 return;1593 }1594 1595 if (isInherit && !CSSProperty::isInheritedProperty(id))1596 state.style()->setHasExplicitlyInheritedProperties();1597 1598 #if ENABLE(CSS_PAINTING_API)1599 if (is<CSSPaintImageValue>(*valueToApply)) {1600 auto& name = downcast<CSSPaintImageValue>(*valueToApply).name();1601 if (auto* paintWorklet = document().paintWorkletGlobalScopeForName(name)) {1602 auto locker = holdLock(paintWorklet->paintDefinitionLock());1603 if (auto* registration = paintWorklet->paintDefinitionMap().get(name)) {1604 for (auto& property : registration->inputProperties)1605 state.style()->addCustomPaintWatchProperty(property);1606 }1607 }1608 }1609 #endif1610 1611 // Use the generated StyleBuilder.1612 StyleBuilder::applyProperty(id, *this, *valueToApply, isInitial, isInherit, customPropertyRegistered);1613 }1614 1615 RefPtr<CSSValue> StyleResolver::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value, Style::PropertyCascade& cascade) const1616 {1617 CSSParser parser(document());1618 return parser.parseValueWithVariableReferences(propID, value, cascade);1619 1479 } 1620 1480 -
trunk/Source/WebCore/css/StyleResolver.h
r251611 r251636 328 328 void setTextOrientation(TextOrientation textOrientation) { m_state.setTextOrientation(textOrientation); } 329 329 330 RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSValue&, Style::PropertyCascade&) const;331 332 330 bool adjustRenderStyleForTextAutosizing(RenderStyle&, const Element&); 333 334 void applyProperty(CSSPropertyID, CSSValue*, Style::PropertyCascade&, SelectorChecker::LinkMatchMask = SelectorChecker::MatchDefault);335 331 336 332 private: -
trunk/Source/WebCore/style/PropertyCascade.cpp
r251632 r251636 27 27 #include "PropertyCascade.h" 28 28 29 #include "CSSPaintImageValue.h" 30 #include "CSSValuePool.h" 31 #include "PaintWorkletGlobalScope.h" 32 #include "StyleBuilder.h" 33 #include "StylePropertyShorthand.h" 29 34 #include "StyleResolver.h" 30 35 … … 91 96 break; 92 97 } 98 return false; 99 } 100 101 static inline bool isValidVisitedLinkProperty(CSSPropertyID id) 102 { 103 switch (id) { 104 case CSSPropertyBackgroundColor: 105 case CSSPropertyBorderLeftColor: 106 case CSSPropertyBorderRightColor: 107 case CSSPropertyBorderTopColor: 108 case CSSPropertyBorderBottomColor: 109 case CSSPropertyCaretColor: 110 case CSSPropertyColor: 111 case CSSPropertyOutlineColor: 112 case CSSPropertyColumnRuleColor: 113 case CSSPropertyTextDecorationColor: 114 case CSSPropertyWebkitTextEmphasisColor: 115 case CSSPropertyWebkitTextFillColor: 116 case CSSPropertyWebkitTextStrokeColor: 117 case CSSPropertyFill: 118 case CSSPropertyStroke: 119 case CSSPropertyStrokeColor: 120 return true; 121 default: 122 break; 123 } 124 93 125 return false; 94 126 } … … 405 437 406 438 if (WTF::holds_alternative<Ref<CSSVariableReferenceValue>>(valueToApply->value())) { 407 RefPtr<CSSValue> parsedValue = m_styleResolver.resolvedVariableValue(CSSPropertyCustom, valueToApply.get(), *this);439 RefPtr<CSSValue> parsedValue = resolvedVariableValue(CSSPropertyCustom, valueToApply.get()); 408 440 409 441 if (m_applyState.appliedCustomProperties.contains(name)) … … 431 463 m_styleResolver.state().setApplyPropertyToVisitedLinkStyle(true); 432 464 } 433 m_styleResolver.applyProperty(CSSPropertyCustom, valueToApply.ptr(), *this, index);465 applyProperty(CSSPropertyCustom, valueToApply.get(), index); 434 466 } 435 467 } … … 448 480 if (inCycle && WTF::holds_alternative<Ref<CSSVariableReferenceValue>>(valueToApply->value())) { 449 481 // Resolve this value so that we reset its dependencies. 450 m_styleResolver.resolvedVariableValue(CSSPropertyCustom, valueToApply.get(), *this);451 } 452 } 453 } 454 455 PropertyCascade* PropertyCascade::propertyCascadeForRollback(CascadeLevel cascadeLevel)482 resolvedVariableValue(CSSPropertyCustom, valueToApply.get()); 483 } 484 } 485 } 486 487 const PropertyCascade* PropertyCascade::propertyCascadeForRollback(CascadeLevel cascadeLevel) 456 488 { 457 489 switch (cascadeLevel) { … … 459 491 if (!m_authorRollbackCascade) { 460 492 auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent, CascadeLevel::User }; 461 m_authorRollbackCascade = makeUnique< PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties);493 m_authorRollbackCascade = makeUnique<const PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties); 462 494 } 463 495 return m_authorRollbackCascade.get(); … … 466 498 if (!m_userRollbackCascade) { 467 499 auto cascadeLevels = OptionSet<CascadeLevel> { CascadeLevel::UserAgent }; 468 m_userRollbackCascade = makeUnique< PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties);500 m_userRollbackCascade = makeUnique<const PropertyCascade>(m_styleResolver, m_matchResult, cascadeLevels, m_direction, m_writingMode, m_includedProperties); 469 501 } 470 502 return m_userRollbackCascade.get(); 471 503 472 504 case CascadeLevel::UserAgent: 473 break;505 return nullptr; 474 506 } 475 507 ASSERT_NOT_REACHED(); … … 486 518 state.setApplyPropertyToRegularStyle(true); 487 519 state.setApplyPropertyToVisitedLinkStyle(false); 488 m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchDefault], *this, SelectorChecker::MatchDefault);520 applyProperty(property.id, *property.cssValue[SelectorChecker::MatchDefault], SelectorChecker::MatchDefault); 489 521 } 490 522 … … 495 527 state.setApplyPropertyToRegularStyle(true); 496 528 state.setApplyPropertyToVisitedLinkStyle(false); 497 m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchLink], *this, SelectorChecker::MatchLink);529 applyProperty(property.id, *property.cssValue[SelectorChecker::MatchLink], SelectorChecker::MatchLink); 498 530 } 499 531 … … 501 533 state.setApplyPropertyToRegularStyle(false); 502 534 state.setApplyPropertyToVisitedLinkStyle(true); 503 m_styleResolver.applyProperty(property.id, property.cssValue[SelectorChecker::MatchVisited], *this, SelectorChecker::MatchVisited);535 applyProperty(property.id, *property.cssValue[SelectorChecker::MatchVisited], SelectorChecker::MatchVisited); 504 536 } 505 537 … … 508 540 } 509 541 510 } 511 } 542 void PropertyCascade::applyProperty(CSSPropertyID id, CSSValue& value, SelectorChecker::LinkMatchMask linkMatchMask) 543 { 544 ASSERT_WITH_MESSAGE(!isShorthandCSSProperty(id), "Shorthand property id = %d wasn't expanded at parsing time", id); 545 546 auto valueToApply = resolveValue(id, value); 547 548 if (CSSProperty::isDirectionAwareProperty(id)) { 549 CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, m_direction, m_writingMode); 550 ASSERT(newId != id); 551 return applyProperty(newId, valueToApply.get(), linkMatchMask); 552 } 553 554 CSSCustomPropertyValue* customPropertyValue = nullptr; 555 CSSValueID customPropertyValueID = CSSValueInvalid; 556 CSSRegisteredCustomProperty* customPropertyRegistered = nullptr; 557 558 if (id == CSSPropertyCustom) { 559 customPropertyValue = downcast<CSSCustomPropertyValue>(valueToApply.ptr()); 560 ASSERT(customPropertyValue->isResolved()); 561 if (WTF::holds_alternative<CSSValueID>(customPropertyValue->value())) 562 customPropertyValueID = WTF::get<CSSValueID>(customPropertyValue->value()); 563 auto& name = customPropertyValue->name(); 564 customPropertyRegistered = m_styleResolver.document().getCSSRegisteredCustomPropertySet().get(name); 565 } 566 567 auto& state = m_styleResolver.state(); 568 bool isInherit = state.parentStyle() ? valueToApply->isInheritedValue() || customPropertyValueID == CSSValueInherit : false; 569 bool isInitial = valueToApply->isInitialValue() || customPropertyValueID == CSSValueInitial || (!state.parentStyle() && (valueToApply->isInheritedValue() || customPropertyValueID == CSSValueInherit)); 570 571 bool isUnset = valueToApply->isUnsetValue() || customPropertyValueID == CSSValueUnset; 572 bool isRevert = valueToApply->isRevertValue() || customPropertyValueID == CSSValueRevert; 573 574 if (isRevert) { 575 if (auto* rollback = propertyCascadeForRollback(state.cascadeLevel())) { 576 // With the rollback cascade built, we need to obtain the property and apply it. If the property is 577 // not present, then we behave like "unset." Otherwise we apply the property instead of 578 // our own. 579 if (customPropertyValue) { 580 if (customPropertyRegistered && customPropertyRegistered->inherits && rollback->hasCustomProperty(customPropertyValue->name())) { 581 auto property = rollback->customProperty(customPropertyValue->name()); 582 if (property.cssValue[linkMatchMask]) 583 applyProperty(property.id, *property.cssValue[linkMatchMask], linkMatchMask); 584 return; 585 } 586 } else if (rollback->hasProperty(id)) { 587 auto& property = rollback->property(id); 588 if (property.cssValue[linkMatchMask]) 589 applyProperty(property.id, *property.cssValue[linkMatchMask], linkMatchMask); 590 return; 591 } 592 } 593 594 isUnset = true; 595 } 596 597 if (isUnset) { 598 if (CSSProperty::isInheritedProperty(id)) 599 isInherit = true; 600 else 601 isInitial = true; 602 } 603 604 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit 605 606 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLinkStyle() || !isValidVisitedLinkProperty(id))) { 607 // Limit the properties that can be applied to only the ones honored by :visited. 608 return; 609 } 610 611 if (isInherit && !CSSProperty::isInheritedProperty(id)) 612 state.style()->setHasExplicitlyInheritedProperties(); 613 614 #if ENABLE(CSS_PAINTING_API) 615 if (is<CSSPaintImageValue>(valueToApply)) { 616 auto& name = downcast<CSSPaintImageValue>(valueToApply.get()).name(); 617 if (auto* paintWorklet = m_styleResolver.document().paintWorkletGlobalScopeForName(name)) { 618 auto locker = holdLock(paintWorklet->paintDefinitionLock()); 619 if (auto* registration = paintWorklet->paintDefinitionMap().get(name)) { 620 for (auto& property : registration->inputProperties) 621 state.style()->addCustomPaintWatchProperty(property); 622 } 623 } 624 } 625 #endif 626 627 // Use the generated StyleBuilder. 628 StyleBuilder::applyProperty(id, m_styleResolver, valueToApply.get(), isInitial, isInherit, customPropertyRegistered); 629 } 630 631 Ref<CSSValue> PropertyCascade::resolveValue(CSSPropertyID propertyID, CSSValue& value) 632 { 633 if (!value.hasVariableReferences()) 634 return value; 635 636 auto variableValue = resolvedVariableValue(propertyID, value); 637 // If the cascade has already applied this id, then we detected a cycle, and this value should be unset. 638 if (!variableValue || m_applyState.appliedProperties.get(propertyID)) { 639 if (CSSProperty::isInheritedProperty(propertyID)) 640 return CSSValuePool::singleton().createInheritedValue(); 641 return CSSValuePool::singleton().createExplicitInitialValue(); 642 } 643 644 return *variableValue; 645 } 646 647 RefPtr<CSSValue> PropertyCascade::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value) 648 { 649 CSSParser parser(m_styleResolver.document()); 650 return parser.parseValueWithVariableReferences(propID, value, *this); 651 } 652 653 } 654 } -
trunk/Source/WebCore/style/PropertyCascade.h
r251632 r251636 61 61 62 62 bool hasProperty(CSSPropertyID) const; 63 Property& property(CSSPropertyID);63 const Property& property(CSSPropertyID) const; 64 64 65 65 bool hasCustomProperty(const String&) const; 66 66 Property customProperty(const String&) const; 67 68 bool hasAppliedProperty(CSSPropertyID) const;69 67 70 68 void applyProperties(int firstProperty, int lastProperty); … … 74 72 void applyCustomProperty(const String& name); 75 73 76 PropertyCascade* propertyCascadeForRollback(CascadeLevel);74 void applyProperty(CSSPropertyID, CSSValue&, SelectorChecker::LinkMatchMask = SelectorChecker::MatchDefault); 77 75 78 76 private: … … 85 83 static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal); 86 84 85 const PropertyCascade* propertyCascadeForRollback(CascadeLevel); 86 87 87 enum CustomPropertyCycleTracking { Enabled = 0, Disabled }; 88 88 template<CustomPropertyCycleTracking trackCycles> … … 90 90 void applyProperty(const Property&); 91 91 92 Ref<CSSValue> resolveValue(CSSPropertyID, CSSValue&); 93 RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSValue&); 94 92 95 StyleResolver& m_styleResolver; 96 93 97 const MatchResult& m_matchResult; 94 IncludedProperties m_includedProperties; 95 96 TextDirection m_direction; 97 WritingMode m_writingMode; 98 const IncludedProperties m_includedProperties; 99 const TextDirection m_direction; 100 const WritingMode m_writingMode; 98 101 99 102 Property m_properties[numCSSProperties + 2]; … … 114 117 ApplyState m_applyState; 115 118 116 std::unique_ptr< PropertyCascade> m_authorRollbackCascade;117 std::unique_ptr< PropertyCascade> m_userRollbackCascade;119 std::unique_ptr<const PropertyCascade> m_authorRollbackCascade; 120 std::unique_ptr<const PropertyCascade> m_userRollbackCascade; 118 121 }; 119 122 … … 124 127 } 125 128 126 inline PropertyCascade::Property& PropertyCascade::property(CSSPropertyID id)129 inline const PropertyCascade::Property& PropertyCascade::property(CSSPropertyID id) const 127 130 { 128 131 return m_properties[id]; … … 139 142 } 140 143 141 inline bool PropertyCascade::hasAppliedProperty(CSSPropertyID propertyID) const142 {143 return m_applyState.appliedProperties.get(propertyID);144 }145 146 144 } 147 145 }
Note:
See TracChangeset
for help on using the changeset viewer.