1 /* This file is part of the KDE project
3 Copyright (C) 1997 Martin Jones (mjones@kde.org)
4 (C) 1998 Waldo Bastian (bastian@kde.org)
5 (C) 1998, 1999 Torben Weis (weis@kde.org)
6 (C) 1999 Lars Knoll (knoll@kde.org)
7 (C) 1999 Antti Koivisto (koivisto@kde.org)
8 (C) 2006 Germain Garand (germain@ebooksfrance.org)
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.
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.
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.
29 #include <khtml_export.h>
31 // qt includes and classes
32 #include <QtGui/QScrollArea>
36 template< typename T
> class QVector
;
37 template <class T
> class QStack
;
40 class HTMLDocumentImpl
;
43 class HTMLTitleElementImpl
;
44 class HTMLGenericFormElementImpl
;
45 class HTMLFormElementImpl
;
46 class HTMLAnchorElementImpl
;
47 class HTMLInputElementImpl
;
61 class RenderPartObject
;
65 class CSSStyleSelector
;
68 class KHTMLWidgetPrivate
;
74 KHTMLWidgetPrivate
* m_kwp
;
76 void applyRule(DOM::CSSProperty
*prop
);
80 class KHTMLViewPrivate
;
87 * Renders and displays HTML in a QScrollArea.
89 * Suitable for use as an application's main view.
91 class KHTML_EXPORT KHTMLView
: public QScrollArea
, public khtml::KHTMLWidget
95 friend class DOM::HTMLDocumentImpl
;
96 friend class DOM::HTMLTitleElementImpl
;
97 friend class DOM::HTMLGenericFormElementImpl
;
98 friend class DOM::HTMLFormElementImpl
;
99 friend class DOM::HTMLAnchorElementImpl
;
100 friend class DOM::HTMLInputElementImpl
;
101 friend class DOM::NodeImpl
;
102 friend class DOM::ElementImpl
;
103 friend class DOM::DocumentImpl
;
104 friend class KHTMLPart
;
105 friend class KHTMLFind
;
106 friend class khtml::RenderCanvas
;
107 friend class khtml::RenderObject
;
108 friend class khtml::RenderLineEdit
;
109 friend class khtml::RenderPartObject
;
110 friend class khtml::RenderWidget
;
111 friend class khtml::KHTMLWidgetPrivate
;
112 friend class khtml::RenderLayer
;
113 friend class khtml::RenderBox
;
114 friend class khtml::CSSStyleSelector
;
115 friend class khtml::LineEditWidget
;
116 friend class KJS::WindowFunc
;
117 friend class KJS::ExternalFunc
;
118 friend void khtml::applyRule(DOM::CSSProperty
*prop
);
123 * Constructs a KHTMLView.
125 KHTMLView( KHTMLPart
*part
, QWidget
*parent
);
126 virtual ~KHTMLView();
129 * Returns a pointer to the KHTMLPart that is
130 * rendering the page.
132 KHTMLPart
*part() const { return m_part
; }
134 int frameWidth() const { return _width
; }
137 * Sets a margin in x direction.
139 void setMarginWidth(int x
);
142 * Returns the margin width.
144 * A return value of -1 means the default value will be used.
146 int marginWidth() const { return _marginWidth
; }
149 * Sets a margin in y direction.
151 void setMarginHeight(int y
);
154 * Returns the margin height.
156 * A return value of -1 means the default value will be used.
158 int marginHeight() { return _marginHeight
; }
161 * Sets vertical scrollbar mode.
163 * WARNING: do not call this method on a base class pointer unless you
164 * specifically want QAbstractScrollArea's variant (not recommended).
165 * QAbstractScrollArea::setVerticalScrollBarPolicy is *not* virtual.
167 virtual void setVerticalScrollBarPolicy( Qt::ScrollBarPolicy policy
);
170 * Sets horizontal scrollbar mode.
172 * WARNING: do not call this method on a base class pointer unless you
173 * specifically want QAbstractScrollArea's variant (not recommended).
174 * QAbstractScrollArea::setHorizontalScrollBarPolicy is *not* virtual.
176 virtual void setHorizontalScrollBarPolicy( Qt::ScrollBarPolicy policy
);
179 * Prints the HTML document.
180 * @param quick if true, fully automated printing, without print dialog
182 void print( bool quick
= false );
185 * Display all accesskeys in small tooltips
187 void displayAccessKeys();
190 * Returns the contents area's width
192 int contentsWidth() const;
195 * Returns the contents area's height
197 int contentsHeight() const;
200 * Returns the x coordinate of the contents area point
201 * that is currently located at the top left in the viewport
203 int contentsX() const;
206 * Returns the y coordinate of the contents area point
207 * that is currently located at the top left in the viewport
209 int contentsY() const;
212 * Returns the width of the viewport
214 int visibleWidth() const;
217 * Returns the height of the viewport
219 int visibleHeight() const;
222 * Place the contents area point x/y
223 * at the top left of the viewport
225 void setContentsPos(int x
, int y
);
228 * Returns a point translated to viewport coordinates
229 * @param p the contents area point to translate
232 QPoint
contentsToViewport(const QPoint
& p
) const;
235 * Returns a point translated to contents area coordinates
236 * @param p the viewport point to translate
239 QPoint
viewportToContents(const QPoint
& p
) const;
242 * Returns a point translated to contents area coordinates
243 * @param x x coordinate of viewport point to translate
244 * @param y y coordinate of viewport point to translate
245 * @param cx resulting x coordinate
246 * @param cy resulting y coordinate
249 void viewportToContents(int x
, int y
, int& cx
, int& cy
) const;
252 * Returns a point translated to viewport coordinates
253 * @param x x coordinate of contents area point to translate
254 * @param y y coordinate of contents area point to translate
255 * @param cx resulting x coordinate
256 * @param cy resulting y coordinate
259 void contentsToViewport(int x
, int y
, int& cx
, int& cy
) const;
262 * Scrolls the content area by a given amount
266 void scrollBy(int x
, int y
);
269 * Requests an update of the content area
270 * @param r the content area rectangle to update
272 void updateContents( const QRect
& r
);
273 void updateContents(int x
, int y
, int w
, int h
);
275 void addChild(QWidget
*child
, int dx
, int dy
);
278 * Requests an immediate repaint of the content area
279 * @param r the content area rectangle to repaint
281 void repaintContents( const QRect
& r
);
282 void repaintContents(int x
, int y
, int w
, int h
);
285 * Apply a zoom level to the content area
286 * @param percent a zoom level expressed as a percentage
288 void setZoomLevel( int percent
);
291 * Retrieve the current zoom level
294 int zoomLevel() const;
297 * Smooth Scrolling Mode enumeration
298 * @li SSMDisabled smooth scrolling is disabled
299 * @li SSMWhenEfficient only use smooth scrolling on pages that do not require a full repaint of the content area when scrolling
300 * @li SSMAlways smooth scrolling is performed unconditionally
302 enum SmoothScrollingMode
{ SSMDisabled
= 0, SSMWhenEfficient
, SSMEnabled
};
305 * Set the smooth scrolling mode.
307 * Smooth scrolling mode is normally controlled by the configuration file's SmoothScrolling key.
308 * Using this setter will override the configuration file's settings.
312 void setSmoothScrollingMode( SmoothScrollingMode m
);
315 * Retrieve the current smooth scrolling mode
319 SmoothScrollingMode
smoothScrollingMode() const;
323 * Resize the contents area
324 * @param w the new width
325 * @param h the new height
327 virtual void resizeContents(int w
, int h
);
330 * ensure the display is up to date
337 * This signal is used for internal layouting. Don't use it to check if rendering finished.
338 * Use @ref KHTMLPart completed() signal instead.
340 void finishedLayout();
342 void zoomView( int );
343 void hideAccessKeys();
344 void repaintAccessKeys();
345 void findAheadActive( bool );
350 virtual bool event ( QEvent
* event
);
351 virtual void paintEvent( QPaintEvent
* );
352 virtual void resizeEvent ( QResizeEvent
* event
);
353 virtual void showEvent ( QShowEvent
* );
354 virtual void hideEvent ( QHideEvent
*);
355 virtual bool focusNextPrevChild( bool next
);
356 virtual void mousePressEvent( QMouseEvent
* );
357 virtual void focusInEvent( QFocusEvent
* );
358 virtual void focusOutEvent( QFocusEvent
* );
359 virtual void mouseDoubleClickEvent( QMouseEvent
* );
360 virtual void mouseMoveEvent(QMouseEvent
*);
361 virtual void mouseReleaseEvent(QMouseEvent
*);
362 #ifndef QT_NO_WHEELEVENT
363 virtual void wheelEvent(QWheelEvent
*);
365 virtual void dragEnterEvent( QDragEnterEvent
* );
366 virtual void dropEvent( QDropEvent
* );
367 virtual void closeEvent ( QCloseEvent
* );
368 virtual bool widgetEvent( QEvent
* );
369 virtual bool viewportEvent( QEvent
* e
);
370 virtual bool eventFilter(QObject
*, QEvent
*);
371 virtual void scrollContentsBy( int dx
, int dy
);
373 void keyPressEvent( QKeyEvent
*_ke
);
374 void keyReleaseEvent ( QKeyEvent
*_ke
);
376 void timerEvent ( QTimerEvent
* );
378 void setSmoothScrollingModeDefault( SmoothScrollingMode m
);
381 void slotPaletteChanged();
384 void tripleClickTimeout();
386 void accessKeysTimeout();
391 * used for autoscrolling with MMB
393 void slotMouseScrollTimer();
396 void resizeContentsToViewport();
398 void scheduleRelayout(khtml::RenderObject
* clippedObj
=0);
399 void unscheduleRelayout();
401 void scheduleRepaint(int x
, int y
, int w
, int h
, bool asap
=false);
402 void unscheduleRepaint();
404 bool needsFullRepaint() const;
406 void closeChildDialogs();
407 bool dialogsAllowed();
409 void setMouseEventsTarget( QWidget
* w
);
410 QWidget
* mouseEventsTarget() const;
412 QStack
<QRegion
>* clipHolder() const;
413 void setClipHolder( QStack
<QRegion
>* ch
);
415 void setPart(KHTMLPart
*part
);
418 * Paints the HTML document to a QPainter.
419 * The document will be scaled to match the width of
420 * rc and clipped to fit in the height.
421 * yOff determines the vertical offset in the document to start with.
422 * more, if nonzero will be set to true if the documents extends
423 * beyond the rc or false if everything below yOff was painted.
425 void paint(QPainter
*p
, const QRect
&rc
, int yOff
= 0, bool *more
= 0);
427 void render(QPainter
*p
, const QRect
& r
, const QPoint
& off
);
430 * Get/set the CSS Media Type.
432 * Media type is set to "screen" for on-screen rendering and "print"
433 * during printing. Other media types lack the proper support in the
434 * renderer and are not activated. The DOM tree and the parser itself,
435 * however, properly handle other media types. To make them actually work
436 * you only need to enable the media type in the view and if necessary
437 * add the media type dependent changes to the renderer.
439 void setMediaType( const QString
&medium
);
440 QString
mediaType() const;
442 bool pagedMode() const;
444 bool scrollTo(const QRect
&);
446 bool focusNextPrevNode(bool next
);
447 bool handleAccessKey(const QKeyEvent
* ev
);
448 bool focusNodeWithAccessKey(QChar c
, KHTMLView
* caller
= NULL
);
449 QMap
< DOM::ElementImpl
*, QChar
> buildFallbackAccessKeys() const;
450 void displayAccessKeys( KHTMLView
* caller
, KHTMLView
* origview
, QVector
< QChar
>& taken
, bool use_fallbacks
);
451 bool isScrollingFromMouseWheel() const;
452 void setHasStaticBackground(bool partial
=false);
453 void setHasNormalBackground();
454 void addStaticObject(bool fixed
);
455 void removeStaticObject(bool fixed
);
456 void applyTransforms( int& x
, int& y
, int& w
, int& h
) const;
457 void revertTransforms( int& x
, int& y
, int& w
, int& h
) const;
458 void revertTransforms( int& x
, int& y
) const;
459 void checkExternalWidgetsPosition();
461 void setIgnoreWheelEvents(bool e
);
465 DOM::NodeImpl
*nodeUnderMouse() const;
466 DOM::NodeImpl
*nonSharedNodeUnderMouse() const;
468 void restoreScrollBar();
470 QStringList
formCompletionItems(const QString
&name
) const;
471 void clearCompletionHistory(const QString
& name
);
472 void addFormCompletionItem(const QString
&name
, const QString
&value
);
474 void addNonPasswordStorableSite( const QString
& host
);
475 bool nonPasswordStorableSite( const QString
& host
) const;
477 bool dispatchMouseEvent(int eventId
, DOM::NodeImpl
*targetNode
,
478 DOM::NodeImpl
*targetNodeNonShared
, bool cancelable
,
479 int detail
,QMouseEvent
*_mouse
, bool setUnder
,
480 int mouseEventType
, int orientation
=0);
481 bool dispatchKeyEvent( QKeyEvent
*_ke
);
482 bool dispatchKeyEventHelper( QKeyEvent
*_ke
, bool generate_keypress
);
484 void complete( bool pendingAction
);
486 void updateScrollBars();
487 void setupSmoothScrolling(int dx
, int dy
);
489 #ifndef KHTML_NO_TYPE_AHEAD_FIND
490 void findAhead(bool increase
);
491 void updateFindAheadTimeout();
492 void startFindAhead( bool linksOnly
);
493 #endif // KHTML_NO_TYPE_AHEAD_FIND
496 * Returns the current caret policy when the view is not focused.
497 * @return a KHTMLPart::CaretDisplay value
499 int caretDisplayPolicyNonFocused() const;
502 * Sets the caret display policy when the view is not focused.
503 * @param policy new display policy as
504 * defined by KHTMLPart::CaretDisplayPolicy
506 void setCaretDisplayPolicyNonFocused(int policy
);
508 // -- caret event handler
511 * Evaluates key presses for caret navigation on editable nodes.
512 * @return true if event has been handled
514 bool caretKeyPressEvent(QKeyEvent
*);
516 // ------------------------------------- member variables ------------------------------------
518 friend class KHTMLViewPrivate
;
519 enum LinkCursor
{ LINK_NORMAL
, LINK_MAILTO
, LINK_NEWWINDOW
};
521 void setWidgetVisible(::khtml::RenderWidget
*, bool visible
);
531 KHTMLViewPrivate
* const d
;
533 QString m_medium
; // media type