Bug 652991 - Part 2. Create FragmentOrURL to hold both local-ref/non-local-ref URL. r=heycam

MozReview-Commit-ID: FVPNqxk3Uyr

--HG--
extra : rebase_source : 4777d3785e4e1794d223fad66a0780f2e79d0511
This commit is contained in:
cku 2016-06-18 00:02:43 +01:00
Родитель bf6722fc83
Коммит 05cf37818b
2 изменённых файлов: 137 добавлений и 0 удалений

Просмотреть файл

@ -66,6 +66,13 @@ EqualURIs(mozilla::css::URLValue *aURI1, mozilla::css::URLValue *aURI2)
(aURI1 && aURI2 && aURI1->URIEquals(*aURI2));
}
static
bool EqualURIs(const FragmentOrURL* aURI1, const FragmentOrURL* aURI2)
{
return aURI1 == aURI2 || // handle null==null, and optimize
(aURI1 && aURI2 && *aURI1 == *aURI2);
}
static bool
EqualImages(imgIRequest *aImage1, imgIRequest* aImage2)
{
@ -1003,6 +1010,103 @@ nsStyleBasicShape::GetShapeTypeName() const
return eCSSKeyword_UNKNOWN;
}
// --------------------
// FragmentOrURL
//
void
FragmentOrURL::SetValue(const nsCSSValue* aValue)
{
mozilla::css::URLValue *urlVal = aValue->GetURLStructValue();
MOZ_ASSERT_IF(urlVal->GetLocalURLFlag(), urlVal->GetURI());
mIsLocalRef = urlVal->GetLocalURLFlag();
mURL = urlVal->GetURI();
#ifdef DEBUG
if (mIsLocalRef) {
bool hasRef = false;
mURL->GetHasRef(&hasRef);
MOZ_ASSERT(hasRef);
}
#endif
}
void
FragmentOrURL::SetNull()
{
mURL = nullptr;
mIsLocalRef = false;
}
FragmentOrURL&
FragmentOrURL::operator=(const FragmentOrURL& aOther)
{
mIsLocalRef = aOther.mIsLocalRef;
mURL = aOther.mURL;
return *this;
}
bool
FragmentOrURL::operator==(const FragmentOrURL& aOther) const
{
if (aOther.mIsLocalRef != mIsLocalRef) {
return false;
}
return EqualURIs(aOther.mURL, mURL);
}
bool
FragmentOrURL::EqualsExceptRef(nsIURI* aURI) const
{
bool ret = false;
mURL->EqualsExceptRef(aURI, &ret);
return ret;
}
void
FragmentOrURL::GetSourceString(nsString &aRef) const
{
MOZ_ASSERT(mURL);
nsCString cref;
if (mIsLocalRef) {
mURL->GetRef(cref);
cref.Insert('#', 0);
} else {
mURL->GetSpec(cref);
}
aRef = NS_ConvertUTF8toUTF16(cref);
}
already_AddRefed<nsIURI>
FragmentOrURL::Resolve(nsIURI* aURI) const
{
nsCOMPtr<nsIURI> result;
if (mIsLocalRef) {
nsCString ref;
mURL->GetRef(ref);
aURI->Clone(getter_AddRefs(result));
result->SetRef(ref);
} else {
result = mURL;
}
return result.forget();
}
already_AddRefed<nsIURI>
FragmentOrURL::Resolve(nsIContent* aContent) const
{
nsCOMPtr<nsIURI> url = aContent->GetBaseURI();
return Resolve(url);
}
// --------------------
// nsStyleClipPath
//

Просмотреть файл

@ -3233,6 +3233,39 @@ protected:
nscoord mTwipsPerPixel;
};
struct FragmentOrURL
{
FragmentOrURL() : mIsLocalRef(false) {}
FragmentOrURL(const FragmentOrURL& aSource)
: mIsLocalRef(false)
{ *this = aSource; }
void SetValue(const nsCSSValue* aValue);
void SetNull();
FragmentOrURL& operator=(const FragmentOrURL& aOther);
bool operator==(const FragmentOrURL& aOther) const;
bool operator!=(const FragmentOrURL& aOther) const {
return !(*this == aOther);
}
bool EqualsExceptRef(nsIURI* aURI) const;
nsIURI* GetSourceURL() const { return mURL; }
void GetSourceString(nsString& aRef) const;
// When matching a url with mIsLocalRef set, resolve it against aURI;
// Otherwise, ignore aURL and return mURL directly.
already_AddRefed<nsIURI> Resolve(nsIURI* aURI) const;
already_AddRefed<nsIURI> Resolve(nsIContent* aContent) const;
bool IsLocalRef() const { return mIsLocalRef; }
private:
nsCOMPtr<nsIURI> mURL;
bool mIsLocalRef;
};
enum nsStyleSVGPaintType {
eStyleSVGPaintType_None = 1,
eStyleSVGPaintType_Color,