diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /layout/style/nsComputedDOMStyle.cpp | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | layout/style/nsComputedDOMStyle.cpp | 147 |
1 files changed, 61 insertions, 86 deletions
diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index d40d4bc801..5b71ec54bf 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -1358,11 +1358,28 @@ already_AddRefed<nsROCSSPrimitiveValue> nsComputedDOMStyle::MatrixToCSSValue( /* Create a value to hold our result. */ RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetString(resultString); return val.forget(); } +already_AddRefed<nsROCSSPrimitiveValue> nsComputedDOMStyle::AppUnitsToCSSValue( + nscoord aAppUnits) { + return PixelsToCSSValue(CSSPixel::FromAppUnits(aAppUnits)); +} + +already_AddRefed<nsROCSSPrimitiveValue> nsComputedDOMStyle::PixelsToCSSValue( + float aPixels) { + RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; + SetValueToPixels(val, aPixels); + return val.forget(); +} + +void nsComputedDOMStyle::SetValueToPixels(nsROCSSPrimitiveValue* aValue, + float aPixels) { + MOZ_ASSERT(mComputedStyle); + aValue->SetPixels(mComputedStyle->EffectiveZoom().Unzoom(aPixels)); +} + already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetMozOsxFontSmoothing() { if (nsContentUtils::ShouldResistFingerprinting( mPresShell->GetPresContext()->GetDocShell(), @@ -1614,9 +1631,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridTemplateColumnsRows( // Add any leading implicit tracks. if (serializeImplicit) { for (uint32_t i = 0; i < numLeadingImplicitTracks; ++i) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(trackSizes[i]); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(trackSizes[i])); } } @@ -1652,8 +1667,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridTemplateColumnsRows( for (uint32_t i = 0; i < repeatStart; i++) { AppendGridLineNames(valueList, aTrackInfo.mResolvedLineNames[i]); RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(*trackSizeIter++); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(*trackSizeIter++)); } auto lineNameIter = aTrackInfo.mResolvedLineNames.cbegin() + repeatStart; // Write the track names at the start of the repeat, including the names @@ -1666,9 +1680,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridTemplateColumnsRows( // track). const nscoord firstRepeatTrackSize = (!aTrackInfo.mRemovedRepeatTracks[0]) ? *trackSizeIter++ : 0; - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(firstRepeatTrackSize); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(firstRepeatTrackSize)); } // Write the line names and track sizes inside the repeat, checking for // removed tracks (size 0). @@ -1688,9 +1700,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridTemplateColumnsRows( trackSizeIter != explicitTrackSizeEnd); const nscoord repeatTrackSize = (!aTrackInfo.mRemovedRepeatTracks[i]) ? *trackSizeIter++ : 0; - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(repeatTrackSize); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(repeatTrackSize)); } // The resolved line names include a single repetition of the auto-repeat // line names. Skip over those. @@ -1698,9 +1708,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridTemplateColumnsRows( // Write out any more tracks after the repeat. while (trackSizeIter != explicitTrackSizeEnd) { AppendGridLineNames(valueList, *lineNameIter++); - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(*trackSizeIter++); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(*trackSizeIter++)); } // Write the final trailing line name. AppendGridLineNames(valueList, *lineNameIter++); @@ -1711,18 +1719,15 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridTemplateColumnsRows( if (i == numExplicitTracks) { break; } - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(trackSizes[i + numLeadingImplicitTracks]); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue( + AppUnitsToCSSValue(trackSizes[i + numLeadingImplicitTracks])); } } // Add any trailing implicit tracks. if (serializeImplicit) { for (uint32_t i = numLeadingImplicitTracks + numExplicitTracks; i < numSizes; ++i) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(trackSizes[i]); - valueList->AppendCSSValue(val.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(trackSizes[i])); } } @@ -1787,15 +1792,9 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetPaddingRight() { already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetBorderSpacing() { RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false); - RefPtr<nsROCSSPrimitiveValue> xSpacing = new nsROCSSPrimitiveValue; - RefPtr<nsROCSSPrimitiveValue> ySpacing = new nsROCSSPrimitiveValue; - const nsStyleTableBorder* border = StyleTableBorder(); - xSpacing->SetAppUnits(border->mBorderSpacingCol); - ySpacing->SetAppUnits(border->mBorderSpacingRow); - - valueList->AppendCSSValue(xSpacing.forget()); - valueList->AppendCSSValue(ySpacing.forget()); + valueList->AppendCSSValue(AppUnitsToCSSValue(border->mBorderSpacingCol)); + valueList->AppendCSSValue(AppUnitsToCSSValue(border->mBorderSpacingRow)); return valueList.forget(); } @@ -1833,32 +1832,26 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetMarginRight() { } already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetHeight() { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - if (mInnerFrame && !IsNonReplacedInline(mInnerFrame)) { AssertFlushedPendingReflows(); - nsMargin adjustedValues = GetAdjustedValuesForBoxSizing(); - val->SetAppUnits(mInnerFrame->GetContentRect().height + - adjustedValues.TopBottom()); - } else { - SetValueToSize(val, StylePosition()->mHeight); + const nsMargin adjustedValues = GetAdjustedValuesForBoxSizing(); + return AppUnitsToCSSValue(mInnerFrame->GetContentRect().height + + adjustedValues.TopBottom()); } - + RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; + SetValueToSize(val, StylePosition()->mHeight); return val.forget(); } already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetWidth() { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - if (mInnerFrame && !IsNonReplacedInline(mInnerFrame)) { AssertFlushedPendingReflows(); nsMargin adjustedValues = GetAdjustedValuesForBoxSizing(); - val->SetAppUnits(mInnerFrame->GetContentRect().width + - adjustedValues.LeftRight()); - } else { - SetValueToSize(val, StylePosition()->mWidth); + return AppUnitsToCSSValue(mInnerFrame->GetContentRect().width + + adjustedValues.LeftRight()); } - + RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; + SetValueToSize(val, StylePosition()->mWidth); return val.forget(); } @@ -1968,14 +1961,13 @@ static_assert(eSideTop == 0 && eSideRight == 1 && eSideBottom == 2 && already_AddRefed<CSSValue> nsComputedDOMStyle::GetNonStaticPositionOffset( mozilla::Side aSide, bool aResolveAuto, PercentageBaseGetter aWidthGetter, PercentageBaseGetter aHeightGetter) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - const nsStylePosition* positionData = StylePosition(); int32_t sign = 1; LengthPercentageOrAuto coord = positionData->mOffset.Get(aSide); if (coord.IsAuto()) { if (!aResolveAuto) { + RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; val->SetString("auto"); return val.forget(); } @@ -1983,14 +1975,12 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetNonStaticPositionOffset( sign = -1; } if (!coord.IsLengthPercentage()) { - val->SetPixels(0.0f); - return val.forget(); + return PixelsToCSSValue(0.0f); } - auto& lp = coord.AsLengthPercentage(); + const auto& lp = coord.AsLengthPercentage(); if (lp.ConvertsToLength()) { - val->SetPixels(sign * lp.ToLengthInCSSPixels()); - return val.forget(); + return PixelsToCSSValue(sign * lp.ToLengthInCSSPixels()); } PercentageBaseGetter baseGetter = (aSide == eSideLeft || aSide == eSideRight) @@ -1998,12 +1988,10 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetNonStaticPositionOffset( : aHeightGetter; nscoord percentageBase; if (!(this->*baseGetter)(percentageBase)) { - val->SetPixels(0.0f); - return val.forget(); + return PixelsToCSSValue(0.0f); } nscoord result = lp.Resolve(percentageBase); - val->SetAppUnits(sign * result); - return val.forget(); + return AppUnitsToCSSValue(sign * result); } already_AddRefed<CSSValue> nsComputedDOMStyle::GetAbsoluteOffset( @@ -2013,9 +2001,7 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetAbsoluteOffset( const auto& oppositeCoord = offset.Get(NS_OPPOSITE_SIDE(aSide)); if (coord.IsAuto() || oppositeCoord.IsAuto()) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - val->SetAppUnits(GetUsedAbsoluteOffset(aSide)); - return val.forget(); + return AppUnitsToCSSValue(GetUsedAbsoluteOffset(aSide)); } return GetNonStaticPositionOffset( @@ -2096,23 +2082,18 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetStaticOffset( already_AddRefed<CSSValue> nsComputedDOMStyle::GetPaddingWidthFor( mozilla::Side aSide) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - - auto& padding = StylePadding()->mPadding.Get(aSide); + const auto& padding = StylePadding()->mPadding.Get(aSide); if (!mInnerFrame || !PaddingNeedsUsedValue(padding, *mComputedStyle)) { + RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; SetValueToLengthPercentage(val, padding, true); - } else { - AssertFlushedPendingReflows(); - val->SetAppUnits(mInnerFrame->GetUsedPadding().Side(aSide)); + return val.forget(); } - - return val.forget(); + AssertFlushedPendingReflows(); + return AppUnitsToCSSValue(mInnerFrame->GetUsedPadding().Side(aSide)); } already_AddRefed<CSSValue> nsComputedDOMStyle::GetBorderWidthFor( mozilla::Side aSide) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - nscoord width; if (mInnerFrame && mComputedStyle->StyleDisplay()->HasAppearance()) { AssertFlushedPendingReflows(); @@ -2120,29 +2101,23 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::GetBorderWidthFor( } else { width = StyleBorder()->GetComputedBorderWidth(aSide); } - val->SetAppUnits(width); - - return val.forget(); + return AppUnitsToCSSValue(width); } already_AddRefed<CSSValue> nsComputedDOMStyle::GetMarginFor(Side aSide) { - RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; - - auto& margin = StyleMargin()->mMargin.Get(aSide); + const auto& margin = StyleMargin()->mMargin.Get(aSide); if (!mInnerFrame || margin.ConvertsToLength()) { + RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue; SetValueToLengthPercentageOrAuto(val, margin, false); - } else { - AssertFlushedPendingReflows(); - - // For tables, GetUsedMargin always returns an empty margin, so we - // should read the margin from the table wrapper frame instead. - val->SetAppUnits(mOuterFrame->GetUsedMargin().Side(aSide)); - NS_ASSERTION(mOuterFrame == mInnerFrame || - mInnerFrame->GetUsedMargin() == nsMargin(0, 0, 0, 0), - "Inner tables must have zero margins"); + return val.forget(); } - - return val.forget(); + AssertFlushedPendingReflows(); + // For tables, GetUsedMargin always returns an empty margin, so we + // should read the margin from the table wrapper frame instead. + NS_ASSERTION( + mOuterFrame == mInnerFrame || mInnerFrame->GetUsedMargin() == nsMargin(), + "Inner tables must have zero margins"); + return AppUnitsToCSSValue(mOuterFrame->GetUsedMargin().Side(aSide)); } static void SetValueToExtremumLength(nsROCSSPrimitiveValue* aValue, @@ -2223,7 +2198,7 @@ void nsComputedDOMStyle::SetValueToLengthPercentage( if (aClampNegativeCalc) { length = std::max(float(length), 0.0f); } - return aValue->SetPixels(length); + return SetValueToPixels(aValue, length); } if (aLength.ConvertsToPercentage()) { float result = aLength.ToPercentage(); |