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
MOZ_ASSERT(aContent->IsHTMLElement(nsGkAtoms::content));
return MatchedNodes(static_cast<HTMLContentElement*>(aContent));
return MatchedNodes(HTMLContentElement::FromContent(aContent));
}
nsIContent*

View File

@ -595,10 +595,11 @@ ShadowRoot::IsPooledNode(nsIContent* aContent, nsIContent* aContainer,
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.
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
return content->IsInsertionPoint() && content->MatchedNodes().IsEmpty() &&
HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
return content && content->IsInsertionPoint() &&
content->MatchedNodes().IsEmpty() &&
aContainer->GetParentNode() == aHost;
}
@ -640,7 +641,7 @@ ShadowRoot::ContentAppended(nsIDocument* aDocument,
while (currentChild) {
// Add insertion point to destination insertion points of fallback content.
if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
if (content->MatchedNodes().IsEmpty()) {
currentChild->DestInsertionPoints().AppendElement(aContainer);
}
@ -671,7 +672,7 @@ ShadowRoot::ContentInserted(nsIDocument* aDocument,
if (IsPooledNode(aChild, aContainer, mPoolHost)) {
// Add insertion point to destination insertion points of fallback content.
if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
if (content->MatchedNodes().IsEmpty()) {
aChild->DestInsertionPoints().AppendElement(aContainer);
}
@ -697,7 +698,7 @@ ShadowRoot::ContentRemoved(nsIDocument* aDocument,
// Clear destination insertion points for removed
// fallback content.
if (nsContentUtils::IsContentInsertionPoint(aContainer)) {
HTMLContentElement* content = static_cast<HTMLContentElement*>(aContainer);
HTMLContentElement* content = HTMLContentElement::FromContent(aContainer);
if (content->MatchedNodes().IsEmpty()) {
aChild->DestInsertionPoints().Clear();
}

View File

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

View File

@ -2412,7 +2412,7 @@ public:
*
* @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.
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:
nsIURI* GetExplicitBaseURI() const {
if (HasExplicitBaseURI()) {

View File

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

View File

@ -23,14 +23,23 @@ class HTMLContentElement final : public nsGenericHTMLElement
public:
explicit HTMLContentElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLContentElement, content)
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentElement,
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 nsIDOMNode* AsDOMNode() override { return this; }