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