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 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 HTMLFormControlElement_h 25 #define HTMLFormControlElement_h 26 27 #include "HTMLElement.h" 28 29 namespace WebCore { 30 31 class FormDataList; 32 class HTMLFormElement; 33 class ValidityState; 34 35 class HTMLFormControlElement : public HTMLElement { 36 public: 37 HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*); 38 virtual ~HTMLFormControlElement(); 39 endTagRequirement()40 virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } tagPriority()41 virtual int tagPriority() const { return 1; } 42 form()43 HTMLFormElement* form() const { return m_form; } 44 virtual ValidityState* validity(); 45 isTextFormControl()46 virtual bool isTextFormControl() const { return false; } isEnabledFormControl()47 virtual bool isEnabledFormControl() const { return !disabled(); } 48 49 virtual void parseMappedAttribute(MappedAttribute*); 50 virtual void attach(); 51 virtual void insertedIntoTree(bool deep); 52 virtual void removedFromTree(bool deep); 53 reset()54 virtual void reset() {} 55 formControlValueMatchesRenderer()56 virtual bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; } setFormControlValueMatchesRenderer(bool b)57 virtual void setFormControlValueMatchesRenderer(bool b) { m_valueMatchesRenderer = b; } 58 59 virtual void dispatchFormControlChangeEvent(); 60 61 bool disabled() const; 62 void setDisabled(bool); 63 64 virtual bool supportsFocus() const; 65 virtual bool isFocusable() const; 66 virtual bool isKeyboardFocusable(KeyboardEvent*) const; 67 virtual bool isMouseFocusable() const; isEnumeratable()68 virtual bool isEnumeratable() const { return false; } 69 isReadOnlyFormControl()70 virtual bool isReadOnlyFormControl() const { return m_readOnly; } 71 void setReadOnly(bool); 72 73 // Determines whether or not a control will be automatically focused 74 virtual bool autofocus() const; 75 void setAutofocus(bool); 76 77 bool required() const; 78 void setRequired(bool); 79 80 virtual void recalcStyle(StyleChange); 81 82 virtual const AtomicString& formControlName() const; 83 virtual const AtomicString& formControlType() const = 0; 84 type()85 const AtomicString& type() const { return formControlType(); } name()86 const AtomicString& name() const { return formControlName(); } 87 88 void setName(const AtomicString& name); 89 isFormControlElement()90 virtual bool isFormControlElement() const { return true; } isRadioButton()91 virtual bool isRadioButton() const { return false; } 92 93 /* Override in derived classes to get the encoded name=value pair for submitting. 94 * Return true for a successful control (see HTML4-17.13.2). 95 */ appendFormData(FormDataList &,bool)96 virtual bool appendFormData(FormDataList&, bool) { return false; } 97 isSuccessfulSubmitButton()98 virtual bool isSuccessfulSubmitButton() const { return false; } isActivatedSubmit()99 virtual bool isActivatedSubmit() const { return false; } setActivatedSubmit(bool)100 virtual void setActivatedSubmit(bool) { } 101 102 virtual short tabIndex() const; 103 104 virtual bool willValidate() const; 105 void setCustomValidity(const String&); 106 valueMissing()107 virtual bool valueMissing() const { return false; } patternMismatch()108 virtual bool patternMismatch() const { return false; } 109 formDestroyed()110 void formDestroyed() { m_form = 0; } 111 112 virtual void dispatchFocusEvent(); 113 virtual void dispatchBlurEvent(); 114 115 protected: 116 void removeFromForm(); 117 118 private: 119 virtual HTMLFormElement* virtualForm() const; 120 121 HTMLFormElement* m_form; 122 RefPtr<ValidityState> m_validityState; 123 bool m_disabled; 124 bool m_readOnly; 125 bool m_valueMatchesRenderer; 126 }; 127 128 class HTMLFormControlElementWithState : public HTMLFormControlElement { 129 public: 130 HTMLFormControlElementWithState(const QualifiedName& tagName, Document*, HTMLFormElement*); 131 virtual ~HTMLFormControlElementWithState(); 132 133 virtual void finishParsingChildren(); 134 135 protected: 136 virtual void willMoveToNewOwnerDocument(); 137 virtual void didMoveToNewOwnerDocument(); 138 }; 139 140 } //namespace 141 142 #endif 143