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 
92 /**
93  * Renders and displays HTML in a QScrollArea.
94  *
95  * Suitable for use as an application's main view.
96  **/
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:
129  /**
130  * Constructs a KHTMLView.
131  */
132  KHTMLView(KHTMLPart *part, QWidget *parent);
133  virtual ~KHTMLView();
134 
135  /**
136  * Returns a pointer to the KHTMLPart that is
137  * rendering the page.
138  **/
139  KHTMLPart *part() const
140  {
141  return m_part;
142  }
143 
144  int frameWidth() const
145  {
146  return _width;
147  }
148 
149  /**
150  * Sets a margin in x direction.
151  */
152  void setMarginWidth(int x);
153 
154  /**
155  * Returns the margin width.
156  *
157  * A return value of -1 means the default value will be used.
158  */
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 
169  /**
170  * Returns the margin height.
171  *
172  * A return value of -1 means the default value will be used.
173  */
175  {
176  return _marginHeight;
177  }
178 
179  /**
180  * Sets vertical scrollbar mode.
181  *
182  * WARNING: do not call this method on a base class pointer unless you
183  * specifically want QAbstractScrollArea's variant (not recommended).
184  * QAbstractScrollArea::setVerticalScrollBarPolicy is *not* virtual.
185  */
186  virtual void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy);
187 
188  /**
189  * Sets horizontal scrollbar mode.
190  *
191  * WARNING: do not call this method on a base class pointer unless you
192  * specifically want QAbstractScrollArea's variant (not recommended).
193  * QAbstractScrollArea::setHorizontalScrollBarPolicy is *not* virtual.
194  */
196 
197  /**
198  * Prints the HTML document.
199  * @param quick if true, fully automated printing, without print dialog
200  */
201  void print(bool quick = false);
202 
203  /**
204  * Prints the HTML document.
205  * @param printer shared printer instance
206  * @param quick if true, fully automated printing, without print dialog
207  *
208  * @since 5.64
209  */
210  void print(QPrinter *printer, bool quick = false);
211 
212  /**
213  * Display all accesskeys in small tooltips
214  */
215  void displayAccessKeys();
216 
217  /**
218  * Returns the contents area's width
219  */
220  int contentsWidth() const;
221 
222  /**
223  * Returns the contents area's height
224  */
225  int contentsHeight() const;
226 
227  /**
228  * Returns the x coordinate of the contents area point
229  * that is currently located at the top left in the viewport
230  */
231  int contentsX() const;
232 
233  /**
234  * Returns the y coordinate of the contents area point
235  * that is currently located at the top left in the viewport
236  */
237  int contentsY() const;
238 
239  /**
240  * Returns the width of the viewport
241  */
242  int visibleWidth() const;
243 
244  /**
245  * Returns the height of the viewport
246  */
247  int visibleHeight() const;
248 
249  /**
250  * Place the contents area point x/y
251  * at the top left of the viewport
252  */
253  void setContentsPos(int x, int y);
254 
255  /**
256  * Returns a point translated to viewport coordinates
257  * @param p the contents area point to translate
258  *
259  */
260  QPoint contentsToViewport(const QPoint &p) const;
261 
262  /**
263  * Returns a point translated to contents area coordinates
264  * @param p the viewport point to translate
265  *
266  */
267  QPoint viewportToContents(const QPoint &p) const;
268 
269  /**
270  * Returns a point translated to contents area coordinates
271  * @param x x coordinate of viewport point to translate
272  * @param y y coordinate of viewport point to translate
273  * @param cx resulting x coordinate
274  * @param cy resulting y coordinate
275  *
276  */
277  void viewportToContents(int x, int y, int &cx, int &cy) const;
278 
279  /**
280  * Returns a point translated to viewport coordinates
281  * @param x x coordinate of contents area point to translate
282  * @param y y coordinate of contents area point to translate
283  * @param cx resulting x coordinate
284  * @param cy resulting y coordinate
285  *
286  */
287  void contentsToViewport(int x, int y, int &cx, int &cy) const;
288 
289  /**
290  * Scrolls the content area by a given amount
291  * @param x x offset
292  * @param y y offset
293  */
294  void scrollBy(int x, int y);
295 
296  /**
297  * Requests an update of the content area
298  * @param r the content area rectangle to update
299  */
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 
305  /**
306  * Requests an immediate repaint of the content area
307  * @param r the content area rectangle to repaint
308  */
309  void repaintContents(const QRect &r);
310  void repaintContents(int x, int y, int w, int h);
311 
312  /**
313  * Apply a zoom level to the content area
314  * @param percent a zoom level expressed as a percentage
315  */
316  void setZoomLevel(int percent);
317 
318  /**
319  * Retrieve the current zoom level
320  *
321  */
322  int zoomLevel() const;
323 
324  /**
325  * Smooth Scrolling Mode enumeration
326  * @li SSMDisabled smooth scrolling is disabled
327  * @li SSMWhenEfficient only use smooth scrolling on pages that do not require a full repaint of the content area when scrolling
328  * @li SSMAlways smooth scrolling is performed unconditionally
329  */
330  enum SmoothScrollingMode { SSMDisabled = 0, SSMWhenEfficient, SSMEnabled };
331 
332  /**
333  * Set the smooth scrolling mode.
334  *
335  * Smooth scrolling mode is normally controlled by the configuration file's SmoothScrolling key.
336  * Using this setter will override the configuration file's settings.
337  *
338  * @since 4.1
339  */
340  void setSmoothScrollingMode(SmoothScrollingMode m);
341 
342  /**
343  * Retrieve the current smooth scrolling mode
344  *
345  * @since 4.1
346  */
347  SmoothScrollingMode smoothScrollingMode() const;
348 
349 public Q_SLOTS:
350  /**
351  * Resize the contents area
352  * @param w the new width
353  * @param h the new height
354  */
355  virtual void resizeContents(int w, int h);
356 
357  /**
358  * ensure the display is up to date
359  */
360  void layout();
361 
362 Q_SIGNALS:
363  /**
364  * This signal is used for internal layouting. Don't use it to check if rendering finished.
365  * Use @ref KHTMLPart completed() signal instead.
366  */
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 
415  /**
416  * @internal
417  * used for autoscrolling with MMB
418  */
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 
445  /**
446  * Paints the HTML document to a QPainter.
447  * The document will be scaled to match the width of
448  * rc and clipped to fit in the height.
449  * yOff determines the vertical offset in the document to start with.
450  * more, if nonzero will be set to true if the documents extends
451  * beyond the rc or false if everything below yOff was painted.
452  **/
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 
457  /**
458  * Get/set the CSS Media Type.
459  *
460  * Media type is set to "screen" for on-screen rendering and "print"
461  * during printing. Other media types lack the proper support in the
462  * renderer and are not activated. The DOM tree and the parser itself,
463  * however, properly handle other media types. To make them actually work
464  * you only need to enable the media type in the view and if necessary
465  * add the media type dependent changes to the renderer.
466  */
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 
518  /**
519  * Returns the current caret policy when the view is not focused.
520  * @return a KHTMLPart::CaretDisplay value
521  */
522  int caretDisplayPolicyNonFocused() const;
523 
524  /**
525  * Sets the caret display policy when the view is not focused.
526  * @param policy new display policy as
527  * defined by KHTMLPart::CaretDisplayPolicy
528  */
529  void setCaretDisplayPolicyNonFocused(int policy);
530 
531  // -- caret event handler
532 
533  /**
534  * Evaluates key presses for caret navigation on editable nodes.
535  * @return true if event has been handled
536  */
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 
This file is part of the HTML rendering engine for KDE.
int marginWidth() const
Returns the margin width.
Definition: khtmlview.h:159
Q_SLOTSQ_SLOTS
virtual void timerEvent(QTimerEvent *event)
QLayout * layout() const const
virtual void mouseDoubleClickEvent(QMouseEvent *e) override
ScrollBarPolicy
virtual void scrollContentsBy(int dx, int dy) override
This library provides a full-featured HTML parser and widget.
This class is khtml's main class.
Definition: khtml_part.h:208
Base Class for all rendering tree objects.
virtual bool eventFilter(QObject *o, QEvent *e) override
virtual void wheelEvent(QWheelEvent *e) override
virtual void dropEvent(QDropEvent *event) override
KHTMLPart * part() const
Returns a pointer to the KHTMLPart that is rendering the page.
Definition: khtmlview.h:139
virtual void keyReleaseEvent(QKeyEvent *event)
Renders and displays HTML in a QScrollArea.
Definition: khtmlview.h:97
virtual void hideEvent(QHideEvent *event)
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
virtual void paintEvent(QPaintEvent *event) override
the StyleSelector implementation for CSS.
virtual void showEvent(QShowEvent *event)
virtual void keyPressEvent(QKeyEvent *e) override
virtual bool focusNextPrevChild(bool next) override
virtual void resizeEvent(QResizeEvent *) override
virtual void dragEnterEvent(QDragEnterEvent *event) override
virtual void focusInEvent(QFocusEvent *event)
Q_SIGNALSQ_SIGNALS
virtual void mouseMoveEvent(QMouseEvent *e) override
ScriptableExtension * host() const
virtual void mouseReleaseEvent(QMouseEvent *e) override
SmoothScrollingMode
Smooth Scrolling Mode enumeration.
Definition: khtmlview.h:330
virtual bool viewportEvent(QEvent *event)
virtual void closeEvent(QCloseEvent *event)
int marginHeight()
Returns the margin height.
Definition: khtmlview.h:174
virtual bool event(QEvent *e) override
virtual void focusOutEvent(QFocusEvent *event)
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
virtual void mousePressEvent(QMouseEvent *e) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Dec 6 2023 04:08:38 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.