Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLFormControlElement.h
1 /*
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.
6  *
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.
11  *
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.
16  *
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.
21  *
22  */
23
24 #ifndef HTMLFormControlElement_h
25 #define HTMLFormControlElement_h
26
27 #include "core/html/FormAssociatedElement.h"
28 #include "core/html/LabelableElement.h"
29
30 namespace WebCore {
31
32 class FormDataList;
33 class HTMLFieldSetElement;
34 class HTMLFormElement;
35 class HTMLLegendElement;
36 class ValidationMessage;
37 class ValidityState;
38
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);
44
45 public:
46     virtual ~HTMLFormControlElement();
47     virtual void trace(Visitor*) OVERRIDE;
48
49     String formEnctype() const;
50     void setFormEnctype(const AtomicString&);
51     String formMethod() const;
52     void setFormMethod(const AtomicString&);
53     bool formNoValidate() const;
54
55     void ancestorDisabledStateWasChanged();
56
57     void reset();
58
59     bool wasChangedSinceLastFormControlChangeEvent() const { return m_wasChangedSinceLastFormControlChangeEvent; }
60     void setChangedSinceLastFormControlChangeEvent(bool);
61
62     virtual void dispatchFormControlChangeEvent();
63     void dispatchChangeEvent();
64     void dispatchFormControlInputEvent();
65
66     virtual HTMLFormElement* formOwner() const OVERRIDE FINAL;
67
68     virtual bool isDisabledFormControl() const OVERRIDE;
69
70     virtual bool isEnumeratable() const OVERRIDE { return false; }
71
72     bool isRequired() const;
73
74     const AtomicString& type() const { return formControlType(); }
75
76     virtual const AtomicString& formControlType() const = 0;
77
78     virtual bool canTriggerImplicitSubmission() const { return false; }
79
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();
84
85     virtual bool canBeSuccessfulSubmitButton() const { return false; }
86     bool isSuccessfulSubmitButton() const;
87     virtual bool isActivatedSubmit() const { return false; }
88     virtual void setActivatedSubmit(bool) { }
89
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;
97
98     bool isReadOnly() const { return m_isReadOnly; }
99     bool isDisabledOrReadOnly() const { return isDisabledFormControl() || m_isReadOnly; }
100
101     bool isAutofocusable() const;
102
103     bool isAutofilled() const { return m_isAutofilled; }
104     void setAutofilled(bool = true);
105
106     static HTMLFormControlElement* enclosingFormControlElement(Node*);
107
108     String nameForAutofill() const;
109
110     virtual void setFocus(bool flag) OVERRIDE;
111
112     using Node::ref;
113     using Node::deref;
114
115 protected:
116     HTMLFormControlElement(const QualifiedName& tagName, Document&, HTMLFormElement*);
117
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;
125
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;
133
134     virtual void didRecalcStyle(StyleRecalcChange) OVERRIDE FINAL;
135
136     // This must be called any time the result of willValidate() has changed.
137     void setNeedsWillValidateCheck();
138     virtual bool recalcWillValidate() const;
139
140     virtual void resetImpl() { }
141     virtual bool supportsAutofocus() const;
142
143 private:
144 #if !ENABLE(OILPAN)
145     virtual void refFormAssociatedElement() OVERRIDE FINAL { ref(); }
146     virtual void derefFormAssociatedElement() OVERRIDE FINAL { deref(); }
147 #endif
148
149     virtual bool isFormControlElement() const OVERRIDE FINAL { return true; }
150     virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE { return true; }
151
152     virtual short tabIndex() const OVERRIDE FINAL;
153
154     virtual bool isDefaultButtonForForm() const OVERRIDE FINAL;
155     virtual bool isValidFormControlElement() OVERRIDE FINAL;
156     void updateAncestorDisabledState() const;
157
158     OwnPtr<ValidationMessage> m_validationMessage;
159     bool m_disabled : 1;
160     bool m_isAutofilled : 1;
161     bool m_isReadOnly : 1;
162     bool m_isRequired : 1;
163
164     enum AncestorDisabledState { AncestorDisabledStateUnknown, AncestorDisabledStateEnabled, AncestorDisabledStateDisabled };
165     mutable AncestorDisabledState m_ancestorDisabledState;
166     enum DataListAncestorState { Unknown, InsideDataList, NotInsideDataList };
167     mutable enum DataListAncestorState m_dataListAncestorState;
168
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;
174
175     // Cache of valid().
176     // But "candidate for constraint validation" doesn't affect m_isValid.
177     bool m_isValid : 1;
178
179     bool m_wasChangedSinceLastFormControlChangeEvent : 1;
180     bool m_wasFocusedByMouse : 1;
181 };
182
183 inline bool isHTMLFormControlElement(const Element& element)
184 {
185     return element.isFormControlElement();
186 }
187
188 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFormControlElement);
189 DEFINE_TYPE_CASTS(HTMLFormControlElement, FormAssociatedElement, control, control->isFormControlElement(), control.isFormControlElement());
190
191 } // namespace
192
193 #endif