/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * Entry for the Document or ShadowRoot's identifier map.
*/
namespace mozilla { namespace dom { class Document; class Element;
} // namespace dom
/** * Right now our identifier map entries contain information for 'name' * and 'id' mappings of a given string. This is so that * nsHTMLDocument::ResolveName only has to do one hash lookup instead * of two. It's not clear whether this still matters for performance. * * We also store the document.all result list here. This is mainly so that * when all elements with the given ID are removed and we remove * the ID's IdentifierMapEntry, the document.all result is released too. * Perhaps the document.all results should have their own hashtable * in nsHTMLDocument.
*/ class IdentifierMapEntry : public PLDHashEntryHdr { typedef dom::Document Document; typedef dom::Element Element;
/** * @see Document::IDTargetObserver, this is just here to avoid include hell.
*/ typedefbool (*IDTargetObserver)(Element* aOldElement, Element* aNewelement, void* aData);
public: // We use DependentAtomOrString as our external key interface. This allows // consumers to use an nsAString, for example, without forcing a copy. struct DependentAtomOrString final {
MOZ_IMPLICIT DependentAtomOrString(nsAtom* aAtom)
: mAtom(aAtom), mString(nullptr) {}
MOZ_IMPLICIT DependentAtomOrString(const nsAString& aString)
: mAtom(nullptr), mString(&aString) {}
DependentAtomOrString(const DependentAtomOrString& aOther) = default;
/** * Returns the element if we know the element associated with this * id. Otherwise returns null.
*/
Element* GetIdElement() const { return mIdContentList->SafeElementAt(0); }
/** * Returns the list of all elements associated with this id.
*/ const nsTArray<Element*>& GetIdElements() const { return mIdContentList; }
/** * If this entry has a non-null image element set (using SetImageElement), * the image element will be returned, otherwise the same as GetIdElement().
*/
Element* GetImageIdElement() { return mImageElement ? mImageElement.get() : GetIdElement();
}
/** * This can fire ID change callbacks.
*/ void AddIdElement(Element* aElement); /** * This can fire ID change callbacks.
*/ void RemoveIdElement(Element* aElement); /** * Set the image element override for this ID. This will be returned by * GetIdElement(true) if non-null.
*/ void SetImageElement(Element* aElement); bool HasIdElementExposedAsHTMLDocumentProperty() const;
private: // We use an OwningAtomOrString as our internal key storage. It needs to own // the key string, whether in atom or string form. struct OwningAtomOrString final {
OwningAtomOrString(const OwningAtomOrString& aOther) = delete;
OwningAtomOrString(OwningAtomOrString&& aOther) = default;
explicit OwningAtomOrString(const DependentAtomOrString& aOther) // aOther may have a null mString, so jump through a bit of a hoop in // that case. I wish there were a way to just default-initialize // mString in that situation... We could also make mString not const // and only assign to it if aOther.mString is not null, but having it be // const is nice.
: mAtom(aOther.mAtom),
mString(aOther.mString ? *aOther.mString : u""_ns) {}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.