Changeset 251864 in webkit
- Timestamp:
- Oct 31, 2019 11:55:34 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r251862 r251864 1 2019-10-31 Antti Koivisto <antti@apple.com> 2 3 Introduce Style::Builder 4 https://bugs.webkit.org/show_bug.cgi?id=203682 5 6 Reviewed by Zalan Bujtas. 7 8 Encapsulate the style building step into a new Builder class. It owns the cascade and the style building state. 9 10 Move tha applying code from StyleResolver and PropertyCascade there. 11 Move a bunch of font related state from StyleResolver::State to BuilderState. 12 13 * DerivedSources-output.xcfilelist: 14 * Sources.txt: 15 * WebCore.xcodeproj/project.pbxproj: 16 * css/CSSVariableReferenceValue.cpp: 17 (WebCore::resolveVariableReference): 18 * css/DOMCSSRegisterCustomProperty.cpp: 19 (WebCore::DOMCSSRegisterCustomProperty::registerProperty): 20 * css/StyleResolver.cpp: 21 (WebCore::StyleResolver::styleForKeyframe): 22 (WebCore::StyleResolver::styleForPage): 23 (WebCore::StyleResolver::applyMatchedProperties): 24 (WebCore::StyleResolver::applyPropertyToCurrentStyle): 25 (WebCore::StyleResolver::initializeFontStyle): 26 (WebCore::StyleResolver::adjustStyleForInterCharacterRuby): Deleted. 27 (WebCore::checkForOrientationChange): Deleted. 28 (WebCore::StyleResolver::updateFont): Deleted. 29 (WebCore::StyleResolver::useSVGZoomRules const): Deleted. 30 (WebCore::StyleResolver::useSVGZoomRulesForLength const): Deleted. 31 (WebCore::StyleResolver::checkForTextSizeAdjust): Deleted. 32 (WebCore::StyleResolver::checkForZoomChange): Deleted. 33 (WebCore::StyleResolver::checkForGenericFamilyChange): Deleted. 34 (WebCore::StyleResolver::setFontSize): Deleted. 35 * css/StyleResolver.h: 36 (WebCore::StyleResolver::State::setFontSizeHasViewportUnits): Deleted. 37 (WebCore::StyleResolver::State::fontSizeHasViewportUnits const): Deleted. 38 (WebCore::StyleResolver::State::useSVGZoomRules const): Deleted. 39 * css/parser/CSSParser.cpp: 40 (WebCore::CSSParser::parseValueWithVariableReferences): 41 * css/parser/CSSPropertyParser.cpp: 42 * style/PropertyCascade.cpp: 43 (WebCore::Style::PropertyCascade::PropertyCascade): 44 (WebCore::Style::PropertyCascade::set): 45 (WebCore::Style::PropertyCascade::propertyCascadeForRollback const): 46 (WebCore::Style::PropertyCascade::resolveDirectionAndWritingMode const): 47 (WebCore::Style::PropertyCascade::applyDeferredProperties): Deleted. 48 (WebCore::Style::PropertyCascade::applyProperties): Deleted. 49 (WebCore::Style::PropertyCascade::applyPropertiesImpl): Deleted. 50 (WebCore::Style::PropertyCascade::applyCustomProperties): Deleted. 51 (WebCore::Style::PropertyCascade::applyCustomProperty): Deleted. 52 (WebCore::Style::PropertyCascade::propertyCascadeForRollback): Deleted. 53 (WebCore::Style::PropertyCascade::applyProperty): Deleted. 54 (WebCore::Style::PropertyCascade::resolveValue): Deleted. 55 (WebCore::Style::PropertyCascade::resolvedVariableValue): Deleted. 56 (WebCore::Style::PropertyCascade::resolveDirectionAndWritingMode): Deleted. 57 * style/PropertyCascade.h: 58 (WebCore::Style::PropertyCascade::deferredProperties const): 59 (WebCore::Style::PropertyCascade::customProperties const): 60 (WebCore::Style::PropertyCascade::direction const): 61 (WebCore::Style::PropertyCascade::builderState): Deleted. 62 * style/StyleBuilder.cpp: Added. 63 (WebCore::Style::directionFromStyle): 64 (WebCore::Style::Builder::Builder): 65 (WebCore::Style::Builder::applyAllProperties): 66 (WebCore::Style::Builder::applyHighPriorityProperties): 67 (WebCore::Style::Builder::applyLowPriorityProperties): 68 (WebCore::Style::Builder::applyPropertyValue): 69 (WebCore::Style::Builder::applyDeferredProperties): 70 (WebCore::Style::Builder::applyProperties): 71 (WebCore::Style::Builder::applyPropertiesImpl): 72 (WebCore::Style::Builder::applyCustomProperties): 73 (WebCore::Style::Builder::applyCustomProperty): 74 (WebCore::Style::Builder::applyCascadeProperty): 75 (WebCore::Style::Builder::applyProperty): 76 (WebCore::Style::Builder::resolveValue): 77 (WebCore::Style::Builder::resolvedVariableValue): 78 * style/StyleBuilder.h: Added. 79 (WebCore::Style::Builder::applyProperty): 80 (WebCore::Style::Builder::state): 81 * style/StyleBuilderCustom.h: 82 (WebCore::Style::BuilderCustom::applyValueFontSize): 83 * style/StyleBuilderState.cpp: 84 (WebCore::Style::BuilderState::BuilderState): 85 (WebCore::Style::BuilderState::useSVGZoomRules const): 86 (WebCore::Style::BuilderState::useSVGZoomRulesForLength const): 87 (WebCore::Style::BuilderState::adjustStyleForInterCharacterRuby): 88 (WebCore::Style::BuilderState::updateFont): 89 (WebCore::Style::BuilderState::updateFontForTextSizeAdjust): 90 (WebCore::Style::BuilderState::updateFontForZoomChange): 91 (WebCore::Style::BuilderState::updateFontForGenericFamilyChange): 92 (WebCore::Style::BuilderState::updateFontForOrientationChange): 93 (WebCore::Style::BuilderState::setFontSize): 94 * style/StyleBuilderState.h: 95 (WebCore::Style::BuilderState::builder): 96 (WebCore::Style::BuilderState::setFontDirty): 97 (WebCore::Style::BuilderState::cascade): Deleted. 98 (WebCore::Style::BuilderState::clearFontDirty): Deleted. 99 1 100 2019-10-31 Alex Christensen <achristensen@webkit.org> 2 101 -
trunk/Source/WebCore/DerivedSources-output.xcfilelist
r251850 r251864 2150 2150 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/Settings.h 2151 2151 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StreamInternalsBuiltins.h 2152 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StyleBuilder.cpp 2152 2153 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StyleBuilderGenerated.cpp 2153 2154 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/StylePropertyShorthandFunctions.cpp -
trunk/Source/WebCore/Sources.txt
r251841 r251864 2346 2346 style/InlineTextBoxStyle.cpp 2347 2347 style/PropertyCascade.cpp 2348 style/StyleBuilder.cpp 2348 2349 style/StyleBuilderState.cpp 2349 2350 style/StyleChange.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r251841 r251864 4844 4844 E4ABABF52368C6EF00FA4345 /* CascadeLevel.h in Headers */ = {isa = PBXBuildFile; fileRef = E4ABABF42368C6EF00FA4345 /* CascadeLevel.h */; }; 4845 4845 E4ABAC04236AE95900FA4345 /* StyleBuilderGenerated.h in Headers */ = {isa = PBXBuildFile; fileRef = E4ABAC02236AE95800FA4345 /* StyleBuilderGenerated.h */; }; 4846 E4ABAC06236B016D00FA4345 /* StyleBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E4ABAC05236B016C00FA4345 /* StyleBuilder.h */; }; 4846 4847 E4AE7C1617D1BB950009FB31 /* ElementIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1517D1BB950009FB31 /* ElementIterator.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4847 4848 E4AE7C1A17D232350009FB31 /* ElementAncestorIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 15181 15182 E4ABABF42368C6EF00FA4345 /* CascadeLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CascadeLevel.h; sourceTree = "<group>"; }; 15182 15183 E4ABAC02236AE95800FA4345 /* StyleBuilderGenerated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilderGenerated.h; sourceTree = "<group>"; }; 15184 E4ABAC05236B016C00FA4345 /* StyleBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilder.h; sourceTree = "<group>"; }; 15185 E4ABAC07236B018100FA4345 /* StyleBuilder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StyleBuilder.cpp; sourceTree = "<group>"; }; 15183 15186 E4AE7C1517D1BB950009FB31 /* ElementIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIterator.h; sourceTree = "<group>"; }; 15184 15187 E4AE7C1917D232350009FB31 /* ElementAncestorIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementAncestorIterator.h; sourceTree = "<group>"; }; … … 26959 26962 E4ABABE52361A34200FA4345 /* PropertyCascade.cpp */, 26960 26963 E4ABABE22361A32900FA4345 /* PropertyCascade.h */, 26964 E4ABAC07236B018100FA4345 /* StyleBuilder.cpp */, 26965 E4ABAC05236B016C00FA4345 /* StyleBuilder.h */, 26961 26966 83B9687919F8AB83004EF7AF /* StyleBuilderConverter.h */, 26962 26967 835D363619FF6193004C93AB /* StyleBuilderCustom.h */, … … 30573 30578 93A806201E03B585008A1F26 /* JSLongRange.h in Headers */, 30574 30579 CDAB6D2E17C814EE00C60B34 /* JSMediaControlsHost.h in Headers */, 30580 E4ABAC06236B016D00FA4345 /* StyleBuilder.h in Headers */, 30575 30581 159741DB1B7D140100201C92 /* JSMediaDeviceInfo.h in Headers */, 30576 30582 15739BBB1B42012D00D258C1 /* JSMediaDevices.h in Headers */, -
trunk/Source/WebCore/css/CSSVariableReferenceValue.cpp
r251796 r251864 31 31 #include "CSSVariableReferenceValue.h" 32 32 33 #include "PropertyCascade.h"34 33 #include "RenderStyle.h" 34 #include "StyleBuilder.h" 35 35 #include "StyleResolver.h" 36 36 … … 68 68 69 69 // Apply this variable first, in case it is still unresolved 70 builderState. cascade().applyCustomProperty(variableName);70 builderState.builder().applyCustomProperty(variableName); 71 71 72 72 // Apply fallback to detect cycles -
trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp
r251796 r251864 34 34 #include "DOMCSSNamespace.h" 35 35 #include "Document.h" 36 #include " PropertyCascade.h"36 #include "StyleBuilder.h" 37 37 #include "StyleBuilderConverter.h" 38 38 #include <wtf/text/WTFString.h> … … 61 61 62 62 MatchResult matchResult; 63 Style:: PropertyCascade dummyCascade(styleResolver, matchResult, { });64 initialValue = CSSPropertyParser::parseTypedCustomPropertyValue(descriptor.name, descriptor.syntax, tokenizer.tokenRange(), dummy Cascade.builderState(), strictCSSParserContext());63 Style::Builder dummyBuilder(styleResolver, matchResult, { }); 64 initialValue = CSSPropertyParser::parseTypedCustomPropertyValue(descriptor.name, descriptor.syntax, tokenizer.tokenRange(), dummyBuilder.state(), strictCSSParserContext()); 65 65 66 66 if (!initialValue || !initialValue->isResolved()) -
trunk/Source/WebCore/css/StyleResolver.cpp
r251796 r251864 3 3 * Copyright (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 5 * Copyright (C) 2005-201 4Apple Inc. All rights reserved.5 * Copyright (C) 2005-2019 Apple Inc. All rights reserved. 6 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> … … 33 33 #include "CSSCalculationValue.h" 34 34 #include "CSSCursorImageValue.h" 35 #include "CSSCustomPropertyValue.h"36 35 #include "CSSDefaultStyleSheets.h" 37 36 #include "CSSFilterImageValue.h" … … 52 51 #include "CSSStyleSheet.h" 53 52 #include "CSSValueList.h" 54 #include "CSSValuePool.h"55 53 #include "CachedResourceLoader.h" 56 54 #include "ElementRuleCollector.h" … … 74 72 #include "NodeRenderStyle.h" 75 73 #include "PageRuleCollector.h" 76 #include "PaintWorkletGlobalScope.h"77 74 #include "Pair.h" 78 #include "PropertyCascade.h"79 75 #include "Quirks.h" 80 76 #include "RenderScrollbar.h" … … 88 84 #include "SVGFontFaceElement.h" 89 85 #include "SVGNames.h" 90 #include "SVGSVGElement.h"91 86 #include "SVGURIReference.h" 92 87 #include "Settings.h" 93 88 #include "ShadowRoot.h" 94 89 #include "SharedStringHash.h" 90 #include "StyleBuilder.h" 95 91 #include "StyleColor.h" 96 92 #include "StyleCachedImage.h" … … 118 114 using namespace HTMLNames; 119 115 120 static const CSSPropertyID firstLowPriorityProperty = static_cast<CSSPropertyID>(lastHighPriorityProperty + 1);121 122 116 inline void StyleResolver::State::cacheBorderAndBackground() 123 117 { … … 364 358 state.setParentStyle(RenderStyle::clonePtr(*elementStyle)); 365 359 366 Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }); 367 368 cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty); 369 370 // If our font got dirtied, update it now. 371 updateFont(cascade); 372 373 // Now resolve remaining custom properties and the rest, in any order 374 cascade.applyCustomProperties(); 375 376 cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty); 377 378 // If our font got dirtied by one of the non-essential font props, update it a second time. 379 updateFont(cascade); 380 381 cascade.applyDeferredProperties(); 360 Style::Builder builder(*this, result, { Style::CascadeLevel::Author }); 361 builder.applyAllProperties(); 382 362 383 363 adjustRenderStyle(*state.style(), *state.parentStyle(), nullptr, nullptr); … … 564 544 auto& result = collector.matchResult(); 565 545 566 Style::PropertyCascade cascade(*this, result, { Style::CascadeLevel::Author }); 567 568 cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty); 569 570 // If our font got dirtied, update it now. 571 updateFont(cascade); 572 573 // Now resolve remaining custom properties and the rest, in any order 574 cascade.applyCustomProperties(); 575 576 cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty); 577 578 cascade.applyDeferredProperties(); 546 Style::Builder builder(*this, result, { Style::CascadeLevel::Author }); 547 builder.applyAllProperties(); 579 548 580 549 // Now return the style. … … 679 648 } 680 649 #endif 681 682 void StyleResolver::adjustStyleForInterCharacterRuby()683 {684 RenderStyle* style = m_state.style();685 if (style->rubyPosition() != RubyPosition::InterCharacter || !m_state.element() || !m_state.element()->hasTagName(rtTag))686 return;687 style->setTextAlign(TextAlignMode::Center);688 if (style->isHorizontalWritingMode())689 style->setWritingMode(LeftToRightWritingMode);690 }691 650 692 651 static bool hasEffectiveDisplayNoneForDisplayContents(const Element& element) … … 1142 1101 } 1143 1102 1144 static void checkForOrientationChange(RenderStyle& style)1145 {1146 auto [fontOrientation, glyphOrientation] = style.fontAndGlyphOrientation();1147 1148 const auto& fontDescription = style.fontDescription();1149 if (fontDescription.orientation() == fontOrientation && fontDescription.nonCJKGlyphOrientation() == glyphOrientation)1150 return;1151 1152 auto newFontDescription = fontDescription;1153 newFontDescription.setNonCJKGlyphOrientation(glyphOrientation);1154 newFontDescription.setOrientation(fontOrientation);1155 style.setFontDescription(WTFMove(newFontDescription));1156 }1157 1158 void StyleResolver::updateFont(Style::PropertyCascade& cascade)1159 {1160 auto& style = *m_state.style();1161 if (!cascade.builderState().fontDirty() && style.fontCascade().fonts())1162 return;1163 1164 #if ENABLE(TEXT_AUTOSIZING)1165 checkForTextSizeAdjust(style);1166 #endif1167 checkForGenericFamilyChange(style, m_state.parentStyle());1168 checkForZoomChange(style, m_state.parentStyle());1169 checkForOrientationChange(style);1170 style.fontCascade().update(&document().fontSelector());1171 if (m_state.fontSizeHasViewportUnits())1172 style.setHasViewportUnits(true);1173 1174 cascade.builderState().clearFontDirty();1175 }1176 1103 1177 1104 Vector<RefPtr<StyleRule>> StyleResolver::styleRulesForElement(const Element* element, unsigned rulesToInclude) … … 1326 1253 // If so, we cache the border and background styles so that RenderTheme::adjustStyle() 1327 1254 // can look at them later to figure out if this is a styled form control or not. 1328 Style::PropertyCascade cascade(*this, matchResult, { Style::CascadeLevel::UserAgent }, includedProperties); 1329 1330 cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition); 1331 adjustStyleForInterCharacterRuby(); 1332 1333 #if ENABLE(DARK_MODE_CSS) 1334 // Supported color schemes can affect resolved colors, so we need to apply that property before any color properties. 1335 cascade.applyProperties(CSSPropertyColorScheme, CSSPropertyColorScheme); 1336 #endif 1337 1338 cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty); 1339 1340 // If our font got dirtied, update it now. 1341 updateFont(cascade); 1342 1343 // Now resolve remaining custom properties and the rest, in any order 1344 cascade.applyCustomProperties(); 1345 1346 cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty); 1255 Style::Builder builder(*this, matchResult, { Style::CascadeLevel::UserAgent }, includedProperties); 1256 builder.applyAllProperties(); 1347 1257 1348 1258 state.cacheBorderAndBackground(); 1349 1259 } 1350 1260 1351 Style::PropertyCascade cascade(*this, matchResult, Style::allCascadeLevels(), includedProperties); 1352 1353 cascade.applyProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition); 1354 adjustStyleForInterCharacterRuby(); 1355 1356 #if ENABLE(DARK_MODE_CSS) 1357 // Supported color schemes can affect resolved colors, so we need to apply that property before any color properties. 1358 cascade.applyProperties(CSSPropertyColorScheme, CSSPropertyColorScheme); 1359 #endif 1360 1361 cascade.applyProperties(firstCSSProperty, lastHighPriorityProperty); 1261 Style::Builder builder(*this, matchResult, Style::allCascadeLevels(), includedProperties); 1262 1263 // High priority properties may affect resolution of other properties (they are mostly font related). 1264 builder.applyHighPriorityProperties(); 1362 1265 1363 1266 // If the effective zoom value changes, we can't use the matched properties cache. Start over. … … 1365 1268 return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache); 1366 1269 1367 // If our font got dirtied, update it now.1368 updateFont(cascade);1369 1370 1270 // If the font changed, we can't use the matched properties cache. Start over. 1371 1271 if (cacheItem && cacheItem->renderStyle->fontDescription() != state.style()->fontDescription()) 1372 1272 return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache); 1373 1273 1374 // Now resolve remaining custom properties and the rest, in any order 1375 cascade.applyCustomProperties(); 1376 1377 cascade.applyProperties(firstLowPriorityProperty, lastCSSProperty); 1378 1379 // Finally, some properties must be applied in the order they were parsed. 1380 // There are some CSS properties that affect the same RenderStyle values, 1381 // so to preserve behavior, we queue them up during cascade and flush here. 1382 cascade.applyDeferredProperties(); 1383 1384 ASSERT(!cascade.builderState().fontDirty()); 1274 builder.applyLowPriorityProperties(); 1385 1275 1386 1276 if (cacheItem || !cacheHash) … … 1405 1295 1406 1296 MatchResult matchResult; 1407 Style::PropertyCascade cascade(*this, matchResult, { }); 1408 cascade.applyProperty(id, *value); 1409 updateFont(cascade); 1410 } 1411 1412 // SVG handles zooming in a different way compared to CSS. The whole document is scaled instead 1413 // of each individual length value in the render style / tree. CSSPrimitiveValue::computeLength*() 1414 // multiplies each resolved length with the zoom multiplier - so for SVG we need to disable that. 1415 // Though all CSS values that can be applied to outermost <svg> elements (width/height/border/padding...) 1416 // need to respect the scaling. RenderBox (the parent class of RenderSVGRoot) grabs values like 1417 // width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale, 1418 // if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific 1419 // properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size). 1420 bool StyleResolver::useSVGZoomRules() const 1421 { 1422 return m_state.element() && m_state.element()->isSVGElement(); 1423 } 1424 1425 // Scale with/height properties on inline SVG root. 1426 bool StyleResolver::useSVGZoomRulesForLength() const 1427 { 1428 return is<SVGElement>(m_state.element()) && !(is<SVGSVGElement>(*m_state.element()) && m_state.element()->parentNode()); 1297 Style::Builder builder(*this, matchResult, { }); 1298 builder.applyPropertyValue(id, *value); 1429 1299 } 1430 1300 … … 1446 1316 1447 1317 return nullptr; 1448 }1449 1450 #if ENABLE(TEXT_AUTOSIZING)1451 void StyleResolver::checkForTextSizeAdjust(RenderStyle& style)1452 {1453 if (style.textSizeAdjust().isAuto()1454 || !settings().textAutosizingEnabled()1455 || (settings().textAutosizingUsesIdempotentMode() && !style.textSizeAdjust().isNone()))1456 return;1457 1458 auto newFontDescription = style.fontDescription();1459 if (!style.textSizeAdjust().isNone())1460 newFontDescription.setComputedSize(newFontDescription.specifiedSize() * style.textSizeAdjust().multiplier());1461 else1462 newFontDescription.setComputedSize(newFontDescription.specifiedSize());1463 style.setFontDescription(WTFMove(newFontDescription));1464 }1465 #endif1466 1467 void StyleResolver::checkForZoomChange(RenderStyle& style, const RenderStyle* parentStyle)1468 {1469 if (!parentStyle)1470 return;1471 1472 if (style.effectiveZoom() == parentStyle->effectiveZoom() && style.textZoom() == parentStyle->textZoom())1473 return;1474 1475 const auto& childFont = style.fontDescription();1476 auto newFontDescription = childFont;1477 setFontSize(newFontDescription, childFont.specifiedSize());1478 style.setFontDescription(WTFMove(newFontDescription));1479 }1480 1481 void StyleResolver::checkForGenericFamilyChange(RenderStyle& style, const RenderStyle* parentStyle)1482 {1483 const auto& childFont = style.fontDescription();1484 1485 if (childFont.isAbsoluteSize() || !parentStyle)1486 return;1487 1488 const auto& parentFont = parentStyle->fontDescription();1489 if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())1490 return;1491 // We know the parent is monospace or the child is monospace, and that font1492 // size was unspecified. We want to scale our font size as appropriate.1493 // If the font uses a keyword size, then we refetch from the table rather than1494 // multiplying by our scale factor.1495 float size;1496 if (CSSValueID sizeIdentifier = childFont.keywordSizeAsIdentifier())1497 size = Style::fontSizeForKeyword(sizeIdentifier, childFont.useFixedDefaultSize(), document());1498 else {1499 float fixedScaleFactor = (settings().defaultFixedFontSize() && settings().defaultFontSize())1500 ? static_cast<float>(settings().defaultFixedFontSize()) / settings().defaultFontSize()1501 : 1;1502 size = parentFont.useFixedDefaultSize() ?1503 childFont.specifiedSize() / fixedScaleFactor :1504 childFont.specifiedSize() * fixedScaleFactor;1505 }1506 1507 auto newFontDescription = childFont;1508 setFontSize(newFontDescription, size);1509 style.setFontDescription(WTFMove(newFontDescription));1510 1318 } 1511 1319 … … 1516 1324 fontDescription.setOneFamily(standardFamily); 1517 1325 fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium); 1518 setFontSize(fontDescription, Style::fontSizeForKeyword(CSSValueMedium, false, document())); 1326 1327 auto size = Style::fontSizeForKeyword(CSSValueMedium, false, document()); 1328 fontDescription.setSpecifiedSize(size); 1329 fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), is<SVGElement>(m_state.element()), m_state.style(), document())); 1330 1519 1331 fontDescription.setShouldAllowUserInstalledFonts(settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No); 1520 1332 style()->setFontDescription(WTFMove(fontDescription)); 1521 }1522 1523 void StyleResolver::setFontSize(FontCascadeDescription& fontDescription, float size)1524 {1525 fontDescription.setSpecifiedSize(size);1526 fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules(), m_state.style(), document()));1527 1333 } 1528 1334 -
trunk/Source/WebCore/css/StyleResolver.h
r251796 r251864 64 64 class MediaQueryEvaluator; 65 65 class Node; 66 class RenderScrollbar;67 66 class RuleData; 68 67 class RuleSet; … … 81 80 class StyledElement; 82 81 class SVGElement; 83 class SVGSVGElement;84 82 class ViewportStyleResolver; 85 83 struct ResourceLoaderOptions; 86 87 namespace Style {88 class PropertyCascade;89 }90 84 91 85 // MatchOnlyUserAgentRules is used in media queries, where relative units … … 164 158 void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*); 165 159 166 void updateFont(Style::PropertyCascade&);167 160 void initializeFontStyle(); 168 169 void setFontSize(FontCascadeDescription&, float size);170 171 bool useSVGZoomRules() const;172 bool useSVGZoomRulesForLength() const;173 161 174 162 static bool colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue&); … … 206 194 207 195 private: 208 // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh209 void checkForGenericFamilyChange(RenderStyle&, const RenderStyle* parentStyle);210 void checkForZoomChange(RenderStyle&, const RenderStyle* parentStyle);211 #if ENABLE(TEXT_AUTOSIZING)212 void checkForTextSizeAdjust(RenderStyle&);213 #endif214 215 196 void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*); 216 197 void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&); … … 247 228 const RenderStyle* rootElementStyle() const { return m_rootElementStyle; } 248 229 249 void setFontSizeHasViewportUnits(bool hasViewportUnits) { m_fontSizeHasViewportUnits = hasViewportUnits; }250 bool fontSizeHasViewportUnits() const { return m_fontSizeHasViewportUnits; }251 252 230 void cacheBorderAndBackground(); 253 231 bool hasUAAppearance() const { return m_hasUAAppearance; } … … 256 234 const Color& backgroundColor() const { return m_backgroundColor; } 257 235 258 bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }259 260 236 const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; } 261 237 … … 279 255 CSSToLengthConversionData m_cssToLengthConversionData; 280 256 281 bool m_fontSizeHasViewportUnits { false };282 257 bool m_hasUAAppearance { false }; 283 258 }; -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r251796 r251864 43 43 #include "Element.h" 44 44 #include "Page.h" 45 #include "PropertyCascade.h"46 45 #include "RenderStyle.h" 47 46 #include "RenderTheme.h" 48 47 #include "Settings.h" 48 #include "StyleBuilder.h" 49 49 #include "StyleColor.h" 50 50 #include "StyleResolver.h" … … 235 235 236 236 for (auto id : dependencies) 237 builderState. cascade().applyProperties(id,id);237 builderState.builder().applyProperty(id); 238 238 239 239 return CSSPropertyParser::parseTypedCustomPropertyValue(name, syntax, resolvedData->tokens(), builderState, m_context); -
trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp
r251841 r251864 68 68 // FIXME-NEWPARSER: Replace Pair and Rect with actual CSSValue subclasses (CSSValuePair and CSSQuadValue). 69 69 #include "Pair.h" 70 #include "PropertyCascade.h"71 70 #include "Rect.h" 72 71 #include "RenderTheme.h" … … 74 73 #include "SVGPathByteStream.h" 75 74 #include "SVGPathUtilities.h" 75 #include "StyleBuilder.h" 76 76 #include "StyleBuilderConverter.h" 77 77 #include "StylePropertyShorthand.h" -
trunk/Source/WebCore/style/PropertyCascade.cpp
r251841 r251864 33 33 #include "StyleBuilderGenerated.h" 34 34 #include "StylePropertyShorthand.h" 35 #include "StyleResolver.h"36 35 37 36 namespace WebCore { … … 174 173 #endif 175 174 176 PropertyCascade::PropertyCascade( StyleResolver& styleResolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, IncludedProperties includedProperties)175 PropertyCascade::PropertyCascade(const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, IncludedProperties includedProperties, Direction direction) 177 176 : m_matchResult(matchResult) 178 177 , m_includedProperties(includedProperties) 179 , m_builderState(std::in_place, *this, styleResolver) 180 { 181 // Directional properties (*-before/after) are aliases that depend on the TextDirection and WritingMode. 182 // These must be resolved before we can begin building the property cascade. 183 resolveDirectionAndWritingMode(); 184 178 , m_direction(resolveDirectionAndWritingMode(direction)) 179 { 185 180 buildCascade(cascadeLevels); 186 181 } 187 182 188 183 PropertyCascade::PropertyCascade(const PropertyCascade& parent, OptionSet<CascadeLevel> cascadeLevels) 189 : 184 : m_matchResult(parent.m_matchResult) 190 185 , m_includedProperties(parent.m_includedProperties) 191 186 , m_direction(parent.m_direction) 192 , m_writingMode(parent.m_writingMode)193 187 { 194 188 buildCascade(cascadeLevels); … … 231 225 { 232 226 if (CSSProperty::isDirectionAwareProperty(id)) 233 id = CSSProperty::resolveDirectionAwareProperty(id, m_direction , m_writingMode);227 id = CSSProperty::resolveDirectionAwareProperty(id, m_direction.textDirection, m_direction.writingMode); 234 228 235 229 ASSERT(!shouldApplyPropertyInParseOrder(id)); … … 378 372 } 379 373 380 void PropertyCascade::applyDeferredProperties() 381 { 382 for (auto& property : m_deferredProperties) 383 applyProperty(property); 384 } 385 386 void PropertyCascade::applyProperties(int firstProperty, int lastProperty) 387 { 388 if (LIKELY(m_customProperties.isEmpty())) 389 return applyPropertiesImpl<CustomPropertyCycleTracking::Disabled>(firstProperty, lastProperty); 390 391 return applyPropertiesImpl<CustomPropertyCycleTracking::Enabled>(firstProperty, lastProperty); 392 } 393 394 template<PropertyCascade::CustomPropertyCycleTracking trackCycles> 395 inline void PropertyCascade::applyPropertiesImpl(int firstProperty, int lastProperty) 396 { 397 for (int id = firstProperty; id <= lastProperty; ++id) { 398 CSSPropertyID propertyID = static_cast<CSSPropertyID>(id); 399 if (!hasProperty(propertyID)) 400 continue; 401 ASSERT(propertyID != CSSPropertyCustom); 402 auto& property = m_properties[propertyID]; 403 404 if (trackCycles == CustomPropertyCycleTracking::Enabled) { 405 if (UNLIKELY(builderState().m_inProgressProperties.get(propertyID))) { 406 // We are in a cycle (eg. setting font size using registered custom property value containing em). 407 // So this value should be unset. 408 builderState().m_appliedProperties.set(propertyID); 409 // This property is in a cycle, and only the root of the call stack will have firstProperty != lastProperty. 410 ASSERT(firstProperty == lastProperty); 411 continue; 412 } 413 auto& builderState = *m_builderState; 414 builderState.m_inProgressProperties.set(propertyID); 415 applyProperty(property); 416 builderState.m_appliedProperties.set(propertyID); 417 builderState.m_inProgressProperties.set(propertyID, false); 418 continue; 419 } 420 421 // If we don't have any custom properties, then there can't be any cycles. 422 applyProperty(property); 423 } 424 } 425 426 void PropertyCascade::applyCustomProperties() 427 { 428 for (auto& name : m_customProperties.keys()) 429 applyCustomProperty(name); 430 } 431 432 void PropertyCascade::applyCustomProperty(const String& name) 433 { 434 auto& builderState = *m_builderState; 435 if (builderState.m_appliedCustomProperties.contains(name) || !m_customProperties.contains(name)) 436 return; 437 438 auto property = customProperty(name); 439 bool inCycle = builderState.m_inProgressPropertiesCustom.contains(name); 440 441 for (auto index : { SelectorChecker::MatchDefault, SelectorChecker::MatchLink, SelectorChecker::MatchVisited }) { 442 if (!property.cssValue[index]) 443 continue; 444 if (index != SelectorChecker::MatchDefault && builderState.style().insideLink() == InsideLink::NotInside) 445 continue; 446 447 Ref<CSSCustomPropertyValue> valueToApply = CSSCustomPropertyValue::create(downcast<CSSCustomPropertyValue>(*property.cssValue[index])); 448 449 if (inCycle) { 450 builderState.m_appliedCustomProperties.add(name); // Make sure we do not try to apply this property again while resolving it. 451 valueToApply = CSSCustomPropertyValue::createWithID(name, CSSValueInvalid); 452 } 453 454 builderState.m_inProgressPropertiesCustom.add(name); 455 456 if (WTF::holds_alternative<Ref<CSSVariableReferenceValue>>(valueToApply->value())) { 457 RefPtr<CSSValue> parsedValue = resolvedVariableValue(CSSPropertyCustom, valueToApply.get()); 458 459 if (builderState.m_appliedCustomProperties.contains(name)) 460 return; // There was a cycle and the value was reset, so bail. 461 462 if (!parsedValue) 463 parsedValue = CSSCustomPropertyValue::createWithID(name, CSSValueUnset); 464 465 valueToApply = downcast<CSSCustomPropertyValue>(*parsedValue); 466 } 467 468 if (builderState.m_inProgressPropertiesCustom.contains(name)) { 469 builderState.m_linkMatch = index; 470 applyProperty(CSSPropertyCustom, valueToApply.get(), index); 471 } 472 } 473 474 builderState.m_linkMatch = SelectorChecker::MatchDefault; 475 builderState.m_inProgressPropertiesCustom.remove(name); 476 builderState.m_appliedCustomProperties.add(name); 477 478 for (auto index : { SelectorChecker::MatchDefault, SelectorChecker::MatchLink, SelectorChecker::MatchVisited }) { 479 if (!property.cssValue[index]) 480 continue; 481 if (index != SelectorChecker::MatchDefault && builderState.style().insideLink() == InsideLink::NotInside) 482 continue; 483 484 Ref<CSSCustomPropertyValue> valueToApply = CSSCustomPropertyValue::create(downcast<CSSCustomPropertyValue>(*property.cssValue[index])); 485 486 if (inCycle && WTF::holds_alternative<Ref<CSSVariableReferenceValue>>(valueToApply->value())) { 487 // Resolve this value so that we reset its dependencies. 488 resolvedVariableValue(CSSPropertyCustom, valueToApply.get()); 489 } 490 } 491 } 492 493 const PropertyCascade* PropertyCascade::propertyCascadeForRollback(CascadeLevel cascadeLevel) 374 const PropertyCascade* PropertyCascade::propertyCascadeForRollback(CascadeLevel cascadeLevel) const 494 375 { 495 376 switch (cascadeLevel) { … … 515 396 } 516 397 517 inline void PropertyCascade::applyProperty(const Property& property) 518 { 519 auto& builderState = *m_builderState; 520 builderState.m_cascadeLevel = property.level; 521 builderState.m_styleScopeOrdinal = property.styleScopeOrdinal; 522 523 auto applyWithLinkMatch = [&](SelectorChecker::LinkMatchMask linkMatch) { 524 if (property.cssValue[linkMatch]) { 525 builderState.m_linkMatch = linkMatch; 526 applyProperty(property.id, *property.cssValue[linkMatch], linkMatch); 527 } 528 }; 529 530 applyWithLinkMatch(SelectorChecker::MatchDefault); 531 532 if (builderState.style().insideLink() == InsideLink::NotInside) 533 return; 534 535 applyWithLinkMatch(SelectorChecker::MatchLink); 536 applyWithLinkMatch(SelectorChecker::MatchVisited); 537 538 builderState.m_linkMatch = SelectorChecker::MatchDefault; 539 } 540 541 void PropertyCascade::applyProperty(CSSPropertyID id, CSSValue& value, SelectorChecker::LinkMatchMask linkMatchMask) 542 { 543 ASSERT_WITH_MESSAGE(!isShorthandCSSProperty(id), "Shorthand property id = %d wasn't expanded at parsing time", id); 544 545 auto valueToApply = resolveValue(id, value); 546 547 if (CSSProperty::isDirectionAwareProperty(id)) { 548 CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, m_direction, m_writingMode); 549 ASSERT(newId != id); 550 return applyProperty(newId, valueToApply.get(), linkMatchMask); 551 } 552 553 auto& builderState = *m_builderState; 554 555 CSSCustomPropertyValue* customPropertyValue = nullptr; 556 CSSValueID customPropertyValueID = CSSValueInvalid; 557 CSSRegisteredCustomProperty* customPropertyRegistered = nullptr; 558 559 if (id == CSSPropertyCustom) { 560 customPropertyValue = downcast<CSSCustomPropertyValue>(valueToApply.ptr()); 561 ASSERT(customPropertyValue->isResolved()); 562 if (WTF::holds_alternative<CSSValueID>(customPropertyValue->value())) 563 customPropertyValueID = WTF::get<CSSValueID>(customPropertyValue->value()); 564 auto& name = customPropertyValue->name(); 565 customPropertyRegistered = builderState.document().getCSSRegisteredCustomPropertySet().get(name); 566 } 567 568 bool isInherit = valueToApply->isInheritedValue() || customPropertyValueID == CSSValueInherit; 569 bool isInitial = valueToApply->isInitialValue() || customPropertyValueID == CSSValueInitial; 570 571 bool isUnset = valueToApply->isUnsetValue() || customPropertyValueID == CSSValueUnset; 572 bool isRevert = valueToApply->isRevertValue() || customPropertyValueID == CSSValueRevert; 573 574 if (isRevert) { 575 if (auto* rollback = propertyCascadeForRollback(builderState.m_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 (builderState.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 builderState.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 = const_cast<Document&>(builderState.document()).paintWorkletGlobalScopeForName(name)) { 618 auto locker = holdLock(paintWorklet->paintDefinitionLock()); 619 if (auto* registration = paintWorklet->paintDefinitionMap().get(name)) { 620 for (auto& property : registration->inputProperties) 621 builderState.style().addCustomPaintWatchProperty(property); 622 } 623 } 624 } 625 #endif 626 627 BuilderGenerated::applyProperty(id, builderState, valueToApply.get(), isInitial, isInherit, customPropertyRegistered); 628 } 629 630 Ref<CSSValue> PropertyCascade::resolveValue(CSSPropertyID propertyID, CSSValue& value) 631 { 632 if (!value.hasVariableReferences()) 633 return value; 634 635 auto variableValue = resolvedVariableValue(propertyID, value); 636 // If the cascade has already applied this id, then we detected a cycle, and this value should be unset. 637 if (!variableValue || builderState().m_appliedProperties.get(propertyID)) { 638 if (CSSProperty::isInheritedProperty(propertyID)) 639 return CSSValuePool::singleton().createInheritedValue(); 640 return CSSValuePool::singleton().createExplicitInitialValue(); 641 } 642 643 return *variableValue; 644 } 645 646 RefPtr<CSSValue> PropertyCascade::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value) 647 { 648 CSSParser parser(builderState().document()); 649 return parser.parseValueWithVariableReferences(propID, value, builderState()); 650 } 651 652 void PropertyCascade::resolveDirectionAndWritingMode() 653 { 654 auto& style = builderState().style(); 655 656 m_direction = style.direction(); 657 m_writingMode = style.writingMode(); 398 PropertyCascade::Direction PropertyCascade::resolveDirectionAndWritingMode(Direction inheritedDirection) const 399 { 400 Direction result = inheritedDirection; 658 401 659 402 bool hadImportantWritingMode = false; … … 669 412 case CSSPropertyWritingMode: 670 413 if (!hadImportantWritingMode || property.isImportant()) { 671 m_writingMode = downcast<CSSPrimitiveValue>(*property.value());414 result.writingMode = downcast<CSSPrimitiveValue>(*property.value()); 672 415 hadImportantWritingMode = property.isImportant(); 673 416 } … … 675 418 case CSSPropertyDirection: 676 419 if (!hadImportantDirection || property.isImportant()) { 677 m_direction = downcast<CSSPrimitiveValue>(*property.value());420 result.textDirection = downcast<CSSPrimitiveValue>(*property.value()); 678 421 hadImportantDirection = property.isImportant(); 679 422 } … … 685 428 } 686 429 } 687 } 688 689 } 690 } 430 431 return result; 432 } 433 434 } 435 } -
trunk/Source/WebCore/style/PropertyCascade.h
r251796 r251864 41 41 public: 42 42 enum IncludedProperties { All, InheritedOnly }; 43 PropertyCascade(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties = IncludedProperties::All); 43 44 struct Direction { 45 TextDirection textDirection; 46 WritingMode writingMode; 47 }; 48 49 PropertyCascade(const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties, Direction); 44 50 PropertyCascade(const PropertyCascade&, OptionSet<CascadeLevel>); 45 51 … … 59 65 Property customProperty(const String&) const; 60 66 61 void applyProperties(int firstProperty, int lastProperty); 62 void applyDeferredProperties(); 63 void applyCustomProperties(); 64 void applyCustomProperty(const String& name); 65 void applyProperty(CSSPropertyID, CSSValue&, SelectorChecker::LinkMatchMask = SelectorChecker::MatchDefault); 67 const Vector<Property, 8>& deferredProperties() const { return m_deferredProperties; } 68 const HashMap<AtomString, Property>& customProperties() const { return m_customProperties; } 66 69 67 BuilderState& builderState() { return *m_builderState; } 70 Direction direction() const { return m_direction; } 71 72 const PropertyCascade* propertyCascadeForRollback(CascadeLevel) const; 68 73 69 74 private: … … 77 82 static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal); 78 83 79 const PropertyCascade* propertyCascadeForRollback(CascadeLevel); 80 81 enum CustomPropertyCycleTracking { Enabled = 0, Disabled }; 82 template<CustomPropertyCycleTracking trackCycles> 83 void applyPropertiesImpl(int firstProperty, int lastProperty); 84 void applyProperty(const Property&); 85 86 Ref<CSSValue> resolveValue(CSSPropertyID, CSSValue&); 87 RefPtr<CSSValue> resolvedVariableValue(CSSPropertyID, const CSSValue&); 88 89 void resolveDirectionAndWritingMode(); 84 Direction resolveDirectionAndWritingMode(Direction inheritedDirection) const; 90 85 91 86 const MatchResult& m_matchResult; 92 87 const IncludedProperties m_includedProperties; 93 94 TextDirection m_direction; 95 WritingMode m_writingMode; 88 const Direction m_direction; 96 89 97 90 Property m_properties[numCSSProperties + 2]; … … 101 94 HashMap<AtomString, Property> m_customProperties; 102 95 103 std::unique_ptr<const PropertyCascade> m_authorRollbackCascade; 104 std::unique_ptr<const PropertyCascade> m_userRollbackCascade; 105 106 Optional<BuilderState> m_builderState; 96 mutable std::unique_ptr<const PropertyCascade> m_authorRollbackCascade; 97 mutable std::unique_ptr<const PropertyCascade> m_userRollbackCascade; 107 98 }; 108 99 -
trunk/Source/WebCore/style/StyleBuilderCustom.h
r251841 r251864 1613 1613 if (primitiveValue.isLength()) { 1614 1614 size = primitiveValue.computeLength<float>(CSSToLengthConversionData(&builderState.parentStyle(), &builderState.rootElementStyle(), builderState.document().renderView(), 1.0f, true)); 1615 builderState.styleResolver().state().setFontSizeHasViewportUnits(primitiveValue.isViewportPercentageLength()); 1615 if (primitiveValue.isViewportPercentageLength()) 1616 builderState.style().setHasViewportUnits(); 1616 1617 } else if (primitiveValue.isPercentage()) 1617 1618 size = (primitiveValue.floatValue() * parentSize) / 100.0f; -
trunk/Source/WebCore/style/StyleBuilderState.cpp
r251796 r251864 1 1 /* 2 * Copyright (C) 2019 Apple Inc. All rights reserved. 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 5 * Copyright (C) 2005-2019 Apple Inc. All rights reserved. 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 11 * Copyright (C) 2012, 2013 Google Inc. All rights reserved. 12 * Copyright (C) 2014 Igalia S.L. 3 13 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 14 * This library is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU Library General Public 16 * License as published by the Free Software Foundation; either 17 * version 2 of the License, or (at your option) any later version. 12 18 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 19 * This library is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Library General Public License for more details. 23 * 24 * You should have received a copy of the GNU Library General Public License 25 * along with this library; see the file COPYING.LIB. If not, write to 26 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 27 * Boston, MA 02110-1301, USA. 24 28 */ 25 29 … … 27 31 #include "StyleBuilderState.h" 28 32 33 #include "SVGElement.h" 34 #include "SVGSVGElement.h" 35 #include "StyleBuilder.h" 29 36 #include "StyleResolver.h" 30 37 … … 32 39 namespace Style { 33 40 34 BuilderState::BuilderState( PropertyCascade& cascade, StyleResolver& styleResolver)35 : m_ cascade(cascade)41 BuilderState::BuilderState(Builder& builder, StyleResolver& styleResolver) 42 : m_builder(builder) 36 43 , m_styleMap(*this) 37 44 , m_cssToLengthConversionData(styleResolver.state().cssToLengthConversionData()) … … 47 54 } 48 55 56 // SVG handles zooming in a different way compared to CSS. The whole document is scaled instead 57 // of each individual length value in the render style / tree. CSSPrimitiveValue::computeLength*() 58 // multiplies each resolved length with the zoom multiplier - so for SVG we need to disable that. 59 // Though all CSS values that can be applied to outermost <svg> elements (width/height/border/padding...) 60 // need to respect the scaling. RenderBox (the parent class of RenderSVGRoot) grabs values like 61 // width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale, 62 // if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific 63 // properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size). 49 64 bool BuilderState::useSVGZoomRules() const 50 65 { 51 return m_styleResolver.useSVGZoomRules();66 return is<SVGElement>(element()); 52 67 } 53 68 54 69 bool BuilderState::useSVGZoomRulesForLength() const 55 70 { 56 return m_styleResolver.useSVGZoomRulesForLength();71 return is<SVGElement>(element()) && !(is<SVGSVGElement>(*element()) && element()->parentNode()); 57 72 } 58 73 … … 72 87 } 73 88 74 void BuilderState:: setFontSize(FontCascadeDescription& description, float size)89 void BuilderState::adjustStyleForInterCharacterRuby() 75 90 { 76 m_styleResolver.setFontSize(description, size); 91 if (m_style.rubyPosition() != RubyPosition::InterCharacter || !element() || !element()->hasTagName(HTMLNames::rtTag)) 92 return; 93 94 m_style.setTextAlign(TextAlignMode::Center); 95 if (m_style.isHorizontalWritingMode()) 96 m_style.setWritingMode(LeftToRightWritingMode); 97 } 98 99 void BuilderState::updateFont() 100 { 101 if (!m_fontDirty && m_style.fontCascade().fonts()) 102 return; 103 104 #if ENABLE(TEXT_AUTOSIZING) 105 updateFontForTextSizeAdjust(); 106 #endif 107 updateFontForGenericFamilyChange(); 108 updateFontForZoomChange(); 109 updateFontForOrientationChange(); 110 111 m_style.fontCascade().update(&const_cast<Document&>(document()).fontSelector()); 112 113 m_fontDirty = false; 114 } 115 116 #if ENABLE(TEXT_AUTOSIZING) 117 void BuilderState::updateFontForTextSizeAdjust() 118 { 119 if (m_style.textSizeAdjust().isAuto() 120 || !document().settings().textAutosizingEnabled() 121 || (document().settings().textAutosizingUsesIdempotentMode() && !m_style.textSizeAdjust().isNone())) 122 return; 123 124 auto newFontDescription = m_style.fontDescription(); 125 if (!m_style.textSizeAdjust().isNone()) 126 newFontDescription.setComputedSize(newFontDescription.specifiedSize() * m_style.textSizeAdjust().multiplier()); 127 else 128 newFontDescription.setComputedSize(newFontDescription.specifiedSize()); 129 130 m_style.setFontDescription(WTFMove(newFontDescription)); 131 } 132 #endif 133 134 void BuilderState::updateFontForZoomChange() 135 { 136 if (m_style.effectiveZoom() == m_parentStyle.effectiveZoom() && m_style.textZoom() == m_parentStyle.textZoom()) 137 return; 138 139 const auto& childFont = m_style.fontDescription(); 140 auto newFontDescription = childFont; 141 setFontSize(newFontDescription, childFont.specifiedSize()); 142 143 m_style.setFontDescription(WTFMove(newFontDescription)); 144 } 145 146 void BuilderState::updateFontForGenericFamilyChange() 147 { 148 const auto& childFont = m_style.fontDescription(); 149 150 if (childFont.isAbsoluteSize()) 151 return; 152 153 const auto& parentFont = m_parentStyle.fontDescription(); 154 if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize()) 155 return; 156 157 // We know the parent is monospace or the child is monospace, and that font 158 // size was unspecified. We want to scale our font size as appropriate. 159 // If the font uses a keyword size, then we refetch from the table rather than 160 // multiplying by our scale factor. 161 float size = [&] { 162 if (CSSValueID sizeIdentifier = childFont.keywordSizeAsIdentifier()) 163 return Style::fontSizeForKeyword(sizeIdentifier, childFont.useFixedDefaultSize(), document()); 164 165 auto fixedSize = document().settings().defaultFixedFontSize(); 166 auto defaultSize = document().settings().defaultFontSize(); 167 float fixedScaleFactor = (fixedSize && defaultSize) ? static_cast<float>(fixedSize) / defaultSize : 1; 168 return parentFont.useFixedDefaultSize() ? childFont.specifiedSize() / fixedScaleFactor : childFont.specifiedSize() * fixedScaleFactor; 169 }(); 170 171 auto newFontDescription = childFont; 172 setFontSize(newFontDescription, size); 173 m_style.setFontDescription(WTFMove(newFontDescription)); 174 } 175 176 void BuilderState::updateFontForOrientationChange() 177 { 178 auto [fontOrientation, glyphOrientation] = m_style.fontAndGlyphOrientation(); 179 180 const auto& fontDescription = m_style.fontDescription(); 181 if (fontDescription.orientation() == fontOrientation && fontDescription.nonCJKGlyphOrientation() == glyphOrientation) 182 return; 183 184 auto newFontDescription = fontDescription; 185 newFontDescription.setNonCJKGlyphOrientation(glyphOrientation); 186 newFontDescription.setOrientation(fontOrientation); 187 m_style.setFontDescription(WTFMove(newFontDescription)); 188 } 189 190 void BuilderState::setFontSize(FontCascadeDescription& fontDescription, float size) 191 { 192 fontDescription.setSpecifiedSize(size); 193 fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules(), &style(), document())); 77 194 } 78 195 -
trunk/Source/WebCore/style/StyleBuilderState.h
r251796 r251864 40 40 namespace Style { 41 41 42 class PropertyCascade;42 class Builder; 43 43 44 44 class BuilderState { 45 45 public: 46 BuilderState( PropertyCascade&, StyleResolver&);46 BuilderState(Builder&, StyleResolver&); 47 47 48 PropertyCascade& cascade() { return m_cascade; }48 Builder& builder() { return m_builder; } 49 49 StyleResolver& styleResolver() { return m_styleResolver; } 50 50 … … 65 65 bool fontDirty() const { return m_fontDirty; } 66 66 void setFontDirty() { m_fontDirty = true; } 67 void clearFontDirty() { m_fontDirty = false; }68 67 69 68 const FontCascadeDescription& fontDescription() { return m_style.fontDescription(); } … … 86 85 87 86 private: 88 friend class PropertyCascade;87 friend class Builder; 89 88 90 PropertyCascade& m_cascade; 89 void adjustStyleForInterCharacterRuby(); 90 91 void updateFont(); 92 #if ENABLE(TEXT_AUTOSIZING) 93 void updateFontForTextSizeAdjust(); 94 #endif 95 void updateFontForZoomChange(); 96 void updateFontForGenericFamilyChange(); 97 void updateFontForOrientationChange(); 98 99 Builder& m_builder; 91 100 92 101 CSSToStyleMap m_styleMap;
Note: See TracChangeset
for help on using the changeset viewer.