Bug 1298774 - Part 8: Make mask-image use css::URLValueData for url() storage instead of FragmentOrURL. r=cjku

MozReview-Commit-ID: 2Xm3IP3SXK0

--HG--
extra : rebase_source : e524bf9a7641a80ef591dc380f4832cbcb5944ba
This commit is contained in:
Cameron McCormack 2016-10-11 14:56:12 +08:00
Родитель 840196223a
Коммит ccba4f429e
5 изменённых файлов: 56 добавлений и 26 удалений

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

@ -2143,10 +2143,11 @@ nsComputedDOMStyle::DoGetImageLayerImage(const nsStyleImageLayers& aLayers)
// Instead, we store the local URI in one place -- on Layer::mSourceURI.
// Hence, we must serialize using mSourceURI (instead of
// SetValueToStyleImage()/mImage) in this case.
if (aLayers.mLayers[i].mSourceURI.IsLocalRef()) {
if (aLayers.mLayers[i].mSourceURI &&
aLayers.mLayers[i].mSourceURI->IsLocalRef()) {
// This is how we represent a 'mask-image' reference for a local URI,
// such as 'mask-image:url(#mymask)' or 'mask:url(#mymask)'
SetValueToFragmentOrURL(&aLayers.mLayers[i].mSourceURI, val);
SetValueToURLValue(aLayers.mLayers[i].mSourceURI, val);
} else {
SetValueToStyleImage(image, val);
}
@ -6168,11 +6169,7 @@ nsComputedDOMStyle::DoGetMask()
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
if (firstLayer.mSourceURI.GetSourceURL()) {
SetValueToFragmentOrURL(&firstLayer.mSourceURI, val);
} else {
val->SetIdent(eCSSKeyword_none);
}
SetValueToURLValue(firstLayer.mSourceURI, val);
return val.forget();
}

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

@ -6704,6 +6704,30 @@ struct BackgroundItemComputer<nsCSSValueList, FragmentOrURL>
}
};
template <>
struct BackgroundItemComputer<nsCSSValueList, RefPtr<css::URLValueData>>
{
static void ComputeValue(nsStyleContext* aStyleContext,
const nsCSSValueList* aSpecifiedValue,
RefPtr<css::URLValueData>& aComputedValue,
RuleNodeCacheConditions& aConditions)
{
switch (aSpecifiedValue->mValue.GetUnit()) {
case eCSSUnit_Null:
break;
case eCSSUnit_URL:
aComputedValue = aSpecifiedValue->mValue.GetURLStructValue();
break;
case eCSSUnit_Image:
aComputedValue = aSpecifiedValue->mValue.GetImageStructValue();
break;
default:
aComputedValue = nullptr;
break;
}
}
};
/* Helper function for ComputePositionValue.
* This function computes a single PositionCoord from two nsCSSValue objects,
* which represent an edge and an offset from that edge.
@ -9938,7 +9962,8 @@ nsRuleNode::ComputeSVGResetData(void* aStartStruct,
svgReset->mMask.mLayers,
parentSVGReset->mMask.mLayers,
&nsStyleImageLayers::Layer::mSourceURI,
FragmentOrURL(), parentSVGReset->mMask.mImageCount,
RefPtr<css::URLValueData>(),
parentSVGReset->mMask.mImageCount,
svgReset->mMask.mImageCount,
maxItemCount, rebuild, conditions);

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

@ -60,14 +60,16 @@ EqualURIs(nsIURI *aURI1, nsIURI *aURI2)
}
static bool
DefinitelyEqualURIs(css::URLValue* aURI1, css::URLValue* aURI2)
DefinitelyEqualURIs(css::URLValueData* aURI1,
css::URLValueData* aURI2)
{
return aURI1 == aURI2 ||
(aURI1 && aURI2 && aURI1->DefinitelyEqualURIs(*aURI2));
}
static bool
DefinitelyEqualURIsAndPrincipal(css::URLValue* aURI1, css::URLValue* aURI2)
DefinitelyEqualURIsAndPrincipal(css::URLValueData* aURI1,
css::URLValueData* aURI2)
{
return aURI1 == aURI2 ||
(aURI1 && aURI2 && aURI1->DefinitelyEqualURIsAndPrincipal(*aURI2));
@ -2545,7 +2547,8 @@ nsStyleImageLayers::HasLayerWithImage() const
// mLayers[i].mImage can be empty if mask-image prop value is a reference
// to SVG mask element.
// So we need to test both mSourceURI and mImage.
if (mLayers[i].mSourceURI.GetSourceURL() || !mLayers[i].mImage.IsEmpty()) {
if ((mLayers[i].mSourceURI && mLayers[i].mSourceURI->GetURI()) ||
!mLayers[i].mImage.IsEmpty()) {
return true;
}
}
@ -2779,7 +2782,7 @@ nsStyleImageLayers::Layer::operator==(const Layer& aOther) const
mImage == aOther.mImage &&
mMaskMode == aOther.mMaskMode &&
mComposite == aOther.mComposite &&
mSourceURI == aOther.mSourceURI;
DefinitelyEqualURIs(mSourceURI, aOther.mSourceURI);
}
nsChangeHint
@ -2787,7 +2790,7 @@ nsStyleImageLayers::Layer::CalcDifference(const nsStyleImageLayers::Layer& aNewL
nsChangeHint aPositionChangeHint) const
{
nsChangeHint hint = nsChangeHint(0);
if (mSourceURI != aNewLayer.mSourceURI) {
if (!DefinitelyEqualURIs(mSourceURI, aNewLayer.mSourceURI)) {
hint |= nsChangeHint_RepaintFrame | nsChangeHint_UpdateEffects;
// If Layer::mSourceURI links to a SVG mask, it has a fragment. Not vice
@ -2802,17 +2805,21 @@ nsStyleImageLayers::Layer::CalcDifference(const nsStyleImageLayers::Layer& aNewL
// 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.IsLocalRef()) {
maybeSVGMask = true;
} else if (mSourceURI.GetSourceURL()) {
mSourceURI.GetSourceURL()->GetHasRef(&maybeSVGMask);
if (mSourceURI) {
if (mSourceURI->IsLocalRef()) {
maybeSVGMask = true;
} else if (mSourceURI->GetURI()) {
mSourceURI->GetURI()->GetHasRef(&maybeSVGMask);
}
}
if (!maybeSVGMask) {
if (aNewLayer.mSourceURI.IsLocalRef()) {
maybeSVGMask = true;
} else if (aNewLayer.mSourceURI.GetSourceURL()) {
aNewLayer.mSourceURI.GetSourceURL()->GetHasRef(&maybeSVGMask);
if (aNewLayer.mSourceURI) {
if (aNewLayer.mSourceURI->IsLocalRef()) {
maybeSVGMask = true;
} else if (aNewLayer.mSourceURI->GetURI()) {
aNewLayer.mSourceURI->GetURI()->GetHasRef(&maybeSVGMask);
}
}
}

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

@ -705,13 +705,14 @@ struct nsStyleImageLayers {
friend struct Layer;
struct Layer {
nsStyleImage mImage; // [reset]
mozilla::FragmentOrURL mSourceURI; // [reset]
RefPtr<mozilla::css::URLValueData> mSourceURI; // [reset]
// mask-only property
// This property is used for mask layer only.
// For a background layer, it should always
// be the initial value, which is nullptr.
// Store mask-image URI so that we can resolve
// SVG mask path later.
// SVG mask path later. (Might be a URLValue
// or an ImageValue.)
mozilla::Position mPosition; // [reset]
Size mSize; // [reset]
uint8_t mClip; // [reset] See nsStyleConsts.h

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

@ -943,7 +943,7 @@ ResolveFragmentOrURL(nsIFrame* aFrame, const FragmentOrURL* aFragmentOrURL)
}
static already_AddRefed<nsIURI>
ResolveURLUsingLocalRef(nsIFrame* aFrame, const css::URLValue* aURL)
ResolveURLUsingLocalRef(nsIFrame* aFrame, const css::URLValueData* aURL)
{
MOZ_ASSERT(aFrame);
@ -1050,6 +1050,6 @@ nsSVGEffects::GetMaskURI(nsIFrame* aFrame, uint32_t aIndex)
const nsStyleSVGReset* svgReset = aFrame->StyleSVGReset();
MOZ_ASSERT(svgReset->mMask.mLayers.Length() > aIndex);
return ResolveFragmentOrURL(aFrame,
&svgReset->mMask.mLayers[aIndex].mSourceURI);
return ResolveURLUsingLocalRef(aFrame,
svgReset->mMask.mLayers[aIndex].mSourceURI);
}