HTML - implement the labels attribute (follow up)

This commit is contained in:
janekptacijarabaci 2017-08-18 13:39:37 +02:00 • committed by Roy Tam
commit b9e802f497
20 changed files with 87 additions and 77 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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)

View file

@ -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;
}

View file

@ -124,8 +124,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;

View file

@ -735,12 +735,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();
}

View file

@ -247,7 +247,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();

View file

@ -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*

View file

@ -1100,31 +1100,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);
}
}
@ -1148,24 +1148,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;
@ -1952,14 +1952,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);
}
@ -2279,10 +2279,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*

View file

@ -261,12 +261,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);