• 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, 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 HTMLFormElement_h
25  #define HTMLFormElement_h
26  
27  #include "core/html/HTMLElement.h"
28  #include "core/html/HTMLFormControlElement.h"
29  #include "core/html/forms/RadioButtonGroupScope.h"
30  #include "core/loader/FormSubmission.h"
31  #include "wtf/OwnPtr.h"
32  #include "wtf/WeakPtr.h"
33  
34  namespace WTF{
35  class TextEncoding;
36  }
37  
38  namespace blink {
39  
40  class Event;
41  class FormAssociatedElement;
42  class FormData;
43  class GenericEventQueue;
44  class HTMLFormControlElement;
45  class HTMLFormControlsCollection;
46  class HTMLImageElement;
47  class HTMLInputElement;
48  
49  class HTMLFormElement FINAL : public HTMLElement {
50      DEFINE_WRAPPERTYPEINFO();
51  public:
52      static PassRefPtrWillBeRawPtr<HTMLFormElement> create(Document&);
53      virtual ~HTMLFormElement();
54      virtual void trace(Visitor*) OVERRIDE;
55  
56      PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> elements();
57      void getNamedElements(const AtomicString&, WillBeHeapVector<RefPtrWillBeMember<Element> >&);
58  
59      unsigned length() const;
60      HTMLElement* item(unsigned index);
61  
enctype()62      String enctype() const { return m_attributes.encodingType(); }
63      void setEnctype(const AtomicString&);
64  
encoding()65      String encoding() const { return m_attributes.encodingType(); }
setEncoding(const AtomicString & value)66      void setEncoding(const AtomicString& value) { setEnctype(value); }
67  
68      bool shouldAutocomplete() const;
69  
70      void associate(FormAssociatedElement&);
71      void disassociate(FormAssociatedElement&);
72      void associate(HTMLImageElement&);
73      void disassociate(HTMLImageElement&);
74  #if !ENABLE(OILPAN)
75      WeakPtr<HTMLFormElement> createWeakPtr();
76  #endif
77      void didAssociateByParser();
78  
79      void prepareForSubmission(Event*);
80      void submit();
81      void submitFromJavaScript();
82      void reset();
83  
84      void setDemoted(bool);
85  
86      void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger);
87  
88      String name() const;
89  
90      bool noValidate() const;
91  
92      const AtomicString& action() const;
93  
94      String method() const;
95      void setMethod(const AtomicString&);
96  
97      bool wasUserSubmitted() const;
98  
99      HTMLFormControlElement* defaultButton() const;
100  
101      bool checkValidity();
102  
103      enum AutocompleteResult {
104          AutocompleteResultSuccess,
105          AutocompleteResultErrorDisabled,
106          AutocompleteResultErrorCancel,
107          AutocompleteResultErrorInvalid,
108      };
109  
110      void requestAutocomplete();
111      void finishRequestAutocomplete(AutocompleteResult);
112  
113      DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete);
114      DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror);
115  
radioButtonGroupScope()116      RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
117  
118      const FormAssociatedElement::List& associatedElements() const;
119      const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >& imageElements();
120  
121      void anonymousNamedGetter(const AtomicString& name, RefPtrWillBeRawPtr<RadioNodeList>&, RefPtrWillBeRawPtr<Element>&);
122  
123  private:
124      explicit HTMLFormElement(Document&);
125  
126      virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
127      virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
128      virtual void removedFrom(ContainerNode*) OVERRIDE;
129      virtual void finishParsingChildren() OVERRIDE;
130  
131      virtual void handleLocalEvents(Event*) OVERRIDE;
132  
133      virtual void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) OVERRIDE;
134      virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
135      virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
136      virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
137  
shouldRegisterAsNamedItem()138      virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; }
139  
140      virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE;
141  
142      void submitDialog(PassRefPtrWillBeRawPtr<FormSubmission>);
143      void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
144  
145      void scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmission>);
146  
147      void collectAssociatedElements(Node& root, FormAssociatedElement::List&) const;
148      void collectImageElements(Node& root, WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >&);
149  
150      // Returns true if the submission should proceed.
151      bool validateInteractively(Event*);
152  
153      // Validates each of the controls, and stores controls of which 'invalid'
154      // event was not canceled to the specified vector. Returns true if there
155      // are any invalid controls in this form.
156      bool checkInvalidControlsAndCollectUnhandled(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >*);
157  
158      Element* elementFromPastNamesMap(const AtomicString&);
159      void addToPastNamesMap(Element*, const AtomicString& pastName);
160      void removeFromPastNamesMap(HTMLElement&);
161  
162      typedef WillBeHeapHashMap<AtomicString, RawPtrWillBeMember<Element> > PastNamesMap;
163  
164      FormSubmission::Attributes m_attributes;
165      OwnPtrWillBeMember<PastNamesMap> m_pastNamesMap;
166  
167      RadioButtonGroupScope m_radioButtonGroupScope;
168  
169      // Do not access m_associatedElements directly. Use associatedElements() instead.
170      FormAssociatedElement::List m_associatedElements;
171      // Do not access m_imageElements directly. Use imageElements() instead.
172      WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> > m_imageElements;
173  #if !ENABLE(OILPAN)
174      WeakPtrFactory<HTMLFormElement> m_weakPtrFactory;
175  #endif
176      bool m_associatedElementsAreDirty : 1;
177      bool m_imageElementsAreDirty : 1;
178      bool m_hasElementsAssociatedByParser : 1;
179      bool m_didFinishParsingChildren : 1;
180  
181      bool m_wasUserSubmitted : 1;
182      bool m_isSubmittingOrInUserJSSubmitEvent : 1;
183      bool m_shouldSubmit : 1;
184  
185      bool m_isInResetFunction : 1;
186  
187      bool m_wasDemoted : 1;
188  
189      OwnPtrWillBeMember<GenericEventQueue> m_pendingAutocompleteEventsQueue;
190  };
191  
192  } // namespace blink
193  
194  #endif // HTMLFormElement_h
195