Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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 FormAssociatedElement_h |
| 25 | #define FormAssociatedElement_h |
| 26 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 27 | #include "wtf/WeakPtr.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 28 | #include "wtf/text/WTFString.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class ContainerNode; |
| 33 | class Document; |
| 34 | class FormAttributeTargetObserver; |
| 35 | class FormDataList; |
| 36 | class HTMLElement; |
| 37 | class HTMLFormElement; |
| 38 | class Node; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 39 | class ValidationMessage; |
| 40 | class ValidityState; |
| 41 | class VisibleSelection; |
| 42 | |
| 43 | class FormAssociatedElement { |
| 44 | public: |
| 45 | virtual ~FormAssociatedElement(); |
| 46 | |
| 47 | void ref() { refFormAssociatedElement(); } |
| 48 | void deref() { derefFormAssociatedElement(); } |
| 49 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 50 | static HTMLFormElement* findAssociatedForm(const HTMLElement*); |
| 51 | HTMLFormElement* form() const { return m_form.get(); } |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 52 | ValidityState* validity(); |
| 53 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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(FormDataList&, bool) { return false; } |
| 66 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 67 | void resetFormOwner(); |
| 68 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 69 | void formRemovedFromTree(const Node& formRoot); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 70 | |
| 71 | // ValidityState attribute implementations |
| 72 | bool customError() const; |
| 73 | |
| 74 | // Override functions for patterMismatch, rangeOverflow, rangerUnderflow, |
| 75 | // stepMismatch, tooLong and valueMissing must call willValidate method. |
Torne (Richard Coles) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 76 | virtual bool hasBadInput() const; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 77 | virtual bool patternMismatch() const; |
| 78 | virtual bool rangeOverflow() const; |
| 79 | virtual bool rangeUnderflow() const; |
| 80 | virtual bool stepMismatch() const; |
| 81 | virtual bool tooLong() const; |
| 82 | virtual bool typeMismatch() const; |
| 83 | virtual bool valueMissing() const; |
| 84 | virtual String validationMessage() const; |
| 85 | bool valid() const; |
| 86 | virtual void setCustomValidity(const String&); |
| 87 | |
| 88 | void formAttributeTargetChanged(); |
| 89 | |
| 90 | protected: |
| 91 | FormAssociatedElement(); |
| 92 | |
| 93 | void insertedInto(ContainerNode*); |
| 94 | void removedFrom(ContainerNode*); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 95 | void didMoveToNewDocument(Document& oldDocument); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 96 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 97 | // FIXME: Remove usage of setForm. resetFormOwner should be enough, and |
| 98 | // setForm is confusing. |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 99 | void setForm(HTMLFormElement*); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 100 | void associateByParser(HTMLFormElement*); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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 void refFormAssociatedElement() = 0; |
| 113 | virtual void derefFormAssociatedElement() = 0; |
| 114 | |
| 115 | void resetFormAttributeTargetObserver(); |
| 116 | |
| 117 | OwnPtr<FormAttributeTargetObserver> m_formAttributeTargetObserver; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 118 | // m_form should be a strong reference in Oilpan. |
| 119 | WeakPtr<HTMLFormElement> m_form; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 120 | OwnPtr<ValidityState> m_validityState; |
| 121 | String m_customValidationMessage; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 122 | bool m_formWasSetByParser; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | HTMLElement* toHTMLElement(FormAssociatedElement*); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 126 | HTMLElement& toHTMLElement(FormAssociatedElement&); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 127 | const HTMLElement* toHTMLElement(const FormAssociatedElement*); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 128 | const HTMLElement& toHTMLElement(const FormAssociatedElement&); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 129 | |
| 130 | } // namespace |
| 131 | |
| 132 | #endif // FormAssociatedElement_h |