| 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 | #pragma once |
| 25 | |
| 26 | #include "FormNamedItem.h" |
| 27 | #include "Node.h" |
| 28 | #include <wtf/WeakPtr.h> |
| 29 | #include <wtf/text/WTFString.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | class ContainerNode; |
| 34 | class DOMFormData; |
| 35 | class Document; |
| 36 | class FormAttributeTargetObserver; |
| 37 | class HTMLElement; |
| 38 | class HTMLFormElement; |
| 39 | class ValidityState; |
| 40 | |
| 41 | class FormAssociatedElement : public FormNamedItem { |
| 42 | WTF_MAKE_NONCOPYABLE(FormAssociatedElement); |
| 43 | WTF_MAKE_FAST_ALLOCATED; |
| 44 | public: |
| 45 | virtual ~FormAssociatedElement(); |
| 46 | |
| 47 | void ref() { refFormAssociatedElement(); } |
| 48 | void deref() { derefFormAssociatedElement(); } |
| 49 | |
| 50 | static HTMLFormElement* findAssociatedForm(const HTMLElement*, HTMLFormElement*); |
| 51 | HTMLFormElement* form() const { return m_form.get(); } |
| 52 | ValidityState* validity(); |
| 53 | |
| 54 | virtual bool isFormControlElement() const = 0; |
| 55 | virtual bool isFormControlElementWithState() const; |
| 56 | virtual bool isEnumeratable() const = 0; |
| 57 | |
| 58 | // Returns the 'name' attribute value. If this element has no name |
| 59 | // attribute, it returns an empty string instead of null string. |
| 60 | // Note that the 'name' IDL attribute doesn't use this function. |
| 61 | virtual const AtomicString& name() const; |
| 62 | |
| 63 | // Override in derived classes to get the encoded name=value pair for submitting. |
| 64 | // Return true for a successful control (see HTML4-17.13.2). |
| 65 | virtual bool appendFormData(DOMFormData&, bool) { return false; } |
| 66 | |
| 67 | void formWillBeDestroyed(); |
| 68 | |
| 69 | void resetFormOwner(); |
| 70 | |
| 71 | void formOwnerRemovedFromTree(const Node&); |
| 72 | |
| 73 | // ValidityState attribute implementations |
| 74 | bool badInput() const { return hasBadInput(); } |
| 75 | bool customError() const; |
| 76 | |
| 77 | // Implementations of patternMismatch, rangeOverflow, rangerUnderflow, stepMismatch, tooShort, tooLong and valueMissing must call willValidate. |
| 78 | virtual bool hasBadInput() const; |
| 79 | virtual bool patternMismatch() const; |
| 80 | virtual bool rangeOverflow() const; |
| 81 | virtual bool rangeUnderflow() const; |
| 82 | virtual bool stepMismatch() const; |
| 83 | virtual bool tooShort() const; |
| 84 | virtual bool tooLong() const; |
| 85 | virtual bool typeMismatch() const; |
| 86 | virtual bool valueMissing() const; |
| 87 | virtual String validationMessage() const; |
| 88 | virtual bool isValid() const; |
| 89 | virtual void setCustomValidity(const String&); |
| 90 | |
| 91 | void formAttributeTargetChanged(); |
| 92 | |
| 93 | protected: |
| 94 | FormAssociatedElement(HTMLFormElement*); |
| 95 | |
| 96 | void insertedIntoAncestor(Node::InsertionType, ContainerNode&); |
| 97 | void removedFromAncestor(Node::RemovalType, ContainerNode&); |
| 98 | void didMoveToNewDocument(Document& oldDocument); |
| 99 | |
| 100 | void setForm(HTMLFormElement*); |
| 101 | void formAttributeChanged(); |
| 102 | |
| 103 | // If you add an override of willChangeForm() or didChangeForm() to a class |
| 104 | // derived from this one, you will need to add a call to setForm(0) to the |
| 105 | // destructor of that class. |
| 106 | virtual void willChangeForm(); |
| 107 | virtual void didChangeForm(); |
| 108 | |
| 109 | String customValidationMessage() const; |
| 110 | |
| 111 | private: |
| 112 | virtual bool willValidate() const = 0; |
| 113 | virtual void refFormAssociatedElement() = 0; |
| 114 | virtual void derefFormAssociatedElement() = 0; |
| 115 | |
| 116 | void resetFormAttributeTargetObserver(); |
| 117 | |
| 118 | bool isFormAssociatedElement() const final { return true; } |
| 119 | |
| 120 | std::unique_ptr<FormAttributeTargetObserver> m_formAttributeTargetObserver; |
| 121 | WeakPtr<HTMLFormElement> m_form; |
| 122 | WeakPtr<HTMLFormElement> m_formSetByParser; |
| 123 | String m_customValidationMessage; |
| 124 | }; |
| 125 | |
| 126 | } // namespace |
| 127 | |