|
|
8 |
#define nsChildContentList_h__ |
8 |
#define nsChildContentList_h__ |
9 |
|
9 |
|
10 |
#include "nsISupportsImpl.h" |
10 |
#include "nsISupportsImpl.h" |
11 |
#include "nsINodeList.h" // base class |
11 |
#include "nsINodeList.h" // base class |
12 |
#include "js/TypeDecls.h" // for Handle, Value, JSObject, JSContext |
12 |
#include "js/TypeDecls.h" // for Handle, Value, JSObject, JSContext |
13 |
|
13 |
|
14 |
class nsIContent; |
14 |
class nsIContent; |
Lines 20-26
class nsINode;
|
Link Here
|
---|
|
20 |
* and Item to its existing child list. |
20 |
* and Item to its existing child list. |
21 |
* @see nsIDOMNodeList |
21 |
* @see nsIDOMNodeList |
22 |
*/ |
22 |
*/ |
23 |
class nsAttrChildContentList : public nsINodeList |
23 |
class nsAttrChildContentList final : public nsINodeList |
24 |
{ |
24 |
{ |
25 |
public: |
25 |
public: |
26 |
explicit nsAttrChildContentList(nsINode* aNode) |
26 |
explicit nsAttrChildContentList(nsINode* aNode) |
Lines 42-48
public:
|
Link Here
|
---|
|
42 |
virtual int32_t IndexOf(nsIContent* aContent) override; |
42 |
virtual int32_t IndexOf(nsIContent* aContent) override; |
43 |
virtual nsIContent* Item(uint32_t aIndex) override; |
43 |
virtual nsIContent* Item(uint32_t aIndex) override; |
44 |
|
44 |
|
45 |
virtual void DropReference() |
45 |
void DropReference() |
46 |
{ |
46 |
{ |
47 |
mNode = nullptr; |
47 |
mNode = nullptr; |
48 |
} |
48 |
} |
Lines 52-107
public:
|
Link Here
|
---|
|
52 |
return mNode; |
52 |
return mNode; |
53 |
} |
53 |
} |
54 |
|
54 |
|
55 |
protected: |
55 |
private: |
56 |
virtual ~nsAttrChildContentList() {} |
56 |
~nsAttrChildContentList() {} |
57 |
|
57 |
|
58 |
private: |
|
|
59 |
// The node whose children make up the list. |
58 |
// The node whose children make up the list. |
60 |
// This is a non-owning ref which is safe because it's set to nullptr by |
59 |
// This is a non-owning ref which is safe because it's set to nullptr by |
61 |
// DropReference() by the node slots get destroyed. |
60 |
// DropReference() by the node slots get destroyed. |
62 |
nsINode* MOZ_NON_OWNING_REF mNode; |
61 |
nsINode* MOZ_NON_OWNING_REF mNode; |
63 |
}; |
62 |
}; |
64 |
|
63 |
|
65 |
class nsParentNodeChildContentList final : public nsAttrChildContentList |
|
|
66 |
{ |
67 |
public: |
68 |
explicit nsParentNodeChildContentList(nsINode* aNode) |
69 |
: nsAttrChildContentList(aNode) |
70 |
, mIsCacheValid(false) |
71 |
{ |
72 |
ValidateCache(); |
73 |
} |
74 |
|
75 |
// nsIDOMNodeList interface |
76 |
NS_DECL_NSIDOMNODELIST |
77 |
|
78 |
// nsINodeList interface |
79 |
virtual int32_t IndexOf(nsIContent* aContent) override; |
80 |
virtual nsIContent* Item(uint32_t aIndex) override; |
81 |
|
82 |
void DropReference() override |
83 |
{ |
84 |
InvalidateCache(); |
85 |
nsAttrChildContentList::DropReference(); |
86 |
} |
87 |
|
88 |
void InvalidateCache() |
89 |
{ |
90 |
mIsCacheValid = false; |
91 |
mCachedChildArray.Clear(); |
92 |
} |
93 |
|
94 |
private: |
95 |
~nsParentNodeChildContentList() {} |
96 |
|
97 |
// Return true if validation succeeds, false otherwise |
98 |
bool ValidateCache(); |
99 |
|
100 |
// Whether cached array of child nodes is valid |
101 |
bool mIsCacheValid; |
102 |
|
103 |
// Cached array of child nodes |
104 |
AutoTArray<nsIContent*, 8> mCachedChildArray; |
105 |
}; |
106 |
|
107 |
#endif /* nsChildContentList_h__ */ |
64 |
#endif /* nsChildContentList_h__ */ |