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