• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RenderTextControl;
34 class ValidityState;
35 class VisibleSelection;
36 
37 class HTMLFormControlElement : public HTMLElement {
38 public:
39     HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*);
40     virtual ~HTMLFormControlElement();
41 
endTagRequirement()42     virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; }
tagPriority()43     virtual int tagPriority() const { return 1; }
44 
form()45     HTMLFormElement* form() const { return m_form; }
46     ValidityState* validity();
47 
48     bool formNoValidate() const;
49     void setFormNoValidate(bool);
50 
isTextFormControl()51     virtual bool isTextFormControl() const { return false; }
isEnabledFormControl()52     virtual bool isEnabledFormControl() const { return !disabled(); }
53 
54     virtual void parseMappedAttribute(MappedAttribute*);
55     virtual void attach();
56     virtual void insertedIntoTree(bool deep);
57     virtual void removedFromTree(bool deep);
58 
reset()59     virtual void reset() {}
60 
formControlValueMatchesRenderer()61     virtual bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; }
setFormControlValueMatchesRenderer(bool b)62     virtual void setFormControlValueMatchesRenderer(bool b) { m_valueMatchesRenderer = b; }
63 
64     virtual void dispatchFormControlChangeEvent();
65 
disabled()66     bool disabled() const { return m_disabled; }
67     void setDisabled(bool);
68 
69     virtual bool supportsFocus() const;
70     virtual bool isFocusable() const;
71     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
72     virtual bool isMouseFocusable() const;
isEnumeratable()73     virtual bool isEnumeratable() const { return false; }
74 
isReadOnlyFormControl()75     virtual bool isReadOnlyFormControl() const { return m_readOnly; }
76     void setReadOnly(bool);
77 
78     // Determines whether or not a control will be automatically focused
79     virtual bool autofocus() const;
80     void setAutofocus(bool);
81 
82     bool required() const;
83     void setRequired(bool);
84 
85     virtual void recalcStyle(StyleChange);
86 
87     virtual const AtomicString& formControlName() const;
88     virtual const AtomicString& formControlType() const = 0;
89 
type()90     const AtomicString& type() const { return formControlType(); }
name()91     const AtomicString& name() const { return formControlName(); }
92 
93     void setName(const AtomicString& name);
94 
isFormControlElement()95     virtual bool isFormControlElement() const { return true; }
isRadioButton()96     virtual bool isRadioButton() const { return false; }
97 
98     /* Override in derived classes to get the encoded name=value pair for submitting.
99      * Return true for a successful control (see HTML4-17.13.2).
100      */
appendFormData(FormDataList &,bool)101     virtual bool appendFormData(FormDataList&, bool) { return false; }
102 
isSuccessfulSubmitButton()103     virtual bool isSuccessfulSubmitButton() const { return false; }
isActivatedSubmit()104     virtual bool isActivatedSubmit() const { return false; }
setActivatedSubmit(bool)105     virtual void setActivatedSubmit(bool) { }
106 
107     virtual short tabIndex() const;
108 
109     virtual bool willValidate() const;
110     String validationMessage();
111     bool checkValidity();
112     // This must be called when a validation constraint or control value is changed.
113     void setNeedsValidityCheck();
114     void setCustomValidity(const String&);
valueMissing()115     virtual bool valueMissing() const { return false; }
patternMismatch()116     virtual bool patternMismatch() const { return false; }
tooLong()117     virtual bool tooLong() const { return false; }
118 
119     void formDestroyed();
120 
121     virtual void dispatchFocusEvent();
122     virtual void dispatchBlurEvent();
123 
124 protected:
125     void removeFromForm();
126     // This must be called any time the result of willValidate() has changed.
127     void setNeedsWillValidateCheck();
128 
129 private:
130     virtual HTMLFormElement* virtualForm() const;
131     virtual bool isDefaultButtonForForm() const;
132     virtual bool isValidFormControlElement();
133 
134     HTMLFormElement* m_form;
135     OwnPtr<ValidityState> m_validityState;
136     bool m_hasName : 1;
137     bool m_disabled : 1;
138     bool m_readOnly : 1;
139     bool m_required : 1;
140     bool m_valueMatchesRenderer : 1;
141 };
142 
143 class HTMLFormControlElementWithState : public HTMLFormControlElement {
144 public:
145     HTMLFormControlElementWithState(const QualifiedName& tagName, Document*, HTMLFormElement*);
146     virtual ~HTMLFormControlElementWithState();
147 
148     virtual void finishParsingChildren();
149 
150 protected:
151     virtual void willMoveToNewOwnerDocument();
152     virtual void didMoveToNewOwnerDocument();
153 };
154 
155 class HTMLTextFormControlElement : public HTMLFormControlElementWithState {
156 public:
157     HTMLTextFormControlElement(const QualifiedName&, Document*, HTMLFormElement*);
158     virtual ~HTMLTextFormControlElement();
159     virtual void dispatchFocusEvent();
160     virtual void dispatchBlurEvent();
161 
162     int selectionStart();
163     int selectionEnd();
164     void setSelectionStart(int);
165     void setSelectionEnd(int);
166     void select();
167     void setSelectionRange(int start, int end);
168     VisibleSelection selection() const;
169 
170 protected:
171     bool placeholderShouldBeVisible() const;
172     void updatePlaceholderVisibility(bool);
173     virtual int cachedSelectionStart() const = 0;
174     virtual int cachedSelectionEnd() const = 0;
175     virtual void parseMappedAttribute(MappedAttribute*);
176 
177 private:
178     // A subclass should return true if placeholder processing is needed.
179     virtual bool supportsPlaceholder() const = 0;
180     // Returns true if user-editable value is empty.  This is used to check placeholder visibility.
181     virtual bool isEmptyValue() const = 0;
182     // Called in dispatchFocusEvent(), after placeholder process, before calling parent's dispatchFocusEvent().
handleFocusEvent()183     virtual void handleFocusEvent() { }
184     // Called in dispatchBlurEvent(), after placeholder process, before calling parent's dispatchBlurEvent().
handleBlurEvent()185     virtual void handleBlurEvent() { }
186     RenderTextControl* textRendererAfterUpdateLayout();
187 };
188 
189 } //namespace
190 
191 #endif
192