Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / base / nsIContent.h
blobe7c6e2056fbef9a61827d5b462b24462516f1a16
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 struct URLExtraData;
21 namespace dom {
22 struct BindContext;
23 class ShadowRoot;
24 class HTMLSlotElement;
25 } // namespace dom
26 namespace widget {
27 enum class IMEEnabled;
28 struct IMEState;
29 } // namespace widget
30 } // namespace mozilla
32 // IID for the nsIContent interface
33 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
34 #define NS_ICONTENT_IID \
35 { \
36 0x8e1bab9d, 0x8815, 0x4d2c, { \
37 0xa2, 0x4d, 0x7a, 0xba, 0x52, 0x39, 0xdc, 0x22 \
38 } \
41 /**
42 * A node of content in a document's content model. This interface
43 * is supported by all content objects.
45 class nsIContent : public nsINode {
46 public:
47 using IMEEnabled = mozilla::widget::IMEEnabled;
48 using IMEState = mozilla::widget::IMEState;
49 using BindContext = mozilla::dom::BindContext;
51 void ConstructUbiNode(void* storage) override;
53 #ifdef MOZILLA_INTERNAL_API
54 // If you're using the external API, the only thing you can know about
55 // nsIContent is that it exists with an IID
57 explicit nsIContent(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
58 : nsINode(std::move(aNodeInfo)) {
59 MOZ_ASSERT(mNodeInfo);
60 MOZ_ASSERT(static_cast<nsINode*>(this) == reinterpret_cast<nsINode*>(this));
61 SetNodeIsContent();
63 #endif // MOZILLA_INTERNAL_API
65 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
67 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL_DELETECYCLECOLLECTABLE
69 NS_DECL_CYCLE_COLLECTION_CLASS(nsIContent)
71 NS_DECL_DOMARENA_DESTROY
73 NS_IMPL_FROMNODE_HELPER(nsIContent, IsContent())
75 /**
76 * Bind this content node to a tree. If this method throws, the caller must
77 * call UnbindFromTree() on the node. In the typical case of a node being
78 * appended to a parent, this will be called after the node has been added to
79 * the parent's child list and before nsIDocumentObserver notifications for
80 * the addition are dispatched.
81 * BindContext propagates various information down the subtree; see its
82 * documentation to know how to set it up.
83 * @param aParent The new parent node for the content node. May be a document.
84 * @note This method must not be called by consumers of nsIContent on a node
85 * that is already bound to a tree. Call UnbindFromTree first.
86 * @note This method will handle rebinding descendants appropriately (eg
87 * changing their binding parent as needed).
88 * @note This method does not add the content node to aParent's child list
89 * @throws NS_ERROR_OUT_OF_MEMORY if that happens
91 * TODO(emilio): Should we move to nsIContent::BindToTree most of the
92 * FragmentOrElement / CharacterData duplicated code?
94 virtual nsresult BindToTree(BindContext&, nsINode& aParent) = 0;
96 /**
97 * Unbind this content node from a tree. This will set its current document
98 * and binding parent to null. In the typical case of a node being removed
99 * from a parent, this will be called after it has been removed from the
100 * parent's child list and after the nsIDocumentObserver notifications for
101 * the removal have been dispatched.
102 * @param aDeep Whether to recursively unbind the entire subtree rooted at
103 * this node. The only time false should be passed is when the
104 * parent node of the content is being destroyed.
105 * @param aNullParent Whether to null out the parent pointer as well. This
106 * is usually desirable. This argument should only be false while
107 * recursively calling UnbindFromTree when a subtree is detached.
108 * @note This method is safe to call on nodes that are not bound to a tree.
110 virtual void UnbindFromTree(bool aNullParent = true) = 0;
112 enum {
114 * All XBL flattened tree children of the node, as well as :before and
115 * :after anonymous content and native anonymous children.
117 * @note the result children order is
118 * 1. :before generated node
119 * 2. Shadow DOM flattened tree children of this node
120 * 3. native anonymous nodes
121 * 4. :after generated node
123 eAllChildren = 0,
126 * Skip native anonymous content created for placeholder of HTML input.
128 eSkipPlaceholderContent = 1 << 0,
131 * Skip native anonymous content created by ancestor frames of the root
132 * element's primary frame, such as scrollbar elements created by the root
133 * scroll frame.
135 eSkipDocumentLevelNativeAnonymousContent = 1 << 1,
139 * Return the flattened tree children of the node, depending on the filter, as
140 * well as native anonymous children.
142 virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) = 0;
145 * Makes this content anonymous
146 * @see nsIAnonymousContentCreator
148 void SetIsNativeAnonymousRoot() {
149 SetFlags(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE |
150 NODE_IS_NATIVE_ANONYMOUS_ROOT);
154 * Returns |this| if it is not chrome-only/native anonymous, otherwise
155 * first non chrome-only/native anonymous ancestor.
157 nsIContent* FindFirstNonChromeOnlyAccessContent() const;
160 * Return true iff this node is in an HTML document (in the HTML5 sense of
161 * the term, i.e. not in an XHTML/XML document).
163 inline bool IsInHTMLDocument() const;
166 * Returns true if in a chrome document
168 inline bool IsInChromeDocument() const;
171 * Get the namespace that this element's tag is defined in
172 * @return the namespace
174 inline int32_t GetNameSpaceID() const { return mNodeInfo->NamespaceID(); }
176 inline bool IsHTMLElement() const {
177 return IsInNamespace(kNameSpaceID_XHTML);
180 inline bool IsHTMLElement(const nsAtom* aTag) const {
181 return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
184 template <typename First, typename... Args>
185 inline bool IsAnyOfHTMLElements(First aFirst, Args... aArgs) const {
186 return IsHTMLElement() && IsNodeInternal(aFirst, aArgs...);
189 inline bool IsSVGElement() const { return IsInNamespace(kNameSpaceID_SVG); }
191 inline bool IsSVGElement(const nsAtom* aTag) const {
192 return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
195 template <typename First, typename... Args>
196 inline bool IsAnyOfSVGElements(First aFirst, Args... aArgs) const {
197 return IsSVGElement() && IsNodeInternal(aFirst, aArgs...);
200 inline bool IsXULElement() const { return IsInNamespace(kNameSpaceID_XUL); }
202 inline bool IsXULElement(const nsAtom* aTag) const {
203 return mNodeInfo->Equals(aTag, kNameSpaceID_XUL);
206 template <typename First, typename... Args>
207 inline bool IsAnyOfXULElements(First aFirst, Args... aArgs) const {
208 return IsXULElement() && IsNodeInternal(aFirst, aArgs...);
211 inline bool IsMathMLElement() const {
212 return IsInNamespace(kNameSpaceID_MathML);
215 inline bool IsMathMLElement(const nsAtom* aTag) const {
216 return mNodeInfo->Equals(aTag, kNameSpaceID_MathML);
219 template <typename First, typename... Args>
220 inline bool IsAnyOfMathMLElements(First aFirst, Args... aArgs) const {
221 return IsMathMLElement() && IsNodeInternal(aFirst, aArgs...);
224 bool IsGeneratedContentContainerForBefore() const {
225 return IsRootOfNativeAnonymousSubtree() &&
226 mNodeInfo->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore;
229 bool IsGeneratedContentContainerForAfter() const {
230 return IsRootOfNativeAnonymousSubtree() &&
231 mNodeInfo->NameAtom() == nsGkAtoms::mozgeneratedcontentafter;
234 bool IsGeneratedContentContainerForMarker() const {
235 return IsRootOfNativeAnonymousSubtree() &&
236 mNodeInfo->NameAtom() == nsGkAtoms::mozgeneratedcontentmarker;
240 * Get direct access (but read only) to the text in the text content.
241 * NOTE: For elements this is *not* the concatenation of all text children,
242 * it is simply null;
244 virtual const nsTextFragment* GetText() = 0;
247 * Get the length of the text content.
248 * NOTE: This should not be called on elements.
250 virtual uint32_t TextLength() const = 0;
253 * Determines if an event attribute name (such as onclick) is valid for
254 * a given element type.
255 * @note calls nsContentUtils::IsEventAttributeName with right flag
256 * @note *Internal is overridden by subclasses as needed
257 * @param aName the event name to look up
259 bool IsEventAttributeName(nsAtom* aName);
261 virtual bool IsEventAttributeNameInternal(nsAtom* aName) { return false; }
264 * Query method to see if the frame is nothing but whitespace
265 * NOTE: Always returns false for elements
267 virtual bool TextIsOnlyWhitespace() = 0;
270 * Thread-safe version of TextIsOnlyWhitespace.
272 virtual bool ThreadSafeTextIsOnlyWhitespace() const = 0;
275 * Check if this content is focusable and in the current tab order.
276 * Note: most callers should use nsIFrame::IsFocusable() instead as it
277 * checks visibility and other layout factors as well.
278 * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable.
279 * For example, only the selected radio button in a group is in the
280 * tab order, unless the radio group has no selection in which case
281 * all of the visible, non-disabled radio buttons in the group are
282 * in the tab order. On the other hand, all of the visible, non-disabled
283 * radio buttons are always focusable via clicking or script.
284 * Also, depending on either the accessibility.tabfocus pref or
285 * a system setting (nowadays: Full keyboard access, mac only)
286 * some widgets may be focusable but removed from the tab order.
287 * @param [inout, optional] aTabIndex the computed tab index
288 * In: default tabindex for element (-1 nonfocusable, == 0 focusable)
289 * Out: computed tabindex
290 * @param [optional] aTabIndex the computed tab index
291 * < 0 if not tabbable
292 * == 0 if in normal tab order
293 * > 0 can be tabbed to in the order specified by this value
294 * @return whether the content is focusable via mouse, kbd or script.
296 bool IsFocusable(int32_t* aTabIndex = nullptr, bool aWithMouse = false);
297 virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse);
299 // https://html.spec.whatwg.org/multipage/interaction.html#focus-delegate
300 mozilla::dom::Element* GetFocusDelegate(bool aWithMouse) const;
303 * Get desired IME state for the content.
305 * @return The desired IME status for the content.
306 * This is a combination of an IME enabled value and
307 * an IME open value of widget::IMEState.
308 * If you return IMEEnabled::Disabled, you should not set the OPEN
309 * nor CLOSE value.
310 * IMEEnabled::Password should be returned only from password editor,
311 * this value has a special meaning. It is used as alternative of
312 * IMEEnabled::Disabled. IMEENabled::Plugin should be returned only
313 * when plug-in has focus. When a plug-in is focused content, we
314 * should send native events directly. Because we don't process some
315 * native events, but they may be needed by the plug-in.
317 virtual IMEState GetDesiredIMEState();
320 * Gets the ShadowRoot binding for this element.
322 * @return The ShadowRoot currently bound to this element.
324 inline mozilla::dom::ShadowRoot* GetShadowRoot() const;
327 * Gets the root of the node tree for this content if it is in a shadow tree.
329 * @return The ShadowRoot that is the root of the node tree.
331 mozilla::dom::ShadowRoot* GetContainingShadow() const {
332 const nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
333 return slots ? slots->mContainingShadow.get() : nullptr;
337 * Gets the assigned slot associated with this content.
339 * @return The assigned slot element or null.
341 mozilla::dom::HTMLSlotElement* GetAssignedSlot() const {
342 const nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
343 return slots ? slots->mAssignedSlot.get() : nullptr;
347 * Sets the assigned slot associated with this content.
349 * @param aSlot The assigned slot.
351 void SetAssignedSlot(mozilla::dom::HTMLSlotElement* aSlot);
354 * Gets the assigned slot associated with this content based on parent's
355 * shadow root mode. Returns null if parent's shadow root is "closed".
356 * https://dom.spec.whatwg.org/#dom-slotable-assignedslot
358 * @return The assigned slot element or null.
360 mozilla::dom::HTMLSlotElement* GetAssignedSlotByMode() const;
362 mozilla::dom::HTMLSlotElement* GetManualSlotAssignment() const {
363 const nsExtendedContentSlots* slots = GetExistingExtendedContentSlots();
364 return slots ? slots->mManualSlotAssignment : nullptr;
367 void SetManualSlotAssignment(mozilla::dom::HTMLSlotElement* aSlot) {
368 MOZ_ASSERT(aSlot || GetExistingExtendedContentSlots());
369 ExtendedContentSlots()->mManualSlotAssignment = aSlot;
373 * Same as GetFlattenedTreeParentNode, but returns null if the parent is
374 * non-nsIContent.
376 inline nsIContent* GetFlattenedTreeParent() const;
379 * Get the index of a child within this content's flat tree children.
381 * @param aPossibleChild the child to get the index of.
382 * @return the index of the child, or Nothing if not a child. Be aware that
383 * anonymous children (e.g. a <div> child of an <input> element) will
384 * result in Nothing.
386 mozilla::Maybe<uint32_t> ComputeFlatTreeIndexOf(
387 const nsINode* aPossibleChild) const;
389 protected:
390 // Handles getting inserted or removed directly under a <slot> element.
391 // This is meant to only be called from the two functions below.
392 inline void HandleInsertionToOrRemovalFromSlot();
394 // Handles Shadow-DOM-related state tracking. Meant to be called near the
395 // end of BindToTree(), only if the tree we're in actually changed, that is,
396 // after the subtree has been bound to the new parent.
397 inline void HandleShadowDOMRelatedInsertionSteps(bool aHadParent);
399 // Handles Shadow-DOM related state tracking. Meant to be called near the
400 // beginning of UnbindFromTree(), before the node has lost the reference to
401 // its parent.
402 inline void HandleShadowDOMRelatedRemovalSteps(bool aNullParent);
404 public:
406 * This method is called when the parser finishes creating the element. This
407 * particularly means that it has done everything you would expect it to have
408 * done after it encounters the > at the end of the tag (for HTML or XML).
409 * This includes setting the attributes, setting the document / form, and
410 * placing the element into the tree at its proper place.
412 * For container elements, this is called *before* any of the children are
413 * created or added into the tree.
415 * NOTE: this is only called for elements listed in
416 * RequiresDoneCreatingElement. This is an efficiency measure.
418 * If you also need to determine whether the parser is the one creating your
419 * element (through createElement() or cloneNode() generally) then add a
420 * uint32_t aFromParser to the NS_NewXXX() constructor for your element and
421 * have the parser pass the appropriate flags. See HTMLInputElement.cpp and
422 * nsHTMLContentSink::MakeContentObject().
424 * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
425 * attributes dynamically. If you make attributes affect your element from
426 * this method, it will only happen on initialization and JavaScript will not
427 * be able to create elements (which requires them to first create the
428 * element and then call setAttribute() directly, at which point
429 * DoneCreatingElement() has already been called and is out of the picture).
431 virtual void DoneCreatingElement() {}
434 * This method is called when the parser finishes creating the element's
435 * children, if any are present.
437 * NOTE: this is only called for elements listed in
438 * RequiresDoneAddingChildren. This is an efficiency measure.
440 * If you also need to determine whether the parser is the one creating your
441 * element (through createElement() or cloneNode() generally) then add a
442 * boolean aFromParser to the NS_NewXXX() constructor for your element and
443 * have the parser pass true. See HTMLInputElement.cpp and
444 * nsHTMLContentSink::MakeContentObject().
446 * @param aHaveNotified Whether there has been a
447 * ContentInserted/ContentAppended notification for this content node
448 * yet.
450 virtual void DoneAddingChildren(bool aHaveNotified) {}
453 * For HTML textarea, select, and object elements, returns true if all
454 * children have been added OR if the element was not created by the parser.
455 * Returns true for all other elements.
457 * @returns false if the element was created by the parser and
458 * it is an HTML textarea, select, or object
459 * element and not all children have been added.
461 * @returns true otherwise.
463 virtual bool IsDoneAddingChildren() { return true; }
466 * Returns true if an element needs its DoneCreatingElement method to be
467 * called after it has been created.
468 * @see nsIContent::DoneCreatingElement
470 * @param aNamespaceID the node's namespace ID
471 * @param aName the node's tag name
473 static inline bool RequiresDoneCreatingElement(int32_t aNamespace,
474 nsAtom* aName) {
475 if (aNamespace == kNameSpaceID_XHTML &&
476 (aName == nsGkAtoms::input || aName == nsGkAtoms::button ||
477 aName == nsGkAtoms::audio || aName == nsGkAtoms::video)) {
478 MOZ_ASSERT(
479 !RequiresDoneAddingChildren(aNamespace, aName),
480 "Both DoneCreatingElement and DoneAddingChildren on a same element "
481 "isn't supported.");
482 return true;
484 return false;
488 * Returns true if an element needs its DoneAddingChildren method to be
489 * called after all of its children have been added.
490 * @see nsIContent::DoneAddingChildren
492 * @param aNamespace the node's namespace ID
493 * @param aName the node's tag name
495 static inline bool RequiresDoneAddingChildren(int32_t aNamespace,
496 nsAtom* aName) {
497 return (aNamespace == kNameSpaceID_XHTML &&
498 (aName == nsGkAtoms::select || aName == nsGkAtoms::textarea ||
499 aName == nsGkAtoms::head || aName == nsGkAtoms::title ||
500 aName == nsGkAtoms::object || aName == nsGkAtoms::output)) ||
501 (aNamespace == kNameSpaceID_SVG && aName == nsGkAtoms::title) ||
502 (aNamespace == kNameSpaceID_XUL && aName == nsGkAtoms::linkset);
506 * Get the ID of this content node (the atom corresponding to the
507 * value of the id attribute). This may be null if there is no ID.
509 nsAtom* GetID() const {
510 if (HasID()) {
511 return DoGetID();
513 return nullptr;
517 * Should be called when the node can become editable or when it can stop
518 * being editable (for example when its contentEditable attribute changes,
519 * when it is moved into an editable parent, ...). If aNotify is true and
520 * the node is an element, this will notify the state change.
522 virtual void UpdateEditableState(bool aNotify);
525 * Destroy this node and its children. Ideally this shouldn't be needed
526 * but for now we need to do it to break cycles.
528 virtual void DestroyContent() {}
531 * Saves the form state of this node and its children.
533 virtual void SaveSubtreeState() = 0;
536 * Getter and setter for our primary frame pointer. This is the frame that
537 * is most closely associated with the content. A frame is more closely
538 * associated with the content than another frame if the one frame contains
539 * directly or indirectly the other frame (e.g., when a frame is scrolled
540 * there is a scroll frame that contains the frame being scrolled). This
541 * frame is always the first continuation.
543 * In the case of absolutely positioned elements and floated elements, this
544 * frame is the out of flow frame, not the placeholder.
546 nsIFrame* GetPrimaryFrame() const {
547 return (IsInUncomposedDoc() || IsInShadowTree()) ? mPrimaryFrame : nullptr;
551 * Get the primary frame for this content with flushing
553 * @param aType the kind of flush to do, typically FlushType::Frames or
554 * FlushType::Layout
555 * @return the primary frame
557 nsIFrame* GetPrimaryFrame(mozilla::FlushType aType);
559 // Defined in nsIContentInlines.h because it needs nsIFrame.
560 inline void SetPrimaryFrame(nsIFrame* aFrame);
562 nsresult LookupNamespaceURIInternal(const nsAString& aNamespacePrefix,
563 nsAString& aNamespaceURI) const;
566 * If this content has independent selection, e.g., if this is input field
567 * or textarea, this return TRUE. Otherwise, false.
569 bool HasIndependentSelection() const;
572 * If the content is a part of HTML editor, this returns editing
573 * host content. When the content is in designMode, this returns its body
574 * element. Also, when the content isn't editable, this returns null.
576 mozilla::dom::Element* GetEditingHost();
578 bool SupportsLangAttr() const {
579 return IsHTMLElement() || IsSVGElement() || IsXULElement();
583 * Determining language. Look at the nearest ancestor element that has a lang
584 * attribute in the XML namespace or is an HTML/SVG element and has a lang in
585 * no namespace attribute.
587 * Returns null if no language was specified. Can return the empty atom.
589 nsAtom* GetLang() const;
591 bool GetLang(nsAString& aResult) const {
592 if (auto* lang = GetLang()) {
593 aResult.Assign(nsDependentAtomString(lang));
594 return true;
597 return false;
600 // Overloaded from nsINode
601 nsIURI* GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override;
603 // Returns base URI for style attribute.
604 nsIURI* GetBaseURIForStyleAttr() const;
606 // Returns the URL data for style attribute.
607 // If aSubjectPrincipal is passed, it should be the scripted principal
608 // responsible for generating the URL data.
609 already_AddRefed<mozilla::URLExtraData> GetURLDataForStyleAttr(
610 nsIPrincipal* aSubjectPrincipal = nullptr) const;
612 void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
614 bool IsPurple() const { return mRefCnt.IsPurple(); }
616 void RemovePurple() { mRefCnt.RemovePurple(); }
618 bool OwnedOnlyByTheDOMTree() {
619 uint32_t rc = mRefCnt.get();
620 if (GetParent()) {
621 --rc;
623 rc -= GetChildCount();
624 return rc == 0;
627 protected:
629 * Lazily allocated extended slots to avoid
630 * that may only be instantiated when a content object is accessed
631 * through the DOM. Rather than burn actual slots in the content
632 * objects for each of these instance variables, we put them off
633 * in a side structure that's only allocated when the content is
634 * accessed through the DOM.
636 class nsExtendedContentSlots {
637 public:
638 nsExtendedContentSlots();
639 virtual ~nsExtendedContentSlots();
641 virtual void TraverseExtendedSlots(nsCycleCollectionTraversalCallback&);
642 virtual void UnlinkExtendedSlots();
644 virtual size_t SizeOfExcludingThis(
645 mozilla::MallocSizeOf aMallocSizeOf) const;
648 * @see nsIContent::GetContainingShadow
650 RefPtr<mozilla::dom::ShadowRoot> mContainingShadow;
653 * @see nsIContent::GetAssignedSlot
655 RefPtr<mozilla::dom::HTMLSlotElement> mAssignedSlot;
657 mozilla::dom::HTMLSlotElement* mManualSlotAssignment = nullptr;
660 class nsContentSlots : public nsINode::nsSlots {
661 public:
662 nsContentSlots() : nsINode::nsSlots(), mExtendedSlots(0) {}
664 ~nsContentSlots() {
665 if (!(mExtendedSlots & sNonOwningExtendedSlotsFlag)) {
666 delete GetExtendedContentSlots();
670 void Traverse(nsCycleCollectionTraversalCallback& aCb) override {
671 nsINode::nsSlots::Traverse(aCb);
672 if (mExtendedSlots) {
673 GetExtendedContentSlots()->TraverseExtendedSlots(aCb);
677 void Unlink() override {
678 nsINode::nsSlots::Unlink();
679 if (mExtendedSlots) {
680 GetExtendedContentSlots()->UnlinkExtendedSlots();
684 void SetExtendedContentSlots(nsExtendedContentSlots* aSlots, bool aOwning) {
685 mExtendedSlots = reinterpret_cast<uintptr_t>(aSlots);
686 if (!aOwning) {
687 mExtendedSlots |= sNonOwningExtendedSlotsFlag;
691 // OwnsExtendedSlots returns true if we have no extended slots or if we
692 // have extended slots and own them.
693 bool OwnsExtendedSlots() const {
694 return !(mExtendedSlots & sNonOwningExtendedSlotsFlag);
697 nsExtendedContentSlots* GetExtendedContentSlots() const {
698 return reinterpret_cast<nsExtendedContentSlots*>(
699 mExtendedSlots & ~sNonOwningExtendedSlotsFlag);
702 private:
703 static const uintptr_t sNonOwningExtendedSlotsFlag = 1u;
705 uintptr_t mExtendedSlots;
708 // Override from nsINode
709 nsContentSlots* CreateSlots() override { return new nsContentSlots(); }
711 nsContentSlots* ContentSlots() {
712 return static_cast<nsContentSlots*>(Slots());
715 const nsContentSlots* GetExistingContentSlots() const {
716 return static_cast<nsContentSlots*>(GetExistingSlots());
719 nsContentSlots* GetExistingContentSlots() {
720 return static_cast<nsContentSlots*>(GetExistingSlots());
723 virtual nsExtendedContentSlots* CreateExtendedSlots() {
724 return new nsExtendedContentSlots();
727 const nsExtendedContentSlots* GetExistingExtendedContentSlots() const {
728 const nsContentSlots* slots = GetExistingContentSlots();
729 return slots ? slots->GetExtendedContentSlots() : nullptr;
732 nsExtendedContentSlots* GetExistingExtendedContentSlots() {
733 nsContentSlots* slots = GetExistingContentSlots();
734 return slots ? slots->GetExtendedContentSlots() : nullptr;
737 nsExtendedContentSlots* ExtendedContentSlots() {
738 nsContentSlots* slots = ContentSlots();
739 if (!slots->GetExtendedContentSlots()) {
740 slots->SetExtendedContentSlots(CreateExtendedSlots(), true);
742 return slots->GetExtendedContentSlots();
746 * Hook for implementing GetID. This is guaranteed to only be
747 * called if HasID() is true.
749 nsAtom* DoGetID() const;
751 ~nsIContent() = default;
753 public:
754 #if defined(DEBUG) || defined(MOZ_DUMP_PAINTING)
755 # define MOZ_DOM_LIST
756 #endif
758 #ifdef MOZ_DOM_LIST
760 * An alias for List() with default arguments. Since some debuggers can't
761 * figure the default arguments easily, having an out-of-line, non-static
762 * function helps quite a lot.
764 void Dump();
767 * List the content (and anything it contains) out to the given
768 * file stream. Use aIndent as the base indent during formatting.
770 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
773 * Dump the content (and anything it contains) out to the given
774 * file stream. Use aIndent as the base indent during formatting.
776 virtual void DumpContent(FILE* out = stdout, int32_t aIndent = 0,
777 bool aDumpAll = true) const = 0;
778 #endif
780 enum ETabFocusType {
781 eTabFocus_textControlsMask =
782 (1 << 0), // textboxes and lists always tabbable
783 eTabFocus_formElementsMask = (1 << 1), // non-text form elements
784 eTabFocus_linksMask = (1 << 2), // links
785 eTabFocus_any = 1 + (1 << 1) + (1 << 2) // everything that can be focused
788 // Tab focus model bit field:
789 static int32_t sTabFocusModel;
791 // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
792 // the tabfocus bit field applies to xul elements.
793 static bool sTabFocusModelAppliesToXUL;
796 NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
798 #endif /* nsIContent_h___ */