summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2022-04-24 21:30:54 -0500
committerMatt A. Tobin <email@mattatobin.com>2022-04-24 21:30:54 -0500
commit13b81b9a58ed8b162d57e770dff3ed99b84eb309 (patch)
treee2af33e1442251aba672084209b9946f99395186
parent33ba1e8f1b45d5f758c8148b3118bd369dbd48a3 (diff)
downloadaura-central-13b81b9a58ed8b162d57e770dff3ed99b84eb309.tar.gz
Issue #29 - Interpret empty or whitespace root margin string as zero length for the IntersectionObserver
Credit to FranklinDM
-rw-r--r--dom/base/DOMIntersectionObserver.cpp6
-rw-r--r--layout/style/nsCSSParser.cpp16
2 files changed, 19 insertions, 3 deletions
diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp
index bc8f030d0..fb6315cc4 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 f3df2df20..72427792f 100644
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -2300,8 +2300,20 @@ CSSParserImpl::ParseMarginString(const nsSubstring& aBuffer,
nsAutoSuppressErrors suppressErrors(this, aSuppressErrors);
- // Parse a margin, and check that there's nothing else after it.
- bool marginParsed = ParseGroupedBoxProperty(VARIANT_LP, aValue, 0) && !GetToken(true);
+ bool marginParsed = false;
+
+ // Treat margin as zero length if there are no tokens, i.e., the specified
+ // margin string is empty or consists only of whitespace characters.
+ if (!GetToken(true)) {
+ nsCSSRect& zeroRootMargin = aValue.SetRectValue();
+ zeroRootMargin.SetAllSidesTo(nsCSSValue(0.0f, eCSSUnit_Pixel));
+ marginParsed = true;
+ } else {
+ UngetToken();
+ // Parse a margin, and check that there's nothing else after it.
+ marginParsed = ParseGroupedBoxProperty(VARIANT_LPN, aValue, 0) &&
+ !GetToken(true);
+ }
if (aSuppressErrors) {
CLEAR_ERROR();