diff --git a/layout/style/nsCSSDataBlock.cpp b/layout/style/nsCSSDataBlock.cpp index ac88d95aaf2d..dd8e886c4dc5 100644 --- a/layout/style/nsCSSDataBlock.cpp +++ b/layout/style/nsCSSDataBlock.cpp @@ -60,6 +60,23 @@ TryToStartImageLoadOnValue(const nsCSSValue& aValue, nsIDocument* aDocument, MOZ_ASSERT(aDocument); if (aValue.GetUnit() == eCSSUnit_URL) { +#ifdef MOZ_ENABLE_MASK_AS_SHORTHAND + // The 'mask-image' property accepts local reference URIs. + // For example, + // mask-image: url(#mask_id); // refer to a SVG mask element, whose id is + // // "mask_id", in the current document. + // For such 'mask-image' values (pointing to an in-document element), + // there is no need to trigger image download. + if (aProperty == eCSSProperty_mask_image) { + nsIURI* docURI = aDocument->GetDocumentURI(); + nsIURI* imageURI = aValue.GetURLValue(); + bool isEqualExceptRef = false; + nsresult rv = imageURI->EqualsExceptRef(docURI, &isEqualExceptRef); + if (NS_SUCCEEDED(rv) && isEqualExceptRef) { + return; + } + } +#endif aValue.StartImageLoad(aDocument); if (aForTokenStream && aContext) { CSSVariableImageTable::Add(aContext, aProperty, diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 294956a1bc7d..5f86c05ba3f7 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -1259,13 +1259,25 @@ static void SetStyleImage(nsStyleContext* aStyleContext, case eCSSUnit_Unset: case eCSSUnit_None: break; - default: - // We might have eCSSUnit_URL values for if-visited style - // contexts, which we can safely treat like 'none'. Otherwise - // this is an unexpected unit. - NS_ASSERTION(aStyleContext->IsStyleIfVisited() && - aValue.GetUnit() == eCSSUnit_URL, + case eCSSUnit_URL: + { +#ifdef DEBUG + nsIDocument* currentDoc = aStyleContext->PresContext()->Document(); + nsIURI* docURI = currentDoc->GetDocumentURI(); + nsIURI* imageURI = aValue.GetURLValue(); + bool isEqualExceptRef = false; + imageURI->EqualsExceptRef(docURI, &isEqualExceptRef); + // Either we have eCSSUnit_URL values for if-visited style contexts, + // which we can safely treat like 'none', or aValue refers to an + // in-document resource. Otherwise this is an unexpected unit. + NS_ASSERTION(aStyleContext->IsStyleIfVisited() || isEqualExceptRef, "unexpected unit; maybe nsCSSValue::Image::Image() failed?"); +#endif + + break; + } + default: + MOZ_ASSERT_UNREACHABLE("Unexpected Unit type."); break; } } @@ -6575,7 +6587,8 @@ struct BackgroundItemComputer > nsCOMPtr& aComputedValue, RuleNodeCacheConditions& aConditions) { - if (eCSSUnit_Image == aSpecifiedValue->mValue.GetUnit()) { + if (eCSSUnit_Image == aSpecifiedValue->mValue.GetUnit() || + eCSSUnit_URL == aSpecifiedValue->mValue.GetUnit()) { aComputedValue = aSpecifiedValue->mValue.GetURLValue(); } else if (eCSSUnit_Null != aSpecifiedValue->mValue.GetUnit()) { aComputedValue = nullptr;