Bug 1842773 - Part 5: Add ArrayBuffer.prototype.{maxByteLength,resizable} getters...
[gecko.git] / dom / base / nsIContent.h
blob238816d987e5f3f660bdbf015a3aa797634964bc
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 #ifndef nsIContent_h___
7 #define nsIContent_h___
9 #include "mozilla/FlushType.h"
10 #include "nsINode.h"
11 #include "nsStringFwd.h"
13 // Forward declarations
14 class nsIURI;
15 class nsTextFragment;
16 class nsIFrame;
18 namespace mozilla {
19 class EventChainPreVisitor;
20 class HTMLEditor;
21 struct URLExtraData;
22 namespace dom {
23 struct BindContext;
24 class ShadowRoot;
25 class HTMLSlotElement;
26 } // namespace dom
27 namespace widget {
28 enum class IMEEnabled;
29 struct IMEState;
30 } // namespace widget
31 } // namespace mozilla
33 struct Focusable {
34 bool mFocusable = false;
35 // The computed tab index:
36 // < 0 if not tabbable
37 // == 0 if in normal tab order
38 // > 0 can be tabbed to in the order specified by this value
39 int32_t mTabIndex = -1;
40 explicit operator bool() const { return mFocusable; }
43 // IID for the nsIContent interface
44 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
45 #define NS_ICONTENT_IID \
46 { \
47 0x8e1bab9d, 0x8815, 0x4d2c, { \
48 0xa2, 0x4d, 0x7a, 0xba, 0x52, 0x39, 0xdc, 0x22 \
49 } \
52 /**
53 * A node of content in a document's content model. This interface
54 * is supported by all content objects.
56 class nsIContent : public nsINode {
57 public:
58 using IMEEnabled = mozilla::widget::IMEEnabled;
59 using IMEState = mozilla::widget::IMEState;
60 using BindContext = mozilla::dom::BindContext;
62 void ConstructUbiNode(void* storage) override;
64 #ifdef MOZILLA_INTERNAL_API
65 // If you're using the external API, the only thing you can know about
66 // nsIContent is that it exists with an IID
68 explicit nsIContent(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
69 : nsINode(std::move(aNodeInfo)) {
70 MOZ_ASSERT(mNodeInfo);
71 MOZ_ASSERT(static_cast<nsINode*>(this) == reinterpret_cast<nsINode*>(this));
72 SetNodeIsContent();
74 #endif // MOZILLA_INTERNAL_API
76 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
78 NS_DECL_ISUPPORTS_INHERITED
79 NS_IMETHOD_(void) DeleteCycleCollectable(void) final;
81 NS_DECL_CYCLE_COLLECTION_CLASS(nsIContent)
83 NS_DECL_DOMARENA_DESTROY
85 NS_IMPL_FROMNODE_HELPER(nsIContent, IsContent())
87 /**
88 * Bind this content node to a tree. If this method throws, the caller must
89 * call UnbindFromTree() on the node. In the typical case of a node being
90 * appended to a parent, this will be called after the node has been added to
91 * the parent's child list and before nsIDocumentObserver notifications for
92 * the addition are dispatched.
93 * BindContext propagates various information down the subtree; see its
94 * documentation to know how to set it up.
95 * @param aParent The new parent node for the content node. May be a document.
96 * @note This method must not be called by consumers of nsIContent on a node
97 * that is already bound to a tree. Call UnbindFromTree first.
98 * @note This method will handle rebinding descendants appropriately (eg
99 * changing their binding parent as needed).
100 * @note This method does not add the content node to aParent's child list
101 * @throws NS_ERROR_OUT_OF_MEMORY if that happens
103 * TODO(emilio): Should we move to nsIContent::BindToTree most of the
104 * FragmentOrElement / CharacterData duplicated code?
106 virtual nsresult BindToTree(BindContext&, nsINode& aParent) = 0;
109 * Unbind this content node from a tree. This will set its current document
110 * and binding parent to null. In the typical case of a node being removed
111 * from a parent, this will be called after it has been removed from the
112 * parent's child list and after the nsIDocumentObserver notifications for
113 * the removal have been dispatched.
114 * @param aDeep Whether to recursively unbind the entire subtree rooted at
115 * this node. The only time false should be passed is when the
116 * parent node of the content is being destroyed.
117 * @param aNullParent Whether to null out the parent pointer as well. This
118 * is usually desirable. This argument should only be false while
119 * recursively calling UnbindFromTree when a subtree is detached.
120 * @note This method is safe to call on nodes that are not bound to a tree.
122 virtual void UnbindFromTree(bool aNullParent = true) = 0;
124 enum {
126 * All XBL flattened tree children of the node, as well as :before and
127 * :after anonymous content and native anonymous children.
129 * @note the result children order is
130 * 1. :before generated node
131 * 2. Shadow DOM flattened tree children of this node
132 * 3. native anonymous nodes
133 * 4. :after generated node
135 eAllChildren = 0,
138 * Skip native anonymous content created for placeholder of HTML input.
140 eSkipPlaceholderContent = 1 << 0,
143 * Skip native anonymous content created by ancestor frames of the root
144 * element's primary frame, such as scrollbar elements created by the root
145 * scroll frame.
147 eSkipDocumentLevelNativeAnonymousContent = 1 << 1,
151 * Makes this content anonymous
152 * @see nsIAnonymousContentCreator
154 void SetIsNativeAnonymousRoot() {
155 SetFlags(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE |
156 NODE_IS_NATIVE_ANONYMOUS_ROOT);
160 * Returns |this| if it is not chrome-only/native anonymous, otherwise
161 * first non chrome-only/native anonymous ancestor.
163 nsIContent* FindFirstNonChromeOnlyAccessContent() const;
166 * Return true iff this node is in an HTML document (in the HTML5 sense of
167 * the term, i.e. not in an XHTML/XML document).
169 inline bool IsInHTMLDocument() const;
172 * Returns true if in a chrome document
174 inline bool IsInChromeDocument() const;
177 * Get the namespace that this element's tag is defined in
178 * @return the namespace
180 inline int32_t GetNameSpaceID() const { return mNodeInfo->NamespaceID(); }
182 inline bool IsHTMLElement() const {
183 return IsInNamespace(kNameSpaceID_XHTML);
186 inline bool IsHTMLElement(const nsAtom* aTag) const {
187 return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
190 template <typename First, typename... Args>
191 inline bool IsAnyOfHTMLElements(First aFirst, Args... aArgs) const {
192 return IsHTMLElement() && IsNodeInternal(aFirst, aArgs...);
195 inline bool IsSVGElement() const { return IsInNamespace(kNameSpaceID_SVG); }
197 inline bool IsSVGElement(const nsAtom* aTag) const {
198 return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
201 template <typename First, typename... Args>
202 inline bool IsAnyOfSVGElements(First aFirst, Args... aArgs) const {
203 return IsSVGElement() && IsNodeInternal(aFirst, aArgs...);
206 inline bool IsXULElement() const { return IsInNamespace(kNameSpaceID_XUL); }
208 inline bool IsXULElement(const nsAtom* aTag) const {
209 return mNodeInfo->Equals(aTag, kNameSpaceID_XUL);
212 template <typename First, typename... Args>
213 inline bool IsAnyOfXULElements(First aFirst, Args... aArgs) const {
214 return IsXULElement() && IsNodeInternal(aFirst, aArgs...);
217 inline bool IsMathMLElement() const {
218 return IsInNamespace(kNameSpaceID_MathML);
221 inline bool IsMathMLElement(const nsAtom* aTag) const {
222 return mNodeInfo->Equals(aTag, kNameSpaceID_MathML);
225 template <typename First, typename... Args>
226 inline bool IsAnyOfMathMLElements(First aFirst, Args... aArgs) const {
227 return IsMathMLElement() && IsNodeInternal(aFirst, aArgs...);
230 bool IsGeneratedContentContainerForBefore() const {
231 return IsRootOfNativeAnonymousSubtree() &&
232 mNodeInfo->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore;
235 bool IsGeneratedContentContainerForAfter() const {
236 return IsRootOfNativeAnonymousSubtree() &&
237 mNodeInfo->NameAtom() == nsGkAtoms::mozgeneratedcontentafter;
240 bool IsGeneratedContentContainerForMarker() const {
241 return IsRootOfNativeAnonymousSubtree() &&
242 mNodeInfo->NameAtom() == nsGkAtoms::mozgeneratedcontentmarker;
246 * Get direct access (but read only) to the text in the text content.
247 * NOTE: For elements this is *not* the concatenation of all text children,
248 * it is simply null;
250 virtual const nsTextFragment* GetText() = 0;
253 * Get the length of the text content.
254 * NOTE: This should not be called on elements.
256 virtual uint32_t TextLength() const = 0;
259 * Determines if an event attribute name (such as onclick) is valid for
260 * a given element type.
261 * @note calls nsContentUtils::IsEventAttributeName with right flag
262 * @note *Internal is overridden by subclasses as needed
263 * @param aName the event name to look up
265 bool IsEventAttributeName(nsAtom* aName);
267 virtual bool IsEventAttributeNameInternal(nsAtom* aName) { return false; }
270 * Query method to see if the frame is nothing but whitespace
271 * NOTE: Always returns false for elements
273 virtual bool TextIsOnlyWhitespace() = 0;
276 * Thread-safe version of TextIsOnlyWhitespace.
278 virtual bool ThreadSafeTextIsOnlyWhitespace() const = 0;
281 * Check if this content is focusable and in the current tab order.
282 * Note: most callers should use nsIFrame::IsFocusable() instead as it
283 * checks visibility and other layout factors as well.
284 * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable.
285 * For example, only the selected radio button in a group is in the
286 * tab order, unless the radio group has no selection in which case
287 * all of the visible, non-disabled radio buttons in the group are
288 * in the tab order. On the other hand, all of the visible, non-disabled
289 * radio buttons are always focusable via clicking or script.
290 * Also, depending on either the accessibility.tabfocus pref or
291 * a system setting (nowadays: Full keyboard access, mac only)
292 * some widgets may be focusable but removed from the tab order.
293 * @return whether the content is focusable via mouse, kbd or script.
295 virtual Focusable IsFocusableWithoutStyle(bool aWithMouse = false);
297 // https://html.spec.whatwg.org/multipage/interaction.html#focus-delegate
298 mozilla::dom::Element* GetFocusDelegate(bool aWithMouse) const;
300 // https://html.spec.whatwg.org/multipage/interaction.html#autofocus-delegate
301 mozilla::dom::Element* GetAutofocusDelegate(bool aWithMouse) const;
304 * Get desired IME state for the content.
306 * @return The desired IME status for the content.
307 * This is a combination of an IME enabled value and
308 * an IME open value of widget::IMEState.
309 * If you return IMEEnabled::Disabled, you should not set the OPEN
310 * nor CLOSE value.
311 * IMEEnabled::Password should be returned only from password editor,
312 * this value has a special meaning. It is used as alternative of
313 * IMEEnabled::Disabled. IMEENabled::Plugin should be returned only
314 * when plug-in has focus. When a plug-in is focused content, we
315 * should send native events directly. Because we don't process some
316 * native events, but they may be needed by the plug-in.
318 virtual IMEState GetDesiredIMEState();
321 * Gets the ShadowRoot binding for this element.
323 * @return The ShadowRoot currently bound to this element.
325 inline mozilla::dom::ShadowRoot* GetShadowRoot() const;
328 * Gets the root of the node tree for this content if it is in a shadow tree.
330 * @return The ShadowRoot that is the root of the node tree.
332 mozilla::dom::ShadowRoot* GetContainingShadow() const {
333 const nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
334 return slots ? slots->mContainingShadow.get() : nullptr;
338 * Gets the assigned slot associated with this content.
340 * @return The assigned slot element or null.
342 mozilla::dom::HTMLSlotElement* GetAssignedSlot() const {
343 const nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
344 return slots ? slots->mAssignedSlot.get() : nullptr;
348 * Sets the assigned slot associated with this content.
350 * @param aSlot The assigned slot.
352 void SetAssignedSlot(mozilla::dom::HTMLSlotElement* aSlot);
355 * Gets the assigned slot associated with this content based on parent's
356 * shadow root mode. Returns null if parent's shadow root is "closed".
357 * https://dom.spec.whatwg.org/#dom-slotable-assignedslot
359 * @return The assigned slot element or null.
361 mozilla::dom::HTMLSlotElement* GetAssignedSlotByMode() const;
363 mozilla::dom::HTMLSlotElement* GetManualSlotAssignment() const {
364 const nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
365 return slots ? slots->mManualSlotAssignment : nullptr;
368 void SetManualSlotAssignment(mozilla::dom::HTMLSlotElement* aSlot) {
369 MOZ_ASSERT(aSlot || GetExistingExtendedContentSlots());
370 ExtendedContentSlots()->mManualSlotAssignment = aSlot;
374 * Same as GetFlattenedTreeParentNode, but returns null if the parent is
375 * non-nsIContent.
377 inline nsIContent* GetFlattenedTreeParent() const;
380 * Get the index of a child within this content's flat tree children.
382 * @param aPossibleChild the child to get the index of.
383 * @return the index of the child, or Nothing if not a child. Be aware that
384 * anonymous children (e.g. a <div> child of an <input> element) will
385 * result in Nothing.
387 mozilla::Maybe<uint32_t> ComputeFlatTreeIndexOf(
388 const nsINode* aPossibleChild) const;
390 protected:
391 // Handles getting inserted or removed directly under a <slot> element.
392 // This is meant to only be called from the two functions below.
393 inline void HandleInsertionToOrRemovalFromSlot();
395 // Handles Shadow-DOM-related state tracking. Meant to be called near the
396 // end of BindToTree(), only if the tree we're in actually changed, that is,
397 // after the subtree has been bound to the new parent.
398 inline void HandleShadowDOMRelatedInsertionSteps(bool aHadParent);
400 // Handles Shadow-DOM related state tracking. Meant to be called near the
401 // beginning of UnbindFromTree(), before the node has lost the reference to
402 // its parent.
403 inline void HandleShadowDOMRelatedRemovalSteps(bool aNullParent);
405 public:
407 * This method is called when the parser finishes creating the element. This
408 * particularly means that it has done everything you would expect it to have
409 * done after it encounters the > at the end of the tag (for HTML or XML).
410 * This includes setting the attributes, setting the document / form, and
411 * placing the element into the tree at its proper place.
413 * For container elements, this is called *before* any of the children are
414 * created or added into the tree.
416 * NOTE: this is only called for elements listed in
417 * RequiresDoneCreatingElement. This is an efficiency measure.
419 * If you also need to determine whether the parser is the one creating your
420 * element (through createElement() or cloneNode() generally) then add a
421 * uint32_t aFromParser to the NS_NewXXX() constructor for your element and
422 * have the parser pass the appropriate flags. See HTMLInputElement.cpp and
423 * nsHTMLContentSink::MakeContentObject().
425 * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
426 * attributes dynamically. If you make attributes affect your element from
427 * this method, it will only happen on initialization and JavaScript will not
428 * be able to create elements (which requires them to first create the
429 * element and then call setAttribute() directly, at which point
430 * DoneCreatingElement() has already been called and is out of the picture).
432 virtual void DoneCreatingElement() {}
435 * This method is called when the parser finishes creating the element's
436 * children, if any are present.
438 * NOTE: this is only called for elements listed in
439 * RequiresDoneAddingChildren. This is an efficiency measure.
441 * If you also need to determine whether the parser is the one creating your
442 * element (through createElement() or cloneNode() generally) then add a
443 * boolean aFromParser to the NS_NewXXX() constructor for your element and
444 * have the parser pass true. See HTMLInputElement.cpp and
445 * nsHTMLContentSink::MakeContentObject().
447 * @param aHaveNotified Whether there has been a
448 * ContentInserted/ContentAppended notification for this content node
449 * yet.
451 virtual void DoneAddingChildren(bool aHaveNotified) {}
454 * Returns true if an element needs its DoneCreatingElement method to be
455 * called after it has been created.
456 * @see nsIContent::DoneCreatingElement
458 * @param aNamespaceID the node's namespace ID
459 * @param aName the node's tag name
461 static inline bool RequiresDoneCreatingElement(int32_t aNamespace,
462 nsAtom* aName) {
463 if (aNamespace == kNameSpaceID_XHTML) {
464 if (aName == nsGkAtoms::input || aName == nsGkAtoms::button ||
465 aName == nsGkAtoms::audio || aName == nsGkAtoms::video) {
466 MOZ_ASSERT(!RequiresDoneAddingChildren(aNamespace, aName),
467 "Both DoneCreatingElement and DoneAddingChildren on a "
468 "same element isn't supported.");
469 return true;
471 if (aName->IsDynamic()) {
472 // This could be a form-associated custom element, so check if its
473 // name includes a -.
474 nsDependentString name(aName->GetUTF16String());
475 return name.Contains('-');
478 return false;
482 * Returns true if an element needs its DoneAddingChildren method to be
483 * called after all of its children have been added.
484 * @see nsIContent::DoneAddingChildren
486 * @param aNamespace the node's namespace ID
487 * @param aName the node's tag name
489 static inline bool RequiresDoneAddingChildren(int32_t aNamespace,
490 nsAtom* aName) {
491 return (aNamespace == kNameSpaceID_XHTML &&
492 (aName == nsGkAtoms::select || aName == nsGkAtoms::textarea ||
493 aName == nsGkAtoms::head || aName == nsGkAtoms::title ||
494 aName == nsGkAtoms::object || aName == nsGkAtoms::output)) ||
495 (aNamespace == kNameSpaceID_SVG && aName == nsGkAtoms::title) ||
496 (aNamespace == kNameSpaceID_XUL && aName == nsGkAtoms::linkset);
500 * Get the ID of this content node (the atom corresponding to the
501 * value of the id attribute). This may be null if there is no ID.
503 nsAtom* GetID() const {
504 if (HasID()) {
505 return DoGetID();
507 return nullptr;
511 * Should be called when the node can become editable or when it can stop
512 * being editable (for example when its contentEditable attribute changes,
513 * when it is moved into an editable parent, ...). If aNotify is true and
514 * the node is an element, this will notify the state change.
516 virtual void UpdateEditableState(bool aNotify);
519 * Destroy this node and its children. Ideally this shouldn't be needed
520 * but for now we need to do it to break cycles.
522 virtual void DestroyContent() {}
525 * Saves the form state of this node and its children.
527 virtual void SaveSubtreeState() = 0;
530 * Getter and setter for our primary frame pointer. This is the frame that
531 * is most closely associated with the content. A frame is more closely
532 * associated with the content than another frame if the one frame contains
533 * directly or indirectly the other frame (e.g., when a frame is scrolled
534 * there is a scroll frame that contains the frame being scrolled). This
535 * frame is always the first continuation.
537 * In the case of absolutely positioned elements and floated elements, this
538 * frame is the out of flow frame, not the placeholder.
540 nsIFrame* GetPrimaryFrame() const {
541 return (IsInUncomposedDoc() || IsInShadowTree()) ? mPrimaryFrame : nullptr;
545 * Get the primary frame for this content with flushing
547 * @param aType the kind of flush to do, typically FlushType::Frames or
548 * FlushType::Layout
549 * @return the primary frame
551 nsIFrame* GetPrimaryFrame(mozilla::FlushType aType);
553 // Defined in nsIContentInlines.h because it needs nsIFrame.
554 inline void SetPrimaryFrame(nsIFrame* aFrame);
556 nsresult LookupNamespaceURIInternal(const nsAString& aNamespacePrefix,
557 nsAString& aNamespaceURI) const;
560 * If this content has independent selection, e.g., if this is input field
561 * or textarea, this return TRUE. Otherwise, false.
563 bool HasIndependentSelection() const;
566 * If the content is a part of HTML editor, this returns editing
567 * host content. When the content is in designMode, this returns its body
568 * element. Also, when the content isn't editable, this returns null.
570 mozilla::dom::Element* GetEditingHost();
572 bool SupportsLangAttr() const {
573 return IsHTMLElement() || IsSVGElement() || IsXULElement();
577 * Determining language. Look at the nearest ancestor element that has a lang
578 * attribute in the XML namespace or is an HTML/SVG element and has a lang in
579 * no namespace attribute.
581 * Returns null if no language was specified. Can return the empty atom.
583 nsAtom* GetLang() const;
585 bool GetLang(nsAString& aResult) const {
586 if (auto* lang = GetLang()) {
587 aResult.Assign(nsDependentAtomString(lang));
588 return true;
591 return false;
594 // Overloaded from nsINode
595 nsIURI* GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override;
597 // Returns base URI for style attribute.
598 nsIURI* GetBaseURIForStyleAttr() const;
600 // Returns the URL data for style attribute.
601 // If aSubjectPrincipal is passed, it should be the scripted principal
602 // responsible for generating the URL data.
603 already_AddRefed<mozilla::URLExtraData> GetURLDataForStyleAttr(
604 nsIPrincipal* aSubjectPrincipal = nullptr) const;
606 void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
608 bool IsPurple() const { return mRefCnt.IsPurple(); }
610 void RemovePurple() { mRefCnt.RemovePurple(); }
612 // Note, currently this doesn't handle the case when frame tree has multiple
613 // references to the nsIContent object.
614 bool OwnedOnlyByTheDOMAndFrameTrees() {
615 return OwnedOnlyByTheDOMTree(GetPrimaryFrame() ? 1 : 0);
618 bool OwnedOnlyByTheDOMTree(uint32_t aExpectedRefs = 0) {
619 uint32_t rc = mRefCnt.get();
620 if (GetParent()) {
621 --rc;
623 rc -= GetChildCount();
624 return rc == aExpectedRefs;
628 * Use this method with designMode and contentEditable to check if the
629 * node may need spellchecking.
631 bool InclusiveDescendantMayNeedSpellchecking(mozilla::HTMLEditor* aEditor);
633 protected:
635 * Lazily allocated extended slots to avoid
636 * that may only be instantiated when a content object is accessed
637 * through the DOM. Rather than burn actual slots in the content
638 * objects for each of these instance variables, we put them off
639 * in a side structure that's only allocated when the content is
640 * accessed through the DOM.
642 class nsExtendedContentSlots {
643 public:
644 nsExtendedContentSlots();
645 virtual ~nsExtendedContentSlots();
647 virtual void TraverseExtendedSlots(nsCycleCollectionTraversalCallback&);
648 virtual void UnlinkExtendedSlots(nsIContent&);
650 virtual size_t SizeOfExcludingThis(
651 mozilla::MallocSizeOf aMallocSizeOf) const;
654 * @see nsIContent::GetContainingShadow
656 RefPtr<mozilla::dom::ShadowRoot> mContainingShadow;
659 * @see nsIContent::GetAssignedSlot
661 RefPtr<mozilla::dom::HTMLSlotElement> mAssignedSlot;
663 mozilla::dom::HTMLSlotElement* mManualSlotAssignment = nullptr;
666 class nsContentSlots : public nsINode::nsSlots {
667 public:
668 nsContentSlots() : mExtendedSlots(0) {}
670 ~nsContentSlots() {
671 if (!(mExtendedSlots & sNonOwningExtendedSlotsFlag)) {
672 delete GetExtendedContentSlots();
676 void Traverse(nsCycleCollectionTraversalCallback& aCb) override {
677 nsINode::nsSlots::Traverse(aCb);
678 if (mExtendedSlots) {
679 GetExtendedContentSlots()->TraverseExtendedSlots(aCb);
683 void Unlink(nsINode& aNode) override {
684 nsINode::nsSlots::Unlink(aNode);
685 if (mExtendedSlots) {
686 GetExtendedContentSlots()->UnlinkExtendedSlots(*aNode.AsContent());
690 void SetExtendedContentSlots(nsExtendedContentSlots* aSlots, bool aOwning) {
691 mExtendedSlots = reinterpret_cast<uintptr_t>(aSlots);
692 if (!aOwning) {
693 mExtendedSlots |= sNonOwningExtendedSlotsFlag;
697 // OwnsExtendedSlots returns true if we have no extended slots or if we
698 // have extended slots and own them.
699 bool OwnsExtendedSlots() const {
700 return !(mExtendedSlots & sNonOwningExtendedSlotsFlag);
703 nsExtendedContentSlots* GetExtendedContentSlots() const {
704 return reinterpret_cast<nsExtendedContentSlots*>(
705 mExtendedSlots & ~sNonOwningExtendedSlotsFlag);
708 private:
709 static const uintptr_t sNonOwningExtendedSlotsFlag = 1u;
711 uintptr_t mExtendedSlots;
714 // Override from nsINode
715 nsContentSlots* CreateSlots() override { return new nsContentSlots(); }
717 nsContentSlots* ContentSlots() {
718 return static_cast<nsContentSlots*>(Slots());
721 const nsContentSlots* GetExistingContentSlots() const {
722 return static_cast<nsContentSlots*>(GetExistingSlots());
725 nsContentSlots* GetExistingContentSlots() {
726 return static_cast<nsContentSlots*>(GetExistingSlots());
729 virtual nsExtendedContentSlots* CreateExtendedSlots() {
730 return new nsExtendedContentSlots();
733 const nsExtendedContentSlots* GetExistingExtendedContentSlots() const {
734 const nsContentSlots* slots = GetExistingContentSlots();
735 return slots ? slots->GetExtendedContentSlots() : nullptr;
738 nsExtendedContentSlots* GetExistingExtendedContentSlots() {
739 nsContentSlots* slots = GetExistingContentSlots();
740 return slots ? slots->GetExtendedContentSlots() : nullptr;
743 nsExtendedContentSlots* ExtendedContentSlots() {
744 nsContentSlots* slots = ContentSlots();
745 if (!slots->GetExtendedContentSlots()) {
746 slots->SetExtendedContentSlots(CreateExtendedSlots(), true);
748 return slots->GetExtendedContentSlots();
752 * Hook for implementing GetID. This is guaranteed to only be
753 * called if HasID() is true.
755 nsAtom* DoGetID() const;
757 ~nsIContent() = default;
759 public:
760 #if defined(DEBUG) || defined(MOZ_DUMP_PAINTING)
761 # define MOZ_DOM_LIST
762 #endif
764 #ifdef MOZ_DOM_LIST
766 * An alias for List() with default arguments. Since some debuggers can't
767 * figure the default arguments easily, having an out-of-line, non-static
768 * function helps quite a lot.
770 void Dump();
773 * List the content (and anything it contains) out to the given
774 * file stream. Use aIndent as the base indent during formatting.
776 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
779 * Dump the content (and anything it contains) out to the given
780 * file stream. Use aIndent as the base indent during formatting.
782 virtual void DumpContent(FILE* out = stdout, int32_t aIndent = 0,
783 bool aDumpAll = true) const = 0;
784 #endif
786 enum ETabFocusType {
787 eTabFocus_textControlsMask =
788 (1 << 0), // textboxes and lists always tabbable
789 eTabFocus_formElementsMask = (1 << 1), // non-text form elements
790 eTabFocus_linksMask = (1 << 2), // links
791 eTabFocus_any = 1 + (1 << 1) + (1 << 2) // everything that can be focused
794 // Tab focus model bit field:
795 static int32_t sTabFocusModel;
797 // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
798 // the tabfocus bit field applies to xul elements.
799 static bool sTabFocusModelAppliesToXUL;
802 NON_VIRTUAL_ADDREF_RELEASE(nsIContent)
804 NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
806 #endif /* nsIContent_h___ */