• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 HTMLFormElement_h
25 #define HTMLFormElement_h
26 
27 #include "CheckedRadioButtons.h"
28 #include "FormDataBuilder.h"
29 #include "HTMLElement.h"
30 #include <wtf/OwnPtr.h>
31 
32 namespace WebCore {
33 
34 class Event;
35 class FormData;
36 class HTMLFormControlElement;
37 class HTMLImageElement;
38 class HTMLInputElement;
39 class HTMLFormCollection;
40 class TextEncoding;
41 
42 struct CollectionCache;
43 
44 class HTMLFormElement : public HTMLElement {
45 public:
46     HTMLFormElement(const QualifiedName&, Document*);
47     virtual ~HTMLFormElement();
48 
endTagRequirement()49     virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; }
tagPriority()50     virtual int tagPriority() const { return 3; }
51 
52     virtual void attach();
53     virtual bool rendererIsNeeded(RenderStyle*);
54     virtual void insertedIntoDocument();
55     virtual void removedFromDocument();
56 
57     virtual void handleLocalEvents(Event*, bool useCapture);
58 
59     PassRefPtr<HTMLCollection> elements();
60     void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&);
61 
62     unsigned length() const;
63     Node* item(unsigned index);
64 
enctype()65     String enctype() const { return m_formDataBuilder.encodingType(); }
66     void setEnctype(const String&);
67 
encoding()68     String encoding() const { return m_formDataBuilder.encodingType(); }
setEncoding(const String & value)69     void setEncoding(const String& value) { setEnctype(value); }
70 
autoComplete()71     bool autoComplete() const { return m_autocomplete; }
72 
73     virtual void parseMappedAttribute(MappedAttribute*);
74 
75     void registerFormElement(HTMLFormControlElement*);
76     void removeFormElement(HTMLFormControlElement*);
77     void registerImgElement(HTMLImageElement*);
78     void removeImgElement(HTMLImageElement*);
79 
80     bool prepareSubmit(Event*);
81     void submit(Event* = 0, bool activateSubmitButton = false, bool lockHistory = false);
82     void reset();
83 
84     // Used to indicate a malformed state to keep from applying the bottom margin of the form.
setMalformed(bool malformed)85     void setMalformed(bool malformed) { m_malformed = malformed; }
isMalformed()86     bool isMalformed() const { return m_malformed; }
87 
setDemoted(bool demoted)88     void setDemoted(bool demoted) { m_demoted = demoted; }
isDemoted()89     bool isDemoted() const { return m_demoted; }
90 
91     virtual bool isURLAttribute(Attribute*) const;
92 
93     void submitClick(Event*);
94     bool formWouldHaveSecureSubmission(const String& url);
95 
96     String name() const;
97     void setName(const String&);
98 
acceptCharset()99     String acceptCharset() const { return m_formDataBuilder.acceptCharset(); }
100     void setAcceptCharset(const String&);
101 
102     String action() const;
103     void setAction(const String&);
104 
105     String method() const;
106     void setMethod(const String&);
107 
108     virtual String target() const;
109     void setTarget(const String&);
110 
111     PassRefPtr<HTMLFormControlElement> elementForAlias(const AtomicString&);
112     void addElementAlias(HTMLFormControlElement*, const AtomicString& alias);
113 
114     // FIXME: Change this to be private after getting rid of all the clients.
115     Vector<HTMLFormControlElement*> formElements;
116 
checkedRadioButtons()117     CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; }
118 
119     virtual void documentDidBecomeActive();
120 
121 protected:
122     virtual void willMoveToNewOwnerDocument();
123     virtual void didMoveToNewOwnerDocument();
124 
125 private:
126     bool isMailtoForm() const;
127     TextEncoding dataEncoding() const;
128     PassRefPtr<FormData> createFormData(const CString& boundary);
129     unsigned formElementIndex(HTMLFormControlElement*);
130 
131     friend class HTMLFormCollection;
132 
133     typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap;
134 
135     FormDataBuilder m_formDataBuilder;
136     AliasMap* m_elementAliases;
137     CollectionCache* collectionInfo;
138 
139     CheckedRadioButtons m_checkedRadioButtons;
140 
141     Vector<HTMLImageElement*> imgElements;
142     String m_url;
143     String m_target;
144     bool m_autocomplete : 1;
145     bool m_insubmit : 1;
146     bool m_doingsubmit : 1;
147     bool m_inreset : 1;
148     bool m_malformed : 1;
149     bool m_demoted : 1;
150     AtomicString m_name;
151 };
152 
153 } // namespace WebCore
154 
155 #endif // HTMLFormElement_h
156