From 7c9304728325428ec47821bd5d983570f495d97a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 24 Apr 2022 17:00:46 +0000 Subject: [PATCH] Issue #1885 - Allow unitless rootMargin entries for IntersectionObserver. I could have done this through a CSSLoader to allow all CSS unit quirks but I wasn't planning to start passing around document and element references everywhere, so instead just did it manually by accepting numbers/floats in addition to pixel and percent. --- dom/base/DOMIntersectionObserver.cpp | 6 +++++- layout/style/nsCSSParser.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp index bc8f030d0f..fb6315cc42 100644 --- a/dom/base/DOMIntersectionObserver.cpp +++ b/dom/base/DOMIntersectionObserver.cpp @@ -126,7 +126,9 @@ DOMIntersectionObserver::SetRootMargin(const nsAString& aString) for (uint32_t i = 0; i < ArrayLength(nsCSSRect::sides); ++i) { nsCSSValue value = mRootMargin.*nsCSSRect::sides[i]; - if (!(value.IsPixelLengthUnit() || value.IsPercentLengthUnit())) { + if (!(value.IsPixelLengthUnit() || + value.IsPercentLengthUnit() || + value.IsFloatUnit(value.GetUnit()))) { return false; } } @@ -327,6 +329,8 @@ DOMIntersectionObserver::Update(nsIDocument* aDocument, DOMHighResTimeStamp time nsStyleCoord coord; if (value.IsPixelLengthUnit()) { coord.SetCoordValue(value.GetPixelLength()); + } else if (value.IsFloatUnit(value.GetUnit())) { + coord.SetCoordValue(value.GetFloatValue()); } else if (value.IsPercentLengthUnit()) { coord.SetPercentValue(value.GetPercentValue()); } else { diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 4331e454dc..a7e5e4d4b9 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -2315,7 +2315,7 @@ CSSParserImpl::ParseMarginString(const nsSubstring& aBuffer, } else { UngetToken(); // Parse a margin, and check that there's nothing else after it. - marginParsed = ParseGroupedBoxProperty(VARIANT_LP, aValue, 0) && + marginParsed = ParseGroupedBoxProperty(VARIANT_LPN, aValue, 0) && !GetToken(true); }