michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsIContent_h___ michael@0: #define nsIContent_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsCaseTreatment.h" // for enum, cannot be forward-declared michael@0: #include "nsINode.h" michael@0: michael@0: // Forward declarations michael@0: class nsAString; michael@0: class nsIAtom; michael@0: class nsIURI; michael@0: class nsRuleWalker; michael@0: class nsAttrValue; michael@0: class nsAttrName; michael@0: class nsTextFragment; michael@0: class nsIFrame; michael@0: class nsXBLBinding; michael@0: michael@0: namespace mozilla { michael@0: class EventChainPreVisitor; michael@0: namespace dom { michael@0: class ShadowRoot; michael@0: struct CustomElementData; michael@0: } // namespace dom michael@0: namespace widget { michael@0: struct IMEState; michael@0: } // namespace widget michael@0: } // namespace mozilla michael@0: michael@0: enum nsLinkState { michael@0: eLinkState_Unvisited = 1, michael@0: eLinkState_Visited = 2, michael@0: eLinkState_NotLink = 3 michael@0: }; michael@0: michael@0: // IID for the nsIContent interface michael@0: #define NS_ICONTENT_IID \ michael@0: { 0x1329e5b7, 0x4bcd, 0x450c, \ michael@0: { 0xa2, 0x3a, 0x98, 0xc5, 0x85, 0xcd, 0x73, 0xf9 } } michael@0: michael@0: /** michael@0: * A node of content in a document's content model. This interface michael@0: * is supported by all content objects. michael@0: */ michael@0: class nsIContent : public nsINode { michael@0: public: michael@0: typedef mozilla::widget::IMEState IMEState; michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: // If you're using the external API, the only thing you can know about michael@0: // nsIContent is that it exists with an IID michael@0: michael@0: nsIContent(already_AddRefed& aNodeInfo) michael@0: : nsINode(aNodeInfo) michael@0: { michael@0: MOZ_ASSERT(mNodeInfo); michael@0: SetNodeIsContent(); michael@0: } michael@0: #endif // MOZILLA_INTERNAL_API michael@0: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID) michael@0: michael@0: /** michael@0: * Bind this content node to a tree. If this method throws, the caller must michael@0: * call UnbindFromTree() on the node. In the typical case of a node being michael@0: * appended to a parent, this will be called after the node has been added to michael@0: * the parent's child list and before nsIDocumentObserver notifications for michael@0: * the addition are dispatched. michael@0: * @param aDocument The new document for the content node. Must match the michael@0: * current document of aParent, if aParent is not null. michael@0: * May not be null if aParent is null. michael@0: * @param aParent The new parent for the content node. May be null if the michael@0: * node is being bound as a direct child of the document. michael@0: * @param aBindingParent The new binding parent for the content node. michael@0: * This is must either be non-null if a particular michael@0: * binding parent is desired or match aParent's binding michael@0: * parent. michael@0: * @param aCompileEventHandlers whether to initialize the event handlers in michael@0: * the document (used by nsXULElement) michael@0: * @note either aDocument or aParent must be non-null. If both are null, michael@0: * this method _will_ crash. michael@0: * @note This method must not be called by consumers of nsIContent on a node michael@0: * that is already bound to a tree. Call UnbindFromTree first. michael@0: * @note This method will handle rebinding descendants appropriately (eg michael@0: * changing their binding parent as needed). michael@0: * @note This method does not add the content node to aParent's child list michael@0: * @throws NS_ERROR_OUT_OF_MEMORY if that happens michael@0: */ michael@0: virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, michael@0: nsIContent* aBindingParent, michael@0: bool aCompileEventHandlers) = 0; michael@0: michael@0: /** michael@0: * Unbind this content node from a tree. This will set its current document michael@0: * and binding parent to null. In the typical case of a node being removed michael@0: * from a parent, this will be called after it has been removed from the michael@0: * parent's child list and after the nsIDocumentObserver notifications for michael@0: * the removal have been dispatched. michael@0: * @param aDeep Whether to recursively unbind the entire subtree rooted at michael@0: * this node. The only time false should be passed is when the michael@0: * parent node of the content is being destroyed. michael@0: * @param aNullParent Whether to null out the parent pointer as well. This michael@0: * is usually desirable. This argument should only be false while michael@0: * recursively calling UnbindFromTree when a subtree is detached. michael@0: * @note This method is safe to call on nodes that are not bound to a tree. michael@0: */ michael@0: virtual void UnbindFromTree(bool aDeep = true, michael@0: bool aNullParent = true) = 0; michael@0: michael@0: /** michael@0: * DEPRECATED - Use GetCurrentDoc or GetOwnerDoc. michael@0: * Get the document for this content. michael@0: * @return the document michael@0: */ michael@0: nsIDocument *GetDocument() const michael@0: { michael@0: return GetCurrentDoc(); michael@0: } michael@0: michael@0: enum { michael@0: /** michael@0: * All XBL flattened tree children of the node, as well as :before and michael@0: * :after anonymous content and native anonymous children. michael@0: * michael@0: * @note the result children order is michael@0: * 1. :before generated node michael@0: * 2. XBL flattened tree children of this node michael@0: * 3. native anonymous nodes michael@0: * 4. :after generated node michael@0: */ michael@0: eAllChildren = 0, michael@0: michael@0: /** michael@0: * All XBL explicit children of the node (see michael@0: * http://www.w3.org/TR/xbl/#explicit3 ), as well as :before and :after michael@0: * anonymous content and native anonymous children. michael@0: * michael@0: * @note the result children order is michael@0: * 1. :before generated node michael@0: * 2. XBL explicit children of the node michael@0: * 3. native anonymous nodes michael@0: * 4. :after generated node michael@0: */ michael@0: eAllButXBL = 1, michael@0: michael@0: /** michael@0: * Skip native anonymous content created for placeholder of HTML input, michael@0: * used in conjunction with eAllChildren or eAllButXBL. michael@0: */ michael@0: eSkipPlaceholderContent = 2 michael@0: }; michael@0: michael@0: /** michael@0: * Return either the XBL explicit children of the node or the XBL flattened michael@0: * tree children of the node, depending on the filter, as well as michael@0: * native anonymous children. michael@0: * michael@0: * @note calling this method with eAllButXBL will return children that are michael@0: * also in the eAllButXBL and eAllChildren child lists of other descendants michael@0: * of this node in the tree, but those other nodes cannot be reached from the michael@0: * eAllButXBL child list. michael@0: */ michael@0: virtual already_AddRefed GetChildren(uint32_t aFilter) = 0; michael@0: michael@0: /** michael@0: * Get whether this content is C++-generated anonymous content michael@0: * @see nsIAnonymousContentCreator michael@0: * @return whether this content is anonymous michael@0: */ michael@0: bool IsRootOfNativeAnonymousSubtree() const michael@0: { michael@0: NS_ASSERTION(!HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT) || michael@0: (HasFlag(NODE_IS_ANONYMOUS_ROOT) && michael@0: HasFlag(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE)), michael@0: "Some flags seem to be missing!"); michael@0: return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT); michael@0: } michael@0: michael@0: bool IsRootOfChromeAccessOnlySubtree() const michael@0: { michael@0: return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT | michael@0: NODE_IS_ROOT_OF_CHROME_ONLY_ACCESS); michael@0: } michael@0: michael@0: /** michael@0: * Makes this content anonymous michael@0: * @see nsIAnonymousContentCreator michael@0: */ michael@0: void SetIsNativeAnonymousRoot() michael@0: { michael@0: SetFlags(NODE_IS_ANONYMOUS_ROOT | NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE | michael@0: NODE_IS_NATIVE_ANONYMOUS_ROOT); michael@0: } michael@0: michael@0: /** michael@0: * Returns |this| if it is not chrome-only/native anonymous, otherwise michael@0: * first non chrome-only/native anonymous ancestor. michael@0: */ michael@0: virtual nsIContent* FindFirstNonChromeOnlyAccessContent() const; michael@0: michael@0: /** michael@0: * Returns true if and only if this node has a parent, but is not in michael@0: * its parent's child list. michael@0: */ michael@0: bool IsRootOfAnonymousSubtree() const michael@0: { michael@0: NS_ASSERTION(!IsRootOfNativeAnonymousSubtree() || michael@0: (GetParent() && GetBindingParent() == GetParent()), michael@0: "root of native anonymous subtree must have parent equal " michael@0: "to binding parent"); michael@0: NS_ASSERTION(!GetParent() || michael@0: ((GetBindingParent() == GetParent()) == michael@0: HasFlag(NODE_IS_ANONYMOUS_ROOT)) || michael@0: // Unfortunately default content for XBL insertion points is michael@0: // anonymous content that is bound with the parent of the michael@0: // insertion point as the parent but the bound element for the michael@0: // binding as the binding parent. So we have to complicate michael@0: // the assert a bit here. michael@0: (GetBindingParent() && michael@0: (GetBindingParent() == GetParent()->GetBindingParent()) == michael@0: HasFlag(NODE_IS_ANONYMOUS_ROOT)), michael@0: "For nodes with parent, flag and GetBindingParent() check " michael@0: "should match"); michael@0: return HasFlag(NODE_IS_ANONYMOUS_ROOT); michael@0: } michael@0: michael@0: /** michael@0: * Returns true if there is NOT a path through child lists michael@0: * from the top of this node's parent chain back to this node or michael@0: * if the node is in native anonymous subtree without a parent. michael@0: */ michael@0: bool IsInAnonymousSubtree() const michael@0: { michael@0: NS_ASSERTION(!IsInNativeAnonymousSubtree() || GetBindingParent() || michael@0: (!IsInDoc() && michael@0: static_cast(SubtreeRoot())->IsInNativeAnonymousSubtree()), michael@0: "Must have binding parent when in native anonymous subtree which is in document.\n" michael@0: "Native anonymous subtree which is not in document must have native anonymous root."); michael@0: return IsInNativeAnonymousSubtree() || (!HasFlag(NODE_IS_IN_SHADOW_TREE) && GetBindingParent() != nullptr); michael@0: } michael@0: michael@0: /** michael@0: * Return true iff this node is in an HTML document (in the HTML5 sense of michael@0: * the term, i.e. not in an XHTML/XML document). michael@0: */ michael@0: inline bool IsInHTMLDocument() const; michael@0: michael@0: /** michael@0: * Get the namespace that this element's tag is defined in michael@0: * @return the namespace michael@0: */ michael@0: inline int32_t GetNameSpaceID() const michael@0: { michael@0: return mNodeInfo->NamespaceID(); michael@0: } michael@0: michael@0: /** michael@0: * Get the NodeInfo for this element michael@0: * @return the nodes node info michael@0: */ michael@0: inline nsINodeInfo* NodeInfo() const michael@0: { michael@0: return mNodeInfo; michael@0: } michael@0: michael@0: inline bool IsInNamespace(int32_t aNamespace) const michael@0: { michael@0: return mNodeInfo->NamespaceID() == aNamespace; michael@0: } michael@0: michael@0: inline bool IsHTML() const michael@0: { michael@0: return IsInNamespace(kNameSpaceID_XHTML); michael@0: } michael@0: michael@0: inline bool IsHTML(nsIAtom* aTag) const michael@0: { michael@0: return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML); michael@0: } michael@0: michael@0: inline bool IsSVG() const michael@0: { michael@0: return IsInNamespace(kNameSpaceID_SVG); michael@0: } michael@0: michael@0: inline bool IsSVG(nsIAtom* aTag) const michael@0: { michael@0: return mNodeInfo->Equals(aTag, kNameSpaceID_SVG); michael@0: } michael@0: michael@0: inline bool IsXUL() const michael@0: { michael@0: return IsInNamespace(kNameSpaceID_XUL); michael@0: } michael@0: michael@0: inline bool IsXUL(nsIAtom* aTag) const michael@0: { michael@0: return mNodeInfo->Equals(aTag, kNameSpaceID_XUL); michael@0: } michael@0: michael@0: inline bool IsMathML() const michael@0: { michael@0: return IsInNamespace(kNameSpaceID_MathML); michael@0: } michael@0: michael@0: inline bool IsMathML(nsIAtom* aTag) const michael@0: { michael@0: return mNodeInfo->Equals(aTag, kNameSpaceID_MathML); michael@0: } michael@0: michael@0: inline bool IsActiveChildrenElement() const michael@0: { michael@0: return mNodeInfo->Equals(nsGkAtoms::children, kNameSpaceID_XBL) && michael@0: GetBindingParent(); michael@0: } michael@0: michael@0: /** michael@0: * Returns an atom holding the name of the attribute of type ID on michael@0: * this content node (if applicable). Returns null for non-element michael@0: * content nodes. michael@0: */ michael@0: virtual nsIAtom *GetIDAttributeName() const = 0; michael@0: michael@0: /** michael@0: * Set attribute values. All attribute values are assumed to have a michael@0: * canonical string representation that can be used for these michael@0: * methods. The SetAttr method is assumed to perform a translation michael@0: * of the canonical form into the underlying content specific michael@0: * form. michael@0: * michael@0: * @param aNameSpaceID the namespace of the attribute michael@0: * @param aName the name of the attribute michael@0: * @param aValue the value to set michael@0: * @param aNotify specifies how whether or not the document should be michael@0: * notified of the attribute change. michael@0: */ michael@0: nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, michael@0: const nsAString& aValue, bool aNotify) michael@0: { michael@0: return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); michael@0: } michael@0: michael@0: /** michael@0: * Set attribute values. All attribute values are assumed to have a michael@0: * canonical String representation that can be used for these michael@0: * methods. The SetAttr method is assumed to perform a translation michael@0: * of the canonical form into the underlying content specific michael@0: * form. michael@0: * michael@0: * @param aNameSpaceID the namespace of the attribute michael@0: * @param aName the name of the attribute michael@0: * @param aPrefix the prefix of the attribute michael@0: * @param aValue the value to set michael@0: * @param aNotify specifies how whether or not the document should be michael@0: * notified of the attribute change. michael@0: */ michael@0: virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, michael@0: nsIAtom* aPrefix, const nsAString& aValue, michael@0: bool aNotify) = 0; michael@0: michael@0: /** michael@0: * Get the current value of the attribute. This returns a form that is michael@0: * suitable for passing back into SetAttr. michael@0: * michael@0: * @param aNameSpaceID the namespace of the attr michael@0: * @param aName the name of the attr michael@0: * @param aResult the value (may legitimately be the empty string) [OUT] michael@0: * @returns true if the attribute was set (even when set to empty string) michael@0: * false when not set. michael@0: */ michael@0: bool GetAttr(int32_t aNameSpaceID, nsIAtom* aName, michael@0: nsAString& aResult) const; michael@0: michael@0: /** michael@0: * Determine if an attribute has been set (empty string or otherwise). michael@0: * michael@0: * @param aNameSpaceId the namespace id of the attribute michael@0: * @param aAttr the attribute name michael@0: * @return whether an attribute exists michael@0: */ michael@0: bool HasAttr(int32_t aNameSpaceID, nsIAtom* aName) const; michael@0: michael@0: /** michael@0: * Test whether this content node's given attribute has the given value. If michael@0: * the attribute is not set at all, this will return false. michael@0: * michael@0: * @param aNameSpaceID The namespace ID of the attribute. Must not michael@0: * be kNameSpaceID_Unknown. michael@0: * @param aName The name atom of the attribute. Must not be null. michael@0: * @param aValue The value to compare to. michael@0: * @param aCaseSensitive Whether to do a case-sensitive compare on the value. michael@0: */ michael@0: bool AttrValueIs(int32_t aNameSpaceID, michael@0: nsIAtom* aName, michael@0: const nsAString& aValue, michael@0: nsCaseTreatment aCaseSensitive) const; michael@0: michael@0: /** michael@0: * Test whether this content node's given attribute has the given value. If michael@0: * the attribute is not set at all, this will return false. michael@0: * michael@0: * @param aNameSpaceID The namespace ID of the attribute. Must not michael@0: * be kNameSpaceID_Unknown. michael@0: * @param aName The name atom of the attribute. Must not be null. michael@0: * @param aValue The value to compare to. Must not be null. michael@0: * @param aCaseSensitive Whether to do a case-sensitive compare on the value. michael@0: */ michael@0: bool AttrValueIs(int32_t aNameSpaceID, michael@0: nsIAtom* aName, michael@0: nsIAtom* aValue, michael@0: nsCaseTreatment aCaseSensitive) const; michael@0: michael@0: enum { michael@0: ATTR_MISSING = -1, michael@0: ATTR_VALUE_NO_MATCH = -2 michael@0: }; michael@0: /** michael@0: * Check whether this content node's given attribute has one of a given michael@0: * list of values. If there is a match, we return the index in the list michael@0: * of the first matching value. If there was no attribute at all, then michael@0: * we return ATTR_MISSING. If there was an attribute but it didn't michael@0: * match, we return ATTR_VALUE_NO_MATCH. A non-negative result always michael@0: * indicates a match. michael@0: * michael@0: * @param aNameSpaceID The namespace ID of the attribute. Must not michael@0: * be kNameSpaceID_Unknown. michael@0: * @param aName The name atom of the attribute. Must not be null. michael@0: * @param aValues a nullptr-terminated array of pointers to atom values to test michael@0: * against. michael@0: * @param aCaseSensitive Whether to do a case-sensitive compare on the values. michael@0: * @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index michael@0: * indicating the first value of aValues that matched michael@0: */ michael@0: typedef nsIAtom* const* const AttrValuesArray; michael@0: virtual int32_t FindAttrValueIn(int32_t aNameSpaceID, michael@0: nsIAtom* aName, michael@0: AttrValuesArray* aValues, michael@0: nsCaseTreatment aCaseSensitive) const michael@0: { michael@0: return ATTR_MISSING; michael@0: } michael@0: michael@0: /** michael@0: * Remove an attribute so that it is no longer explicitly specified. michael@0: * michael@0: * @param aNameSpaceID the namespace id of the attribute michael@0: * @param aAttr the name of the attribute to unset michael@0: * @param aNotify specifies whether or not the document should be michael@0: * notified of the attribute change michael@0: */ michael@0: virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr, michael@0: bool aNotify) = 0; michael@0: michael@0: michael@0: /** michael@0: * Get the namespace / name / prefix of a given attribute. michael@0: * michael@0: * @param aIndex the index of the attribute name michael@0: * @returns The name at the given index, or null if the index is michael@0: * out-of-bounds. michael@0: * @note The document returned by NodeInfo()->GetDocument() (if one is michael@0: * present) is *not* necessarily the owner document of the element. michael@0: * @note The pointer returned by this function is only valid until the michael@0: * next call of either GetAttrNameAt or SetAttr on the element. michael@0: */ michael@0: virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const = 0; michael@0: michael@0: /** michael@0: * Get the number of all specified attributes. michael@0: * michael@0: * @return the number of attributes michael@0: */ michael@0: virtual uint32_t GetAttrCount() const = 0; michael@0: michael@0: /** michael@0: * Get direct access (but read only) to the text in the text content. michael@0: * NOTE: For elements this is *not* the concatenation of all text children, michael@0: * it is simply null; michael@0: */ michael@0: virtual const nsTextFragment *GetText() = 0; michael@0: michael@0: /** michael@0: * Get the length of the text content. michael@0: * NOTE: This should not be called on elements. michael@0: */ michael@0: virtual uint32_t TextLength() const = 0; michael@0: michael@0: /** michael@0: * Determines if an event attribute name (such as onclick) is valid for michael@0: * a given element type. michael@0: * @note calls nsContentUtils::IsEventAttributeName with right flag michael@0: * @note overridden by subclasses as needed michael@0: * @param aName the event name to look up michael@0: */ michael@0: virtual bool IsEventAttributeName(nsIAtom* aName) michael@0: { michael@0: return false; michael@0: } michael@0: michael@0: /** michael@0: * Set the text to the given value. If aNotify is true then michael@0: * the document is notified of the content change. michael@0: * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE michael@0: */ michael@0: virtual nsresult SetText(const char16_t* aBuffer, uint32_t aLength, michael@0: bool aNotify) = 0; michael@0: michael@0: /** michael@0: * Append the given value to the current text. If aNotify is true then michael@0: * the document is notified of the content change. michael@0: * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE michael@0: */ michael@0: virtual nsresult AppendText(const char16_t* aBuffer, uint32_t aLength, michael@0: bool aNotify) = 0; michael@0: michael@0: /** michael@0: * Set the text to the given value. If aNotify is true then michael@0: * the document is notified of the content change. michael@0: * NOTE: For elements this always asserts and returns NS_ERROR_FAILURE michael@0: */ michael@0: nsresult SetText(const nsAString& aStr, bool aNotify) michael@0: { michael@0: return SetText(aStr.BeginReading(), aStr.Length(), aNotify); michael@0: } michael@0: michael@0: /** michael@0: * Query method to see if the frame is nothing but whitespace michael@0: * NOTE: Always returns false for elements michael@0: */ michael@0: virtual bool TextIsOnlyWhitespace() = 0; michael@0: michael@0: /** michael@0: * Method to see if the text node contains data that is useful michael@0: * for a translation: i.e., it consists of more than just whitespace, michael@0: * digits and punctuation. michael@0: * NOTE: Always returns false for elements. michael@0: */ michael@0: virtual bool HasTextForTranslation() = 0; michael@0: michael@0: /** michael@0: * Append the text content to aResult. michael@0: * NOTE: This asserts and returns for elements michael@0: */ michael@0: virtual void AppendTextTo(nsAString& aResult) = 0; michael@0: michael@0: /** michael@0: * Append the text content to aResult. michael@0: * NOTE: This asserts and returns for elements michael@0: */ michael@0: virtual bool AppendTextTo(nsAString& aResult, michael@0: const mozilla::fallible_t&) NS_WARN_UNUSED_RESULT = 0; michael@0: michael@0: /** michael@0: * Check if this content is focusable and in the current tab order. michael@0: * Note: most callers should use nsIFrame::IsFocusable() instead as it michael@0: * checks visibility and other layout factors as well. michael@0: * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable. michael@0: * For example, only the selected radio button in a group is in the michael@0: * tab order, unless the radio group has no selection in which case michael@0: * all of the visible, non-disabled radio buttons in the group are michael@0: * in the tab order. On the other hand, all of the visible, non-disabled michael@0: * radio buttons are always focusable via clicking or script. michael@0: * Also, depending on either the accessibility.tabfocus pref or michael@0: * a system setting (nowadays: Full keyboard access, mac only) michael@0: * some widgets may be focusable but removed from the tab order. michael@0: * @param [inout, optional] aTabIndex the computed tab index michael@0: * In: default tabindex for element (-1 nonfocusable, == 0 focusable) michael@0: * Out: computed tabindex michael@0: * @param [optional] aTabIndex the computed tab index michael@0: * < 0 if not tabbable michael@0: * == 0 if in normal tab order michael@0: * > 0 can be tabbed to in the order specified by this value michael@0: * @return whether the content is focusable via mouse, kbd or script. michael@0: */ michael@0: bool IsFocusable(int32_t* aTabIndex = nullptr, bool aWithMouse = false); michael@0: virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse); michael@0: michael@0: /** michael@0: * The method focuses (or activates) element that accesskey is bound to. It is michael@0: * called when accesskey is activated. michael@0: * michael@0: * @param aKeyCausesActivation - if true then element should be activated michael@0: * @param aIsTrustedEvent - if true then event that is cause of accesskey michael@0: * execution is trusted. michael@0: */ michael@0: virtual void PerformAccesskey(bool aKeyCausesActivation, michael@0: bool aIsTrustedEvent) michael@0: { michael@0: } michael@0: michael@0: /* michael@0: * Get desired IME state for the content. michael@0: * michael@0: * @return The desired IME status for the content. michael@0: * This is a combination of an IME enabled value and michael@0: * an IME open value of widget::IMEState. michael@0: * If you return DISABLED, you should not set the OPEN and CLOSE michael@0: * value. michael@0: * PASSWORD should be returned only from password editor, this value michael@0: * has a special meaning. It is used as alternative of DISABLED. michael@0: * PLUGIN should be returned only when plug-in has focus. When a michael@0: * plug-in is focused content, we should send native events directly. michael@0: * Because we don't process some native events, but they may be needed michael@0: * by the plug-in. michael@0: */ michael@0: virtual IMEState GetDesiredIMEState(); michael@0: michael@0: /** michael@0: * Gets content node with the binding (or native code, possibly on the michael@0: * frame) responsible for our construction (and existence). Used by michael@0: * anonymous content (both XBL-generated and native-anonymous). michael@0: * michael@0: * null for all explicit content (i.e., content reachable from the top michael@0: * of its GetParent() chain via child lists). michael@0: * michael@0: * @return the binding parent michael@0: */ michael@0: virtual nsIContent *GetBindingParent() const = 0; michael@0: michael@0: /** michael@0: * Gets the current XBL binding that is bound to this element. michael@0: * michael@0: * @return the current binding. michael@0: */ michael@0: virtual nsXBLBinding *GetXBLBinding() const = 0; michael@0: michael@0: /** michael@0: * Sets or unsets an XBL binding for this element. Setting a michael@0: * binding on an element that already has a binding will remove the michael@0: * old binding. michael@0: * michael@0: * @param aBinding The binding to bind to this content. If nullptr is michael@0: * provided as the argument, then existing binding will be michael@0: * removed. michael@0: * michael@0: * @param aOldBindingManager The old binding manager that contains michael@0: * this content if this content was adopted michael@0: * to another document. michael@0: */ michael@0: virtual void SetXBLBinding(nsXBLBinding* aBinding, michael@0: nsBindingManager* aOldBindingManager = nullptr) = 0; michael@0: michael@0: /** michael@0: * Sets the ShadowRoot binding for this element. The contents of the michael@0: * binding is rendered in place of this node's children. michael@0: * michael@0: * @param aShadowRoot The ShadowRoot to be bound to this element. michael@0: */ michael@0: virtual void SetShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot) = 0; michael@0: michael@0: /** michael@0: * Gets the ShadowRoot binding for this element. michael@0: * michael@0: * @return The ShadowRoot currently bound to this element. michael@0: */ michael@0: virtual mozilla::dom::ShadowRoot *GetShadowRoot() const = 0; michael@0: michael@0: /** michael@0: * Gets the root of the node tree for this content if it is in a shadow tree. michael@0: * This method is called |GetContainingShadow| instead of |GetRootShadowRoot| michael@0: * to avoid confusion with |GetShadowRoot|. michael@0: * michael@0: * @return The ShadowRoot that is the root of the node tree. michael@0: */ michael@0: virtual mozilla::dom::ShadowRoot *GetContainingShadow() const = 0; michael@0: michael@0: /** michael@0: * Gets the insertion parent element of the XBL binding. michael@0: * The insertion parent is our one true parent in the transformed DOM. michael@0: * michael@0: * @return the insertion parent element. michael@0: */ michael@0: virtual nsIContent *GetXBLInsertionParent() const = 0; michael@0: michael@0: /** michael@0: * Sets the insertion parent element of the XBL binding. michael@0: * michael@0: * @param aContent The insertion parent element. michael@0: */ michael@0: virtual void SetXBLInsertionParent(nsIContent* aContent) = 0; michael@0: michael@0: /** michael@0: * Returns the content node that is the parent of this node in the flattened michael@0: * tree. For nodes that are not filtered into an insertion point, this michael@0: * simply returns their DOM parent in the original DOM tree. michael@0: * michael@0: * @return the flattened tree parent michael@0: */ michael@0: nsIContent *GetFlattenedTreeParent() const; michael@0: michael@0: /** michael@0: * Gets the custom element data used by web components custom element. michael@0: * Custom element data is created at the first attempt to enqueue a callback. michael@0: * michael@0: * @return The custom element data or null if none. michael@0: */ michael@0: virtual mozilla::dom::CustomElementData *GetCustomElementData() const = 0; michael@0: michael@0: /** michael@0: * Sets the custom element data, ownership of the michael@0: * callback data is taken by this content. michael@0: * michael@0: * @param aCallbackData The custom element data. michael@0: */ michael@0: virtual void SetCustomElementData(mozilla::dom::CustomElementData* aData) = 0; michael@0: michael@0: /** michael@0: * API to check if this is a link that's traversed in response to user input michael@0: * (e.g. a click event). Specializations for HTML/SVG/generic XML allow for michael@0: * different types of link in different types of content. michael@0: * michael@0: * @param aURI Required out param. If this content is a link, a new nsIURI michael@0: * set to this link's URI will be passed out. michael@0: * michael@0: * @note The out param, aURI, is guaranteed to be set to a non-null pointer michael@0: * when the return value is true. michael@0: * michael@0: * XXXjwatt: IMO IsInteractiveLink would be a better name. michael@0: */ michael@0: virtual bool IsLink(nsIURI** aURI) const = 0; michael@0: michael@0: /** michael@0: * Get a pointer to the full href URI (fully resolved and canonicalized, michael@0: * since it's an nsIURI object) for link elements. michael@0: * michael@0: * @return A pointer to the URI or null if the element is not a link or it michael@0: * has no HREF attribute. michael@0: */ michael@0: virtual already_AddRefed GetHrefURI() const michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: /** michael@0: * This method is called when the parser finishes creating the element. This michael@0: * particularly means that it has done everything you would expect it to have michael@0: * done after it encounters the > at the end of the tag (for HTML or XML). michael@0: * This includes setting the attributes, setting the document / form, and michael@0: * placing the element into the tree at its proper place. michael@0: * michael@0: * For container elements, this is called *before* any of the children are michael@0: * created or added into the tree. michael@0: * michael@0: * NOTE: this is currently only called for input and button, in the HTML michael@0: * content sink. If you want to call it on your element, modify the content michael@0: * sink of your choice to do so. This is an efficiency measure. michael@0: * michael@0: * If you also need to determine whether the parser is the one creating your michael@0: * element (through createElement() or cloneNode() generally) then add a michael@0: * uint32_t aFromParser to the NS_NewXXX() constructor for your element and michael@0: * have the parser pass the appropriate flags. See HTMLInputElement.cpp and michael@0: * nsHTMLContentSink::MakeContentObject(). michael@0: * michael@0: * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with michael@0: * attributes dynamically. If you make attributes affect your element from michael@0: * this method, it will only happen on initialization and JavaScript will not michael@0: * be able to create elements (which requires them to first create the michael@0: * element and then call setAttribute() directly, at which point michael@0: * DoneCreatingElement() has already been called and is out of the picture). michael@0: */ michael@0: virtual void DoneCreatingElement() michael@0: { michael@0: } michael@0: michael@0: /** michael@0: * This method is called when the parser begins creating the element's michael@0: * children, if any are present. michael@0: * michael@0: * This is only called for XTF elements currently. michael@0: */ michael@0: virtual void BeginAddingChildren() michael@0: { michael@0: } michael@0: michael@0: /** michael@0: * This method is called when the parser finishes creating the element's children, michael@0: * if any are present. michael@0: * michael@0: * NOTE: this is currently only called for textarea, select, applet, and michael@0: * object elements in the HTML content sink. If you want michael@0: * to call it on your element, modify the content sink of your michael@0: * choice to do so. This is an efficiency measure. michael@0: * michael@0: * If you also need to determine whether the parser is the one creating your michael@0: * element (through createElement() or cloneNode() generally) then add a michael@0: * boolean aFromParser to the NS_NewXXX() constructor for your element and michael@0: * have the parser pass true. See HTMLInputElement.cpp and michael@0: * nsHTMLContentSink::MakeContentObject(). michael@0: * michael@0: * @param aHaveNotified Whether there has been a michael@0: * ContentInserted/ContentAppended notification for this content node michael@0: * yet. michael@0: */ michael@0: virtual void DoneAddingChildren(bool aHaveNotified) michael@0: { michael@0: } michael@0: michael@0: /** michael@0: * For HTML textarea, select, applet, and object elements, returns michael@0: * true if all children have been added OR if the element was not michael@0: * created by the parser. Returns true for all other elements. michael@0: * @returns false if the element was created by the parser and michael@0: * it is an HTML textarea, select, applet, or object michael@0: * element and not all children have been added. michael@0: * @returns true otherwise. michael@0: */ michael@0: virtual bool IsDoneAddingChildren() michael@0: { michael@0: return true; michael@0: } michael@0: michael@0: /** michael@0: * Get the ID of this content node (the atom corresponding to the michael@0: * value of the null-namespace attribute whose name is given by michael@0: * GetIDAttributeName(). This may be null if there is no ID. michael@0: */ michael@0: nsIAtom* GetID() const { michael@0: if (HasID()) { michael@0: return DoGetID(); michael@0: } michael@0: return nullptr; michael@0: } michael@0: michael@0: /** michael@0: * Get the class list of this content node (this corresponds to the michael@0: * value of the null-namespace attribute whose name is given by michael@0: * GetClassAttributeName()). This may be null if there are no michael@0: * classes, but that's not guaranteed. michael@0: */ michael@0: const nsAttrValue* GetClasses() const { michael@0: if (HasFlag(NODE_MAY_HAVE_CLASS)) { michael@0: return DoGetClasses(); michael@0: } michael@0: return nullptr; michael@0: } michael@0: michael@0: /** michael@0: * Walk aRuleWalker over the content style rules (presentational michael@0: * hint rules) for this content node. michael@0: */ michael@0: NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) = 0; michael@0: michael@0: /** michael@0: * Should be called when the node can become editable or when it can stop michael@0: * being editable (for example when its contentEditable attribute changes, michael@0: * when it is moved into an editable parent, ...). If aNotify is true and michael@0: * the node is an element, this will notify the state change. michael@0: */ michael@0: virtual void UpdateEditableState(bool aNotify); michael@0: michael@0: /** michael@0: * Destroy this node and its children. Ideally this shouldn't be needed michael@0: * but for now we need to do it to break cycles. michael@0: */ michael@0: virtual void DestroyContent() = 0; michael@0: michael@0: /** michael@0: * Saves the form state of this node and its children. michael@0: */ michael@0: virtual void SaveSubtreeState() = 0; michael@0: michael@0: /** michael@0: * Getter and setter for our primary frame pointer. This is the frame that michael@0: * is most closely associated with the content. A frame is more closely michael@0: * associated with the content than another frame if the one frame contains michael@0: * directly or indirectly the other frame (e.g., when a frame is scrolled michael@0: * there is a scroll frame that contains the frame being scrolled). This michael@0: * frame is always the first continuation. michael@0: * michael@0: * In the case of absolutely positioned elements and floated elements, this michael@0: * frame is the out of flow frame, not the placeholder. michael@0: */ michael@0: nsIFrame* GetPrimaryFrame() const michael@0: { michael@0: return IsInDoc() ? mPrimaryFrame : nullptr; michael@0: } michael@0: void SetPrimaryFrame(nsIFrame* aFrame) { michael@0: NS_ASSERTION(IsInDoc(), "This will end badly!"); michael@0: NS_PRECONDITION(!aFrame || !mPrimaryFrame || aFrame == mPrimaryFrame, michael@0: "Losing track of existing primary frame"); michael@0: mPrimaryFrame = aFrame; michael@0: } michael@0: michael@0: nsresult LookupNamespaceURIInternal(const nsAString& aNamespacePrefix, michael@0: nsAString& aNamespaceURI) const; michael@0: michael@0: /** michael@0: * If this content has independent selection, e.g., if this is input field michael@0: * or textarea, this return TRUE. Otherwise, false. michael@0: */ michael@0: bool HasIndependentSelection(); michael@0: michael@0: /** michael@0: * If the content is a part of HTML editor, this returns editing michael@0: * host content. When the content is in designMode, this returns its body michael@0: * element. Also, when the content isn't editable, this returns null. michael@0: */ michael@0: mozilla::dom::Element* GetEditingHost(); michael@0: michael@0: /** michael@0: * Determing language. Look at the nearest ancestor element that has a lang michael@0: * attribute in the XML namespace or is an HTML/SVG element and has a lang in michael@0: * no namespace attribute. michael@0: */ michael@0: void GetLang(nsAString& aResult) const { michael@0: for (const nsIContent* content = this; content; content = content->GetParent()) { michael@0: if (content->GetAttrCount() > 0) { michael@0: // xml:lang has precedence over lang on HTML elements (see michael@0: // XHTML1 section C.7). michael@0: bool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang, michael@0: aResult); michael@0: if (!hasAttr && (content->IsHTML() || content->IsSVG())) { michael@0: hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang, michael@0: aResult); michael@0: } michael@0: NS_ASSERTION(hasAttr || aResult.IsEmpty(), michael@0: "GetAttr that returns false should not make string non-empty"); michael@0: if (hasAttr) { michael@0: return; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: // Overloaded from nsINode michael@0: virtual already_AddRefed GetBaseURI(bool aTryUseXHRDocBaseURI = false) const MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult PreHandleEvent( michael@0: mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsPurple() = 0; michael@0: virtual void RemovePurple() = 0; michael@0: michael@0: virtual bool OwnedOnlyByTheDOMTree() { return false; } michael@0: protected: michael@0: /** michael@0: * Hook for implementing GetID. This is guaranteed to only be michael@0: * called if HasID() is true. michael@0: */ michael@0: virtual nsIAtom* DoGetID() const = 0; michael@0: michael@0: private: michael@0: /** michael@0: * Hook for implementing GetClasses. This is guaranteed to only be michael@0: * called if the NODE_MAY_HAVE_CLASS flag is set. michael@0: */ michael@0: virtual const nsAttrValue* DoGetClasses() const = 0; michael@0: michael@0: public: michael@0: #ifdef DEBUG michael@0: /** michael@0: * List the content (and anything it contains) out to the given michael@0: * file stream. Use aIndent as the base indent during formatting. michael@0: */ michael@0: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; michael@0: michael@0: /** michael@0: * Dump the content (and anything it contains) out to the given michael@0: * file stream. Use aIndent as the base indent during formatting. michael@0: */ michael@0: virtual void DumpContent(FILE* out = stdout, int32_t aIndent = 0, michael@0: bool aDumpAll = true) const = 0; michael@0: #endif michael@0: michael@0: /** michael@0: * Append to aOutDescription a short (preferably one line) string michael@0: * describing the content. michael@0: * Currently implemented for elements only. michael@0: */ michael@0: virtual void Describe(nsAString& aOutDescription) const { michael@0: aOutDescription = NS_LITERAL_STRING("(not an element)"); michael@0: } michael@0: michael@0: enum ETabFocusType { michael@0: //eTabFocus_textControlsMask = (1<<0), // unused - textboxes always tabbable michael@0: eTabFocus_formElementsMask = (1<<1), // non-text form elements michael@0: eTabFocus_linksMask = (1<<2), // links michael@0: eTabFocus_any = 1 + (1<<1) + (1<<2) // everything that can be focused michael@0: }; michael@0: michael@0: // Tab focus model bit field: michael@0: static int32_t sTabFocusModel; michael@0: michael@0: // accessibility.tabfocus_applies_to_xul pref - if it is set to true, michael@0: // the tabfocus bit field applies to xul elements. michael@0: static bool sTabFocusModelAppliesToXUL; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID) michael@0: michael@0: inline nsIContent* nsINode::AsContent() michael@0: { michael@0: MOZ_ASSERT(IsContent()); michael@0: return static_cast(this); michael@0: } michael@0: michael@0: #define NS_IMPL_FROMCONTENT_HELPER(_class, _check) \ michael@0: static _class* FromContent(nsIContent* aContent) \ michael@0: { \ michael@0: return aContent->_check ? static_cast<_class*>(aContent) : nullptr; \ michael@0: } \ michael@0: static _class* FromContentOrNull(nsIContent* aContent) \ michael@0: { \ michael@0: return aContent ? FromContent(aContent) : nullptr; \ michael@0: } michael@0: michael@0: #define NS_IMPL_FROMCONTENT(_class, _nsid) \ michael@0: NS_IMPL_FROMCONTENT_HELPER(_class, IsInNamespace(_nsid)) michael@0: michael@0: #define NS_IMPL_FROMCONTENT_WITH_TAG(_class, _nsid, _tag) \ michael@0: NS_IMPL_FROMCONTENT_HELPER(_class, NodeInfo()->Equals(nsGkAtoms::_tag, _nsid)) michael@0: michael@0: #define NS_IMPL_FROMCONTENT_HTML_WITH_TAG(_class, _tag) \ michael@0: NS_IMPL_FROMCONTENT_WITH_TAG(_class, kNameSpaceID_XHTML, _tag) michael@0: michael@0: #endif /* nsIContent_h___ */