Bug 1345377 - Implement URLValueData::HasRef.
Improve code readability.
MozReview-Commit-ID: HDJ7TeyqCpN
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -2843,16 +2843,37 @@ css::URLValueData::GetURI() const
nullptr, const_cast<nsIURI*>(mBaseURI.get()));
mURI = new PtrHolder<nsIURI>(newURI.forget());
mURIResolved = true;
}
return mURI;
}
+bool
+css::URLValueData::HasRef() const
+{
+ if (IsLocalRef()) {
+ return true;
+ }
+
+ nsIURI* uri = GetURI();
+ if (!uri) {
+ return false;
+ }
+
+ nsAutoCString ref;
+ nsresult rv = uri->GetRef(ref);
+ if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
+ return true;
+ }
+
+ return false;
+}
+
already_AddRefed<nsIURI>
css::URLValueData::ResolveLocalRef(nsIURI* aURI) const
{
nsCOMPtr<nsIURI> result = GetURI();
if (result && mIsLocalRef) {
nsCString ref;
mURI->GetRef(ref);
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -133,16 +133,18 @@ public:
// Smae as DefinitelyEqualURIs but additionally compares the nsIPrincipal
// pointers of the two URLValueData objects.
bool DefinitelyEqualURIsAndPrincipal(const URLValueData& aOther) const;
nsIURI* GetURI() const;
bool IsLocalRef() const { return mIsLocalRef; }
+ bool HasRef() const;
+
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(URLValueData)
// When matching a url with mIsLocalRef set, resolve it against aURI;
// Otherwise, ignore aURL and return mURL directly.
already_AddRefed<nsIURI> ResolveLocalRef(nsIURI* aURI) const;
already_AddRefed<nsIURI> ResolveLocalRef(nsIContent* aContent) const;
// Serializes mURI as a computed URI value, taking into account mIsLocalRef
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -2927,31 +2927,21 @@ nsStyleImageLayers::Layer::CalcDifferenc
// mask:url(#localMaskID); // The fragment of this URI is an ID of a mask
// // element in local document.
// mask:url(b.svg#viewBoxID); // The fragment of this URI is an ID of a
// // viewbox defined in b.svg.
// That is, if mSourceURI has a fragment, it may link to a SVG mask; If
// not, it "must" not link to a SVG mask.
bool maybeSVGMask = false;
if (mSourceURI) {
- if (mSourceURI->IsLocalRef()) {
- maybeSVGMask = true;
- } else if (mSourceURI->GetURI()) {
- mSourceURI->GetURI()->GetHasRef(&maybeSVGMask);
- }
+ maybeSVGMask = mSourceURI->HasRef();
}
- if (!maybeSVGMask) {
- if (aNewLayer.mSourceURI) {
- if (aNewLayer.mSourceURI->IsLocalRef()) {
- maybeSVGMask = true;
- } else if (aNewLayer.mSourceURI->GetURI()) {
- aNewLayer.mSourceURI->GetURI()->GetHasRef(&maybeSVGMask);
- }
- }
+ if (!maybeSVGMask && aNewLayer.mSourceURI) {
+ maybeSVGMask = aNewLayer.mSourceURI->HasRef();
}
// Return nsChangeHint_UpdateOverflow if either URI might link to an SVG
// mask.
if (maybeSVGMask) {
// Mask changes require that we update the PreEffectsBBoxProperty,
// which is done during overflow computation.
hint |= nsChangeHint_UpdateOverflow;