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 WebCore { 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 public: 51 static PassRefPtrWillBeRawPtr<HTMLFormElement> create(Document&); 52 virtual ~HTMLFormElement(); 53 virtual void trace(Visitor*) OVERRIDE; 54 55 PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> elements(); 56 void getNamedElements(const AtomicString&, WillBeHeapVector<RefPtrWillBeMember<Element> >&); 57 58 unsigned length() const; 59 Element* item(unsigned index); 60 enctype()61 String enctype() const { return m_attributes.encodingType(); } 62 void setEnctype(const AtomicString&); 63 encoding()64 String encoding() const { return m_attributes.encodingType(); } setEncoding(const AtomicString & value)65 void setEncoding(const AtomicString& value) { setEnctype(value); } 66 67 bool shouldAutocomplete() const; 68 69 void associate(FormAssociatedElement&); 70 void disassociate(FormAssociatedElement&); 71 void associate(HTMLImageElement&); 72 void disassociate(HTMLImageElement&); 73 #if !ENABLE(OILPAN) 74 WeakPtr<HTMLFormElement> createWeakPtr(); 75 #endif 76 void didAssociateByParser(); 77 78 void prepareForSubmission(Event*); 79 void submit(); 80 void submitFromJavaScript(); 81 void reset(); 82 83 void setDemoted(bool); 84 85 void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger); 86 87 String name() const; 88 89 bool noValidate() const; 90 91 const AtomicString& action() const; 92 93 String method() const; 94 void setMethod(const AtomicString&); 95 96 bool wasUserSubmitted() const; 97 98 HTMLFormControlElement* defaultButton() const; 99 100 bool checkValidity(); 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 radioButtonGroupScope()115 RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; } 116 117 const FormAssociatedElement::List& associatedElements() const; 118 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >& imageElements(); 119 120 void anonymousNamedGetter(const AtomicString& name, bool&, RefPtrWillBeRawPtr<RadioNodeList>&, bool&, RefPtrWillBeRawPtr<Element>&); 121 122 private: 123 explicit HTMLFormElement(Document&); 124 125 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE; 126 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 127 virtual void removedFrom(ContainerNode*) OVERRIDE; 128 virtual void finishParsingChildren() OVERRIDE; 129 130 virtual void handleLocalEvents(Event*) OVERRIDE; 131 132 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 133 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; 134 virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE; 135 shouldRegisterAsNamedItem()136 virtual bool shouldRegisterAsNamedItem() const OVERRIDE { return true; } 137 138 virtual void copyNonAttributePropertiesFromElement(const Element&) OVERRIDE; 139 140 void submitDialog(PassRefPtrWillBeRawPtr<FormSubmission>); 141 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger); 142 143 void scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmission>); 144 145 void collectAssociatedElements(Node& root, FormAssociatedElement::List&) const; 146 void collectImageElements(Node& root, WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >&); 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(WillBeHeapVector<RefPtrWillBeMember<FormAssociatedElement> >*); 155 156 Element* elementFromPastNamesMap(const AtomicString&); 157 void addToPastNamesMap(Element*, const AtomicString& pastName); 158 void removeFromPastNamesMap(HTMLElement&); 159 160 typedef WillBeHeapHashMap<AtomicString, RawPtrWillBeMember<Element> > PastNamesMap; 161 162 FormSubmission::Attributes m_attributes; 163 OwnPtrWillBeMember<PastNamesMap> m_pastNamesMap; 164 165 RadioButtonGroupScope m_radioButtonGroupScope; 166 167 // Do not access m_associatedElements directly. Use associatedElements() instead. 168 FormAssociatedElement::List m_associatedElements; 169 // Do not access m_imageElements directly. Use imageElements() instead. 170 WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> > m_imageElements; 171 #if !ENABLE(OILPAN) 172 WeakPtrFactory<HTMLFormElement> m_weakPtrFactory; 173 #endif 174 bool m_associatedElementsAreDirty; 175 bool m_imageElementsAreDirty; 176 bool m_hasElementsAssociatedByParser; 177 bool m_didFinishParsingChildren; 178 179 bool m_wasUserSubmitted; 180 bool m_isSubmittingOrInUserJSSubmitEvent; 181 bool m_shouldSubmit; 182 183 bool m_isInResetFunction; 184 185 bool m_wasDemoted; 186 187 OwnPtrWillBeMember<GenericEventQueue> m_pendingAutocompleteEventsQueue; 188 }; 189 190 } // namespace WebCore 191 192 #endif // HTMLFormElement_h 193