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 
00221 #ifndef NO_SMOOTH_SCROLL_HACK
00222     void startScrolling();
00223     void stopScrolling();
00224 #ifndef QT_NO_WHEELEVENT
00225     void scrollViewWheelEvent( QWheelEvent* e );
00226 #endif
00227 #endif
00228 
00229 protected slots:
00230     void slotPaletteChanged();
00231     void slotScrollBarMoved();
00232 #ifndef NO_SMOOTH_SCROLL_HACK
00233     void scrollTick();
00234 #else
00235     void scrollTick() {}; // moc cannot handle #if
00236 #endif
00237 
00238 private slots:
00239     void tripleClickTimeout();
00240     void findTimeout();
00241     void accessKeysTimeout();
00242 
00248     void slotMouseScrollTimer();
00249 
00250 private:
00251 
00252     void scheduleRelayout(khtml::RenderObject* clippedObj=0);
00253     void unscheduleRelayout();
00254 
00255     void scheduleRepaint(int x, int y, int w, int h, bool asap=false);
00256     void unscheduleRepaint();
00257 
00258     bool needsFullRepaint() const;
00259 
00260     void closeChildDialogs();
00261     bool dialogsAllowed();
00262 
00271     void paint(QPainter *p, const QRect &rc, int yOff = 0, bool *more = 0);
00272 
00273 #if 0
00274 
00278     void paint(QPainter *p, int width);
00279 #endif
00280 
00291     void setMediaType( const QString &medium );
00292     QString mediaType() const;
00293 
00294     bool pagedMode() const;
00295 
00296     bool scrollTo(const QRect &);
00297 
00298     bool focusNextPrevNode(bool next);
00299     bool handleAccessKey(const QKeyEvent* ev);
00300     bool focusNodeWithAccessKey(QChar c, KHTMLView* caller = NULL);
00301     QMap< DOM::ElementImpl*, QChar > buildFallbackAccessKeys() const;
00302     void displayAccessKeys( KHTMLView* caller, KHTMLView* origview, QValueVector< QChar >& taken, bool use_fallbacks );
00303 
00304     void useSlowRepaints();
00305 
00306     void setIgnoreWheelEvents(bool e);
00307 
00308     void init();
00309 
00310     DOM::NodeImpl *nodeUnderMouse() const;
00311     DOM::NodeImpl *nonSharedNodeUnderMouse() const;
00312 
00313     void restoreScrollBar();
00314 
00315     QStringList formCompletionItems(const QString &name) const;
00316     void clearCompletionHistory(const QString& name);
00317     void addFormCompletionItem(const QString &name, const QString &value);
00318 
00319     void addNonPasswordStorableSite( const QString& host );
00320     bool nonPasswordStorableSite( const QString& host ) const;
00321 
00322     bool dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode,
00323                 DOM::NodeImpl *targetNodeNonShared, bool cancelable,
00324                 int detail,QMouseEvent *_mouse, bool setUnder,
00325                 int mouseEventType);
00326     bool dispatchKeyEvent( QKeyEvent *_ke );
00327     bool dispatchKeyEventHelper( QKeyEvent *_ke, bool generate_keypress );
00328 
00329     void complete( bool pendingAction );
00330 
00331 #ifndef KHTML_NO_TYPE_AHEAD_FIND
00332     void findAhead(bool increase);
00333     void updateFindAheadTimeout();
00334     void startFindAhead( bool linksOnly );
00335 #endif // KHTML_NO_TYPE_AHEAD_FIND
00336 
00337 #ifndef KHTML_NO_CARET
00338     // -- caret-related member functions (for caretMode as well as designMode)
00339 
00350     void initCaret(bool keepSelection = false);
00353     bool caretOverrides() const;
00361     void ensureNodeHasFocus(DOM::NodeImpl *node);
00368     void recalcAndStoreCaretPos(khtml::CaretBox *hintBox = 0);
00375     void caretOn();
00381     void caretOff();
00390     void showCaret(bool forceRepaint = false);
00397     void hideCaret();
00402     void ensureCaretVisible();
00403 
00419     bool foldSelectionToCaret(DOM::NodeImpl *startNode, long startOffset,
00420                     DOM::NodeImpl *endNode, long endOffset);
00421 
00431     bool placeCaret(khtml::CaretBox *hintBox = 0);
00432 
00449     bool extendSelection(DOM::NodeImpl *startNode, long startOffset,
00450                 DOM::NodeImpl *endNode, long endOffset);
00451 
00461     void updateSelection(DOM::NodeImpl *startNode, long startOffset,
00462             DOM::NodeImpl *endNode, long endOffset);
00463 
00468     int caretDisplayPolicyNonFocused() const;
00469 
00476     void setCaretDisplayPolicyNonFocused(int policy);
00477 
00478     // -- caret event handler
00479 
00483     void caretKeyPressEvent(QKeyEvent *);
00484 
00485     // -- caret navigation member functions
00486 
00498     bool moveCaretTo(DOM::NodeImpl *node, long offset, bool clearSelection);
00499 
00505     enum CaretMovement { CaretByCharacter, CaretByWord };
00506 
00517     void moveCaretBy(bool next, CaretMovement cmv, int n);
00518 
00521     void moveCaretByLine(bool next, int n);
00522 
00527     void moveCaretToLineBoundary(bool end);
00528 
00533     void moveCaretToDocumentBoundary(bool end);
00534 
00543     void placeCaretOnChar(khtml::CaretBox *hintBox);
00544 
00561     void placeCaretOnLine(khtml::CaretBox *caretBox, int x, int absx, int absy);
00562 
00566     void moveCaretByPage(bool next);
00567 
00570     void moveCaretPrevWord();
00571 
00574     void moveCaretNextWord();
00575 
00580     void moveCaretPrevLine(int n = 1);
00581 
00586     void moveCaretNextLine(int n = 1);
00587 
00590     void moveCaretPrevPage();
00591 
00594     void moveCaretNextPage();
00595 
00598     void moveCaretToLineBegin();
00599 
00602     void moveCaretToLineEnd();
00603 
00604 #endif // KHTML_NO_CARET
00605 
00606     // ------------------------------------- member variables ------------------------------------
00607  private:
00608 
00609     void setWidgetVisible(::khtml::RenderWidget*, bool visible);
00610 
00611     int _width;
00612     int _height;
00613 
00614     int _marginWidth;
00615     int _marginHeight;
00616 
00617     KHTMLPart *m_part;
00618     KHTMLViewPrivate *d;
00619 
00620     QString m_medium;   // media type
00621 };
00622 
00623 #endif
00624 
KDE Home | KDE Accessibility Home | Description of Access Keys