1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsGenericHTMLElement_h___
7 #define nsGenericHTMLElement_h___
9 #include "mozilla/Attributes.h"
10 #include "mozilla/EventForwards.h"
11 #include "nsMappedAttributeElement.h"
12 #include "nsNameSpaceManager.h" // for kNameSpaceID_None
13 #include "nsIFormControl.h"
14 #include "nsGkAtoms.h"
15 #include "nsContentCreatorFunctions.h"
16 #include "mozilla/dom/BindingDeclarations.h"
17 #include "mozilla/dom/Element.h"
18 #include "mozilla/dom/DOMRect.h"
19 #include "mozilla/dom/ValidityState.h"
20 #include "mozilla/dom/PopoverData.h"
21 #include "mozilla/dom/ToggleEvent.h"
24 class nsIFormControlFrame
;
26 class nsILayoutHistoryState
;
33 class EventChainPostVisitor
;
34 class EventChainPreVisitor
;
35 class EventChainVisitor
;
36 class EventListenerManager
;
39 class ElementInternals
;
40 class HTMLFormElement
;
42 } // namespace mozilla
44 using nsGenericHTMLElementBase
= nsMappedAttributeElement
;
47 * A common superclass for HTML elements
49 class nsGenericHTMLElement
: public nsGenericHTMLElementBase
{
52 using Element::SetTabIndex
;
53 explicit nsGenericHTMLElement(
54 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
55 : nsGenericHTMLElementBase(std::move(aNodeInfo
)) {
56 NS_ASSERTION(mNodeInfo
->NamespaceID() == kNameSpaceID_XHTML
,
57 "Unexpected namespace");
58 AddStatesSilently(mozilla::dom::ElementState::LTR
);
59 SetFlags(NODE_HAS_DIRECTION_LTR
);
62 NS_INLINE_DECL_REFCOUNTING_INHERITED(nsGenericHTMLElement
,
63 nsGenericHTMLElementBase
)
65 NS_IMPL_FROMNODE(nsGenericHTMLElement
, kNameSpaceID_XHTML
)
68 nsresult
CopyInnerTo(mozilla::dom::Element
* aDest
);
70 void GetTitle(mozilla::dom::DOMString
& aTitle
) {
71 GetHTMLAttr(nsGkAtoms::title
, aTitle
);
73 void SetTitle(const nsAString
& aTitle
) {
74 SetHTMLAttr(nsGkAtoms::title
, aTitle
);
76 void GetLang(mozilla::dom::DOMString
& aLang
) {
77 GetHTMLAttr(nsGkAtoms::lang
, aLang
);
79 void SetLang(const nsAString
& aLang
) { SetHTMLAttr(nsGkAtoms::lang
, aLang
); }
80 bool Translate() const override
;
81 void SetTranslate(bool aTranslate
, mozilla::ErrorResult
& aError
) {
82 SetHTMLAttr(nsGkAtoms::translate
, aTranslate
? u
"yes"_ns
: u
"no"_ns
,
85 void GetDir(nsAString
& aDir
) { GetHTMLEnumAttr(nsGkAtoms::dir
, aDir
); }
86 void SetDir(const nsAString
& aDir
, mozilla::ErrorResult
& aError
) {
87 SetHTMLAttr(nsGkAtoms::dir
, aDir
, aError
);
89 void GetPopover(nsString
& aPopover
) {
90 GetHTMLEnumAttr(nsGkAtoms::popover
, aPopover
);
92 void SetPopover(const nsAString
& aPopover
, mozilla::ErrorResult
& aError
) {
93 SetHTMLAttr(nsGkAtoms::popover
, aPopover
, aError
);
95 bool Hidden() const { return GetBoolAttr(nsGkAtoms::hidden
); }
96 void SetHidden(bool aHidden
, mozilla::ErrorResult
& aError
) {
97 SetHTMLBoolAttr(nsGkAtoms::hidden
, aHidden
, aError
);
99 bool Inert() const { return GetBoolAttr(nsGkAtoms::inert
); }
100 void SetInert(bool aInert
, mozilla::ErrorResult
& aError
) {
101 SetHTMLBoolAttr(nsGkAtoms::inert
, aInert
, aError
);
103 MOZ_CAN_RUN_SCRIPT
void Click(mozilla::dom::CallerType aCallerType
);
104 void GetAccessKey(nsString
& aAccessKey
) {
105 GetHTMLAttr(nsGkAtoms::accesskey
, aAccessKey
);
107 void SetAccessKey(const nsAString
& aAccessKey
, mozilla::ErrorResult
& aError
) {
108 SetHTMLAttr(nsGkAtoms::accesskey
, aAccessKey
, aError
);
110 void GetAccessKeyLabel(nsString
& aAccessKeyLabel
);
111 virtual bool Draggable() const {
112 return AttrValueIs(kNameSpaceID_None
, nsGkAtoms::draggable
,
113 nsGkAtoms::_true
, eIgnoreCase
);
115 void SetDraggable(bool aDraggable
, mozilla::ErrorResult
& aError
) {
116 SetHTMLAttr(nsGkAtoms::draggable
, aDraggable
? u
"true"_ns
: u
"false"_ns
,
119 void GetContentEditable(nsString
& aContentEditable
) {
120 ContentEditableTristate value
= GetContentEditableValue();
121 if (value
== eTrue
) {
122 aContentEditable
.AssignLiteral("true");
123 } else if (value
== eFalse
) {
124 aContentEditable
.AssignLiteral("false");
126 aContentEditable
.AssignLiteral("inherit");
129 void SetContentEditable(const nsAString
& aContentEditable
,
130 mozilla::ErrorResult
& aError
) {
131 if (aContentEditable
.LowerCaseEqualsLiteral("inherit")) {
132 UnsetHTMLAttr(nsGkAtoms::contenteditable
, aError
);
133 } else if (aContentEditable
.LowerCaseEqualsLiteral("true")) {
134 SetHTMLAttr(nsGkAtoms::contenteditable
, u
"true"_ns
, aError
);
135 } else if (aContentEditable
.LowerCaseEqualsLiteral("false")) {
136 SetHTMLAttr(nsGkAtoms::contenteditable
, u
"false"_ns
, aError
);
138 aError
.Throw(NS_ERROR_DOM_SYNTAX_ERR
);
141 bool IsContentEditable() {
142 for (nsIContent
* node
= this; node
; node
= node
->GetParent()) {
143 nsGenericHTMLElement
* element
= FromNode(node
);
145 ContentEditableTristate value
= element
->GetContentEditableValue();
146 if (value
!= eInherit
) {
147 return value
== eTrue
;
154 mozilla::dom::PopoverState
GetPopoverState() const;
155 void PopoverPseudoStateUpdate(bool aOpen
, bool aNotify
);
156 bool PopoverOpen() const;
157 bool CheckPopoverValidity(mozilla::dom::PopoverVisibilityState aExpectedState
,
158 Document
* aExpectedDocument
, ErrorResult
& aRv
);
159 /** Returns true if the event has been cancelled. */
160 MOZ_CAN_RUN_SCRIPT
bool FireToggleEvent(
161 mozilla::dom::PopoverVisibilityState aOldState
,
162 mozilla::dom::PopoverVisibilityState aNewState
, const nsAString
& aType
);
163 MOZ_CAN_RUN_SCRIPT
void QueuePopoverEventTask(
164 mozilla::dom::PopoverVisibilityState aOldState
);
165 MOZ_CAN_RUN_SCRIPT
void RunPopoverToggleEventTask(
166 mozilla::dom::PopoverToggleEventTask
* aTask
,
167 mozilla::dom::PopoverVisibilityState aOldState
);
168 MOZ_CAN_RUN_SCRIPT
void ShowPopover(ErrorResult
& aRv
);
169 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void HidePopoverWithoutRunningScript();
170 MOZ_CAN_RUN_SCRIPT
void HidePopoverInternal(bool aFocusPreviousElement
,
173 MOZ_CAN_RUN_SCRIPT
void HidePopover(ErrorResult
& aRv
);
174 MOZ_CAN_RUN_SCRIPT
void TogglePopover(bool force
, ErrorResult
& aRv
);
175 MOZ_CAN_RUN_SCRIPT
void FocusPopover();
176 void ForgetPreviouslyFocusedElementAfterHidingPopover();
177 MOZ_CAN_RUN_SCRIPT
void FocusPreviousElementAfterHidingPopover();
179 MOZ_CAN_RUN_SCRIPT
void FocusCandidate(Element
&, bool aClearUpFocus
);
181 void SetNonce(const nsAString
& aNonce
) {
182 SetProperty(nsGkAtoms::nonce
, new nsString(aNonce
),
183 nsINode::DeleteProperty
<nsString
>);
185 void RemoveNonce() { RemoveProperty(nsGkAtoms::nonce
); }
186 void GetNonce(nsAString
& aNonce
) const {
187 nsString
* cspNonce
= static_cast<nsString
*>(GetProperty(nsGkAtoms::nonce
));
193 /** Returns whether a form control should be default-focusable. */
194 bool IsFormControlDefaultFocusable(bool aWithMouse
) const;
197 * Returns the count of descendants (inclusive of this node) in
198 * the uncomposed document that are explicitly set as editable.
200 uint32_t EditableInclusiveDescendantCount();
203 void SetSpellcheck(bool aSpellcheck
, mozilla::ErrorResult
& aError
) {
204 SetHTMLAttr(nsGkAtoms::spellcheck
, aSpellcheck
? u
"true"_ns
: u
"false"_ns
,
209 void GetInnerText(mozilla::dom::DOMString
& aValue
, ErrorResult
& aError
);
211 void GetOuterText(mozilla::dom::DOMString
& aValue
, ErrorResult
& aError
) {
212 return GetInnerText(aValue
, aError
);
214 MOZ_CAN_RUN_SCRIPT
void SetInnerText(const nsAString
& aValue
);
215 MOZ_CAN_RUN_SCRIPT
void SetOuterText(const nsAString
& aValue
,
218 void GetInputMode(nsAString
& aValue
) {
219 GetEnumAttr(nsGkAtoms::inputmode
, nullptr, aValue
);
221 void SetInputMode(const nsAString
& aValue
, ErrorResult
& aRv
) {
222 SetHTMLAttr(nsGkAtoms::inputmode
, aValue
, aRv
);
224 virtual void GetAutocapitalize(nsAString
& aValue
) const;
225 void SetAutocapitalize(const nsAString
& aValue
, ErrorResult
& aRv
) {
226 SetHTMLAttr(nsGkAtoms::autocapitalize
, aValue
, aRv
);
229 void GetEnterKeyHint(nsAString
& aValue
) const {
230 GetEnumAttr(nsGkAtoms::enterkeyhint
, nullptr, aValue
);
232 void SetEnterKeyHint(const nsAString
& aValue
, ErrorResult
& aRv
) {
233 SetHTMLAttr(nsGkAtoms::enterkeyhint
, aValue
, aRv
);
237 * Determine whether an attribute is an event (onclick, etc.)
238 * @param aName the attribute
239 * @return whether the name is an event handler name
241 bool IsEventAttributeNameInternal(nsAtom
* aName
) override
;
243 #define EVENT(name_, id_, type_, struct_) /* nothing; handled by nsINode */
244 // The using nsINode::Get/SetOn* are to avoid warnings about shadowing the XPCOM
245 // getter and setter on nsINode.
246 #define FORWARDED_EVENT(name_, id_, type_, struct_) \
247 using nsINode::GetOn##name_; \
248 using nsINode::SetOn##name_; \
249 mozilla::dom::EventHandlerNonNull* GetOn##name_(); \
250 void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler);
251 #define ERROR_EVENT(name_, id_, type_, struct_) \
252 using nsINode::GetOn##name_; \
253 using nsINode::SetOn##name_; \
254 already_AddRefed<mozilla::dom::EventHandlerNonNull> GetOn##name_(); \
255 void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler);
256 #include "mozilla/EventNameList.h" // IWYU pragma: keep
258 #undef FORWARDED_EVENT
260 mozilla::dom::Element
* GetOffsetParent() {
261 mozilla::CSSIntRect rcFrame
;
262 return GetOffsetRect(rcFrame
);
264 int32_t OffsetTop() {
265 mozilla::CSSIntRect rcFrame
;
266 GetOffsetRect(rcFrame
);
270 int32_t OffsetLeft() {
271 mozilla::CSSIntRect rcFrame
;
272 GetOffsetRect(rcFrame
);
276 int32_t OffsetWidth() {
277 mozilla::CSSIntRect rcFrame
;
278 GetOffsetRect(rcFrame
);
280 return rcFrame
.Width();
282 int32_t OffsetHeight() {
283 mozilla::CSSIntRect rcFrame
;
284 GetOffsetRect(rcFrame
);
286 return rcFrame
.Height();
289 // These methods are already implemented in nsIContent but we want something
290 // faster for HTMLElements ignoring the namespace checking.
291 // This is safe because we already know that we are in the HTML namespace.
292 inline bool IsHTMLElement() const { return true; }
294 inline bool IsHTMLElement(nsAtom
* aTag
) const {
295 return mNodeInfo
->Equals(aTag
);
298 template <typename First
, typename
... Args
>
299 inline bool IsAnyOfHTMLElements(First aFirst
, Args
... aArgs
) const {
300 return IsNodeInternal(aFirst
, aArgs
...);
303 // https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals
304 virtual already_AddRefed
<mozilla::dom::ElementInternals
> AttachInternals(
307 mozilla::dom::ElementInternals
* GetInternals() const;
309 bool IsFormAssociatedCustomElements() const;
311 // Returns true if the event should not be handled from GetEventTargetParent.
312 virtual bool IsDisabledForEvents(mozilla::WidgetEvent
* aEvent
) {
316 bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus
); }
317 void SetAutofocus(bool aVal
, ErrorResult
& aRv
) {
318 SetHTMLBoolAttr(nsGkAtoms::autofocus
, aVal
, aRv
);
322 virtual ~nsGenericHTMLElement() = default;
325 // Implementation for nsIContent
326 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
327 void UnbindFromTree(bool aNullParent
= true) override
;
329 bool IsFocusableInternal(int32_t* aTabIndex
, bool aWithMouse
) override
{
330 bool isFocusable
= false;
331 IsHTMLFocusable(aWithMouse
, &isFocusable
, aTabIndex
);
335 * Returns true if a subclass is not allowed to override the value returned
338 virtual bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
341 mozilla::Result
<bool, nsresult
> PerformAccesskey(
342 bool aKeyCausesActivation
, bool aIsTrustedEvent
) override
;
345 * Check if an event for an anchor can be handled
346 * @return true if the event can be handled, false otherwise
348 bool CheckHandleEventForAnchorsPreconditions(
349 mozilla::EventChainVisitor
& aVisitor
);
350 void GetEventTargetParentForAnchors(mozilla::EventChainPreVisitor
& aVisitor
);
352 nsresult
PostHandleEventForAnchors(mozilla::EventChainPostVisitor
& aVisitor
);
353 bool IsHTMLLink(nsIURI
** aURI
) const;
355 // HTML element methods
356 void Compact() { mAttrs
.Compact(); }
358 void UpdateEditableState(bool aNotify
) override
;
360 mozilla::dom::ElementState
IntrinsicState() const override
;
362 // Helper for setting our editable flag and notifying
363 void DoSetEditableFlag(bool aEditable
, bool aNotify
) {
364 SetEditableFlag(aEditable
);
365 UpdateState(aNotify
);
368 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
369 const nsAString
& aValue
,
370 nsIPrincipal
* aMaybeScriptedPrincipal
,
371 nsAttrValue
& aResult
) override
;
373 bool ParseBackgroundAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
374 const nsAString
& aValue
, nsAttrValue
& aResult
);
376 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
377 nsMapRuleToAttributesFunc
GetAttributeMappingFunction() const override
;
380 * Get the base target for any links within this piece
381 * of content. Generally, this is the document's base target,
382 * but certain content carries a local base for backward
385 * @param aBaseTarget the base target [OUT]
387 void GetBaseTarget(nsAString
& aBaseTarget
) const;
390 * Get the primary form control frame for this element. Same as
391 * GetPrimaryFrame(), except it QI's to nsIFormControlFrame.
393 * @param aFlush whether to flush out frames so that they're up to date.
394 * @return the primary frame as nsIFormControlFrame
396 nsIFormControlFrame
* GetFormControlFrame(bool aFlushFrames
);
398 //----------------------------------------
401 * Parse an alignment attribute (top/middle/bottom/baseline)
403 * @param aString the string to parse
404 * @param aResult the resulting HTMLValue
405 * @return whether the value was parsed
407 static bool ParseAlignValue(const nsAString
& aString
, nsAttrValue
& aResult
);
410 * Parse a div align string to value (left/right/center/middle/justify)
412 * @param aString the string to parse
413 * @param aResult the resulting HTMLValue
414 * @return whether the value was parsed
416 static bool ParseDivAlignValue(const nsAString
& aString
,
417 nsAttrValue
& aResult
);
420 * Convert a table halign string to value (left/right/center/char/justify)
422 * @param aString the string to parse
423 * @param aResult the resulting HTMLValue
424 * @return whether the value was parsed
426 static bool ParseTableHAlignValue(const nsAString
& aString
,
427 nsAttrValue
& aResult
);
430 * Convert a table cell halign string to value
432 * @param aString the string to parse
433 * @param aResult the resulting HTMLValue
434 * @return whether the value was parsed
436 static bool ParseTableCellHAlignValue(const nsAString
& aString
,
437 nsAttrValue
& aResult
);
440 * Convert a table valign string to value (left/right/center/char/justify/
441 * abscenter/absmiddle/middle)
443 * @param aString the string to parse
444 * @param aResult the resulting HTMLValue
445 * @return whether the value was parsed
447 static bool ParseTableVAlignValue(const nsAString
& aString
,
448 nsAttrValue
& aResult
);
451 * Convert an image attribute to value (width, height, hspace, vspace, border)
453 * @param aAttribute the attribute to parse
454 * @param aString the string to parse
455 * @param aResult the resulting HTMLValue
456 * @return whether the value was parsed
458 static bool ParseImageAttribute(nsAtom
* aAttribute
, const nsAString
& aString
,
459 nsAttrValue
& aResult
);
461 static bool ParseReferrerAttribute(const nsAString
& aString
,
462 nsAttrValue
& aResult
);
465 * Convert a frameborder string to value (yes/no/1/0)
467 * @param aString the string to parse
468 * @param aResult the resulting HTMLValue
469 * @return whether the value was parsed
471 static bool ParseFrameborderValue(const nsAString
& aString
,
472 nsAttrValue
& aResult
);
475 * Convert a scrolling string to value (yes/no/on/off/scroll/noscroll/auto)
477 * @param aString the string to parse
478 * @param aResult the resulting HTMLValue
479 * @return whether the value was parsed
481 static bool ParseScrollingValue(const nsAString
& aString
,
482 nsAttrValue
& aResult
);
485 * Attribute Mapping Helpers
489 * A style attribute mapping function for the most common attributes, to be
490 * called by subclasses' attribute mapping functions. Currently handles
491 * dir, lang and hidden, could handle others.
493 * @param aAttributes the list of attributes to map
494 * @param aData the returned rule data [INOUT]
495 * @see GetAttributeMappingFunction
497 static void MapCommonAttributesInto(const nsMappedAttributes
* aAttributes
,
498 mozilla::MappedDeclarations
&);
500 * Same as MapCommonAttributesInto except that it does not handle hidden.
502 * @param aAttributes the list of attributes to map
503 * @param aData the returned rule data [INOUT]
504 * @see GetAttributeMappingFunction
506 static void MapCommonAttributesIntoExceptHidden(
507 const nsMappedAttributes
* aAttributes
, mozilla::MappedDeclarations
&);
509 static const MappedAttributeEntry sCommonAttributeMap
[];
510 static const MappedAttributeEntry sImageMarginSizeAttributeMap
[];
511 static const MappedAttributeEntry sImageBorderAttributeMap
[];
512 static const MappedAttributeEntry sImageAlignAttributeMap
[];
513 static const MappedAttributeEntry sDivAlignAttributeMap
[];
514 static const MappedAttributeEntry sBackgroundAttributeMap
[];
515 static const MappedAttributeEntry sBackgroundColorAttributeMap
[];
518 * Helper to map the align attribute into a style struct.
520 * @param aAttributes the list of attributes to map
521 * @param aData the returned rule data [INOUT]
522 * @see GetAttributeMappingFunction
524 static void MapImageAlignAttributeInto(const nsMappedAttributes
* aAttributes
,
525 mozilla::MappedDeclarations
&);
528 * Helper to map the align attribute into a style struct for things
529 * like <div>, <h1>, etc.
531 * @param aAttributes the list of attributes to map
532 * @param aData the returned rule data [INOUT]
533 * @see GetAttributeMappingFunction
535 static void MapDivAlignAttributeInto(const nsMappedAttributes
* aAttributes
,
536 mozilla::MappedDeclarations
&);
539 * Helper to map the valign attribute into a style struct for things
540 * like <col>, <tr>, <section>, etc.
542 * @param aAttributes the list of attributes to map
543 * @param aData the returned rule data [INOUT]
544 * @see GetAttributeMappingFunction
546 static void MapVAlignAttributeInto(const nsMappedAttributes
* aAttributes
,
547 mozilla::MappedDeclarations
&);
550 * Helper to map the image border attribute into a style struct.
552 * @param aAttributes the list of attributes to map
553 * @param aData the returned rule data [INOUT]
554 * @see GetAttributeMappingFunction
556 static void MapImageBorderAttributeInto(const nsMappedAttributes
* aAttributes
,
557 mozilla::MappedDeclarations
&);
559 * Helper to map the image margin attribute into a style struct.
561 * @param aAttributes the list of attributes to map
562 * @param aData the returned rule data [INOUT]
563 * @see GetAttributeMappingFunction
565 static void MapImageMarginAttributeInto(const nsMappedAttributes
* aAttributes
,
566 mozilla::MappedDeclarations
&);
568 // Whether to map the width and height attributes to aspect-ratio.
569 enum class MapAspectRatio
{ No
, Yes
};
572 * Helper to map the image position attribute into a style struct.
574 static void MapImageSizeAttributesInto(const nsMappedAttributes
*,
575 mozilla::MappedDeclarations
&,
576 MapAspectRatio
= MapAspectRatio::No
);
578 * Helper to map the iamge source attributes into a style stuct.
580 * This will override the declaration created by the presentation attributes
581 * of HTMLImageElement (i.e. mapped by MapImageSizeAttributeInto).
582 * https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element
584 static void MapPictureSourceSizeAttributesInto(const nsMappedAttributes
*,
585 mozilla::MappedDeclarations
&);
588 * Helper to map the width and height attributes into the aspect-ratio
591 * If you also map the width/height attributes to width/height (as you should
592 * for any HTML element that isn't <canvas>) then you should use
593 * MapImageSizeAttributesInto instead, passing MapAspectRatio::Yes instead, as
596 static void MapAspectRatioInto(const nsMappedAttributes
*,
597 mozilla::MappedDeclarations
&);
600 * Helper to map `width` attribute into a style struct.
602 * @param aAttributes the list of attributes to map
603 * @param aData the returned rule data [INOUT]
604 * @see GetAttributeMappingFunction
606 static void MapWidthAttributeInto(const nsMappedAttributes
* aAttributes
,
607 mozilla::MappedDeclarations
&);
609 * Helper to map `height` attribute into a style struct.
611 * @param aAttributes the list of attributes to map
612 * @param aData the returned rule data [INOUT]
613 * @see GetAttributeMappingFunction
615 static void MapHeightAttributeInto(const nsMappedAttributes
* aAttributes
,
616 mozilla::MappedDeclarations
&);
618 * Helper to map the background attribute
619 * into a style struct.
621 * @param aAttributes the list of attributes to map
622 * @param aData the returned rule data [INOUT]
623 * @see GetAttributeMappingFunction
625 static void MapBackgroundInto(const nsMappedAttributes
* aAttributes
,
626 mozilla::MappedDeclarations
&);
628 * Helper to map the bgcolor attribute
629 * into a style struct.
631 * @param aAttributes the list of attributes to map
632 * @param aData the returned rule data [INOUT]
633 * @see GetAttributeMappingFunction
635 static void MapBGColorInto(const nsMappedAttributes
* aAttributes
,
636 mozilla::MappedDeclarations
&);
638 * Helper to map the background attributes (currently background and bgcolor)
639 * into a style struct.
641 * @param aAttributes the list of attributes to map
642 * @param aData the returned rule data [INOUT]
643 * @see GetAttributeMappingFunction
645 static void MapBackgroundAttributesInto(const nsMappedAttributes
* aAttributes
,
646 mozilla::MappedDeclarations
&);
648 * Helper to map the scrolling attribute on FRAME and IFRAME
649 * into a style struct.
651 * @param aAttributes the list of attributes to map
652 * @param aData the returned rule data [INOUT]
653 * @see GetAttributeMappingFunction
655 static void MapScrollingAttributeInto(const nsMappedAttributes
* aAttributes
,
656 mozilla::MappedDeclarations
&);
658 // Form Helper Routines
660 * Find an ancestor of this content node which is a form (could be null)
661 * @param aCurrentForm the current form for this node. If this is
662 * non-null, and no ancestor form is found, and the current form is in
663 * a connected subtree with the node, the current form will be
664 * returned. This is needed to handle cases when HTML elements have a
665 * current form that they're not descendants of.
666 * @note This method should not be called if the element has a form attribute.
668 mozilla::dom::HTMLFormElement
* FindAncestorForm(
669 mozilla::dom::HTMLFormElement
* aCurrentForm
= nullptr);
672 * See if the document being tested has nav-quirks mode enabled.
673 * @param doc the document
675 static bool InNavQuirksMode(Document
*);
678 * Gets the absolute URI value of an attribute, by resolving any relative
679 * URIs in the attribute against the baseuri of the element. If the attribute
680 * isn't a relative URI the value of the attribute is returned as is. Only
681 * works for attributes in null namespace.
683 * @param aAttr name of attribute.
684 * @param aBaseAttr name of base attribute.
685 * @param aResult result value [out]
687 void GetURIAttr(nsAtom
* aAttr
, nsAtom
* aBaseAttr
, nsAString
& aResult
) const;
690 * Gets the absolute URI values of an attribute, by resolving any relative
691 * URIs in the attribute against the baseuri of the element. If a substring
692 * isn't a relative URI, the substring is returned as is. Only works for
693 * attributes in null namespace.
695 bool GetURIAttr(nsAtom
* aAttr
, nsAtom
* aBaseAttr
, nsIURI
** aURI
) const;
697 bool IsHidden() const {
698 return HasAttr(kNameSpaceID_None
, nsGkAtoms::hidden
);
701 bool IsLabelable() const override
;
703 static bool MatchLabelsElement(Element
* aElement
, int32_t aNamespaceID
,
704 nsAtom
* aAtom
, void* aData
);
706 already_AddRefed
<nsINodeList
> Labels();
708 static bool LegacyTouchAPIEnabled(JSContext
* aCx
, JSObject
* aObj
);
710 static inline bool CanHaveName(nsAtom
* aTag
) {
711 return aTag
== nsGkAtoms::img
|| aTag
== nsGkAtoms::form
||
712 aTag
== nsGkAtoms::embed
|| aTag
== nsGkAtoms::object
;
714 static inline bool ShouldExposeNameAsHTMLDocumentProperty(Element
* aElement
) {
715 return aElement
->IsHTMLElement() &&
716 CanHaveName(aElement
->NodeInfo()->NameAtom());
718 static inline bool ShouldExposeIdAsHTMLDocumentProperty(Element
* aElement
) {
719 if (aElement
->IsHTMLElement(nsGkAtoms::object
)) {
723 // Per spec, <img> is exposed by id only if it also has a nonempty
724 // name (which doesn't have to match the id or anything).
725 // HasName() is true precisely when name is nonempty.
726 return aElement
->IsHTMLElement(nsGkAtoms::img
) && aElement
->HasName();
729 virtual inline void ResultForDialogSubmit(nsAString
& aResult
) {
730 GetAttr(kNameSpaceID_None
, nsGkAtoms::value
, aResult
);
735 * Add/remove this element to the documents name cache
737 void AddToNameTable(nsAtom
* aName
);
738 void RemoveFromNameTable();
741 * Register or unregister an access key to this element based on the
742 * accesskey attribute.
744 void RegUnRegAccessKey(bool aDoReg
) override
{
745 if (!HasFlag(NODE_HAS_ACCESSKEY
)) {
749 nsStyledElement::RegUnRegAccessKey(aDoReg
);
753 void BeforeSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
754 const nsAttrValue
* aValue
, bool aNotify
) override
;
755 // TODO: Convert AfterSetAttr to MOZ_CAN_RUN_SCRIPT and get rid of
756 // kungFuDeathGrip in it.
757 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void AfterSetAttr(
758 int32_t aNamespaceID
, nsAtom
* aName
, const nsAttrValue
* aValue
,
759 const nsAttrValue
* aOldValue
, nsIPrincipal
* aMaybeScriptedPrincipal
,
760 bool aNotify
) override
;
762 MOZ_CAN_RUN_SCRIPT
void AfterSetPopoverAttr();
764 mozilla::EventListenerManager
* GetEventListenerManagerForAttr(
765 nsAtom
* aAttrName
, bool* aDefer
) override
;
768 * Handles dispatching a simulated click on `this` on space or enter.
769 * TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
771 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void HandleKeyboardActivation(
772 mozilla::EventChainPostVisitor
&);
774 /** Dispatch a simulated mouse click by keyboard to the given element. */
775 MOZ_CAN_RUN_SCRIPT
static nsresult
DispatchSimulatedClick(
776 nsGenericHTMLElement
* aElement
, bool aIsTrusted
,
777 nsPresContext
* aPresContext
);
780 * Create a URI for the given aURISpec string.
781 * Returns INVALID_STATE_ERR and nulls *aURI if aURISpec is empty
782 * and the document's URI matches the element's base URI.
784 nsresult
NewURIFromString(const nsAString
& aURISpec
, nsIURI
** aURI
);
786 void GetHTMLAttr(nsAtom
* aName
, nsAString
& aResult
) const {
787 GetAttr(aName
, aResult
);
789 void GetHTMLAttr(nsAtom
* aName
, mozilla::dom::DOMString
& aResult
) const {
790 GetAttr(kNameSpaceID_None
, aName
, aResult
);
792 void GetHTMLEnumAttr(nsAtom
* aName
, nsAString
& aResult
) const {
793 GetEnumAttr(aName
, nullptr, aResult
);
795 void GetHTMLURIAttr(nsAtom
* aName
, nsAString
& aResult
) const {
796 GetURIAttr(aName
, nullptr, aResult
);
799 void SetHTMLAttr(nsAtom
* aName
, const nsAString
& aValue
) {
800 SetAttr(kNameSpaceID_None
, aName
, aValue
, true);
802 void SetHTMLAttr(nsAtom
* aName
, const nsAString
& aValue
,
803 mozilla::ErrorResult
& aError
) {
804 SetAttr(aName
, aValue
, aError
);
806 void SetHTMLAttr(nsAtom
* aName
, const nsAString
& aValue
,
807 nsIPrincipal
* aTriggeringPrincipal
,
808 mozilla::ErrorResult
& aError
) {
809 SetAttr(aName
, aValue
, aTriggeringPrincipal
, aError
);
811 void UnsetHTMLAttr(nsAtom
* aName
, mozilla::ErrorResult
& aError
) {
812 UnsetAttr(aName
, aError
);
814 void SetHTMLBoolAttr(nsAtom
* aName
, bool aValue
,
815 mozilla::ErrorResult
& aError
) {
817 SetHTMLAttr(aName
, u
""_ns
, aError
);
819 UnsetHTMLAttr(aName
, aError
);
822 template <typename T
>
823 void SetHTMLIntAttr(nsAtom
* aName
, T aValue
, mozilla::ErrorResult
& aError
) {
825 value
.AppendInt(aValue
);
827 SetHTMLAttr(aName
, value
, aError
);
831 * Gets the integer-value of an attribute, returns specified default value
832 * if the attribute isn't set or isn't set to an integer. Only works for
833 * attributes in null namespace.
835 * @param aAttr name of attribute.
836 * @param aDefault default-value to return if attribute isn't set.
838 int32_t GetIntAttr(nsAtom
* aAttr
, int32_t aDefault
) const;
841 * Sets value of attribute to specified integer. Only works for attributes
844 * @param aAttr name of attribute.
845 * @param aValue Integer value of attribute.
847 nsresult
SetIntAttr(nsAtom
* aAttr
, int32_t aValue
);
850 * Gets the unsigned integer-value of an attribute, returns specified default
851 * value if the attribute isn't set or isn't set to an integer. Only works for
852 * attributes in null namespace.
854 * @param aAttr name of attribute.
855 * @param aDefault default-value to return if attribute isn't set.
857 uint32_t GetUnsignedIntAttr(nsAtom
* aAttr
, uint32_t aDefault
) const;
860 * Sets value of attribute to specified unsigned integer. Only works for
861 * attributes in null namespace.
863 * @param aAttr name of attribute.
864 * @param aValue Integer value of attribute.
865 * @param aDefault Default value (in case value is out of range). If the spec
866 * doesn't provide one, should be 1 if the value is limited to
867 * nonzero values, and 0 otherwise.
869 void SetUnsignedIntAttr(nsAtom
* aName
, uint32_t aValue
, uint32_t aDefault
,
870 mozilla::ErrorResult
& aError
) {
872 if (aValue
> INT32_MAX
) {
873 value
.AppendInt(aDefault
);
875 value
.AppendInt(aValue
);
878 SetHTMLAttr(aName
, value
, aError
);
882 * Gets the unsigned integer-value of an attribute that is stored as a
883 * dimension (i.e. could be an integer or a percentage), returns specified
884 * default value if the attribute isn't set or isn't set to a dimension. Only
885 * works for attributes in null namespace.
887 * @param aAttr name of attribute.
888 * @param aDefault default-value to return if attribute isn't set.
890 uint32_t GetDimensionAttrAsUnsignedInt(nsAtom
* aAttr
,
891 uint32_t aDefault
) const;
894 * Sets value of attribute to specified double. Only works for attributes
897 * @param aAttr name of attribute.
898 * @param aValue Double value of attribute.
900 void SetDoubleAttr(nsAtom
* aAttr
, double aValue
, mozilla::ErrorResult
& aRv
) {
902 value
.AppendFloat(aValue
);
904 SetHTMLAttr(aAttr
, value
, aRv
);
908 * Locates the EditorBase associated with this node. In general this is
909 * equivalent to GetEditorInternal(), but for designmode or contenteditable,
910 * this may need to get an editor that's not actually on this element's
911 * associated TextControlFrame. This is used by the spellchecking routines
912 * to get the editor affected by changing the spellcheck attribute on this
915 virtual already_AddRefed
<mozilla::EditorBase
> GetAssociatedEditor();
918 * Get the frame's offset information for offsetTop/Left/Width/Height.
919 * Returns the parent the offset is relative to.
920 * @note This method flushes pending notifications (FlushType::Layout).
921 * @param aRect the offset information [OUT]
923 mozilla::dom::Element
* GetOffsetRect(mozilla::CSSIntRect
& aRect
);
926 * Ensures all editors associated with a subtree are synced, for purposes of
929 static void SyncEditorsOnSubtree(nsIContent
* content
);
931 enum ContentEditableTristate
{ eInherit
= -1, eFalse
= 0, eTrue
= 1 };
934 * Returns eTrue if the element has a contentEditable attribute and its value
935 * is "true" or an empty string. Returns eFalse if the element has a
936 * contentEditable attribute and its value is "false". Otherwise returns
939 ContentEditableTristate
GetContentEditableValue() const {
940 static const Element::AttrValuesArray values
[] = {
941 nsGkAtoms::_false
, nsGkAtoms::_true
, nsGkAtoms::_empty
, nullptr};
943 if (!MayHaveContentEditableAttr()) return eInherit
;
945 int32_t value
= FindAttrValueIn(
946 kNameSpaceID_None
, nsGkAtoms::contenteditable
, values
, eIgnoreCase
);
948 return value
> 0 ? eTrue
: (value
== 0 ? eFalse
: eInherit
);
951 // Used by A, AREA, LINK, and STYLE.
952 already_AddRefed
<nsIURI
> GetHrefURIForAnchors() const;
956 * Returns whether this element is an editable root. There are two types of
958 * 1) the documentElement if the whole document is editable (for example for
960 * 2) an element that is marked editable with contentEditable=true and that
961 * doesn't have a parent or whose parent is not editable.
962 * Note that this doesn't return input and textarea elements that haven't been
963 * made editable through contentEditable or designMode.
965 bool IsEditableRoot() const;
968 void ChangeEditableState(int32_t aChange
);
971 namespace mozilla::dom
{
972 class HTMLFieldSetElement
;
973 } // namespace mozilla::dom
975 #define HTML_ELEMENT_FLAG_BIT(n_) \
976 NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
978 // HTMLElement specific bits
980 // Used to handle keyboard activation.
981 HTML_ELEMENT_ACTIVE_FOR_KEYBOARD
= HTML_ELEMENT_FLAG_BIT(0),
983 // Remaining bits are type specific.
984 HTML_ELEMENT_TYPE_SPECIFIC_BITS_OFFSET
=
985 ELEMENT_TYPE_SPECIFIC_BITS_OFFSET
+ 1,
988 ASSERT_NODE_FLAGS_SPACE(HTML_ELEMENT_TYPE_SPECIFIC_BITS_OFFSET
);
990 #define FORM_ELEMENT_FLAG_BIT(n_) \
991 NODE_FLAG_BIT(HTML_ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
993 // Form element specific bits
995 // If this flag is set on an nsGenericHTMLFormElement or an HTMLImageElement,
996 // that means that we have added ourselves to our mForm. It's possible to
997 // have a non-null mForm, but not have this flag set. That happens when the
998 // form is set via the content sink.
999 ADDED_TO_FORM
= FORM_ELEMENT_FLAG_BIT(0),
1001 // If this flag is set on an nsGenericHTMLFormElement or an HTMLImageElement,
1002 // that means that its form is in the process of being unbound from the tree,
1003 // and this form element hasn't re-found its form in
1004 // nsGenericHTMLFormElement::UnbindFromTree yet.
1005 MAYBE_ORPHAN_FORM_ELEMENT
= FORM_ELEMENT_FLAG_BIT(1),
1007 // If this flag is set on an nsGenericHTMLElement or an HTMLImageElement, then
1008 // the element might be in the past names map of its form.
1009 MAY_BE_IN_PAST_NAMES_MAP
= FORM_ELEMENT_FLAG_BIT(2)
1012 // NOTE: I don't think it's possible to have both ADDED_TO_FORM and
1013 // MAYBE_ORPHAN_FORM_ELEMENT set at the same time, so if it becomes an issue we
1014 // can probably merge them into the same bit. --bz
1016 ASSERT_NODE_FLAGS_SPACE(HTML_ELEMENT_TYPE_SPECIFIC_BITS_OFFSET
+ 3);
1018 #undef FORM_ELEMENT_FLAG_BIT
1021 * A helper class for form elements that can contain children
1023 class nsGenericHTMLFormElement
: public nsGenericHTMLElement
{
1025 nsGenericHTMLFormElement(
1026 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
1029 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
1030 void UnbindFromTree(bool aNullParent
= true) override
;
1033 * This callback is called by a fieldest on all its elements whenever its
1034 * disabled attribute is changed so the element knows its disabled state
1035 * might have changed.
1037 * @note Classes redefining this method should not do any content
1038 * state updates themselves but should just make sure to call into
1039 * nsGenericHTMLFormElement::FieldSetDisabledChanged.
1041 virtual void FieldSetDisabledChanged(bool aNotify
);
1043 void FieldSetFirstLegendChanged(bool aNotify
) { UpdateFieldSet(aNotify
); }
1046 * This callback is called by a fieldset on all it's elements when it's being
1047 * destroyed. When called, the elements should check that aFieldset is there
1048 * first parent fieldset and null mFieldset in that case only.
1050 * @param aFieldSet The fieldset being removed.
1052 void ForgetFieldSet(nsIContent
* aFieldset
);
1054 void ClearForm(bool aRemoveFromForm
, bool aUnbindOrDelete
);
1057 virtual ~nsGenericHTMLFormElement() = default;
1059 void BeforeSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
1060 const nsAttrValue
* aValue
, bool aNotify
) override
;
1062 void AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
1063 const nsAttrValue
* aValue
, const nsAttrValue
* aOldValue
,
1064 nsIPrincipal
* aMaybeScriptedPrincipal
,
1065 bool aNotify
) override
;
1067 virtual void BeforeSetForm(bool aBindToTree
) {}
1069 virtual void AfterClearForm(bool aUnbindOrDelete
) {}
1072 * Check our disabled content attribute and fieldset's (if it exists) disabled
1073 * state to decide whether our disabled flag should be toggled.
1075 virtual void UpdateDisabledState(bool aNotify
);
1077 virtual void SetFormInternal(mozilla::dom::HTMLFormElement
* aForm
,
1078 bool aBindToTree
) {}
1080 virtual mozilla::dom::HTMLFormElement
* GetFormInternal() const {
1084 virtual mozilla::dom::HTMLFieldSetElement
* GetFieldSetInternal() const {
1088 virtual void SetFieldSetInternal(
1089 mozilla::dom::HTMLFieldSetElement
* aFieldset
) {}
1092 * This method will update the form owner, using @form or looking to a parent.
1094 * @param aBindToTree Whether the element is being attached to the tree.
1095 * @param aFormIdElement The element associated with the id in @form. If
1096 * aBindToTree is false, aFormIdElement *must* contain the element associated
1097 * with the id in @form. Otherwise, it *must* be null.
1099 * @note Callers of UpdateFormOwner have to be sure the element is in a
1100 * document (GetUncomposedDoc() != nullptr).
1102 virtual void UpdateFormOwner(bool aBindToTree
, Element
* aFormIdElement
);
1105 * This method will update mFieldset and set it to the first fieldset parent.
1107 void UpdateFieldSet(bool aNotify
);
1110 * Add a form id observer which will observe when the element with the id in
1111 * @form will change.
1113 * @return The element associated with the current id in @form (may be null).
1115 Element
* AddFormIdObserver();
1118 * Remove the form id observer.
1120 void RemoveFormIdObserver();
1123 * This method is a a callback for IDTargetObserver (from Document).
1124 * It will be called each time the element associated with the id in @form
1127 static bool FormIdUpdated(Element
* aOldElement
, Element
* aNewElement
,
1130 // Returns true if the event should not be handled from GetEventTargetParent
1131 bool IsElementDisabledForEvents(mozilla::WidgetEvent
* aEvent
,
1135 * Returns if the control can be disabled.
1137 virtual bool CanBeDisabled() const { return false; }
1140 * Returns if the readonly attribute applies.
1142 virtual bool DoesReadOnlyApply() const { return false; }
1145 * Returns true if the element is a form associated element.
1146 * See https://html.spec.whatwg.org/#form-associated-element.
1148 virtual bool IsFormAssociatedElement() const { return false; }
1151 class nsGenericHTMLFormControlElement
: public nsGenericHTMLFormElement
,
1152 public nsIFormControl
{
1154 nsGenericHTMLFormControlElement(
1155 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
, FormControlType
);
1157 NS_DECL_ISUPPORTS_INHERITED
1159 NS_IMPL_FROMNODE_HELPER(nsGenericHTMLFormControlElement
,
1160 IsHTMLFormControlElement())
1163 nsINode
* GetScopeChainParent() const override
;
1164 bool IsHTMLFormControlElement() const final
{ return true; }
1167 void SaveSubtreeState() override
;
1168 IMEState
GetDesiredIMEState() override
;
1169 void UnbindFromTree(bool aNullParent
= true) override
;
1171 // nsGenericHTMLElement
1172 // autocapitalize attribute support
1173 void GetAutocapitalize(nsAString
& aValue
) const override
;
1174 bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
1175 int32_t* aTabIndex
) override
;
1178 void GetEventTargetParent(mozilla::EventChainPreVisitor
& aVisitor
) override
;
1179 nsresult
PreHandleEvent(mozilla::EventChainVisitor
& aVisitor
) override
;
1182 mozilla::dom::HTMLFieldSetElement
* GetFieldSet() override
;
1183 mozilla::dom::HTMLFormElement
* GetForm() const override
{ return mForm
; }
1184 void SetForm(mozilla::dom::HTMLFormElement
* aForm
) override
;
1185 void ClearForm(bool aRemoveFromForm
, bool aUnbindOrDelete
) override
;
1186 bool AllowDrop() override
{ return true; }
1189 virtual ~nsGenericHTMLFormControlElement();
1192 mozilla::dom::ElementState
IntrinsicState() const override
;
1193 bool IsLabelable() const override
;
1195 // nsGenericHTMLFormElement
1196 bool CanBeDisabled() const override
;
1197 bool DoesReadOnlyApply() const override
;
1198 void SetFormInternal(mozilla::dom::HTMLFormElement
* aForm
,
1199 bool aBindToTree
) override
;
1200 mozilla::dom::HTMLFormElement
* GetFormInternal() const override
;
1201 mozilla::dom::HTMLFieldSetElement
* GetFieldSetInternal() const override
;
1202 void SetFieldSetInternal(
1203 mozilla::dom::HTMLFieldSetElement
* aFieldset
) override
;
1204 bool IsFormAssociatedElement() const override
{ return true; }
1207 * Update our required/optional flags to match the given aIsRequired boolean.
1209 void UpdateRequiredState(bool aIsRequired
, bool aNotify
);
1211 bool IsAutocapitalizeInheriting() const;
1214 * Save to presentation state. The form control will determine whether it
1215 * has anything to save and if so, create an entry in the layout history for
1218 virtual void SaveState() {}
1220 /** The form that contains this control */
1221 mozilla::dom::HTMLFormElement
* mForm
;
1223 /* This is a pointer to our closest fieldset parent if any */
1224 mozilla::dom::HTMLFieldSetElement
* mFieldSet
;
1227 enum class PopoverTargetAction
: uint8_t {
1233 class nsGenericHTMLFormControlElementWithState
1234 : public nsGenericHTMLFormControlElement
{
1236 nsGenericHTMLFormControlElementWithState(
1237 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
1238 mozilla::dom::FromParser aFromParser
, FormControlType
);
1240 bool IsGenericHTMLFormControlElementWithState() const final
{ return true; }
1241 NS_IMPL_FROMNODE_HELPER(nsGenericHTMLFormControlElementWithState
,
1242 IsGenericHTMLFormControlElementWithState())
1245 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
1246 const nsAString
& aValue
,
1247 nsIPrincipal
* aMaybeScriptedPrincipal
,
1248 nsAttrValue
& aResult
) override
;
1250 // PopoverInvokerElement
1251 mozilla::dom::Element
* GetPopoverTargetElement() const;
1252 void SetPopoverTargetElement(mozilla::dom::Element
*);
1253 void GetPopoverTargetAction(nsAString
& aValue
) const {
1254 GetHTMLEnumAttr(nsGkAtoms::popovertargetaction
, aValue
);
1256 void SetPopoverTargetAction(const nsAString
& aValue
) {
1257 SetHTMLAttr(nsGkAtoms::popovertargetaction
, aValue
);
1261 * https://html.spec.whatwg.org/#popover-target-attribute-activation-behavior
1263 MOZ_CAN_RUN_SCRIPT
void HandlePopoverTargetAction();
1266 * Get the presentation state for a piece of content, or create it if it does
1267 * not exist. Generally used by SaveState().
1269 mozilla::PresState
* GetPrimaryPresState();
1272 * Get the layout history object for a particular piece of content.
1274 * @param aRead if true, won't return a layout history state if the
1275 * layout history state is empty.
1276 * @return the history state object
1278 already_AddRefed
<nsILayoutHistoryState
> GetLayoutHistory(bool aRead
);
1281 * Called when we have been cloned and adopted, and the information of the
1282 * node has been changed.
1284 void NodeInfoChanged(Document
* aOldDoc
) override
;
1286 void GetFormAction(nsString
& aValue
);
1290 * Restore from presentation state. You pass in the presentation state for
1291 * this form control (generated with GenerateStateKey() + "-C") and the form
1292 * control will grab its state from there.
1294 * @param aState the pres state to use to restore the control
1295 * @return true if the form control was a checkbox and its
1296 * checked state was restored, false otherwise.
1298 virtual bool RestoreState(mozilla::PresState
* aState
) { return false; }
1301 * Restore the state for a form control in response to the element being
1302 * inserted into the document by the parser. Ends up calling RestoreState().
1304 * GenerateStateKey() must already have been called.
1306 * @return false if RestoreState() was not called, the return
1307 * value of RestoreState() otherwise.
1309 bool RestoreFormControlState();
1311 /* Generates the state key for saving the form state in the session if not
1312 computed already. The result is stored in mStateKey. */
1313 void GenerateStateKey();
1315 int32_t GetParserInsertedControlNumberForStateKey() const override
{
1316 return mControlNumber
;
1319 /* Used to store the key to that element in the session. Is void until
1320 GenerateStateKey has been used */
1321 nsCString mStateKey
;
1323 // A number for this form control that is unique within its owner document.
1324 // This is only set to a number for elements inserted into the document by
1325 // the parser from the network. Otherwise, it is -1.
1326 int32_t mControlNumber
;
1329 #define NS_INTERFACE_MAP_ENTRY_IF_TAG(_interface, _tag) \
1330 NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface, \
1331 mNodeInfo->Equals(nsGkAtoms::_tag))
1333 namespace mozilla::dom
{
1335 using HTMLContentCreatorFunction
=
1336 nsGenericHTMLElement
* (*)(already_AddRefed
<mozilla::dom::NodeInfo
>&&,
1337 mozilla::dom::FromParser
);
1339 } // namespace mozilla::dom
1342 * A macro to declare the NS_NewHTMLXXXElement() functions.
1344 #define NS_DECLARE_NS_NEW_HTML_ELEMENT(_elementName) \
1345 namespace mozilla { \
1347 class HTML##_elementName##Element; \
1350 nsGenericHTMLElement* NS_NewHTML##_elementName##Element( \
1351 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
1352 mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
1354 #define NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(_elementName) \
1355 inline nsGenericHTMLElement* NS_NewHTML##_elementName##Element( \
1356 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
1357 mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER) { \
1358 return NS_NewHTMLSharedElement(std::move(aNodeInfo), aFromParser); \
1362 * A macro to implement the NS_NewHTMLXXXElement() functions.
1364 #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName) \
1365 nsGenericHTMLElement* NS_NewHTML##_elementName##Element( \
1366 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
1367 mozilla::dom::FromParser aFromParser) { \
1368 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo); \
1369 auto* nim = nodeInfo->NodeInfoManager(); \
1372 mozilla::dom::HTML##_elementName##Element(nodeInfo.forget()); \
1375 #define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName) \
1376 nsGenericHTMLElement* NS_NewHTML##_elementName##Element( \
1377 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
1378 mozilla::dom::FromParser aFromParser) { \
1379 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo); \
1380 auto* nim = nodeInfo->NodeInfoManager(); \
1382 return new (nim) mozilla::dom::HTML##_elementName##Element( \
1383 nodeInfo.forget(), aFromParser); \
1386 // Here, we expand 'NS_DECLARE_NS_NEW_HTML_ELEMENT()' by hand.
1387 // (Calling the macro directly (with no args) produces compiler warnings.)
1388 nsGenericHTMLElement
* NS_NewHTMLElement(
1389 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
1390 mozilla::dom::FromParser aFromParser
= mozilla::dom::NOT_FROM_PARSER
);
1392 // Distinct from the above in order to have function pointer that compared
1393 // unequal to a function pointer to the above.
1394 nsGenericHTMLElement
* NS_NewCustomElement(
1395 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
1396 mozilla::dom::FromParser aFromParser
= mozilla::dom::NOT_FROM_PARSER
);
1398 NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared
)
1399 NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList
)
1401 NS_DECLARE_NS_NEW_HTML_ELEMENT(Anchor
)
1402 NS_DECLARE_NS_NEW_HTML_ELEMENT(Area
)
1403 NS_DECLARE_NS_NEW_HTML_ELEMENT(Audio
)
1404 NS_DECLARE_NS_NEW_HTML_ELEMENT(BR
)
1405 NS_DECLARE_NS_NEW_HTML_ELEMENT(Body
)
1406 NS_DECLARE_NS_NEW_HTML_ELEMENT(Button
)
1407 NS_DECLARE_NS_NEW_HTML_ELEMENT(Canvas
)
1408 NS_DECLARE_NS_NEW_HTML_ELEMENT(Content
)
1409 NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod
)
1410 NS_DECLARE_NS_NEW_HTML_ELEMENT(Data
)
1411 NS_DECLARE_NS_NEW_HTML_ELEMENT(DataList
)
1412 NS_DECLARE_NS_NEW_HTML_ELEMENT(Details
)
1413 NS_DECLARE_NS_NEW_HTML_ELEMENT(Dialog
)
1414 NS_DECLARE_NS_NEW_HTML_ELEMENT(Div
)
1415 NS_DECLARE_NS_NEW_HTML_ELEMENT(Embed
)
1416 NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet
)
1417 NS_DECLARE_NS_NEW_HTML_ELEMENT(Font
)
1418 NS_DECLARE_NS_NEW_HTML_ELEMENT(Form
)
1419 NS_DECLARE_NS_NEW_HTML_ELEMENT(Frame
)
1420 NS_DECLARE_NS_NEW_HTML_ELEMENT(FrameSet
)
1421 NS_DECLARE_NS_NEW_HTML_ELEMENT(HR
)
1422 NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(Head
)
1423 NS_DECLARE_NS_NEW_HTML_ELEMENT(Heading
)
1424 NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(Html
)
1425 NS_DECLARE_NS_NEW_HTML_ELEMENT(IFrame
)
1426 NS_DECLARE_NS_NEW_HTML_ELEMENT(Image
)
1427 NS_DECLARE_NS_NEW_HTML_ELEMENT(Input
)
1428 NS_DECLARE_NS_NEW_HTML_ELEMENT(LI
)
1429 NS_DECLARE_NS_NEW_HTML_ELEMENT(Label
)
1430 NS_DECLARE_NS_NEW_HTML_ELEMENT(Legend
)
1431 NS_DECLARE_NS_NEW_HTML_ELEMENT(Link
)
1432 NS_DECLARE_NS_NEW_HTML_ELEMENT(Marquee
)
1433 NS_DECLARE_NS_NEW_HTML_ELEMENT(Map
)
1434 NS_DECLARE_NS_NEW_HTML_ELEMENT(Menu
)
1435 NS_DECLARE_NS_NEW_HTML_ELEMENT(Meta
)
1436 NS_DECLARE_NS_NEW_HTML_ELEMENT(Meter
)
1437 NS_DECLARE_NS_NEW_HTML_ELEMENT(Object
)
1438 NS_DECLARE_NS_NEW_HTML_ELEMENT(OptGroup
)
1439 NS_DECLARE_NS_NEW_HTML_ELEMENT(Option
)
1440 NS_DECLARE_NS_NEW_HTML_ELEMENT(Output
)
1441 NS_DECLARE_NS_NEW_HTML_ELEMENT(Paragraph
)
1442 NS_DECLARE_NS_NEW_HTML_ELEMENT(Picture
)
1443 NS_DECLARE_NS_NEW_HTML_ELEMENT(Pre
)
1444 NS_DECLARE_NS_NEW_HTML_ELEMENT(Progress
)
1445 NS_DECLARE_NS_NEW_HTML_ELEMENT(Script
)
1446 NS_DECLARE_NS_NEW_HTML_ELEMENT(Select
)
1447 NS_DECLARE_NS_NEW_HTML_ELEMENT(Slot
)
1448 NS_DECLARE_NS_NEW_HTML_ELEMENT(Source
)
1449 NS_DECLARE_NS_NEW_HTML_ELEMENT(Span
)
1450 NS_DECLARE_NS_NEW_HTML_ELEMENT(Style
)
1451 NS_DECLARE_NS_NEW_HTML_ELEMENT(Summary
)
1452 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCaption
)
1453 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCell
)
1454 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCol
)
1455 NS_DECLARE_NS_NEW_HTML_ELEMENT(Table
)
1456 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableRow
)
1457 NS_DECLARE_NS_NEW_HTML_ELEMENT(TableSection
)
1458 NS_DECLARE_NS_NEW_HTML_ELEMENT(Tbody
)
1459 NS_DECLARE_NS_NEW_HTML_ELEMENT(Template
)
1460 NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea
)
1461 NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot
)
1462 NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead
)
1463 NS_DECLARE_NS_NEW_HTML_ELEMENT(Time
)
1464 NS_DECLARE_NS_NEW_HTML_ELEMENT(Title
)
1465 NS_DECLARE_NS_NEW_HTML_ELEMENT(Track
)
1466 NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown
)
1467 NS_DECLARE_NS_NEW_HTML_ELEMENT(Video
)
1469 #endif /* nsGenericHTMLElement_h___ */