00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef KHTMLVIEW_H
00026 #define KHTMLVIEW_H
00027
00028
00029 #include <qscrollview.h>
00030
00031 #include <kdelibs_export.h>
00032
00033 class QPainter;
00034 class QRect;
00035 template< typename T > class QValueVector;
00036
00037 namespace DOM {
00038 class HTMLDocumentImpl;
00039 class DocumentImpl;
00040 class ElementImpl;
00041 class HTMLElementImpl;
00042 class HTMLTitleElementImpl;
00043 class HTMLGenericFormElementImpl;
00044 class HTMLFormElementImpl;
00045 class HTMLAnchorElementImpl;
00046 class HTMLInputElementImpl;
00047 class Range;
00048 class NodeImpl;
00049 class CSSProperty;
00050 }
00051
00052 namespace KJS {
00053 class WindowFunc;
00054 class ExternalFunc;
00055 }
00056
00057 namespace khtml {
00058 class RenderObject;
00059 class RenderCanvas;
00060 class RenderStyle;
00061 class RenderLineEdit;
00062 class RenderPartObject;
00063 class RenderWidget;
00064 class CSSStyleSelector;
00065 class LineEditWidget;
00066 class CaretBox;
00067 void applyRule(DOM::CSSProperty *prop);
00068 }
00069
00070 class KHTMLPart;
00071 class KHTMLViewPrivate;
00072
00078 class KHTML_EXPORT KHTMLView : public QScrollView
00079 {
00080 Q_OBJECT
00081
00082 friend class DOM::HTMLDocumentImpl;
00083 friend class DOM::HTMLTitleElementImpl;
00084 friend class DOM::HTMLGenericFormElementImpl;
00085 friend class DOM::HTMLFormElementImpl;
00086 friend class DOM::HTMLAnchorElementImpl;
00087 friend class DOM::HTMLInputElementImpl;
00088 friend class DOM::DocumentImpl;
00089 friend class KHTMLPart;
00090 friend class khtml::RenderCanvas;
00091 friend class khtml::RenderObject;
00092 friend class khtml::RenderLineEdit;
00093 friend class khtml::RenderPartObject;
00094 friend class khtml::RenderWidget;
00095 friend class khtml::CSSStyleSelector;
00096 friend class khtml::LineEditWidget;
00097 friend class KJS::WindowFunc;
00098 friend class KJS::ExternalFunc;
00099 friend void khtml::applyRule(DOM::CSSProperty *prop);
00100
00101
00102 public:
00106 KHTMLView( KHTMLPart *part, QWidget *parent, const char *name=0 );
00107 virtual ~KHTMLView();
00108
00113 KHTMLPart *part() const { return m_part; }
00114
00115 int frameWidth() const { return _width; }
00116
00120 void setMarginWidth(int x);
00121
00127 int marginWidth() const { return _marginWidth; }
00128
00129
00130
00131
00132 void setMarginHeight(int y);
00133
00139 int marginHeight() { return _marginHeight; }
00140
00144 virtual void setVScrollBarMode ( ScrollBarMode mode );
00145
00149 virtual void setHScrollBarMode ( ScrollBarMode mode );
00150
00154 void print();
00155
00160 void print( bool quick );
00161
00165 void layout();
00169 void displayAccessKeys();
00170
00171
00172
00173 signals:
00174 void finishedLayout();
00175 void cleared();
00176 void zoomView( int );
00177 void hideAccessKeys();
00178 void repaintAccessKeys();
00179 void findAheadActive( bool );
00180
00181 protected:
00182 void clear();
00183
00184 virtual void resizeEvent ( QResizeEvent * event );
00185 virtual void showEvent ( QShowEvent * );
00186 virtual void hideEvent ( QHideEvent *);
00187 virtual bool focusNextPrevChild( bool next );
00188 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
00189 virtual void drawContents( QPainter* );
00190 virtual void viewportMousePressEvent( QMouseEvent * );
00191 virtual void focusInEvent( QFocusEvent * );
00192 virtual void focusOutEvent( QFocusEvent * );
00193 virtual void viewportMouseDoubleClickEvent( QMouseEvent * );
00194 virtual void viewportMouseMoveEvent(QMouseEvent *);
00195 virtual void viewportMouseReleaseEvent(QMouseEvent *);
00196 virtual void viewportResizeEvent(QResizeEvent*);
00197 #ifndef QT_NO_WHEELEVENT
00198 virtual void viewportWheelEvent(QWheelEvent*);
00199 #endif
00200 virtual void dragEnterEvent( QDragEnterEvent* );
00201 virtual void dropEvent( QDropEvent* );
00202 virtual void closeEvent ( QCloseEvent * );
00203 virtual bool eventFilter(QObject *, QEvent *);
00204
00205 void keyPressEvent( QKeyEvent *_ke );
00206 void keyReleaseEvent ( QKeyEvent *_ke );
00207 void contentsContextMenuEvent ( QContextMenuEvent *_ce );
00208 void doAutoScroll();
00209 void timerEvent ( QTimerEvent * );
00210 protected slots:
00211 void slotPaletteChanged();
00212 void slotScrollBarMoved();
00213
00214 private slots:
00215 void tripleClickTimeout();
00216 void findTimeout();
00217 void accessKeysTimeout();
00218
00224 void slotMouseScrollTimer();
00225
00226 private:
00227
00228 void scheduleRelayout(khtml::RenderObject* clippedObj=0);
00229 void unscheduleRelayout();
00230
00231 void scheduleRepaint(int x, int y, int w, int h, bool asap=false);
00232 void unscheduleRepaint();
00233
00234 bool needsFullRepaint() const;
00235
00236 void closeChildDialogs();
00237 bool dialogsAllowed();
00238
00247 void paint(QPainter *p, const QRect &rc, int yOff = 0, bool *more = 0);
00248
00249 #if 0
00250
00254 void paint(QPainter *p, int width);
00255 #endif
00256
00267 void setMediaType( const QString &medium );
00268 QString mediaType() const;
00269
00270 bool pagedMode() const;
00271
00272 bool scrollTo(const QRect &);
00273
00274 bool focusNextPrevNode(bool next);
00275 bool handleAccessKey(const QKeyEvent* ev);
00276 bool focusNodeWithAccessKey(QChar c, KHTMLView* caller = NULL);
00277 QMap< DOM::ElementImpl*, QChar > buildFallbackAccessKeys() const;
00278 void displayAccessKeys( KHTMLView* caller, KHTMLView* origview, QValueVector< QChar >& taken, bool use_fallbacks );
00279
00280 void useSlowRepaints();
00281
00282 void setIgnoreWheelEvents(bool e);
00283
00284 void init();
00285
00286 DOM::NodeImpl *nodeUnderMouse() const;
00287 DOM::NodeImpl *nonSharedNodeUnderMouse() const;
00288
00289 void restoreScrollBar();
00290
00291 QStringList formCompletionItems(const QString &name) const;
00292 void clearCompletionHistory(const QString& name);
00293 void addFormCompletionItem(const QString &name, const QString &value);
00294
00295 void addNonPasswordStorableSite( const QString& host );
00296 bool nonPasswordStorableSite( const QString& host ) const;
00297
00298 bool dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode,
00299 DOM::NodeImpl *targetNodeNonShared, bool cancelable,
00300 int detail,QMouseEvent *_mouse, bool setUnder,
00301 int mouseEventType);
00302 bool dispatchKeyEvent( QKeyEvent *_ke );
00303 bool dispatchKeyEventHelper( QKeyEvent *_ke, bool generate_keypress );
00304
00305 void complete( bool pendingAction );
00306
00307 #ifndef KHTML_NO_TYPE_AHEAD_FIND
00308 void findAhead(bool increase);
00309 void updateFindAheadTimeout();
00310 void startFindAhead( bool linksOnly );
00311 #endif // KHTML_NO_TYPE_AHEAD_FIND
00312
00313 #ifndef KHTML_NO_CARET
00314
00315
00326 void initCaret(bool keepSelection = false);
00329 bool caretOverrides() const;
00337 void ensureNodeHasFocus(DOM::NodeImpl *node);
00344 void recalcAndStoreCaretPos(khtml::CaretBox *hintBox = 0);
00351 void caretOn();
00357 void caretOff();
00366 void showCaret(bool forceRepaint = false);
00373 void hideCaret();
00378 void ensureCaretVisible();
00379
00395 bool foldSelectionToCaret(DOM::NodeImpl *startNode, long startOffset,
00396 DOM::NodeImpl *endNode, long endOffset);
00397
00407 bool placeCaret(khtml::CaretBox *hintBox = 0);
00408
00425 bool extendSelection(DOM::NodeImpl *startNode, long startOffset,
00426 DOM::NodeImpl *endNode, long endOffset);
00427
00437 void updateSelection(DOM::NodeImpl *startNode, long startOffset,
00438 DOM::NodeImpl *endNode, long endOffset);
00439
00444 int caretDisplayPolicyNonFocused() const;
00445
00452 void setCaretDisplayPolicyNonFocused(int policy);
00453
00454
00455
00459 void caretKeyPressEvent(QKeyEvent *);
00460
00461
00462
00474 bool moveCaretTo(DOM::NodeImpl *node, long offset, bool clearSelection);
00475
00481 enum CaretMovement { CaretByCharacter, CaretByWord };
00482
00493 void moveCaretBy(bool next, CaretMovement cmv, int n);
00494
00497 void moveCaretByLine(bool next, int n);
00498
00503 void moveCaretToLineBoundary(bool end);
00504
00509 void moveCaretToDocumentBoundary(bool end);
00510
00519 void placeCaretOnChar(khtml::CaretBox *hintBox);
00520
00537 void placeCaretOnLine(khtml::CaretBox *caretBox, int x, int absx, int absy);
00538
00542 void moveCaretByPage(bool next);
00543
00546 void moveCaretPrevWord();
00547
00550 void moveCaretNextWord();
00551
00556 void moveCaretPrevLine(int n = 1);
00557
00562 void moveCaretNextLine(int n = 1);
00563
00566 void moveCaretPrevPage();
00567
00570 void moveCaretNextPage();
00571
00574 void moveCaretToLineBegin();
00575
00578 void moveCaretToLineEnd();
00579
00580 #endif // KHTML_NO_CARET
00581
00582
00583 private:
00584
00585 void setWidgetVisible(::khtml::RenderWidget*, bool visible);
00586
00587 int _width;
00588 int _height;
00589
00590 int _marginWidth;
00591 int _marginHeight;
00592
00593 KHTMLPart *m_part;
00594 KHTMLViewPrivate *d;
00595
00596 QString m_medium;
00597 };
00598
00599 #endif
00600