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