Bug 1319255 part 2. Stop doing casts to HTMLContentElement* simply based on tag. r=wchen

This commit is contained in:
Boris Zbarsky 2016-11-22 22:41:51 -05:00
parent 3e49872974
commit 23cc88e459
7 changed files with 29 additions and 17 deletions

View File

@ -60,7 +60,7 @@ GetMatchedNodesForPoint(nsIContent* aContent)
// Web components case // Web components case
MOZ_ASSERT(aContent->IsHTMLElement(nsGkAtoms::content)); MOZ_ASSERT(aContent->IsHTMLElement(nsGkAtoms::content));
return MatchedNodes(static_cast<HTMLContentElement*>(aContent)); return MatchedNodes(HTMLContentElement::FromContent(aContent));
} }
nsIContent* nsIContent*

View File

@ -595,10 +595,11 @@ ShadowRoot::IsPooledNode(nsIContent* aContent, nsIContent* aContainer,
return true; return true;
} }
if (aContainer && aContainer->IsHTMLElement(nsGkAtoms::content)) { if (aContainer) {
// Fallback content will end up in pool if its parent is a child of the host. // Fallback content will end up in pool if its parent is a child of the host.
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer); HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
return content->IsInsertionPoint() && content->MatchedNodes().IsEmpty() && return content && content->IsInsertionPoint() &&
content->MatchedNodes().IsEmpty() &&
aContainer->GetParentNode() == aHost; aContainer->GetParentNode() == aHost;
} }
@ -640,7 +641,7 @@ ShadowRoot::ContentAppended(nsIDocument* aDocument,
while (currentChild) { while (currentChild) {
// Add insertion point to destination insertion points of fallback content. // Add insertion point to destination insertion points of fallback content.
if (nsContentUtils::IsContentInsertionPoint(aContainer)) { if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer); HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
if (content->MatchedNodes().IsEmpty()) { if (content->MatchedNodes().IsEmpty()) {
currentChild->DestInsertionPoints().AppendElement(aContainer); currentChild->DestInsertionPoints().AppendElement(aContainer);
} }
@ -671,7 +672,7 @@ ShadowRoot::ContentInserted(nsIDocument* aDocument,
if (IsPooledNode(aChild, aContainer, mPoolHost)) { if (IsPooledNode(aChild, aContainer, mPoolHost)) {
// Add insertion point to destination insertion points of fallback content. // Add insertion point to destination insertion points of fallback content.
if (nsContentUtils::IsContentInsertionPoint(aContainer)) { if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer); HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
if (content->MatchedNodes().IsEmpty()) { if (content->MatchedNodes().IsEmpty()) {
aChild->DestInsertionPoints().AppendElement(aContainer); aChild->DestInsertionPoints().AppendElement(aContainer);
} }
@ -697,7 +698,7 @@ ShadowRoot::ContentRemoved(nsIDocument* aDocument,
// Clear destination insertion points for removed // Clear destination insertion points for removed
// fallback content. // fallback content.
if (nsContentUtils::IsContentInsertionPoint(aContainer)) { if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer); HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
if (content->MatchedNodes().IsEmpty()) { if (content->MatchedNodes().IsEmpty()) {
aChild->DestInsertionPoints().Clear(); aChild->DestInsertionPoints().Clear();
} }

View File

@ -7063,7 +7063,7 @@ nsContentUtils::GetHTMLEditor(nsPresContext* aPresContext)
} }
bool bool
nsContentUtils::IsContentInsertionPoint(const nsIContent* aContent) nsContentUtils::IsContentInsertionPoint(nsIContent* aContent)
{ {
// Check if the content is a XBL insertion point. // Check if the content is a XBL insertion point.
if (aContent->IsActiveChildrenElement()) { if (aContent->IsActiveChildrenElement()) {
@ -7071,11 +7071,9 @@ nsContentUtils::IsContentInsertionPoint(const nsIContent* aContent)
} }
// Check if the content is a web components content insertion point. // Check if the content is a web components content insertion point.
if (aContent->IsHTMLElement(nsGkAtoms::content)) { HTMLContentElement* contentElement =
return static_cast<const HTMLContentElement*>(aContent)->IsInsertionPoint(); HTMLContentElement::FromContent(aContent);
} return contentElement && contentElement->IsInsertionPoint();
return false;
} }
// static // static

View File

@ -2412,7 +2412,7 @@ public:
* *
* @param aContent The content to test for being an insertion point. * @param aContent The content to test for being an insertion point.
*/ */
static bool IsContentInsertionPoint(const nsIContent* aContent); static bool IsContentInsertionPoint(nsIContent* aContent);
/** /**

View File

@ -1329,6 +1329,10 @@ public:
// a way to ask an element whether it's an HTMLShadowElement. // a way to ask an element whether it's an HTMLShadowElement.
virtual bool IsHTMLShadowElement() const { return false; } virtual bool IsHTMLShadowElement() const { return false; }
// Elements named <content> may or may not be HTMLContentElement. This is a
// way to ask an element whether it's an HTMLContentElement.
virtual bool IsHTMLContentElement() const { return false; }
protected: protected:
nsIURI* GetExplicitBaseURI() const { nsIURI* GetExplicitBaseURI() const {
if (HasExplicitBaseURI()) { if (HasExplicitBaseURI()) {

View File

@ -66,7 +66,7 @@ HTMLContentElement::BindToTree(nsIDocument* aDocument,
if (containingShadow && !oldContainingShadow) { if (containingShadow && !oldContainingShadow) {
nsINode* parentNode = nsINode::GetParentNode(); nsINode* parentNode = nsINode::GetParentNode();
while (parentNode && parentNode != containingShadow) { while (parentNode && parentNode != containingShadow) {
if (parentNode->IsHTMLElement(nsGkAtoms::content)) { if (parentNode->IsHTMLContentElement()) {
// Content element in fallback content is not an insertion point. // Content element in fallback content is not an insertion point.
return NS_OK; return NS_OK;
} }

View File

@ -23,14 +23,23 @@ class HTMLContentElement final : public nsGenericHTMLElement
public: public:
explicit HTMLContentElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo); explicit HTMLContentElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLContentElement, content)
// nsISupports // nsISupports
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentElement, NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentElement,
nsGenericHTMLElement) nsGenericHTMLElement)
static HTMLContentElement* FromContent(nsIContent* aContent)
{
if (aContent->IsHTMLContentElement()) {
return static_cast<HTMLContentElement*>(aContent);
}
return nullptr;
}
virtual bool IsHTMLContentElement() const override { return true; }
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
virtual nsIDOMNode* AsDOMNode() override { return this; } virtual nsIDOMNode* AsDOMNode() override { return this; }