1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
/*
* This file is part of the DOM implementation for KDE.
*
* Copyright (C) 1999 Lars Knoll ([email protected])
* (C) 1999 Antti Koivisto ([email protected])
* (C) 2000 Dirk Mueller ([email protected])
* (C) 2004, 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef HTML_FORMIMPL_H
#define HTML_FORMIMPL_H
#include "html/html_elementimpl.h"
#include "html/html_imageimpl.h"
#include "dom/html_element.h"
#include <tqvaluelist.h>
#include <tqptrlist.h>
#include <tqcstring.h>
#include <tqmemarray.h>
class TDEHTMLView;
class TQTextCodec;
namespace tdehtml
{
class RenderFormElement;
class RenderTextArea;
class RenderSelect;
class RenderLineEdit;
class RenderRadioButton;
class RenderFileButton;
typedef TQValueList<TQCString> encodingList;
}
namespace TDEWallet {
class Wallet;
}
namespace DOM {
class HTMLFormElement;
class DOMString;
class HTMLGenericFormElementImpl;
class HTMLOptionElementImpl;
// -------------------------------------------------------------------------
class HTMLFormElementImpl : public HTMLElementImpl
{
public:
HTMLFormElementImpl(DocumentImpl *doc, bool implicit);
virtual ~HTMLFormElementImpl();
virtual Id id() const;
virtual void insertedIntoDocument();
virtual void removedFromDocument();
virtual void addId(const TQString& id);
virtual void removeId(const TQString& id);
long length() const;
TQByteArray formData(bool& ok);
DOMString enctype() const { return m_enctype; }
void setEnctype( const DOMString & );
bool autoComplete() const { return m_autocomplete; }
void doAutoFill();
void walletOpened(TDEWallet::Wallet *w);
virtual void parseAttribute(AttributeImpl *attr);
void radioClicked( HTMLGenericFormElementImpl *caller );
void registerFormElement(HTMLGenericFormElementImpl *);
void removeFormElement(HTMLGenericFormElementImpl *);
void registerImgElement(HTMLImageElementImpl *);
void removeImgElement(HTMLImageElementImpl *);
void submitFromKeyboard();
bool prepareSubmit();
void submit();
void reset();
void setMalformed(bool malformed) { m_malformed = malformed; }
bool isMalformed() const { return m_malformed; }
friend class HTMLFormElement;
friend class HTMLFormCollectionImpl;
private:
void gatherWalletData();
TQPtrList<HTMLGenericFormElementImpl> formElements;
TQPtrList<HTMLImageElementImpl> imgElements;
DOMString m_target;
DOMString m_enctype;
TQString m_boundary;
DOMString m_acceptcharset;
TQString m_encCharset;
bool m_post : 1;
bool m_multipart : 1;
bool m_autocomplete : 1;
bool m_insubmit : 1;
bool m_doingsubmit : 1;
bool m_inreset : 1;
bool m_malformed : 1;
bool m_haveTextarea : 1; // for wallet storage
bool m_havePassword : 1; // for wallet storage
DOMString m_name; // our name
TQMap<TQString, TQString> m_walletMap; // for wallet storage
};
// -------------------------------------------------------------------------
class HTMLGenericFormElementImpl : public HTMLElementImpl
{
friend class HTMLFormElementImpl;
friend class tdehtml::RenderFormElement;
public:
HTMLGenericFormElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual ~HTMLGenericFormElementImpl();
HTMLFormElementImpl *form() { return m_form; }
virtual void parseAttribute(AttributeImpl *attr);
virtual void attach();
virtual void reset() {}
virtual void insertedIntoDocument();
virtual void removedFromDocument();
void onSelect();
void onChange();
bool disabled() const { return m_disabled; }
void setDisabled(bool _disabled);
virtual bool isFocusable() const;
virtual bool isEnumeratable() const { return false; }
bool readOnly() const { return m_readOnly; }
void setReadOnly(bool _readOnly) { m_readOnly = _readOnly; }
DOMString name() const;
void setName(const DOMString& name);
virtual bool isGenericFormElement() const { return true; }
/*
* override in derived classes to get the encoded name=value pair
* for submitting
* return true for a successful control (see HTML4-17.13.2)
*/
virtual bool encoding(const TQTextCodec*, tdehtml::encodingList&, bool) { return false; }
virtual void defaultEventHandler(EventImpl *evt);
virtual bool isEditable();
protected:
HTMLFormElementImpl *getForm() const;
DOMStringImpl* m_name;
HTMLFormElementImpl *m_form;
bool m_disabled, m_readOnly;
};
// -------------------------------------------------------------------------
class HTMLButtonElementImpl : public HTMLGenericFormElementImpl
{
public:
HTMLButtonElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual ~HTMLButtonElementImpl();
enum typeEnum {
SUBMIT,
RESET,
BUTTON
};
virtual Id id() const;
virtual bool isEnumeratable() const { return true; }
DOMString type() const;
typeEnum buttonType() const { return m_type; }
virtual void parseAttribute(AttributeImpl *attr);
virtual void defaultEventHandler(EventImpl *evt);
virtual bool encoding(const TQTextCodec*, tdehtml::encodingList&, bool);
void activate();
virtual void attach();
void click();
void blur();
void focus();
protected:
DOMString m_value;
TQString m_currValue;
typeEnum m_type : 2;
bool m_dirty : 1;
bool m_clicked : 1;
bool m_activeSubmit : 1;
};
// -------------------------------------------------------------------------
class HTMLFieldSetElementImpl : public HTMLGenericFormElementImpl
{
public:
HTMLFieldSetElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual ~HTMLFieldSetElementImpl();
virtual Id id() const;
virtual void attach();
virtual void parseAttribute(AttributeImpl *attr);
};
// -------------------------------------------------------------------------
class HTMLInputElementImpl : public HTMLGenericFormElementImpl
{
friend class tdehtml::RenderLineEdit;
friend class tdehtml::RenderRadioButton;
friend class tdehtml::RenderFileButton;
public:
// do not change the order!
enum typeEnum {
TEXT,
PASSWORD,
ISINDEX,
CHECKBOX,
RADIO,
SUBMIT,
RESET,
FILE,
HIDDEN,
IMAGE,
BUTTON
};
HTMLInputElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual ~HTMLInputElementImpl();
virtual Id id() const;
virtual bool isEnumeratable() const { return inputType() != IMAGE; }
bool autoComplete() const { return m_autocomplete; }
bool checked() const { return m_useDefaultChecked ? m_defaultChecked : m_checked; }
void setChecked(bool);
bool indeterminate() const { return m_indeterminate; }
void setIndeterminate(bool);
long maxLength() const { return m_maxLen; }
int size() const { return m_size; }
DOMString type() const;
void setType(const DOMString& t);
DOMString value() const;
void setValue(DOMString val);
DOMString valueWithDefault() const;
void blur();
void focus();
virtual bool maintainsState() { return true; }
virtual TQString state();
virtual void restoreState(const TQString &state);
void select();
void click();
virtual void parseAttribute(AttributeImpl *attr);
virtual void attach();
virtual bool encoding(const TQTextCodec*, tdehtml::encodingList&, bool);
typeEnum inputType() const { return m_type; }
virtual void reset();
// used in case input type=image was clicked.
int clickX() const { return xPos; }
int clickY() const { return yPos; }
virtual void defaultEventHandler(EventImpl *evt);
virtual bool isEditable();
DOMString altText() const;
void activate();
void setUnsubmittedFormChange(bool unsubmitted) { m_unsubmittedFormChange = unsubmitted; }
//Mozilla extensions.
long selectionStart();
long selectionEnd();
void setSelectionStart(long pos);
void setSelectionEnd (long pos);
void setSelectionRange(long start, long end);
protected:
void parseType(const DOMString& t);
DOMString m_value;
int xPos;
short m_maxLen;
short m_size;
short yPos;
typeEnum m_type : 4;
bool m_clicked : 1 ;
bool m_checked : 1;
bool m_defaultChecked : 1; // could do without by checking ATTR_CHECKED
bool m_useDefaultChecked : 1;
bool m_indeterminate : 1;
bool m_haveType : 1;
bool m_activeSubmit : 1;
bool m_autocomplete : 1;
bool m_inited : 1;
bool m_unsubmittedFormChange : 1;
};
// -------------------------------------------------------------------------
class HTMLLabelElementImpl : public HTMLGenericFormElementImpl
{
public:
HTMLLabelElementImpl(DocumentImpl *doc);
virtual ~HTMLLabelElementImpl();
virtual Id id() const;
virtual void attach();
virtual void defaultEventHandler(EventImpl *evt);
virtual bool isFocusable() const { return true; };
virtual bool isTabFocusable() const { return false; };
NodeImpl* getFormElement();
private:
DOMString m_formElementID;
};
// -------------------------------------------------------------------------
class HTMLLegendElementImpl : public HTMLGenericFormElementImpl
{
public:
HTMLLegendElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual ~HTMLLegendElementImpl();
virtual Id id() const;
virtual void attach();
virtual void parseAttribute(AttributeImpl *attr);
};
// -------------------------------------------------------------------------
class HTMLSelectElementImpl : public HTMLGenericFormElementImpl
{
friend class tdehtml::RenderSelect;
public:
HTMLSelectElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
~HTMLSelectElementImpl();
virtual Id id() const;
DOMString type() const;
long selectedIndex() const;
void setSelectedIndex( long index );
virtual bool isEnumeratable() const { return true; }
long length() const;
long minWidth() const { return m_minwidth; }
long size() const { return m_size; }
bool multiple() const { return m_multiple; }
void add ( const HTMLElement &element, const HTMLElement &before, int& exceptioncode );
void remove ( long index );
void blur();
void focus();
DOMString value() const;
void setValue(DOMStringImpl* value);
virtual bool maintainsState() { return true; }
virtual TQString state();
virtual void restoreState(const TQString &state);
virtual NodeImpl *insertBefore ( NodeImpl *newChild, NodeImpl *refChild, int &exceptioncode );
virtual void replaceChild ( NodeImpl *newChild, NodeImpl *oldChild, int &exceptioncode );
virtual void removeChild ( NodeImpl *oldChild, int &exceptioncode );
virtual NodeImpl *appendChild ( NodeImpl *newChild, int &exceptioncode );
virtual NodeImpl *addChild( NodeImpl* newChild );
virtual void childrenChanged();
virtual void parseAttribute(AttributeImpl *attr);
virtual void attach();
virtual bool encoding(const TQTextCodec*, tdehtml::encodingList&, bool);
// get the actual listbox index of the optionIndexth option
int optionToListIndex(int optionIndex) const;
// reverse of optionToListIndex - get optionIndex from listboxIndex
int listToOptionIndex(int listIndex) const;
void setRecalcListItems();
TQMemArray<HTMLGenericFormElementImpl*> listItems() const
{
if (m_recalcListItems) const_cast<HTMLSelectElementImpl*>(this)->recalcListItems();
return m_listItems;
}
virtual void reset();
void notifyOptionSelected(HTMLOptionElementImpl *selectedOption, bool selected);
private:
void recalcListItems() const;
protected:
mutable TQMemArray<HTMLGenericFormElementImpl*> m_listItems;
short m_minwidth;
signed short m_size : 15;
bool m_multiple : 1;
mutable bool m_recalcListItems :1;
mutable unsigned int m_length:31;
};
// -------------------------------------------------------------------------
class HTMLKeygenElementImpl : public HTMLSelectElementImpl
{
public:
HTMLKeygenElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual Id id() const;
DOMString type() const;
long selectedIndex() const;
void setSelectedIndex( long index );
// ### this is just a rough guess
virtual bool isEnumeratable() const { return false; }
virtual void parseAttribute(AttributeImpl *attr);
virtual bool encoding(const TQTextCodec*, tdehtml::encodingList&, bool);
};
// -------------------------------------------------------------------------
class HTMLOptGroupElementImpl : public HTMLGenericFormElementImpl
{
public:
HTMLOptGroupElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0)
: HTMLGenericFormElementImpl(doc, f) {}
virtual Id id() const;
};
// ---------------------------------------------------------------------------
class HTMLOptionElementImpl : public HTMLGenericFormElementImpl
{
friend class tdehtml::RenderSelect;
friend class DOM::HTMLSelectElementImpl;
public:
HTMLOptionElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
virtual Id id() const;
DOMString text() const;
long index() const;
void setIndex( long );
virtual void parseAttribute(AttributeImpl *attr);
DOMString value() const;
void setValue(DOMStringImpl* value);
bool selected() const { return m_selected; }
void setSelected(bool _selected);
HTMLSelectElementImpl *getSelect() const;
protected:
DOMString m_value;
bool m_selected;
};
// -------------------------------------------------------------------------
class HTMLTextAreaElementImpl : public HTMLGenericFormElementImpl
{
friend class tdehtml::RenderTextArea;
public:
enum WrapMethod {
ta_NoWrap,
ta_Virtual,
ta_Physical
};
HTMLTextAreaElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
~HTMLTextAreaElementImpl();
virtual Id id() const;
long cols() const { return m_cols; }
long rows() const { return m_rows; }
WrapMethod wrap() const { return m_wrap; }
virtual bool isEnumeratable() const { return true; }
DOMString type() const;
virtual bool maintainsState() { return true; }
virtual TQString state();
virtual void restoreState(const TQString &state);
void select ( );
virtual void parseAttribute(AttributeImpl *attr);
virtual void attach();
virtual bool encoding(const TQTextCodec*, tdehtml::encodingList&, bool);
virtual void reset();
DOMString value();
void setValue(DOMString _value);
DOMString defaultValue();
void setDefaultValue(DOMString _defaultValue);
void blur();
void focus();
virtual bool isEditable();
void setUnsubmittedFormChange(bool unsubmitted) { m_unsubmittedFormChange = unsubmitted; }
//Mozilla extensions.
long selectionStart();
long selectionEnd();
void setSelectionStart(long pos);
void setSelectionEnd (long pos);
void setSelectionRange(long start, long end);
long textLength();
protected:
int m_rows;
int m_cols;
WrapMethod m_wrap;
TQString m_value;
bool m_changed: 1; //States whether the contents has been editted
bool m_dirtyvalue: 1; //States whether m_value is out-of-date compared to the renderer or default
bool m_unsubmittedFormChange: 1;
bool m_initialized: 1;
};
// -------------------------------------------------------------------------
class HTMLIsIndexElementImpl : public HTMLInputElementImpl
{
public:
HTMLIsIndexElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f = 0);
~HTMLIsIndexElementImpl();
virtual Id id() const;
virtual void parseAttribute(AttributeImpl *attr);
DOMString prompt() const;
void setPrompt(const DOMString& _value);
};
} //namespace
#endif
|