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/. */
7 #ifndef mozilla_dom_HTMLOutputElement_h
8 #define mozilla_dom_HTMLOutputElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/ConstraintValidation.h"
12 #include "nsGenericHTMLElement.h"
13 #include "nsStubMutationObserver.h"
15 namespace mozilla::dom
{
19 class HTMLOutputElement final
: public nsGenericHTMLFormControlElement
,
20 public nsStubMutationObserver
,
21 public ConstraintValidation
{
23 using ConstraintValidation::GetValidationMessage
;
25 explicit HTMLOutputElement(
26 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
27 FromParser aFromParser
= NOT_FROM_PARSER
);
30 NS_DECL_ISUPPORTS_INHERITED
33 NS_IMETHOD
Reset() override
;
34 // The output element is not submittable.
35 NS_IMETHOD
SubmitNamesValues(FormData
* aFormData
) override
{ return NS_OK
; }
37 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
39 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
40 const nsAString
& aValue
,
41 nsIPrincipal
* aMaybeScriptedPrincipal
,
42 nsAttrValue
& aResult
) override
;
44 void DoneAddingChildren(bool aHaveNotified
) override
;
46 // This function is called when a callback function from nsIMutationObserver
47 // has to be used to update the defaultValue attribute.
48 void DescendantsChanged();
50 // nsIMutationObserver
51 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
52 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
53 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
54 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
56 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLOutputElement
,
57 nsGenericHTMLFormControlElement
)
59 JSObject
* WrapNode(JSContext
*, JS::Handle
<JSObject
*> aGivenProto
) override
;
62 nsDOMTokenList
* HtmlFor();
64 void GetName(nsAString
& aName
) { GetHTMLAttr(nsGkAtoms::name
, aName
); }
66 void SetName(const nsAString
& aName
, ErrorResult
& aRv
) {
67 SetHTMLAttr(nsGkAtoms::name
, aName
, aRv
);
70 void GetType(nsAString
& aType
) { aType
.AssignLiteral("output"); }
72 void GetDefaultValue(nsAString
& aDefaultValue
) {
73 aDefaultValue
= mDefaultValue
;
76 void SetDefaultValue(const nsAString
& aDefaultValue
, ErrorResult
& aRv
);
78 void GetValue(nsAString
& aValue
) const;
79 void SetValue(const nsAString
& aValue
, ErrorResult
& aRv
);
81 // nsIConstraintValidation::WillValidate is fine.
82 // nsIConstraintValidation::Validity() is fine.
83 // nsIConstraintValidation::GetValidationMessage() is fine.
84 // nsIConstraintValidation::CheckValidity() is fine.
85 void SetCustomValidity(const nsAString
& aError
);
88 virtual ~HTMLOutputElement();
90 enum ValueModeFlag
{ eModeDefault
, eModeValue
};
92 ValueModeFlag mValueModeFlag
;
93 bool mIsDoneAddingChildren
;
94 nsString mDefaultValue
;
95 RefPtr
<nsDOMTokenList
> mTokenList
;
98 } // namespace mozilla::dom
100 #endif // mozilla_dom_HTMLOutputElement_h