html_formimpl.h Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# html_formimpl.h

    00001 /*
    00002  * This file is part of the DOM implementation for KDE.
    00003  *
    00004  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    00005  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    00006  *           (C) 2000 Dirk Mueller (mueller@kde.org)
    00007  *
    00008  * This library is free software; you can redistribute it and/or
    00009  * modify it under the terms of the GNU Library General Public
    00010  * License as published by the Free Software Foundation; either
    00011  * version 2 of the License, or (at your option) any later version.
    00012  *
    00013  * This library is distributed in the hope that it will be useful,
    00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016  * Library General Public License for more details.
    00017  *
    00018  * You should have received a copy of the GNU Library General Public License
    00019  * along with this library; see the file COPYING.LIB.  If not, write to
    00020  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021  * Boston, MA 02111-1307, USA.
    00022  *
    00023  */
    00024 #ifndef HTML_FORMIMPL_H
    00025 #define HTML_FORMIMPL_H
    00026
    00027 #include "html/html_elementimpl.h"
    00028 #include "html/html_imageimpl.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     bool autoComplete() const { return m_autocomplete; }
    00076
    00077     virtual void parseAttribute(AttributeImpl *attr);
    00078
    00079     void radioClicked( HTMLGenericFormElementImpl *caller );
    00080
    00081     void registerFormElement(HTMLGenericFormElementImpl *);
    00082     void removeFormElement(HTMLGenericFormElementImpl *);
    00083     void registerImgElement(HTMLImageElementImpl *);
    00084     void removeImgElement(HTMLImageElementImpl *);
    00085
    00086     void submitFromKeyboard();
    00087     bool prepareSubmit();
    00088     void submit();
    00089     void reset();
    00090
    00091     friend class HTMLFormElement;
    00092     friend class HTMLFormCollectionImpl;
    00093
    00094 private:
    00095     QPtrList<HTMLGenericFormElementImpl> formElements;
    00096     QPtrList<HTMLImageElementImpl> imgElements;
    00097     DOMString m_target;
    00098     DOMString m_enctype;
    00099     QString m_boundary;
    00100     DOMString m_acceptcharset;
    00101     QString m_encCharset;
    00102     bool m_post : 1;
    00103     bool m_multipart : 1;
    00104     bool m_autocomplete : 1;
    00105     bool m_insubmit : 1;
    00106     bool m_doingsubmit : 1;
    00107     bool m_inreset : 1;
    00108 };
    00109
    00110 // -------------------------------------------------------------------------
    00111
    00112 class HTMLGenericFormElementImpl : public HTMLElementImpl
    00113 {
    00114     friend class HTMLFormElementImpl;
    00115     friend class khtml::RenderFormElement;
    00116
    00117 public:
    00118     HTMLGenericFormElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00119     virtual ~HTMLGenericFormElementImpl();
    00120
    00121     HTMLFormElementImpl *form() { return m_form; }
    00122
    00123     virtual void parseAttribute(AttributeImpl *attr);
    00124     virtual void attach();
    00125     virtual void reset() {}
    00126
    00127     virtual void insertedIntoDocument();
    00128     virtual void removedFromDocument();
    00129
    00130     void onSelect();
    00131     void onChange();
    00132
    00133     bool disabled() const { return m_disabled; }
    00134     void setDisabled(bool _disabled);
    00135
    00136     virtual bool isSelectable() const;
    00137     virtual bool isEnumeratable() const { return false; }
    00138
    00139     bool readOnly() const { return m_readOnly; }
    00140     void setReadOnly(bool _readOnly) { m_readOnly = _readOnly; }
    00141
    00142     DOMString name() const;
    00143     void setName(const DOMString& name);
    00144
    00145     virtual bool isGenericFormElement() const { return true; }
    00146
    00147     /*
    00148      * override in derived classes to get the encoded name=value pair
    00149      * for submitting
    00150      * return true for a successful control (see HTML4-17.13.2)
    00151      */
    00152     virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool) { return false; }
    00153
    00154     virtual void defaultEventHandler(EventImpl *evt);
    00155     virtual bool isEditable();
    00156
    00157 protected:
    00158     HTMLFormElementImpl *getForm() const;
    00159
    00160     DOMStringImpl* m_name;
    00161     HTMLFormElementImpl *m_form;
    00162     bool m_disabled, m_readOnly;
    00163 };
    00164
    00165 // -------------------------------------------------------------------------
    00166
    00167 class HTMLButtonElementImpl : public HTMLGenericFormElementImpl
    00168 {
    00169 public:
    00170     HTMLButtonElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00171
    00172     virtual ~HTMLButtonElementImpl();
    00173
    00174     enum typeEnum {
    00175         SUBMIT,
    00176         RESET,
    00177         BUTTON
    00178     };
    00179
    00180     virtual Id id() const;
    00181
    00182     DOMString type() const;
    00183     typeEnum buttonType() const { return m_type; }
    00184     virtual void attach();
    00185     virtual void parseAttribute(AttributeImpl *attr);
    00186     virtual void defaultEventHandler(EventImpl *evt);
    00187     virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
    00188     void activate();
    00189
    00190 protected:
    00191     DOMString m_value;
    00192     QString   m_currValue;
    00193     typeEnum  m_type : 2;
    00194     bool      m_dirty : 1;
    00195     bool      m_clicked : 1;
    00196     bool      m_activeSubmit : 1;
    00197 };
    00198
    00199 // -------------------------------------------------------------------------
    00200
    00201 class HTMLFieldSetElementImpl : public HTMLGenericFormElementImpl
    00202 {
    00203 public:
    00204     HTMLFieldSetElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00205
    00206     virtual ~HTMLFieldSetElementImpl();
    00207
    00208     virtual Id id() const;
    00209     virtual void attach();
    00210     virtual NodeImpl *addChild(NodeImpl *child);
    00211     virtual void parseAttribute(AttributeImpl *attr);
    00212
    00213 protected:
    00214     NodeImpl *m_legend;
    00215 };
    00216
    00217 // -------------------------------------------------------------------------
    00218
    00219 class HTMLInputElementImpl : public HTMLGenericFormElementImpl
    00220 {
    00221     friend class khtml::RenderLineEdit;
    00222     friend class khtml::RenderRadioButton;
    00223     friend class khtml::RenderFileButton;
    00224
    00225 public:
    00226     // do not change the order!
    00227     enum typeEnum {
    00228         TEXT,
    00229         PASSWORD,
    00230         ISINDEX,
    00231         CHECKBOX,
    00232         RADIO,
    00233         SUBMIT,
    00234         RESET,
    00235         FILE,
    00236         HIDDEN,
    00237         IMAGE,
    00238         BUTTON
    00239     };
    00240
    00241     HTMLInputElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00242     virtual ~HTMLInputElementImpl();
    00243
    00244     virtual Id id() const;
    00245
    00246     virtual bool isEnumeratable() const { return inputType() != IMAGE; }
    00247
    00248     bool autoComplete() const { return m_autocomplete; }
    00249
    00250     bool checked() const { return m_checked; }
    00251     void setChecked(bool);
    00252     long maxLength() const { return m_maxLen; }
    00253     int size() const { return m_size; }
    00254     DOMString type() const;
    00255     void setType(const DOMString& t);
    00256
    00257     DOMString value() const;
    00258     void setValue(DOMString val);
    00259
    00260     void blur();
    00261     void focus();
    00262
    00263     virtual bool maintainsState() { return true; }
    00264     virtual QString state();
    00265     virtual void restoreState(const QString &);
    00266
    00267     void select();
    00268     void click();
    00269
    00270     virtual void parseAttribute(AttributeImpl *attr);
    00271
    00272     virtual void attach();
    00273     virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
    00274
    00275     typeEnum inputType() const { return m_type; }
    00276     virtual void reset();
    00277
    00278     // used in case input type=image was clicked.
    00279     int clickX() const { return xPos; }
    00280     int clickY() const { return yPos; }
    00281
    00282     virtual void defaultEventHandler(EventImpl *evt);
    00283     virtual bool isEditable();
    00284
    00285     DOMString altText() const;
    00286     void activate();
    00287
    00288 protected:
    00289
    00290     DOMString m_value;
    00291     int       xPos;
    00292     short     m_maxLen;
    00293     short     m_size;
    00294     short     yPos;
    00295
    00296     typeEnum m_type : 4;
    00297     bool m_clicked : 1 ;
    00298     bool m_checked : 1;
    00299     bool m_activeSubmit : 1;
    00300     bool m_autocomplete : 1;
    00301     bool m_inited : 1;
    00302 };
    00303
    00304 // -------------------------------------------------------------------------
    00305
    00306 class HTMLLabelElementImpl : public HTMLGenericFormElementImpl
    00307 {
    00308 public:
    00309     HTMLLabelElementImpl(DocumentPtr *doc);
    00310     virtual ~HTMLLabelElementImpl();
    00311
    00312     virtual Id id() const;
    00313     virtual void parseAttribute(AttributeImpl *attr);
    00314     virtual void attach();
    00315
    00316  private:
    00317     DOMString m_formElementID;
    00318 };
    00319
    00320 // -------------------------------------------------------------------------
    00321
    00322 class HTMLLegendElementImpl : public HTMLGenericFormElementImpl
    00323 {
    00324 public:
    00325     HTMLLegendElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00326     virtual ~HTMLLegendElementImpl();
    00327
    00328     virtual Id id() const;
    00329     virtual void attach();
    00330     virtual void parseAttribute(AttributeImpl *attr);
    00331 };
    00332
    00333
    00334 // -------------------------------------------------------------------------
    00335
    00336 class HTMLSelectElementImpl : public HTMLGenericFormElementImpl
    00337 {
    00338     friend class khtml::RenderSelect;
    00339
    00340 public:
    00341     HTMLSelectElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00342     ~HTMLSelectElementImpl();
    00343
    00344     virtual Id id() const;
    00345
    00346     DOMString type() const;
    00347
    00348     long selectedIndex() const;
    00349     void setSelectedIndex( long index );
    00350
    00351     virtual bool isEnumeratable() const { return true; }
    00352
    00353     long length() const;
    00354
    00355     long minWidth() const { return m_minwidth; }
    00356
    00357     long size() const { return m_size; }
    00358
    00359     bool multiple() const { return m_multiple; }
    00360
    00361     void add ( const HTMLElement &element, const HTMLElement &before, int& exceptioncode );
    00362     void remove ( long index );
    00363     void blur();
    00364     void focus();
    00365
    00366     DOMString value();
    00367     void setValue(DOMStringImpl* value);
    00368
    00369     virtual bool maintainsState() { return true; }
    00370     virtual QString state();
    00371     virtual void restoreState(const QString &);
    00372
    00373     virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode );
    00374     virtual NodeImpl *replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode );
    00375     virtual NodeImpl *removeChild ( NodeImpl *oldChild, int &exceptioncode );
    00376     virtual NodeImpl *appendChild ( NodeImpl *newChild, int &exceptioncode );
    00377     virtual NodeImpl *addChild( NodeImpl* newChild );
    00378
    00379     virtual void childrenChanged();
    00380
    00381     virtual void parseAttribute(AttributeImpl *attr);
    00382
    00383     virtual void attach();
    00384     virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
    00385
    00386     // get the actual listbox index of the optionIndexth option
    00387     int optionToListIndex(int optionIndex) const;
    00388     // reverse of optionToListIndex - get optionIndex from listboxIndex
    00389     int listToOptionIndex(int listIndex) const;
    00390
    00391     void setRecalcListItems();
    00392
    00393     QMemArray<HTMLGenericFormElementImpl*> listItems() const
    00394      {
    00395          if (m_recalcListItems) const_cast<HTMLSelectElementImpl*>(this)->recalcListItems();
    00396          return m_listItems;
    00397      }
    00398     virtual void reset();
    00399     void notifyOptionSelected(HTMLOptionElementImpl *selectedOption, bool selected);
    00400
    00401 private:
    00402     void recalcListItems();
    00403
    00404 protected:
    00405     mutable QMemArray<HTMLGenericFormElementImpl*> m_listItems;
    00406     short m_minwidth;
    00407     signed short m_size : 15;
    00408     bool m_multiple : 1;
    00409     bool m_recalcListItems;
    00410 };
    00411
    00412 // -------------------------------------------------------------------------
    00413
    00414 class HTMLKeygenElementImpl : public HTMLSelectElementImpl
    00415 {
    00416 public:
    00417     HTMLKeygenElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00418
    00419     virtual Id id() const;
    00420
    00421     DOMString type() const;
    00422
    00423     long selectedIndex() const;
    00424     void setSelectedIndex( long index );
    00425
    00426     // ### this is just a rough guess
    00427     virtual bool isEnumeratable() const { return false; }
    00428
    00429     virtual void parseAttribute(AttributeImpl *attr);
    00430     virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
    00431
    00432 };
    00433
    00434 // -------------------------------------------------------------------------
    00435
    00436 class HTMLOptGroupElementImpl : public HTMLGenericFormElementImpl
    00437 {
    00438 public:
    00439     HTMLOptGroupElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0)
    00440         : HTMLGenericFormElementImpl(doc, f) {}
    00441
    00442     virtual Id id() const;
    00443 };
    00444
    00445
    00446 // ---------------------------------------------------------------------------
    00447
    00448 class HTMLOptionElementImpl : public HTMLGenericFormElementImpl
    00449 {
    00450     friend class khtml::RenderSelect;
    00451     friend class DOM::HTMLSelectElementImpl;
    00452
    00453 public:
    00454     HTMLOptionElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00455
    00456     virtual Id id() const;
    00457
    00458     DOMString text() const;
    00459
    00460     long index() const;
    00461     void setIndex( long );
    00462     virtual void parseAttribute(AttributeImpl *attr);
    00463     DOMString value() const;
    00464     void setValue(DOMStringImpl* value);
    00465
    00466     bool selected() const { return m_selected; }
    00467     void setSelected(bool _selected);
    00468
    00469     HTMLSelectElementImpl *getSelect() const;
    00470
    00471 protected:
    00472     DOMString m_value;
    00473     bool m_selected;
    00474 };
    00475
    00476
    00477 // -------------------------------------------------------------------------
    00478
    00479 class HTMLTextAreaElementImpl : public HTMLGenericFormElementImpl
    00480 {
    00481     friend class khtml::RenderTextArea;
    00482
    00483 public:
    00484     enum WrapMethod {
    00485         ta_NoWrap,
    00486         ta_Virtual,
    00487         ta_Physical
    00488     };
    00489
    00490     HTMLTextAreaElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00491     ~HTMLTextAreaElementImpl();
    00492
    00493     virtual Id id() const;
    00494
    00495     long cols() const { return m_cols; }
    00496
    00497     long rows() const { return m_rows; }
    00498
    00499     WrapMethod wrap() const { return m_wrap; }
    00500
    00501     virtual bool isEnumeratable() const { return true; }
    00502
    00503     DOMString type() const;
    00504
    00505     virtual bool maintainsState() { return true; }
    00506     virtual QString state();
    00507     virtual void restoreState(const QString &);
    00508
    00509     void select (  );
    00510
    00511     virtual void parseAttribute(AttributeImpl *attr);
    00512     virtual void attach();
    00513     virtual bool encoding(const QTextCodec*, khtml::encodingList&, bool);
    00514     virtual void reset();
    00515     DOMString value();
    00516     void setValue(DOMString _value);
    00517     DOMString defaultValue();
    00518     void setDefaultValue(DOMString _defaultValue);
    00519     void blur();
    00520     void focus();
    00521
    00522     virtual bool isEditable();
    00523
    00524 protected:
    00525     int m_rows;
    00526     int m_cols;
    00527     WrapMethod m_wrap;
    00528     QString m_value;
    00529     bool m_dirtyvalue;
    00530 };
    00531
    00532 // -------------------------------------------------------------------------
    00533
    00534 class HTMLIsIndexElementImpl : public HTMLInputElementImpl
    00535 {
    00536 public:
    00537     HTMLIsIndexElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
    00538     ~HTMLIsIndexElementImpl();
    00539
    00540     virtual Id id() const;
    00541     virtual void parseAttribute(AttributeImpl *attr);
    00542
    00543     DOMString prompt() const;
    00544     void setPrompt(const DOMString& _value);
    00545 };
    00546
    00547
    00548 } //namespace
    00549
    00550 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:53 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001