зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 820657 (Implement the NamedGetter functionality on HTMLDocument) - implement GetSupportedNames on HTMLDocument. r=bz.
--HG-- extra : rebase_source : 3d97a79286b3c4ec15f1515219d853e1914d739e
This commit is contained in:
Родитель
0004d681d3
Коммит
14965e0e30
|
@ -134,14 +134,15 @@ public:
|
|||
}
|
||||
~nsIdentifierMapEntry();
|
||||
|
||||
void SetInvalidName();
|
||||
bool IsInvalidName();
|
||||
void AddNameElement(nsIDocument* aDocument, Element* aElement);
|
||||
void RemoveNameElement(Element* aElement);
|
||||
bool IsEmpty();
|
||||
nsBaseContentList* GetNameContentList() {
|
||||
return mNameContentList;
|
||||
}
|
||||
bool HasNameElement() const {
|
||||
return mNameContentList && !mNameContentList->Length() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element if we know the element associated with this
|
||||
|
|
|
@ -717,6 +717,19 @@ public:
|
|||
|
||||
static bool TouchEventsEnabled(JSContext* /* unused */, JSObject* /* unused */);
|
||||
|
||||
static inline bool
|
||||
ShouldExposeIdAsHTMLDocumentProperty(Element* aElement)
|
||||
{
|
||||
if (!aElement->IsHTML()) {
|
||||
return false;
|
||||
}
|
||||
nsIAtom* tag = aElement->Tag();
|
||||
return tag == nsGkAtoms::img ||
|
||||
tag == nsGkAtoms::applet ||
|
||||
tag == nsGkAtoms::embed ||
|
||||
tag == nsGkAtoms::object;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Add/remove this element to the documents name cache
|
||||
|
|
|
@ -2311,15 +2311,9 @@ nsHTMLDocument::ResolveName(const nsAString& aName, nsWrapperCache **aCache)
|
|||
// No named items were found, see if there's one registerd by id for aName.
|
||||
Element *e = entry->GetIdElement();
|
||||
|
||||
if (e && e->IsHTML()) {
|
||||
nsIAtom *tag = e->Tag();
|
||||
if (tag == nsGkAtoms::embed ||
|
||||
tag == nsGkAtoms::img ||
|
||||
tag == nsGkAtoms::object ||
|
||||
tag == nsGkAtoms::applet) {
|
||||
*aCache = e;
|
||||
return e;
|
||||
}
|
||||
if (e && nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(e)) {
|
||||
*aCache = e;
|
||||
return e;
|
||||
}
|
||||
|
||||
*aCache = nullptr;
|
||||
|
@ -2385,10 +2379,23 @@ nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
|
|||
return &val.toObject();
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
IdentifierMapEntryAddNames(nsIdentifierMapEntry* aEntry, void* aArg)
|
||||
{
|
||||
nsTArray<nsString>* aNames = static_cast<nsTArray<nsString>*>(aArg);
|
||||
Element* idElement;
|
||||
if (aEntry->HasNameElement() ||
|
||||
((idElement = aEntry->GetIdElement()) &&
|
||||
nsGenericHTMLElement::ShouldExposeIdAsHTMLDocumentProperty(idElement))) {
|
||||
aNames->AppendElement(aEntry->GetKey());
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLDocument::GetSupportedNames(nsTArray<nsString>& aNames)
|
||||
{
|
||||
// Nothing, for now. We should fix that.
|
||||
mIdentifierMap.EnumerateEntries(IdentifierMapEntryAddNames, &aNames);
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче