mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-04 16:15:25 +00:00
01583602a9
The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
224 lines
6.3 KiB
C++
224 lines
6.3 KiB
C++
/* -*- 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/. */
|
|
|
|
#ifndef HTMLPropertiesCollection_h_
|
|
#define HTMLPropertiesCollection_h_
|
|
|
|
#include "mozilla/Attributes.h"
|
|
#include "mozilla/dom/DOMStringList.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nsCOMArray.h"
|
|
#include "nsIMutationObserver.h"
|
|
#include "nsStubMutationObserver.h"
|
|
#include "nsBaseHashtable.h"
|
|
#include "nsINodeList.h"
|
|
#include "nsIHTMLCollection.h"
|
|
#include "nsHashKeys.h"
|
|
#include "nsRefPtrHashtable.h"
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
class nsIDocument;
|
|
class nsINode;
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
class HTMLPropertiesCollection;
|
|
class PropertyNodeList;
|
|
class Element;
|
|
|
|
class PropertyStringList : public DOMStringList
|
|
{
|
|
public:
|
|
explicit PropertyStringList(HTMLPropertiesCollection* aCollection);
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PropertyStringList, DOMStringList)
|
|
|
|
bool ContainsInternal(const nsAString& aString);
|
|
|
|
protected:
|
|
virtual ~PropertyStringList();
|
|
|
|
virtual void EnsureFresh() override;
|
|
|
|
RefPtr<HTMLPropertiesCollection> mCollection;
|
|
};
|
|
|
|
class HTMLPropertiesCollection final : public nsIHTMLCollection,
|
|
public nsStubMutationObserver,
|
|
public nsWrapperCache
|
|
{
|
|
friend class PropertyNodeList;
|
|
friend class PropertyStringList;
|
|
public:
|
|
explicit HTMLPropertiesCollection(nsGenericHTMLElement* aRoot);
|
|
|
|
// nsWrapperCache
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
|
using nsWrapperCache::GetWrapper;
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
protected:
|
|
virtual ~HTMLPropertiesCollection();
|
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
|
{
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
}
|
|
public:
|
|
|
|
virtual Element* GetElementAt(uint32_t aIndex) override;
|
|
|
|
void SetDocument(nsIDocument* aDocument);
|
|
nsINode* GetParentObject() override;
|
|
|
|
virtual Element*
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override
|
|
{
|
|
// HTMLPropertiesCollection.namedItem and the named getter call the
|
|
// NamedItem that returns a PropertyNodeList, calling
|
|
// HTMLCollection.namedItem doesn't make sense so this returns null.
|
|
aFound = false;
|
|
return nullptr;
|
|
}
|
|
PropertyNodeList* NamedItem(const nsAString& aName);
|
|
PropertyNodeList* NamedGetter(const nsAString& aName, bool& aFound)
|
|
{
|
|
aFound = IsSupportedNamedProperty(aName);
|
|
return aFound ? NamedItem(aName) : nullptr;
|
|
}
|
|
bool NameIsEnumerable(const nsAString& aName)
|
|
{
|
|
return true;
|
|
}
|
|
DOMStringList* Names()
|
|
{
|
|
EnsureFresh();
|
|
return mNames;
|
|
}
|
|
virtual void GetSupportedNames(unsigned,
|
|
nsTArray<nsString>& aNames) override;
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(HTMLPropertiesCollection,
|
|
nsIHTMLCollection)
|
|
|
|
protected:
|
|
// Make sure this collection is up to date, in case the DOM has been mutated.
|
|
void EnsureFresh();
|
|
|
|
// Crawl the properties of mRoot, following any itemRefs it may have
|
|
void CrawlProperties();
|
|
|
|
// Crawl startNode and its descendants, looking for items
|
|
void CrawlSubtree(Element* startNode);
|
|
|
|
bool IsSupportedNamedProperty(const nsAString& aName)
|
|
{
|
|
EnsureFresh();
|
|
return mNames->ContainsInternal(aName);
|
|
}
|
|
|
|
// the items that make up this collection
|
|
nsTArray<RefPtr<nsGenericHTMLElement> > mProperties;
|
|
|
|
// the itemprop attribute of the properties
|
|
RefPtr<PropertyStringList> mNames;
|
|
|
|
// The cached PropertyNodeLists that are NamedItems of this collection
|
|
nsRefPtrHashtable<nsStringHashKey, PropertyNodeList> mNamedItemEntries;
|
|
|
|
// The element this collection is rooted at
|
|
RefPtr<nsGenericHTMLElement> mRoot;
|
|
|
|
// The document mRoot is in, if any
|
|
nsCOMPtr<nsIDocument> mDoc;
|
|
|
|
// True if there have been DOM modifications since the last EnsureFresh call.
|
|
bool mIsDirty;
|
|
};
|
|
|
|
class PropertyNodeList final : public nsINodeList,
|
|
public nsStubMutationObserver
|
|
{
|
|
public:
|
|
PropertyNodeList(HTMLPropertiesCollection* aCollection,
|
|
nsIContent* aRoot, const nsAString& aName);
|
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
void SetDocument(nsIDocument* aDocument);
|
|
|
|
void GetValues(JSContext* aCx, nsTArray<JS::Value >& aResult,
|
|
ErrorResult& aError);
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(PropertyNodeList,
|
|
nsINodeList)
|
|
NS_DECL_NSIDOMNODELIST
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
// nsINodeList interface
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
virtual nsINode* GetParentObject() override;
|
|
|
|
void AppendElement(nsGenericHTMLElement* aElement)
|
|
{
|
|
mElements.AppendElement(aElement);
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
mElements.Clear();
|
|
}
|
|
|
|
void SetDirty() { mIsDirty = true; }
|
|
|
|
protected:
|
|
virtual ~PropertyNodeList();
|
|
|
|
// Make sure this list is up to date, in case the DOM has been mutated.
|
|
void EnsureFresh();
|
|
|
|
// the the name that this list corresponds to
|
|
nsString mName;
|
|
|
|
// the document mParent is in, if any
|
|
nsCOMPtr<nsIDocument> mDoc;
|
|
|
|
// the collection that this list is a named item of
|
|
RefPtr<HTMLPropertiesCollection> mCollection;
|
|
|
|
// the node this list is rooted at
|
|
nsCOMPtr<nsINode> mParent;
|
|
|
|
// the properties that make up this list
|
|
nsTArray<RefPtr<nsGenericHTMLElement> > mElements;
|
|
|
|
// True if there have been DOM modifications since the last EnsureFresh call.
|
|
bool mIsDirty;
|
|
};
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
#endif // HTMLPropertiesCollection_h_
|