/src/mozilla-central/dom/xul/nsXULElement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | /* |
7 | | |
8 | | The base XUL element class and associates. |
9 | | |
10 | | */ |
11 | | |
12 | | #ifndef nsXULElement_h__ |
13 | | #define nsXULElement_h__ |
14 | | |
15 | | #include "js/TracingAPI.h" |
16 | | #include "mozilla/Attributes.h" |
17 | | #include "nsIServiceManager.h" |
18 | | #include "nsAtom.h" |
19 | | #include "mozilla/dom/NodeInfo.h" |
20 | | #include "nsIControllers.h" |
21 | | #include "nsIDOMXULMultSelectCntrlEl.h" |
22 | | #include "nsIURI.h" |
23 | | #include "nsLayoutCID.h" |
24 | | #include "AttrArray.h" |
25 | | #include "nsGkAtoms.h" |
26 | | #include "nsStringFwd.h" |
27 | | #include "nsStyledElement.h" |
28 | | #include "mozilla/dom/DOMRect.h" |
29 | | #include "mozilla/dom/Element.h" |
30 | | #include "mozilla/dom/DOMString.h" |
31 | | #include "mozilla/dom/FromParser.h" |
32 | | |
33 | | class nsIDocument; |
34 | | class nsXULPrototypeDocument; |
35 | | |
36 | | class nsIObjectInputStream; |
37 | | class nsIObjectOutputStream; |
38 | | class nsIOffThreadScriptReceiver; |
39 | | class nsXULPrototypeNode; |
40 | | typedef nsTArray<RefPtr<nsXULPrototypeNode> > nsPrototypeArray; |
41 | | |
42 | | namespace mozilla { |
43 | | class EventChainPreVisitor; |
44 | | class EventListenerManager; |
45 | | namespace css { |
46 | | class StyleRule; |
47 | | } // namespace css |
48 | | namespace dom { |
49 | | class BoxObject; |
50 | | class HTMLIFrameElement; |
51 | | enum class CallerType : uint32_t; |
52 | | } // namespace dom |
53 | | } // namespace mozilla |
54 | | |
55 | | namespace JS { |
56 | | class SourceBufferHolder; |
57 | | } // namespace JS |
58 | | |
59 | | //////////////////////////////////////////////////////////////////////// |
60 | | |
61 | | #ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING |
62 | | #define XUL_PROTOTYPE_ATTRIBUTE_METER(counter) (nsXULPrototypeAttribute::counter++) |
63 | | #else |
64 | 0 | #define XUL_PROTOTYPE_ATTRIBUTE_METER(counter) ((void) 0) |
65 | | #endif |
66 | | |
67 | | |
68 | | /** |
69 | | |
70 | | A prototype attribute for an nsXULPrototypeElement. |
71 | | |
72 | | */ |
73 | | |
74 | | class nsXULPrototypeAttribute |
75 | | { |
76 | | public: |
77 | | nsXULPrototypeAttribute() |
78 | | : mName(nsGkAtoms::id) // XXX this is a hack, but names have to have a value |
79 | 0 | { |
80 | 0 | XUL_PROTOTYPE_ATTRIBUTE_METER(gNumAttributes); |
81 | 0 | MOZ_COUNT_CTOR(nsXULPrototypeAttribute); |
82 | 0 | } |
83 | | |
84 | | ~nsXULPrototypeAttribute(); |
85 | | |
86 | | nsAttrName mName; |
87 | | nsAttrValue mValue; |
88 | | |
89 | | #ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING |
90 | | static uint32_t gNumElements; |
91 | | static uint32_t gNumAttributes; |
92 | | static uint32_t gNumCacheTests; |
93 | | static uint32_t gNumCacheHits; |
94 | | static uint32_t gNumCacheSets; |
95 | | static uint32_t gNumCacheFills; |
96 | | #endif /* !XUL_PROTOTYPE_ATTRIBUTE_METERING */ |
97 | | }; |
98 | | |
99 | | |
100 | | /** |
101 | | |
102 | | A prototype content model element that holds the "primordial" values |
103 | | that have been parsed from the original XUL document. |
104 | | |
105 | | */ |
106 | | |
107 | | class nsXULPrototypeNode |
108 | | { |
109 | | public: |
110 | | enum Type { eType_Element, eType_Script, eType_Text, eType_PI }; |
111 | | |
112 | | Type mType; |
113 | | |
114 | | virtual nsresult Serialize(nsIObjectOutputStream* aStream, |
115 | | nsXULPrototypeDocument* aProtoDoc, |
116 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) = 0; |
117 | | virtual nsresult Deserialize(nsIObjectInputStream* aStream, |
118 | | nsXULPrototypeDocument* aProtoDoc, |
119 | | nsIURI* aDocumentURI, |
120 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) = 0; |
121 | | |
122 | | /** |
123 | | * The prototype document must call ReleaseSubtree when it is going |
124 | | * away. This makes the parents through the tree stop owning their |
125 | | * children, whether or not the parent's reference count is zero. |
126 | | * Individual elements may still own individual prototypes, but |
127 | | * those prototypes no longer remember their children to allow them |
128 | | * to be constructed. |
129 | | */ |
130 | 0 | virtual void ReleaseSubtree() { } |
131 | | |
132 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsXULPrototypeNode) |
133 | | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXULPrototypeNode) |
134 | | |
135 | | protected: |
136 | | explicit nsXULPrototypeNode(Type aType) |
137 | 0 | : mType(aType) {} |
138 | 0 | virtual ~nsXULPrototypeNode() {} |
139 | | }; |
140 | | |
141 | | class nsXULPrototypeElement : public nsXULPrototypeNode |
142 | | { |
143 | | public: |
144 | | nsXULPrototypeElement() |
145 | | : nsXULPrototypeNode(eType_Element), |
146 | | mNumAttributes(0), |
147 | | mHasIdAttribute(false), |
148 | | mHasClassAttribute(false), |
149 | | mHasStyleAttribute(false), |
150 | | mAttributes(nullptr), |
151 | | mIsAtom(nullptr) |
152 | 0 | { |
153 | 0 | } |
154 | | |
155 | | virtual ~nsXULPrototypeElement() |
156 | 0 | { |
157 | 0 | Unlink(); |
158 | 0 | } |
159 | | |
160 | | virtual void ReleaseSubtree() override |
161 | 0 | { |
162 | 0 | for (int32_t i = mChildren.Length() - 1; i >= 0; i--) { |
163 | 0 | if (mChildren[i].get()) |
164 | 0 | mChildren[i]->ReleaseSubtree(); |
165 | 0 | } |
166 | 0 | mChildren.Clear(); |
167 | 0 | nsXULPrototypeNode::ReleaseSubtree(); |
168 | 0 | } |
169 | | |
170 | | virtual nsresult Serialize(nsIObjectOutputStream* aStream, |
171 | | nsXULPrototypeDocument* aProtoDoc, |
172 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
173 | | virtual nsresult Deserialize(nsIObjectInputStream* aStream, |
174 | | nsXULPrototypeDocument* aProtoDoc, |
175 | | nsIURI* aDocumentURI, |
176 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
177 | | |
178 | | nsresult SetAttrAt(uint32_t aPos, const nsAString& aValue, nsIURI* aDocumentURI); |
179 | | |
180 | | void Unlink(); |
181 | | |
182 | | // Trace all scripts held by this element and its children. |
183 | | void TraceAllScripts(JSTracer* aTrc); |
184 | | |
185 | | nsPrototypeArray mChildren; |
186 | | |
187 | | RefPtr<mozilla::dom::NodeInfo> mNodeInfo; |
188 | | |
189 | | uint32_t mNumAttributes:29; |
190 | | uint32_t mHasIdAttribute:1; |
191 | | uint32_t mHasClassAttribute:1; |
192 | | uint32_t mHasStyleAttribute:1; |
193 | | nsXULPrototypeAttribute* mAttributes; // [OWNER] |
194 | | RefPtr<nsAtom> mIsAtom; |
195 | | }; |
196 | | |
197 | | namespace mozilla { |
198 | | namespace dom { |
199 | | class XULDocument; |
200 | | } // namespace dom |
201 | | } // namespace mozilla |
202 | | |
203 | | class nsXULPrototypeScript : public nsXULPrototypeNode |
204 | | { |
205 | | public: |
206 | | explicit nsXULPrototypeScript(uint32_t aLineNo); |
207 | | virtual ~nsXULPrototypeScript(); |
208 | | |
209 | | virtual nsresult Serialize(nsIObjectOutputStream* aStream, |
210 | | nsXULPrototypeDocument* aProtoDoc, |
211 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
212 | | nsresult SerializeOutOfLine(nsIObjectOutputStream* aStream, |
213 | | nsXULPrototypeDocument* aProtoDoc); |
214 | | virtual nsresult Deserialize(nsIObjectInputStream* aStream, |
215 | | nsXULPrototypeDocument* aProtoDoc, |
216 | | nsIURI* aDocumentURI, |
217 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
218 | | nsresult DeserializeOutOfLine(nsIObjectInputStream* aInput, |
219 | | nsXULPrototypeDocument* aProtoDoc); |
220 | | |
221 | | nsresult Compile(JS::SourceBufferHolder& aSrcBuf, |
222 | | nsIURI* aURI, uint32_t aLineNo, |
223 | | nsIDocument* aDocument, |
224 | | nsIOffThreadScriptReceiver *aOffThreadReceiver = nullptr); |
225 | | |
226 | | nsresult Compile(const char16_t* aText, int32_t aTextLength, |
227 | | nsIURI* aURI, uint32_t aLineNo, |
228 | | nsIDocument* aDocument, |
229 | | nsIOffThreadScriptReceiver *aOffThreadReceiver = nullptr); |
230 | | |
231 | | void UnlinkJSObjects(); |
232 | | |
233 | | void Set(JSScript* aObject); |
234 | | |
235 | | bool HasScriptObject() |
236 | 0 | { |
237 | 0 | // Conversion to bool doesn't trigger mScriptObject's read barrier. |
238 | 0 | return mScriptObject; |
239 | 0 | } |
240 | | |
241 | | JSScript* GetScriptObject() |
242 | 0 | { |
243 | 0 | return mScriptObject; |
244 | 0 | } |
245 | | |
246 | | void TraceScriptObject(JSTracer* aTrc) |
247 | 0 | { |
248 | 0 | JS::TraceEdge(aTrc, &mScriptObject, "active window XUL prototype script"); |
249 | 0 | } |
250 | | |
251 | | void Trace(const TraceCallbacks& aCallbacks, void* aClosure) |
252 | 0 | { |
253 | 0 | if (mScriptObject) { |
254 | 0 | aCallbacks.Trace(&mScriptObject, "mScriptObject", aClosure); |
255 | 0 | } |
256 | 0 | } |
257 | | |
258 | | nsCOMPtr<nsIURI> mSrcURI; |
259 | | uint32_t mLineNo; |
260 | | bool mSrcLoading; |
261 | | bool mOutOfLine; |
262 | | mozilla::dom::XULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr |
263 | | private: |
264 | | JS::Heap<JSScript*> mScriptObject; |
265 | | }; |
266 | | |
267 | | class nsXULPrototypeText : public nsXULPrototypeNode |
268 | | { |
269 | | public: |
270 | | nsXULPrototypeText() |
271 | | : nsXULPrototypeNode(eType_Text) |
272 | 0 | { |
273 | 0 | } |
274 | | |
275 | | virtual ~nsXULPrototypeText() |
276 | 0 | { |
277 | 0 | } |
278 | | |
279 | | virtual nsresult Serialize(nsIObjectOutputStream* aStream, |
280 | | nsXULPrototypeDocument* aProtoDoc, |
281 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
282 | | virtual nsresult Deserialize(nsIObjectInputStream* aStream, |
283 | | nsXULPrototypeDocument* aProtoDoc, |
284 | | nsIURI* aDocumentURI, |
285 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
286 | | |
287 | | nsString mValue; |
288 | | }; |
289 | | |
290 | | class nsXULPrototypePI : public nsXULPrototypeNode |
291 | | { |
292 | | public: |
293 | | nsXULPrototypePI() |
294 | | : nsXULPrototypeNode(eType_PI) |
295 | 0 | { |
296 | 0 | } |
297 | | |
298 | | virtual ~nsXULPrototypePI() |
299 | 0 | { |
300 | 0 | } |
301 | | |
302 | | virtual nsresult Serialize(nsIObjectOutputStream* aStream, |
303 | | nsXULPrototypeDocument* aProtoDoc, |
304 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
305 | | virtual nsresult Deserialize(nsIObjectInputStream* aStream, |
306 | | nsXULPrototypeDocument* aProtoDoc, |
307 | | nsIURI* aDocumentURI, |
308 | | const nsTArray<RefPtr<mozilla::dom::NodeInfo>> *aNodeInfos) override; |
309 | | |
310 | | nsString mTarget; |
311 | | nsString mData; |
312 | | }; |
313 | | |
314 | | //////////////////////////////////////////////////////////////////////// |
315 | | |
316 | | /** |
317 | | |
318 | | The XUL element. |
319 | | |
320 | | */ |
321 | | |
322 | | #define XUL_ELEMENT_FLAG_BIT(n_) NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_)) |
323 | | |
324 | | // XUL element specific bits |
325 | | enum { |
326 | | XUL_ELEMENT_HAS_CONTENTMENU_LISTENER = XUL_ELEMENT_FLAG_BIT(0), |
327 | | XUL_ELEMENT_HAS_POPUP_LISTENER = XUL_ELEMENT_FLAG_BIT(1) |
328 | | }; |
329 | | |
330 | | ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 2); |
331 | | |
332 | | #undef XUL_ELEMENT_FLAG_BIT |
333 | | |
334 | | class nsXULElement : public nsStyledElement |
335 | | { |
336 | | protected: |
337 | | // Use Construct to construct elements instead of this constructor. |
338 | | explicit nsXULElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); |
339 | | |
340 | | public: |
341 | | using Element::Blur; |
342 | | using Element::Focus; |
343 | | |
344 | | static nsresult |
345 | | CreateFromPrototype(nsXULPrototypeElement* aPrototype, |
346 | | nsIDocument* aDocument, |
347 | | bool aIsScriptable, |
348 | | bool aIsRoot, |
349 | | mozilla::dom::Element** aResult); |
350 | | |
351 | | // This is the constructor for nsXULElements. |
352 | | static nsXULElement* Construct(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); |
353 | | |
354 | | NS_IMPL_FROMNODE(nsXULElement, kNameSpaceID_XUL) |
355 | | |
356 | | // nsISupports |
357 | | NS_DECL_ISUPPORTS_INHERITED |
358 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsXULElement, nsStyledElement) |
359 | | |
360 | | // nsINode |
361 | | void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override; |
362 | | virtual nsresult PreHandleEvent( |
363 | | mozilla::EventChainVisitor& aVisitor) override; |
364 | | // nsIContent |
365 | | virtual nsresult BindToTree(nsIDocument* aDocument, |
366 | | nsIContent* aParent, |
367 | | nsIContent* aBindingParent) override; |
368 | | virtual void UnbindFromTree(bool aDeep, bool aNullParent) override; |
369 | | virtual void DestroyContent() override; |
370 | | |
371 | | #ifdef DEBUG |
372 | | virtual void List(FILE* out, int32_t aIndent) const override; |
373 | | virtual void DumpContent(FILE* out, int32_t aIndent,bool aDumpAll) const override |
374 | | { |
375 | | } |
376 | | #endif |
377 | | |
378 | | bool HasMenu(); |
379 | | MOZ_CAN_RUN_SCRIPT void OpenMenu(bool aOpenFlag); |
380 | | |
381 | | virtual bool PerformAccesskey(bool aKeyCausesActivation, |
382 | | bool aIsTrustedEvent) override; |
383 | | void ClickWithInputSource(uint16_t aInputSource, bool aIsTrustedEvent); |
384 | | |
385 | | nsIContent* GetBindingParent() const final |
386 | 0 | { |
387 | 0 | return mBindingParent; |
388 | 0 | } |
389 | | |
390 | | virtual bool IsNodeOfType(uint32_t aFlags) const override; |
391 | | virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse) override; |
392 | | |
393 | | virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute, |
394 | | int32_t aModType) const override; |
395 | | NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; |
396 | | |
397 | | virtual nsresult Clone(mozilla::dom::NodeInfo*, nsINode** aResult) const override; |
398 | | virtual mozilla::EventStates IntrinsicState() const override; |
399 | | |
400 | | virtual void RecompileScriptEventListeners() override; |
401 | | |
402 | | // This function should ONLY be used by BindToTree implementations. |
403 | | // The function exists solely because XUL elements store the binding |
404 | | // parent as a member instead of in the slots, as Element does. |
405 | | void SetXULBindingParent(nsIContent* aBindingParent) |
406 | 0 | { |
407 | 0 | mBindingParent = aBindingParent; |
408 | 0 | } |
409 | | |
410 | | virtual bool IsEventAttributeNameInternal(nsAtom* aName) override; |
411 | | |
412 | | typedef mozilla::dom::DOMString DOMString; |
413 | | void GetXULAttr(nsAtom* aName, DOMString& aResult) const |
414 | 0 | { |
415 | 0 | GetAttr(kNameSpaceID_None, aName, aResult); |
416 | 0 | } |
417 | | void SetXULAttr(nsAtom* aName, const nsAString& aValue, |
418 | | mozilla::ErrorResult& aError) |
419 | 0 | { |
420 | 0 | SetAttr(aName, aValue, aError); |
421 | 0 | } |
422 | | void SetXULBoolAttr(nsAtom* aName, bool aValue) |
423 | 0 | { |
424 | 0 | if (aValue) { |
425 | 0 | SetAttr(kNameSpaceID_None, aName, NS_LITERAL_STRING("true"), true); |
426 | 0 | } else { |
427 | 0 | UnsetAttr(kNameSpaceID_None, aName, true); |
428 | 0 | } |
429 | 0 | } |
430 | | |
431 | | // WebIDL API |
432 | | void GetAlign(DOMString& aValue) const |
433 | 0 | { |
434 | 0 | GetXULAttr(nsGkAtoms::align, aValue); |
435 | 0 | } |
436 | | void SetAlign(const nsAString& aValue, mozilla::ErrorResult& rv) |
437 | 0 | { |
438 | 0 | SetXULAttr(nsGkAtoms::align, aValue, rv); |
439 | 0 | } |
440 | | void GetDir(DOMString& aValue) const |
441 | 0 | { |
442 | 0 | GetXULAttr(nsGkAtoms::dir, aValue); |
443 | 0 | } |
444 | | void SetDir(const nsAString& aValue, mozilla::ErrorResult& rv) |
445 | 0 | { |
446 | 0 | SetXULAttr(nsGkAtoms::dir, aValue, rv); |
447 | 0 | } |
448 | | void GetFlex(DOMString& aValue) const |
449 | 0 | { |
450 | 0 | GetXULAttr(nsGkAtoms::flex, aValue); |
451 | 0 | } |
452 | | void SetFlex(const nsAString& aValue, mozilla::ErrorResult& rv) |
453 | 0 | { |
454 | 0 | SetXULAttr(nsGkAtoms::flex, aValue, rv); |
455 | 0 | } |
456 | | void GetOrdinal(DOMString& aValue) const |
457 | 0 | { |
458 | 0 | GetXULAttr(nsGkAtoms::ordinal, aValue); |
459 | 0 | } |
460 | | void SetOrdinal(const nsAString& aValue, mozilla::ErrorResult& rv) |
461 | 0 | { |
462 | 0 | SetXULAttr(nsGkAtoms::ordinal, aValue, rv); |
463 | 0 | } |
464 | | void GetOrient(DOMString& aValue) const |
465 | 0 | { |
466 | 0 | GetXULAttr(nsGkAtoms::orient, aValue); |
467 | 0 | } |
468 | | void SetOrient(const nsAString& aValue, mozilla::ErrorResult& rv) |
469 | 0 | { |
470 | 0 | SetXULAttr(nsGkAtoms::orient, aValue, rv); |
471 | 0 | } |
472 | | void GetPack(DOMString& aValue) const |
473 | 0 | { |
474 | 0 | GetXULAttr(nsGkAtoms::pack, aValue); |
475 | 0 | } |
476 | | void SetPack(const nsAString& aValue, mozilla::ErrorResult& rv) |
477 | 0 | { |
478 | 0 | SetXULAttr(nsGkAtoms::pack, aValue, rv); |
479 | 0 | } |
480 | | bool Hidden() const |
481 | 0 | { |
482 | 0 | return BoolAttrIsTrue(nsGkAtoms::hidden); |
483 | 0 | } |
484 | | void SetHidden(bool aHidden) |
485 | 0 | { |
486 | 0 | SetXULBoolAttr(nsGkAtoms::hidden, aHidden); |
487 | 0 | } |
488 | | bool Collapsed() const |
489 | 0 | { |
490 | 0 | return BoolAttrIsTrue(nsGkAtoms::collapsed); |
491 | 0 | } |
492 | | void SetCollapsed(bool aCollapsed) |
493 | 0 | { |
494 | 0 | SetXULBoolAttr(nsGkAtoms::collapsed, aCollapsed); |
495 | 0 | } |
496 | | void GetObserves(DOMString& aValue) const |
497 | 0 | { |
498 | 0 | GetXULAttr(nsGkAtoms::observes, aValue); |
499 | 0 | } |
500 | | void SetObserves(const nsAString& aValue, mozilla::ErrorResult& rv) |
501 | 0 | { |
502 | 0 | SetXULAttr(nsGkAtoms::observes, aValue, rv); |
503 | 0 | } |
504 | | void GetMenu(DOMString& aValue) const |
505 | 0 | { |
506 | 0 | GetXULAttr(nsGkAtoms::menu, aValue); |
507 | 0 | } |
508 | | void SetMenu(const nsAString& aValue, mozilla::ErrorResult& rv) |
509 | 0 | { |
510 | 0 | SetXULAttr(nsGkAtoms::menu, aValue, rv); |
511 | 0 | } |
512 | | void GetContextMenu(DOMString& aValue) |
513 | 0 | { |
514 | 0 | GetXULAttr(nsGkAtoms::contextmenu, aValue); |
515 | 0 | } |
516 | | void SetContextMenu(const nsAString& aValue, mozilla::ErrorResult& rv) |
517 | 0 | { |
518 | 0 | SetXULAttr(nsGkAtoms::contextmenu, aValue, rv); |
519 | 0 | } |
520 | | void GetTooltip(DOMString& aValue) const |
521 | 0 | { |
522 | 0 | GetXULAttr(nsGkAtoms::tooltip, aValue); |
523 | 0 | } |
524 | | void SetTooltip(const nsAString& aValue, mozilla::ErrorResult& rv) |
525 | 0 | { |
526 | 0 | SetXULAttr(nsGkAtoms::tooltip, aValue, rv); |
527 | 0 | } |
528 | | void GetWidth(DOMString& aValue) const |
529 | 0 | { |
530 | 0 | GetXULAttr(nsGkAtoms::width, aValue); |
531 | 0 | } |
532 | | void SetWidth(const nsAString& aValue, mozilla::ErrorResult& rv) |
533 | 0 | { |
534 | 0 | SetXULAttr(nsGkAtoms::width, aValue, rv); |
535 | 0 | } |
536 | | void GetHeight(DOMString& aValue) |
537 | 0 | { |
538 | 0 | GetXULAttr(nsGkAtoms::height, aValue); |
539 | 0 | } |
540 | | void SetHeight(const nsAString& aValue, mozilla::ErrorResult& rv) |
541 | 0 | { |
542 | 0 | SetXULAttr(nsGkAtoms::height, aValue, rv); |
543 | 0 | } |
544 | | void GetMinWidth(DOMString& aValue) const |
545 | 0 | { |
546 | 0 | GetXULAttr(nsGkAtoms::minwidth, aValue); |
547 | 0 | } |
548 | | void SetMinWidth(const nsAString& aValue, mozilla::ErrorResult& rv) |
549 | 0 | { |
550 | 0 | SetXULAttr(nsGkAtoms::minwidth, aValue, rv); |
551 | 0 | } |
552 | | void GetMinHeight(DOMString& aValue) const |
553 | 0 | { |
554 | 0 | GetXULAttr(nsGkAtoms::minheight, aValue); |
555 | 0 | } |
556 | | void SetMinHeight(const nsAString& aValue, mozilla::ErrorResult& rv) |
557 | 0 | { |
558 | 0 | SetXULAttr(nsGkAtoms::minheight, aValue, rv); |
559 | 0 | } |
560 | | void GetMaxWidth(DOMString& aValue) const |
561 | 0 | { |
562 | 0 | GetXULAttr(nsGkAtoms::maxwidth, aValue); |
563 | 0 | } |
564 | | void SetMaxWidth(const nsAString& aValue, mozilla::ErrorResult& rv) |
565 | 0 | { |
566 | 0 | SetXULAttr(nsGkAtoms::maxwidth, aValue, rv); |
567 | 0 | } |
568 | | void GetMaxHeight(DOMString& aValue) const |
569 | 0 | { |
570 | 0 | GetXULAttr(nsGkAtoms::maxheight, aValue); |
571 | 0 | } |
572 | | void SetMaxHeight(const nsAString& aValue, mozilla::ErrorResult& rv) |
573 | 0 | { |
574 | 0 | SetXULAttr(nsGkAtoms::maxheight, aValue, rv); |
575 | 0 | } |
576 | | void GetLeft(DOMString& aValue) const |
577 | 0 | { |
578 | 0 | GetXULAttr(nsGkAtoms::left, aValue); |
579 | 0 | } |
580 | | void SetLeft(const nsAString& aValue, mozilla::ErrorResult& rv) |
581 | 0 | { |
582 | 0 | SetXULAttr(nsGkAtoms::left, aValue, rv); |
583 | 0 | } |
584 | | void GetTop(DOMString& aValue) const |
585 | 0 | { |
586 | 0 | GetXULAttr(nsGkAtoms::top, aValue); |
587 | 0 | } |
588 | | void SetTop(const nsAString& aValue, mozilla::ErrorResult& rv) |
589 | 0 | { |
590 | 0 | SetXULAttr(nsGkAtoms::top, aValue, rv); |
591 | 0 | } |
592 | | void GetTooltipText(DOMString& aValue) const |
593 | 0 | { |
594 | 0 | GetXULAttr(nsGkAtoms::tooltiptext, aValue); |
595 | 0 | } |
596 | | void SetTooltipText(const nsAString& aValue, mozilla::ErrorResult& rv) |
597 | 0 | { |
598 | 0 | SetXULAttr(nsGkAtoms::tooltiptext, aValue, rv); |
599 | 0 | } |
600 | | void GetSrc(DOMString& aValue) const |
601 | 0 | { |
602 | 0 | GetXULAttr(nsGkAtoms::src, aValue); |
603 | 0 | } |
604 | | void SetSrc(const nsAString& aValue, mozilla::ErrorResult& rv) |
605 | 0 | { |
606 | 0 | SetXULAttr(nsGkAtoms::src, aValue, rv); |
607 | 0 | } |
608 | | bool AllowEvents() const |
609 | 0 | { |
610 | 0 | return BoolAttrIsTrue(nsGkAtoms::allowevents); |
611 | 0 | } |
612 | | void SetAllowEvents(bool aAllowEvents) |
613 | 0 | { |
614 | 0 | SetXULBoolAttr(nsGkAtoms::allowevents, aAllowEvents); |
615 | 0 | } |
616 | | nsIControllers* GetControllers(mozilla::ErrorResult& rv); |
617 | | // Note: this can only fail if the do_CreateInstance for the boxobject |
618 | | // contact fails for some reason. |
619 | | already_AddRefed<mozilla::dom::BoxObject> GetBoxObject(mozilla::ErrorResult& rv); |
620 | | void Click(mozilla::dom::CallerType aCallerType); |
621 | | void DoCommand(); |
622 | | // Style() inherited from nsStyledElement |
623 | | |
624 | | nsINode* GetScopeChainParent() const override |
625 | 0 | { |
626 | 0 | // For XUL, the parent is the parent element, if any |
627 | 0 | Element* parent = GetParentElement(); |
628 | 0 | return parent ? parent : nsStyledElement::GetScopeChainParent(); |
629 | 0 | } |
630 | | |
631 | | protected: |
632 | | ~nsXULElement(); |
633 | | |
634 | | // This can be removed if EnsureContentsGenerated dies. |
635 | | friend class nsNSElementTearoff; |
636 | | |
637 | | // Implementation methods |
638 | | nsresult EnsureContentsGenerated(void) const; |
639 | | |
640 | | nsresult AddPopupListener(nsAtom* aName); |
641 | | |
642 | | /** |
643 | | * The nearest enclosing content node with a binding |
644 | | * that created us. |
645 | | */ |
646 | | nsCOMPtr<nsIContent> mBindingParent; |
647 | | |
648 | | /** |
649 | | * Abandon our prototype linkage, and copy all attributes locally |
650 | | */ |
651 | | nsresult MakeHeavyweight(nsXULPrototypeElement* aPrototype); |
652 | | |
653 | | virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, |
654 | | const nsAttrValueOrString* aValue, |
655 | | bool aNotify) override; |
656 | | virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, |
657 | | const nsAttrValue* aValue, |
658 | | const nsAttrValue* aOldValue, |
659 | | nsIPrincipal* aSubjectPrincipal, |
660 | | bool aNotify) override; |
661 | | |
662 | | virtual void UpdateEditableState(bool aNotify) override; |
663 | | |
664 | | virtual bool ParseAttribute(int32_t aNamespaceID, |
665 | | nsAtom* aAttribute, |
666 | | const nsAString& aValue, |
667 | | nsIPrincipal* aMaybeScriptedPrincipal, |
668 | | nsAttrValue& aResult) override; |
669 | | |
670 | | virtual mozilla::EventListenerManager* |
671 | | GetEventListenerManagerForAttr(nsAtom* aAttrName, |
672 | | bool* aDefer) override; |
673 | | |
674 | | /** |
675 | | * Add a listener for the specified attribute, if appropriate. |
676 | | */ |
677 | | void AddListenerFor(const nsAttrName& aName); |
678 | | void MaybeAddPopupListener(nsAtom* aLocalName); |
679 | | |
680 | | nsIWidget* GetWindowWidget(); |
681 | | |
682 | | // attribute setters for widget |
683 | | nsresult HideWindowChrome(bool aShouldHide); |
684 | | void SetChromeMargins(const nsAttrValue* aValue); |
685 | | void ResetChromeMargins(); |
686 | | |
687 | | void SetDrawsInTitlebar(bool aState); |
688 | | void SetDrawsTitle(bool aState); |
689 | | void UpdateBrightTitlebarForeground(nsIDocument* aDocument); |
690 | | |
691 | | void RemoveBroadcaster(const nsAString & broadcasterId); |
692 | | |
693 | | protected: |
694 | | void AddTooltipSupport(); |
695 | | void RemoveTooltipSupport(); |
696 | | |
697 | | // Internal accessor. This shadows the 'Slots', and returns |
698 | | // appropriate value. |
699 | 0 | nsIControllers *Controllers() { |
700 | 0 | nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); |
701 | 0 | return slots ? slots->mControllers.get() : nullptr; |
702 | 0 | } |
703 | | |
704 | | void UnregisterAccessKey(const nsAString& aOldValue); |
705 | | bool BoolAttrIsTrue(nsAtom* aName) const; |
706 | | |
707 | | friend nsXULElement* |
708 | | NS_NewBasicXULElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); |
709 | | |
710 | | friend nsresult |
711 | | NS_NewXULElement(mozilla::dom::Element** aResult, mozilla::dom::NodeInfo *aNodeInfo, |
712 | | mozilla::dom::FromParser aFromParser, const nsAString* aIs); |
713 | | friend void |
714 | | NS_TrustedNewXULElement(mozilla::dom::Element** aResult, mozilla::dom::NodeInfo *aNodeInfo); |
715 | | |
716 | | static already_AddRefed<nsXULElement> |
717 | | CreateFromPrototype(nsXULPrototypeElement* aPrototype, |
718 | | mozilla::dom::NodeInfo *aNodeInfo, |
719 | | bool aIsScriptable, |
720 | | bool aIsRoot); |
721 | | |
722 | | bool IsReadWriteTextElement() const |
723 | 0 | { |
724 | 0 | return IsAnyOfXULElements(nsGkAtoms::textbox, nsGkAtoms::textarea) && |
725 | 0 | !HasAttr(kNameSpaceID_None, nsGkAtoms::readonly); |
726 | 0 | } |
727 | | |
728 | | virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override; |
729 | | |
730 | | void MaybeUpdatePrivateLifetime(); |
731 | | |
732 | | bool IsEventStoppedFromAnonymousScrollbar(mozilla::EventMessage aMessage); |
733 | | |
734 | | nsresult DispatchXULCommand(const mozilla::EventChainVisitor& aVisitor, |
735 | | nsAutoString& aCommand); |
736 | | }; |
737 | | |
738 | | #endif // nsXULElement_h__ |