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/html/FormAssociatedElement.h"
28 #include "core/html/LabelableElement.h"
33 class HTMLFieldSetElement;
34 class HTMLFormElement;
35 class HTMLLegendElement;
36 class ValidationMessage;
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 HTMLFormControlElement : public LabelableElement, public FormAssociatedElement {
43 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLFormControlElement);
46 virtual ~HTMLFormControlElement();
47 virtual void trace(Visitor*) OVERRIDE;
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 virtual HTMLFormElement* formOwner() const OVERRIDE FINAL;
68 virtual bool isDisabledFormControl() const OVERRIDE;
70 virtual 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 // Override in derived classes to get the encoded name=value pair for submitting.
81 // Return true for a successful control (see HTML4-17.13.2).
82 virtual bool appendFormData(FormDataList&, bool) OVERRIDE { return false; }
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 virtual bool willValidate() const OVERRIDE;
91 void updateVisibleValidationMessage();
92 void hideVisibleValidationMessage();
93 bool checkValidity(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >* unhandledInvalidControls = 0);
94 // This must be called when a validation constraint or control value is changed.
95 void setNeedsValidityCheck();
96 virtual void setCustomValidity(const String&) OVERRIDE FINAL;
98 bool isReadOnly() const { return m_isReadOnly; }
99 bool isDisabledOrReadOnly() const { return isDisabledFormControl() || m_isReadOnly; }
101 bool isAutofocusable() const;
103 bool isAutofilled() const { return m_isAutofilled; }
104 void setAutofilled(bool = true);
106 static HTMLFormControlElement* enclosingFormControlElement(Node*);
108 String nameForAutofill() const;
110 virtual void setFocus(bool flag) OVERRIDE;
116 HTMLFormControlElement(const QualifiedName& tagName, Document&, HTMLFormElement*);
118 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
119 virtual void requiredAttributeChanged();
120 virtual void disabledAttributeChanged();
121 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
122 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
123 virtual void removedFrom(ContainerNode*) OVERRIDE;
124 virtual void didMoveToNewDocument(Document& oldDocument) OVERRIDE;
126 virtual bool supportsFocus() const OVERRIDE;
127 virtual bool isKeyboardFocusable() const OVERRIDE;
128 virtual bool shouldShowFocusRingOnMouseFocus() const;
129 virtual bool shouldHaveFocusAppearance() const OVERRIDE FINAL;
130 virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusType) OVERRIDE;
131 virtual void dispatchBlurEvent(Element* newFocusedElement) OVERRIDE;
132 virtual void willCallDefaultEventHandler(const Event&) OVERRIDE FINAL;
134 virtual void didRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
136 // This must be called any time the result of willValidate() has changed.
137 void setNeedsWillValidateCheck();
138 virtual bool recalcWillValidate() const;
140 virtual void resetImpl() { }
141 virtual bool supportsAutofocus() const;
145 virtual void refFormAssociatedElement() OVERRIDE FINAL { ref(); }
146 virtual void derefFormAssociatedElement() OVERRIDE FINAL { deref(); }
149 virtual bool isFormControlElement() const OVERRIDE FINAL { return true; }
150 virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE { return true; }
152 virtual short tabIndex() const OVERRIDE FINAL;
154 virtual bool isDefaultButtonForForm() const OVERRIDE FINAL;
155 virtual bool isValidFormControlElement() OVERRIDE FINAL;
156 void updateAncestorDisabledState() const;
158 OwnPtr<ValidationMessage> m_validationMessage;
160 bool m_isAutofilled : 1;
161 bool m_isReadOnly : 1;
162 bool m_isRequired : 1;
164 enum AncestorDisabledState { AncestorDisabledStateUnknown, AncestorDisabledStateEnabled, AncestorDisabledStateDisabled };
165 mutable AncestorDisabledState m_ancestorDisabledState;
166 enum DataListAncestorState { Unknown, InsideDataList, NotInsideDataList };
167 mutable enum DataListAncestorState m_dataListAncestorState;
169 // The initial value of m_willValidate depends on the derived class. We can't
170 // initialize it with a virtual function in the constructor. m_willValidate
171 // is not deterministic as long as m_willValidateInitialized is false.
172 mutable bool m_willValidateInitialized: 1;
173 mutable bool m_willValidate : 1;
176 // But "candidate for constraint validation" doesn't affect m_isValid.
179 bool m_wasChangedSinceLastFormControlChangeEvent : 1;
180 bool m_wasFocusedByMouse : 1;
183 inline bool isHTMLFormControlElement(const Element& element)
185 return element.isFormControlElement();
188 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFormControlElement);
189 DEFINE_TYPE_CASTS(HTMLFormControlElement, FormAssociatedElement, control, control->isFormControlElement(), control.isFormControlElement());