Bug 1298774 - Part 4: Make ShapeStyleSource use css::URLValue for url() storage instead of FragmentOrURL. r=cjku

MozReview-Commit-ID: CQy6ArR48Sp

--HG--
extra : rebase_source : 71203745bca616395daeffe5b47b288b0ce67b0b
This commit is contained in:
Cameron McCormack 2016-10-11 14:56:11 +08:00
Родитель 5ed807d5a2
Коммит f1dcd6fc45
6 изменённых файлов: 92 добавлений и 32 удалений

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

@ -4120,12 +4120,8 @@ StyleAnimationValue::ExtractComputedValue(nsCSSPropertyID aProperty,
const StyleShapeSourceType type = clipPath.GetType();
if (type == StyleShapeSourceType::URL) {
nsIDocument* doc = aStyleContext->PresContext()->Document();
RefPtr<mozilla::css::URLValue> url =
FragmentOrURLToURLValue(clipPath.GetURL(), doc);
auto result = MakeUnique<nsCSSValue>();
result->SetURLValue(url);
result->SetURLValue(clipPath.GetURL());
aComputedValue.SetAndAdoptCSSValueValue(result.release(), eUnit_URL);
} else if (type == StyleShapeSourceType::Box) {
aComputedValue.SetIntValue(clipPath.GetReferenceBox(),

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

@ -2407,6 +2407,26 @@ nsComputedDOMStyle::SetValueToFragmentOrURL(
}
}
void
nsComputedDOMStyle::SetValueToURLValue(const css::URLValueData* aURL,
nsROCSSPrimitiveValue* aValue)
{
if (aURL && aURL->IsLocalRef()) {
nsString fragment;
aURL->GetSourceString(fragment);
fragment.Insert(u"url(\"", 0);
fragment.Append(u"\")");
aValue->SetString(fragment);
} else {
nsCOMPtr<nsIURI> url;
if (aURL && (url = aURL->GetURI())) {
aValue->SetURI(url);
} else {
aValue->SetIdent(eCSSKeyword_none);
}
}
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBackgroundPosition()
{
@ -6030,7 +6050,7 @@ nsComputedDOMStyle::GetShapeSource(
aBoxKeywordTable);
case StyleShapeSourceType::URL: {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
SetValueToFragmentOrURL(aShapeSource.GetURL(), val);
SetValueToURLValue(aShapeSource.GetURL(), val);
return val.forget();
}
case StyleShapeSourceType::None: {

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

@ -593,6 +593,8 @@ private:
nsDOMCSSValueList* aValueList);
void SetValueToFragmentOrURL(const mozilla::FragmentOrURL* aFragmentOrURL,
nsROCSSPrimitiveValue* aValue);
void SetValueToURLValue(const mozilla::css::URLValueData* aURL,
nsROCSSPrimitiveValue* aValue);
/**
* A method to get a percentage base for a percentage value. Returns true

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

@ -6452,7 +6452,7 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
break;
case eCSSUnit_URL: {
display->mShapeOutside = StyleShapeOutside();
display->mShapeOutside.SetURL(shapeOutsideValue);
display->mShapeOutside.SetURL(shapeOutsideValue->GetURLStructValue());
break;
}
case eCSSUnit_Array: {
@ -9865,7 +9865,7 @@ nsRuleNode::ComputeSVGResetData(void* aStartStruct,
break;
case eCSSUnit_URL: {
svgReset->mClipPath = StyleClipPath();
svgReset->mClipPath.SetURL(clipPathValue);
svgReset->mClipPath.SetURL(clipPathValue->GetURLStructValue());
break;
}
case eCSSUnit_Array: {

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

@ -2542,7 +2542,7 @@ struct StyleShapeSource
: StyleShapeSource()
{
if (aSource.mType == StyleShapeSourceType::URL) {
CopyURL(aSource);
SetURL(aSource.mURL);
} else if (aSource.mType == StyleShapeSourceType::Shape) {
SetBasicShape(aSource.mBasicShape, aSource.mReferenceBox);
} else if (aSource.mType == StyleShapeSourceType::Box) {
@ -2562,7 +2562,7 @@ struct StyleShapeSource
}
if (aOther.mType == StyleShapeSourceType::URL) {
CopyURL(aOther);
SetURL(aOther.mURL);
} else if (aOther.mType == StyleShapeSourceType::Shape) {
SetBasicShape(aOther.mBasicShape, aOther.mReferenceBox);
} else if (aOther.mType == StyleShapeSourceType::Box) {
@ -2582,7 +2582,7 @@ struct StyleShapeSource
}
if (mType == StyleShapeSourceType::URL) {
return mURL == aOther.mURL;
return mURL->Equals(*aOther.mURL);
} else if (mType == StyleShapeSourceType::Shape) {
return *mBasicShape == *aOther.mBasicShape &&
mReferenceBox == aOther.mReferenceBox;
@ -2603,22 +2603,18 @@ struct StyleShapeSource
return mType;
}
FragmentOrURL* GetURL() const
css::URLValue* GetURL() const
{
MOZ_ASSERT(mType == StyleShapeSourceType::URL, "Wrong shape source type!");
return mURL;
}
bool SetURL(const nsCSSValue* aValue)
bool SetURL(css::URLValue* aValue)
{
if (!aValue->GetURLValue()) {
return false;
}
MOZ_ASSERT(aValue);
ReleaseRef();
mURL = new FragmentOrURL();
mURL->SetValue(aValue);
mURL = aValue;
mURL->AddRef();
mType = StyleShapeSourceType::URL;
return true;
}
@ -2663,26 +2659,18 @@ private:
mBasicShape->Release();
} else if (mType == StyleShapeSourceType::URL) {
NS_ASSERTION(mURL, "expected pointer");
delete mURL;
mURL->Release();
}
// Both mBasicShape and mURL are pointers in a union. Nulling one of them
// nulls both of them.
mURL = nullptr;
}
void CopyURL(const StyleShapeSource& aOther)
{
ReleaseRef();
mURL = new FragmentOrURL(*aOther.mURL);
mType = StyleShapeSourceType::URL;
}
void* operator new(size_t) = delete;
union {
StyleBasicShape* mBasicShape;
FragmentOrURL* mURL;
css::URLValue* mURL;
};
StyleShapeSourceType mType = StyleShapeSourceType::None;
ReferenceBox mReferenceBox = ReferenceBox::NoBox;

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

@ -942,6 +942,60 @@ ResolveFragmentOrURL(nsIFrame* aFrame, const FragmentOrURL* aFragmentOrURL)
return aFragmentOrURL->Resolve(baseURI);
}
static already_AddRefed<nsIURI>
ResolveURLUsingLocalRef(nsIFrame* aFrame, const css::URLValue* aURL)
{
MOZ_ASSERT(aFrame);
if (!aURL) {
return nullptr;
}
// Non-local-reference URL.
if (!aURL->IsLocalRef()) {
nsCOMPtr<nsIURI> result = aURL->GetURI();
return result.forget();
}
// For a local-reference URL, resolve that fragment against the current
// document that relative URLs are resolved against.
nsIContent* content = aFrame->GetContent();
nsCOMPtr<nsIURI> baseURI = content->OwnerDoc()->GetDocumentURI();
if (content->IsInAnonymousSubtree()) {
nsIContent* bindingParent = content->GetBindingParent();
nsCOMPtr<nsIURI> originalURI;
// content is in a shadow tree. If this URL was specified in the subtree
// referenced by the <use>(or -moz-binding) element, and that subtree came
// from a separate resource document, then we want the fragment-only URL
// to resolve to an element from the resource document. Otherwise, the
// URL was specified somewhere in the document with the <use> element, and
// we want the fragment-only URL to resolve to an element in that document.
if (bindingParent) {
if (content->IsAnonymousContentInSVGUseSubtree()) {
SVGUseElement* useElement = static_cast<SVGUseElement*>(bindingParent);
originalURI = useElement->GetSourceDocURI();
} else {
nsXBLBinding* binding = bindingParent->GetXBLBinding();
if (binding) {
originalURI = binding->GetSourceDocURI();
} else {
MOZ_ASSERT(content->IsInNativeAnonymousSubtree(),
"an non-native anonymous tree which is not from "
"an XBL binding?");
}
}
if (originalURI && aURL->EqualsExceptRef(originalURI)) {
baseURI = originalURI;
}
}
}
return aURL->ResolveLocalRef(baseURI);
}
already_AddRefed<nsIURI>
nsSVGEffects::GetMarkerURI(nsIFrame* aFrame,
FragmentOrURL nsStyleSVG::* aMarker)
@ -955,8 +1009,8 @@ nsSVGEffects::GetClipPathURI(nsIFrame* aFrame)
const nsStyleSVGReset* svgResetStyle = aFrame->StyleSVGReset();
MOZ_ASSERT(svgResetStyle->mClipPath.GetType() == StyleShapeSourceType::URL);
FragmentOrURL* url = svgResetStyle->mClipPath.GetURL();
return ResolveFragmentOrURL(aFrame, url);
css::URLValue* url = svgResetStyle->mClipPath.GetURL();
return ResolveURLUsingLocalRef(aFrame, url);
}
already_AddRefed<nsIURI>