00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef HTML_FORMIMPL_H
00026 #define HTML_FORMIMPL_H
00027
00028 #include "html/html_elementimpl.h"
00029 #include "dom/html_element.h"
00030
00031 #include <qvaluelist.h>
00032 #include <qptrlist.h>
00033 #include <qcstring.h>
00034 #include <qmemarray.h>
00035
00036 class KHTMLView;
00037 class QTextCodec;
00038
00039 namespace khtml
00040 {
00041 class RenderFormElement;
00042 class RenderTextArea;
00043 class RenderSelect;
00044 class RenderLineEdit;
00045 class RenderRadioButton;
00046 class RenderFileButton;
00047
00048 typedef QValueList<QCString> encodingList;
00049 }
00050
00051 namespace DOM {
00052
00053 class HTMLFormElement;
00054 class DOMString;
00055 class HTMLGenericFormElementImpl;
00056 class HTMLOptionElementImpl;
00057
00058
00059
00060 class HTMLFormElementImpl : public HTMLElementImpl
00061 {
00062 public:
00063 HTMLFormElementImpl(DocumentPtr *doc, bool implicit);
00064 virtual ~HTMLFormElementImpl();
00065
00066 virtual Id id() const;
00067
00068 long length() const;
00069
00070 QByteArray formData(bool& ok);
00071
00072 DOMString enctype() const { return m_enctype; }
00073 void setEnctype( const DOMString & );
00074
00075 DOMString boundary() const { return m_boundary; }
00076 void setBoundary( const DOMString & );
00077
00078 bool autoComplete() const { return m_autocomplete; }
00079
00080 virtual void parseAttribute(AttributeImpl *attr);
00081
00082 void radioClicked( HTMLGenericFormElementImpl *caller );
00083
00084 void registerFormElement(khtml::RenderFormElement *);
00085 void removeFormElement(khtml::RenderFormElement *);
00086
00087 void registerFormElement(HTMLGenericFormElementImpl *);
00088 void removeFormElement(HTMLGenericFormElementImpl *);
00089
00090 void submitFromKeyboard();
00091 bool prepareSubmit();
00092 void submit();
00093 void reset();
00094
00095 friend class HTMLFormElement;
00096 friend class HTMLFormCollectionImpl;
00097
00098 private:
00099 QPtrList<HTMLGenericFormElementImpl> formElements;
00100 DOMString m_target;
00101 DOMString m_enctype;
00102 DOMString m_boundary;
00103 DOMString m_acceptcharset;
00104 QString m_encCharset;
00105 bool m_post : 1;
00106 bool m_multipart : 1;
00107 bool m_autocomplete : 1;
00108 bool m_insubmit : 1;
00109 bool m_doingsubmit : 1;
00110 bool m_inreset : 1;
00111 };
00112
00113
00114
00115 class HTMLGenericFormElementImpl : public HTMLElementImpl
00116 {
00117 friend class HTMLFormElementImpl;
00118 friend class khtml::RenderFormElement;
00119
00120 public:
00121 HTMLGenericFormElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00122 virtual ~HTMLGenericFormElementImpl();
00123
00124 HTMLFormElementImpl *form() { return m_form; }
00125
00126 virtual void parseAttribute(AttributeImpl *attr);
00127 virtual void attach();
00128 virtual void reset() {}
00129
00130 virtual void insertedIntoDocument();
00131 virtual void removedFromDocument();
00132
00133 void onSelect();
00134 void onChange();
00135
00136 bool disabled() const { return m_disabled; }
00137 void setDisabled(bool _disabled);
00138
00139 virtual bool isSelectable() const;
00140 virtual bool isEnumeratable() const { return false; }
00141
00142 bool readOnly() const { return m_readOnly; }
00143 void setReadOnly(bool _readOnly) { m_readOnly = _readOnly; }
00144
00145 DOMString name() const;
00146 void setName(const DOMString& name);
00147
00148 virtual bool isGenericFormElement() const { return true; }
00149
00150
00151
00152
00153
00154
00155 virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool) { return false; }
00156
00157 virtual void defaultEventHandler(EventImpl *evt);
00158 virtual bool isEditable();
00159
00160 protected:
00161 HTMLFormElementImpl *getForm() const;
00162
00163 DOMStringImpl* m_name;
00164 HTMLFormElementImpl *m_form;
00165 bool m_disabled, m_readOnly;
00166 };
00167
00168
00169
00170 class HTMLButtonElementImpl : public HTMLGenericFormElementImpl
00171 {
00172 public:
00173 HTMLButtonElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00174
00175 virtual ~HTMLButtonElementImpl();
00176
00177 enum typeEnum {
00178 SUBMIT,
00179 RESET,
00180 BUTTON
00181 };
00182
00183 virtual Id id() const;
00184
00185 DOMString type() const;
00186 typeEnum buttonType() const { return m_type; }
00187 virtual void attach();
00188 virtual void parseAttribute(AttributeImpl *attr);
00189 virtual void defaultEventHandler(EventImpl *evt);
00190 virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
00191 void activate();
00192
00193 protected:
00194 DOMString m_value;
00195 QString m_currValue;
00196 typeEnum m_type : 2;
00197 bool m_dirty : 1;
00198 bool m_clicked : 1;
00199 bool m_activeSubmit : 1;
00200 };
00201
00202
00203
00204 class HTMLFieldSetElementImpl : public HTMLGenericFormElementImpl
00205 {
00206 public:
00207 HTMLFieldSetElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00208
00209 virtual ~HTMLFieldSetElementImpl();
00210
00211 virtual Id id() const;
00212 virtual void attach();
00213 virtual NodeImpl *addChild(NodeImpl *child);
00214 virtual void parseAttribute(AttributeImpl *attr);
00215
00216 protected:
00217 NodeImpl *m_legend;
00218 };
00219
00220
00221
00222 class HTMLInputElementImpl : public HTMLGenericFormElementImpl
00223 {
00224 friend class khtml::RenderLineEdit;
00225 friend class khtml::RenderRadioButton;
00226 friend class khtml::RenderFileButton;
00227
00228 public:
00229
00230 enum typeEnum {
00231 TEXT,
00232 PASSWORD,
00233 ISINDEX,
00234 CHECKBOX,
00235 RADIO,
00236 SUBMIT,
00237 RESET,
00238 FILE,
00239 HIDDEN,
00240 IMAGE,
00241 BUTTON
00242 };
00243
00244 HTMLInputElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00245 virtual ~HTMLInputElementImpl();
00246
00247 virtual Id id() const;
00248
00249 virtual bool isEnumeratable() const { return inputType() != IMAGE; }
00250
00251 bool autoComplete() const { return m_autocomplete; }
00252
00253 bool checked() const { return m_checked; }
00254 void setChecked(bool);
00255 long maxLength() const { return m_maxLen; }
00256 int size() const { return m_size; }
00257 DOMString type() const;
00258 void setType(const DOMString& t);
00259
00260 DOMString value() const;
00261 void setValue(DOMString val);
00262
00263 void blur();
00264 void focus();
00265
00266 virtual bool maintainsState() { return true; }
00267 virtual QString state();
00268 virtual void restoreState(const QString &);
00269
00270 void select();
00271 void click();
00272
00273 virtual void parseAttribute(AttributeImpl *attr);
00274
00275 virtual void attach();
00276 virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
00277
00278 typeEnum inputType() const { return m_type; }
00279 virtual void reset();
00280
00281
00282 int clickX() const { return xPos; }
00283 int clickY() const { return yPos; }
00284
00285 virtual void defaultEventHandler(EventImpl *evt);
00286 virtual bool isEditable();
00287
00288 DOMString altText() const;
00289 void activate();
00290
00291 protected:
00292
00293 DOMString m_value;
00294 int xPos;
00295 short m_maxLen;
00296 short m_size;
00297 short yPos;
00298
00299 typeEnum m_type : 4;
00300 bool m_clicked : 1 ;
00301 bool m_checked : 1;
00302 bool m_activeSubmit : 1;
00303 bool m_autocomplete : 1;
00304 bool m_inited : 1;
00305 };
00306
00307
00308
00309 class HTMLLabelElementImpl : public HTMLGenericFormElementImpl
00310 {
00311 public:
00312 HTMLLabelElementImpl(DocumentPtr *doc);
00313 virtual ~HTMLLabelElementImpl();
00314
00315 virtual Id id() const;
00316 virtual void parseAttribute(AttributeImpl *attr);
00317 virtual void attach();
00318
00319 private:
00320 DOMString m_formElementID;
00321 };
00322
00323
00324
00325 class HTMLLegendElementImpl : public HTMLGenericFormElementImpl
00326 {
00327 public:
00328 HTMLLegendElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00329 virtual ~HTMLLegendElementImpl();
00330
00331 virtual Id id() const;
00332 virtual void attach();
00333 virtual void parseAttribute(AttributeImpl *attr);
00334 };
00335
00336
00337
00338
00339 class HTMLSelectElementImpl : public HTMLGenericFormElementImpl
00340 {
00341 friend class khtml::RenderSelect;
00342
00343 public:
00344 HTMLSelectElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00345 ~HTMLSelectElementImpl();
00346
00347 virtual Id id() const;
00348
00349 DOMString type() const;
00350
00351 long selectedIndex() const;
00352 void setSelectedIndex( long index );
00353
00354 virtual bool isEnumeratable() const { return true; }
00355
00356 long length() const;
00357
00358 long minWidth() const { return m_minwidth; }
00359
00360 long size() const { return m_size; }
00361
00362 bool multiple() const { return m_multiple; }
00363
00364 void add ( const HTMLElement &element, const HTMLElement &before, int& exceptioncode );
00365 void remove ( long index );
00366 void blur();
00367 void focus();
00368
00369 DOMString value();
00370 void setValue(DOMStringImpl* value);
00371
00372 virtual bool maintainsState() { return true; }
00373 virtual QString state();
00374 virtual void restoreState(const QString &);
00375
00376 virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode );
00377 virtual NodeImpl *replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode );
00378 virtual NodeImpl *removeChild ( NodeImpl *oldChild, int &exceptioncode );
00379 virtual NodeImpl *appendChild ( NodeImpl *newChild, int &exceptioncode );
00380 virtual NodeImpl *addChild( NodeImpl* newChild );
00381
00382 virtual void childrenChanged();
00383
00384 virtual void parseAttribute(AttributeImpl *attr);
00385
00386 virtual void attach();
00387 virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
00388
00389
00390 int optionToListIndex(int optionIndex) const;
00391
00392 int listToOptionIndex(int listIndex) const;
00393
00394 void setRecalcListItems();
00395
00396 QMemArray<HTMLGenericFormElementImpl*> listItems() const
00397 {
00398 if (m_recalcListItems) const_cast<HTMLSelectElementImpl*>(this)->recalcListItems();
00399 return m_listItems;
00400 }
00401 virtual void reset();
00402 void notifyOptionSelected(HTMLOptionElementImpl *selectedOption, bool selected);
00403
00404 private:
00405 void recalcListItems();
00406
00407 protected:
00408 mutable QMemArray<HTMLGenericFormElementImpl*> m_listItems;
00409 short m_minwidth;
00410 short m_size : 15;
00411 bool m_multiple : 1;
00412 bool m_recalcListItems;
00413 };
00414
00415
00416
00417 class HTMLKeygenElementImpl : public HTMLSelectElementImpl
00418 {
00419 public:
00420 HTMLKeygenElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00421
00422 virtual Id id() const;
00423
00424 DOMString type() const;
00425
00426 long selectedIndex() const;
00427 void setSelectedIndex( long index );
00428
00429
00430 virtual bool isEnumeratable() const { return false; }
00431
00432 virtual void parseAttribute(AttributeImpl *attr);
00433 virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
00434
00435 };
00436
00437
00438
00439 class HTMLOptGroupElementImpl : public HTMLGenericFormElementImpl
00440 {
00441 public:
00442 HTMLOptGroupElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0)
00443 : HTMLGenericFormElementImpl(doc, f) {}
00444
00445 virtual Id id() const;
00446 };
00447
00448
00449
00450
00451 class HTMLOptionElementImpl : public HTMLGenericFormElementImpl
00452 {
00453 friend class khtml::RenderSelect;
00454 friend class DOM::HTMLSelectElementImpl;
00455
00456 public:
00457 HTMLOptionElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00458
00459 virtual Id id() const;
00460
00461 DOMString text() const;
00462
00463 long index() const;
00464 void setIndex( long );
00465 virtual void parseAttribute(AttributeImpl *attr);
00466 DOMString value() const;
00467 void setValue(DOMStringImpl* value);
00468
00469 bool selected() const { return m_selected; }
00470 void setSelected(bool _selected);
00471
00472 HTMLSelectElementImpl *getSelect() const;
00473
00474 protected:
00475 DOMString m_value;
00476 bool m_selected;
00477 };
00478
00479
00480
00481
00482 class HTMLTextAreaElementImpl : public HTMLGenericFormElementImpl
00483 {
00484 friend class khtml::RenderTextArea;
00485
00486 public:
00487 enum WrapMethod {
00488 ta_NoWrap,
00489 ta_Virtual,
00490 ta_Physical
00491 };
00492
00493 HTMLTextAreaElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00494 ~HTMLTextAreaElementImpl();
00495
00496 virtual Id id() const;
00497
00498 long cols() const { return m_cols; }
00499
00500 long rows() const { return m_rows; }
00501
00502 WrapMethod wrap() const { return m_wrap; }
00503
00504 virtual bool isEnumeratable() const { return true; }
00505
00506 DOMString type() const;
00507
00508 virtual bool maintainsState() { return true; }
00509 virtual QString state();
00510 virtual void restoreState(const QString &);
00511
00512 void select ( );
00513
00514 virtual void parseAttribute(AttributeImpl *attr);
00515 virtual void attach();
00516 virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
00517 virtual void reset();
00518 DOMString value();
00519 void setValue(DOMString _value);
00520 DOMString defaultValue();
00521 void setDefaultValue(DOMString _defaultValue);
00522 void blur();
00523 void focus();
00524
00525 virtual bool isEditable();
00526
00527 protected:
00528 int m_rows;
00529 int m_cols;
00530 WrapMethod m_wrap;
00531 QString m_value;
00532 bool m_dirtyvalue;
00533 };
00534
00535
00536
00537 class HTMLIsIndexElementImpl : public HTMLInputElementImpl
00538 {
00539 public:
00540 HTMLIsIndexElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
00541 ~HTMLIsIndexElementImpl();
00542
00543 virtual Id id() const;
00544 virtual void parseAttribute(AttributeImpl *attr);
00545
00546 DOMString prompt() const;
00547 void setPrompt(const DOMString& _value);
00548 };
00549
00550
00551 };
00552
00553 #endif