From 8ae2b45691511022d9efc4dd1ac4bea953521e7b Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 25 Apr 2025 20:29:05 +0200 Subject: [PATCH] Issue #2732 - Part 3: Explicitly search for only. Relying on the implicit conversion by `::FromContent` doesn't work for us because we inherit that from `nsGenericHTMLElement` and isn't specific to `HTMLAreaElement`, so it would accept other elements. This also updates the Attribute changed event handler to exclude `` elements and cleans up an unused variable from the old code. --- layout/generic/nsImageMap.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/layout/generic/nsImageMap.cpp b/layout/generic/nsImageMap.cpp index 8f306ccba8..6208c56888 100644 --- a/layout/generic/nsImageMap.cpp +++ b/layout/generic/nsImageMap.cpp @@ -751,16 +751,15 @@ nsImageMap::Init(nsImageFrame* aImageFrame, nsIContent* aMap) void nsImageMap::SearchForAreas(nsIContent* aParent) { - uint32_t n = aParent->GetChildCount(); - // Look for elements. for (nsIContent* child = aParent->GetFirstChild(); child; child = child->GetNextSibling()) { - if (auto* area = static_cast(HTMLAreaElement::FromContent(child))) { + if (child->IsHTMLElement(nsGkAtoms::area)) { + HTMLAreaElement* area = static_cast(HTMLAreaElement::FromContent(child)); AddArea(area); - // Continue to next child. This stops mConsiderWholeSubtree from + // Continue to next sibling. This stops mConsiderWholeSubtree from // getting set. It also makes us ignore children of s which // is consistent with how we react to dynamic insertion of such // children. @@ -895,11 +894,10 @@ nsImageMap::AttributeChanged(nsIDocument* aDocument, const nsAttrValue* aOldValue) { // If the parent of the changing content node is our map then update - // the map. But only do this if the node is an HTML or + // the map. But only do this if the node is an HTML // and the attribute that's changing is "shape" or "coords" -- those // are the only cases we care about. - if ((aElement->NodeInfo()->Equals(nsGkAtoms::area) || - aElement->NodeInfo()->Equals(nsGkAtoms::a)) && + if (aElement->NodeInfo()->Equals(nsGkAtoms::area) && aElement->IsHTMLElement() && aNameSpaceID == kNameSpaceID_None && (aAttribute == nsGkAtoms::shape ||