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"
33 class HTMLFormElement
;
34 class ValidationMessageClient
;
36 enum CheckValidityEventBehavior
{ CheckValidityDispatchNoEvent
, CheckValidityDispatchInvalidEvent
};
38 // HTMLFormControlElement is the default implementation of FormAssociatedElement,
39 // and form-associated element implementations should use HTMLFormControlElement
40 // unless there is a special reason.
41 class CORE_EXPORT HTMLFormControlElement
: public LabelableElement
, public FormAssociatedElement
{
42 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLFormControlElement
);
45 ~HTMLFormControlElement() override
;
46 DECLARE_VIRTUAL_TRACE();
48 String
formAction() const;
49 void setFormAction(const AtomicString
&);
50 String
formEnctype() const;
51 void setFormEnctype(const AtomicString
&);
52 String
formMethod() const;
53 void setFormMethod(const AtomicString
&);
54 bool formNoValidate() const;
56 void ancestorDisabledStateWasChanged();
60 bool wasChangedSinceLastFormControlChangeEvent() const { return m_wasChangedSinceLastFormControlChangeEvent
; }
61 void setChangedSinceLastFormControlChangeEvent(bool);
63 virtual void dispatchFormControlChangeEvent();
64 void dispatchChangeEvent();
65 void dispatchFormControlInputEvent();
67 HTMLFormElement
* formOwner() const final
;
69 bool isDisabledFormControl() const override
;
71 bool isEnumeratable() const override
{ return false; }
73 bool isRequired() const;
75 const AtomicString
& type() const { return formControlType(); }
77 virtual const AtomicString
& formControlType() const = 0;
79 virtual bool canTriggerImplicitSubmission() const { return false; }
81 virtual bool isSubmittableElement() { return true; }
83 virtual String
resultForDialogSubmit();
85 virtual bool canBeSuccessfulSubmitButton() const { return false; }
86 bool isSuccessfulSubmitButton() const;
87 virtual bool isActivatedSubmit() const { return false; }
88 virtual void setActivatedSubmit(bool) { }
90 bool willValidate() const override
;
92 void updateVisibleValidationMessage();
93 void hideVisibleValidationMessage();
94 bool checkValidity(WillBeHeapVector
<RefPtrWillBeMember
<HTMLFormControlElement
>>* unhandledInvalidControls
= 0, CheckValidityEventBehavior
= CheckValidityDispatchInvalidEvent
);
95 bool reportValidity();
96 // This must be called only after the caller check the element is focusable.
97 void showValidationMessage();
98 // This must be called when a validation constraint or control value is changed.
99 void setNeedsValidityCheck();
100 void setCustomValidity(const String
&) final
;
101 void findCustomValidationMessageTextDirection(const String
& message
, TextDirection
&messageDir
, String
& subMessage
, TextDirection
& subMessageDir
);
103 bool isReadOnly() const { return m_isReadOnly
; }
104 bool isDisabledOrReadOnly() const { return isDisabledFormControl() || m_isReadOnly
; }
106 bool isAutofocusable() const;
108 bool isAutofilled() const { return m_isAutofilled
; }
109 void setAutofilled(bool = true);
111 static HTMLFormControlElement
* enclosingFormControlElement(Node
*);
113 String
nameForAutofill() const;
115 void setFocus(bool flag
) override
;
116 void copyNonAttributePropertiesFromElement(const Element
&) override
;
124 HTMLFormControlElement(const QualifiedName
& tagName
, Document
&, HTMLFormElement
*);
126 void parseAttribute(const QualifiedName
&, const AtomicString
&) override
;
127 virtual void requiredAttributeChanged();
128 virtual void disabledAttributeChanged();
129 void attach(const AttachContext
& = AttachContext()) override
;
130 InsertionNotificationRequest
insertedInto(ContainerNode
*) override
;
131 void removedFrom(ContainerNode
*) override
;
132 void willChangeForm() override
;
133 void didChangeForm() override
;
134 void didMoveToNewDocument(Document
& oldDocument
) override
;
136 bool supportsFocus() const override
;
137 bool isKeyboardFocusable() const override
;
138 virtual bool shouldShowFocusRingOnMouseFocus() const;
139 bool shouldHaveFocusAppearance() const final
;
140 void dispatchBlurEvent(Element
* newFocusedElement
, WebFocusType
, InputDeviceCapabilities
* sourceCapabilities
) override
;
141 void dispatchFocusEvent(Element
* oldFocusedElement
, WebFocusType
, InputDeviceCapabilities
* sourceCapabilities
) override
;
142 void willCallDefaultEventHandler(const Event
&) final
;
144 void didRecalcStyle(StyleRecalcChange
) override
;
146 // This must be called any time the result of willValidate() has changed.
147 void setNeedsWillValidateCheck();
148 virtual bool recalcWillValidate() const;
150 virtual void resetImpl() { }
151 virtual bool supportsAutofocus() const;
155 void refFormAssociatedElement() final
{ ref(); }
156 void derefFormAssociatedElement() final
{ deref(); }
159 bool isFormControlElement() const final
{ return true; }
160 bool alwaysCreateUserAgentShadowRoot() const override
{ return true; }
162 short tabIndex() const final
;
164 bool isDefaultButtonForForm() const final
;
165 bool isValidElement() override
;
166 bool matchesValidityPseudoClasses() const override
;
167 void updateAncestorDisabledState() const;
169 bool isValidationMessageVisible() const;
170 ValidationMessageClient
* validationMessageClient() const;
172 // Requests validity recalc for the form owner, if one exists.
173 void formOwnerSetNeedsValidityCheck();
174 // Requests validity recalc for all ancestor fieldsets, if exist.
175 void fieldSetAncestorsSetNeedsValidityCheck(Node
*);
178 bool m_isAutofilled
: 1;
179 bool m_isReadOnly
: 1;
180 bool m_isRequired
: 1;
181 bool m_hasValidationMessage
: 1;
183 enum AncestorDisabledState
{ AncestorDisabledStateUnknown
, AncestorDisabledStateEnabled
, AncestorDisabledStateDisabled
};
184 mutable AncestorDisabledState m_ancestorDisabledState
;
185 enum DataListAncestorState
{ Unknown
, InsideDataList
, NotInsideDataList
};
186 mutable enum DataListAncestorState m_dataListAncestorState
;
188 // The initial value of m_willValidate depends on the derived class. We can't
189 // initialize it with a virtual function in the constructor. m_willValidate
190 // is not deterministic as long as m_willValidateInitialized is false.
191 mutable bool m_willValidateInitialized
: 1;
192 mutable bool m_willValidate
: 1;
196 bool m_validityIsDirty
: 1;
198 bool m_wasChangedSinceLastFormControlChangeEvent
: 1;
199 bool m_wasFocusedByMouse
: 1;
202 inline bool isHTMLFormControlElement(const Element
& element
)
204 return element
.isFormControlElement();
207 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFormControlElement
);
208 DEFINE_TYPE_CASTS(HTMLFormControlElement
, FormAssociatedElement
, control
, control
->isFormControlElement(), control
.isFormControlElement());