2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2000 Dirk Mueller (mueller@kde.org)
7 * (C) 2004, 2005, 2006 Apple Computer, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #ifndef HTML_FORMIMPL_H
26 #define HTML_FORMIMPL_H
28 #include "html/html_elementimpl.h"
29 #include "html/html_imageimpl.h"
30 #include "dom/html_element.h"
36 class RenderFormElement
;
40 class RenderRadioButton
;
41 class RenderFileButton
;
43 typedef QList
<QByteArray
> encodingList
;
52 class HTMLFormElement
;
54 class HTMLGenericFormElementImpl
;
55 class HTMLOptionElementImpl
;
56 class HTMLCollectionImpl
;
58 // -------------------------------------------------------------------------
60 class HTMLFormElementImpl
: public HTMLElementImpl
63 HTMLFormElementImpl(DocumentImpl
*doc
, bool implicit
);
64 virtual ~HTMLFormElementImpl();
66 virtual Id
id() const;
68 virtual void insertedIntoDocument();
69 virtual void removedFromDocument();
70 virtual void addId(const QString
& id
);
71 virtual void removeId(const QString
& id
);
76 QByteArray
formData(bool& ok
);
78 DOMString
enctype() const { return m_enctype
; }
79 void setEnctype( const DOMString
& );
81 DOMString
target() const;
82 DOMString
action() const;
83 HTMLCollectionImpl
* elements();
85 bool autoComplete() const { return m_autocomplete
; }
87 void walletOpened(KWallet::Wallet
*w
);
89 virtual void parseAttribute(AttributeImpl
*attr
);
91 void radioClicked( HTMLGenericFormElementImpl
*caller
);
93 void registerFormElement(HTMLGenericFormElementImpl
*);
94 void removeFormElement(HTMLGenericFormElementImpl
*);
95 void registerImgElement(HTMLImageElementImpl
*);
96 void removeImgElement(HTMLImageElementImpl
*);
98 void submitFromKeyboard();
103 void setMalformed(bool malformed
) { m_malformed
= malformed
; }
104 bool isMalformed() const { return m_malformed
; }
106 friend class HTMLFormElement
;
107 friend class HTMLFormCollectionImpl
;
110 void gatherWalletData();
111 QList
<HTMLGenericFormElementImpl
*> formElements
;
112 QList
<HTMLImageElementImpl
*> imgElements
;
116 DOMString m_acceptcharset
;
117 QString m_encCharset
;
119 bool m_multipart
: 1;
120 bool m_autocomplete
: 1;
122 bool m_doingsubmit
: 1;
124 bool m_malformed
: 1;
125 bool m_haveTextarea
: 1; // for wallet storage
126 bool m_havePassword
: 1; // for wallet storage
127 DOMString m_name
; // our name
128 QMap
<QString
, QString
> m_walletMap
; // for wallet storage
131 // -------------------------------------------------------------------------
133 class HTMLGenericFormElementImpl
: public HTMLElementImpl
135 friend class HTMLFormElementImpl
;
136 friend class khtml::RenderFormElement
;
139 HTMLGenericFormElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
140 virtual ~HTMLGenericFormElementImpl();
142 HTMLFormElementImpl
*form() const { return m_form
; }
144 virtual void parseAttribute(AttributeImpl
*attr
);
145 virtual void attach();
146 virtual void reset() {}
148 virtual void insertedIntoDocument();
149 virtual void removedFromDocument();
154 bool disabled() const { return m_disabled
; }
155 void setDisabled(bool _disabled
);
157 virtual bool isFocusable() const;
158 virtual bool isEnumeratable() const { return false; }
160 virtual bool isDefault() const { return false; }
162 bool readOnly() const { return m_readOnly
; }
163 void setReadOnly(bool _readOnly
) { m_readOnly
= _readOnly
; }
165 DOMString
name() const;
166 void setName(const DOMString
& name
);
168 virtual bool isGenericFormElement() const { return true; }
171 * override in derived classes to get the encoded name=value pair
173 * return true for a successful control (see HTML4-17.13.2)
175 virtual bool encoding(const QTextCodec
*, khtml::encodingList
&, bool) { return false; }
177 virtual void defaultEventHandler(EventImpl
*evt
);
178 virtual bool isEditable();
180 virtual bool unsubmittedFormChanges() const { return false; }
183 HTMLFormElementImpl
*getForm() const;
185 DOMStringImpl
* m_name
;
186 HTMLFormElementImpl
*m_form
;
187 bool m_disabled
, m_readOnly
;
190 // -------------------------------------------------------------------------
192 class HTMLButtonElementImpl
: public HTMLGenericFormElementImpl
195 HTMLButtonElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
197 virtual ~HTMLButtonElementImpl();
205 virtual Id
id() const;
206 virtual bool isEnumeratable() const { return true; }
208 DOMString
type() const;
209 typeEnum
buttonType() const { return KDE_CAST_BF_ENUM(typeEnum
, m_type
); }
210 virtual void parseAttribute(AttributeImpl
*attr
);
211 virtual void defaultEventHandler(EventImpl
*evt
);
212 virtual bool encoding(const QTextCodec
*, khtml::encodingList
&, bool);
214 virtual void attach();
220 KDE_BF_ENUM(typeEnum
) m_type
: 2;
223 bool m_activeSubmit
: 1;
226 // -------------------------------------------------------------------------
228 class HTMLFieldSetElementImpl
: public HTMLGenericFormElementImpl
231 HTMLFieldSetElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
233 virtual ~HTMLFieldSetElementImpl();
235 virtual Id
id() const;
236 virtual void attach();
237 virtual void parseAttribute(AttributeImpl
*attr
);
241 // -------------------------------------------------------------------------
243 class HTMLInputElementImpl
: public HTMLGenericFormElementImpl
245 friend class khtml::RenderLineEdit
;
246 friend class khtml::RenderRadioButton
;
247 friend class khtml::RenderFileButton
;
250 // do not change the order!
265 HTMLInputElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
266 virtual ~HTMLInputElementImpl();
268 virtual Id
id() const;
270 virtual bool isEnumeratable() const { return inputType() != IMAGE
; }
271 virtual bool isDefault() const { return m_defaultChecked
; }
273 bool autoComplete() const { return m_autocomplete
; }
275 bool checked() const { return m_useDefaultChecked
? m_defaultChecked
: m_checked
; }
276 void setChecked(bool);
277 bool indeterminate() const { return m_indeterminate
; }
278 void setIndeterminate(bool);
279 long maxLength() const { return m_maxLen
; }
280 int size() const { return m_size
; }
281 DOMString
type() const;
282 void setType(const DOMString
& t
);
284 DOMString
value() const;
285 void setValue(DOMString val
);
287 DOMString
valueWithDefault() const;
289 virtual bool maintainsState() { return true; }
290 virtual QString
state();
291 virtual void restoreState(const QString
&state
);
296 virtual void parseAttribute(AttributeImpl
*attr
);
298 virtual void copyNonAttributeProperties(const ElementImpl
* source
);
300 virtual void attach();
301 virtual bool encoding(const QTextCodec
*, khtml::encodingList
&, bool);
303 typeEnum
inputType() const { return KDE_CAST_BF_ENUM(typeEnum
, m_type
); }
304 virtual void reset();
306 // used in case input type=image was clicked.
307 int clickX() const { return xPos
; }
308 int clickY() const { return yPos
; }
310 virtual void defaultEventHandler(EventImpl
*evt
);
311 virtual bool isEditable();
313 DOMString
altText() const;
316 void setUnsubmittedFormChange(bool unsubmitted
) { m_unsubmittedFormChange
= unsubmitted
; }
317 virtual bool unsubmittedFormChanges() const { return m_unsubmittedFormChange
; }
319 //Mozilla extensions.
320 long selectionStart();
322 void setSelectionStart(long pos
);
323 void setSelectionEnd (long pos
);
324 void setSelectionRange(long start
, long end
);
326 void parseType(const DOMString
& t
);
334 KDE_BF_ENUM(typeEnum
) m_type
: 4;
337 bool m_defaultChecked
: 1; // could do without by checking ATTR_CHECKED
338 bool m_useDefaultChecked
: 1;
339 bool m_indeterminate
: 1;
341 bool m_activeSubmit
: 1;
342 bool m_autocomplete
: 1;
344 bool m_unsubmittedFormChange
: 1;
347 // -------------------------------------------------------------------------
349 class HTMLLabelElementImpl
: public HTMLGenericFormElementImpl
352 HTMLLabelElementImpl(DocumentImpl
*doc
);
353 virtual ~HTMLLabelElementImpl();
355 virtual Id
id() const;
356 virtual void attach();
357 virtual void defaultEventHandler(EventImpl
*evt
);
358 virtual bool isFocusable() const { return true; }
359 virtual bool isTabFocusable() const { return false; }
360 NodeImpl
* getFormElement();
363 DOMString m_formElementID
;
366 // -------------------------------------------------------------------------
368 class HTMLLegendElementImpl
: public HTMLGenericFormElementImpl
371 HTMLLegendElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
372 virtual ~HTMLLegendElementImpl();
374 virtual Id
id() const;
375 virtual void attach();
376 virtual void parseAttribute(AttributeImpl
*attr
);
380 // -------------------------------------------------------------------------
382 class HTMLSelectElementImpl
: public HTMLGenericFormElementImpl
384 friend class khtml::RenderSelect
;
387 HTMLSelectElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
388 ~HTMLSelectElementImpl();
390 virtual Id
id() const;
392 DOMString
type() const;
394 HTMLCollectionImpl
* options();
396 long selectedIndex() const;
397 void setSelectedIndex( long index
);
399 virtual bool isEnumeratable() const { return true; }
403 long minWidth() const { return m_minwidth
; }
405 long size() const { return m_size
; }
407 bool multiple() const { return m_multiple
; }
409 void add ( HTMLElementImpl
* element
, HTMLElementImpl
* before
, int& exceptioncode
);
410 void remove ( long index
);
412 DOMString
value() const;
413 void setValue(DOMStringImpl
* value
);
415 virtual bool maintainsState() { return true; }
416 virtual QString
state();
417 virtual void restoreState(const QString
&state
);
419 virtual NodeImpl
*insertBefore ( NodeImpl
*newChild
, NodeImpl
*refChild
, int &exceptioncode
);
420 virtual void replaceChild ( NodeImpl
*newChild
, NodeImpl
*oldChild
, int &exceptioncode
);
421 virtual void removeChild ( NodeImpl
*oldChild
, int &exceptioncode
);
422 virtual NodeImpl
*appendChild ( NodeImpl
*newChild
, int &exceptioncode
);
423 virtual NodeImpl
*addChild( NodeImpl
* newChild
);
425 virtual void childrenChanged();
427 virtual void parseAttribute(AttributeImpl
*attr
);
429 virtual void attach();
430 virtual bool encoding(const QTextCodec
*, khtml::encodingList
&, bool);
432 // get the actual listbox index of the optionIndexth option
433 int optionToListIndex(int optionIndex
) const;
434 // reverse of optionToListIndex - get optionIndex from listboxIndex
435 int listToOptionIndex(int listIndex
) const;
437 void setRecalcListItems();
439 QVector
<HTMLGenericFormElementImpl
*> listItems() const
441 if (m_recalcListItems
) const_cast<HTMLSelectElementImpl
*>(this)->recalcListItems();
444 virtual void reset();
445 void notifyOptionSelected(HTMLOptionElementImpl
*selectedOption
, bool selected
);
448 void recalcListItems() const;
451 mutable QVector
<HTMLGenericFormElementImpl
*> m_listItems
;
453 signed short m_size
: 15;
455 mutable bool m_recalcListItems
:1;
456 mutable unsigned int m_length
:31;
459 // -------------------------------------------------------------------------
461 class HTMLKeygenElementImpl
: public HTMLSelectElementImpl
464 HTMLKeygenElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
466 virtual Id
id() const;
468 DOMString
type() const;
470 long selectedIndex() const;
471 void setSelectedIndex( long index
);
473 // ### this is just a rough guess
474 virtual bool isEnumeratable() const { return false; }
476 virtual void parseAttribute(AttributeImpl
*attr
);
477 virtual bool encoding(const QTextCodec
*, khtml::encodingList
&, bool);
481 // -------------------------------------------------------------------------
483 class HTMLOptGroupElementImpl
: public HTMLGenericFormElementImpl
486 HTMLOptGroupElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0)
487 : HTMLGenericFormElementImpl(doc
, f
) {}
489 virtual Id
id() const;
493 // ---------------------------------------------------------------------------
495 class HTMLOptionElementImpl
: public HTMLGenericFormElementImpl
497 friend class khtml::RenderSelect
;
498 friend class DOM::HTMLSelectElementImpl
;
501 HTMLOptionElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
503 virtual Id
id() const;
505 DOMString
text() const;
508 void setIndex( long );
509 virtual void parseAttribute(AttributeImpl
*attr
);
510 DOMString
value() const;
511 void setValue(DOMStringImpl
* value
);
513 virtual bool isDefault() const { return m_defaultSelected
; }
515 // For internal use --- just returns the bit
516 bool selectedBit() const { return m_selected
; }
518 // DOM use --- may recompute information of a parent <select>
519 bool selected() const;
520 void setSelected(bool _selected
);
521 void setDefaultSelected( bool _defaultSelected
);
523 HTMLSelectElementImpl
*getSelect() const;
528 bool m_defaultSelected
;
532 // -------------------------------------------------------------------------
534 class HTMLTextAreaElementImpl
: public HTMLGenericFormElementImpl
536 friend class khtml::RenderTextArea
;
545 HTMLTextAreaElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
546 ~HTMLTextAreaElementImpl();
548 virtual Id
id() const;
549 virtual void childrenChanged();
551 long cols() const { return m_cols
; }
553 long rows() const { return m_rows
; }
555 WrapMethod
wrap() const { return m_wrap
; }
557 virtual bool isEnumeratable() const { return true; }
559 DOMString
type() const;
561 virtual bool maintainsState() { return true; }
562 virtual QString
state();
563 virtual void restoreState(const QString
&state
);
567 virtual void parseAttribute(AttributeImpl
*attr
);
568 virtual void attach();
569 virtual bool encoding(const QTextCodec
*, khtml::encodingList
&, bool);
570 virtual void reset();
572 void setValue(DOMString _value
);
573 DOMString
defaultValue();
574 void setDefaultValue(DOMString _defaultValue
);
576 virtual bool isEditable();
577 void setUnsubmittedFormChange(bool unsubmitted
) { m_unsubmittedFormChange
= unsubmitted
; }
578 virtual bool unsubmittedFormChanges() const { return m_unsubmittedFormChange
; }
580 //Mozilla extensions.
581 long selectionStart();
583 void setSelectionStart(long pos
);
584 void setSelectionEnd (long pos
);
585 void setSelectionRange(long start
, long end
);
592 bool m_changed
: 1; //States whether the contents has been editted
593 bool m_unsubmittedFormChange
: 1;
594 bool m_initialized
: 1;
597 // -------------------------------------------------------------------------
599 class HTMLIsIndexElementImpl
: public HTMLInputElementImpl
602 HTMLIsIndexElementImpl(DocumentImpl
*doc
, HTMLFormElementImpl
*f
= 0);
603 ~HTMLIsIndexElementImpl();
605 virtual Id
id() const;
606 virtual void parseAttribute(AttributeImpl
*attr
);
608 DOMString
prompt() const;
609 void setPrompt(const DOMString
& _value
);