Bug 1426525 part 1. Remove XULDocument's mRefMap member, since there should be no XUL elements with 'ref' attributes anymore. r=smaug

'ref' used to be used for templates, but those are gone as of bug 1425356 being
fixed.

MozReview-Commit-ID: GerfZrckypp
This commit is contained in:
Boris Zbarsky 2018-01-05 13:48:38 -05:00
Родитель c83ae3a2c6
Коммит bde68b50e6
3 изменённых файлов: 3 добавлений и 171 удалений

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

@ -6,7 +6,6 @@
#include "DocumentOrShadowRoot.h"
#include "mozilla/dom/StyleSheetList.h"
#include "XULDocument.h"
namespace mozilla {
namespace dom {
@ -44,11 +43,6 @@ DocumentOrShadowRoot::GetElementById(const nsAString& aElementId)
}
}
if (MOZ_UNLIKELY(mKind == Kind::Document &&
static_cast<nsIDocument&>(AsNode()).IsXULDocument())) {
return static_cast<XULDocument&>(AsNode()).GetRefById(aElementId);
}
return nullptr;
}

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

@ -149,36 +149,6 @@ struct BroadcasterMapEntry : public PLDHashEntryHdr
nsTArray<BroadcastListener*> mListeners; // [OWNING] of BroadcastListener objects
};
Element*
nsRefMapEntry::GetFirstElement()
{
return mRefContentList.SafeElementAt(0);
}
void
nsRefMapEntry::AppendAll(nsCOMArray<Element>* aElements)
{
for (size_t i = 0; i < mRefContentList.Length(); ++i) {
aElements->AppendObject(mRefContentList[i]);
}
}
bool
nsRefMapEntry::AddElement(Element* aElement)
{
if (mRefContentList.Contains(aElement)) {
return true;
}
return mRefContentList.AppendElement(aElement);
}
bool
nsRefMapEntry::RemoveElement(Element* aElement)
{
mRefContentList.RemoveElement(aElement);
return mRefContentList.IsEmpty();
}
//----------------------------------------------------------------------
//
// ctors & dtors
@ -891,24 +861,6 @@ XULDocument::ExecuteOnBroadcastHandlerFor(Element* aBroadcaster,
return NS_OK;
}
void
XULDocument::AttributeWillChange(nsIDocument* aDocument,
Element* aElement, int32_t aNameSpaceID,
nsAtom* aAttribute, int32_t aModType,
const nsAttrValue* aNewValue)
{
MOZ_ASSERT(aElement, "Null content!");
NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
// XXXbz check aNameSpaceID, dammit!
// See if we need to update our ref map.
if (aAttribute == nsGkAtoms::ref) {
// Might not need this, but be safe for now.
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
RemoveElementFromRefMap(aElement);
}
}
static bool
ShouldPersistAttribute(Element* aElement, nsAtom* aAttribute)
{
@ -942,12 +894,6 @@ XULDocument::AttributeChanged(nsIDocument* aDocument,
// Might not need this, but be safe for now.
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
// XXXbz check aNameSpaceID, dammit!
// See if we need to update our ref map.
if (aAttribute == nsGkAtoms::ref) {
AddElementToRefMap(aElement);
}
// Synchronize broadcast listeners
if (mBroadcasterMap &&
CanBroadcast(aNameSpaceID, aAttribute)) {
@ -1085,10 +1031,6 @@ XULDocument::GetElementsForID(const nsAString& aID,
if (entry) {
entry->AppendAllIdContent(&aElements);
}
nsRefMapEntry *refEntry = mRefMap.GetEntry(aID);
if (refEntry) {
refEntry->AppendAll(&aElements);
}
}
nsresult
@ -1577,17 +1519,6 @@ XULDocument::GetCommandDispatcher(nsIDOMXULCommandDispatcher** aTracker)
return NS_OK;
}
Element*
XULDocument::GetRefById(const nsAString& aID)
{
if (nsRefMapEntry* refEntry = mRefMap.GetEntry(aID)) {
MOZ_ASSERT(refEntry->GetFirstElement());
return refEntry->GetFirstElement();
}
return nullptr;
}
nsresult
XULDocument::AddElementToDocumentPre(Element* aElement)
{
@ -1595,17 +1526,14 @@ XULDocument::AddElementToDocumentPre(Element* aElement)
// to the XUL Document.
nsresult rv;
// 1. Add the element to the resource-to-element map. Also add it to
// the id map, since it seems this can be called when creating
// elements from prototypes.
// 1. Add the element to the id map, since it seems this can be
// called when creating elements from prototypes.
nsAtom* id = aElement->GetID();
if (id) {
// FIXME: Shouldn't BindToTree take care of this?
nsAutoScriptBlocker scriptBlocker;
AddToIdTable(aElement, id);
}
rv = AddElementToRefMap(aElement);
if (NS_FAILED(rv)) return rv;
// 2. If the element is a 'command updater' (i.e., has a
// "commandupdater='true'" attribute), then add the element to the
@ -1706,10 +1634,8 @@ XULDocument::RemoveSubtreeFromDocument(nsIContent* aContent)
return rv;
}
// 2. Remove the element from the resource-to-element map.
// Also remove it from the id map, since we added it in
// Remove the element from the id map, since we added it in
// AddElementToDocumentPre().
RemoveElementFromRefMap(aElement);
nsAtom* id = aElement->GetID();
if (id) {
// FIXME: Shouldn't UnbindFromTree take care of this?
@ -1743,46 +1669,6 @@ XULDocument::RemoveSubtreeFromDocument(nsIContent* aContent)
return NS_OK;
}
static void
GetRefMapAttribute(Element* aElement, nsAutoString* aValue)
{
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::ref, *aValue);
}
nsresult
XULDocument::AddElementToRefMap(Element* aElement)
{
// Look at the element's 'ref' attribute, and if set,
// add an entry in the resource-to-element map to the element.
nsAutoString value;
GetRefMapAttribute(aElement, &value);
if (!value.IsEmpty()) {
nsRefMapEntry *entry = mRefMap.PutEntry(value);
if (!entry)
return NS_ERROR_OUT_OF_MEMORY;
if (!entry->AddElement(aElement))
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
void
XULDocument::RemoveElementFromRefMap(Element* aElement)
{
// Remove the element from the resource-to-element map.
nsAutoString value;
GetRefMapAttribute(aElement, &value);
if (!value.IsEmpty()) {
nsRefMapEntry *entry = mRefMap.GetEntry(value);
if (!entry)
return;
if (entry->RemoveElement(aElement)) {
mRefMap.RemoveEntry(entry);
}
}
}
//----------------------------------------------------------------------
//
// nsIDOMNode interface
@ -2238,9 +2124,6 @@ XULDocument::PrepareToWalk()
rv = AppendChildTo(root, false);
if (NS_FAILED(rv)) return rv;
rv = AddElementToRefMap(root);
if (NS_FAILED(rv)) return rv;
// Block onload until we've finished building the complete
// document content model.
BlockOnload();

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

@ -46,39 +46,6 @@ class nsIObjectOutputStream;
#include "nsURIHashKey.h"
#include "nsInterfaceHashtable.h"
class nsRefMapEntry : public nsStringHashKey
{
public:
explicit nsRefMapEntry(const nsAString& aKey) :
nsStringHashKey(&aKey)
{
}
explicit nsRefMapEntry(const nsAString* aKey) :
nsStringHashKey(aKey)
{
}
nsRefMapEntry(const nsRefMapEntry& aOther) :
nsStringHashKey(&aOther.GetKey())
{
NS_ERROR("Should never be called");
}
mozilla::dom::Element* GetFirstElement();
void AppendAll(nsCOMArray<mozilla::dom::Element>* aElements);
/**
* @return true if aElement was added, false if we failed due to OOM
*/
bool AddElement(mozilla::dom::Element* aElement);
/**
* @return true if aElement was removed and it was the last content for
* this ref, so this entry should be removed from the map
*/
bool RemoveElement(mozilla::dom::Element* aElement);
private:
nsTArray<mozilla::dom::Element*> mRefContentList;
};
/**
* The XUL document class
*/
@ -122,7 +89,6 @@ public:
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
// nsIXULDocument interface
virtual void GetElementsForID(const nsAString& aID,
@ -153,9 +119,6 @@ public:
using nsDocument::MozSetImageElement;
using nsIDocument::GetLocation;
// Helper for StyleScope::GetElementById.
Element* GetRefById(const nsAString & elementId);
// nsIDOMXULDocument interface
NS_DECL_NSIDOMXULDOCUMENT
@ -233,11 +196,6 @@ protected:
nsresult Init(void) override;
nsresult StartLayout(void);
nsresult
AddElementToRefMap(Element* aElement);
void
RemoveElementFromRefMap(Element* aElement);
nsresult GetViewportSize(int32_t* aWidth, int32_t* aHeight);
nsresult PrepareToLoad(nsISupports* aContainer,
@ -318,9 +276,6 @@ protected:
XULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr
// Tracks elements with a 'ref' attribute, or an 'id' attribute where
// the element's namespace has no registered ID attribute name.
nsTHashtable<nsRefMapEntry> mRefMap;
nsCOMPtr<nsIXULStore> mLocalStore;
bool mApplyingPersistedAttrs;
bool mIsWritingFastLoad;