2015-05-19 13:33:00 +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: */
|
|
|
|
/* 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 nsChildContentList_h__
|
|
|
|
#define nsChildContentList_h__
|
|
|
|
|
2019-06-25 09:56:23 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-05-19 13:33:00 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
2017-08-21 11:11:56 +03:00
|
|
|
#include "nsINodeList.h" // base class
|
2015-05-19 13:33:00 +03:00
|
|
|
#include "js/TypeDecls.h" // for Handle, Value, JSObject, JSContext
|
|
|
|
|
|
|
|
class nsIContent;
|
|
|
|
class nsINode;
|
|
|
|
|
|
|
|
/**
|
2018-03-20 21:02:08 +03:00
|
|
|
* Class that implements the nsINodeList interface (a list of children of
|
|
|
|
* the content), by holding a reference to the content and delegating Length
|
2015-05-19 13:33:00 +03:00
|
|
|
* and Item to its existing child list.
|
2018-03-20 21:02:08 +03:00
|
|
|
* @see nsINodeList
|
2015-05-19 13:33:00 +03:00
|
|
|
*/
|
2017-08-21 11:11:56 +03:00
|
|
|
class nsAttrChildContentList : public nsINodeList {
|
2015-05-19 13:33:00 +03:00
|
|
|
public:
|
2017-08-11 05:12:17 +03:00
|
|
|
explicit nsAttrChildContentList(nsINode* aNode) : mNode(aNode) {}
|
2015-05-19 13:33:00 +03:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2017-08-11 05:12:17 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsAttrChildContentList)
|
2015-05-19 13:33:00 +03:00
|
|
|
|
|
|
|
// nsWrapperCache
|
2017-08-11 05:12:17 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2015-05-19 13:33:00 +03:00
|
|
|
|
|
|
|
// nsINodeList interface
|
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t Length() override;
|
2019-06-25 09:56:23 +03:00
|
|
|
nsINode* GetParentObject() final { return mNode; }
|
2015-05-19 13:33:00 +03:00
|
|
|
|
2019-06-25 09:56:23 +03:00
|
|
|
virtual void InvalidateCacheIfAvailable() {}
|
2015-05-19 13:33:00 +03:00
|
|
|
|
2017-08-21 11:11:56 +03:00
|
|
|
protected:
|
|
|
|
virtual ~nsAttrChildContentList() {}
|
2017-10-13 07:05:54 +03:00
|
|
|
|
2017-08-21 11:11:56 +03:00
|
|
|
private:
|
2015-05-19 13:33:00 +03:00
|
|
|
// The node whose children make up the list.
|
2019-06-25 09:56:23 +03:00
|
|
|
RefPtr<nsINode> mNode;
|
2015-05-19 13:33:00 +03:00
|
|
|
};
|
|
|
|
|
2017-08-21 11:11:56 +03:00
|
|
|
class nsParentNodeChildContentList final : public nsAttrChildContentList {
|
|
|
|
public:
|
|
|
|
explicit nsParentNodeChildContentList(nsINode* aNode)
|
|
|
|
: nsAttrChildContentList(aNode), mIsCacheValid(false) {
|
|
|
|
ValidateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsINodeList interface
|
|
|
|
virtual int32_t IndexOf(nsIContent* aContent) override;
|
|
|
|
virtual nsIContent* Item(uint32_t aIndex) override;
|
2018-03-20 21:02:08 +03:00
|
|
|
uint32_t Length() override;
|
2017-08-21 11:11:56 +03:00
|
|
|
|
2019-06-25 09:56:23 +03:00
|
|
|
void InvalidateCacheIfAvailable() final { InvalidateCache(); }
|
2017-08-21 11:11:56 +03:00
|
|
|
|
|
|
|
void InvalidateCache() {
|
|
|
|
mIsCacheValid = false;
|
|
|
|
mCachedChildArray.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsParentNodeChildContentList() {}
|
|
|
|
|
|
|
|
// Return true if validation succeeds, false otherwise
|
|
|
|
bool ValidateCache();
|
|
|
|
|
|
|
|
// Whether cached array of child nodes is valid
|
|
|
|
bool mIsCacheValid;
|
|
|
|
|
|
|
|
// Cached array of child nodes
|
|
|
|
AutoTArray<nsIContent*, 8> mCachedChildArray;
|
|
|
|
};
|
|
|
|
|
2015-05-19 13:33:00 +03:00
|
|
|
#endif /* nsChildContentList_h__ */
|