dc9e83c9d921944713e0ff6b0239184587f32d44
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / FormAssociatedElement.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 FormAssociatedElement_h
25 #define FormAssociatedElement_h
26
27 #include "platform/heap/Handle.h"
28 #include "wtf/WeakPtr.h"
29 #include "wtf/text/WTFString.h"
30
31 namespace blink {
32
33 class ContainerNode;
34 class Document;
35 class FormAttributeTargetObserver;
36 class FormDataList;
37 class HTMLElement;
38 class HTMLFormElement;
39 class Node;
40 class ValidityState;
41 class VisibleSelection;
42
43 class FormAssociatedElement : public WillBeGarbageCollectedMixin {
44 public:
45     virtual ~FormAssociatedElement();
46
47 #if !ENABLE(OILPAN)
48     void ref() { refFormAssociatedElement(); }
49     void deref() { derefFormAssociatedElement(); }
50 #endif
51
52     static HTMLFormElement* findAssociatedForm(const HTMLElement*);
53     HTMLFormElement* form() const { return m_form.get(); }
54     ValidityState* validity();
55
56     virtual bool isFormControlElement() const = 0;
57     virtual bool isFormControlElementWithState() const;
58     virtual bool isEnumeratable() const = 0;
59
60     // Returns the 'name' attribute value. If this element has no name
61     // attribute, it returns an empty string instead of null string.
62     // Note that the 'name' IDL attribute doesn't use this function.
63     virtual const AtomicString& name() const;
64
65     // Override in derived classes to get the encoded name=value pair for submitting.
66     // Return true for a successful control (see HTML4-17.13.2).
67     virtual bool appendFormData(FormDataList&, bool) { return false; }
68
69     void resetFormOwner();
70
71     void formRemovedFromTree(const Node& formRoot);
72
73     // ValidityState attribute implementations
74     bool customError() const;
75
76     // Override functions for patterMismatch, rangeOverflow, rangerUnderflow,
77     // stepMismatch, tooLong and valueMissing must call willValidate method.
78     virtual bool hasBadInput() const;
79     virtual bool patternMismatch() const;
80     virtual bool rangeOverflow() const;
81     virtual bool rangeUnderflow() const;
82     virtual bool stepMismatch() const;
83     virtual bool tooLong() const;
84     virtual bool typeMismatch() const;
85     virtual bool valueMissing() const;
86     virtual String validationMessage() const;
87     bool valid() const;
88     virtual void setCustomValidity(const String&);
89
90     void formAttributeTargetChanged();
91
92     typedef WillBeHeapVector<RawPtrWillBeMember<FormAssociatedElement> > List;
93
94 protected:
95     FormAssociatedElement();
96
97     virtual void trace(Visitor*);
98     void insertedInto(ContainerNode*);
99     void removedFrom(ContainerNode*);
100     void didMoveToNewDocument(Document& oldDocument);
101
102     // FIXME: Remove usage of setForm. resetFormOwner should be enough, and
103     // setForm is confusing.
104     void setForm(HTMLFormElement*);
105     void associateByParser(HTMLFormElement*);
106     void formAttributeChanged();
107
108     // If you add an override of willChangeForm() or didChangeForm() to a class
109     // derived from this one, you will need to add a call to setForm(0) to the
110     // destructor of that class.
111     virtual void willChangeForm();
112     virtual void didChangeForm();
113
114     String customValidationMessage() const;
115
116 private:
117 #if !ENABLE(OILPAN)
118     virtual void refFormAssociatedElement() = 0;
119     virtual void derefFormAssociatedElement() = 0;
120 #endif
121
122     void setFormAttributeTargetObserver(PassOwnPtrWillBeRawPtr<FormAttributeTargetObserver>);
123     void resetFormAttributeTargetObserver();
124
125     OwnPtrWillBeMember<FormAttributeTargetObserver> m_formAttributeTargetObserver;
126 #if ENABLE(OILPAN)
127     Member<HTMLFormElement> m_form;
128 #else
129     WeakPtr<HTMLFormElement> m_form;
130 #endif
131     OwnPtrWillBeMember<ValidityState> m_validityState;
132     String m_customValidationMessage;
133     bool m_formWasSetByParser;
134 };
135
136 HTMLElement* toHTMLElement(FormAssociatedElement*);
137 HTMLElement& toHTMLElement(FormAssociatedElement&);
138 const HTMLElement* toHTMLElement(const FormAssociatedElement*);
139 const HTMLElement& toHTMLElement(const FormAssociatedElement&);
140
141 } // namespace
142
143 #endif // FormAssociatedElement_h