/src/mozilla-central/dom/xbl/nsXBLBinding.h
Line | Count | Source (jump to first uncovered line) |
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 nsXBLBinding_h_ |
8 | | #define nsXBLBinding_h_ |
9 | | |
10 | | #include "nsXBLService.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsINodeList.h" |
13 | | #include "nsClassHashtable.h" |
14 | | #include "nsTArray.h" |
15 | | #include "nsCycleCollectionParticipant.h" |
16 | | #include "nsISupportsImpl.h" |
17 | | #include "js/TypeDecls.h" |
18 | | |
19 | | class nsXBLPrototypeBinding; |
20 | | class nsIContent; |
21 | | class nsAtom; |
22 | | class nsIDocument; |
23 | | struct RawServoAuthorStyles; |
24 | | |
25 | | namespace mozilla { |
26 | | namespace dom { |
27 | | |
28 | | class XBLChildrenElement; |
29 | | |
30 | | } // namespace dom |
31 | | } // namespace mozilla |
32 | | |
33 | | class nsAnonymousContentList; |
34 | | |
35 | | // *********************************************************************/ |
36 | | // The XBLBinding class |
37 | | |
38 | | class nsXBLBinding final |
39 | | { |
40 | | public: |
41 | | explicit nsXBLBinding(nsXBLPrototypeBinding* aProtoBinding); |
42 | | |
43 | | /** |
44 | | * XBLBindings are refcounted. They are held onto in 3 ways: |
45 | | * 1. The binding manager's binding table holds onto all bindings that are |
46 | | * currently attached to a content node. |
47 | | * 2. Bindings hold onto their base binding. This is important since |
48 | | * the base binding itself may not be attached to anything. |
49 | | * 3. The binding manager holds an additional reference to bindings |
50 | | * which are queued to fire their constructors. |
51 | | */ |
52 | | |
53 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLBinding) |
54 | | |
55 | | NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding) |
56 | | |
57 | 0 | nsXBLPrototypeBinding* PrototypeBinding() const { return mPrototypeBinding; } |
58 | 0 | nsIContent* GetAnonymousContent() { return mContent.get(); } |
59 | | nsXBLBinding* GetBindingWithContent(); |
60 | | |
61 | 0 | nsXBLBinding* GetBaseBinding() const { return mNextBinding; } |
62 | | void SetBaseBinding(nsXBLBinding *aBinding); |
63 | | |
64 | 0 | mozilla::dom::Element* GetBoundElement() { return mBoundElement; } |
65 | | void SetBoundElement(mozilla::dom::Element* aElement); |
66 | | |
67 | | /* |
68 | | * Does a lookup for a method or attribute provided by one of the bindings' |
69 | | * prototype implementation. If found, |desc| will be set up appropriately, |
70 | | * and wrapped into cx->compartment. |
71 | | * |
72 | | * May only be called when XBL code is being run in a separate scope, because |
73 | | * otherwise we don't have untainted data with which to do a proper lookup. |
74 | | */ |
75 | | bool LookupMember(JSContext* aCx, JS::Handle<jsid> aId, |
76 | | JS::MutableHandle<JS::PropertyDescriptor> aDesc); |
77 | | |
78 | | /* |
79 | | * Determines whether the binding has a field with the given name. |
80 | | */ |
81 | | bool HasField(nsString& aName); |
82 | | |
83 | | protected: |
84 | | |
85 | | ~nsXBLBinding(); |
86 | | |
87 | | /* |
88 | | * Internal version. Requires that aCx is in appropriate xbl scope. |
89 | | */ |
90 | | bool LookupMemberInternal(JSContext* aCx, nsString& aName, |
91 | | JS::Handle<jsid> aNameAsId, |
92 | | JS::MutableHandle<JS::PropertyDescriptor> aDesc, |
93 | | JS::Handle<JSObject*> aXBLScope); |
94 | | |
95 | | public: |
96 | | |
97 | | void MarkForDeath(); |
98 | 0 | bool MarkedForDeath() const { return mMarkedForDeath; } |
99 | | |
100 | | bool HasStyleSheets() const; |
101 | | bool InheritsStyle() const; |
102 | | bool ImplementsInterface(REFNSIID aIID) const; |
103 | | |
104 | | void GenerateAnonymousContent(); |
105 | | void BindAnonymousContent(nsIContent* aAnonParent, nsIContent* aElement, |
106 | | bool aNativeAnon); |
107 | | static void UnbindAnonymousContent(nsIDocument* aDocument, |
108 | | nsIContent* aAnonParent, |
109 | | bool aNullParent = true); |
110 | | void InstallEventHandlers(); |
111 | | nsresult InstallImplementation(); |
112 | | |
113 | | void ExecuteAttachedHandler(); |
114 | | void ExecuteDetachedHandler(); |
115 | | void UnhookEventHandlers(); |
116 | | |
117 | | nsAtom* GetBaseTag(int32_t* aNameSpaceID); |
118 | | nsXBLBinding* RootBinding(); |
119 | | |
120 | | // Resolve all the fields for this binding and all ancestor bindings on the |
121 | | // object |obj|. False return means a JS exception was set. |
122 | | bool ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const; |
123 | | |
124 | | void AttributeChanged(nsAtom* aAttribute, int32_t aNameSpaceID, |
125 | | bool aRemoveFlag, bool aNotify); |
126 | | |
127 | | void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument); |
128 | | |
129 | | |
130 | | const RawServoAuthorStyles* GetServoStyles() const; |
131 | | |
132 | | static nsresult DoInitJSClass(JSContext *cx, JS::Handle<JSObject*> obj, |
133 | | const nsString& aClassName, |
134 | | nsXBLPrototypeBinding* aProtoBinding, |
135 | | JS::MutableHandle<JSObject*> aClassObject, |
136 | | bool* aNew); |
137 | | |
138 | | bool AllowScripts(); |
139 | | |
140 | | mozilla::dom::XBLChildrenElement* FindInsertionPointFor(nsIContent* aChild); |
141 | | |
142 | | bool HasFilteredInsertionPoints() |
143 | 0 | { |
144 | 0 | return !mInsertionPoints.IsEmpty(); |
145 | 0 | } |
146 | | |
147 | | mozilla::dom::XBLChildrenElement* GetDefaultInsertionPoint() |
148 | 0 | { |
149 | 0 | return mDefaultInsertionPoint; |
150 | 0 | } |
151 | | |
152 | | // Removes all inserted node from <xbl:children> insertion points under us. |
153 | | void ClearInsertionPoints(); |
154 | | |
155 | | // Returns a live node list that iterates over the anonymous nodes generated |
156 | | // by this binding. |
157 | | nsAnonymousContentList* GetAnonymousNodeList(); |
158 | | |
159 | | nsIURI* GetSourceDocURI(); |
160 | | |
161 | | // MEMBER VARIABLES |
162 | | protected: |
163 | | |
164 | | bool mMarkedForDeath; |
165 | | bool mUsingContentXBLScope; |
166 | | |
167 | | nsXBLPrototypeBinding* mPrototypeBinding; // Weak, but we're holding a ref to the docinfo |
168 | | nsCOMPtr<nsIContent> mContent; // Strong. Our anonymous content stays around with us. |
169 | | RefPtr<nsXBLBinding> mNextBinding; // Strong. The derived binding owns the base class bindings. |
170 | | |
171 | | mozilla::dom::Element* mBoundElement; // [WEAK] We have a reference, but we don't own it. |
172 | | |
173 | | // The <xbl:children> elements that we found in our <xbl:content> when we |
174 | | // processed this binding. The default insertion point has no includes |
175 | | // attribute and all other insertion points must have at least one includes |
176 | | // attribute. These points must be up-to-date with respect to their parent's |
177 | | // children, even if their parent has another binding attached to it, |
178 | | // preventing us from rendering their contents directly. |
179 | | RefPtr<mozilla::dom::XBLChildrenElement> mDefaultInsertionPoint; |
180 | | nsTArray<RefPtr<mozilla::dom::XBLChildrenElement> > mInsertionPoints; |
181 | | RefPtr<nsAnonymousContentList> mAnonymousContentList; |
182 | | |
183 | | mozilla::dom::XBLChildrenElement* FindInsertionPointForInternal(nsIContent* aChild); |
184 | | }; |
185 | | |
186 | | #endif // nsXBLBinding_h_ |