Bug 1338725 part 1. Change the matcher functions used for nsContentList to take an Element argument, not nsIContent. r=baku
This commit is contained in:
@@ -18,6 +18,12 @@ class nsINode;
|
||||
class nsString;
|
||||
class nsAString;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class Element;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
// Magic namespace id that means "match all namespaces". This is
|
||||
// negative so it won't collide with actual namespace constants.
|
||||
#define kNameSpaceID_Wildcard INT32_MIN
|
||||
@@ -26,7 +32,7 @@ class nsAString;
|
||||
// arbitrary matching algorithm. aContent is the content that may
|
||||
// match the list, while aNamespaceID, aAtom, and aData are whatever
|
||||
// was passed to the list's constructor.
|
||||
typedef bool (*nsContentListMatchFunc)(nsIContent* aContent,
|
||||
typedef bool (*nsContentListMatchFunc)(mozilla::dom::Element* aElement,
|
||||
int32_t aNamespaceID,
|
||||
nsIAtom* aAtom,
|
||||
void* aData);
|
||||
|
||||
@@ -6349,11 +6349,11 @@ struct ClassMatchingInfo {
|
||||
|
||||
// static
|
||||
bool
|
||||
nsContentUtils::MatchClassNames(nsIContent* aContent, int32_t aNamespaceID,
|
||||
nsContentUtils::MatchClassNames(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
// We can't match if there are no class names
|
||||
const nsAttrValue* classAttr = aContent->GetClasses();
|
||||
const nsAttrValue* classAttr = aElement->GetClasses();
|
||||
if (!classAttr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2827,7 +2827,8 @@ private:
|
||||
|
||||
static void DropFragmentParsers();
|
||||
|
||||
static bool MatchClassNames(nsIContent* aContent, int32_t aNamespaceID,
|
||||
static bool MatchClassNames(mozilla::dom::Element* aElement,
|
||||
int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static void DestroyClassNameArray(void* aData);
|
||||
static void* AllocClassMatchingInfo(nsINode* aRootNode,
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "mozilla/dom/HTMLAllCollectionBinding.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsHTMLDocument.h"
|
||||
|
||||
namespace mozilla {
|
||||
@@ -86,14 +87,14 @@ IsAllNamedElement(nsIContent* aContent)
|
||||
}
|
||||
|
||||
static bool
|
||||
DocAllResultMatch(nsIContent* aContent, int32_t aNamespaceID, nsIAtom* aAtom,
|
||||
DocAllResultMatch(Element* aElement, int32_t aNamespaceID, nsIAtom* aAtom,
|
||||
void* aData)
|
||||
{
|
||||
if (aContent->GetID() == aAtom) {
|
||||
if (aElement->GetID() == aAtom) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
|
||||
nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aElement);
|
||||
if (!elm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLDataListElement)
|
||||
|
||||
bool
|
||||
HTMLDataListElement::MatchOptions(nsIContent* aContent, int32_t aNamespaceID,
|
||||
HTMLDataListElement::MatchOptions(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
return aContent->NodeInfo()->Equals(nsGkAtoms::option, kNameSpaceID_XHTML) &&
|
||||
!aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
|
||||
return aElement->NodeInfo()->Equals(nsGkAtoms::option, kNameSpaceID_XHTML) &&
|
||||
!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
||||
@@ -37,8 +37,8 @@ public:
|
||||
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
|
||||
|
||||
// This function is used to generate the nsContentList (option elements).
|
||||
static bool MatchOptions(nsIContent* aContent, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static bool MatchOptions(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLDataListElement,
|
||||
nsGenericHTMLElement)
|
||||
|
||||
@@ -120,10 +120,10 @@ HTMLFieldSetElement::GetType(nsAString& aType)
|
||||
|
||||
/* static */
|
||||
bool
|
||||
HTMLFieldSetElement::MatchListedElements(nsIContent* aContent, int32_t aNamespaceID,
|
||||
HTMLFieldSetElement::MatchListedElements(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aContent);
|
||||
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aElement);
|
||||
return formControl;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,8 +125,8 @@ private:
|
||||
void NotifyElementsForFirstLegendChange(bool aNotify);
|
||||
|
||||
// This function is used to generate the nsContentList (listed form elements).
|
||||
static bool MatchListedElements(nsIContent* aContent, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static bool MatchListedElements(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
|
||||
// listed form controls elements.
|
||||
RefPtr<nsContentList> mElements;
|
||||
|
||||
@@ -748,12 +748,12 @@ HTMLSelectElement::SetLength(uint32_t aLength, ErrorResult& aRv)
|
||||
|
||||
/* static */
|
||||
bool
|
||||
HTMLSelectElement::MatchSelectedOptions(nsIContent* aContent,
|
||||
HTMLSelectElement::MatchSelectedOptions(Element* aElement,
|
||||
int32_t /* unused */,
|
||||
nsIAtom* /* unused */,
|
||||
void* /* unused*/)
|
||||
{
|
||||
HTMLOptionElement* option = HTMLOptionElement::FromContent(aContent);
|
||||
HTMLOptionElement* option = HTMLOptionElement::FromContent(aElement);
|
||||
return option && option->Selected();
|
||||
}
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ public:
|
||||
mOptions->IndexedSetter(aIndex, aOption, aRv);
|
||||
}
|
||||
|
||||
static bool MatchSelectedOptions(nsIContent* aContent, int32_t, nsIAtom*,
|
||||
static bool MatchSelectedOptions(Element* aElement, int32_t, nsIAtom*,
|
||||
void*);
|
||||
|
||||
nsIHTMLCollection* SelectedOptions();
|
||||
|
||||
@@ -120,10 +120,10 @@ HTMLTableRowElement::SectionRowIndex() const
|
||||
}
|
||||
|
||||
static bool
|
||||
IsCell(nsIContent *aContent, int32_t aNamespaceID,
|
||||
IsCell(Element *aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void *aData)
|
||||
{
|
||||
return aContent->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th);
|
||||
return aElement->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th);
|
||||
}
|
||||
|
||||
nsIHTMLCollection*
|
||||
|
||||
@@ -1105,31 +1105,31 @@ nsHTMLDocument::Applets()
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLDocument::MatchLinks(nsIContent *aContent, int32_t aNamespaceID,
|
||||
nsHTMLDocument::MatchLinks(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
nsIDocument* doc = aContent->GetUncomposedDoc();
|
||||
nsIDocument* doc = aElement->GetUncomposedDoc();
|
||||
|
||||
if (doc) {
|
||||
NS_ASSERTION(aContent->IsInUncomposedDoc(),
|
||||
NS_ASSERTION(aElement->IsInUncomposedDoc(),
|
||||
"This method should never be called on content nodes that "
|
||||
"are not in a document!");
|
||||
#ifdef DEBUG
|
||||
{
|
||||
nsCOMPtr<nsIHTMLDocument> htmldoc =
|
||||
do_QueryInterface(aContent->GetUncomposedDoc());
|
||||
do_QueryInterface(aElement->GetUncomposedDoc());
|
||||
NS_ASSERTION(htmldoc,
|
||||
"Huh, how did this happen? This should only be used with "
|
||||
"HTML documents!");
|
||||
}
|
||||
#endif
|
||||
|
||||
mozilla::dom::NodeInfo *ni = aContent->NodeInfo();
|
||||
mozilla::dom::NodeInfo *ni = aElement->NodeInfo();
|
||||
|
||||
nsIAtom *localName = ni->NameAtom();
|
||||
if (ni->NamespaceID() == kNameSpaceID_XHTML &&
|
||||
(localName == nsGkAtoms::a || localName == nsGkAtoms::area)) {
|
||||
return aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::href);
|
||||
return aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::href);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1153,24 +1153,24 @@ nsHTMLDocument::Links()
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLDocument::MatchAnchors(nsIContent *aContent, int32_t aNamespaceID,
|
||||
nsHTMLDocument::MatchAnchors(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
NS_ASSERTION(aContent->IsInUncomposedDoc(),
|
||||
NS_ASSERTION(aElement->IsInUncomposedDoc(),
|
||||
"This method should never be called on content nodes that "
|
||||
"are not in a document!");
|
||||
#ifdef DEBUG
|
||||
{
|
||||
nsCOMPtr<nsIHTMLDocument> htmldoc =
|
||||
do_QueryInterface(aContent->GetUncomposedDoc());
|
||||
do_QueryInterface(aElement->GetUncomposedDoc());
|
||||
NS_ASSERTION(htmldoc,
|
||||
"Huh, how did this happen? This should only be used with "
|
||||
"HTML documents!");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aContent->NodeInfo()->Equals(nsGkAtoms::a, kNameSpaceID_XHTML)) {
|
||||
return aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::name);
|
||||
if (aElement->IsHTMLElement(nsGkAtoms::a)) {
|
||||
return aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::name);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1947,14 +1947,14 @@ nsHTMLDocument::Writeln(JSContext* cx, const Sequence<nsString>& aText,
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID,
|
||||
nsHTMLDocument::MatchNameAttribute(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
NS_PRECONDITION(aContent, "Must have content node to work with!");
|
||||
NS_PRECONDITION(aElement, "Must have element to work with!");
|
||||
nsString* elementName = static_cast<nsString*>(aData);
|
||||
return
|
||||
aContent->GetNameSpaceID() == kNameSpaceID_XHTML &&
|
||||
aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
||||
aElement->GetNameSpaceID() == kNameSpaceID_XHTML &&
|
||||
aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
||||
*elementName, eCaseMatters);
|
||||
}
|
||||
|
||||
@@ -2274,10 +2274,10 @@ nsHTMLDocument::GetForms()
|
||||
return mForms;
|
||||
}
|
||||
|
||||
static bool MatchFormControls(nsIContent* aContent, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
static bool MatchFormControls(Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData)
|
||||
{
|
||||
return aContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL);
|
||||
return aElement->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL);
|
||||
}
|
||||
|
||||
nsContentList*
|
||||
|
||||
@@ -260,12 +260,13 @@ protected:
|
||||
|
||||
nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
|
||||
|
||||
static bool MatchLinks(nsIContent *aContent, int32_t aNamespaceID,
|
||||
static bool MatchLinks(mozilla::dom::Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static bool MatchAnchors(mozilla::dom::Element* aElement, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static bool MatchAnchors(nsIContent *aContent, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static bool MatchNameAttribute(nsIContent* aContent, int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static bool MatchNameAttribute(mozilla::dom::Element* aElement,
|
||||
int32_t aNamespaceID,
|
||||
nsIAtom* aAtom, void* aData);
|
||||
static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
|
||||
|
||||
static void DocumentWriteTerminationFunc(nsISupports *aRef);
|
||||
|
||||
@@ -1932,26 +1932,26 @@ XULDocument::StartLayout(void)
|
||||
|
||||
/* static */
|
||||
bool
|
||||
XULDocument::MatchAttribute(nsIContent* aContent,
|
||||
XULDocument::MatchAttribute(Element* aElement,
|
||||
int32_t aNamespaceID,
|
||||
nsIAtom* aAttrName,
|
||||
void* aData)
|
||||
{
|
||||
NS_PRECONDITION(aContent, "Must have content node to work with!");
|
||||
NS_PRECONDITION(aElement, "Must have content node to work with!");
|
||||
nsString* attrValue = static_cast<nsString*>(aData);
|
||||
if (aNamespaceID != kNameSpaceID_Unknown &&
|
||||
aNamespaceID != kNameSpaceID_Wildcard) {
|
||||
return attrValue->EqualsLiteral("*") ?
|
||||
aContent->HasAttr(aNamespaceID, aAttrName) :
|
||||
aContent->AttrValueIs(aNamespaceID, aAttrName, *attrValue,
|
||||
aElement->HasAttr(aNamespaceID, aAttrName) :
|
||||
aElement->AttrValueIs(aNamespaceID, aAttrName, *attrValue,
|
||||
eCaseMatters);
|
||||
}
|
||||
|
||||
// Qualified name match. This takes more work.
|
||||
|
||||
uint32_t count = aContent->GetAttrCount();
|
||||
uint32_t count = aElement->GetAttrCount();
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
const nsAttrName* name = aContent->GetAttrNameAt(i);
|
||||
const nsAttrName* name = aElement->GetAttrNameAt(i);
|
||||
bool nameMatch;
|
||||
if (name->IsAtom()) {
|
||||
nameMatch = name->Atom() == aAttrName;
|
||||
@@ -1963,7 +1963,7 @@ XULDocument::MatchAttribute(nsIContent* aContent,
|
||||
|
||||
if (nameMatch) {
|
||||
return attrValue->EqualsLiteral("*") ||
|
||||
aContent->AttrValueIs(name->NamespaceID(), name->LocalName(),
|
||||
aElement->AttrValueIs(name->NamespaceID(), name->LocalName(),
|
||||
*attrValue, eCaseMatters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public:
|
||||
NS_IMETHOD OnScriptCompileComplete(JSScript* aScript, nsresult aStatus) override;
|
||||
|
||||
static bool
|
||||
MatchAttribute(nsIContent* aContent,
|
||||
MatchAttribute(Element* aContent,
|
||||
int32_t aNameSpaceID,
|
||||
nsIAtom* aAttrName,
|
||||
void* aData);
|
||||
|
||||
Reference in New Issue
Block a user