2015-05-03 22:32:37 +03: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 15:12:37 +04: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 12:03:04 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsBaseContentList is a basic list of content nodes; nsContentList
|
|
|
|
* is a commonly used NodeList implementation (used for
|
2018-01-26 09:03:25 +03:00
|
|
|
* getElementsByTagName, some properties on HTMLDocument/Document, etc).
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
1998-07-23 03:32:19 +04:00
|
|
|
#ifndef nsContentList_h___
|
|
|
|
#define nsContentList_h___
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-03-17 11:55:10 +04:00
|
|
|
#include "nsContentListDeclarations.h"
|
1998-07-23 03:32:19 +04:00
|
|
|
#include "nsISupports.h"
|
2011-11-01 06:48:59 +04:00
|
|
|
#include "nsTArray.h"
|
2013-09-23 21:25:00 +04:00
|
|
|
#include "nsString.h"
|
2008-11-01 00:40:35 +03:00
|
|
|
#include "nsIHTMLCollection.h"
|
2008-09-11 07:15:29 +04:00
|
|
|
#include "nsINodeList.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
#include "nsStubMutationObserver.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2007-03-08 14:17:16 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2008-11-13 19:54:52 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "nsHashKeys.h"
|
2012-03-13 02:53:18 +04:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2014-08-18 18:44:50 +04:00
|
|
|
#include "mozilla/dom/NameSpaceConstants.h"
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2011-07-20 23:18:54 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2008-10-22 18:31:14 +04:00
|
|
|
class nsBaseContentList : public nsINodeList
|
2001-03-22 11:51:52 +03:00
|
|
|
{
|
|
|
|
public:
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2008-09-11 07:15:29 +04:00
|
|
|
// nsINodeList
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
2012-10-13 16:50:24 +04:00
|
|
|
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t Length() override {
|
2011-11-01 06:48:59 +04:00
|
|
|
return mElements.Length();
|
2009-07-24 17:33:20 +04:00
|
|
|
}
|
|
|
|
|
2012-02-11 00:47:29 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsBaseContentList)
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2011-11-01 06:48:59 +04:00
|
|
|
void AppendElement(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
mElements.AppendElement(aContent);
|
|
|
|
}
|
2010-02-11 20:34:01 +03:00
|
|
|
void MaybeAppendElement(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent)
|
|
|
|
AppendElement(aContent);
|
|
|
|
}
|
2009-07-24 17:33:20 +04: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 19:56:38 +04:00
|
|
|
void InsertElementAt(nsIContent* aContent, int32_t aIndex)
|
2011-11-01 06:48:59 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "Element to insert must not be null");
|
|
|
|
mElements.InsertElementAt(aIndex, aContent);
|
|
|
|
}
|
2009-07-24 17:33:20 +04:00
|
|
|
|
2011-11-01 06:48:59 +04:00
|
|
|
void RemoveElement(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
mElements.RemoveElement(aContent);
|
|
|
|
}
|
2009-07-24 17:33:20 +04:00
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
mElements.Clear();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual int32_t IndexOf(nsIContent *aContent, bool aDoFlush);
|
2001-03-22 11:51:52 +03: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 17:13:33 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
|
2015-03-21 19:28:04 +03:00
|
|
|
override = 0;
|
2011-06-01 01:47:17 +04:00
|
|
|
|
2013-11-07 23:59:48 +04:00
|
|
|
void SetCapacity(uint32_t aCapacity)
|
|
|
|
{
|
|
|
|
mElements.SetCapacity(aCapacity);
|
|
|
|
}
|
2017-06-29 13:25:15 +03:00
|
|
|
|
|
|
|
virtual void LastRelease() {}
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
protected:
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~nsBaseContentList();
|
|
|
|
|
2013-09-25 06:56:18 +04:00
|
|
|
/**
|
|
|
|
* To be called from non-destructor locations (e.g. unlink) that want to
|
|
|
|
* remove from caches. Cacheable subclasses should override.
|
|
|
|
*/
|
|
|
|
virtual void RemoveFromCaches()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-03 20:04:48 +03:00
|
|
|
AutoTArray<nsCOMPtr<nsIContent>, 10> mElements;
|
2001-03-22 11:51:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-16 10:32:10 +04:00
|
|
|
class nsSimpleContentList : public nsBaseContentList
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsSimpleContentList(nsINode* aRoot) : nsBaseContentList(),
|
|
|
|
mRoot(aRoot)
|
2009-06-16 10:32:10 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsSimpleContentList,
|
|
|
|
nsBaseContentList)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsINode* GetParentObject() override
|
2009-06-16 10:32:10 +04:00
|
|
|
{
|
|
|
|
return mRoot;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2009-06-16 10:32:10 +04:00
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsSimpleContentList() {}
|
|
|
|
|
2009-06-16 10:32:10 +04:00
|
|
|
private:
|
|
|
|
// This has to be a strong reference, the root might go away before the list.
|
|
|
|
nsCOMPtr<nsINode> mRoot;
|
|
|
|
};
|
|
|
|
|
2017-07-29 02:44:39 +03:00
|
|
|
// Used for returning lists that will always be empty, such as the applets list
|
|
|
|
// in HTML Documents
|
2017-11-13 18:39:06 +03:00
|
|
|
class nsEmptyContentList final : public nsBaseContentList,
|
|
|
|
public nsIHTMLCollection
|
2017-07-29 02:44:39 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit nsEmptyContentList(nsINode* aRoot) : nsBaseContentList(),
|
|
|
|
mRoot(aRoot)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsEmptyContentList,
|
|
|
|
nsBaseContentList)
|
|
|
|
|
|
|
|
virtual nsINode* GetParentObject() override
|
|
|
|
{
|
|
|
|
return mRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
|
|
|
{
|
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
|
|
}
|
|
|
|
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
|
|
|
|
{
|
|
|
|
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
|
|
|
|
}
|
|
|
|
|
2018-02-09 08:22:43 +03:00
|
|
|
uint32_t Length() final
|
2017-11-13 18:39:06 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-29 02:44:39 +03:00
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
|
|
|
virtual mozilla::dom::Element* GetElementAt(uint32_t index) override;
|
|
|
|
virtual mozilla::dom::Element*
|
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override;
|
|
|
|
virtual void GetSupportedNames(nsTArray<nsString>& aNames) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsEmptyContentList() {}
|
|
|
|
private:
|
|
|
|
// This has to be a strong reference, the root might go away before the list.
|
|
|
|
nsCOMPtr<nsINode> mRoot;
|
|
|
|
};
|
|
|
|
|
2002-06-28 05:30:09 +04:00
|
|
|
/**
|
|
|
|
* Class that's used as the key to hash nsContentList implementations
|
|
|
|
* for fast retrieval
|
|
|
|
*/
|
2010-11-23 22:10:56 +03:00
|
|
|
struct nsContentListKey
|
2002-05-09 00:48:19 +04:00
|
|
|
{
|
2015-10-15 22:11:59 +03: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 11:23:10 +04:00
|
|
|
nsContentListKey(nsINode* aRootNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMatchNameSpaceId,
|
2015-10-15 22:11:59 +03:00
|
|
|
const nsAString& aTagname,
|
|
|
|
bool aIsHTMLDocument)
|
2010-11-23 22:10:56 +03:00
|
|
|
: mRootNode(aRootNode),
|
2002-05-09 00:48:19 +04:00
|
|
|
mMatchNameSpaceId(aMatchNameSpaceId),
|
2013-11-05 23:40:09 +04:00
|
|
|
mTagname(aTagname),
|
2015-10-15 22:11:59 +03:00
|
|
|
mIsHTMLDocument(aIsHTMLDocument),
|
2013-11-05 23:40:09 +04:00
|
|
|
mHash(mozilla::AddToHash(mozilla::HashString(aTagname), mRootNode,
|
2015-10-15 22:11:59 +03:00
|
|
|
mMatchNameSpaceId, mIsHTMLDocument))
|
2002-05-09 00:48:19 +04:00
|
|
|
{
|
|
|
|
}
|
2010-11-23 22:10:56 +03:00
|
|
|
|
2002-05-09 00:48:19 +04:00
|
|
|
nsContentListKey(const nsContentListKey& aContentListKey)
|
2010-11-23 22:10:56 +03:00
|
|
|
: mRootNode(aContentListKey.mRootNode),
|
2002-05-09 00:48:19 +04:00
|
|
|
mMatchNameSpaceId(aContentListKey.mMatchNameSpaceId),
|
2013-11-05 23:40:09 +04:00
|
|
|
mTagname(aContentListKey.mTagname),
|
2015-10-15 22:11:59 +03:00
|
|
|
mIsHTMLDocument(aContentListKey.mIsHTMLDocument),
|
2013-11-05 23:40:09 +04:00
|
|
|
mHash(aContentListKey.mHash)
|
2002-05-09 00:48:19 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline uint32_t GetHash(void) const
|
2002-05-09 00:48:19 +04:00
|
|
|
{
|
2013-11-05 23:40:09 +04:00
|
|
|
return mHash;
|
2002-05-09 00:48:19 +04:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-11-23 22:10:56 +03:00
|
|
|
nsINode* const mRootNode; // Weak ref
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t mMatchNameSpaceId;
|
2010-11-23 22:10:56 +03:00
|
|
|
const nsAString& mTagname;
|
2015-10-15 22:11:59 +03:00
|
|
|
bool mIsHTMLDocument;
|
2013-11-05 23:40:09 +04:00
|
|
|
const uint32_t mHash;
|
2002-05-09 00:48:19 +04:00
|
|
|
};
|
|
|
|
|
2006-09-30 19:12:47 +04: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 05:30:09 +04:00
|
|
|
/**
|
2017-08-27 05:26:55 +03:00
|
|
|
* Class that implements a possibly live NodeList that matches Elements
|
|
|
|
* in the tree based on some criterion.
|
2002-06-28 05:30:09 +04:00
|
|
|
*/
|
2001-03-22 11:51:52 +03:00
|
|
|
class nsContentList : public nsBaseContentList,
|
2008-11-01 00:40:35 +03:00
|
|
|
public nsIHTMLCollection,
|
2009-06-16 10:32:10 +04:00
|
|
|
public nsStubMutationObserver
|
2001-03-22 11:51:52 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2006-04-26 01:21:49 +04:00
|
|
|
/**
|
2006-07-02 11:23:10 +04:00
|
|
|
* @param aRootNode The node under which to limit our search.
|
2006-07-20 07:25:39 +04: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 23:05:23 +03:00
|
|
|
* tagName to match.
|
2006-07-20 07:25:39 +04: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-26 01:21:49 +04: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.
|
2017-08-27 05:26:55 +03:00
|
|
|
* @param aLiveList Whether the created list should be a live list observing
|
|
|
|
* mutations to the DOM tree.
|
2017-07-06 15:00:35 +03:00
|
|
|
*/
|
2006-07-02 11:23:10 +04:00
|
|
|
nsContentList(nsINode* aRootNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMatchNameSpaceId,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLMatchAtom,
|
|
|
|
nsAtom* aXMLMatchAtom,
|
2017-08-27 05:26:55 +03:00
|
|
|
bool aDeep = true,
|
|
|
|
bool aLiveList = true);
|
2006-04-26 01:21:49 +04:00
|
|
|
|
|
|
|
/**
|
2006-07-02 11:23:10 +04:00
|
|
|
* @param aRootNode The node under which to limit our search.
|
2008-09-13 02:35:15 +04: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 17:12:05 +04:00
|
|
|
* passed to the function will be IsElement().
|
2007-02-01 18:14:00 +03: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-26 01:21:49 +04: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 23:05:23 +03:00
|
|
|
* @param aMatchNameSpaceId a namespace id to be passed back to aFunc
|
2006-04-26 01:21:49 +04:00
|
|
|
* @param aFuncMayDependOnAttr a boolean that indicates whether this list is
|
|
|
|
* sensitive to attribute changes.
|
2017-08-27 05:26:55 +03:00
|
|
|
* @param aLiveList Whether the created list should be a live list observing
|
|
|
|
* mutations to the DOM tree.
|
2017-07-06 15:00:35 +03:00
|
|
|
*/
|
2006-07-02 11:23:10 +04:00
|
|
|
nsContentList(nsINode* aRootNode,
|
1999-01-15 22:18:30 +03:00
|
|
|
nsContentListMatchFunc aFunc,
|
2007-02-01 18:14:00 +03:00
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
void* aData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDeep = true,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aMatchAtom = nullptr,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aMatchNameSpaceId = kNameSpaceID_None,
|
2017-08-27 05:26:55 +03:00
|
|
|
bool aFuncMayDependOnAttr = true,
|
|
|
|
bool aLiveList = true);
|
1998-07-23 03:32:19 +04:00
|
|
|
|
2011-05-23 19:39:52 +04:00
|
|
|
// nsWrapperCache
|
2012-11-22 15:09:43 +04:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2017-05-17 07:52:53 +03:00
|
|
|
using nsWrapperCache::PreserveWrapper;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-12 19:22:22 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~nsContentList();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
2013-11-12 19:22:22 +04:00
|
|
|
{
|
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
|
|
|
}
|
2017-05-17 07:52:53 +03:00
|
|
|
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
|
|
|
|
{
|
|
|
|
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
|
|
|
|
}
|
2013-11-12 19:22:22 +04:00
|
|
|
public:
|
2011-05-23 19:39:52 +04:00
|
|
|
|
2005-02-03 02:16:02 +03:00
|
|
|
// nsBaseContentList overrides
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual int32_t IndexOf(nsIContent *aContent, bool aDoFlush) override;
|
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsINode* GetParentObject() override
|
2009-06-16 10:32:10 +04:00
|
|
|
{
|
|
|
|
return mRootNode;
|
|
|
|
}
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2018-02-09 08:22:43 +03:00
|
|
|
uint32_t Length() final
|
2017-11-13 18:39:06 +03:00
|
|
|
{
|
|
|
|
return Length(true);
|
|
|
|
}
|
2018-03-20 21:02:08 +03:00
|
|
|
nsIContent* Item(uint32_t aIndex) final;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual mozilla::dom::Element* GetElementAt(uint32_t index) override;
|
2013-11-11 11:55:41 +04:00
|
|
|
virtual mozilla::dom::Element*
|
2015-03-21 19:28:04 +03:00
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override
|
2013-11-11 11:55:41 +04:00
|
|
|
{
|
|
|
|
mozilla::dom::Element* item = NamedItem(aName, true);
|
|
|
|
aFound = !!item;
|
|
|
|
return item;
|
|
|
|
}
|
2016-05-10 05:25:40 +03:00
|
|
|
virtual void GetSupportedNames(nsTArray<nsString>& aNames) override;
|
2012-09-05 19:42:58 +04:00
|
|
|
|
2005-02-03 02:16:02 +03:00
|
|
|
// nsContentList public methods
|
2014-06-02 16:08:21 +04:00
|
|
|
uint32_t Length(bool aDoFlush);
|
|
|
|
nsIContent* Item(uint32_t aIndex, bool aDoFlush);
|
|
|
|
mozilla::dom::Element*
|
2013-11-11 11:55:41 +04:00
|
|
|
NamedItem(const nsAString& aName, bool aDoFlush);
|
2005-02-03 02:16:02 +03:00
|
|
|
|
2006-07-02 11:23:10 +04:00
|
|
|
// nsIMutationObserver
|
2007-07-13 00:05:45 +04:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-10-22 18:31:14 +04: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 10:19:26 +04:00
|
|
|
bool MatchesKey(const nsContentListKey& aKey) const
|
2010-11-23 22:10:56 +03: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 22:11:59 +03:00
|
|
|
// string first. Cases in which whether our root's ownerDocument
|
|
|
|
// is HTML changes are extremely rare, so check those last.
|
2010-11-23 22:10:56 +03: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 22:11:59 +03:00
|
|
|
mMatchNameSpaceId == aKey.mMatchNameSpaceId &&
|
|
|
|
mIsHTMLDocument == aKey.mIsHTMLDocument;
|
2010-11-23 22:10:56 +03:00
|
|
|
}
|
|
|
|
|
2013-09-02 21:23:27 +04: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();
|
|
|
|
}
|
|
|
|
|
2017-06-29 13:25:15 +03:00
|
|
|
virtual void LastRelease() override;
|
|
|
|
|
2000-06-02 02:55:19 +04:00
|
|
|
protected:
|
2002-06-28 05:30:09 +04:00
|
|
|
/**
|
2010-04-30 17:12:05 +04:00
|
|
|
* Returns whether the element matches our criterion
|
2002-06-28 05:30:09 +04:00
|
|
|
*
|
2010-04-30 17:12:05 +04:00
|
|
|
* @param aElement the element to attempt to match
|
2002-06-28 05:30:09 +04:00
|
|
|
* @return whether we match
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Match(mozilla::dom::Element *aElement);
|
2002-06-28 05:30:09 +04:00
|
|
|
/**
|
2010-05-11 05:12:34 +04:00
|
|
|
* See if anything in the subtree rooted at aContent, including
|
|
|
|
* aContent itself, matches our criterion.
|
2002-06-28 05:30:09 +04: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 10:19:26 +04:00
|
|
|
bool MatchSelf(nsIContent *aContent);
|
2002-06-28 05:30:09 +04: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
|
2017-06-16 03:04:00 +03:00
|
|
|
* done (unless it exhausts the document)
|
2002-06-28 05:30:09 +04:00
|
|
|
*/
|
2017-06-16 03:04:00 +03:00
|
|
|
virtual void PopulateSelf(uint32_t aNeededLength);
|
2002-06-28 05:30:09 +04:00
|
|
|
|
|
|
|
/**
|
2006-07-02 11:23:10 +04:00
|
|
|
* @param aContainer a content node which must be a descendant of
|
|
|
|
* mRootNode
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true if children or descendants of aContainer could match our
|
2006-07-02 11:23:10 +04:00
|
|
|
* criterion.
|
2011-10-17 18:59:28 +04:00
|
|
|
* false otherwise.
|
2002-06-28 05:30:09 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool MayContainRelevantNodes(nsINode* aContainer)
|
2006-07-02 11:23:10 +04:00
|
|
|
{
|
|
|
|
return mDeep || aContainer == mRootNode;
|
|
|
|
}
|
2002-06-28 05:30:09 +04:00
|
|
|
|
2004-04-30 01:07:44 +04:00
|
|
|
/**
|
|
|
|
* Remove ourselves from the hashtable that caches commonly accessed
|
|
|
|
* content lists. Generally done on destruction.
|
|
|
|
*/
|
2002-05-09 00:48:19 +04:00
|
|
|
void RemoveFromHashtable();
|
2004-04-30 01:07:44 +04:00
|
|
|
/**
|
|
|
|
* If state is not LIST_UP_TO_DATE, fully populate ourselves with
|
|
|
|
* all the nodes we can find.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
inline void BringSelfUpToDate(bool aDoFlush);
|
2006-09-30 19:12:47 +04:00
|
|
|
|
2010-02-09 20:09:06 +03: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 19:28:04 +03:00
|
|
|
virtual void RemoveFromCaches() override
|
2013-09-25 06:56:18 +04:00
|
|
|
{
|
2010-02-09 20:09:06 +03:00
|
|
|
RemoveFromHashtable();
|
|
|
|
}
|
|
|
|
|
2010-11-23 22:10:56 +03:00
|
|
|
nsINode* mRootNode; // Weak ref
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mMatchNameSpaceId;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> mHTMLMatchAtom;
|
|
|
|
RefPtr<nsAtom> mXMLMatchAtom;
|
2010-11-23 22:10:56 +03:00
|
|
|
|
2002-06-28 05:30:09 +04:00
|
|
|
/**
|
|
|
|
* Function to use to determine whether a piece of content matches
|
|
|
|
* our criterion
|
|
|
|
*/
|
1998-07-23 03:32:19 +04:00
|
|
|
nsContentListMatchFunc mFunc;
|
2007-02-01 18:14:00 +03:00
|
|
|
/**
|
|
|
|
* Cleanup closure data with this.
|
|
|
|
*/
|
|
|
|
nsContentListDestroyFunc mDestroyFunc;
|
2002-06-28 05:30:09 +04:00
|
|
|
/**
|
|
|
|
* Closure data to pass to mFunc when we call it
|
|
|
|
*/
|
2007-02-01 18:14:00 +03:00
|
|
|
void* mData;
|
2002-06-28 05:30:09 +04:00
|
|
|
/**
|
|
|
|
* The current state of the list (possible values are:
|
|
|
|
* LIST_UP_TO_DATE, LIST_LAZY, LIST_DIRTY
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mState;
|
2010-09-28 21:46:08 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
// The booleans have to use uint8_t to pack with mState, because MSVC won't
|
2010-09-28 21:46:08 +04:00
|
|
|
// pack different typedefs together. Once we no longer have to worry about
|
2011-09-29 10:19:26 +04:00
|
|
|
// flushes in XML documents, we can go back to using bool for the
|
2010-09-28 21:46:08 +04:00
|
|
|
// booleans.
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-09-28 21:46:08 +04:00
|
|
|
/**
|
|
|
|
* True if we are looking for elements named "*"
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mMatchAll : 1;
|
2004-04-14 08:26:00 +04:00
|
|
|
/**
|
|
|
|
* Whether to actually descend the tree. If this is false, we won't
|
2006-07-02 11:23:10 +04:00
|
|
|
* consider grandkids of mRootNode.
|
2004-04-14 08:26:00 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mDeep : 1;
|
2005-08-16 05:43:53 +04:00
|
|
|
/**
|
|
|
|
* Whether the return value of mFunc could depend on the values of
|
|
|
|
* attributes.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mFuncMayDependOnAttr : 1;
|
2010-09-28 21:46:08 +04:00
|
|
|
/**
|
|
|
|
* Whether we actually need to flush to get our state correct.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mFlushesNeeded : 1;
|
2015-10-15 22:11:59 +03: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;
|
2017-08-27 05:26:55 +03:00
|
|
|
/**
|
|
|
|
* Whether the list observes mutations to the DOM tree.
|
|
|
|
*/
|
|
|
|
const uint8_t mIsLiveList : 1;
|
2006-08-10 22:58:37 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_CONTENT_LIST
|
|
|
|
void AssertInSync();
|
|
|
|
#endif
|
1998-07-23 03:32:19 +04:00
|
|
|
};
|
|
|
|
|
2010-02-09 20:09:06 +03:00
|
|
|
/**
|
|
|
|
* A class of cacheable content list; cached on the combination of aRootNode + aFunc + aDataString
|
|
|
|
*/
|
|
|
|
class nsCacheableFuncStringContentList;
|
|
|
|
|
2013-04-12 07:20:09 +04:00
|
|
|
class MOZ_STACK_CLASS nsFuncStringCacheKey {
|
2010-02-09 20:09:06 +03:00
|
|
|
public:
|
|
|
|
nsFuncStringCacheKey(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
const nsAString& aString) :
|
|
|
|
mRootNode(aRootNode),
|
|
|
|
mFunc(aFunc),
|
|
|
|
mString(aString)
|
|
|
|
{}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetHash(void) const
|
2010-02-09 20:09:06 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t hash = mozilla::HashString(mString);
|
2012-03-13 02:53:18 +04:00
|
|
|
return mozilla::AddToHash(hash, mRootNode, mFunc);
|
2010-02-09 20:09:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class nsCacheableFuncStringContentList;
|
|
|
|
|
|
|
|
nsINode* const mRootNode;
|
|
|
|
const nsContentListMatchFunc mFunc;
|
|
|
|
const nsAString& mString;
|
|
|
|
};
|
|
|
|
|
2010-06-08 23:58:26 +04:00
|
|
|
// aDestroyFunc is allowed to be null
|
2012-09-26 18:17:47 +04:00
|
|
|
// aDataAllocator must always return a non-null pointer
|
2010-02-09 20:09:06 +03:00
|
|
|
class nsCacheableFuncStringContentList : public nsContentList {
|
|
|
|
public:
|
2012-09-06 00:49:53 +04: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:
|
2018-04-13 16:01:28 +03:00
|
|
|
nsCacheableFuncStringContentList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString) :
|
|
|
|
nsContentList(aRootNode, aFunc, aDestroyFunc, nullptr),
|
2010-02-09 20:09:06 +03:00
|
|
|
mString(aString)
|
2010-06-08 23:58:26 +04:00
|
|
|
{
|
|
|
|
mData = (*aDataAllocator)(aRootNode, &mString);
|
2012-09-26 18:17:47 +04:00
|
|
|
MOZ_ASSERT(mData);
|
2010-06-08 23:58:26 +04:00
|
|
|
}
|
2010-02-09 20:09:06 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void RemoveFromCaches() override {
|
2010-02-09 20:09:06 +03:00
|
|
|
RemoveFromFuncStringHashtable();
|
|
|
|
}
|
|
|
|
void RemoveFromFuncStringHashtable();
|
|
|
|
|
|
|
|
nsString mString;
|
|
|
|
};
|
|
|
|
|
2017-07-26 09:34:00 +03:00
|
|
|
class nsCachableElementsByNameNodeList
|
2012-09-06 00:49:53 +04:00
|
|
|
: public nsCacheableFuncStringContentList
|
|
|
|
{
|
|
|
|
public:
|
2017-07-26 09:34:00 +03:00
|
|
|
nsCachableElementsByNameNodeList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
nsFuncStringContentListDataAllocator aDataAllocator,
|
|
|
|
const nsAString& aString)
|
2012-09-06 00:49:53 +04:00
|
|
|
: nsCacheableFuncStringContentList(aRootNode, aFunc, aDestroyFunc,
|
|
|
|
aDataAllocator, aString)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
mType = eNodeList;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-26 09:34:00 +03:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-09-06 00:49:53 +04: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 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-09-06 00:49:53 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const ContentListType sType;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2017-06-16 03:04:00 +03:00
|
|
|
class nsLabelsNodeList final : public nsContentList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsLabelsNodeList(nsINode* aRootNode,
|
|
|
|
nsContentListMatchFunc aFunc,
|
|
|
|
nsContentListDestroyFunc aDestroyFunc,
|
|
|
|
void* aData)
|
|
|
|
: nsContentList(aRootNode, aFunc, aDestroyFunc, aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset root, mutation observer, and clear content list
|
|
|
|
* if the root has been changed.
|
|
|
|
*
|
|
|
|
* @param aRootNode The node under which to limit our search.
|
|
|
|
*/
|
|
|
|
void MaybeResetRoot(nsINode* aRootNode);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Start searching at the last one if we already have nodes, otherwise
|
|
|
|
* start searching at the root.
|
|
|
|
*
|
|
|
|
* @param aNeededLength The list of length should have when we are
|
|
|
|
* done (unless it exhausts the document).
|
|
|
|
*/
|
|
|
|
void PopulateSelf(uint32_t aNeededLength) override;
|
|
|
|
};
|
1998-07-23 03:32:19 +04:00
|
|
|
#endif // nsContentList_h___
|