Bug 1376695 - Part 1: Let ElementHasName flag be applied to all nodes. r=ehsan

We'd like to use HasName() to know whether a node has a name attribute, but now
it's only applied to elements that CanHaveName(), hence we change it so that
it's applied to all nodes. Therefore, when document named items related
functions wants to use HasName() now, it must also check CanHaveName().

MozReview-Commit-ID: 2i5hfjnxXIF
This commit is contained in:
Jessica Jong 2017-07-26 02:33:00 -04:00
Родитель 3781656f2d
Коммит 490097db70
2 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -487,7 +487,7 @@ nsGenericHTMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
if (aDocument) {
RegAccessKey();
if (HasName()) {
if (CanHaveName(NodeInfo()->NameAtom()) && HasName()) {
aDocument->
AddToNameTable(this, GetParsedAttr(nsGkAtoms::name)->GetAtomValue());
}
@ -776,15 +776,16 @@ nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
RegAccessKey();
}
} else if (aName == nsGkAtoms::name) {
if (aValue && !aValue->Equals(EmptyString(), eIgnoreCase) &&
CanHaveName(NodeInfo()->NameAtom())) {
if (aValue && !aValue->Equals(EmptyString(), eIgnoreCase)) {
// This may not be quite right because we can have subclass code run
// before here. But in practice subclasses don't care about this flag,
// and in particular selector matching does not care. Otherwise we'd
// want to handle it like we handle id attributes (in PreIdMaybeChange
// and PostIdMaybeChange).
SetHasName();
AddToNameTable(aValue->GetAtomValue());
if (CanHaveName(NodeInfo()->NameAtom())) {
AddToNameTable(aValue->GetAtomValue());
}
}
}
}

Просмотреть файл

@ -733,7 +733,7 @@ protected:
}
}
void RemoveFromNameTable() {
if (HasName()) {
if (CanHaveName(NodeInfo()->NameAtom()) && HasName()) {
nsIDocument* doc = GetUncomposedDoc();
if (doc) {
doc->RemoveFromNameTable(this, GetParsedAttr(nsGkAtoms::name)->