Changeset 251916 in webkit
- Timestamp:
- Nov 1, 2019 8:20:19 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251914 r251916 1 2019-11-01 Antti Koivisto <antti@apple.com> 2 3 Style::Builder should not depend on StyleResolver 4 https://bugs.webkit.org/show_bug.cgi?id=203729 5 6 Reviewed by Zalan Bujtas. 7 8 With all style building state in builder, we can remove the back-reference to style resolver. 9 10 * css/CSSFilterImageValue.cpp: 11 (WebCore::CSSFilterImageValue::createFilterOperations): 12 * css/CSSFilterImageValue.h: 13 * css/CSSGradientValue.cpp: 14 (WebCore::CSSGradientValue::gradientWithStylesResolved): 15 (WebCore::CSSGradientValue::resolveRGBColors): 16 17 Add helper for resolving basic colors without style builder. 18 19 * css/CSSGradientValue.h: 20 * css/StyleResolver.cpp: 21 (WebCore::StyleResolver::State::clear): 22 (WebCore::StyleResolver::State::State): 23 (WebCore::StyleResolver::State::setStyle): 24 (WebCore::StyleResolver::applyMatchedProperties): 25 26 Register content attributes encountered during style building. 27 28 (WebCore::StyleResolver::State::updateConversionData): Deleted. 29 30 This is now created by BuilderState constructor. 31 32 (WebCore::StyleResolver::styleImage): Deleted. 33 (WebCore::StyleResolver::colorFromPrimitiveValueIsDerivedFromElement): Deleted. 34 (WebCore::StyleResolver::colorFromPrimitiveValue const): Deleted. 35 (WebCore::filterOperationForType): Deleted. 36 (WebCore::StyleResolver::createFilterOperations): Deleted. 37 38 Move image mapping functions to BuilderState. 39 40 * css/StyleResolver.h: 41 (WebCore::StyleResolver::State::cssToLengthConversionData const): Deleted. 42 * html/HTMLInputElement.cpp: 43 (WebCore::autoFillStrongPasswordMaskImage): 44 (WebCore::HTMLInputElement::createInnerTextStyle): 45 46 Create mask image without requiring style resolver. 47 48 * style/StyleBuilder.cpp: 49 (WebCore::Style::Builder::Builder): 50 * style/StyleBuilderCustom.h: 51 (WebCore::Style::BuilderCustom::applyValueZoom): 52 (WebCore::Style::BuilderCustom::applyValueContent): 53 (WebCore::Style::BuilderCustom::applyValueFontSize): 54 (WebCore::Style::BuilderCustom::applyValueAlt): 55 * style/StyleBuilderState.cpp: 56 (WebCore::Style::BuilderState::BuilderState): 57 58 No more m_styleResolver. 59 60 (WebCore::Style::BuilderState::createStyleImage): 61 (WebCore::Style::filterOperationForType): 62 (WebCore::Style::BuilderState::createFilterOperations): 63 (WebCore::Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement): 64 (WebCore::Style::BuilderState::colorFromPrimitiveValue const): 65 (WebCore::Style::BuilderState::registerContentAttribute): 66 67 Collect content attributes so they can be applied later by StyleResolver. 68 69 * style/StyleBuilderState.h: 70 (WebCore::Style::BuilderState::builder): 71 (WebCore::Style::BuilderState::rootElementStyle const): 72 73 Restore this to be nullable for simplicity. 74 75 (WebCore::Style::BuilderState::registeredContentAttributes const): 76 (WebCore::Style::BuilderState::styleResolver): Deleted. 77 1 78 2019-11-01 Zan Dobersek <zdobersek@igalia.com> and Chris Lord <clord@igalia.com> 2 79 -
trunk/Source/WebCore/css/CSSFilterImageValue.cpp
r251493 r251916 34 34 #include "ImageBuffer.h" 35 35 #include "RenderElement.h" 36 #include "StyleBuilderState.h" 36 37 #include "StyleCachedImage.h" 37 #include "StyleResolver.h"38 38 #include <wtf/text/StringBuilder.h> 39 39 … … 141 141 } 142 142 143 void CSSFilterImageValue::createFilterOperations(Style Resolver* resolver)143 void CSSFilterImageValue::createFilterOperations(Style::BuilderState& builderState) 144 144 { 145 145 m_filterOperations.clear(); 146 resolver->createFilterOperations(m_filterValue, m_filterOperations);146 builderState.createFilterOperations(m_filterValue, m_filterOperations); 147 147 } 148 148 -
trunk/Source/WebCore/css/CSSFilterImageValue.h
r251493 r251916 40 40 class RenderElement; 41 41 class Document; 42 class StyleResolver; 42 43 namespace Style { 44 class BuilderState; 45 } 43 46 44 47 class CSSFilterImageValue final : public CSSImageGeneratorValue { … … 69 72 bool equalInputImages(const CSSFilterImageValue&) const; 70 73 71 void createFilterOperations(Style Resolver*);74 void createFilterOperations(Style::BuilderState&); 72 75 73 76 const FilterOperations& filterOperations() const { return m_filterOperations; } -
trunk/Source/WebCore/css/CSSGradientValue.cpp
r251474 r251916 37 37 #include "RenderElement.h" 38 38 #include "RenderView.h" 39 #include "Style Resolver.h"39 #include "StyleBuilderState.h" 40 40 #include <wtf/text/StringBuilder.h> 41 41 … … 104 104 } 105 105 106 Ref<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(const StyleResolver& styleResolver) 106 template<typename Function> 107 void resolveStopColors(Vector<CSSGradientColorStop, 2>& stops, Function&& colorResolveFunction) 108 { 109 for (size_t i = 0; i < stops.size(); ++i) { 110 auto& stop = stops[i]; 111 if (stop.isMidpoint) 112 continue; 113 if (stop.m_color) 114 stop.m_resolvedColor = colorResolveFunction(*stop.m_color); 115 else if (i) { 116 auto& previousStop = stops[i - 1]; 117 ASSERT(previousStop.m_color); 118 stop.m_color = previousStop.m_color; 119 stop.m_resolvedColor = previousStop.m_resolvedColor; 120 } 121 } 122 } 123 124 Ref<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(Style::BuilderState& builderState) 107 125 { 108 126 bool colorIsDerivedFromElement = false; 109 127 for (auto& stop : m_stops) { 110 if (!stop.isMidpoint && stop.m_color && styleResolver.colorFromPrimitiveValueIsDerivedFromElement(*stop.m_color)) {128 if (!stop.isMidpoint && stop.m_color && Style::BuilderState::isColorFromPrimitiveValueDerivedFromElement(*stop.m_color)) { 111 129 stop.m_colorIsDerivedFromElement = true; 112 130 colorIsDerivedFromElement = true; … … 115 133 } 116 134 auto result = colorIsDerivedFromElement ? clone(*this) : makeRef(*this); 117 for (size_t i = 0; i < result->m_stops.size(); ++i) { 118 auto& stop = result->m_stops[i]; 119 if (stop.isMidpoint) 120 continue; 121 if (stop.m_color) 122 stop.m_resolvedColor = styleResolver.colorFromPrimitiveValue(*stop.m_color); 123 else if (i) { 124 auto& previousStop = result->m_stops[i - 1]; 125 ASSERT(previousStop.m_color); 126 stop.m_color = previousStop.m_color; 127 stop.m_resolvedColor = previousStop.m_resolvedColor; 128 } 129 } 135 resolveStopColors(result->m_stops, [&](const CSSPrimitiveValue& colorValue) { 136 return builderState.colorFromPrimitiveValue(colorValue); 137 }); 130 138 return result; 139 } 140 141 void CSSGradientValue::resolveRGBColors() 142 { 143 resolveStopColors(m_stops, [&](const CSSPrimitiveValue& colorValue) { 144 ASSERT(colorValue.isRGBColor()); 145 return colorValue.color(); 146 }); 131 147 } 132 148 -
trunk/Source/WebCore/css/CSSGradientValue.h
r251437 r251916 36 36 class StyleResolver; 37 37 38 namespace Style { 39 class BuilderState; 40 } 41 38 42 enum CSSGradientType { 39 43 CSSDeprecatedLinearGradient, … … 87 91 88 92 void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&) { } 89 Ref<CSSGradientValue> gradientWithStylesResolved(const StyleResolver&); 93 Ref<CSSGradientValue> gradientWithStylesResolved(Style::BuilderState&); 94 void resolveRGBColors(); 90 95 91 96 protected: -
trunk/Source/WebCore/css/StyleResolver.cpp
r251864 r251916 31 31 #include "StyleResolver.h" 32 32 33 #include "CSSCalculationValue.h"34 #include "CSSCursorImageValue.h"35 33 #include "CSSDefaultStyleSheets.h" 36 #include "CSSFilterImageValue.h"37 34 #include "CSSFontSelector.h" 38 #include "CSSFunctionValue.h"39 #include "CSSGradientValue.h"40 #include "CSSImageSetValue.h"41 #include "CSSImageValue.h"42 35 #include "CSSKeyframeRule.h" 43 36 #include "CSSKeyframesRule.h" … … 45 38 #include "CSSPrimitiveValueMappings.h" 46 39 #include "CSSPropertyNames.h" 47 #include "CSSReflectValue.h"48 40 #include "CSSSelector.h" 49 #include "CSSShadowValue.h"50 41 #include "CSSStyleRule.h" 51 42 #include "CSSStyleSheet.h" 52 #include "CSSValueList.h"53 43 #include "CachedResourceLoader.h" 54 44 #include "ElementRuleCollector.h" 55 #include "FilterOperation.h"56 45 #include "Frame.h" 57 46 #include "FrameSelection.h" … … 89 78 #include "SharedStringHash.h" 90 79 #include "StyleBuilder.h" 91 #include "StyleColor.h"92 #include "StyleCachedImage.h"93 80 #include "StyleFontSizeFunctions.h" 94 #include "StyleGeneratedImage.h"95 81 #include "StyleProperties.h" 96 82 #include "StylePropertyShorthand.h" … … 98 84 #include "StyleRule.h" 99 85 #include "StyleSheetContents.h" 100 #include "TransformFunctions.h"101 #include "TransformOperations.h"102 86 #include "UserAgentStyleSheets.h" 103 87 #include "ViewportStyleResolver.h" … … 129 113 m_parentStyle = nullptr; 130 114 m_ownedParentStyle = nullptr; 131 m_cssToLengthConversionData = CSSToLengthConversionData();132 115 } 133 116 … … 250 233 else 251 234 m_rootElementStyle = documentElementStyle ? documentElementStyle : documentElement->renderStyle(); 252 253 updateConversionData();254 }255 256 inline void StyleResolver::State::updateConversionData()257 {258 m_cssToLengthConversionData = CSSToLengthConversionData(m_style.get(), m_rootElementStyle, m_element ? m_element->document().renderView() : nullptr);259 235 } 260 236 … … 262 238 { 263 239 m_style = WTFMove(style); 264 updateConversionData();265 240 } 266 241 … … 1274 1249 builder.applyLowPriorityProperties(); 1275 1250 1251 for (auto& contentAttribute : builder.state().registeredContentAttributes()) 1252 ruleSets().mutableFeatures().registerContentAttribute(contentAttribute); 1253 1276 1254 if (cacheItem || !cacheHash) 1277 1255 return; … … 1299 1277 } 1300 1278 1301 RefPtr<StyleImage> StyleResolver::styleImage(CSSValue& value)1302 {1303 if (is<CSSImageGeneratorValue>(value)) {1304 if (is<CSSGradientValue>(value))1305 return StyleGeneratedImage::create(downcast<CSSGradientValue>(value).gradientWithStylesResolved(*this));1306 1307 if (is<CSSFilterImageValue>(value)) {1308 // FilterImage needs to calculate FilterOperations.1309 downcast<CSSFilterImageValue>(value).createFilterOperations(this);1310 }1311 return StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(value));1312 }1313 1314 if (is<CSSImageValue>(value) || is<CSSImageSetValue>(value) || is<CSSCursorImageValue>(value))1315 return StyleCachedImage::create(value);1316 1317 return nullptr;1318 }1319 1320 1279 void StyleResolver::initializeFontStyle() 1321 1280 { … … 1333 1292 } 1334 1293 1335 bool StyleResolver::colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue& value)1336 {1337 switch (value.valueID()) {1338 case CSSValueWebkitText:1339 case CSSValueWebkitLink:1340 case CSSValueWebkitActivelink:1341 case CSSValueCurrentcolor:1342 return true;1343 default:1344 return false;1345 }1346 }1347 1348 Color StyleResolver::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const1349 {1350 if (value.isRGBColor())1351 return value.color();1352 1353 auto identifier = value.valueID();1354 switch (identifier) {1355 case CSSValueWebkitText:1356 return document().textColor();1357 case CSSValueWebkitLink:1358 return (m_state.element()->isLink() && forVisitedLink) ? document().visitedLinkColor() : document().linkColor();1359 case CSSValueWebkitActivelink:1360 return document().activeLinkColor();1361 case CSSValueWebkitFocusRingColor:1362 return RenderTheme::singleton().focusRingColor(document().styleColorOptions(m_state.style()));1363 case CSSValueCurrentcolor:1364 // Color is an inherited property so depending on it effectively makes the property inherited.1365 // FIXME: Setting the flag as a side effect of calling this function is a bit oblique. Can we do better?1366 m_state.style()->setHasExplicitlyInheritedProperties();1367 return m_state.style()->color();1368 default:1369 return StyleColor::colorFromKeyword(identifier, document().styleColorOptions(m_state.style()));1370 }1371 }1372 1373 1294 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExpression& expression, bool result) 1374 1295 { … … 1416 1337 } 1417 1338 1418 static FilterOperation::OperationType filterOperationForType(CSSValueID type)1419 {1420 switch (type) {1421 case CSSValueUrl:1422 return FilterOperation::REFERENCE;1423 case CSSValueGrayscale:1424 return FilterOperation::GRAYSCALE;1425 case CSSValueSepia:1426 return FilterOperation::SEPIA;1427 case CSSValueSaturate:1428 return FilterOperation::SATURATE;1429 case CSSValueHueRotate:1430 return FilterOperation::HUE_ROTATE;1431 case CSSValueInvert:1432 return FilterOperation::INVERT;1433 case CSSValueAppleInvertLightness:1434 return FilterOperation::APPLE_INVERT_LIGHTNESS;1435 case CSSValueOpacity:1436 return FilterOperation::OPACITY;1437 case CSSValueBrightness:1438 return FilterOperation::BRIGHTNESS;1439 case CSSValueContrast:1440 return FilterOperation::CONTRAST;1441 case CSSValueBlur:1442 return FilterOperation::BLUR;1443 case CSSValueDropShadow:1444 return FilterOperation::DROP_SHADOW;1445 default:1446 break;1447 }1448 ASSERT_NOT_REACHED();1449 return FilterOperation::NONE;1450 }1451 1452 bool StyleResolver::createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations)1453 {1454 State& state = m_state;1455 ASSERT(outOperations.isEmpty());1456 1457 if (is<CSSPrimitiveValue>(inValue)) {1458 auto& primitiveValue = downcast<CSSPrimitiveValue>(inValue);1459 if (primitiveValue.valueID() == CSSValueNone)1460 return true;1461 }1462 1463 if (!is<CSSValueList>(inValue))1464 return false;1465 1466 FilterOperations operations;1467 for (auto& currentValue : downcast<CSSValueList>(inValue)) {1468 1469 if (is<CSSPrimitiveValue>(currentValue)) {1470 auto& primitiveValue = downcast<CSSPrimitiveValue>(currentValue.get());1471 if (!primitiveValue.isURI())1472 continue;1473 1474 String cssUrl = primitiveValue.stringValue();1475 URL url = document().completeURL(cssUrl);1476 1477 auto operation = ReferenceFilterOperation::create(cssUrl, url.fragmentIdentifier());1478 operations.operations().append(WTFMove(operation));1479 continue;1480 }1481 1482 if (!is<CSSFunctionValue>(currentValue))1483 continue;1484 1485 auto& filterValue = downcast<CSSFunctionValue>(currentValue.get());1486 FilterOperation::OperationType operationType = filterOperationForType(filterValue.name());1487 1488 // Check that all parameters are primitive values, with the1489 // exception of drop shadow which has a CSSShadowValue parameter.1490 const CSSPrimitiveValue* firstValue = nullptr;1491 if (operationType != FilterOperation::DROP_SHADOW) {1492 bool haveNonPrimitiveValue = false;1493 for (unsigned j = 0; j < filterValue.length(); ++j) {1494 if (!is<CSSPrimitiveValue>(*filterValue.itemWithoutBoundsCheck(j))) {1495 haveNonPrimitiveValue = true;1496 break;1497 }1498 }1499 if (haveNonPrimitiveValue)1500 continue;1501 if (filterValue.length())1502 firstValue = downcast<CSSPrimitiveValue>(filterValue.itemWithoutBoundsCheck(0));1503 }1504 1505 switch (operationType) {1506 case FilterOperation::GRAYSCALE:1507 case FilterOperation::SEPIA:1508 case FilterOperation::SATURATE: {1509 double amount = 1;1510 if (filterValue.length() == 1) {1511 amount = firstValue->doubleValue();1512 if (firstValue->isPercentage())1513 amount /= 100;1514 }1515 1516 operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType));1517 break;1518 }1519 case FilterOperation::HUE_ROTATE: {1520 double angle = 0;1521 if (filterValue.length() == 1)1522 angle = firstValue->computeDegrees();1523 1524 operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType));1525 break;1526 }1527 case FilterOperation::INVERT:1528 case FilterOperation::BRIGHTNESS:1529 case FilterOperation::CONTRAST:1530 case FilterOperation::OPACITY: {1531 double amount = 1;1532 if (filterValue.length() == 1) {1533 amount = firstValue->doubleValue();1534 if (firstValue->isPercentage())1535 amount /= 100;1536 }1537 1538 operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType));1539 break;1540 }1541 case FilterOperation::APPLE_INVERT_LIGHTNESS: {1542 operations.operations().append(InvertLightnessFilterOperation::create());1543 break;1544 }1545 case FilterOperation::BLUR: {1546 Length stdDeviation = Length(0, Fixed);1547 if (filterValue.length() >= 1)1548 stdDeviation = convertToFloatLength(firstValue, state.cssToLengthConversionData());1549 if (stdDeviation.isUndefined())1550 return false;1551 1552 operations.operations().append(BlurFilterOperation::create(stdDeviation));1553 break;1554 }1555 case FilterOperation::DROP_SHADOW: {1556 if (filterValue.length() != 1)1557 return false;1558 1559 const auto* cssValue = filterValue.itemWithoutBoundsCheck(0);1560 if (!is<CSSShadowValue>(cssValue))1561 continue;1562 1563 const auto& item = downcast<CSSShadowValue>(*cssValue);1564 int x = item.x->computeLength<int>(state.cssToLengthConversionData());1565 int y = item.y->computeLength<int>(state.cssToLengthConversionData());1566 IntPoint location(x, y);1567 int blur = item.blur ? item.blur->computeLength<int>(state.cssToLengthConversionData()) : 0;1568 Color color;1569 if (item.color)1570 color = colorFromPrimitiveValue(*item.color);1571 1572 operations.operations().append(DropShadowFilterOperation::create(location, blur, color.isValid() ? color : Color::transparent));1573 break;1574 }1575 default:1576 ASSERT_NOT_REACHED();1577 break;1578 }1579 }1580 1581 outOperations = operations;1582 return true;1583 }1584 1585 1339 } // namespace WebCore -
trunk/Source/WebCore/css/StyleResolver.h
r251864 r251916 23 23 24 24 #include "CSSSelector.h" 25 #include "CSSToLengthConversionData.h"26 #include "CSSToStyleMap.h"27 25 #include "DocumentRuleSets.h" 28 26 #include "ElementRuleCollector.h" … … 160 158 void initializeFontStyle(); 161 159 162 static bool colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue&);163 Color colorFromPrimitiveValue(const CSSPrimitiveValue&, bool forVisitedLink = false) const;164 165 160 bool hasSelectorForId(const AtomString&) const; 166 161 bool hasSelectorForAttribute(const Element&, const AtomString&) const; … … 191 186 void clearCachedPropertiesAffectedByViewportUnits(); 192 187 193 bool createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations);194 195 188 private: 196 189 void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*); 197 190 void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&); 198 199 void adjustStyleForInterCharacterRuby(); 200 191 201 192 enum ShouldUseMatchedPropertiesCache { DoNotUseMatchedPropertiesCache = 0, UseMatchedPropertiesCache }; 202 193 void applyMatchedProperties(const MatchResult&, const Element&, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache); … … 234 225 const Color& backgroundColor() const { return m_backgroundColor; } 235 226 236 const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; }237 238 227 const SelectorFilter* selectorFilter() const { return m_selectorFilter; } 239 228 240 229 private: 241 void updateConversionData();242 243 230 const Element* m_element { nullptr }; 244 231 std::unique_ptr<RenderStyle> m_style; … … 253 240 Color m_backgroundColor; 254 241 255 CSSToLengthConversionData m_cssToLengthConversionData;256 257 242 bool m_hasUAAppearance { false }; 258 243 }; … … 261 246 const State& state() const { return m_state; } 262 247 263 RefPtr<StyleImage> styleImage(CSSValue&);264 265 248 InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; } 266 249 … … 269 252 private: 270 253 void cacheBorderAndBackground(); 271 272 void applySVGProperty(CSSPropertyID, CSSValue*);273 254 274 255 static unsigned computeMatchedPropertiesHash(const MatchResult&); -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r251110 r251916 63 63 #include "SearchInputType.h" 64 64 #include "Settings.h" 65 #include "Style Resolver.h"65 #include "StyleGeneratedImage.h" 66 66 #include "TextControlInnerElements.h" 67 67 #include <wtf/IsoMallocInlines.h> … … 2067 2067 gradient->addStop(firstStop); 2068 2068 gradient->addStop(secondStop); 2069 gradient->resolveRGBColors(); 2070 2069 2071 return gradient; 2070 2072 } … … 2089 2091 textBlockStyle.setColor({ 0.0f, 0.0f, 0.0f, 0.6f }); 2090 2092 textBlockStyle.setTextOverflow(TextOverflow::Clip); 2091 textBlockStyle.setMaskImage( styleResolver().styleImage(autoFillStrongPasswordMaskImage()));2093 textBlockStyle.setMaskImage(StyleGeneratedImage::create(autoFillStrongPasswordMaskImage())); 2092 2094 // A stacking context is needed for the mask. 2093 2095 if (textBlockStyle.hasAutoZIndex()) -
trunk/Source/WebCore/style/StyleBuilder.cpp
r251864 r251916 35 35 #include "StyleBuilderGenerated.h" 36 36 #include "StyleFontSizeFunctions.h" 37 #include "StyleResolver.h" 37 38 38 39 namespace WebCore { … … 48 49 Builder::Builder(StyleResolver& resolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties) 49 50 : m_cascade(matchResult, cascadeLevels, includedProperties, directionFromStyle(*resolver.style())) 50 , m_state(*this, resolver) 51 { 51 , m_state(*this, *resolver.style(), *resolver.parentStyle(), resolver.rootElementStyle(), resolver.document(), resolver.element()) 52 { 53 ASSERT(resolver.style()); 54 ASSERT(resolver.parentStyle()); 52 55 } 53 56 -
trunk/Source/WebCore/style/StyleBuilderCustom.h
r251864 r251916 220 220 builderState.setZoom(RenderStyle::initialZoom()); 221 221 } else if (primitiveValue.valueID() == CSSValueDocument) { 222 float docZoom = builderState.rootElementStyle() .zoom();222 float docZoom = builderState.rootElementStyle() ? builderState.rootElementStyle()->zoom() : RenderStyle::initialZoom(); 223 223 builderState.setEffectiveZoom(docZoom); 224 224 builderState.setZoom(docZoom); … … 1321 1321 if (is<CSSImageGeneratorValue>(item)) { 1322 1322 if (is<CSSGradientValue>(item)) 1323 builderState.style().setContent(StyleGeneratedImage::create(downcast<CSSGradientValue>(item.get()).gradientWithStylesResolved(builderState .styleResolver())), didSet);1323 builderState.style().setContent(StyleGeneratedImage::create(downcast<CSSGradientValue>(item.get()).gradientWithStylesResolved(builderState)), didSet); 1324 1324 else 1325 1325 builderState.style().setContent(StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(item.get())), didSet); … … 1354 1354 didSet = true; 1355 1355 // Register the fact that the attribute value affects the style. 1356 builderState. styleResolver().ruleSets().mutableFeatures().registerContentAttribute(attr.localName());1356 builderState.registerContentAttribute(attr.localName()); 1357 1357 } else if (contentValue.isCounter()) { 1358 1358 auto* counterValue = contentValue.counterValue(); … … 1612 1612 fontDescription.setIsAbsoluteSize(parentIsAbsoluteSize || !(primitiveValue.isPercentage() || primitiveValue.isFontRelativeLength())); 1613 1613 if (primitiveValue.isLength()) { 1614 size = primitiveValue.computeLength<float>(CSSToLengthConversionData(&builderState.parentStyle(), &builderState.rootElementStyle(), builderState.document().renderView(), 1.0f, true));1614 size = primitiveValue.computeLength<float>(CSSToLengthConversionData(&builderState.parentStyle(), builderState.rootElementStyle(), builderState.document().renderView(), 1.0f, true)); 1615 1615 if (primitiveValue.isViewportPercentageLength()) 1616 1616 builderState.style().setHasViewportUnits(); … … 1748 1748 1749 1749 // Register the fact that the attribute value affects the style. 1750 builderState. styleResolver().ruleSets().mutableFeatures().registerContentAttribute(attr.localName());1750 builderState.registerContentAttribute(attr.localName()); 1751 1751 } else 1752 1752 builderState.style().setContentAltText(emptyAtom()); -
trunk/Source/WebCore/style/StyleBuilderState.cpp
r251864 r251916 31 31 #include "StyleBuilderState.h" 32 32 33 #include "CSSCursorImageValue.h" 34 #include "CSSFilterImageValue.h" 35 #include "CSSFunctionValue.h" 36 #include "CSSGradientValue.h" 37 #include "CSSImageSetValue.h" 38 #include "CSSImageValue.h" 39 #include "CSSShadowValue.h" 40 #include "RenderTheme.h" 33 41 #include "SVGElement.h" 34 42 #include "SVGSVGElement.h" 35 43 #include "StyleBuilder.h" 36 #include "StyleResolver.h" 44 #include "StyleCachedImage.h" 45 #include "StyleGeneratedImage.h" 46 #include "TransformFunctions.h" 37 47 38 48 namespace WebCore { 39 49 namespace Style { 40 50 41 BuilderState::BuilderState(Builder& builder, StyleResolver& styleResolver)51 BuilderState::BuilderState(Builder& builder, RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* rootElementStyle, const Document& document, const Element* element) 42 52 : m_builder(builder) 43 53 , m_styleMap(*this) 44 , m_cssToLengthConversionData(styleResolver.state().cssToLengthConversionData()) 45 , m_styleResolver(styleResolver) 46 , m_style(*styleResolver.style()) 47 , m_parentStyle(*styleResolver.parentStyle()) 48 , m_rootElementStyle(styleResolver.rootElementStyle() ? *styleResolver.rootElementStyle() : RenderStyle::defaultStyle()) 49 , m_document(m_styleResolver.document()) 50 , m_element(m_styleResolver.element()) 51 { 52 ASSERT(styleResolver.style()); 53 ASSERT(styleResolver.parentStyle()); 54 , m_style(style) 55 , m_parentStyle(parentStyle) 56 , m_rootElementStyle(rootElementStyle) 57 , m_cssToLengthConversionData(&style, rootElementStyle, document.renderView()) 58 , m_document(document) 59 , m_element(element) 60 { 54 61 } 55 62 … … 74 81 RefPtr<StyleImage> BuilderState::createStyleImage(CSSValue& value) 75 82 { 76 return m_styleResolver.styleImage(value); 77 } 78 79 bool BuilderState::createFilterOperations(const CSSValue& value, FilterOperations& outOperations) 80 { 81 return m_styleResolver.createFilterOperations(value, outOperations); 83 if (is<CSSImageGeneratorValue>(value)) { 84 if (is<CSSGradientValue>(value)) 85 return StyleGeneratedImage::create(downcast<CSSGradientValue>(value).gradientWithStylesResolved(*this)); 86 87 if (is<CSSFilterImageValue>(value)) { 88 // FilterImage needs to calculate FilterOperations. 89 downcast<CSSFilterImageValue>(value).createFilterOperations(*this); 90 } 91 return StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(value)); 92 } 93 94 if (is<CSSImageValue>(value) || is<CSSImageSetValue>(value) || is<CSSCursorImageValue>(value)) 95 return StyleCachedImage::create(value); 96 97 return nullptr; 98 } 99 100 static FilterOperation::OperationType filterOperationForType(CSSValueID type) 101 { 102 switch (type) { 103 case CSSValueUrl: 104 return FilterOperation::REFERENCE; 105 case CSSValueGrayscale: 106 return FilterOperation::GRAYSCALE; 107 case CSSValueSepia: 108 return FilterOperation::SEPIA; 109 case CSSValueSaturate: 110 return FilterOperation::SATURATE; 111 case CSSValueHueRotate: 112 return FilterOperation::HUE_ROTATE; 113 case CSSValueInvert: 114 return FilterOperation::INVERT; 115 case CSSValueAppleInvertLightness: 116 return FilterOperation::APPLE_INVERT_LIGHTNESS; 117 case CSSValueOpacity: 118 return FilterOperation::OPACITY; 119 case CSSValueBrightness: 120 return FilterOperation::BRIGHTNESS; 121 case CSSValueContrast: 122 return FilterOperation::CONTRAST; 123 case CSSValueBlur: 124 return FilterOperation::BLUR; 125 case CSSValueDropShadow: 126 return FilterOperation::DROP_SHADOW; 127 default: 128 break; 129 } 130 ASSERT_NOT_REACHED(); 131 return FilterOperation::NONE; 132 } 133 134 bool BuilderState::createFilterOperations(const CSSValue& inValue, FilterOperations& outOperations) 135 { 136 // FIXME: Move this code somewhere else. 137 138 ASSERT(outOperations.isEmpty()); 139 140 if (is<CSSPrimitiveValue>(inValue)) { 141 auto& primitiveValue = downcast<CSSPrimitiveValue>(inValue); 142 if (primitiveValue.valueID() == CSSValueNone) 143 return true; 144 } 145 146 if (!is<CSSValueList>(inValue)) 147 return false; 148 149 FilterOperations operations; 150 for (auto& currentValue : downcast<CSSValueList>(inValue)) { 151 152 if (is<CSSPrimitiveValue>(currentValue)) { 153 auto& primitiveValue = downcast<CSSPrimitiveValue>(currentValue.get()); 154 if (!primitiveValue.isURI()) 155 continue; 156 157 String cssUrl = primitiveValue.stringValue(); 158 URL url = document().completeURL(cssUrl); 159 160 auto operation = ReferenceFilterOperation::create(cssUrl, url.fragmentIdentifier()); 161 operations.operations().append(WTFMove(operation)); 162 continue; 163 } 164 165 if (!is<CSSFunctionValue>(currentValue)) 166 continue; 167 168 auto& filterValue = downcast<CSSFunctionValue>(currentValue.get()); 169 FilterOperation::OperationType operationType = filterOperationForType(filterValue.name()); 170 171 // Check that all parameters are primitive values, with the 172 // exception of drop shadow which has a CSSShadowValue parameter. 173 const CSSPrimitiveValue* firstValue = nullptr; 174 if (operationType != FilterOperation::DROP_SHADOW) { 175 bool haveNonPrimitiveValue = false; 176 for (unsigned j = 0; j < filterValue.length(); ++j) { 177 if (!is<CSSPrimitiveValue>(*filterValue.itemWithoutBoundsCheck(j))) { 178 haveNonPrimitiveValue = true; 179 break; 180 } 181 } 182 if (haveNonPrimitiveValue) 183 continue; 184 if (filterValue.length()) 185 firstValue = downcast<CSSPrimitiveValue>(filterValue.itemWithoutBoundsCheck(0)); 186 } 187 188 switch (operationType) { 189 case FilterOperation::GRAYSCALE: 190 case FilterOperation::SEPIA: 191 case FilterOperation::SATURATE: { 192 double amount = 1; 193 if (filterValue.length() == 1) { 194 amount = firstValue->doubleValue(); 195 if (firstValue->isPercentage()) 196 amount /= 100; 197 } 198 199 operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType)); 200 break; 201 } 202 case FilterOperation::HUE_ROTATE: { 203 double angle = 0; 204 if (filterValue.length() == 1) 205 angle = firstValue->computeDegrees(); 206 207 operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType)); 208 break; 209 } 210 case FilterOperation::INVERT: 211 case FilterOperation::BRIGHTNESS: 212 case FilterOperation::CONTRAST: 213 case FilterOperation::OPACITY: { 214 double amount = 1; 215 if (filterValue.length() == 1) { 216 amount = firstValue->doubleValue(); 217 if (firstValue->isPercentage()) 218 amount /= 100; 219 } 220 221 operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType)); 222 break; 223 } 224 case FilterOperation::APPLE_INVERT_LIGHTNESS: { 225 operations.operations().append(InvertLightnessFilterOperation::create()); 226 break; 227 } 228 case FilterOperation::BLUR: { 229 Length stdDeviation = Length(0, Fixed); 230 if (filterValue.length() >= 1) 231 stdDeviation = convertToFloatLength(firstValue, cssToLengthConversionData()); 232 if (stdDeviation.isUndefined()) 233 return false; 234 235 operations.operations().append(BlurFilterOperation::create(stdDeviation)); 236 break; 237 } 238 case FilterOperation::DROP_SHADOW: { 239 if (filterValue.length() != 1) 240 return false; 241 242 const auto* cssValue = filterValue.itemWithoutBoundsCheck(0); 243 if (!is<CSSShadowValue>(cssValue)) 244 continue; 245 246 const auto& item = downcast<CSSShadowValue>(*cssValue); 247 int x = item.x->computeLength<int>(cssToLengthConversionData()); 248 int y = item.y->computeLength<int>(cssToLengthConversionData()); 249 IntPoint location(x, y); 250 int blur = item.blur ? item.blur->computeLength<int>(cssToLengthConversionData()) : 0; 251 Color color; 252 if (item.color) 253 color = colorFromPrimitiveValue(*item.color); 254 255 operations.operations().append(DropShadowFilterOperation::create(location, blur, color.isValid() ? color : Color::transparent)); 256 break; 257 } 258 default: 259 ASSERT_NOT_REACHED(); 260 break; 261 } 262 } 263 264 outOperations = operations; 265 return true; 266 } 267 268 bool BuilderState::isColorFromPrimitiveValueDerivedFromElement(const CSSPrimitiveValue& value) 269 { 270 switch (value.valueID()) { 271 case CSSValueWebkitText: 272 case CSSValueWebkitLink: 273 case CSSValueWebkitActivelink: 274 case CSSValueCurrentcolor: 275 return true; 276 default: 277 return false; 278 } 82 279 } 83 280 84 281 Color BuilderState::colorFromPrimitiveValue(const CSSPrimitiveValue& value, bool forVisitedLink) const 85 282 { 86 return m_styleResolver.colorFromPrimitiveValue(value, forVisitedLink); 283 if (value.isRGBColor()) 284 return value.color(); 285 286 auto identifier = value.valueID(); 287 switch (identifier) { 288 case CSSValueWebkitText: 289 return document().textColor(); 290 case CSSValueWebkitLink: 291 return (element() && element()->isLink() && forVisitedLink) ? document().visitedLinkColor() : document().linkColor(); 292 case CSSValueWebkitActivelink: 293 return document().activeLinkColor(); 294 case CSSValueWebkitFocusRingColor: 295 return RenderTheme::singleton().focusRingColor(document().styleColorOptions(&m_style)); 296 case CSSValueCurrentcolor: 297 // Color is an inherited property so depending on it effectively makes the property inherited. 298 // FIXME: Setting the flag as a side effect of calling this function is a bit oblique. Can we do better? 299 m_style.setHasExplicitlyInheritedProperties(); 300 return m_style.color(); 301 default: 302 return StyleColor::colorFromKeyword(identifier, document().styleColorOptions(&m_style)); 303 } 304 } 305 306 void BuilderState::registerContentAttribute(const AtomString& attributeLocalName) 307 { 308 if (style().styleType() == PseudoId::Before || style().styleType() == PseudoId::After) 309 m_registeredContentAttributes.append(attributeLocalName); 87 310 } 88 311 -
trunk/Source/WebCore/style/StyleBuilderState.h
r251864 r251916 44 44 class BuilderState { 45 45 public: 46 BuilderState(Builder&, StyleResolver&);46 BuilderState(Builder&, RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* rootElementStyle, const Document&, const Element*); 47 47 48 48 Builder& builder() { return m_builder; } 49 StyleResolver& styleResolver() { return m_styleResolver; }50 49 51 50 RenderStyle& style() { return m_style; } 52 51 const RenderStyle& parentStyle() const { return m_parentStyle; } 53 const RenderStyle &rootElementStyle() const { return m_rootElementStyle; }52 const RenderStyle* rootElementStyle() const { return m_rootElementStyle; } 54 53 55 54 const Document& document() const { return m_document.get(); } … … 79 78 RefPtr<StyleImage> createStyleImage(CSSValue&); 80 79 bool createFilterOperations(const CSSValue&, FilterOperations& outOperations); 80 81 static bool isColorFromPrimitiveValueDerivedFromElement(const CSSPrimitiveValue&); 81 82 Color colorFromPrimitiveValue(const CSSPrimitiveValue&, bool forVisitedLink = false) const; 83 84 const Vector<AtomString>& registeredContentAttributes() const { return m_registeredContentAttributes; } 85 void registerContentAttribute(const AtomString& attributeLocalName); 82 86 83 87 const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; } … … 100 104 101 105 CSSToStyleMap m_styleMap; 102 CSSToLengthConversionData m_cssToLengthConversionData;103 104 // FIXME: Remove.105 StyleResolver& m_styleResolver;106 106 107 107 RenderStyle& m_style; 108 108 const RenderStyle& m_parentStyle; 109 const RenderStyle& m_rootElementStyle; 109 const RenderStyle* m_rootElementStyle; 110 111 const CSSToLengthConversionData m_cssToLengthConversionData; 110 112 111 113 Ref<const Document> m_document; … … 122 124 123 125 bool m_fontDirty { false }; 126 Vector<AtomString> m_registeredContentAttributes; 124 127 }; 125 128
Note: See TracChangeset
for help on using the changeset viewer.