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 "FormAssociatedElement.h"
28 #include "LabelableElement.h"
33 class HTMLFormElement;
34 class ValidationMessage;
37 // HTMLFormControlElement is the default implementation of FormAssociatedElement,
38 // and form-associated element implementations should use HTMLFormControlElement
39 // unless there is a special reason.
40 class HTMLFormControlElement : public LabelableElement, public FormAssociatedElement {
42 virtual ~HTMLFormControlElement();
44 HTMLFormElement* form() const { return FormAssociatedElement::form(); }
46 String formEnctype() const;
47 void setFormEnctype(const String&);
48 String formMethod() const;
49 void setFormMethod(const String&);
50 bool formNoValidate() const;
52 virtual void reset() { }
54 virtual bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; }
55 virtual void setFormControlValueMatchesRenderer(bool b) { m_valueMatchesRenderer = b; }
57 virtual bool wasChangedSinceLastFormControlChangeEvent() const;
58 virtual void setChangedSinceLastFormControlChangeEvent(bool);
60 virtual void dispatchFormControlChangeEvent();
61 virtual void dispatchFormControlInputEvent();
63 virtual bool disabled() const { return m_disabled; }
64 void setDisabled(bool);
66 virtual bool isFocusable() const;
67 virtual bool isEnumeratable() const { return false; }
69 // Determines whether or not a control will be automatically focused.
70 virtual bool autofocus() const;
72 bool required() const;
74 const AtomicString& type() const { return formControlType(); }
76 void setName(const AtomicString& name);
78 virtual const AtomicString& formControlName() const OVERRIDE;
79 virtual const AtomicString& formControlType() const OVERRIDE = 0;
80 virtual bool isEnabledFormControl() const { return !disabled(); }
81 virtual bool isReadOnlyFormControl() const { return readOnly(); }
83 virtual bool isRadioButton() const { return false; }
84 virtual bool canTriggerImplicitSubmission() const { return false; }
86 // Override in derived classes to get the encoded name=value pair for submitting.
87 // Return true for a successful control (see HTML4-17.13.2).
88 virtual bool appendFormData(FormDataList&, bool) { return false; }
90 virtual bool isSuccessfulSubmitButton() const { return false; }
91 virtual bool isActivatedSubmit() const { return false; }
92 virtual void setActivatedSubmit(bool) { }
94 virtual bool willValidate() const;
95 String validationMessage();
96 void updateVisibleValidationMessage();
97 void hideVisibleValidationMessage();
98 bool checkValidity(Vector<RefPtr<FormAssociatedElement> >* unhandledInvalidControls = 0);
99 // This must be called when a validation constraint or control value is changed.
100 void setNeedsValidityCheck();
101 void setCustomValidity(const String&);
103 bool readOnly() const { return m_readOnly; }
105 bool hasAutofocused() { return m_hasAutofocused; }
106 void setAutofocused() { m_hasAutofocused = true; }
108 using TreeShared<ContainerNode>::ref;
109 using TreeShared<ContainerNode>::deref;
112 HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*);
114 virtual void parseAttribute(Attribute*) OVERRIDE;
115 virtual void requiredAttributeChanged();
116 virtual void attach();
117 virtual void insertedIntoTree(bool deep);
118 virtual void removedFromTree(bool deep);
119 virtual void insertedIntoDocument();
120 virtual void removedFromDocument();
121 virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
123 virtual bool supportsFocus() const;
124 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
125 virtual bool isMouseFocusable() const;
127 virtual void didRecalcStyle(StyleChange);
129 virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode);
130 virtual void detach();
132 // This must be called any time the result of willValidate() has changed.
133 void setNeedsWillValidateCheck();
134 virtual bool recalcWillValidate() const;
137 virtual void refFormAssociatedElement() { ref(); }
138 virtual void derefFormAssociatedElement() { deref(); }
140 virtual bool isFormControlElement() const { return true; }
142 virtual short tabIndex() const;
144 virtual HTMLFormElement* virtualForm() const;
145 virtual bool isDefaultButtonForForm() const;
146 virtual bool isValidFormControlElement();
147 String visibleValidationMessage() const;
149 OwnPtr<ValidationMessage> m_validationMessage;
153 bool m_valueMatchesRenderer : 1;
155 // The initial value of m_willValidate depends on the derived class. We can't
156 // initialize it with a virtual function in the constructor. m_willValidate
157 // is not deterministic as long as m_willValidateInitialized is false.
158 mutable bool m_willValidateInitialized: 1;
159 mutable bool m_willValidate : 1;
161 // Cache of validity()->valid().
162 // But "candidate for constraint validation" doesn't affect m_isValid.
165 bool m_wasChangedSinceLastFormControlChangeEvent : 1;
167 bool m_hasAutofocused : 1;