khtmlview.h

00001 /* This file is part of the KDE project
00002 
00003    Copyright (C) 1997 Martin Jones (mjones@kde.org)
00004              (C) 1998 Waldo Bastian (bastian@kde.org)
00005              (C) 1998, 1999 Torben Weis (weis@kde.org)
00006              (C) 1999 Lars Knoll (knoll@kde.org)
00007              (C) 1999 Antti Koivisto (koivisto@kde.org)
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License as published by the Free Software Foundation; either
00012    version 2 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Library General Public License for more details.
00018 
00019    You should have received a copy of the GNU Library General Public License
00020    along with this library; see the file COPYING.LIB.  If not, write to
00021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022    Boston, MA 02110-1301, USA.
00023 */
00024 
00025 #ifndef KHTMLVIEW_H
00026 #define KHTMLVIEW_H
00027 
00028 // qt includes and classes
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      * Sets a margin in y direction.
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 ); // KDE 4.0: merge with above
00161 
00165     void layout(); // KDE 4.0: make private
00169     void displayAccessKeys();
00170 
00171 
00172 
00173 signals:
00178     void finishedLayout();
00179     void cleared();
00180     void zoomView( int );
00181     void hideAccessKeys();
00182     void repaintAccessKeys();
00183     void findAheadActive( bool );
00184 //#define NO_SMOOTH_SCROLL_HACK
00185 #ifndef NO_SMOOTH_SCROLL_HACK
00186 public slots:
00187     void scrollBy(int dx, int dy);
00188 #endif
00189 
00190 protected:
00191     void clear();
00192 
00193     virtual void resizeEvent ( QResizeEvent * event );
00194     virtual void showEvent ( QShowEvent * );
00195     virtual void hideEvent ( QHideEvent *);
00196     virtual bool focusNextPrevChild( bool next );
00197     virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
00198     virtual void drawContents( QPainter* );
00199     virtual void viewportMousePressEvent( QMouseEvent * );
00200     virtual void focusInEvent( QFocusEvent * );
00201     virtual void focusOutEvent( QFocusEvent * );
00202     virtual void viewportMouseDoubleClickEvent( QMouseEvent * );
00203     virtual void viewportMouseMoveEvent(QMouseEvent *);
00204     virtual void viewportMouseReleaseEvent(QMouseEvent *);
00205     virtual void viewportResizeEvent(QResizeEvent*);
00206 #ifndef QT_NO_WHEELEVENT
00207     virtual void viewportWheelEvent(QWheelEvent*);
00208 #endif
00209     virtual void dragEnterEvent( QDragEnterEvent* );
00210     virtual void dropEvent( QDropEvent* );
00211     virtual void closeEvent ( QCloseEvent * );
00212     virtual bool eventFilter(QObject *, QEvent *);
00213 
00214     void keyPressEvent( QKeyEvent *_ke );
00215     void keyReleaseEvent ( QKeyEvent *_ke );
00216     void contentsContextMenuEvent ( QContextMenuEvent *_ce );
00217     void doAutoScroll();
00218     void timerEvent ( QTimerEvent * );
00219 
00220 #ifndef NO_SMOOTH_SCROLL_HACK
00221     void startScrolling();
00222     void stopScrolling();
00223 #ifndef QT_NO_WHEELEVENT
00224     void scrollViewWheelEvent( QWheelEvent* e );
00225 #endif
00226 #endif
00227 
00228 protected slots:
00229     void slotPaletteChanged();
00230     void slotScrollBarMoved();
00231 #ifndef NO_SMOOTH_SCROLL_HACK
00232     void scrollTick();
00233 #else
00234     void scrollTick() {}; // moc cannot handle #if
00235 #endif
00236 
00237 private slots:
00238     void tripleClickTimeout();
00239     void findTimeout();
00240     void accessKeysTimeout();
00241 
00247     void slotMouseScrollTimer();
00248 
00249 private:
00250 
00251     void scheduleRelayout(khtml::RenderObject* clippedObj=0);
00252     void unscheduleRelayout();
00253 
00254     void scheduleRepaint(int x, int y, int w, int h, bool asap=false);
00255     void unscheduleRepaint();
00256 
00257     bool needsFullRepaint() const;
00258 
00259     void closeChildDialogs();
00260     bool dialogsAllowed();
00261 
00270     void paint(QPainter *p, const QRect &rc, int yOff = 0, bool *more = 0);
00271 
00272 #if 0
00273 
00277     void paint(QPainter *p, int width);
00278 #endif
00279 
00290     void setMediaType( const QString &medium );
00291     QString mediaType() const;
00292 
00293     bool pagedMode() const;
00294 
00295     bool scrollTo(const QRect &);
00296 
00297     bool focusNextPrevNode(bool next);
00298     bool handleAccessKey(const QKeyEvent* ev);
00299     bool focusNodeWithAccessKey(QChar c, KHTMLView* caller = NULL);
00300     QMap< DOM::ElementImpl*, QChar > buildFallbackAccessKeys() const;
00301     void displayAccessKeys( KHTMLView* caller, KHTMLView* origview, QValueVector< QChar >& taken, bool use_fallbacks );
00302 
00303     void useSlowRepaints();
00304 
00305     void setIgnoreWheelEvents(bool e);
00306 
00307     void init();
00308 
00309     DOM::NodeImpl *nodeUnderMouse() const;
00310     DOM::NodeImpl *nonSharedNodeUnderMouse() const;
00311 
00312     void restoreScrollBar();
00313 
00314     QStringList formCompletionItems(const QString &name) const;
00315     void clearCompletionHistory(const QString& name);
00316     void addFormCompletionItem(const QString &name, const QString &value);
00317 
00318     void addNonPasswordStorableSite( const QString& host );
00319     bool nonPasswordStorableSite( const QString& host ) const;
00320 
00321     bool dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode,
00322                 DOM::NodeImpl *targetNodeNonShared, bool cancelable,
00323                 int detail,QMouseEvent *_mouse, bool setUnder,
00324                 int mouseEventType);
00325     bool dispatchKeyEvent( QKeyEvent *_ke );
00326     bool dispatchKeyEventHelper( QKeyEvent *_ke, bool generate_keypress );
00327 
00328     void complete( bool pendingAction );
00329 
00330 #ifndef KHTML_NO_TYPE_AHEAD_FIND
00331     void findAhead(bool increase);
00332     void updateFindAheadTimeout();
00333     void startFindAhead( bool linksOnly );
00334 #endif // KHTML_NO_TYPE_AHEAD_FIND
00335 
00336 #ifndef KHTML_NO_CARET
00337     // -- caret-related member functions (for caretMode as well as designMode)
00338 
00349     void initCaret(bool keepSelection = false);
00352     bool caretOverrides() const;
00360     void ensureNodeHasFocus(DOM::NodeImpl *node);
00367     void recalcAndStoreCaretPos(khtml::CaretBox *hintBox = 0);
00374     void caretOn();
00380     void caretOff();
00389     void showCaret(bool forceRepaint = false);
00396     void hideCaret();
00401     void ensureCaretVisible();
00402 
00418     bool foldSelectionToCaret(DOM::NodeImpl *startNode, long startOffset,
00419                     DOM::NodeImpl *endNode, long endOffset);
00420 
00430     bool placeCaret(khtml::CaretBox *hintBox = 0);
00431 
00448     bool extendSelection(DOM::NodeImpl *startNode, long startOffset,
00449                 DOM::NodeImpl *endNode, long endOffset);
00450 
00460     void updateSelection(DOM::NodeImpl *startNode, long startOffset,
00461             DOM::NodeImpl *endNode, long endOffset);
00462 
00467     int caretDisplayPolicyNonFocused() const;
00468 
00475     void setCaretDisplayPolicyNonFocused(int policy);
00476 
00477     // -- caret event handler
00478 
00482     void caretKeyPressEvent(QKeyEvent *);
00483 
00484     // -- caret navigation member functions
00485 
00497     bool moveCaretTo(DOM::NodeImpl *node, long offset, bool clearSelection);
00498 
00504     enum CaretMovement { CaretByCharacter, CaretByWord };
00505 
00516     void moveCaretBy(bool next, CaretMovement cmv, int n);
00517 
00520     void moveCaretByLine(bool next, int n);
00521 
00526     void moveCaretToLineBoundary(bool end);
00527 
00532     void moveCaretToDocumentBoundary(bool end);
00533 
00542     void placeCaretOnChar(khtml::CaretBox *hintBox);
00543 
00560     void placeCaretOnLine(khtml::CaretBox *caretBox, int x, int absx, int absy);
00561 
00565     void moveCaretByPage(bool next);
00566 
00569     void moveCaretPrevWord();
00570 
00573     void moveCaretNextWord();
00574 
00579     void moveCaretPrevLine(int n = 1);
00580 
00585     void moveCaretNextLine(int n = 1);
00586 
00589     void moveCaretPrevPage();
00590 
00593     void moveCaretNextPage();
00594 
00597     void moveCaretToLineBegin();
00598 
00601     void moveCaretToLineEnd();
00602 
00603 #endif // KHTML_NO_CARET
00604 
00605     // ------------------------------------- member variables ------------------------------------
00606  private:
00607 
00608     void setWidgetVisible(::khtml::RenderWidget*, bool visible);
00609 
00610     int _width;
00611     int _height;
00612 
00613     int _marginWidth;
00614     int _marginHeight;
00615 
00616     KHTMLPart *m_part;
00617     KHTMLViewPrivate *d;
00618 
00619     QString m_medium;   // media type
00620 };
00621 
00622 #endif
00623 
KDE Home | KDE Accessibility Home | Description of Access Keys