|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=2 et : |
|
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_DocumentFragment_h__ |
|
8 #define mozilla_dom_DocumentFragment_h__ |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "mozilla/dom/FragmentOrElement.h" |
|
12 #include "nsIDOMDocumentFragment.h" |
|
13 |
|
14 class nsINodeInfo; |
|
15 class nsIAtom; |
|
16 class nsAString; |
|
17 class nsIDocument; |
|
18 class nsIContent; |
|
19 |
|
20 namespace mozilla { |
|
21 namespace dom { |
|
22 |
|
23 class Element; |
|
24 |
|
25 class DocumentFragment : public FragmentOrElement, |
|
26 public nsIDOMDocumentFragment |
|
27 { |
|
28 private: |
|
29 void Init() |
|
30 { |
|
31 NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == |
|
32 nsIDOMNode::DOCUMENT_FRAGMENT_NODE && |
|
33 mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName, |
|
34 kNameSpaceID_None), |
|
35 "Bad NodeType in aNodeInfo"); |
|
36 } |
|
37 |
|
38 public: |
|
39 using FragmentOrElement::GetFirstChild; |
|
40 using nsINode::QuerySelector; |
|
41 using nsINode::QuerySelectorAll; |
|
42 // Make sure bindings can see our superclass' protected GetElementById method. |
|
43 using nsINode::GetElementById; |
|
44 |
|
45 // nsISupports |
|
46 NS_DECL_ISUPPORTS_INHERITED |
|
47 |
|
48 // interface nsIDOMNode |
|
49 NS_FORWARD_NSIDOMNODE_TO_NSINODE |
|
50 |
|
51 // interface nsIDOMDocumentFragment |
|
52 NS_DECL_NSIDOMDOCUMENTFRAGMENT |
|
53 |
|
54 DocumentFragment(already_AddRefed<nsINodeInfo>& aNodeInfo) |
|
55 : FragmentOrElement(aNodeInfo), mHost(nullptr) |
|
56 { |
|
57 Init(); |
|
58 } |
|
59 |
|
60 DocumentFragment(nsNodeInfoManager* aNodeInfoManager) |
|
61 : FragmentOrElement(aNodeInfoManager->GetNodeInfo( |
|
62 nsGkAtoms::documentFragmentNodeName, |
|
63 nullptr, kNameSpaceID_None, |
|
64 nsIDOMNode::DOCUMENT_FRAGMENT_NODE)), |
|
65 mHost(nullptr) |
|
66 { |
|
67 Init(); |
|
68 } |
|
69 |
|
70 virtual ~DocumentFragment() |
|
71 { |
|
72 } |
|
73 |
|
74 virtual JSObject* WrapNode(JSContext *aCx) MOZ_OVERRIDE; |
|
75 |
|
76 // nsIContent |
|
77 nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, |
|
78 const nsAString& aValue, bool aNotify) |
|
79 { |
|
80 return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); |
|
81 } |
|
82 virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, |
|
83 nsIAtom* aPrefix, const nsAString& aValue, |
|
84 bool aNotify) MOZ_OVERRIDE |
|
85 { |
|
86 return NS_OK; |
|
87 } |
|
88 virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, |
|
89 bool aNotify) MOZ_OVERRIDE |
|
90 { |
|
91 return NS_OK; |
|
92 } |
|
93 virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const MOZ_OVERRIDE |
|
94 { |
|
95 return nullptr; |
|
96 } |
|
97 virtual uint32_t GetAttrCount() const MOZ_OVERRIDE |
|
98 { |
|
99 return 0; |
|
100 } |
|
101 |
|
102 virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE; |
|
103 |
|
104 virtual nsIDOMNode* AsDOMNode() MOZ_OVERRIDE { return this; } |
|
105 |
|
106 virtual nsIAtom* DoGetID() const MOZ_OVERRIDE; |
|
107 virtual nsIAtom *GetIDAttributeName() const MOZ_OVERRIDE; |
|
108 |
|
109 virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, |
|
110 nsIContent* aBindingParent, |
|
111 bool aCompileEventHandlers) MOZ_OVERRIDE |
|
112 { |
|
113 NS_ASSERTION(false, "Trying to bind a fragment to a tree"); |
|
114 return NS_ERROR_NOT_IMPLEMENTED; |
|
115 } |
|
116 |
|
117 virtual void UnbindFromTree(bool aDeep, bool aNullParent) MOZ_OVERRIDE |
|
118 { |
|
119 NS_ASSERTION(false, "Trying to unbind a fragment from a tree"); |
|
120 return; |
|
121 } |
|
122 |
|
123 virtual Element* GetNameSpaceElement() |
|
124 { |
|
125 return nullptr; |
|
126 } |
|
127 |
|
128 nsIContent* GetHost() const |
|
129 { |
|
130 return mHost; |
|
131 } |
|
132 |
|
133 void SetHost(nsIContent* aHost) |
|
134 { |
|
135 mHost = aHost; |
|
136 } |
|
137 |
|
138 static already_AddRefed<DocumentFragment> |
|
139 Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); |
|
140 |
|
141 #ifdef DEBUG |
|
142 virtual void List(FILE* out, int32_t aIndent) const MOZ_OVERRIDE; |
|
143 virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const MOZ_OVERRIDE; |
|
144 #endif |
|
145 |
|
146 protected: |
|
147 nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE; |
|
148 nsIContent* mHost; // Weak |
|
149 }; |
|
150 |
|
151 } // namespace dom |
|
152 } // namespace mozilla |
|
153 |
|
154 |
|
155 #endif // mozilla_dom_DocumentFragment_h__ |