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 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 HTMLFormElement_h
25 #define HTMLFormElement_h
27 #include "FormDataBuilder.h"
28 #include "HTMLCollection.h"
29 #include "HTMLElement.h"
31 #include <wtf/OwnPtr.h>
37 class HTMLFormControlElement
;
38 class HTMLImageElement
;
39 class HTMLInputElement
;
40 class HTMLFormCollection
;
43 class HTMLFormElement
: public HTMLElement
{
45 HTMLFormElement(const QualifiedName
&, Document
*);
46 virtual ~HTMLFormElement();
48 virtual HTMLTagStatus
endTagRequirement() const { return TagStatusRequired
; }
49 virtual int tagPriority() const { return 3; }
51 virtual void attach();
52 virtual void insertedIntoDocument();
53 virtual void removedFromDocument();
55 virtual void handleLocalEvents(Event
*, bool useCapture
);
57 PassRefPtr
<HTMLCollection
> elements();
58 void getNamedElements(const AtomicString
&, Vector
<RefPtr
<Node
> >&);
60 unsigned length() const;
61 Node
* item(unsigned index
);
63 String
enctype() const { return m_formDataBuilder
.encodingType(); }
64 void setEnctype(const String
&);
66 String
encoding() const { return m_formDataBuilder
.encodingType(); }
67 void setEncoding(const String
& value
) { setEnctype(value
); }
69 bool autoComplete() const { return m_autocomplete
; }
71 bool autocorrect() const;
72 void setAutocorrect(bool);
74 bool autocapitalize() const;
75 void setAutocapitalize(bool);
77 virtual void parseMappedAttribute(MappedAttribute
*);
79 void registerFormElement(HTMLFormControlElement
*);
80 void removeFormElement(HTMLFormControlElement
*);
81 void registerImgElement(HTMLImageElement
*);
82 void removeImgElement(HTMLImageElement
*);
84 bool prepareSubmit(Event
*);
85 void submit(Event
* = 0, bool activateSubmitButton
= false, bool lockHistory
= false, bool lockBackForwardList
= false);
88 // Used to indicate a malformed state to keep from applying the bottom margin of the form.
89 void setMalformed(bool malformed
) { m_malformed
= malformed
; }
90 bool isMalformed() const { return m_malformed
; }
92 virtual bool isURLAttribute(Attribute
*) const;
94 void submitClick(Event
*);
95 bool formWouldHaveSecureSubmission(const String
& url
);
98 void setName(const String
&);
100 String
acceptCharset() const { return m_formDataBuilder
.acceptCharset(); }
101 void setAcceptCharset(const String
&);
103 String
action() const;
104 void setAction(const String
&);
106 String
method() const;
107 void setMethod(const String
&);
109 virtual String
target() const;
110 void setTarget(const String
&);
112 PassRefPtr
<HTMLFormControlElement
> elementForAlias(const AtomicString
&);
113 void addElementAlias(HTMLFormControlElement
*, const AtomicString
& alias
);
115 // FIXME: Change this to be private after getting rid of all the clients.
116 Vector
<HTMLFormControlElement
*> formElements
;
118 class CheckedRadioButtons
{
120 void addButton(HTMLFormControlElement
*);
121 void removeButton(HTMLFormControlElement
*);
122 HTMLInputElement
* checkedButtonForGroup(const AtomicString
& name
) const;
125 typedef HashMap
<AtomicStringImpl
*, HTMLInputElement
*> NameToInputMap
;
126 OwnPtr
<NameToInputMap
> m_nameToCheckedRadioButtonMap
;
129 CheckedRadioButtons
& checkedRadioButtons() { return m_checkedRadioButtons
; }
131 virtual void documentDidBecomeActive();
134 virtual void willMoveToNewOwnerDocument();
135 virtual void didMoveToNewOwnerDocument();
138 bool isMailtoForm() const;
139 TextEncoding
dataEncoding() const;
140 PassRefPtr
<FormData
> createFormData(const CString
& boundary
);
141 unsigned formElementIndex(HTMLFormControlElement
*);
143 friend class HTMLFormCollection
;
145 typedef HashMap
<RefPtr
<AtomicStringImpl
>, RefPtr
<HTMLFormControlElement
> > AliasMap
;
147 FormDataBuilder m_formDataBuilder
;
148 AliasMap
* m_elementAliases
;
149 HTMLCollection::CollectionInfo
* collectionInfo
;
151 CheckedRadioButtons m_checkedRadioButtons
;
153 Vector
<HTMLImageElement
*> imgElements
;
156 bool m_autocomplete
: 1;
158 bool m_doingsubmit
: 1;
160 bool m_malformed
: 1;
164 } // namespace WebCore
166 #endif // HTMLFormElement_h