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 27 #include "HTMLElement.h" 28 29 namespace WebCore { 30 31 class FormDataList; 32 class HTMLFormElement; 33 class ValidationMessage; 34 class ValidityState; 35 class VisibleSelection; 36 37 class FormAssociatedElement { 38 public: 39 virtual ~FormAssociatedElement(); 40 ref()41 void ref() { refFormAssociatedElement(); } deref()42 void deref() { derefFormAssociatedElement(); } 43 form()44 HTMLFormElement* form() const { return m_form; } 45 ValidityState* validity(); 46 47 virtual bool isFormControlElement() const = 0; 48 virtual bool isEnumeratable() const = 0; 49 name()50 const AtomicString& name() const { return formControlName(); } 51 52 // Override in derived classes to get the encoded name=value pair for submitting. 53 // Return true for a successful control (see HTML4-17.13.2). appendFormData(FormDataList &,bool)54 virtual bool appendFormData(FormDataList&, bool) { return false; } 55 formDestroyed()56 virtual void formDestroyed() { m_form = 0; } 57 58 void resetFormOwner(HTMLFormElement*); 59 60 protected: 61 FormAssociatedElement(HTMLFormElement*); 62 63 void insertedIntoTree(); 64 void removedFromTree(); 65 void insertedIntoDocument(); 66 void removedFromDocument(); 67 void willMoveToNewOwnerDocument(); 68 setForm(HTMLFormElement * form)69 void setForm(HTMLFormElement* form) { m_form = form; } 70 void removeFromForm(); 71 void formAttributeChanged(); 72 73 private: 74 virtual const AtomicString& formControlName() const = 0; 75 76 virtual void refFormAssociatedElement() = 0; 77 virtual void derefFormAssociatedElement() = 0; 78 79 HTMLFormElement* m_form; 80 OwnPtr<ValidityState> m_validityState; 81 }; 82 83 HTMLElement* toHTMLElement(FormAssociatedElement*); 84 const HTMLElement* toHTMLElement(const FormAssociatedElement*); 85 86 } // namespace 87 88 #endif // FormAssociatedElement_h 89