Bug 1329093 - Part 3: Overload FromContent() to work with const; r?bz
MozReview-Commit-ID: BUFmPtcf6LM
--- a/dom/base/nsIContent.h
+++ b/dom/base/nsIContent.h
@@ -1032,19 +1032,27 @@ inline nsIContent* nsINode::AsContent()
return static_cast<nsIContent*>(this);
}
#define NS_IMPL_FROMCONTENT_HELPER(_class, _check) \
static _class* FromContent(nsIContent* aContent) \
{ \
return aContent->_check ? static_cast<_class*>(aContent) : nullptr; \
} \
+ static const _class* FromContent(const nsIContent* aContent) \
+ { \
+ return aContent->_check ? static_cast<const _class*>(aContent) : nullptr; \
+ } \
static _class* FromContentOrNull(nsIContent* aContent) \
{ \
return aContent ? FromContent(aContent) : nullptr; \
+ } \
+ static const _class* FromContentOrNull(const nsIContent* aContent) \
+ { \
+ return aContent ? FromContent(aContent) : nullptr; \
}
#define NS_IMPL_FROMCONTENT(_class, _nsid) \
NS_IMPL_FROMCONTENT_HELPER(_class, IsInNamespace(_nsid))
#define NS_IMPL_FROMCONTENT_WITH_TAG(_class, _nsid, _tag) \
NS_IMPL_FROMCONTENT_HELPER(_class, NodeInfo()->Equals(nsGkAtoms::_tag, _nsid))
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -368,17 +368,17 @@ Gecko_GetStyleAttrDeclarationBlock(RawGe
RawServoDeclarationBlockStrongBorrowedOrNull
Gecko_GetHTMLPresentationAttrDeclarationBlock(RawGeckoElementBorrowed aElement)
{
static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
sizeof(RawServoDeclarationBlockStrong),
"RefPtr should just be a pointer");
const nsMappedAttributes* attrs = aElement->GetMappedAttributes();
if (!attrs) {
- auto* svg = nsSVGElement::FromContentOrNull(const_cast<dom::Element*>(aElement));
+ auto* svg = nsSVGElement::FromContentOrNull(aElement);
if (svg) {
if (auto decl = svg->GetContentDeclarationBlock()) {
return decl->AsServo()->RefRawStrong();
}
}
return nullptr;
}