Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_HTMLContentElement_h__
8 : #define mozilla_dom_HTMLContentElement_h__
9 :
10 : #include "nsAutoPtr.h"
11 : #include "nsINodeList.h"
12 : #include "nsGenericHTMLElement.h"
13 :
14 : struct nsCSSSelectorList;
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class DistributedContentList;
20 :
21 : class HTMLContentElement final : public nsGenericHTMLElement
22 : {
23 : public:
24 : explicit HTMLContentElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
25 :
26 : // nsISupports
27 : NS_DECL_ISUPPORTS_INHERITED
28 :
29 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLContentElement,
30 : nsGenericHTMLElement)
31 :
32 9479 : static HTMLContentElement* FromContent(nsIContent* aContent)
33 : {
34 9479 : if (aContent->IsHTMLContentElement()) {
35 0 : return static_cast<HTMLContentElement*>(aContent);
36 : }
37 :
38 9479 : return nullptr;
39 : }
40 :
41 0 : virtual bool IsHTMLContentElement() const override { return true; }
42 :
43 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
44 : bool aPreallocateChildren) const override;
45 :
46 0 : virtual nsIDOMNode* AsDOMNode() override { return this; }
47 :
48 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
49 : nsIContent* aBindingParent,
50 : bool aCompileEventHandlers) override;
51 :
52 : virtual void UnbindFromTree(bool aDeep = true,
53 : bool aNullParent = true) override;
54 :
55 : /**
56 : * Returns whether if the selector of this insertion point
57 : * matches the provided content.
58 : */
59 : bool Match(nsIContent* aContent);
60 0 : bool IsInsertionPoint() const { return mIsInsertionPoint; }
61 0 : nsCOMArray<nsIContent>& MatchedNodes() { return mMatchedNodes; }
62 : void AppendMatchedNode(nsIContent* aContent);
63 : void RemoveMatchedNode(nsIContent* aContent);
64 : void InsertMatchedNode(uint32_t aIndex, nsIContent* aContent);
65 : void ClearMatchedNodes();
66 :
67 : // WebIDL methods.
68 : already_AddRefed<DistributedContentList> GetDistributedNodes();
69 0 : void GetSelect(nsAString& aSelect)
70 : {
71 0 : Element::GetAttr(kNameSpaceID_None, nsGkAtoms::select, aSelect);
72 0 : }
73 0 : void SetSelect(const nsAString& aSelect)
74 : {
75 0 : Element::SetAttr(kNameSpaceID_None, nsGkAtoms::select, aSelect, true);
76 0 : }
77 :
78 : protected:
79 : virtual ~HTMLContentElement();
80 :
81 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
82 :
83 : /**
84 : * Updates the destination insertion points of the fallback
85 : * content of this insertion point. If there are nodes matched
86 : * to this insertion point, then destination insertion points
87 : * of fallback are cleared, otherwise, this insertion point
88 : * is a destination insertion point.
89 : */
90 : void UpdateFallbackDistribution();
91 :
92 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
93 : const nsAttrValue* aValue,
94 : const nsAttrValue* aOldValue,
95 : bool aNotify) override;
96 :
97 : /**
98 : * An array of nodes from the ShadowRoot host that match the
99 : * content insertion selector.
100 : */
101 : nsCOMArray<nsIContent> mMatchedNodes;
102 :
103 : nsAutoPtr<nsCSSSelectorList> mSelectorList;
104 : bool mValidSelector;
105 : bool mIsInsertionPoint;
106 : };
107 :
108 : class DistributedContentList : public nsINodeList
109 : {
110 : public:
111 : explicit DistributedContentList(HTMLContentElement* aHostElement);
112 :
113 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
114 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DistributedContentList)
115 :
116 : // nsIDOMNodeList
117 : NS_DECL_NSIDOMNODELIST
118 :
119 : // nsINodeList
120 : virtual nsIContent* Item(uint32_t aIndex) override;
121 : virtual int32_t IndexOf(nsIContent* aContent) override;
122 0 : virtual nsINode* GetParentObject() override { return mParent; }
123 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
124 : protected:
125 : virtual ~DistributedContentList();
126 : RefPtr<HTMLContentElement> mParent;
127 : nsCOMArray<nsIContent> mDistributedNodes;
128 : };
129 :
130 : } // namespace dom
131 : } // namespace mozilla
132 :
133 : #endif // mozilla_dom_HTMLContentElement_h__
134 :
|