Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsIContent_h___
6 #define nsIContent_h___
8 #include "mozilla/Attributes.h"
9 #include "nsCaseTreatment.h" // for enum, cannot be forward-declared
10 #include "nsINode.h"
12 // Forward declarations
13 class nsAString;
14 class nsIAtom;
15 class nsIURI;
16 class nsRuleWalker;
17 class nsAttrValue;
18 class nsAttrName;
19 class nsTextFragment;
20 class nsIFrame;
21 class nsXBLBinding;
23 namespace mozilla {
24 class EventChainPreVisitor;
25 namespace dom {
26 class ShadowRoot;
27 struct CustomElementData;
28 } // namespace dom
29 namespace widget {
30 struct IMEState;
31 } // namespace widget
32 } // namespace mozilla
34 enum nsLinkState {
35 eLinkState_Unvisited = 1,
36 eLinkState_Visited = 2,
37 eLinkState_NotLink = 3
38 };
40 // IID for the nsIContent interface
41 #define NS_ICONTENT_IID \
42 { 0x1329e5b7, 0x4bcd, 0x450c, \
43 { 0xa2, 0x3a, 0x98, 0xc5, 0x85, 0xcd, 0x73, 0xf9 } }
45 /**
46 * A node of content in a document's content model. This interface
47 * is supported by all content objects.
48 */
49 class nsIContent : public nsINode {
50 public:
51 typedef mozilla::widget::IMEState IMEState;
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 nsIContent(already_AddRefed<nsINodeInfo>& aNodeInfo)
58 : nsINode(aNodeInfo)
59 {
60 MOZ_ASSERT(mNodeInfo);
61 SetNodeIsContent();
62 }
63 #endif // MOZILLA_INTERNAL_API
65 NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
67 /**
68 * Bind this content node to a tree. If this method throws, the caller must
69 * call UnbindFromTree() on the node. In the typical case of a node being
70 * appended to a parent, this will be called after the node has been added to
71 * the parent's child list and before nsIDocumentObserver notifications for
72 * the addition are dispatched.
73 * @param aDocument The new document for the content node. Must match the
74 * current document of aParent, if aParent is not null.
75 * May not be null if aParent is null.
76 * @param aParent The new parent for the content node. May be null if the
77 * node is being bound as a direct child of the document.
78 * @param aBindingParent The new binding parent for the content node.
79 * This is must either be non-null if a particular
80 * binding parent is desired or match aParent's binding
81 * parent.
82 * @param aCompileEventHandlers whether to initialize the event handlers in
83 * the document (used by nsXULElement)
84 * @note either aDocument or aParent must be non-null. If both are null,
85 * this method _will_ crash.
86 * @note This method must not be called by consumers of nsIContent on a node
87 * that is already bound to a tree. Call UnbindFromTree first.
88 * @note This method will handle rebinding descendants appropriately (eg
89 * changing their binding parent as needed).
90 * @note This method does not add the content node to aParent's child list
91 * @throws NS_ERROR_OUT_OF_MEMORY if that happens
92 */
93 virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
94 nsIContent* aBindingParent,
95 bool aCompileEventHandlers) = 0;
97 /**
98 * Unbind this content node from a tree. This will set its current document
99 * and binding parent to null. In the typical case of a node being removed
100 * from a parent, this will be called after it has been removed from the
101 * parent's child list and after the nsIDocumentObserver notifications for
102 * the removal have been dispatched.
103 * @param aDeep Whether to recursively unbind the entire subtree rooted at
104 * this node. The only time false should be passed is when the
105 * parent node of the content is being destroyed.
106 * @param aNullParent Whether to null out the parent pointer as well. This
107 * is usually desirable. This argument should only be false while
108 * recursively calling UnbindFromTree when a subtree is detached.
109 * @note This method is safe to call on nodes that are not bound to a tree.
110 */
111 virtual void UnbindFromTree(bool aDeep = true,
112 bool aNullParent = true) = 0;
114 /**
115 * DEPRECATED - Use GetCurrentDoc or GetOwnerDoc.
116 * Get the document for this content.
117 * @return the document
118 */
119 nsIDocument *GetDocument() const
120 {
121 return GetCurrentDoc();
122 }
124 enum {
125 /**
126 * All XBL flattened tree children of the node, as well as :before and
127 * :after anonymous content and native anonymous children.
128 *
129 * @note the result children order is
130 * 1. :before generated node
131 * 2. XBL flattened tree children of this node
132 * 3. native anonymous nodes
133 * 4. :after generated node
134 */
135 eAllChildren = 0,
137 /**
138 * All XBL explicit children of the node (see
139 * http://www.w3.org/TR/xbl/#explicit3 ), as well as :before and :after
140 * anonymous content and native anonymous children.
141 *
142 * @note the result children order is
143 * 1. :before generated node
144 * 2. XBL explicit children of the node
145 * 3. native anonymous nodes
146 * 4. :after generated node
147 */
148 eAllButXBL = 1,
150 /**
151 * Skip native anonymous content created for placeholder of HTML input,
152 * used in conjunction with eAllChildren or eAllButXBL.
153 */
154 eSkipPlaceholderContent = 2
155 };
157 /**
158 * Return either the XBL explicit children of the node or the XBL flattened
159 * tree children of the node, depending on the filter, as well as
160 * native anonymous children.
161 *
162 * @note calling this method with eAllButXBL will return children that are
163 * also in the eAllButXBL and eAllChildren child lists of other descendants
164 * of this node in the tree, but those other nodes cannot be reached from the
165 * eAllButXBL child list.
166 */
167 virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) = 0;
169 /**
170 * Get whether this content is C++-generated anonymous content
171 * @see nsIAnonymousContentCreator
172 * @return whether this content is anonymous
173 */
174 bool IsRootOfNativeAnonymousSubtree() const
175 {
176 NS_ASSERTION(!HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT) ||
177 (HasFlag(NODE_IS_ANONYMOUS_ROOT) &&
178 HasFlag(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE)),
179 "Some flags seem to be missing!");
180 return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT);
181 }
183 bool IsRootOfChromeAccessOnlySubtree() const
184 {
185 return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT |
186 NODE_IS_ROOT_OF_CHROME_ONLY_ACCESS);
187 }
189 /**
190 * Makes this content anonymous
191 * @see nsIAnonymousContentCreator
192 */
193 void SetIsNativeAnonymousRoot()
194 {
195 SetFlags(NODE_IS_ANONYMOUS_ROOT | NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE |
196 NODE_IS_NATIVE_ANONYMOUS_ROOT);
197 }
199 /**
200 * Returns |this| if it is not chrome-only/native anonymous, otherwise
201 * first non chrome-only/native anonymous ancestor.
202 */
203 virtual nsIContent* FindFirstNonChromeOnlyAccessContent() const;
205 /**
206 * Returns true if and only if this node has a parent, but is not in
207 * its parent's child list.
208 */
209 bool IsRootOfAnonymousSubtree() const
210 {
211 NS_ASSERTION(!IsRootOfNativeAnonymousSubtree() ||
212 (GetParent() && GetBindingParent() == GetParent()),
213 "root of native anonymous subtree must have parent equal "
214 "to binding parent");
215 NS_ASSERTION(!GetParent() ||
216 ((GetBindingParent() == GetParent()) ==
217 HasFlag(NODE_IS_ANONYMOUS_ROOT)) ||
218 // Unfortunately default content for XBL insertion points is
219 // anonymous content that is bound with the parent of the
220 // insertion point as the parent but the bound element for the
221 // binding as the binding parent. So we have to complicate
222 // the assert a bit here.
223 (GetBindingParent() &&
224 (GetBindingParent() == GetParent()->GetBindingParent()) ==
225 HasFlag(NODE_IS_ANONYMOUS_ROOT)),
226 "For nodes with parent, flag and GetBindingParent() check "
227 "should match");
228 return HasFlag(NODE_IS_ANONYMOUS_ROOT);
229 }
231 /**
232 * Returns true if there is NOT a path through child lists
233 * from the top of this node's parent chain back to this node or
234 * if the node is in native anonymous subtree without a parent.
235 */
236 bool IsInAnonymousSubtree() const
237 {
238 NS_ASSERTION(!IsInNativeAnonymousSubtree() || GetBindingParent() ||
239 (!IsInDoc() &&
240 static_cast<nsIContent*>(SubtreeRoot())->IsInNativeAnonymousSubtree()),
241 "Must have binding parent when in native anonymous subtree which is in document.\n"
242 "Native anonymous subtree which is not in document must have native anonymous root.");
243 return IsInNativeAnonymousSubtree() || (!HasFlag(NODE_IS_IN_SHADOW_TREE) && GetBindingParent() != nullptr);
244 }
246 /**
247 * Return true iff this node is in an HTML document (in the HTML5 sense of
248 * the term, i.e. not in an XHTML/XML document).
249 */
250 inline bool IsInHTMLDocument() const;
252 /**
253 * Get the namespace that this element's tag is defined in
254 * @return the namespace
255 */
256 inline int32_t GetNameSpaceID() const
257 {
258 return mNodeInfo->NamespaceID();
259 }
261 /**
262 * Get the NodeInfo for this element
263 * @return the nodes node info
264 */
265 inline nsINodeInfo* NodeInfo() const
266 {
267 return mNodeInfo;
268 }
270 inline bool IsInNamespace(int32_t aNamespace) const
271 {
272 return mNodeInfo->NamespaceID() == aNamespace;
273 }
275 inline bool IsHTML() const
276 {
277 return IsInNamespace(kNameSpaceID_XHTML);
278 }
280 inline bool IsHTML(nsIAtom* aTag) const
281 {
282 return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
283 }
285 inline bool IsSVG() const
286 {
287 return IsInNamespace(kNameSpaceID_SVG);
288 }
290 inline bool IsSVG(nsIAtom* aTag) const
291 {
292 return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
293 }
295 inline bool IsXUL() const
296 {
297 return IsInNamespace(kNameSpaceID_XUL);
298 }
300 inline bool IsXUL(nsIAtom* aTag) const
301 {
302 return mNodeInfo->Equals(aTag, kNameSpaceID_XUL);
303 }
305 inline bool IsMathML() const
306 {
307 return IsInNamespace(kNameSpaceID_MathML);
308 }
310 inline bool IsMathML(nsIAtom* aTag) const
311 {
312 return mNodeInfo->Equals(aTag, kNameSpaceID_MathML);
313 }
315 inline bool IsActiveChildrenElement() const
316 {
317 return mNodeInfo->Equals(nsGkAtoms::children, kNameSpaceID_XBL) &&
318 GetBindingParent();
319 }
321 /**
322 * Returns an atom holding the name of the attribute of type ID on
323 * this content node (if applicable). Returns null for non-element
324 * content nodes.
325 */
326 virtual nsIAtom *GetIDAttributeName() const = 0;
328 /**
329 * Set attribute values. All attribute values are assumed to have a
330 * canonical string representation that can be used for these
331 * methods. The SetAttr method is assumed to perform a translation
332 * of the canonical form into the underlying content specific
333 * form.
334 *
335 * @param aNameSpaceID the namespace of the attribute
336 * @param aName the name of the attribute
337 * @param aValue the value to set
338 * @param aNotify specifies how whether or not the document should be
339 * notified of the attribute change.
340 */
341 nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
342 const nsAString& aValue, bool aNotify)
343 {
344 return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
345 }
347 /**
348 * Set attribute values. All attribute values are assumed to have a
349 * canonical String representation that can be used for these
350 * methods. The SetAttr method is assumed to perform a translation
351 * of the canonical form into the underlying content specific
352 * form.
353 *
354 * @param aNameSpaceID the namespace of the attribute
355 * @param aName the name of the attribute
356 * @param aPrefix the prefix of the attribute
357 * @param aValue the value to set
358 * @param aNotify specifies how whether or not the document should be
359 * notified of the attribute change.
360 */
361 virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
362 nsIAtom* aPrefix, const nsAString& aValue,
363 bool aNotify) = 0;
365 /**
366 * Get the current value of the attribute. This returns a form that is
367 * suitable for passing back into SetAttr.
368 *
369 * @param aNameSpaceID the namespace of the attr
370 * @param aName the name of the attr
371 * @param aResult the value (may legitimately be the empty string) [OUT]
372 * @returns true if the attribute was set (even when set to empty string)
373 * false when not set.
374 */
375 bool GetAttr(int32_t aNameSpaceID, nsIAtom* aName,
376 nsAString& aResult) const;
378 /**
379 * Determine if an attribute has been set (empty string or otherwise).
380 *
381 * @param aNameSpaceId the namespace id of the attribute
382 * @param aAttr the attribute name
383 * @return whether an attribute exists
384 */
385 bool HasAttr(int32_t aNameSpaceID, nsIAtom* aName) const;
387 /**
388 * Test whether this content node's given attribute has the given value. If
389 * the attribute is not set at all, this will return false.
390 *
391 * @param aNameSpaceID The namespace ID of the attribute. Must not
392 * be kNameSpaceID_Unknown.
393 * @param aName The name atom of the attribute. Must not be null.
394 * @param aValue The value to compare to.
395 * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
396 */
397 bool AttrValueIs(int32_t aNameSpaceID,
398 nsIAtom* aName,
399 const nsAString& aValue,
400 nsCaseTreatment aCaseSensitive) const;
402 /**
403 * Test whether this content node's given attribute has the given value. If
404 * the attribute is not set at all, this will return false.
405 *
406 * @param aNameSpaceID The namespace ID of the attribute. Must not
407 * be kNameSpaceID_Unknown.
408 * @param aName The name atom of the attribute. Must not be null.
409 * @param aValue The value to compare to. Must not be null.
410 * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
411 */
412 bool AttrValueIs(int32_t aNameSpaceID,
413 nsIAtom* aName,
414 nsIAtom* aValue,
415 nsCaseTreatment aCaseSensitive) const;
417 enum {
418 ATTR_MISSING = -1,
419 ATTR_VALUE_NO_MATCH = -2
420 };
421 /**
422 * Check whether this content node's given attribute has one of a given
423 * list of values. If there is a match, we return the index in the list
424 * of the first matching value. If there was no attribute at all, then
425 * we return ATTR_MISSING. If there was an attribute but it didn't
426 * match, we return ATTR_VALUE_NO_MATCH. A non-negative result always
427 * indicates a match.
428 *
429 * @param aNameSpaceID The namespace ID of the attribute. Must not
430 * be kNameSpaceID_Unknown.
431 * @param aName The name atom of the attribute. Must not be null.
432 * @param aValues a nullptr-terminated array of pointers to atom values to test
433 * against.
434 * @param aCaseSensitive Whether to do a case-sensitive compare on the values.
435 * @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
436 * indicating the first value of aValues that matched
437 */
438 typedef nsIAtom* const* const AttrValuesArray;
439 virtual int32_t FindAttrValueIn(int32_t aNameSpaceID,
440 nsIAtom* aName,
441 AttrValuesArray* aValues,
442 nsCaseTreatment aCaseSensitive) const
443 {
444 return ATTR_MISSING;
445 }
447 /**
448 * Remove an attribute so that it is no longer explicitly specified.
449 *
450 * @param aNameSpaceID the namespace id of the attribute
451 * @param aAttr the name of the attribute to unset
452 * @param aNotify specifies whether or not the document should be
453 * notified of the attribute change
454 */
455 virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
456 bool aNotify) = 0;
459 /**
460 * Get the namespace / name / prefix of a given attribute.
461 *
462 * @param aIndex the index of the attribute name
463 * @returns The name at the given index, or null if the index is
464 * out-of-bounds.
465 * @note The document returned by NodeInfo()->GetDocument() (if one is
466 * present) is *not* necessarily the owner document of the element.
467 * @note The pointer returned by this function is only valid until the
468 * next call of either GetAttrNameAt or SetAttr on the element.
469 */
470 virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const = 0;
472 /**
473 * Get the number of all specified attributes.
474 *
475 * @return the number of attributes
476 */
477 virtual uint32_t GetAttrCount() const = 0;
479 /**
480 * Get direct access (but read only) to the text in the text content.
481 * NOTE: For elements this is *not* the concatenation of all text children,
482 * it is simply null;
483 */
484 virtual const nsTextFragment *GetText() = 0;
486 /**
487 * Get the length of the text content.
488 * NOTE: This should not be called on elements.
489 */
490 virtual uint32_t TextLength() const = 0;
492 /**
493 * Determines if an event attribute name (such as onclick) is valid for
494 * a given element type.
495 * @note calls nsContentUtils::IsEventAttributeName with right flag
496 * @note overridden by subclasses as needed
497 * @param aName the event name to look up
498 */
499 virtual bool IsEventAttributeName(nsIAtom* aName)
500 {
501 return false;
502 }
504 /**
505 * Set the text to the given value. If aNotify is true then
506 * the document is notified of the content change.
507 * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
508 */
509 virtual nsresult SetText(const char16_t* aBuffer, uint32_t aLength,
510 bool aNotify) = 0;
512 /**
513 * Append the given value to the current text. If aNotify is true then
514 * the document is notified of the content change.
515 * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
516 */
517 virtual nsresult AppendText(const char16_t* aBuffer, uint32_t aLength,
518 bool aNotify) = 0;
520 /**
521 * Set the text to the given value. If aNotify is true then
522 * the document is notified of the content change.
523 * NOTE: For elements this always asserts and returns NS_ERROR_FAILURE
524 */
525 nsresult SetText(const nsAString& aStr, bool aNotify)
526 {
527 return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
528 }
530 /**
531 * Query method to see if the frame is nothing but whitespace
532 * NOTE: Always returns false for elements
533 */
534 virtual bool TextIsOnlyWhitespace() = 0;
536 /**
537 * Method to see if the text node contains data that is useful
538 * for a translation: i.e., it consists of more than just whitespace,
539 * digits and punctuation.
540 * NOTE: Always returns false for elements.
541 */
542 virtual bool HasTextForTranslation() = 0;
544 /**
545 * Append the text content to aResult.
546 * NOTE: This asserts and returns for elements
547 */
548 virtual void AppendTextTo(nsAString& aResult) = 0;
550 /**
551 * Append the text content to aResult.
552 * NOTE: This asserts and returns for elements
553 */
554 virtual bool AppendTextTo(nsAString& aResult,
555 const mozilla::fallible_t&) NS_WARN_UNUSED_RESULT = 0;
557 /**
558 * Check if this content is focusable and in the current tab order.
559 * Note: most callers should use nsIFrame::IsFocusable() instead as it
560 * checks visibility and other layout factors as well.
561 * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable.
562 * For example, only the selected radio button in a group is in the
563 * tab order, unless the radio group has no selection in which case
564 * all of the visible, non-disabled radio buttons in the group are
565 * in the tab order. On the other hand, all of the visible, non-disabled
566 * radio buttons are always focusable via clicking or script.
567 * Also, depending on either the accessibility.tabfocus pref or
568 * a system setting (nowadays: Full keyboard access, mac only)
569 * some widgets may be focusable but removed from the tab order.
570 * @param [inout, optional] aTabIndex the computed tab index
571 * In: default tabindex for element (-1 nonfocusable, == 0 focusable)
572 * Out: computed tabindex
573 * @param [optional] aTabIndex the computed tab index
574 * < 0 if not tabbable
575 * == 0 if in normal tab order
576 * > 0 can be tabbed to in the order specified by this value
577 * @return whether the content is focusable via mouse, kbd or script.
578 */
579 bool IsFocusable(int32_t* aTabIndex = nullptr, bool aWithMouse = false);
580 virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse);
582 /**
583 * The method focuses (or activates) element that accesskey is bound to. It is
584 * called when accesskey is activated.
585 *
586 * @param aKeyCausesActivation - if true then element should be activated
587 * @param aIsTrustedEvent - if true then event that is cause of accesskey
588 * execution is trusted.
589 */
590 virtual void PerformAccesskey(bool aKeyCausesActivation,
591 bool aIsTrustedEvent)
592 {
593 }
595 /*
596 * Get desired IME state for the content.
597 *
598 * @return The desired IME status for the content.
599 * This is a combination of an IME enabled value and
600 * an IME open value of widget::IMEState.
601 * If you return DISABLED, you should not set the OPEN and CLOSE
602 * value.
603 * PASSWORD should be returned only from password editor, this value
604 * has a special meaning. It is used as alternative of DISABLED.
605 * PLUGIN should be returned only when plug-in has focus. When a
606 * plug-in is focused content, we should send native events directly.
607 * Because we don't process some native events, but they may be needed
608 * by the plug-in.
609 */
610 virtual IMEState GetDesiredIMEState();
612 /**
613 * Gets content node with the binding (or native code, possibly on the
614 * frame) responsible for our construction (and existence). Used by
615 * anonymous content (both XBL-generated and native-anonymous).
616 *
617 * null for all explicit content (i.e., content reachable from the top
618 * of its GetParent() chain via child lists).
619 *
620 * @return the binding parent
621 */
622 virtual nsIContent *GetBindingParent() const = 0;
624 /**
625 * Gets the current XBL binding that is bound to this element.
626 *
627 * @return the current binding.
628 */
629 virtual nsXBLBinding *GetXBLBinding() const = 0;
631 /**
632 * Sets or unsets an XBL binding for this element. Setting a
633 * binding on an element that already has a binding will remove the
634 * old binding.
635 *
636 * @param aBinding The binding to bind to this content. If nullptr is
637 * provided as the argument, then existing binding will be
638 * removed.
639 *
640 * @param aOldBindingManager The old binding manager that contains
641 * this content if this content was adopted
642 * to another document.
643 */
644 virtual void SetXBLBinding(nsXBLBinding* aBinding,
645 nsBindingManager* aOldBindingManager = nullptr) = 0;
647 /**
648 * Sets the ShadowRoot binding for this element. The contents of the
649 * binding is rendered in place of this node's children.
650 *
651 * @param aShadowRoot The ShadowRoot to be bound to this element.
652 */
653 virtual void SetShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot) = 0;
655 /**
656 * Gets the ShadowRoot binding for this element.
657 *
658 * @return The ShadowRoot currently bound to this element.
659 */
660 virtual mozilla::dom::ShadowRoot *GetShadowRoot() const = 0;
662 /**
663 * Gets the root of the node tree for this content if it is in a shadow tree.
664 * This method is called |GetContainingShadow| instead of |GetRootShadowRoot|
665 * to avoid confusion with |GetShadowRoot|.
666 *
667 * @return The ShadowRoot that is the root of the node tree.
668 */
669 virtual mozilla::dom::ShadowRoot *GetContainingShadow() const = 0;
671 /**
672 * Gets the insertion parent element of the XBL binding.
673 * The insertion parent is our one true parent in the transformed DOM.
674 *
675 * @return the insertion parent element.
676 */
677 virtual nsIContent *GetXBLInsertionParent() const = 0;
679 /**
680 * Sets the insertion parent element of the XBL binding.
681 *
682 * @param aContent The insertion parent element.
683 */
684 virtual void SetXBLInsertionParent(nsIContent* aContent) = 0;
686 /**
687 * Returns the content node that is the parent of this node in the flattened
688 * tree. For nodes that are not filtered into an insertion point, this
689 * simply returns their DOM parent in the original DOM tree.
690 *
691 * @return the flattened tree parent
692 */
693 nsIContent *GetFlattenedTreeParent() const;
695 /**
696 * Gets the custom element data used by web components custom element.
697 * Custom element data is created at the first attempt to enqueue a callback.
698 *
699 * @return The custom element data or null if none.
700 */
701 virtual mozilla::dom::CustomElementData *GetCustomElementData() const = 0;
703 /**
704 * Sets the custom element data, ownership of the
705 * callback data is taken by this content.
706 *
707 * @param aCallbackData The custom element data.
708 */
709 virtual void SetCustomElementData(mozilla::dom::CustomElementData* aData) = 0;
711 /**
712 * API to check if this is a link that's traversed in response to user input
713 * (e.g. a click event). Specializations for HTML/SVG/generic XML allow for
714 * different types of link in different types of content.
715 *
716 * @param aURI Required out param. If this content is a link, a new nsIURI
717 * set to this link's URI will be passed out.
718 *
719 * @note The out param, aURI, is guaranteed to be set to a non-null pointer
720 * when the return value is true.
721 *
722 * XXXjwatt: IMO IsInteractiveLink would be a better name.
723 */
724 virtual bool IsLink(nsIURI** aURI) const = 0;
726 /**
727 * Get a pointer to the full href URI (fully resolved and canonicalized,
728 * since it's an nsIURI object) for link elements.
729 *
730 * @return A pointer to the URI or null if the element is not a link or it
731 * has no HREF attribute.
732 */
733 virtual already_AddRefed<nsIURI> GetHrefURI() const
734 {
735 return nullptr;
736 }
738 /**
739 * This method is called when the parser finishes creating the element. This
740 * particularly means that it has done everything you would expect it to have
741 * done after it encounters the > at the end of the tag (for HTML or XML).
742 * This includes setting the attributes, setting the document / form, and
743 * placing the element into the tree at its proper place.
744 *
745 * For container elements, this is called *before* any of the children are
746 * created or added into the tree.
747 *
748 * NOTE: this is currently only called for input and button, in the HTML
749 * content sink. If you want to call it on your element, modify the content
750 * sink of your choice to do so. This is an efficiency measure.
751 *
752 * If you also need to determine whether the parser is the one creating your
753 * element (through createElement() or cloneNode() generally) then add a
754 * uint32_t aFromParser to the NS_NewXXX() constructor for your element and
755 * have the parser pass the appropriate flags. See HTMLInputElement.cpp and
756 * nsHTMLContentSink::MakeContentObject().
757 *
758 * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
759 * attributes dynamically. If you make attributes affect your element from
760 * this method, it will only happen on initialization and JavaScript will not
761 * be able to create elements (which requires them to first create the
762 * element and then call setAttribute() directly, at which point
763 * DoneCreatingElement() has already been called and is out of the picture).
764 */
765 virtual void DoneCreatingElement()
766 {
767 }
769 /**
770 * This method is called when the parser begins creating the element's
771 * children, if any are present.
772 *
773 * This is only called for XTF elements currently.
774 */
775 virtual void BeginAddingChildren()
776 {
777 }
779 /**
780 * This method is called when the parser finishes creating the element's children,
781 * if any are present.
782 *
783 * NOTE: this is currently only called for textarea, select, applet, and
784 * object elements in the HTML content sink. If you want
785 * to call it on your element, modify the content sink of your
786 * choice to do so. This is an efficiency measure.
787 *
788 * If you also need to determine whether the parser is the one creating your
789 * element (through createElement() or cloneNode() generally) then add a
790 * boolean aFromParser to the NS_NewXXX() constructor for your element and
791 * have the parser pass true. See HTMLInputElement.cpp and
792 * nsHTMLContentSink::MakeContentObject().
793 *
794 * @param aHaveNotified Whether there has been a
795 * ContentInserted/ContentAppended notification for this content node
796 * yet.
797 */
798 virtual void DoneAddingChildren(bool aHaveNotified)
799 {
800 }
802 /**
803 * For HTML textarea, select, applet, and object elements, returns
804 * true if all children have been added OR if the element was not
805 * created by the parser. Returns true for all other elements.
806 * @returns false if the element was created by the parser and
807 * it is an HTML textarea, select, applet, or object
808 * element and not all children have been added.
809 * @returns true otherwise.
810 */
811 virtual bool IsDoneAddingChildren()
812 {
813 return true;
814 }
816 /**
817 * Get the ID of this content node (the atom corresponding to the
818 * value of the null-namespace attribute whose name is given by
819 * GetIDAttributeName(). This may be null if there is no ID.
820 */
821 nsIAtom* GetID() const {
822 if (HasID()) {
823 return DoGetID();
824 }
825 return nullptr;
826 }
828 /**
829 * Get the class list of this content node (this corresponds to the
830 * value of the null-namespace attribute whose name is given by
831 * GetClassAttributeName()). This may be null if there are no
832 * classes, but that's not guaranteed.
833 */
834 const nsAttrValue* GetClasses() const {
835 if (HasFlag(NODE_MAY_HAVE_CLASS)) {
836 return DoGetClasses();
837 }
838 return nullptr;
839 }
841 /**
842 * Walk aRuleWalker over the content style rules (presentational
843 * hint rules) for this content node.
844 */
845 NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) = 0;
847 /**
848 * Should be called when the node can become editable or when it can stop
849 * being editable (for example when its contentEditable attribute changes,
850 * when it is moved into an editable parent, ...). If aNotify is true and
851 * the node is an element, this will notify the state change.
852 */
853 virtual void UpdateEditableState(bool aNotify);
855 /**
856 * Destroy this node and its children. Ideally this shouldn't be needed
857 * but for now we need to do it to break cycles.
858 */
859 virtual void DestroyContent() = 0;
861 /**
862 * Saves the form state of this node and its children.
863 */
864 virtual void SaveSubtreeState() = 0;
866 /**
867 * Getter and setter for our primary frame pointer. This is the frame that
868 * is most closely associated with the content. A frame is more closely
869 * associated with the content than another frame if the one frame contains
870 * directly or indirectly the other frame (e.g., when a frame is scrolled
871 * there is a scroll frame that contains the frame being scrolled). This
872 * frame is always the first continuation.
873 *
874 * In the case of absolutely positioned elements and floated elements, this
875 * frame is the out of flow frame, not the placeholder.
876 */
877 nsIFrame* GetPrimaryFrame() const
878 {
879 return IsInDoc() ? mPrimaryFrame : nullptr;
880 }
881 void SetPrimaryFrame(nsIFrame* aFrame) {
882 NS_ASSERTION(IsInDoc(), "This will end badly!");
883 NS_PRECONDITION(!aFrame || !mPrimaryFrame || aFrame == mPrimaryFrame,
884 "Losing track of existing primary frame");
885 mPrimaryFrame = aFrame;
886 }
888 nsresult LookupNamespaceURIInternal(const nsAString& aNamespacePrefix,
889 nsAString& aNamespaceURI) const;
891 /**
892 * If this content has independent selection, e.g., if this is input field
893 * or textarea, this return TRUE. Otherwise, false.
894 */
895 bool HasIndependentSelection();
897 /**
898 * If the content is a part of HTML editor, this returns editing
899 * host content. When the content is in designMode, this returns its body
900 * element. Also, when the content isn't editable, this returns null.
901 */
902 mozilla::dom::Element* GetEditingHost();
904 /**
905 * Determing language. Look at the nearest ancestor element that has a lang
906 * attribute in the XML namespace or is an HTML/SVG element and has a lang in
907 * no namespace attribute.
908 */
909 void GetLang(nsAString& aResult) const {
910 for (const nsIContent* content = this; content; content = content->GetParent()) {
911 if (content->GetAttrCount() > 0) {
912 // xml:lang has precedence over lang on HTML elements (see
913 // XHTML1 section C.7).
914 bool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang,
915 aResult);
916 if (!hasAttr && (content->IsHTML() || content->IsSVG())) {
917 hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
918 aResult);
919 }
920 NS_ASSERTION(hasAttr || aResult.IsEmpty(),
921 "GetAttr that returns false should not make string non-empty");
922 if (hasAttr) {
923 return;
924 }
925 }
926 }
927 }
929 // Overloaded from nsINode
930 virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const MOZ_OVERRIDE;
932 virtual nsresult PreHandleEvent(
933 mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
935 virtual bool IsPurple() = 0;
936 virtual void RemovePurple() = 0;
938 virtual bool OwnedOnlyByTheDOMTree() { return false; }
939 protected:
940 /**
941 * Hook for implementing GetID. This is guaranteed to only be
942 * called if HasID() is true.
943 */
944 virtual nsIAtom* DoGetID() const = 0;
946 private:
947 /**
948 * Hook for implementing GetClasses. This is guaranteed to only be
949 * called if the NODE_MAY_HAVE_CLASS flag is set.
950 */
951 virtual const nsAttrValue* DoGetClasses() const = 0;
953 public:
954 #ifdef DEBUG
955 /**
956 * List the content (and anything it contains) out to the given
957 * file stream. Use aIndent as the base indent during formatting.
958 */
959 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
961 /**
962 * Dump the content (and anything it contains) out to the given
963 * file stream. Use aIndent as the base indent during formatting.
964 */
965 virtual void DumpContent(FILE* out = stdout, int32_t aIndent = 0,
966 bool aDumpAll = true) const = 0;
967 #endif
969 /**
970 * Append to aOutDescription a short (preferably one line) string
971 * describing the content.
972 * Currently implemented for elements only.
973 */
974 virtual void Describe(nsAString& aOutDescription) const {
975 aOutDescription = NS_LITERAL_STRING("(not an element)");
976 }
978 enum ETabFocusType {
979 //eTabFocus_textControlsMask = (1<<0), // unused - textboxes always tabbable
980 eTabFocus_formElementsMask = (1<<1), // non-text form elements
981 eTabFocus_linksMask = (1<<2), // links
982 eTabFocus_any = 1 + (1<<1) + (1<<2) // everything that can be focused
983 };
985 // Tab focus model bit field:
986 static int32_t sTabFocusModel;
988 // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
989 // the tabfocus bit field applies to xul elements.
990 static bool sTabFocusModelAppliesToXUL;
991 };
993 NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
995 inline nsIContent* nsINode::AsContent()
996 {
997 MOZ_ASSERT(IsContent());
998 return static_cast<nsIContent*>(this);
999 }
1001 #define NS_IMPL_FROMCONTENT_HELPER(_class, _check) \
1002 static _class* FromContent(nsIContent* aContent) \
1003 { \
1004 return aContent->_check ? static_cast<_class*>(aContent) : nullptr; \
1005 } \
1006 static _class* FromContentOrNull(nsIContent* aContent) \
1007 { \
1008 return aContent ? FromContent(aContent) : nullptr; \
1009 }
1011 #define NS_IMPL_FROMCONTENT(_class, _nsid) \
1012 NS_IMPL_FROMCONTENT_HELPER(_class, IsInNamespace(_nsid))
1014 #define NS_IMPL_FROMCONTENT_WITH_TAG(_class, _nsid, _tag) \
1015 NS_IMPL_FROMCONTENT_HELPER(_class, NodeInfo()->Equals(nsGkAtoms::_tag, _nsid))
1017 #define NS_IMPL_FROMCONTENT_HTML_WITH_TAG(_class, _tag) \
1018 NS_IMPL_FROMCONTENT_WITH_TAG(_class, kNameSpaceID_XHTML, _tag)
1020 #endif /* nsIContent_h___ */