2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-03-30 08:03:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsBaseContentList is a basic list of content nodes; nsContentList
|
|
|
|
* is a commonly used NodeList implementation (used for
|
2006-03-31 08:41:49 +00:00
|
|
|
* getElementsByTagName, some properties on nsIDOMHTMLDocument, etc).
|
2006-03-30 08:03:04 +00:00
|
|
|
*/
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
#ifndef nsContentList_h___
|
|
|
|
#define nsContentList_h___
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-03-17 07:55:10 +00:00
|
|
|
#include "nsContentListDeclarations.h"
|
1998-07-22 23:32:19 +00:00
|
|
|
#include "nsISupports.h"
|
2011-11-01 02:48:59 +00:00
|
|
|
#include "nsTArray.h"
|
2013-09-23 17:25:00 +00:00
|
|
|
#include "nsString.h"
|
2008-10-31 21:40:35 +00:00
|
|
|
#include "nsIHTMLCollection.h"
|
1998-07-22 23:32:19 +00:00
|
|
|
#include "nsIDOMNodeList.h"
|
2008-09-11 03:15:29 +00:00
|
|
|
#include "nsINodeList.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsStubMutationObserver.h"
|
2002-07-25 18:31:10 +00:00
|
|
|
#include "nsIAtom.h"
|
2007-03-08 11:17:16 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2008-11-13 16:54:52 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "nsHashKeys.h"
|
2012-03-12 22:53:18 +00:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2014-08-18 14:44:50 +00:00
|
|
|
#include "mozilla/dom/NameSpaceConstants.h"
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2011-07-20 19:18:54 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2008-10-22 14:31:14 +00:00
|
|
|
class nsBaseContentList : public nsINodeList
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2001-03-22 08:51:52 +00:00
|
|
|
|
|
|
|
// nsIDOMNodeList
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
NS_DECL_NSIDOMNODELIST
|
2008-09-11 03:15:29 +00:00
|
|
|
|
|
|
|
// nsINodeList
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
2012-10-13 12:50:24 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t Length() const {
|
2011-11-01 02:48:59 +00:00
|
|
|
return mElements.Length();
|
2009-07-24 13:33:20 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 20:47:29 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsBaseContentList)
|
2001-03-22 08:51:52 +00:00
|
|
|
|
2011-11-01 02:48:59 +00:00
|
|
|
void AppendElement(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
mElements.AppendElement(aContent);
|
|
|
|
}
|
2010-02-11 17:34:01 +00:00
|
|
|
void MaybeAppendElement(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent)
|
|
|
|
AppendElement(aContent);
|
|
|
|
}
|
2009-07-24 13:33:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert the element at a given index, shifting the objects at
|
|
|
|
* the given index and later to make space.
|
|
|
|
* @param aContent Element to insert, must not be null
|
|
|
|
* @param aIndex Index to insert the element at.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
void InsertElementAt(nsIContent* aContent, int32_t aIndex)
|
2011-11-01 02:48:59 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "Element to insert must not be null");
|
|
|
|
mElements.InsertElementAt(aIndex, aContent);
|
|
|
|
}
|
2009-07-24 13:33:20 +00:00
|
|
|
|
2011-11-01 02:48:59 +00:00
|
|
|
void RemoveElement(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
mElements.RemoveElement(aContent);
|
|
|
|
}
|
2009-07-24 13:33:20 +00:00
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
mElements.Clear();
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual int32_t IndexOf(nsIContent *aContent, bool aDoFlush);
|
2001-03-22 08:51:52 +00:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2015-03-21 16:28:04 +00:00
|
|
|
override = 0;
|
2011-05-31 21:47:17 +00:00
|
|
|
|
2013-11-07 19:59:48 +00:00
|
|
|
void SetCapacity(uint32_t aCapacity)
|
|
|
|
{
|
|
|
|
mElements.SetCapacity(aCapacity);
|
|
|
|
}
|
2001-03-22 08:51:52 +00:00
|
|
|
protected:
|
2014-06-25 02:09:15 +00:00
|
|
|
virtual ~nsBaseContentList();
|
|
|
|
|
2013-09-25 02:56:18 +00:00
|
|
|
/**
|
|
|
|
* To be called from non-destructor locations (e.g. unlink) that want to
|
|
|
|
* remove from caches. Cacheable subclasses should override.
|
|
|
|
*/
|
|
|
|
virtual void RemoveFromCaches()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-01 02:48:59 +00:00
|
|
|
nsTArray< nsCOMPtr<nsIContent> > mElements;
|
2001-03-22 08:51:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-16 06:32:10 +00:00
|
|
|
class nsSimpleContentList : public nsBaseContentList
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 00:49:25 +00:00
|
|
|
explicit nsSimpleContentList(nsINode* aRoot) : nsBaseContentList(),
|
|
|
|
mRoot(aRoot)
|
2009-06-16 06:32:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSimpleContentList,
|
|
|
|
nsBaseContentList)
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsINode* GetParentObject() override
|
2009-06-16 06:32:10 +00:00
|
|
|
{
|
|
|
|
return mRoot;
|
|
|
|
}
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2009-06-16 06:32:10 +00:00
|
|
|
|
2014-07-08 21:23:16 +00:00
|
|
|
protected:
|
|
|
|
virtual ~nsSimpleContentList() {}
|
|
|
|
|
2009-06-16 06:32:10 +00:00
|
|
|
private:
|
|
|
|
// This has to be a strong reference, the root might go away before the list.
|
|
|
|
nsCOMPtr<nsINode> mRoot;
|
|
|
|
};
|
|
|
|
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* Class that's used as the key to hash nsContentList implementations
|
|
|
|
* for fast retrieval
|
|
|
|
*/
|
2010-11-23 19:10:56 +00:00
|
|
|
struct nsContentListKey
|
2002-05-08 20:48:19 +00:00
|
|
|
{
|
2015-10-15 19:11:59 +00:00
|
|
|
// We have to take an aIsHTMLDocument arg for two reasons:
|
|
|
|
// 1) We don't want to include nsIDocument.h in this header.
|
|
|
|
// 2) We need to do that to make nsContentList::RemoveFromHashtable
|
|
|
|
// work, because by the time it's called the document of the
|
|
|
|
// list's root node might have changed.
|
2006-07-02 07:23:10 +00:00
|
|
|
nsContentListKey(nsINode* aRootNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aMatchNameSpaceId,
|
2015-10-15 19:11:59 +00:00
|
|
|
const nsAString& aTagname,
|
|
|
|
bool aIsHTMLDocument)
|
2010-11-23 19:10:56 +00:00
|
|
|
: mRootNode(aRootNode),
|
2002-05-08 20:48:19 +00:00
|
|
|
mMatchNameSpaceId(aMatchNameSpaceId),
|
2013-11-05 19:40:09 +00:00
|
|
|
mTagname(aTagname),
|
2015-10-15 19:11:59 +00:00
|
|
|
mIsHTMLDocument(aIsHTMLDocument),
|
2013-11-05 19:40:09 +00:00
|
|
|
mHash(mozilla::AddToHash(mozilla::HashString(aTagname), mRootNode,
|
2015-10-15 19:11:59 +00:00
|
|
|
mMatchNameSpaceId, mIsHTMLDocument))
|
2002-05-08 20:48:19 +00:00
|
|
|
{
|
|
|
|
}
|
2010-11-23 19:10:56 +00:00
|
|
|
|
2002-05-08 20:48:19 +00:00
|
|
|
nsContentListKey(const nsContentListKey& aContentListKey)
|
2010-11-23 19:10:56 +00:00
|
|
|
: mRootNode(aContentListKey.mRootNode),
|
2002-05-08 20:48:19 +00:00
|
|
|
mMatchNameSpaceId(aContentListKey.mMatchNameSpaceId),
|
2013-11-05 19:40:09 +00:00
|
|
|
mTagname(aContentListKey.mTagname),
|
2015-10-15 19:11:59 +00:00
|
|
|
mIsHTMLDocument(aContentListKey.mIsHTMLDocument),
|
2013-11-05 19:40:09 +00:00
|
|
|
mHash(aContentListKey.mHash)
|
2002-05-08 20:48:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
inline uint32_t GetHash(void) const
|
2002-05-08 20:48:19 +00:00
|
|
|
{
|
2013-11-05 19:40:09 +00:00
|
|
|
return mHash;
|
2002-05-08 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 19:10:56 +00:00
|
|
|
nsINode* const mRootNode; // Weak ref
|
2012-08-22 15:56:38 +00:00
|
|
|
const int32_t mMatchNameSpaceId;
|
2010-11-23 19:10:56 +00:00
|
|
|
const nsAString& mTagname;
|
2015-10-15 19:11:59 +00:00
|
|
|
bool mIsHTMLDocument;
|
2013-11-05 19:40:09 +00:00
|
|
|
const uint32_t mHash;
|
2002-05-08 20:48:19 +00:00
|
|
|
};
|
|
|
|
|
2006-09-30 15:12:47 +00:00
|
|
|
/**
|
|
|
|
* LIST_UP_TO_DATE means that the list is up to date and need not do
|
|
|
|
* any walking to be able to answer any questions anyone may have.
|
|
|
|
*/
|
|
|
|
#define LIST_UP_TO_DATE 0
|
|
|
|
/**
|
|
|
|
* LIST_DIRTY means that the list contains no useful information and
|
|
|
|
* if anyone asks it anything it will have to populate itself before
|
|
|
|
* answering.
|
|
|
|
*/
|
|
|
|
#define LIST_DIRTY 1
|
|
|
|
/**
|
|
|
|
* LIST_LAZY means that the list has populated itself to a certain
|
|
|
|
* extent and that that part of the list is still valid. Requests for
|
|
|
|
* things outside that part of the list will require walking the tree
|
|
|
|
* some more. When a list is in this state, the last thing in
|
|
|
|
* mElements is the last node in the tree that the list looked at.
|
|
|
|
*/
|
|
|
|
#define LIST_LAZY 2
|
|
|
|
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
2008-09-12 22:35:15 +00:00
|
|
|
* Class that implements a live NodeList that matches Elements in the
|
|
|
|
* tree based on some criterion.
|
2002-06-28 01:30:09 +00:00
|
|
|
*/
|
2001-03-22 08:51:52 +00:00
|
|
|
class nsContentList : public nsBaseContentList,
|
2008-10-31 21:40:35 +00:00
|
|
|
public nsIHTMLCollection,
|
2009-06-16 06:32:10 +00:00
|
|
|
public nsStubMutationObserver
|
2001-03-22 08:51:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2006-04-25 21:21:49 +00:00
|
|
|
/**
|
2006-07-02 07:23:10 +00:00
|
|
|
* @param aRootNode The node under which to limit our search.
|
2006-07-20 03:25:39 +00:00
|
|
|
* @param aMatchAtom An atom whose meaning depends on aMatchNameSpaceId.
|
|
|
|
* The special value "*" always matches whatever aMatchAtom
|
|
|
|
* is matched against.
|
|
|
|
* @param aMatchNameSpaceId If kNameSpaceID_Unknown, then aMatchAtom is the
|
2016-01-05 20:05:23 +00:00
|
|
|
* tagName to match.
|
2006-07-20 03:25:39 +00:00
|
|
|
* If kNameSpaceID_Wildcard, then aMatchAtom is the
|
|
|
|
* localName to match.
|
|
|
|
* Otherwise we match nodes whose namespace is
|
|
|
|
* aMatchNameSpaceId and localName matches
|
|
|
|
* aMatchAtom.
|
2006-04-25 21:21:49 +00:00
|
|
|
* @param aDeep If false, then look only at children of the root, nothing
|
|
|
|
* deeper. If true, then look at the whole subtree rooted at
|
|
|
|
* our root.
|
|
|
|
*/
|
2006-07-02 07:23:10 +00:00
|
|
|
nsContentList(nsINode* aRootNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aMatchNameSpaceId,
|
2010-09-01 02:47:00 +00:00
|
|
|
nsIAtom* aHTMLMatchAtom,
|
|
|
|
nsIAtom* aXMLMatchAtom,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDeep = true);
|
2006-04-25 21:21:49 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-02 07:23:10 +00:00
|
|
|
* @param aRootNode The node under which to limit our search.
|
2008-09-12 22:35:15 +00:00
|
|
|
* @param aFunc the function to be called to determine whether we match.
|
|
|
|
* This function MUST NOT ever cause mutation of the DOM.
|
|
|
|
* The nsContentList implementation guarantees that everything
|
2010-04-30 13:12:05 +00:00
|
|
|
* passed to the function will be IsElement().
|
2007-02-01 15:14:00 +00:00
|
|
|
* @param aDestroyFunc the function that will be called to destroy aData
|
|
|
|
* @param aData closure data that will need to be passed back to aFunc
|
2006-04-25 21:21:49 +00:00
|
|
|
* @param aDeep If false, then look only at children of the root, nothing
|
|
|
|
* deeper. If true, then look at the whole subtree rooted at
|
|
|
|
* our root.
|
|
|
|
* @param aMatchAtom an atom to be passed back to aFunc
|
2016-01-05 20:05:23 +00:00
|
|
|
* @param aMatchNameSpaceId a namespace id to be passed back to aFunc
|
2006-04-25 21:21:49 +00:00
|
|
|
* @param aFuncMayDependOnAttr a boolean that indicates whether this list is
|
|
|
|
* sensitive to attribute changes.
|
|
|
|
*/
|
2006-07-02 07:23:10 +00:00
|
|
|
nsContentList(nsINode* aRootNode,
|
1999-01-15 19:18:30 +00:00
|
|
|
nsContentListMatchFunc aFunc,
|
2007-02-01 15:14:00 +00:00
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
void* aData,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDeep = true,
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIAtom* aMatchAtom = nullptr,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aMatchNameSpaceId = kNameSpaceID_None,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aFuncMayDependOnAttr = true);
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2011-05-23 15:39:52 +00:00
|
|
|
// nsWrapperCache
|
2012-11-22 11:09:43 +00:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-12 15:22:22 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~nsContentList();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
2013-11-12 15:22:22 +00:00
|
|
|
{
|
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
|
|
}
|
|
|
|
public:
|
2011-05-23 15:39:52 +00:00
|
|
|
|
1999-01-18 03:43:43 +00:00
|
|
|
// nsIDOMHTMLCollection
|
2004-01-24 00:46:17 +00:00
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
1998-07-22 23:32:19 +00:00
|
|
|
|
2005-02-02 23:16:02 +00:00
|
|
|
// nsBaseContentList overrides
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual int32_t IndexOf(nsIContent *aContent, bool aDoFlush) override;
|
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsINode* GetParentObject() override
|
2009-06-16 06:32:10 +00:00
|
|
|
{
|
|
|
|
return mRootNode;
|
|
|
|
}
|
2008-10-31 21:40:35 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
|
|
|
virtual mozilla::dom::Element* GetElementAt(uint32_t index) override;
|
2013-11-11 07:55:41 +00:00
|
|
|
virtual mozilla::dom::Element*
|
2015-03-21 16:28:04 +00:00
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override
|
2013-11-11 07:55:41 +00:00
|
|
|
{
|
|
|
|
mozilla::dom::Element* item = NamedItem(aName, true);
|
|
|
|
aFound = !!item;
|
|
|
|
return item;
|
|
|
|
}
|
2016-05-10 02:25:40 +00:00
|
|
|
virtual void GetSupportedNames(nsTArray<nsString>& aNames) override;
|
2012-09-05 15:42:58 +00:00
|
|
|
|
2005-02-02 23:16:02 +00:00
|
|
|
// nsContentList public methods
|
2014-06-02 12:08:21 +00:00
|
|
|
uint32_t Length(bool aDoFlush);
|
|
|
|
nsIContent* Item(uint32_t aIndex, bool aDoFlush);
|
|
|
|
mozilla::dom::Element*
|
2013-11-11 07:55:41 +00:00
|
|
|
NamedItem(const nsAString& aName, bool aDoFlush);
|
2005-02-02 23:16:02 +00:00
|
|
|
|
2006-07-02 07:23:10 +00:00
|
|
|
// nsIMutationObserver
|
2007-07-12 20:05:45 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
|
|
|
|
2008-10-22 14:31:14 +00:00
|
|
|
static nsContentList* FromSupports(nsISupports* aSupports)
|
|
|
|
{
|
|
|
|
nsINodeList* list = static_cast<nsINodeList*>(aSupports);
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsINodeList> list_qi = do_QueryInterface(aSupports);
|
|
|
|
|
|
|
|
// If this assertion fires the QI implementation for the object in
|
|
|
|
// question doesn't use the nsINodeList pointer as the nsISupports
|
|
|
|
// pointer. That must be fixed, or we'll crash...
|
|
|
|
NS_ASSERTION(list_qi == list, "Uh, fix QI!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return static_cast<nsContentList*>(list);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool MatchesKey(const nsContentListKey& aKey) const
|
2010-11-23 19:10:56 +00:00
|
|
|
{
|
|
|
|
// The root node is most commonly the same: the document. And the
|
|
|
|
// most common namespace id is kNameSpaceID_Unknown. So check the
|
2015-10-15 19:11:59 +00:00
|
|
|
// string first. Cases in which whether our root's ownerDocument
|
|
|
|
// is HTML changes are extremely rare, so check those last.
|
2010-11-23 19:10:56 +00:00
|
|
|
NS_PRECONDITION(mXMLMatchAtom,
|
|
|
|
"How did we get here with a null match atom on our list?");
|
|
|
|
return
|
|
|
|
mXMLMatchAtom->Equals(aKey.mTagname) &&
|
|
|
|
mRootNode == aKey.mRootNode &&
|
2015-10-15 19:11:59 +00:00
|
|
|
mMatchNameSpaceId == aKey.mMatchNameSpaceId &&
|
|
|
|
mIsHTMLDocument == aKey.mIsHTMLDocument;
|
2010-11-23 19:10:56 +00:00
|
|
|
}
|
|
|
|
|
2013-09-02 17:23:27 +00:00
|
|
|
/**
|
|
|
|
* Sets the state to LIST_DIRTY and clears mElements array.
|
|
|
|
* @note This is the only acceptable way to set state to LIST_DIRTY.
|
|
|
|
*/
|
|
|
|
void SetDirty()
|
|
|
|
{
|
|
|
|
mState = LIST_DIRTY;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2000-06-01 22:55:19 +00:00
|
|
|
protected:
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
2010-04-30 13:12:05 +00:00
|
|
|
* Returns whether the element matches our criterion
|
2002-06-28 01:30:09 +00:00
|
|
|
*
|
2010-04-30 13:12:05 +00:00
|
|
|
* @param aElement the element to attempt to match
|
2002-06-28 01:30:09 +00:00
|
|
|
* @return whether we match
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Match(mozilla::dom::Element *aElement);
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
2010-05-11 01:12:34 +00:00
|
|
|
* See if anything in the subtree rooted at aContent, including
|
|
|
|
* aContent itself, matches our criterion.
|
2002-06-28 01:30:09 +00:00
|
|
|
*
|
|
|
|
* @param aContent the root of the subtree to match against
|
|
|
|
* @return whether we match something in the tree rooted at aContent
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool MatchSelf(nsIContent *aContent);
|
2002-06-28 01:30:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate our list. Stop once we have at least aNeededLength
|
|
|
|
* elements. At the end of PopulateSelf running, either the last
|
|
|
|
* node we examined is the last node in our array or we have
|
|
|
|
* traversed the whole document (or both).
|
|
|
|
*
|
|
|
|
* @param aNeededLength the length the list should have when we are
|
|
|
|
* done (unless it exhausts the document)
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
void PopulateSelf(uint32_t aNeededLength);
|
2002-06-28 01:30:09 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-02 07:23:10 +00:00
|
|
|
* @param aContainer a content node which must be a descendant of
|
|
|
|
* mRootNode
|
2011-10-17 14:59:28 +00:00
|
|
|
* @return true if children or descendants of aContainer could match our
|
2006-07-02 07:23:10 +00:00
|
|
|
* criterion.
|
2011-10-17 14:59:28 +00:00
|
|
|
* false otherwise.
|
2002-06-28 01:30:09 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool MayContainRelevantNodes(nsINode* aContainer)
|
2006-07-02 07:23:10 +00:00
|
|
|
{
|
|
|
|
return mDeep || aContainer == mRootNode;
|
|
|
|
}
|
2002-06-28 01:30:09 +00:00
|
|
|
|
2004-04-29 21:07:44 +00:00
|
|
|
/**
|
|
|
|
* Remove ourselves from the hashtable that caches commonly accessed
|
|
|
|
* content lists. Generally done on destruction.
|
|
|
|
*/
|
2002-05-08 20:48:19 +00:00
|
|
|
void RemoveFromHashtable();
|
2004-04-29 21:07:44 +00:00
|
|
|
/**
|
|
|
|
* If state is not LIST_UP_TO_DATE, fully populate ourselves with
|
|
|
|
* all the nodes we can find.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
inline void BringSelfUpToDate(bool aDoFlush);
|
2006-09-30 15:12:47 +00:00
|
|
|
|
2010-02-09 17:09:06 +00:00
|
|
|
/**
|
|
|
|
* To be called from non-destructor locations that want to remove from caches.
|
|
|
|
* Needed because if subclasses want to have cache behavior they can't just
|
|
|
|
* override RemoveFromHashtable(), since we call that in our destructor.
|
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void RemoveFromCaches() override
|
2013-09-25 02:56:18 +00:00
|
|
|
{
|
2010-02-09 17:09:06 +00:00
|
|
|
RemoveFromHashtable();
|
|
|
|
}
|
|
|
|
|
2010-11-23 19:10:56 +00:00
|
|
|
nsINode* mRootNode; // Weak ref
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mMatchNameSpaceId;
|
2010-11-23 19:10:56 +00:00
|
|
|
nsCOMPtr<nsIAtom> mHTMLMatchAtom;
|
|
|
|
nsCOMPtr<nsIAtom> mXMLMatchAtom;
|
|
|
|
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* Function to use to determine whether a piece of content matches
|
|
|
|
* our criterion
|
|
|
|
*/
|
1998-07-22 23:32:19 +00:00
|
|
|
nsContentListMatchFunc mFunc;
|
2007-02-01 15:14:00 +00:00
|
|
|
/**
|
|
|
|
* Cleanup closure data with this.
|
|
|
|
*/
|
|
|
|
nsContentListDestroyFunc mDestroyFunc;
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* Closure data to pass to mFunc when we call it
|
|
|
|
*/
|
2007-02-01 15:14:00 +00:00
|
|
|
void* mData;
|
2002-06-28 01:30:09 +00:00
|
|
|
/**
|
|
|
|
* The current state of the list (possible values are:
|
|
|
|
* LIST_UP_TO_DATE, LIST_LAZY, LIST_DIRTY
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mState;
|
2010-09-28 17:46:08 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
// The booleans have to use uint8_t to pack with mState, because MSVC won't
|
2010-09-28 17:46:08 +00:00
|
|
|
// pack different typedefs together. Once we no longer have to worry about
|
2011-09-29 06:19:26 +00:00
|
|
|
// flushes in XML documents, we can go back to using bool for the
|
2010-09-28 17:46:08 +00:00
|
|
|
// booleans.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if we are looking for elements named "*"
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mMatchAll : 1;
|
2004-04-14 04:26:00 +00:00
|
|
|
/**
|
|
|
|
* Whether to actually descend the tree. If this is false, we won't
|
2006-07-02 07:23:10 +00:00
|
|
|
* consider grandkids of mRootNode.
|
2004-04-14 04:26:00 +00:00
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mDeep : 1;
|
2005-08-16 01:43:53 +00:00
|
|
|
/**
|
|
|
|
* Whether the return value of mFunc could depend on the values of
|
|
|
|
* attributes.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mFuncMayDependOnAttr : 1;
|
2010-09-28 17:46:08 +00:00
|
|
|
/**
|
|
|
|
* Whether we actually need to flush to get our state correct.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mFlushesNeeded : 1;
|
2015-10-15 19:11:59 +00:00
|
|
|
/**
|
|
|
|
* Whether the ownerDocument of our root node at list creation time was an
|
|
|
|
* HTML document. Only needed when we're doing a namespace/atom match, not
|
|
|
|
* when doing function matching, always false otherwise.
|
|
|
|
*/
|
|
|
|
uint8_t mIsHTMLDocument : 1;
|
2006-08-10 18:58:37 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_CONTENT_LIST
|
|
|
|
void AssertInSync();
|
|
|
|
#endif
|
1998-07-22 23:32:19 +00:00
|
|
|
};
|
|
|
|
|
2010-02-09 17:09:06 +00:00
|
|
|
/**
|
|
|
|
* A class of cacheable content list; cached on the combination of aRootNode + aFunc + aDataString
|
|
|
|
*/
|
|
|
|
class nsCacheableFuncStringContentList;
|
|
|
|
|
2013-04-12 03:20:09 +00:00
|
|
|
class MOZ_STACK_CLASS nsFuncStringCacheKey {
|
2010-02-09 17:09:06 +00:00
|
|
|
public:
|
|
|
|
nsFuncStringCacheKey(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
const nsAString& aString) :
|
|
|
|
mRootNode(aRootNode),
|
|
|
|
mFunc(aFunc),
|
|
|
|
mString(aString)
|
|
|
|
{}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetHash(void) const
|
2010-02-09 17:09:06 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t hash = mozilla::HashString(mString);
|
2012-03-12 22:53:18 +00:00
|
|
|
return mozilla::AddToHash(hash, mRootNode, mFunc);
|
2010-02-09 17:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class nsCacheableFuncStringContentList;
|
|
|
|
|
|
|
|
nsINode* const mRootNode;
|
|
|
|
const nsContentListMatchFunc mFunc;
|
|
|
|
const nsAString& mString;
|
|
|
|
};
|
|
|
|
|
2010-06-08 19:58:26 +00:00
|
|
|
// aDestroyFunc is allowed to be null
|
2012-09-26 14:17:47 +00:00
|
|
|
// aDataAllocator must always return a non-null pointer
|
2010-02-09 17:09:06 +00:00
|
|
|
class nsCacheableFuncStringContentList : public nsContentList {
|
|
|
|
public:
|
2012-09-05 20:49:53 +00:00
|
|
|
virtual ~nsCacheableFuncStringContentList();
|
|
|
|
|
|
|
|
bool Equals(const nsFuncStringCacheKey* aKey) {
|
|
|
|
return mRootNode == aKey->mRootNode && mFunc == aKey->mFunc &&
|
|
|
|
mString == aKey->mString;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
enum ContentListType {
|
|
|
|
eNodeList,
|
|
|
|
eHTMLCollection
|
|
|
|
};
|
|
|
|
ContentListType mType;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2010-02-09 17:09:06 +00:00
|
|
|
nsCacheableFuncStringContentList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
2010-06-08 19:58:26 +00:00
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
2010-02-09 17:09:06 +00:00
|
|
|
const nsAString& aString) :
|
2012-07-30 14:20:58 +00:00
|
|
|
nsContentList(aRootNode, aFunc, aDestroyFunc, nullptr),
|
2010-02-09 17:09:06 +00:00
|
|
|
mString(aString)
|
2010-06-08 19:58:26 +00:00
|
|
|
{
|
|
|
|
mData = (*aDataAllocator)(aRootNode, &mString);
|
2012-09-26 14:17:47 +00:00
|
|
|
MOZ_ASSERT(mData);
|
2010-06-08 19:58:26 +00:00
|
|
|
}
|
2010-02-09 17:09:06 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void RemoveFromCaches() override {
|
2010-02-09 17:09:06 +00:00
|
|
|
RemoveFromFuncStringHashtable();
|
|
|
|
}
|
|
|
|
void RemoveFromFuncStringHashtable();
|
|
|
|
|
|
|
|
nsString mString;
|
|
|
|
};
|
|
|
|
|
2012-09-05 20:49:53 +00:00
|
|
|
class nsCacheableFuncStringNodeList
|
|
|
|
: public nsCacheableFuncStringContentList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCacheableFuncStringNodeList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString)
|
|
|
|
: nsCacheableFuncStringContentList(aRootNode, aFunc, aDestroyFunc,
|
|
|
|
aDataAllocator, aString)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
mType = eNodeList;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-09-05 20:49:53 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const ContentListType sType;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsCacheableFuncStringHTMLCollection
|
|
|
|
: public nsCacheableFuncStringContentList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCacheableFuncStringHTMLCollection(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString)
|
|
|
|
: nsCacheableFuncStringContentList(aRootNode, aFunc, aDestroyFunc,
|
|
|
|
aDataAllocator, aString)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
mType = eHTMLCollection;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-09-05 20:49:53 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const ContentListType sType;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
1998-07-22 23:32:19 +00:00
|
|
|
#endif // nsContentList_h___
|