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/CheckedRadioButtons.h" 30 #include "core/loader/FormState.h" 31 #include "core/loader/FormSubmission.h" 32 #include "wtf/OwnPtr.h" 33 34 namespace WTF{ 35 class TextEncoding; 36 } 37 38 namespace WebCore { 39 40 class Event; 41 class FormAssociatedElement; 42 class FormData; 43 class HTMLFormControlElement; 44 class HTMLImageElement; 45 class HTMLInputElement; 46 47 class HTMLFormElement FINAL : public HTMLElement { 48 public: 49 static PassRefPtr<HTMLFormElement> create(Document&); 50 virtual ~HTMLFormElement(); 51 52 PassRefPtr<HTMLCollection> elements(); 53 void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&); 54 55 unsigned length() const; 56 Node* item(unsigned index); 57 enctype()58 String enctype() const { return m_attributes.encodingType(); } 59 void setEnctype(const AtomicString&); 60 encoding()61 String encoding() const { return m_attributes.encodingType(); } setEncoding(const AtomicString & value)62 void setEncoding(const AtomicString& value) { setEnctype(value); } 63 64 bool shouldAutocomplete() const; 65 66 // FIXME: Should rename these two functions to say "form control" or "form-associated element" instead of "form element". 67 void registerFormElement(FormAssociatedElement&); 68 void removeFormElement(FormAssociatedElement*); 69 70 void registerImgElement(HTMLImageElement*); 71 void removeImgElement(HTMLImageElement*); 72 73 bool prepareForSubmission(Event*); 74 void submit(); 75 void submitFromJavaScript(); 76 void reset(); 77 78 void setDemoted(bool); 79 80 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger); 81 bool formWouldHaveSecureSubmission(const String& url); 82 83 String name() const; 84 85 bool noValidate() const; 86 87 const AtomicString& action() const; 88 void setAction(const AtomicString&); 89 90 String method() const; 91 void setMethod(const AtomicString&); 92 93 virtual String target() const; 94 95 bool wasUserSubmitted() const; 96 97 HTMLFormControlElement* defaultButton() const; 98 99 bool checkValidity(); 100 bool checkValidityWithoutDispatchingEvents(); 101 102 enum AutocompleteResult { 103 AutocompleteResultSuccess, 104 AutocompleteResultErrorDisabled, 105 AutocompleteResultErrorCancel, 106 AutocompleteResultErrorInvalid, 107 }; 108 109 void requestAutocomplete(); 110 void finishRequestAutocomplete(AutocompleteResult); 111 112 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocomplete); 113 DEFINE_ATTRIBUTE_EVENT_LISTENER(autocompleteerror); 114 checkedRadioButtons()115 CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } 116 associatedElements()117 const Vector<FormAssociatedElement*>& associatedElements() const { return m_associatedElements; } imageElements()118 const Vector<HTMLImageElement*>& imageElements() const { return m_imageElements; } 119 120 void getTextFieldValues(StringPairVector& fieldNamesAndValues) const; 121 void anonymousNamedGetter(const AtomicString& name, bool&, RefPtr<NodeList>&, bool&, RefPtr<Node>&); 122 123 private: 124 explicit HTMLFormElement(Document&); 125 126 virtual bool rendererIsNeeded(const RenderStyle&); 127 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 128 virtual void removedFrom(ContainerNode*) OVERRIDE; 129 virtual void finishParsingChildren() OVERRIDE; 130 131 virtual void handleLocalEvents(Event*); 132 133 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 134 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; 135 shouldRegisterAsNamedItem()136 virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; } 137 138 virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE; 139 140 void submitDialog(PassRefPtr<FormSubmission>); 141 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger); 142 143 void scheduleFormSubmission(PassRefPtr<FormSubmission>); 144 145 unsigned formElementIndexWithFormAttribute(Element*, unsigned rangeStart, unsigned rangeEnd); 146 unsigned formElementIndex(FormAssociatedElement&); 147 148 // Returns true if the submission should proceed. 149 bool validateInteractively(Event*); 150 151 // Validates each of the controls, and stores controls of which 'invalid' 152 // event was not canceled to the specified vector. Returns true if there 153 // are any invalid controls in this form. 154 bool checkInvalidControlsAndCollectUnhandled(Vector<RefPtr<FormAssociatedElement> >*, HTMLFormControlElement::CheckValidityDispatchEvents = HTMLFormControlElement::CheckValidityDispatchEventsAllowed); 155 156 Node* elementFromPastNamesMap(const AtomicString&) const; 157 void addToPastNamesMap(Node*, const AtomicString& pastName); 158 void removeFromPastNamesMap(HTMLElement&); 159 160 typedef HashMap<AtomicString, Node*> PastNamesMap; 161 162 FormSubmission::Attributes m_attributes; 163 OwnPtr<PastNamesMap> m_pastNamesMap; 164 165 CheckedRadioButtons m_checkedRadioButtons; 166 167 unsigned m_associatedElementsBeforeIndex; 168 unsigned m_associatedElementsAfterIndex; 169 Vector<FormAssociatedElement*> m_associatedElements; 170 Vector<HTMLImageElement*> m_imageElements; 171 172 bool m_wasUserSubmitted; 173 bool m_isSubmittingOrPreparingForSubmission; 174 bool m_shouldSubmit; 175 176 bool m_isInResetFunction; 177 178 bool m_wasDemoted; 179 180 void requestAutocompleteTimerFired(Timer<HTMLFormElement>*); 181 182 Vector<RefPtr<Event> > m_pendingAutocompleteEvents; 183 Timer<HTMLFormElement> m_requestAutocompleteTimer; 184 }; 185 186 DEFINE_NODE_TYPE_CASTS(HTMLFormElement, hasTagName(HTMLNames::formTag)); 187 188 } // namespace WebCore 189 190 #endif // HTMLFormElement_h 191