Warning, file /frameworks/khtml/src/rendering/render_form.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * This file is part of the DOM implementation for KDE. 0003 * 0004 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 0005 * (C) 1999 Antti Koivisto (koivisto@kde.org) 0006 * (C) 2000-2003 Dirk Mueller (mueller@kde.org) 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Library General Public 0010 * License as published by the Free Software Foundation; either 0011 * version 2 of the License, or (at your option) any later version. 0012 * 0013 * This library is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Library General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Library General Public License 0019 * along with this library; see the file COPYING.LIB. If not, write to 0020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 * 0023 */ 0024 #ifndef RENDER_FORM_H 0025 #define RENDER_FORM_H 0026 0027 #include "rendering/render_replaced.h" 0028 #include "rendering/render_image.h" 0029 #include "rendering/render_flow.h" 0030 #include "rendering/render_style.h" 0031 #include "khtmlview.h" 0032 #include "html/html_formimpl.h" 0033 0034 class QWidget; 0035 0036 #include <ktextedit.h> 0037 #include <kurlrequester.h> 0038 #include <klineedit.h> 0039 #include <QCheckBox> 0040 #include <QRadioButton> 0041 #include <QPushButton> 0042 #include <QListWidget> 0043 #include <QProxyStyle> 0044 #include <kcombobox.h> 0045 #include "dom/dom_misc.h" 0046 0047 class QAction; 0048 class KUrlRequester; 0049 0050 namespace DOM 0051 { 0052 class HTMLInputElementImpl; 0053 class HTMLSelectElementImpl; 0054 class HTMLGenericFormElementImpl; 0055 class HTMLTextAreaElementImpl; 0056 } 0057 0058 namespace khtml 0059 { 0060 0061 // ------------------------------------------------------------------------- 0062 0063 class RenderFormElement : public khtml::RenderWidget 0064 { 0065 public: 0066 RenderFormElement(DOM::HTMLGenericFormElementImpl *node); 0067 virtual ~RenderFormElement(); 0068 0069 const char *renderName() const override 0070 { 0071 return "RenderForm"; 0072 } 0073 void setStyle(RenderStyle *style) override; 0074 0075 bool isFormElement() const override 0076 { 0077 return true; 0078 } 0079 0080 // form elements apply the padding themselves, so 0081 // the rest of the layout should disregard it 0082 int paddingTop() const override; 0083 int paddingBottom() const override; 0084 int paddingLeft() const override; 0085 int paddingRight() const override; 0086 0087 // some widgets don't apply padding, and thus it is ignored 0088 // entirely, this function allows them to opt out 0089 bool includesPadding() const override; 0090 0091 void updateFromElement() override; 0092 0093 void layout() override; 0094 void calcWidth() override; 0095 void calcHeight() override; 0096 void calcMinMaxWidth() override; 0097 short baselinePosition(bool) const override; 0098 int calcContentWidth(int w) const override; 0099 int calcContentHeight(int h) const override; 0100 0101 DOM::HTMLGenericFormElementImpl *element() const 0102 { 0103 return static_cast<DOM::HTMLGenericFormElementImpl *>(RenderObject::element()); 0104 } 0105 0106 // this is not a virtual function 0107 void setQWidget(QWidget *w); 0108 0109 protected: 0110 virtual bool isRenderButton() const 0111 { 0112 return false; 0113 } 0114 bool isEditable() const override 0115 { 0116 return false; 0117 } 0118 virtual void setPadding(); 0119 void paintOneBackground(QPainter *p, const QColor &c, const BackgroundLayer *bgLayer, QRect clipr, int _tx, int _ty, int w, int height) override; 0120 0121 Qt::Alignment textAlignment() const; 0122 QProxyStyle *getProxyStyle(); 0123 QProxyStyle *m_proxyStyle; 0124 bool m_exposeInternalPadding; 0125 bool m_isOxygenStyle; 0126 }; 0127 0128 // ------------------------------------------------------------------------- 0129 0130 // generic class for all buttons 0131 class RenderButton : public RenderFormElement 0132 { 0133 Q_OBJECT 0134 public: 0135 RenderButton(DOM::HTMLGenericFormElementImpl *node); 0136 0137 const char *renderName() const override 0138 { 0139 return "RenderButton"; 0140 } 0141 0142 void layout() override; 0143 short baselinePosition(bool) const override; 0144 void setStyle(RenderStyle *style) override; 0145 bool forceTransparentText() const override 0146 { 0147 return m_hasTextIndentHack; 0148 } 0149 0150 // don't even think about making this method virtual! 0151 DOM::HTMLInputElementImpl *element() const 0152 { 0153 return static_cast<DOM::HTMLInputElementImpl *>(RenderObject::element()); 0154 } 0155 0156 protected: 0157 bool isRenderButton() const override 0158 { 0159 return true; 0160 } 0161 0162 bool m_hasTextIndentHack; 0163 }; 0164 0165 // ------------------------------------------------------------------------- 0166 0167 class CheckBoxWidget: public QCheckBox, public KHTMLWidget 0168 { 0169 public: 0170 CheckBoxWidget(QWidget *p): QCheckBox(p) 0171 { 0172 m_kwp->setIsRedirected(true); 0173 } 0174 }; 0175 0176 class RenderCheckBox : public RenderButton 0177 { 0178 Q_OBJECT 0179 public: 0180 RenderCheckBox(DOM::HTMLInputElementImpl *node); 0181 0182 const char *renderName() const override 0183 { 0184 return "RenderCheckBox"; 0185 } 0186 void updateFromElement() override; 0187 void calcMinMaxWidth() override; 0188 0189 bool handleEvent(const DOM::EventImpl &) override; 0190 0191 QCheckBox *widget() const 0192 { 0193 return static_cast<QCheckBox *>(m_widget); 0194 } 0195 protected: 0196 bool includesPadding() const override 0197 { 0198 return false; 0199 } 0200 public Q_SLOTS: 0201 virtual void slotStateChanged(int state); 0202 private: 0203 bool m_ignoreStateChanged; 0204 }; 0205 0206 // ------------------------------------------------------------------------- 0207 0208 class RadioButtonWidget: public QRadioButton, public KHTMLWidget 0209 { 0210 public: 0211 RadioButtonWidget(QWidget *p): QRadioButton(p) 0212 { 0213 m_kwp->setIsRedirected(true); 0214 } 0215 }; 0216 0217 class RenderRadioButton : public RenderButton 0218 { 0219 Q_OBJECT 0220 public: 0221 RenderRadioButton(DOM::HTMLInputElementImpl *node); 0222 0223 const char *renderName() const override 0224 { 0225 return "RenderRadioButton"; 0226 } 0227 0228 void calcMinMaxWidth() override; 0229 void updateFromElement() override; 0230 0231 bool handleEvent(const DOM::EventImpl &) override; 0232 0233 QRadioButton *widget() const 0234 { 0235 return static_cast<QRadioButton *>(m_widget); 0236 } 0237 protected: 0238 bool includesPadding() const override 0239 { 0240 return false; 0241 } 0242 public Q_SLOTS: 0243 virtual void slotToggled(bool); 0244 private: 0245 bool m_ignoreToggled; 0246 }; 0247 0248 // ------------------------------------------------------------------------- 0249 0250 class PushButtonWidget: public QPushButton, public KHTMLWidget 0251 { 0252 public: 0253 PushButtonWidget(QWidget *p): QPushButton(p) 0254 { 0255 m_kwp->setIsRedirected(true); 0256 } 0257 }; 0258 0259 class RenderSubmitButton : public RenderButton 0260 { 0261 public: 0262 RenderSubmitButton(DOM::HTMLInputElementImpl *element); 0263 0264 const char *renderName() const override 0265 { 0266 return "RenderSubmitButton"; 0267 } 0268 0269 void calcMinMaxWidth() override; 0270 void updateFromElement() override; 0271 short baselinePosition(bool) const override; 0272 protected: 0273 void setPadding() override; 0274 void setStyle(RenderStyle *style) override; 0275 bool canHaveBorder() const override; 0276 private: 0277 QString rawText(); 0278 }; 0279 0280 // ------------------------------------------------------------------------- 0281 0282 class RenderImageButton : public RenderImage 0283 { 0284 public: 0285 RenderImageButton(DOM::HTMLInputElementImpl *element) 0286 : RenderImage(element) {} 0287 0288 const char *renderName() const override 0289 { 0290 return "RenderImageButton"; 0291 } 0292 }; 0293 0294 // ------------------------------------------------------------------------- 0295 0296 class RenderResetButton : public RenderSubmitButton 0297 { 0298 public: 0299 RenderResetButton(DOM::HTMLInputElementImpl *element); 0300 0301 const char *renderName() const override 0302 { 0303 return "RenderResetButton"; 0304 } 0305 0306 }; 0307 0308 // ------------------------------------------------------------------------- 0309 0310 class RenderPushButton : public RenderSubmitButton 0311 { 0312 public: 0313 RenderPushButton(DOM::HTMLInputElementImpl *element) 0314 : RenderSubmitButton(element) {} 0315 0316 }; 0317 0318 // ------------------------------------------------------------------------- 0319 0320 class RenderLineEdit : public RenderFormElement 0321 { 0322 Q_OBJECT 0323 public: 0324 RenderLineEdit(DOM::HTMLInputElementImpl *element); 0325 0326 void calcMinMaxWidth() override; 0327 0328 const char *renderName() const override 0329 { 0330 return "RenderLineEdit"; 0331 } 0332 void updateFromElement() override; 0333 void setStyle(RenderStyle *style) override; 0334 short baselinePosition(bool) const override; 0335 void handleFocusOut() override; 0336 0337 void select(); 0338 0339 KLineEdit *widget() const 0340 { 0341 return static_cast<KLineEdit *>(m_widget); 0342 } 0343 DOM::HTMLInputElementImpl *element() const 0344 { 0345 return static_cast<DOM::HTMLInputElementImpl *>(RenderObject::element()); 0346 } 0347 void highLightWord(unsigned int length, unsigned int pos); 0348 0349 long selectionStart(); 0350 long selectionEnd(); 0351 void setSelectionStart(long pos); 0352 void setSelectionEnd(long pos); 0353 void setSelectionRange(long start, long end); 0354 public Q_SLOTS: 0355 void slotReturnPressed(); 0356 void slotTextChanged(const QString &string); 0357 protected: 0358 bool canHaveBorder() const override 0359 { 0360 return true; 0361 } 0362 private: 0363 bool isEditable() const override 0364 { 0365 return true; 0366 } 0367 bool m_blockElementUpdates; 0368 }; 0369 0370 // ------------------------------------------------------------------------- 0371 0372 class LineEditWidget : public KLineEdit, public KHTMLWidget 0373 { 0374 Q_OBJECT 0375 public: 0376 LineEditWidget(DOM::HTMLInputElementImpl *input, 0377 KHTMLView *view, QWidget *parent); 0378 ~LineEditWidget(); 0379 void setFocus(); 0380 void highLightWord(unsigned int length, unsigned int pos); 0381 0382 protected: 0383 bool event(QEvent *e) override; 0384 void mouseMoveEvent(QMouseEvent *e) override; 0385 void contextMenuEvent(QContextMenuEvent *e) override; 0386 private Q_SLOTS: 0387 void clearHistoryActivated(); 0388 void slotCheckSpelling(); 0389 void slotSpellCheckDone(const QString &s); 0390 void slotCreateWebShortcut(); 0391 void spellCheckerMisspelling(const QString &text, int pos); 0392 void spellCheckerCorrected(const QString &, int, const QString &); 0393 void spellCheckerFinished(); 0394 0395 private: 0396 enum LineEditMenuID { 0397 ClearHistory 0398 }; 0399 DOM::HTMLInputElementImpl *m_input; 0400 KHTMLView *m_view; 0401 QAction *m_spellAction; 0402 }; 0403 0404 // ------------------------------------------------------------------------- 0405 0406 class RenderFieldset : public RenderBlock 0407 { 0408 public: 0409 RenderFieldset(DOM::HTMLGenericFormElementImpl *element); 0410 0411 void calcMinMaxWidth() override; 0412 const char *renderName() const override 0413 { 0414 return "RenderFieldSet"; 0415 } 0416 RenderObject *layoutLegend(bool relayoutChildren) override; 0417 void setStyle(RenderStyle *_style) override; 0418 0419 protected: 0420 void paintBoxDecorations(PaintInfo &pI, int _tx, int _ty) override; 0421 void paintBorderMinusLegend(QPainter *p, int _tx, int _ty, int w, 0422 int h, const RenderStyle *style, int lx, int lw, int lb); 0423 RenderObject *findLegend() const; 0424 short intrinsicWidth() const override 0425 { 0426 return m_intrinsicWidth; 0427 } 0428 int m_intrinsicWidth; 0429 }; 0430 0431 // ------------------------------------------------------------------------- 0432 0433 class FileButtonWidget: public KUrlRequester, public KHTMLWidget 0434 { 0435 public: 0436 FileButtonWidget(QWidget *p): KUrlRequester(p) 0437 { 0438 m_kwp->setIsRedirected(true); 0439 } 0440 }; 0441 0442 class RenderFileButton : public RenderFormElement 0443 { 0444 Q_OBJECT 0445 public: 0446 RenderFileButton(DOM::HTMLInputElementImpl *element); 0447 0448 const char *renderName() const override 0449 { 0450 return "RenderFileButton"; 0451 } 0452 void calcMinMaxWidth() override; 0453 void updateFromElement() override; 0454 short baselinePosition(bool) const override; 0455 void select(); 0456 0457 KUrlRequester *widget() const 0458 { 0459 return static_cast<KUrlRequester *>(m_widget); 0460 } 0461 0462 DOM::HTMLInputElementImpl *element() const 0463 { 0464 return static_cast<DOM::HTMLInputElementImpl *>(RenderObject::element()); 0465 } 0466 0467 public Q_SLOTS: 0468 void slotReturnPressed(); 0469 void slotTextChanged(const QString &string); 0470 void slotUrlSelected(); 0471 0472 protected: 0473 void handleFocusOut() override; 0474 0475 bool isEditable() const override 0476 { 0477 return true; 0478 } 0479 bool acceptsSyntheticEvents() const override 0480 { 0481 return false; 0482 } 0483 0484 bool includesPadding() const override 0485 { 0486 return false; 0487 } 0488 0489 bool m_clicked; 0490 bool m_haveFocus; 0491 }; 0492 0493 // ------------------------------------------------------------------------- 0494 0495 class RenderLabel : public RenderFormElement 0496 { 0497 public: 0498 RenderLabel(DOM::HTMLGenericFormElementImpl *element); 0499 0500 const char *renderName() const override 0501 { 0502 return "RenderLabel"; 0503 } 0504 0505 protected: 0506 bool canHaveBorder() const override 0507 { 0508 return true; 0509 } 0510 }; 0511 0512 // ------------------------------------------------------------------------- 0513 0514 class RenderLegend : public RenderBlock 0515 { 0516 public: 0517 RenderLegend(DOM::HTMLGenericFormElementImpl *element); 0518 0519 const char *renderName() const override 0520 { 0521 return "RenderLegend"; 0522 } 0523 }; 0524 0525 // ------------------------------------------------------------------------- 0526 0527 class ComboBoxWidget : public KComboBox, public KHTMLWidget 0528 { 0529 public: 0530 ComboBoxWidget(QWidget *parent); 0531 0532 protected: 0533 bool event(QEvent *) override; 0534 bool eventFilter(QObject *dest, QEvent *e) override; 0535 void keyPressEvent(QKeyEvent *e) override; 0536 void showPopup() override; 0537 void hidePopup() override; 0538 }; 0539 0540 // ------------------------------------------------------------------------- 0541 0542 class ListBoxWidget: public QListWidget, public KHTMLWidget 0543 { 0544 public: 0545 ListBoxWidget(QWidget *p): QListWidget(p) 0546 { 0547 m_kwp->setIsRedirected(true); 0548 } 0549 protected: 0550 void scrollContentsBy(int, int) override 0551 { 0552 viewport()->update(); 0553 } 0554 bool event(QEvent *event) override; 0555 }; 0556 0557 class RenderSelect : public RenderFormElement 0558 { 0559 Q_OBJECT 0560 public: 0561 RenderSelect(DOM::HTMLSelectElementImpl *element); 0562 0563 const char *renderName() const override 0564 { 0565 return "RenderSelect"; 0566 } 0567 0568 void calcMinMaxWidth() override; 0569 void layout() override; 0570 0571 void setOptionsChanged(bool _optionsChanged); 0572 0573 bool selectionChanged() 0574 { 0575 return m_selectionChanged; 0576 } 0577 void setSelectionChanged(bool _selectionChanged) 0578 { 0579 m_selectionChanged = _selectionChanged; 0580 } 0581 void setStyle(RenderStyle *_style) override; 0582 void updateFromElement() override; 0583 short baselinePosition(bool) const override; 0584 0585 void updateSelection(); 0586 0587 DOM::HTMLSelectElementImpl *element() const 0588 { 0589 return static_cast<DOM::HTMLSelectElementImpl *>(RenderObject::element()); 0590 } 0591 0592 protected: 0593 void setPadding() override; 0594 ListBoxWidget *createListBox(); 0595 ComboBoxWidget *createComboBox(); 0596 0597 unsigned m_size; 0598 bool m_multiple; 0599 bool m_useListBox; 0600 bool m_selectionChanged; 0601 bool m_ignoreSelectEvents; 0602 bool m_optionsChanged; 0603 0604 void clearItemFlags(int index, Qt::ItemFlags flags); 0605 bool canHaveBorder() const override 0606 { 0607 return true; 0608 } 0609 0610 protected Q_SLOTS: 0611 void slotSelected(int index); 0612 void slotSelectionChanged(); 0613 }; 0614 0615 // ------------------------------------------------------------------------- 0616 class TextAreaWidget : public KTextEdit, public KHTMLWidget 0617 { 0618 Q_OBJECT 0619 public: 0620 TextAreaWidget(int wrap, QWidget *parent); 0621 virtual ~TextAreaWidget(); 0622 0623 protected: 0624 bool event(QEvent *e) override; 0625 void keyPressEvent(QKeyEvent *e) override; 0626 void scrollContentsBy(int dx, int dy) override; 0627 0628 }; 0629 0630 // ------------------------------------------------------------------------- 0631 0632 class RenderTextArea : public RenderFormElement 0633 { 0634 Q_OBJECT 0635 public: 0636 RenderTextArea(DOM::HTMLTextAreaElementImpl *element); 0637 ~RenderTextArea(); 0638 0639 const char *renderName() const override 0640 { 0641 return "RenderTextArea"; 0642 } 0643 void calcMinMaxWidth() override; 0644 void setStyle(RenderStyle *style) override; 0645 0646 short scrollWidth() const override; 0647 int scrollHeight() const override; 0648 0649 void updateFromElement() override; 0650 0651 // don't even think about making this method virtual! 0652 TextAreaWidget *widget() const 0653 { 0654 return static_cast<TextAreaWidget *>(m_widget); 0655 } 0656 DOM::HTMLTextAreaElementImpl *element() const 0657 { 0658 return static_cast<DOM::HTMLTextAreaElementImpl *>(RenderObject::element()); 0659 } 0660 0661 QString text(); 0662 void setText(const QString &text); 0663 0664 void highLightWord(unsigned int length, unsigned int pos); 0665 0666 void select(); 0667 0668 long selectionStart(); 0669 long selectionEnd(); 0670 void setSelectionStart(long pos); 0671 void setSelectionEnd(long pos); 0672 void setSelectionRange(long start, long end); 0673 protected Q_SLOTS: 0674 void slotTextChanged(); 0675 0676 protected: 0677 void handleFocusOut() override; 0678 0679 bool isEditable() const override 0680 { 0681 return true; 0682 } 0683 bool canHaveBorder() const override 0684 { 0685 return true; 0686 } 0687 0688 Qt::Alignment m_textAlignment; 0689 }; 0690 0691 // ------------------------------------------------------------------------- 0692 0693 class ScrollBarWidget: public QScrollBar, public KHTMLWidget 0694 { 0695 public: 0696 ScrollBarWidget(QWidget *parent = nullptr): QScrollBar(parent) 0697 { 0698 m_kwp->setIsRedirected(true); 0699 } 0700 ScrollBarWidget(Qt::Orientation orientation, QWidget *parent = nullptr): QScrollBar(orientation, parent) 0701 { 0702 m_kwp->setIsRedirected(true); 0703 } 0704 }; 0705 0706 } //namespace 0707 0708 #endif