KHtml

khtmlview.h
1 /* This file is part of the KDE project
2 
3  Copyright (C) 1997 Martin Jones ([email protected])
4  (C) 1998 Waldo Bastian ([email protected])
5  (C) 1998, 1999 Torben Weis ([email protected])
6  (C) 1999 Lars Knoll ([email protected])
7  (C) 1999 Antti Koivisto ([email protected])
8  (C) 2006 Germain Garand ([email protected])
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License as published by the Free Software Foundation; either
13  version 2 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 */
25 
26 #ifndef KHTMLVIEW_H
27 #define KHTMLVIEW_H
28 
29 #include <khtml_export.h>
30 
31 // qt includes and classes
32 #include <QScrollArea>
33 
34 class QPainter;
35 class QPrinter;
36 class QRect;
37 template< typename T > class QVector;
38 template <class T> class QStack;
39 
40 namespace DOM
41 {
42 class HTMLDocumentImpl;
43 class DocumentImpl;
44 class ElementImpl;
45 class HTMLTitleElementImpl;
46 class HTMLGenericFormElementImpl;
47 class HTMLFormElementImpl;
48 class HTMLAnchorElementImpl;
49 class HTMLInputElementImpl;
50 class NodeImpl;
51 class CSSProperty;
52 }
53 
54 namespace KJS
55 {
56 class WindowFunc;
57 class ExternalFunc;
58 }
59 
60 namespace khtml
61 {
62 class RenderObject;
63 class RenderCanvas;
64 class RenderLineEdit;
65 class RenderPartObject;
66 class RenderWidget;
67 class RenderLayer;
68 class RenderBox;
69 class CSSStyleSelector;
70 class LineEditWidget;
71 class CaretBox;
72 class HTMLTokenizer;
73 class KHTMLWidgetPrivate;
74 class KHTMLWidget
75 {
76 public:
77  KHTMLWidget();
78  ~KHTMLWidget();
79  KHTMLWidgetPrivate *m_kwp;
80 };
81 void applyRule(DOM::CSSProperty *prop);
82 }
83 
84 class KHTMLPart;
85 class KHTMLViewPrivate;
86 
87 namespace khtml
88 {
89 
90 }
91 
97 class KHTML_EXPORT KHTMLView : public QScrollArea, public khtml::KHTMLWidget
98 {
99  Q_OBJECT
100 
101  friend class DOM::HTMLDocumentImpl;
102  friend class DOM::HTMLTitleElementImpl;
103  friend class DOM::HTMLGenericFormElementImpl;
104  friend class DOM::HTMLFormElementImpl;
105  friend class DOM::HTMLAnchorElementImpl;
106  friend class DOM::HTMLInputElementImpl;
107  friend class DOM::NodeImpl;
108  friend class DOM::ElementImpl;
109  friend class DOM::DocumentImpl;
110  friend class KHTMLPart;
111  friend class KHTMLFind;
112  friend class StorePass;
113  friend class khtml::RenderCanvas;
114  friend class khtml::RenderObject;
115  friend class khtml::RenderLineEdit;
116  friend class khtml::RenderPartObject;
117  friend class khtml::RenderWidget;
118  friend class khtml::KHTMLWidgetPrivate;
119  friend class khtml::RenderLayer;
120  friend class khtml::RenderBox;
121  friend class khtml::CSSStyleSelector;
122  friend class khtml::LineEditWidget;
123  friend class khtml::HTMLTokenizer;
124  friend class KJS::WindowFunc;
125  friend class KJS::ExternalFunc;
126  friend void khtml::applyRule(DOM::CSSProperty *prop);
127 
128 public:
132  KHTMLView(KHTMLPart *part, QWidget *parent);
133  virtual ~KHTMLView();
134 
139  KHTMLPart *part() const
140  {
141  return m_part;
142  }
143 
144  int frameWidth() const
145  {
146  return _width;
147  }
148 
152  void setMarginWidth(int x);
153 
159  int marginWidth() const
160  {
161  return _marginWidth;
162  }
163 
164  /*
165  * Sets a margin in y direction.
166  */
167  void setMarginHeight(int y);
168 
175  {
176  return _marginHeight;
177  }
178 
186  virtual void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy);
187 
195  virtual void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy);
196 
201  void print(bool quick = false);
202 
210  void print(QPrinter *printer, bool quick = false);
211 
215  void displayAccessKeys();
216 
220  int contentsWidth() const;
221 
225  int contentsHeight() const;
226 
231  int contentsX() const;
232 
237  int contentsY() const;
238 
242  int visibleWidth() const;
243 
247  int visibleHeight() const;
248 
253  void setContentsPos(int x, int y);
254 
260  QPoint contentsToViewport(const QPoint &p) const;
261 
267  QPoint viewportToContents(const QPoint &p) const;
268 
277  void viewportToContents(int x, int y, int &cx, int &cy) const;
278 
287  void contentsToViewport(int x, int y, int &cx, int &cy) const;
288 
294  void scrollBy(int x, int y);
295 
300  void updateContents(const QRect &r);
301  void updateContents(int x, int y, int w, int h);
302 
303  void addChild(QWidget *child, int dx, int dy);
304 
309  void repaintContents(const QRect &r);
310  void repaintContents(int x, int y, int w, int h);
311 
316  void setZoomLevel(int percent);
317 
322  int zoomLevel() const;
323 
330  enum SmoothScrollingMode { SSMDisabled = 0, SSMWhenEfficient, SSMEnabled };
331 
340  void setSmoothScrollingMode(SmoothScrollingMode m);
341 
347  SmoothScrollingMode smoothScrollingMode() const;
348 
349 public Q_SLOTS:
355  virtual void resizeContents(int w, int h);
356 
360  void layout();
361 
362 Q_SIGNALS:
367  void finishedLayout();
368  void cleared();
369  void zoomView(int);
370  void hideAccessKeys();
371  void repaintAccessKeys();
372  void findAheadActive(bool);
373 
374 protected:
375  void clear();
376 
377  bool event(QEvent *event) override;
378  void paintEvent(QPaintEvent *) override;
379  void resizeEvent(QResizeEvent *event) override;
380  void showEvent(QShowEvent *) override;
381  void hideEvent(QHideEvent *) override;
382  bool focusNextPrevChild(bool next) override;
383  void mousePressEvent(QMouseEvent *) override;
384  void focusInEvent(QFocusEvent *) override;
385  void focusOutEvent(QFocusEvent *) override;
386  void mouseDoubleClickEvent(QMouseEvent *) override;
387  void mouseMoveEvent(QMouseEvent *) override;
388  void mouseReleaseEvent(QMouseEvent *) override;
389 #ifndef QT_NO_WHEELEVENT
390  void wheelEvent(QWheelEvent *) override;
391 #endif
392  void dragEnterEvent(QDragEnterEvent *) override;
393  void dropEvent(QDropEvent *) override;
394  void closeEvent(QCloseEvent *) override;
395  virtual bool widgetEvent(QEvent *);
396  bool viewportEvent(QEvent *e) override;
397  bool eventFilter(QObject *, QEvent *) override;
398  void scrollContentsBy(int dx, int dy) override;
399 
400  void keyPressEvent(QKeyEvent *_ke) override;
401  void keyReleaseEvent(QKeyEvent *_ke) override;
402  void doAutoScroll();
403  void timerEvent(QTimerEvent *) override;
404 
405  void setSmoothScrollingModeDefault(SmoothScrollingMode m);
406 
407 protected Q_SLOTS:
408  void slotPaletteChanged();
409 
410 private Q_SLOTS:
411  void tripleClickTimeout();
412  void accessKeysTimeout();
413  void scrollTick();
414 
419  void slotMouseScrollTimer();
420 
421 private:
422  void resizeContentsToViewport();
423 
424  void scheduleRelayout(khtml::RenderObject *clippedObj = nullptr);
425  void unscheduleRelayout();
426 
427  bool hasLayoutPending();
428 
429  void scheduleRepaint(int x, int y, int w, int h, bool asap = false);
430  void unscheduleRepaint();
431 
432  bool needsFullRepaint() const;
433 
434  void closeChildDialogs();
435  bool dialogsAllowed();
436 
437  void setMouseEventsTarget(QWidget *w);
438  QWidget *mouseEventsTarget() const;
439 
440  QStack<QRegion> *clipHolder() const;
441  void setClipHolder(QStack<QRegion> *ch);
442 
443  void setPart(KHTMLPart *part);
444 
453  void paint(QPainter *p, const QRect &rc, int yOff = 0, bool *more = nullptr);
454 
455  void render(QPainter *p, const QRect &r, const QPoint &off);
456 
467  void setMediaType(const QString &medium);
468  QString mediaType() const;
469 
470  bool pagedMode() const;
471 
472  bool scrollTo(const QRect &);
473 
474  bool focusNextPrevNode(bool next);
475  bool handleAccessKey(const QKeyEvent *ev);
476  bool focusNodeWithAccessKey(QChar c, KHTMLView *caller = nullptr);
477  QMap< DOM::ElementImpl *, QChar > buildFallbackAccessKeys() const;
478  void displayAccessKeys(KHTMLView *caller, KHTMLView *origview, QVector< QChar > &taken, bool use_fallbacks);
479  bool isScrollingFromMouseWheel() const;
480  void setHasStaticBackground(bool partial = false);
481  void setHasNormalBackground();
482  void addStaticObject(bool fixed);
483  void removeStaticObject(bool fixed);
484  void applyTransforms(int &x, int &y, int &w, int &h) const;
485  void revertTransforms(int &x, int &y, int &w, int &h) const;
486  void revertTransforms(int &x, int &y) const;
487  void checkExternalWidgetsPosition();
488 
489  void setIgnoreWheelEvents(bool e);
490 
491  void initWidget();
492 
493  DOM::NodeImpl *nodeUnderMouse() const;
494  DOM::NodeImpl *nonSharedNodeUnderMouse() const;
495 
496  void restoreScrollBar();
497 
498  QStringList formCompletionItems(const QString &name) const;
499  void clearCompletionHistory(const QString &name);
500  void addFormCompletionItem(const QString &name, const QString &value);
501 
502  void addNonPasswordStorableSite(const QString &host);
503  void delNonPasswordStorableSite(const QString &host);
504  bool nonPasswordStorableSite(const QString &host) const;
505 
506  bool dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode,
507  DOM::NodeImpl *targetNodeNonShared, bool cancelable,
508  int detail, QMouseEvent *_mouse, bool setUnder,
509  int mouseEventType, int orientation = 0);
510  bool dispatchKeyEvent(QKeyEvent *_ke);
511  bool dispatchKeyEventHelper(QKeyEvent *_ke, bool generate_keypress);
512 
513  void complete(bool pendingAction);
514 
515  void updateScrollBars();
516  void setupSmoothScrolling(int dx, int dy);
517 
522  int caretDisplayPolicyNonFocused() const;
523 
529  void setCaretDisplayPolicyNonFocused(int policy);
530 
531  // -- caret event handler
532 
537  bool caretKeyPressEvent(QKeyEvent *);
538 
539  // ------------------------------------- member variables ------------------------------------
540 private:
541  friend class KHTMLViewPrivate;
542  enum LinkCursor { LINK_NORMAL, LINK_MAILTO, LINK_NEWWINDOW };
543 
544  void setWidgetVisible(::khtml::RenderWidget *, bool visible);
545 
546  int _width;
547  int _height;
548 
549  int _marginWidth;
550  int _marginHeight;
551 
552  KHTMLPart *m_part;
553  KHTMLViewPrivate *const d;
554 
555  QString m_medium; // media type
556 };
557 
558 #endif
559 
ScrollBarPolicy
SmoothScrollingMode
Smooth Scrolling Mode enumeration.
Definition: khtmlview.h:330
int marginWidth() const
Returns the margin width.
Definition: khtmlview.h:159
This file is part of the HTML rendering engine for KDE.
This class is khtml&#39;s main class.
Definition: khtml_part.h:208
Renders and displays HTML in a QScrollArea.
Definition: khtmlview.h:97
KHTMLPart * part() const
Returns a pointer to the KHTMLPart that is rendering the page.
Definition: khtmlview.h:139
the StyleSelector implementation for CSS.
This library provides a full-featured HTML parser and widget.
Base Class for all rendering tree objects.
int marginHeight()
Returns the margin height.
Definition: khtmlview.h:174
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Oct 27 2020 22:51:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.