KHtml

render_form.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1999-2003 Lars Knoll ([email protected])
5  * (C) 1999 Antti Koivisto ([email protected])
6  * (C) 2000-2003 Dirk Mueller ([email protected])
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 #ifndef RENDER_FORM_H
25 #define RENDER_FORM_H
26 
27 #include "rendering/render_replaced.h"
28 #include "rendering/render_image.h"
29 #include "rendering/render_flow.h"
30 #include "rendering/render_style.h"
31 #include "khtmlview.h"
32 #include "html/html_formimpl.h"
33 
34 class QWidget;
35 
36 #include <ktextedit.h>
37 #include <kurlrequester.h>
38 #include <klineedit.h>
39 #include <QCheckBox>
40 #include <QRadioButton>
41 #include <QPushButton>
42 #include <QListWidget>
43 #include <QProxyStyle>
44 #include <kcombobox.h>
45 #include "dom/dom_misc.h"
46 
47 class QAction;
48 class KUrlRequester;
49 
50 namespace DOM
51 {
52 class HTMLInputElementImpl;
53 class HTMLSelectElementImpl;
54 class HTMLGenericFormElementImpl;
55 class HTMLTextAreaElementImpl;
56 }
57 
58 namespace khtml
59 {
60 
61 // -------------------------------------------------------------------------
62 
63 class RenderFormElement : public khtml::RenderWidget
64 {
65 public:
66  RenderFormElement(DOM::HTMLGenericFormElementImpl *node);
67  virtual ~RenderFormElement();
68 
69  const char *renderName() const override
70  {
71  return "RenderForm";
72  }
73  void setStyle(RenderStyle *style) override;
74 
75  bool isFormElement() const override
76  {
77  return true;
78  }
79 
80  // form elements apply the padding themselves, so
81  // the rest of the layout should disregard it
82  int paddingTop() const override;
83  int paddingBottom() const override;
84  int paddingLeft() const override;
85  int paddingRight() const override;
86 
87  // some widgets don't apply padding, and thus it is ignored
88  // entirely, this function allows them to opt out
89  bool includesPadding() const override;
90 
91  void updateFromElement() override;
92 
93  void layout() override;
94  void calcWidth() override;
95  void calcHeight() override;
96  void calcMinMaxWidth() override;
97  short baselinePosition(bool) const override;
98  int calcContentWidth(int w) const override;
99  int calcContentHeight(int h) const override;
100 
101  DOM::HTMLGenericFormElementImpl *element() const
102  {
103  return static_cast<DOM::HTMLGenericFormElementImpl *>(RenderObject::element());
104  }
105 
106  // this is not a virtual function
107  void setQWidget(QWidget *w);
108 
109 protected:
110  virtual bool isRenderButton() const
111  {
112  return false;
113  }
114  bool isEditable() const override
115  {
116  return false;
117  }
118  virtual void setPadding();
119  void paintOneBackground(QPainter *p, const QColor &c, const BackgroundLayer *bgLayer, QRect clipr, int _tx, int _ty, int w, int height) override;
120 
121  Qt::Alignment textAlignment() const;
122  QProxyStyle *getProxyStyle();
123  QProxyStyle *m_proxyStyle;
124  bool m_exposeInternalPadding;
125  bool m_isOxygenStyle;
126 };
127 
128 // -------------------------------------------------------------------------
129 
130 // generic class for all buttons
131 class RenderButton : public RenderFormElement
132 {
133  Q_OBJECT
134 public:
135  RenderButton(DOM::HTMLGenericFormElementImpl *node);
136 
137  const char *renderName() const override
138  {
139  return "RenderButton";
140  }
141 
142  void layout() override;
143  short baselinePosition(bool) const override;
144  void setStyle(RenderStyle *style) override;
145  bool forceTransparentText() const override
146  {
147  return m_hasTextIndentHack;
148  }
149 
150  // don't even think about making this method virtual!
151  DOM::HTMLInputElementImpl *element() const
152  {
153  return static_cast<DOM::HTMLInputElementImpl *>(RenderObject::element());
154  }
155 
156 protected:
157  bool isRenderButton() const override
158  {
159  return true;
160  }
161 
162  bool m_hasTextIndentHack;
163 };
164 
165 // -------------------------------------------------------------------------
166 
167 class CheckBoxWidget: public QCheckBox, public KHTMLWidget
168 {
169 public:
170  CheckBoxWidget(QWidget *p): QCheckBox(p)
171  {
172  m_kwp->setIsRedirected(true);
173  }
174 };
175 
176 class RenderCheckBox : public RenderButton
177 {
178  Q_OBJECT
179 public:
180  RenderCheckBox(DOM::HTMLInputElementImpl *node);
181 
182  const char *renderName() const override
183  {
184  return "RenderCheckBox";
185  }
186  void updateFromElement() override;
187  void calcMinMaxWidth() override;
188 
189  bool handleEvent(const DOM::EventImpl &) override;
190 
191  QCheckBox *widget() const
192  {
193  return static_cast<QCheckBox *>(m_widget);
194  }
195 protected:
196  bool includesPadding() const override
197  {
198  return false;
199  }
200 public Q_SLOTS:
201  virtual void slotStateChanged(int state);
202 private:
203  bool m_ignoreStateChanged;
204 };
205 
206 // -------------------------------------------------------------------------
207 
208 class RadioButtonWidget: public QRadioButton, public KHTMLWidget
209 {
210 public:
211  RadioButtonWidget(QWidget *p): QRadioButton(p)
212  {
213  m_kwp->setIsRedirected(true);
214  }
215 };
216 
217 class RenderRadioButton : public RenderButton
218 {
219  Q_OBJECT
220 public:
221  RenderRadioButton(DOM::HTMLInputElementImpl *node);
222 
223  const char *renderName() const override
224  {
225  return "RenderRadioButton";
226  }
227 
228  void calcMinMaxWidth() override;
229  void updateFromElement() override;
230 
231  bool handleEvent(const DOM::EventImpl &) override;
232 
233  QRadioButton *widget() const
234  {
235  return static_cast<QRadioButton *>(m_widget);
236  }
237 protected:
238  bool includesPadding() const override
239  {
240  return false;
241  }
242 public Q_SLOTS:
243  virtual void slotToggled(bool);
244 private:
245  bool m_ignoreToggled;
246 };
247 
248 // -------------------------------------------------------------------------
249 
250 class PushButtonWidget: public QPushButton, public KHTMLWidget
251 {
252 public:
253  PushButtonWidget(QWidget *p): QPushButton(p)
254  {
255  m_kwp->setIsRedirected(true);
256  }
257 };
258 
259 class RenderSubmitButton : public RenderButton
260 {
261 public:
262  RenderSubmitButton(DOM::HTMLInputElementImpl *element);
263 
264  const char *renderName() const override
265  {
266  return "RenderSubmitButton";
267  }
268 
269  void calcMinMaxWidth() override;
270  void updateFromElement() override;
271  short baselinePosition(bool) const override;
272 protected:
273  void setPadding() override;
274  void setStyle(RenderStyle *style) override;
275  bool canHaveBorder() const override;
276 private:
277  QString rawText();
278 };
279 
280 // -------------------------------------------------------------------------
281 
282 class RenderImageButton : public RenderImage
283 {
284 public:
285  RenderImageButton(DOM::HTMLInputElementImpl *element)
286  : RenderImage(element) {}
287 
288  const char *renderName() const override
289  {
290  return "RenderImageButton";
291  }
292 };
293 
294 // -------------------------------------------------------------------------
295 
296 class RenderResetButton : public RenderSubmitButton
297 {
298 public:
299  RenderResetButton(DOM::HTMLInputElementImpl *element);
300 
301  const char *renderName() const override
302  {
303  return "RenderResetButton";
304  }
305 
306 };
307 
308 // -------------------------------------------------------------------------
309 
310 class RenderPushButton : public RenderSubmitButton
311 {
312 public:
313  RenderPushButton(DOM::HTMLInputElementImpl *element)
314  : RenderSubmitButton(element) {}
315 
316 };
317 
318 // -------------------------------------------------------------------------
319 
320 class RenderLineEdit : public RenderFormElement
321 {
322  Q_OBJECT
323 public:
324  RenderLineEdit(DOM::HTMLInputElementImpl *element);
325 
326  void calcMinMaxWidth() override;
327 
328  const char *renderName() const override
329  {
330  return "RenderLineEdit";
331  }
332  void updateFromElement() override;
333  void setStyle(RenderStyle *style) override;
334  short baselinePosition(bool) const override;
335  void handleFocusOut() override;
336 
337  void select();
338 
339  KLineEdit *widget() const
340  {
341  return static_cast<KLineEdit *>(m_widget);
342  }
343  DOM::HTMLInputElementImpl *element() const
344  {
345  return static_cast<DOM::HTMLInputElementImpl *>(RenderObject::element());
346  }
347  void highLightWord(unsigned int length, unsigned int pos);
348 
349  long selectionStart();
350  long selectionEnd();
351  void setSelectionStart(long pos);
352  void setSelectionEnd(long pos);
353  void setSelectionRange(long start, long end);
354 public Q_SLOTS:
355  void slotReturnPressed();
356  void slotTextChanged(const QString &string);
357 protected:
358  bool canHaveBorder() const override
359  {
360  return true;
361  }
362 private:
363  bool isEditable() const override
364  {
365  return true;
366  }
367  bool m_blockElementUpdates;
368 };
369 
370 // -------------------------------------------------------------------------
371 
372 class LineEditWidget : public KLineEdit, public KHTMLWidget
373 {
374  Q_OBJECT
375 public:
376  LineEditWidget(DOM::HTMLInputElementImpl *input,
377  KHTMLView *view, QWidget *parent);
378  ~LineEditWidget();
379  void setFocus();
380  void highLightWord(unsigned int length, unsigned int pos);
381 
382 protected:
383  bool event(QEvent *e) override;
384  void mouseMoveEvent(QMouseEvent *e) override;
385  void contextMenuEvent(QContextMenuEvent *e) override;
386 private Q_SLOTS:
387  void clearHistoryActivated();
388  void slotCheckSpelling();
389  void slotSpellCheckDone(const QString &s);
390  void slotCreateWebShortcut();
391  void spellCheckerMisspelling(const QString &text, int pos);
392  void spellCheckerCorrected(const QString &, int, const QString &);
393  void spellCheckerFinished();
394 
395 private:
396  enum LineEditMenuID {
397  ClearHistory
398  };
399  DOM::HTMLInputElementImpl *m_input;
400  KHTMLView *m_view;
401  QAction *m_spellAction;
402 };
403 
404 // -------------------------------------------------------------------------
405 
406 class RenderFieldset : public RenderBlock
407 {
408 public:
409  RenderFieldset(DOM::HTMLGenericFormElementImpl *element);
410 
411  void calcMinMaxWidth() override;
412  const char *renderName() const override
413  {
414  return "RenderFieldSet";
415  }
416  RenderObject *layoutLegend(bool relayoutChildren) override;
417  void setStyle(RenderStyle *_style) override;
418 
419 protected:
420  void paintBoxDecorations(PaintInfo &pI, int _tx, int _ty) override;
421  void paintBorderMinusLegend(QPainter *p, int _tx, int _ty, int w,
422  int h, const RenderStyle *style, int lx, int lw, int lb);
423  RenderObject *findLegend() const;
424  short intrinsicWidth() const override
425  {
426  return m_intrinsicWidth;
427  }
428  int m_intrinsicWidth;
429 };
430 
431 // -------------------------------------------------------------------------
432 
433 class FileButtonWidget: public KUrlRequester, public KHTMLWidget
434 {
435 public:
436  FileButtonWidget(QWidget *p): KUrlRequester(p)
437  {
438  m_kwp->setIsRedirected(true);
439  }
440 };
441 
442 class RenderFileButton : public RenderFormElement
443 {
444  Q_OBJECT
445 public:
446  RenderFileButton(DOM::HTMLInputElementImpl *element);
447 
448  const char *renderName() const override
449  {
450  return "RenderFileButton";
451  }
452  void calcMinMaxWidth() override;
453  void updateFromElement() override;
454  short baselinePosition(bool) const override;
455  void select();
456 
457  KUrlRequester *widget() const
458  {
459  return static_cast<KUrlRequester *>(m_widget);
460  }
461 
462  DOM::HTMLInputElementImpl *element() const
463  {
464  return static_cast<DOM::HTMLInputElementImpl *>(RenderObject::element());
465  }
466 
467 public Q_SLOTS:
468  void slotReturnPressed();
469  void slotTextChanged(const QString &string);
470  void slotUrlSelected();
471 
472 protected:
473  void handleFocusOut() override;
474 
475  bool isEditable() const override
476  {
477  return true;
478  }
479  bool acceptsSyntheticEvents() const override
480  {
481  return false;
482  }
483 
484  bool includesPadding() const override
485  {
486  return false;
487  }
488 
489  bool m_clicked;
490  bool m_haveFocus;
491 };
492 
493 // -------------------------------------------------------------------------
494 
495 class RenderLabel : public RenderFormElement
496 {
497 public:
498  RenderLabel(DOM::HTMLGenericFormElementImpl *element);
499 
500  const char *renderName() const override
501  {
502  return "RenderLabel";
503  }
504 
505 protected:
506  bool canHaveBorder() const override
507  {
508  return true;
509  }
510 };
511 
512 // -------------------------------------------------------------------------
513 
514 class RenderLegend : public RenderBlock
515 {
516 public:
517  RenderLegend(DOM::HTMLGenericFormElementImpl *element);
518 
519  const char *renderName() const override
520  {
521  return "RenderLegend";
522  }
523 };
524 
525 // -------------------------------------------------------------------------
526 
527 class ComboBoxWidget : public KComboBox, public KHTMLWidget
528 {
529 public:
530  ComboBoxWidget(QWidget *parent);
531 
532 protected:
533  bool event(QEvent *) override;
534  bool eventFilter(QObject *dest, QEvent *e) override;
535  void keyPressEvent(QKeyEvent *e) override;
536  void showPopup() override;
537  void hidePopup() override;
538 };
539 
540 // -------------------------------------------------------------------------
541 
542 class ListBoxWidget: public QListWidget, public KHTMLWidget
543 {
544 public:
545  ListBoxWidget(QWidget *p): QListWidget(p)
546  {
547  m_kwp->setIsRedirected(true);
548  }
549 protected:
550  void scrollContentsBy(int, int) override
551  {
552  viewport()->update();
553  }
554  bool event(QEvent *event) override;
555 };
556 
557 class RenderSelect : public RenderFormElement
558 {
559  Q_OBJECT
560 public:
561  RenderSelect(DOM::HTMLSelectElementImpl *element);
562 
563  const char *renderName() const override
564  {
565  return "RenderSelect";
566  }
567 
568  void calcMinMaxWidth() override;
569  void layout() override;
570 
571  void setOptionsChanged(bool _optionsChanged);
572 
573  bool selectionChanged()
574  {
575  return m_selectionChanged;
576  }
577  void setSelectionChanged(bool _selectionChanged)
578  {
579  m_selectionChanged = _selectionChanged;
580  }
581  void setStyle(RenderStyle *_style) override;
582  void updateFromElement() override;
583  short baselinePosition(bool) const override;
584 
585  void updateSelection();
586 
587  DOM::HTMLSelectElementImpl *element() const
588  {
589  return static_cast<DOM::HTMLSelectElementImpl *>(RenderObject::element());
590  }
591 
592 protected:
593  void setPadding() override;
594  ListBoxWidget *createListBox();
595  ComboBoxWidget *createComboBox();
596 
597  unsigned m_size;
598  bool m_multiple;
599  bool m_useListBox;
600  bool m_selectionChanged;
601  bool m_ignoreSelectEvents;
602  bool m_optionsChanged;
603 
604  void clearItemFlags(int index, Qt::ItemFlags flags);
605  bool canHaveBorder() const override
606  {
607  return true;
608  }
609 
610 protected Q_SLOTS:
611  void slotSelected(int index);
612  void slotSelectionChanged();
613 };
614 
615 // -------------------------------------------------------------------------
616 class TextAreaWidget : public KTextEdit, public KHTMLWidget
617 {
618  Q_OBJECT
619 public:
620  TextAreaWidget(int wrap, QWidget *parent);
621  virtual ~TextAreaWidget();
622 
623 protected:
624  bool event(QEvent *e) override;
625  void keyPressEvent(QKeyEvent *e) override;
626  void scrollContentsBy(int dx, int dy) override;
627 
628 };
629 
630 // -------------------------------------------------------------------------
631 
632 class RenderTextArea : public RenderFormElement
633 {
634  Q_OBJECT
635 public:
636  RenderTextArea(DOM::HTMLTextAreaElementImpl *element);
637  ~RenderTextArea();
638 
639  const char *renderName() const override
640  {
641  return "RenderTextArea";
642  }
643  void calcMinMaxWidth() override;
644  void setStyle(RenderStyle *style) override;
645 
646  short scrollWidth() const override;
647  int scrollHeight() const override;
648 
649  void updateFromElement() override;
650 
651  // don't even think about making this method virtual!
652  TextAreaWidget *widget() const
653  {
654  return static_cast<TextAreaWidget *>(m_widget);
655  }
656  DOM::HTMLTextAreaElementImpl *element() const
657  {
658  return static_cast<DOM::HTMLTextAreaElementImpl *>(RenderObject::element());
659  }
660 
661  QString text();
662  void setText(const QString &text);
663 
664  void highLightWord(unsigned int length, unsigned int pos);
665 
666  void select();
667 
668  long selectionStart();
669  long selectionEnd();
670  void setSelectionStart(long pos);
671  void setSelectionEnd(long pos);
672  void setSelectionRange(long start, long end);
673 protected Q_SLOTS:
674  void slotTextChanged();
675 
676 protected:
677  void handleFocusOut() override;
678 
679  bool isEditable() const override
680  {
681  return true;
682  }
683  bool canHaveBorder() const override
684  {
685  return true;
686  }
687 
688  Qt::Alignment m_textAlignment;
689 };
690 
691 // -------------------------------------------------------------------------
692 
693 class ScrollBarWidget: public QScrollBar, public KHTMLWidget
694 {
695 public:
696  ScrollBarWidget(QWidget *parent = nullptr): QScrollBar(parent)
697  {
698  m_kwp->setIsRedirected(true);
699  }
700  ScrollBarWidget(Qt::Orientation orientation, QWidget *parent = nullptr): QScrollBar(orientation, parent)
701  {
702  m_kwp->setIsRedirected(true);
703  }
704 };
705 
706 } //namespace
707 
708 #endif
This file is part of the HTML rendering engine for KDE.
Renders and displays HTML in a QScrollArea.
Definition: khtmlview.h:97
typedef Alignment
void update(const QModelIndex &index)
This library provides a full-featured HTML parser and widget.
Orientation
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.