2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef HTMLFormControlElement_h
25 #define HTMLFormControlElement_h
27 #include "core/CoreExport.h"
28 #include "core/html/FormAssociatedElement.h"
29 #include "core/html/LabelableElement.h"
34 class HTMLFormElement
;
35 class ValidationMessageClient
;
37 enum CheckValidityEventBehavior
{ CheckValidityDispatchNoEvent
, CheckValidityDispatchInvalidEvent
};
39 // HTMLFormControlElement is the default implementation of FormAssociatedElement,
40 // and form-associated element implementations should use HTMLFormControlElement
41 // unless there is a special reason.
42 class CORE_EXPORT HTMLFormControlElement
: public LabelableElement
, public FormAssociatedElement
{
43 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLFormControlElement
);
46 ~HTMLFormControlElement() override
;
47 DECLARE_VIRTUAL_TRACE();
49 String
formEnctype() const;
50 void setFormEnctype(const AtomicString
&);
51 String
formMethod() const;
52 void setFormMethod(const AtomicString
&);
53 bool formNoValidate() const;
55 void ancestorDisabledStateWasChanged();
59 bool wasChangedSinceLastFormControlChangeEvent() const { return m_wasChangedSinceLastFormControlChangeEvent
; }
60 void setChangedSinceLastFormControlChangeEvent(bool);
62 virtual void dispatchFormControlChangeEvent();
63 void dispatchChangeEvent();
64 void dispatchFormControlInputEvent();
66 HTMLFormElement
* formOwner() const final
;
68 bool isDisabledFormControl() const override
;
70 bool isEnumeratable() const override
{ return false; }
72 bool isRequired() const;
74 const AtomicString
& type() const { return formControlType(); }
76 virtual const AtomicString
& formControlType() const = 0;
78 virtual bool canTriggerImplicitSubmission() const { return false; }
80 virtual bool isSubmittableElement() { return true; }
82 // Override in derived classes to get the encoded name=value pair for submitting.
83 // Return true for a successful control (see HTML4-17.13.2).
84 bool appendFormData(FormDataList
&, bool) override
{ return false; }
85 virtual String
resultForDialogSubmit();
87 virtual bool canBeSuccessfulSubmitButton() const { return false; }
88 bool isSuccessfulSubmitButton() const;
89 virtual bool isActivatedSubmit() const { return false; }
90 virtual void setActivatedSubmit(bool) { }
92 bool willValidate() const override
;
94 void updateVisibleValidationMessage();
95 void hideVisibleValidationMessage();
96 bool checkValidity(WillBeHeapVector
<RefPtrWillBeMember
<HTMLFormControlElement
>>* unhandledInvalidControls
= 0, CheckValidityEventBehavior
= CheckValidityDispatchInvalidEvent
);
97 bool reportValidity();
98 // This must be called only after the caller check the element is focusable.
99 void showValidationMessage();
100 // This must be called when a validation constraint or control value is changed.
101 void setNeedsValidityCheck();
102 void setCustomValidity(const String
&) final
;
103 void findCustomValidationMessageTextDirection(const String
& message
, TextDirection
&messageDir
, String
& subMessage
, TextDirection
& subMessageDir
);
105 bool isReadOnly() const { return m_isReadOnly
; }
106 bool isDisabledOrReadOnly() const { return isDisabledFormControl() || m_isReadOnly
; }
108 bool isAutofocusable() const;
110 bool isAutofilled() const { return m_isAutofilled
; }
111 void setAutofilled(bool = true);
113 static HTMLFormControlElement
* enclosingFormControlElement(Node
*);
115 String
nameForAutofill() const;
117 void setFocus(bool flag
) override
;
118 void copyNonAttributePropertiesFromElement(const Element
&) override
;
126 HTMLFormControlElement(const QualifiedName
& tagName
, Document
&, HTMLFormElement
*);
128 void parseAttribute(const QualifiedName
&, const AtomicString
&) override
;
129 virtual void requiredAttributeChanged();
130 virtual void disabledAttributeChanged();
131 void attach(const AttachContext
& = AttachContext()) override
;
132 InsertionNotificationRequest
insertedInto(ContainerNode
*) override
;
133 void removedFrom(ContainerNode
*) override
;
134 void willChangeForm() override
;
135 void didChangeForm() override
;
136 void didMoveToNewDocument(Document
& oldDocument
) override
;
138 bool supportsFocus() const override
;
139 bool isKeyboardFocusable() const override
;
140 virtual bool shouldShowFocusRingOnMouseFocus() const;
141 bool shouldHaveFocusAppearance() const final
;
142 void dispatchBlurEvent(Element
* newFocusedElement
, WebFocusType
, InputDeviceCapabilities
* sourceCapabilities
) override
;
143 void dispatchFocusEvent(Element
* oldFocusedElement
, WebFocusType
, InputDeviceCapabilities
* sourceCapabilities
) override
;
144 void willCallDefaultEventHandler(const Event
&) final
;
146 void didRecalcStyle(StyleRecalcChange
) override
;
148 // This must be called any time the result of willValidate() has changed.
149 void setNeedsWillValidateCheck();
150 virtual bool recalcWillValidate() const;
152 virtual void resetImpl() { }
153 virtual bool supportsAutofocus() const;
157 void refFormAssociatedElement() final
{ ref(); }
158 void derefFormAssociatedElement() final
{ deref(); }
161 bool isFormControlElement() const final
{ return true; }
162 bool alwaysCreateUserAgentShadowRoot() const override
{ return true; }
164 short tabIndex() const final
;
166 bool isDefaultButtonForForm() const final
;
167 bool isValidElement() override
;
168 bool matchesValidityPseudoClasses() const override
;
169 void updateAncestorDisabledState() const;
171 bool isValidationMessageVisible() const;
172 ValidationMessageClient
* validationMessageClient() const;
174 // Requests validity recalc for the form owner, if one exists.
175 void formOwnerSetNeedsValidityCheck();
176 // Requests validity recalc for all ancestor fieldsets, if exist.
177 void fieldSetAncestorsSetNeedsValidityCheck(Node
*);
180 bool m_isAutofilled
: 1;
181 bool m_isReadOnly
: 1;
182 bool m_isRequired
: 1;
183 bool m_hasValidationMessage
: 1;
185 enum AncestorDisabledState
{ AncestorDisabledStateUnknown
, AncestorDisabledStateEnabled
, AncestorDisabledStateDisabled
};
186 mutable AncestorDisabledState m_ancestorDisabledState
;
187 enum DataListAncestorState
{ Unknown
, InsideDataList
, NotInsideDataList
};
188 mutable enum DataListAncestorState m_dataListAncestorState
;
190 // The initial value of m_willValidate depends on the derived class. We can't
191 // initialize it with a virtual function in the constructor. m_willValidate
192 // is not deterministic as long as m_willValidateInitialized is false.
193 mutable bool m_willValidateInitialized
: 1;
194 mutable bool m_willValidate
: 1;
198 bool m_validityIsDirty
: 1;
200 bool m_wasChangedSinceLastFormControlChangeEvent
: 1;
201 bool m_wasFocusedByMouse
: 1;
204 inline bool isHTMLFormControlElement(const Element
& element
)
206 return element
.isFormControlElement();
209 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFormControlElement
);
210 DEFINE_TYPE_CASTS(HTMLFormControlElement
, FormAssociatedElement
, control
, control
->isFormControlElement(), control
.isFormControlElement());