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