1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef nsIContent_h___
38 #define nsIContent_h___
40 #include "nsCOMPtr.h" // for already_AddRefed
41 #include "nsStringGlue.h"
42 #include "nsCaseTreatment.h"
43 #include "nsChangeHint.h"
45 #include "nsIProgrammingLanguage.h" // for ::JAVASCRIPT
47 // Forward declarations
54 class nsIEventListenerManager
;
56 class nsICSSStyleRule
;
63 // IID for the nsIContent interface
64 #define NS_ICONTENT_IID \
65 { 0x0acd0482, 0x09a2, 0x42fd, \
66 { 0xb6, 0x1b, 0x95, 0xa2, 0x01, 0x6a, 0x55, 0xd3 } }
69 * A node of content in a document's content model. This interface
70 * is supported by all content objects.
72 class nsIContent
: public nsINode
{
74 #ifdef MOZILLA_INTERNAL_API
75 // If you're using the external API, the only thing you can know about
76 // nsIContent is that it exists with an IID
78 nsIContent(nsINodeInfo
*aNodeInfo
)
81 NS_ASSERTION(aNodeInfo
,
82 "No nsINodeInfo passed to nsIContent, PREPARE TO CRASH!!!");
84 #endif // MOZILLA_INTERNAL_API
86 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID
)
89 * Bind this content node to a tree. If this method throws, the caller must
90 * call UnbindFromTree() on the node. In the typical case of a node being
91 * appended to a parent, this will be called after the node has been added to
92 * the parent's child list and before nsIDocumentObserver notifications for
93 * the addition are dispatched.
94 * @param aDocument The new document for the content node. Must match the
95 * current document of aParent, if aParent is not null.
96 * May not be null if aParent is null.
97 * @param aParent The new parent for the content node. May be null if the
98 * node is being bound as a direct child of the document.
99 * @param aBindingParent The new binding parent for the content node.
100 * This is allowed to be null. In that case, the
101 * binding parent of aParent, if any, will be used.
102 * @param aCompileEventHandlers whether to initialize the event handlers in
103 * the document (used by nsXULElement)
104 * @note either aDocument or aParent must be non-null. If both are null,
105 * this method _will_ crash.
106 * @note This method must not be called by consumers of nsIContent on a node
107 * that is already bound to a tree. Call UnbindFromTree first.
108 * @note This method will handle rebinding descendants appropriately (eg
109 * changing their binding parent as needed).
110 * @note This method does not add the content node to aParent's child list
111 * @throws NS_ERROR_OUT_OF_MEMORY if that happens
113 virtual nsresult
BindToTree(nsIDocument
* aDocument
, nsIContent
* aParent
,
114 nsIContent
* aBindingParent
,
115 PRBool aCompileEventHandlers
) = 0;
118 * Unbind this content node from a tree. This will set its current document
119 * and binding parent to null. In the typical case of a node being removed
120 * from a parent, this will be called after it has been removed from the
121 * parent's child list and after the nsIDocumentObserver notifications for
122 * the removal have been dispatched.
123 * @param aDeep Whether to recursively unbind the entire subtree rooted at
124 * this node. The only time PR_FALSE should be passed is when the
125 * parent node of the content is being destroyed.
126 * @param aNullParent Whether to null out the parent pointer as well. This
127 * is usually desirable. This argument should only be false while
128 * recursively calling UnbindFromTree when a subtree is detached.
129 * @note This method is safe to call on nodes that are not bound to a tree.
131 virtual void UnbindFromTree(PRBool aDeep
= PR_TRUE
,
132 PRBool aNullParent
= PR_TRUE
) = 0;
135 * DEPRECATED - Use GetCurrentDoc or GetOwnerDoc.
136 * Get the document for this content.
137 * @return the document
139 nsIDocument
*GetDocument() const
141 return GetCurrentDoc();
145 * Get whether this content is C++-generated anonymous content
146 * @see nsIAnonymousContentCreator
147 * @return whether this content is anonymous
149 PRBool
IsRootOfNativeAnonymousSubtree() const
151 return HasFlag(NODE_IS_ANONYMOUS
);
155 * Makes this content anonymous
156 * @see nsIAnonymousContentCreator
158 void SetNativeAnonymous()
160 SetFlags(NODE_IS_ANONYMOUS
);
164 * Returns |this| if it is not native anonymous, otherwise
165 * first non native anonymous ancestor.
167 virtual nsIContent
* FindFirstNonNativeAnonymous() const;
170 * Returns PR_TRUE if |this| or any of its ancestors is native anonymous.
172 PRBool
IsInNativeAnonymousSubtree() const
175 if (HasFlag(NODE_IS_IN_ANONYMOUS_SUBTREE
)) {
178 nsIContent
* content
= GetBindingParent();
180 if (content
->IsRootOfNativeAnonymousSubtree()) {
181 NS_ERROR("Element not marked to be in native anonymous subtree!");
184 content
= content
->GetBindingParent();
188 return HasFlag(NODE_IS_IN_ANONYMOUS_SUBTREE
);
193 * Returns true if and only if this node has a parent, but is not in
194 * its parent's child list.
196 PRBool
IsRootOfAnonymousSubtree() const
198 NS_ASSERTION(!IsRootOfNativeAnonymousSubtree() ||
199 (GetParent() && GetBindingParent() == GetParent()),
200 "root of native anonymous subtree must have parent equal "
201 "to binding parent");
202 nsIContent
*bindingParent
= GetBindingParent();
203 return bindingParent
&& bindingParent
== GetParent();
207 * Returns true if and only if there is NOT a path through child lists
208 * from the top of this node's parent chain back to this node.
210 PRBool
IsInAnonymousSubtree() const
212 NS_ASSERTION(!IsInNativeAnonymousSubtree() || GetBindingParent(),
213 "must have binding parent when in native anonymous subtree");
214 return GetBindingParent() != nsnull
;
218 * Get the namespace that this element's tag is defined in
219 * @return the namespace
221 PRInt32
GetNameSpaceID() const
223 return mNodeInfo
->NamespaceID();
227 * Get the tag for this element. This will always return a non-null
228 * atom pointer (as implied by the naming of the method).
232 return mNodeInfo
->NameAtom();
236 * Get the NodeInfo for this element
237 * @return the nodes node info
239 nsINodeInfo
*NodeInfo() const
245 * Returns an atom holding the name of the attribute of type ID on
246 * this content node (if applicable). Returns null for non-element
249 virtual nsIAtom
*GetIDAttributeName() const = 0;
252 * Normalizes an attribute name and returns it as a nodeinfo if an attribute
253 * with that name exists. This method is intended for character case
254 * conversion if the content object is case insensitive (e.g. HTML). Returns
255 * the nodeinfo of the attribute with the specified name if one exists or
258 * @param aStr the unparsed attribute string
259 * @return the node info. May be nsnull.
261 virtual already_AddRefed
<nsINodeInfo
> GetExistingAttrNameFromQName(const nsAString
& aStr
) const = 0;
264 * Set attribute values. All attribute values are assumed to have a
265 * canonical string representation that can be used for these
266 * methods. The SetAttr method is assumed to perform a translation
267 * of the canonical form into the underlying content specific
270 * @param aNameSpaceID the namespace of the attribute
271 * @param aName the name of the attribute
272 * @param aValue the value to set
273 * @param aNotify specifies how whether or not the document should be
274 * notified of the attribute change.
276 nsresult
SetAttr(PRInt32 aNameSpaceID
, nsIAtom
* aName
,
277 const nsAString
& aValue
, PRBool aNotify
)
279 return SetAttr(aNameSpaceID
, aName
, nsnull
, aValue
, aNotify
);
283 * Set attribute values. All attribute values are assumed to have a
284 * canonical String representation that can be used for these
285 * methods. The SetAttr method is assumed to perform a translation
286 * of the canonical form into the underlying content specific
289 * @param aNameSpaceID the namespace of the attribute
290 * @param aName the name of the attribute
291 * @param aPrefix the prefix of the attribute
292 * @param aValue the value to set
293 * @param aNotify specifies how whether or not the document should be
294 * notified of the attribute change.
296 virtual nsresult
SetAttr(PRInt32 aNameSpaceID
, nsIAtom
* aName
,
297 nsIAtom
* aPrefix
, const nsAString
& aValue
,
301 * Get the current value of the attribute. This returns a form that is
302 * suitable for passing back into SetAttr.
304 * @param aNameSpaceID the namespace of the attr
305 * @param aName the name of the attr
306 * @param aResult the value (may legitimately be the empty string) [OUT]
307 * @returns PR_TRUE if the attribute was set (even when set to empty string)
308 * PR_FALSE when not set.
310 virtual PRBool
GetAttr(PRInt32 aNameSpaceID
, nsIAtom
* aName
,
311 nsAString
& aResult
) const = 0;
314 * Determine if an attribute has been set (empty string or otherwise).
316 * @param aNameSpaceId the namespace id of the attribute
317 * @param aAttr the attribute name
318 * @return whether an attribute exists
320 virtual PRBool
HasAttr(PRInt32 aNameSpaceID
, nsIAtom
* aName
) const = 0;
323 * Test whether this content node's given attribute has the given value. If
324 * the attribute is not set at all, this will return false.
326 * @param aNameSpaceID The namespace ID of the attribute. Must not
327 * be kNameSpaceID_Unknown.
328 * @param aName The name atom of the attribute. Must not be null.
329 * @param aValue The value to compare to.
330 * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
332 virtual PRBool
AttrValueIs(PRInt32 aNameSpaceID
,
334 const nsAString
& aValue
,
335 nsCaseTreatment aCaseSensitive
) const
341 * Test whether this content node's given attribute has the given value. If
342 * the attribute is not set at all, this will return false.
344 * @param aNameSpaceID The namespace ID of the attribute. Must not
345 * be kNameSpaceID_Unknown.
346 * @param aName The name atom of the attribute. Must not be null.
347 * @param aValue The value to compare to. Must not be null.
348 * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
350 virtual PRBool
AttrValueIs(PRInt32 aNameSpaceID
,
353 nsCaseTreatment aCaseSensitive
) const
360 ATTR_VALUE_NO_MATCH
= -2
363 * Check whether this content node's given attribute has one of a given
364 * list of values. If there is a match, we return the index in the list
365 * of the first matching value. If there was no attribute at all, then
366 * we return ATTR_MISSING. If there was an attribute but it didn't
367 * match, we return ATTR_VALUE_NO_MATCH. A non-negative result always
370 * @param aNameSpaceID The namespace ID of the attribute. Must not
371 * be kNameSpaceID_Unknown.
372 * @param aName The name atom of the attribute. Must not be null.
373 * @param aValues a NULL-terminated array of pointers to atom values to test
375 * @param aCaseSensitive Whether to do a case-sensitive compare on the values.
376 * @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
377 * indicating the first value of aValues that matched
379 typedef nsIAtom
* const* const AttrValuesArray
;
380 virtual PRInt32
FindAttrValueIn(PRInt32 aNameSpaceID
,
382 AttrValuesArray
* aValues
,
383 nsCaseTreatment aCaseSensitive
) const
389 * Remove an attribute so that it is no longer explicitly specified.
391 * @param aNameSpaceID the namespace id of the attribute
392 * @param aAttr the name of the attribute to unset
393 * @param aNotify specifies whether or not the document should be
394 * notified of the attribute change
396 virtual nsresult
UnsetAttr(PRInt32 aNameSpaceID
, nsIAtom
* aAttr
,
401 * Get the namespace / name / prefix of a given attribute.
403 * @param aIndex the index of the attribute name
404 * @returns The name at the given index, or null if the index is
406 * @note The document returned by NodeInfo()->GetDocument() (if one is
407 * present) is *not* neccesarily the owner document of the element.
408 * @note The pointer returned by this function is only valid until the
409 * next call of either GetAttrNameAt or SetAttr on the element.
411 virtual const nsAttrName
* GetAttrNameAt(PRUint32 aIndex
) const = 0;
414 * Get the number of all specified attributes.
416 * @return the number of attributes
418 virtual PRUint32
GetAttrCount() const = 0;
421 * Get direct access (but read only) to the text in the text content.
422 * NOTE: For elements this is *not* the concatenation of all text children,
425 virtual const nsTextFragment
*GetText() = 0;
428 * Get the length of the text content.
429 * NOTE: This should not be called on elements.
431 virtual PRUint32
TextLength() = 0;
434 * Set the text to the given value. If aNotify is PR_TRUE then
435 * the document is notified of the content change.
436 * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
438 virtual nsresult
SetText(const PRUnichar
* aBuffer
, PRUint32 aLength
,
442 * Append the given value to the current text. If aNotify is PR_TRUE then
443 * the document is notified of the content change.
444 * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
446 virtual nsresult
AppendText(const PRUnichar
* aBuffer
, PRUint32 aLength
,
450 * Set the text to the given value. If aNotify is PR_TRUE then
451 * the document is notified of the content change.
452 * NOTE: For elements this always asserts and returns NS_ERROR_FAILURE
454 nsresult
SetText(const nsAString
& aStr
, PRBool aNotify
)
456 return SetText(aStr
.BeginReading(), aStr
.Length(), aNotify
);
460 * Query method to see if the frame is nothing but whitespace
461 * NOTE: Always returns PR_FALSE for elements
463 virtual PRBool
TextIsOnlyWhitespace() = 0;
466 * Append the text content to aResult.
467 * NOTE: This asserts and returns for elements
469 virtual void AppendTextTo(nsAString
& aResult
) = 0;
472 * Set the focus on this content. This is generally something for the event
473 * state manager to do, not ordinary people. Ordinary people should do
474 * something like nsGenericHTMLElement::SetElementFocus(). This method is
475 * the end result, the point where the content finds out it has been focused.
477 * All content elements are potentially focusable.
479 * @param aPresContext the pres context
480 * @see nsGenericHTMLElement::SetElementFocus()
482 virtual void SetFocus(nsPresContext
* aPresContext
)
487 * Remove the focus on this content. This is generally something for the
488 * event state manager to do, not ordinary people. Ordinary people should do
489 * something like nsGenericHTMLElement::SetElementFocus(). This method is
490 * the end result, the point where the content finds out it has been focused.
492 * All content elements are potentially focusable.
494 * @param aPresContext the pres context
495 * @see nsGenericHTMLElement::SetElementFocus()
497 virtual void RemoveFocus(nsPresContext
* aPresContext
)
502 * Check if this content is focusable and in the current tab order.
503 * Note: most callers should use nsIFrame::IsFocusable() instead as it
504 * checks visibility and other layout factors as well.
505 * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable.
506 * For example, only the selected radio button in a group is in the
507 * tab order, unless the radio group has no selection in which case
508 * all of the visible, non-disabled radio buttons in the group are
509 * in the tab order. On the other hand, all of the visible, non-disabled
510 * radio buttons are always focusable via clicking or script.
511 * Also, depending on either the accessibility.tabfocus pref or
512 * a system setting (nowadays: Full keyboard access, mac only)
513 * some widgets may be focusable but removed from the tab order.
514 * @param [inout, optional] aTabIndex the computed tab index
515 * In: default tabindex for element (-1 nonfocusable, == 0 focusable)
516 * Out: computed tabindex
517 * @param [optional] aTabIndex the computed tab index
518 * < 0 if not tabbable
519 * == 0 if in normal tab order
520 * > 0 can be tabbed to in the order specified by this value
521 * @return whether the content is focusable via mouse, kbd or script.
523 virtual PRBool
IsFocusable(PRInt32
*aTabIndex
= nsnull
)
526 *aTabIndex
= -1; // Default, not tabbable
531 * The method focuses (or activates) element that accesskey is bound to. It is
532 * called when accesskey is activated.
534 * @param aKeyCausesActivation - if true then element should be activated
535 * @param aIsTrustedEvent - if true then event that is cause of accesskey
536 * execution is trusted.
538 virtual void PerformAccesskey(PRBool aKeyCausesActivation
,
539 PRBool aIsTrustedEvent
)
544 * Get desired IME state for the content.
546 * @return The desired IME status for the content.
547 * This is a combination of IME_STATUS_* flags,
548 * controlling what happens to IME when the content takes focus.
549 * If this is IME_STATUS_NONE, IME remains in its current state.
550 * IME_STATUS_ENABLE and IME_STATUS_DISABLE must not be set
551 * together; likewise IME_STATUS_OPEN and IME_STATUS_CLOSE must
552 * not be set together.
553 * If you return IME_STATUS_DISABLE, you should not set the
554 * OPEN or CLOSE flag; that way, when IME is next enabled,
555 * the previous OPEN/CLOSE state will be restored (unless the newly
556 * focused content specifies the OPEN/CLOSE state by setting the OPEN
557 * or CLOSE flag with the ENABLE flag).
558 * IME_STATUS_PASSWORD should be returned only from password editor,
559 * this value has a special meaning. It is used as alternative of
560 * IME_STATUS_DISABLED.
563 IME_STATUS_NONE
= 0x0000,
564 IME_STATUS_ENABLE
= 0x0001,
565 IME_STATUS_DISABLE
= 0x0002,
566 IME_STATUS_PASSWORD
= 0x0004,
567 IME_STATUS_OPEN
= 0x0008,
568 IME_STATUS_CLOSE
= 0x0010
571 IME_STATUS_MASK_ENABLED
= IME_STATUS_ENABLE
| IME_STATUS_DISABLE
|
573 IME_STATUS_MASK_OPENED
= IME_STATUS_OPEN
| IME_STATUS_CLOSE
575 virtual PRUint32
GetDesiredIMEState()
577 if (!IsEditableInternal())
578 return IME_STATUS_DISABLE
;
579 nsIContent
*editableAncestor
= nsnull
;
580 for (nsIContent
* parent
= GetParent();
581 parent
&& parent
->HasFlag(NODE_IS_EDITABLE
);
582 parent
= parent
->GetParent())
583 editableAncestor
= parent
;
584 // This is in another editable content, use the result of it.
585 if (editableAncestor
)
586 return editableAncestor
->GetDesiredIMEState();
587 return IME_STATUS_ENABLE
;
591 * Gets content node with the binding (or native code, possibly on the
592 * frame) responsible for our construction (and existence). Used by
593 * anonymous content (both XBL-generated and native-anonymous).
595 * null for all explicit content (i.e., content reachable from the top
596 * of its GetParent() chain via child lists).
598 * @return the binding parent
600 virtual nsIContent
*GetBindingParent() const = 0;
603 * Get the base URI for any relative URIs within this piece of
604 * content. Generally, this is the document's base URI, but certain
605 * content carries a local base for backward compatibility, and XML
606 * supports setting a per-node base URI.
608 * @return the base URI
610 virtual already_AddRefed
<nsIURI
> GetBaseURI() const = 0;
613 * API to check if this is a link that's traversed in response to user input
614 * (e.g. a click event). Specializations for HTML/SVG/generic XML allow for
615 * different types of link in different types of content.
617 * @param aURI Required out param. If this content is a link, a new nsIURI
618 * set to this link's URI will be passed out.
620 * @note The out param, aURI, is guaranteed to be set to a non-null pointer
621 * when the return value is PR_TRUE.
623 * XXXjwatt: IMO IsInteractiveLink would be a better name.
625 virtual PRBool
IsLink(nsIURI
** aURI
) const = 0;
628 * Give this element a chance to fire links that should be fired
629 * automatically when loaded. If the element was an autoloading link
630 * and it was successfully handled, we will throw special nsresult values.
632 * @param aShell the current doc shell (to possibly load the link on)
633 * @throws NS_OK if nothing happened
634 * @throws NS_XML_AUTOLINK_EMBED if the caller is loading the link embedded
635 * @throws NS_XML_AUTOLINK_NEW if the caller is loading the link in a new
637 * @throws NS_XML_AUTOLINK_REPLACE if it is loading a link that will replace
638 * the current window (and thus the caller must stop parsing)
639 * @throws NS_XML_AUTOLINK_UNDEFINED if it is loading in any other way--in
640 * which case, the caller should stop parsing as well.
642 virtual nsresult
MaybeTriggerAutoLink(nsIDocShell
*aShell
)
648 * This method is called when the parser finishes creating the element. This
649 * particularly means that it has done everything you would expect it to have
650 * done after it encounters the > at the end of the tag (for HTML or XML).
651 * This includes setting the attributes, setting the document / form, and
652 * placing the element into the tree at its proper place.
654 * For container elements, this is called *before* any of the children are
655 * created or added into the tree.
657 * NOTE: this is currently only called for input and button, in the HTML
658 * content sink. If you want to call it on your element, modify the content
659 * sink of your choice to do so. This is an efficiency measure.
661 * If you also need to determine whether the parser is the one creating your
662 * element (through createElement() or cloneNode() generally) then add a
663 * boolean aFromParser to the NS_NewXXX() constructor for your element and
664 * have the parser pass true. See nsHTMLInputElement.cpp and
665 * nsHTMLContentSink::MakeContentObject().
667 * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
668 * attributes dynamically. If you make attributes affect your element from
669 * this method, it will only happen on initialization and JavaScript will not
670 * be able to create elements (which requires them to first create the
671 * element and then call setAttribute() directly, at which point
672 * DoneCreatingElement() has already been called and is out of the picture).
674 virtual void DoneCreatingElement()
679 * Call to let the content node know that it may now have a frame.
680 * The content node may use this to determine what MayHaveFrame
683 virtual void SetMayHaveFrame(PRBool aMayHaveFrame
)
688 * @returns PR_TRUE if there is a chance that the content node has a
690 * @returns PR_FALSE otherwise.
692 virtual PRBool
MayHaveFrame() const
698 * This method is called when the parser begins creating the element's
699 * children, if any are present.
701 * This is only called for XTF elements currently.
703 virtual void BeginAddingChildren()
708 * This method is called when the parser finishes creating the element's children,
709 * if any are present.
711 * NOTE: this is currently only called for textarea, select, applet, and
712 * object elements in the HTML content sink. If you want
713 * to call it on your element, modify the content sink of your
714 * choice to do so. This is an efficiency measure.
716 * If you also need to determine whether the parser is the one creating your
717 * element (through createElement() or cloneNode() generally) then add a
718 * boolean aFromParser to the NS_NewXXX() constructor for your element and
719 * have the parser pass true. See nsHTMLInputElement.cpp and
720 * nsHTMLContentSink::MakeContentObject().
722 * It is ok to ignore an error returned from this function. However the
723 * following errors may be of interest to some callers:
725 * NS_ERROR_HTMLPARSER_BLOCK Returned by script elements to indicate
726 * that a script will be loaded asynchronously
728 * This means that implementations will have to deal with returned error
729 * codes being ignored.
731 * @param aHaveNotified Whether there has been a
732 * ContentInserted/ContentAppended notification for this content node
735 virtual nsresult
DoneAddingChildren(PRBool aHaveNotified
)
741 * For HTML textarea, select, applet, and object elements, returns
742 * PR_TRUE if all children have been added OR if the element was not
743 * created by the parser. Returns PR_TRUE for all other elements.
744 * @returns PR_FALSE if the element was created by the parser and
745 * it is an HTML textarea, select, applet, or object
746 * element and not all children have been added.
747 * @returns PR_TRUE otherwise.
749 virtual PRBool
IsDoneAddingChildren()
755 * Method to get the _intrinsic_ content state of this content node. This is
756 * the state that is independent of the node's presentation. To get the full
757 * content state, use nsIEventStateManager. Also see nsIEventStateManager
758 * for the possible bits that could be set here.
760 // XXXbz this is PRInt32 because all the ESM content state APIs use
761 // PRInt32. We should really use PRUint32 instead.
762 virtual PRInt32
IntrinsicState() const;
764 /* The default script type (language) ID for this content.
765 All content must support fetching the default script language.
767 virtual PRUint32
GetScriptTypeID() const
768 { return nsIProgrammingLanguage::JAVASCRIPT
; }
770 /* Not all content supports setting a new default language */
771 virtual nsresult
SetScriptTypeID(PRUint32 aLang
)
773 NS_NOTREACHED("SetScriptTypeID not implemented");
774 return NS_ERROR_NOT_IMPLEMENTED
;
778 * Get the ID of this content node (the atom corresponding to the
779 * value of the null-namespace attribute whose name is given by
780 * GetIDAttributeName(). This may be null if there is no ID.
782 virtual nsIAtom
* GetID() const = 0;
785 * Get the class list of this content node (this corresponds to the
786 * value of the null-namespace attribute whose name is given by
787 * GetClassAttributeName(). This may be null if there are no
788 * classes, but that's not guaranteed.
790 virtual const nsAttrValue
* GetClasses() const = 0;
793 * Walk aRuleWalker over the content style rules (presentational
794 * hint rules) for this content node.
796 NS_IMETHOD
WalkContentStyleRules(nsRuleWalker
* aRuleWalker
) = 0;
799 * Get the inline style rule, if any, for this content node
801 virtual nsICSSStyleRule
* GetInlineStyleRule() = 0;
804 * Set the inline style rule for this node. This will send an
805 * appropriate AttributeChanged notification if aNotify is true.
807 NS_IMETHOD
SetInlineStyleRule(nsICSSStyleRule
* aStyleRule
, PRBool aNotify
) = 0;
810 * Is the attribute named stored in the mapped attributes?
812 * // XXXbz we use this method in HasAttributeDependentStyle, so svg
813 * returns true here even though it stores nothing in the mapped
816 NS_IMETHOD_(PRBool
) IsAttributeMapped(const nsIAtom
* aAttribute
) const = 0;
819 * Get a hint that tells the style system what to do when
820 * an attribute on this node changes, if something needs to happen
821 * in response to the change *other* than the result of what is
822 * mapped into style data via any type of style rule.
824 virtual nsChangeHint
GetAttributeChangeHint(const nsIAtom
* aAttribute
,
825 PRInt32 aModType
) const = 0;
828 * Returns an atom holding the name of the "class" attribute on this
829 * content node (if applicable). Returns null if there is no
830 * "class" attribute for this type of content node.
832 virtual nsIAtom
*GetClassAttributeName() const = 0;
835 * Should be called when the node can become editable or when it can stop
836 * being editable (for example when its contentEditable attribute changes,
837 * when it is moved into an editable parent, ...).
839 virtual void UpdateEditableState();
842 * Destroy this node and its children. Ideally this shouldn't be needed
843 * but for now we need to do it to break cycles.
845 virtual void DestroyContent() = 0;
848 * Saves the form state of this node and its children.
850 virtual void SaveSubtreeState() = 0;
854 * List the content (and anything it contains) out to the given
855 * file stream. Use aIndent as the base indent during formatting.
857 virtual void List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const = 0;
860 * Dump the content (and anything it contains) out to the given
861 * file stream. Use aIndent as the base indent during formatting.
863 virtual void DumpContent(FILE* out
= stdout
, PRInt32 aIndent
= 0,
864 PRBool aDumpAll
= PR_TRUE
) const = 0;
868 //eTabFocus_textControlsMask = (1<<0), // unused - textboxes always tabbable
869 eTabFocus_formElementsMask
= (1<<1), // non-text form elements
870 eTabFocus_linksMask
= (1<<2), // links
871 eTabFocus_any
= 1 + (1<<1) + (1<<2) // everything that can be focused
874 // Tab focus model bit field:
875 static PRInt32 sTabFocusModel
;
877 // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
878 // the tabfocus bit field applies to xul elements.
879 static PRBool sTabFocusModelAppliesToXUL
;
883 NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent
, NS_ICONTENT_IID
)
885 // Some cycle-collecting helper macros for nsIContent subclasses
887 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER \
888 if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) { \
889 nsContentUtils::TraverseListenerManager(tmp, cb); \
892 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER \
894 nsISupports *preservedWrapper = nsnull; \
895 if (tmp->GetOwnerDoc()) \
896 preservedWrapper = tmp->GetOwnerDoc()->GetReference(tmp); \
897 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[preserved wrapper]");\
898 cb.NoteXPCOMChild(preservedWrapper); \
901 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA \
902 if (tmp->HasProperties()) { \
903 nsNodeUtils::TraverseUserData(tmp, cb); \
906 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER \
907 if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) { \
908 nsContentUtils::RemoveListenerManager(tmp); \
909 tmp->UnsetFlags(NODE_HAS_LISTENERMANAGER); \
912 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
913 if (tmp->GetOwnerDoc()) \
914 tmp->GetOwnerDoc()->RemoveReference(tmp);
916 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA \
917 if (tmp->HasProperties()) { \
918 nsNodeUtils::UnlinkUserData(tmp); \
922 #endif /* nsIContent_h___ */