Skip to content

Commit 435b354

Browse files
committed
[Style] Require an explicit type when calling Style::evaluate to make it clear which evaluation is being applied
https://bugs.webkit.org/show_bug.cgi?id=299528 Reviewed by Antti Koivisto. Replaces calls like: `Style::evaluate(length, containerLength, Style::ZoomNeeded { })` with ones that explicitly indicate the result of the evaluation: `Style::evaluate<LengthUnit>(length, containerLength, Style::ZoomNeeded { })` This allows for more clarity and makes disambiguation possible for more cases. * Source/WebCore/accessibility/AccessibilityRenderObject.cpp: * Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp: * Source/WebCore/animation/ScrollTimeline.cpp: * Source/WebCore/animation/ViewTimeline.cpp: * Source/WebCore/dom/Document.cpp: * Source/WebCore/layout/Verification.cpp: * Source/WebCore/layout/formattingContexts/FormattingGeometry.cpp: * Source/WebCore/layout/formattingContexts/FormattingGeometry.h: * Source/WebCore/layout/formattingContexts/block/BlockFormattingGeometry.cpp: * Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp: * Source/WebCore/layout/formattingContexts/flex/FlexFormattingUtils.cpp: * Source/WebCore/layout/formattingContexts/inline/InlineFormattingUtils.cpp: * Source/WebCore/layout/formattingContexts/inline/InlineLevelBoxInlines.h: * Source/WebCore/layout/formattingContexts/table/TableLayout.cpp: * Source/WebCore/layout/integration/LayoutIntegrationBoxGeometryUpdater.cpp: * Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp: * Source/WebCore/page/IntersectionObserver.cpp: * Source/WebCore/page/LocalFrameView.cpp: * Source/WebCore/page/SpatialNavigation.cpp: * Source/WebCore/platform/graphics/PathUtilities.cpp: * Source/WebCore/rendering/AutoTableLayout.cpp: * Source/WebCore/rendering/BackgroundPainter.cpp: * Source/WebCore/rendering/BorderEdge.cpp: * Source/WebCore/rendering/BorderPainter.cpp: * Source/WebCore/rendering/BorderShape.cpp: * Source/WebCore/rendering/FixedTableLayout.cpp: * Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp: * Source/WebCore/rendering/MotionPath.cpp: * Source/WebCore/rendering/NinePieceImagePainter.cpp: * Source/WebCore/rendering/PositionedLayoutConstraints.h: * Source/WebCore/rendering/RenderBlock.cpp: * Source/WebCore/rendering/RenderBlockFlow.cpp: * Source/WebCore/rendering/RenderBox.cpp: * Source/WebCore/rendering/RenderBoxModelObject.cpp: * Source/WebCore/rendering/RenderBoxModelObjectInlines.h: * Source/WebCore/rendering/RenderElement.cpp: * Source/WebCore/rendering/RenderFileUploadControl.cpp: * Source/WebCore/rendering/RenderFlexibleBox.cpp: * Source/WebCore/rendering/RenderGrid.cpp: * Source/WebCore/rendering/RenderImage.cpp: * Source/WebCore/rendering/RenderInline.cpp: * Source/WebCore/rendering/RenderLayer.cpp: * Source/WebCore/rendering/RenderListBox.cpp: * Source/WebCore/rendering/RenderMarquee.cpp: * Source/WebCore/rendering/RenderMenuList.cpp: * Source/WebCore/rendering/RenderMultiColumnSet.cpp: * Source/WebCore/rendering/RenderReplaced.cpp: * Source/WebCore/rendering/RenderScrollbarPart.cpp: * Source/WebCore/rendering/RenderSlider.cpp: * Source/WebCore/rendering/RenderTable.cpp: * Source/WebCore/rendering/RenderTableCell.cpp: * Source/WebCore/rendering/RenderTableSection.cpp: * Source/WebCore/rendering/RenderTextControl.cpp: * Source/WebCore/rendering/RenderTextInlines.h: * Source/WebCore/rendering/RenderTheme.cpp: * Source/WebCore/rendering/RenderTreeAsText.cpp: * Source/WebCore/rendering/cocoa/RenderThemeCocoa.mm: * Source/WebCore/rendering/ios/RenderThemeIOS.mm: * Source/WebCore/rendering/shapes/LayoutShape.cpp: * Source/WebCore/rendering/shapes/ShapeOutsideInfo.cpp: * Source/WebCore/rendering/style/CollapsedBorderValue.h: * Source/WebCore/rendering/style/RenderStyle.cpp: * Source/WebCore/rendering/svg/SVGRenderSupport.cpp: * Source/WebCore/rendering/svg/SVGTextLayoutEngineBaseline.cpp: * Source/WebCore/style/StyleExtractorCustom.h: * Source/WebCore/style/StyleResolveForFont.cpp: * Source/WebCore/style/values/StyleValueTypes.h: * Source/WebCore/style/values/backgrounds/StyleLineWidth.cpp: * Source/WebCore/style/values/backgrounds/StyleLineWidth.h: * Source/WebCore/style/values/borders/StyleBorderRadius.cpp: * Source/WebCore/style/values/borders/StyleBorderRadius.h: * Source/WebCore/style/values/filter-effects/StyleBrightnessFunction.cpp: * Source/WebCore/style/values/filter-effects/StyleContrastFunction.cpp: * Source/WebCore/style/values/filter-effects/StyleGrayscaleFunction.cpp: * Source/WebCore/style/values/filter-effects/StyleInvertFunction.cpp: * Source/WebCore/style/values/filter-effects/StyleOpacityFunction.cpp: * Source/WebCore/style/values/filter-effects/StyleSaturateFunction.cpp: * Source/WebCore/style/values/filter-effects/StyleSepiaFunction.cpp: * Source/WebCore/style/values/images/StyleGradient.cpp: * Source/WebCore/style/values/non-standard/StyleWebKitTextStrokeWidth.h: * Source/WebCore/style/values/primitives/StyleLengthWrapper.h: * Source/WebCore/style/values/primitives/StylePosition.cpp: * Source/WebCore/style/values/primitives/StylePosition.h: * Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h: * Source/WebCore/style/values/scroll-snap/StyleScrollMargin.cpp: * Source/WebCore/style/values/scroll-snap/StyleScrollMargin.h: * Source/WebCore/style/values/scroll-snap/StyleScrollPadding.cpp: * Source/WebCore/style/values/scroll-snap/StyleScrollPadding.h: * Source/WebCore/style/values/shapes/StyleCircleFunction.cpp: * Source/WebCore/style/values/shapes/StyleEllipseFunction.cpp: * Source/WebCore/style/values/shapes/StyleInsetFunction.cpp: * Source/WebCore/style/values/shapes/StylePolygonFunction.cpp: * Source/WebCore/style/values/shapes/StyleShapeFunction.cpp: * Source/WebCore/style/values/text-decoration/StyleTextDecorationThickness.cpp: * Source/WebCore/style/values/text-decoration/StyleTextUnderlineOffset.cpp: * Source/WebCore/svg/SVGLengthContext.cpp: * Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm: * Source/WebKitLegacy/mac/DOM/DOM.mm: Canonical link: https://commits.webkit.org/300548@main
1 parent efaa47c commit 435b354

File tree

98 files changed

+698
-613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+698
-613
lines changed

Source/WebCore/accessibility/AccessibilityRenderObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ Path AccessibilityRenderObject::elementPath() const
949949
if (!needsPath)
950950
return { };
951951

952-
float outlineOffset = Style::evaluate(style.outlineOffset(), Style::ZoomNeeded { });
952+
auto outlineOffset = Style::evaluate<float>(style.outlineOffset(), Style::ZoomNeeded { });
953953
float deviceScaleFactor = renderText->document().deviceScaleFactor();
954954
Vector<FloatRect> pixelSnappedRects;
955955
for (auto rect : rects) {

Source/WebCore/accessibility/atspi/AccessibilityObjectTextAtspi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ AccessibilityObjectAtspi::TextAttributes AccessibilityObjectAtspi::textAttribute
793793
addAttributeIfNeeded("invisible"_s, style.visibility() == Visibility::Hidden ? "true"_s : "false"_s);
794794
addAttributeIfNeeded("editable"_s, m_coreObject->canSetValueAttribute() ? "true"_s : "false"_s);
795795
addAttributeIfNeeded("direction"_s, style.writingMode().isBidiLTR() ? "ltr"_s : "rtl"_s);
796-
addAttributeIfNeeded("indent"_s, makeString(Style::evaluate(style.textIndent().length, m_coreObject->size().width(), Style::ZoomNeeded { })));
796+
addAttributeIfNeeded("indent"_s, makeString(Style::evaluate<float>(style.textIndent().length, m_coreObject->size().width(), Style::ZoomNeeded { })));
797797

798798
switch (style.textAlign()) {
799799
case TextAlignMode::Start:

Source/WebCore/animation/ScrollTimeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ std::pair<WebAnimationTime, WebAnimationTime> ScrollTimeline::intervalForAttachm
345345
auto computedPercentageIfNecessary = [&](const auto& rangeOffset) {
346346
if (auto percentage = rangeOffset.tryPercentage())
347347
return percentage->value;
348-
return Style::evaluate(rangeOffset, maxScrollOffset, Style::ZoomNeeded { }) / maxScrollOffset * 100;
348+
return Style::evaluate<float>(rangeOffset, maxScrollOffset, Style::ZoomNeeded { }) / maxScrollOffset * 100;
349349
};
350350

351351
return {

Source/WebCore/animation/ViewTimeline.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "ScrollAnchoringController.h"
4242
#include "ScrollingConstraints.h"
4343
#include "StyleLengthWrapper+DeprecatedCSSValueConversion.h"
44+
#include "StylePrimitiveNumericTypes+Evaluation.h"
4445
#include "StylePrimitiveNumericTypes+Logging.h"
4546
#include "StyleScrollPadding.h"
4647
#include "StyleSingleAnimationRange.h"
@@ -376,14 +377,14 @@ void ViewTimeline::cacheCurrentTime()
376377
float insetEnd = 0;
377378

378379
if (m_insets.start().isAuto())
379-
insetStart = Style::evaluate(scrollPadding(PaddingEdge::Start), scrollContainerSize, Style::ZoomNeeded { });
380+
insetStart = Style::evaluate<float>(scrollPadding(PaddingEdge::Start), scrollContainerSize, Style::ZoomNeeded { });
380381
else
381-
insetStart = Style::evaluate(m_insets.start(), scrollContainerSize, Style::ZoomNeeded { });
382+
insetStart = Style::evaluate<float>(m_insets.start(), scrollContainerSize, Style::ZoomNeeded { });
382383

383384
if (m_insets.end().isAuto())
384-
insetEnd = Style::evaluate(scrollPadding(PaddingEdge::End), scrollContainerSize, Style::ZoomNeeded { });
385+
insetEnd = Style::evaluate<float>(scrollPadding(PaddingEdge::End), scrollContainerSize, Style::ZoomNeeded { });
385386
else
386-
insetEnd = Style::evaluate(m_insets.end(), scrollContainerSize, Style::ZoomNeeded { });
387+
insetEnd = Style::evaluate<float>(m_insets.end(), scrollContainerSize, Style::ZoomNeeded { });
387388

388389
StickinessAdjustmentData stickyData;
389390
if (auto stickyContainer = dynamicDowncast<RenderBoxModelObject>(this->stickyContainer())) {
@@ -583,7 +584,7 @@ std::pair<double, double> ViewTimeline::offsetIntervalForAttachmentRange(const S
583584
auto offsetForSingleTimelineRange = [&](const auto& rangeToConvert) {
584585
auto [conversionRangeStart, conversionRangeEnd] = intervalForTimelineRangeName(data, rangeToConvert.name());
585586
auto conversionRange = conversionRangeEnd - conversionRangeStart;
586-
auto convertedValue = Style::evaluate(rangeToConvert.offset(), conversionRange, Style::ZoomNeeded { });
587+
auto convertedValue = Style::evaluate<float>(rangeToConvert.offset(), conversionRange, Style::ZoomNeeded { });
587588
auto position = conversionRangeStart + convertedValue;
588589
return (position - data.rangeStart) / timelineRange;
589590
};
@@ -604,7 +605,7 @@ std::pair<WebAnimationTime, WebAnimationTime> ViewTimeline::intervalForAttachmen
604605

605606
auto computeTime = [&](const auto& rangeToConvert) {
606607
auto mappedOffset = mapOffsetToTimelineRange(data, rangeToConvert.name(), [&](const float& subjectRange) {
607-
return Style::evaluate(rangeToConvert.offset(), subjectRange, Style::ZoomNeeded { });
608+
return Style::evaluate<float>(rangeToConvert.offset(), subjectRange, Style::ZoomNeeded { });
608609
});
609610
return WebAnimationTime::fromPercentage(mappedOffset * 100);
610611
};

Source/WebCore/dom/Document.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
#include "StyleColorOptions.h"
297297
#include "StyleColorScheme.h"
298298
#include "StyleOriginatedTimelinesController.h"
299+
#include "StylePrimitiveNumericTypes+Evaluation.h"
299300
#include "StyleProperties.h"
300301
#include "StyleResolveForDocument.h"
301302
#include "StyleResolver.h"
@@ -3373,10 +3374,10 @@ void Document::pageSizeAndMarginsInPixels(int pageIndex, IntSize& pageSize, int&
33733374

33743375
// The percentage is calculated with respect to the width even for margin top and bottom.
33753376
// http://www.w3.org/TR/CSS2/box.html#margin-properties
3376-
marginTop = style->marginTop().isAuto() ? marginTop : Style::evaluate(style->marginTop(), pageSize.width(), Style::ZoomNeeded { });
3377-
marginRight = style->marginRight().isAuto() ? marginRight : Style::evaluate(style->marginRight(), pageSize.width(), Style::ZoomNeeded { });
3378-
marginBottom = style->marginBottom().isAuto() ? marginBottom : Style::evaluate(style->marginBottom(), pageSize.width(), Style::ZoomNeeded { });
3379-
marginLeft = style->marginLeft().isAuto() ? marginLeft : Style::evaluate(style->marginLeft(), pageSize.width(), Style::ZoomNeeded { });
3377+
marginTop = style->marginTop().isAuto() ? marginTop : Style::evaluate<int>(style->marginTop(), pageSize.width(), Style::ZoomNeeded { });
3378+
marginRight = style->marginRight().isAuto() ? marginRight : Style::evaluate<int>(style->marginRight(), pageSize.width(), Style::ZoomNeeded { });
3379+
marginBottom = style->marginBottom().isAuto() ? marginBottom : Style::evaluate<int>(style->marginBottom(), pageSize.width(), Style::ZoomNeeded { });
3380+
marginLeft = style->marginLeft().isAuto() ? marginLeft : Style::evaluate<int>(style->marginLeft(), pageSize.width(), Style::ZoomNeeded { });
33803381
}
33813382

33823383
void Document::fontsNeedUpdate(FontSelector&)

Source/WebCore/layout/Verification.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ static bool outputMismatchingBlockBoxInformationIfNeeded(TextStream& stream, con
190190
auto marginStart = LayoutUnit { };
191191
auto& marginStartStyle = layoutBox.style().marginStart();
192192
if (marginStartStyle.isFixed() || marginStartStyle.isPercent() || marginStartStyle.isCalculated())
193-
marginStart = Style::evaluate(marginStartStyle, containingBlockWidth, Style::ZoomNeeded { });
193+
marginStart = Style::evaluate<LayoutUnit>(marginStartStyle, containingBlockWidth, Style::ZoomNeeded { });
194194

195195
auto marginEnd = LayoutUnit { };
196196
auto& marginEndStyle = layoutBox.style().marginEnd();
197197
if (marginEndStyle.isFixed() || marginEndStyle.isPercent() || marginEndStyle.isCalculated())
198-
marginEnd = Style::evaluate(marginEndStyle, containingBlockWidth, Style::ZoomNeeded { });
198+
marginEnd = Style::evaluate<LayoutUnit>(marginEndStyle, containingBlockWidth, Style::ZoomNeeded { });
199199

200200
auto marginBefore = boxGeometry.marginBefore();
201201
auto marginAfter = boxGeometry.marginAfter();

Source/WebCore/layout/formattingContexts/FormattingGeometry.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ template<FormattingGeometry::HeightType heightType> std::optional<LayoutUnit> Fo
113113
if (!containingBlockHeight)
114114
return { };
115115

116-
return Style::evaluate(height, *containingBlockHeight, Style::ZoomNeeded { });
116+
return Style::evaluate<LayoutUnit>(height, *containingBlockHeight, Style::ZoomNeeded { });
117117
}
118118

119119
std::optional<LayoutUnit> FormattingGeometry::computedHeight(const Box& layoutBox, std::optional<LayoutUnit> containingBlockHeight) const
@@ -1084,8 +1084,14 @@ BoxGeometry::Edges FormattingGeometry::computedBorder(const Box& layoutBox) cons
10841084
auto& style = layoutBox.style();
10851085
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Border] -> layoutBox: " << &layoutBox);
10861086
return {
1087-
{ LayoutUnit(Style::evaluate(style.borderLeftWidth(), Style::ZoomNeeded { })), LayoutUnit(Style::evaluate(style.borderRightWidth(), Style::ZoomNeeded { })) },
1088-
{ LayoutUnit(Style::evaluate(style.borderTopWidth(), Style::ZoomNeeded { })), LayoutUnit(Style::evaluate(style.borderBottomWidth(), Style::ZoomNeeded { })) },
1087+
{
1088+
Style::evaluate<LayoutUnit>(style.borderLeftWidth(), Style::ZoomNeeded { }),
1089+
Style::evaluate<LayoutUnit>(style.borderRightWidth(), Style::ZoomNeeded { })
1090+
},
1091+
{
1092+
Style::evaluate<LayoutUnit>(style.borderTopWidth(), Style::ZoomNeeded { }),
1093+
Style::evaluate<LayoutUnit>(style.borderBottomWidth(), Style::ZoomNeeded { })
1094+
},
10891095
};
10901096
}
10911097

@@ -1097,8 +1103,13 @@ BoxGeometry::Edges FormattingGeometry::computedPadding(const Box& layoutBox, con
10971103
auto& style = layoutBox.style();
10981104
LOG_WITH_STREAM(FormattingContextLayout, stream << "[Padding] -> layoutBox: " << &layoutBox);
10991105
return {
1100-
{ Style::evaluate(style.paddingStart(), containingBlockWidth, Style::ZoomNeeded { }), Style::evaluate(style.paddingEnd(), containingBlockWidth, Style::ZoomNeeded { }) },
1101-
{ Style::evaluate(style.paddingBefore(), containingBlockWidth, Style::ZoomNeeded { }), Style::evaluate(style.paddingAfter(), containingBlockWidth, Style::ZoomNeeded { }) }
1106+
{
1107+
Style::evaluate<LayoutUnit>(style.paddingStart(), containingBlockWidth, Style::ZoomNeeded { }),
1108+
Style::evaluate<LayoutUnit>(style.paddingEnd(), containingBlockWidth, Style::ZoomNeeded { }) },
1109+
{
1110+
Style::evaluate<LayoutUnit>(style.paddingBefore(), containingBlockWidth, Style::ZoomNeeded { }),
1111+
Style::evaluate<LayoutUnit>(style.paddingAfter(), containingBlockWidth, Style::ZoomNeeded { })
1112+
}
11021113
};
11031114
}
11041115

Source/WebCore/layout/formattingContexts/FormattingGeometry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ std::optional<LayoutUnit> FormattingGeometry::computedValue(const auto& geometry
130130
{
131131
// In general, the computed value resolves the specified value as far as possible without laying out the content.
132132
if (geometryProperty.isSpecified())
133-
return Style::evaluate(geometryProperty, containingBlockWidth, Style::ZoomNeeded { });
133+
return Style::evaluate<LayoutUnit>(geometryProperty, containingBlockWidth, Style::ZoomNeeded { });
134134
return { };
135135
}
136136

137137
std::optional<LayoutUnit> FormattingGeometry::fixedValue(const auto& geometryProperty) const
138138
{
139139
if (auto fixed = geometryProperty.tryFixed())
140-
return LayoutUnit { fixed->resolveZoom(Style::ZoomNeeded { }) };
140+
return LayoutUnit(fixed->resolveZoom(Style::ZoomNeeded { }));
141141
return { };
142142
}
143143

Source/WebCore/layout/formattingContexts/block/BlockFormattingGeometry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ IntrinsicWidthConstraints BlockFormattingGeometry::intrinsicWidthConstraints(con
327327
auto fixedMarginBorderAndPadding = [&](auto& layoutBox) {
328328
auto& style = layoutBox.style();
329329
return fixedValue(style.marginStart()).value_or(0)
330-
+ LayoutUnit { Style::evaluate(style.borderLeftWidth(), Style::ZoomNeeded { }) }
330+
+ Style::evaluate<LayoutUnit>(style.borderLeftWidth(), Style::ZoomNeeded { })
331331
+ fixedValue(style.paddingLeft()).value_or(0)
332332
+ fixedValue(style.paddingRight()).value_or(0)
333-
+ LayoutUnit { Style::evaluate(style.borderRightWidth(), Style::ZoomNeeded { }) }
333+
+ Style::evaluate<LayoutUnit>(style.borderRightWidth(), Style::ZoomNeeded { })
334334
+ fixedValue(style.marginEnd()).value_or(0);
335335
};
336336

Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "LayoutState.h"
3636
#include "LengthFunctions.h"
3737
#include "RenderStyleInlines.h"
38+
#include "StylePrimitiveNumericTypes+Evaluation.h"
3839
#include <ranges>
3940
#include <wtf/FixedVector.h>
4041
#include <wtf/TZoneMallocInlines.h>
@@ -91,9 +92,9 @@ FlexLayout::LogicalFlexItems FlexFormattingContext::convertFlexItemsToLogicalSpa
9192

9293
auto propertyValueForLength = [&](auto& propertyValue, auto availableSize) -> std::optional<LayoutUnit> {
9394
if (auto fixedPropertyValue = propertyValue.tryFixed())
94-
return LayoutUnit { fixedPropertyValue->resolveZoom(Style::ZoomNeeded { }) };
95+
return Style::evaluate<LayoutUnit>(*fixedPropertyValue, Style::ZoomNeeded { });
9596
if (propertyValue.isSpecified() && availableSize)
96-
return Style::evaluate(propertyValue, *availableSize, Style::ZoomNeeded { });
97+
return Style::evaluate<LayoutUnit>(propertyValue, *availableSize, Style::ZoomNeeded { });
9798
return { };
9899
};
99100

0 commit comments

Comments
 (0)