1 | /* This file is part of the KDE project |
2 | |
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) |
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 <QtGui/QScrollArea> |
33 | |
34 | class QPainter; |
35 | class QRect; |
36 | template< typename T > class QVector; |
37 | template <class T> class QStack; |
38 | |
39 | namespace DOM { |
40 | class HTMLDocumentImpl; |
41 | class DocumentImpl; |
42 | class ElementImpl; |
43 | class HTMLTitleElementImpl; |
44 | class HTMLGenericFormElementImpl; |
45 | class HTMLFormElementImpl; |
46 | class HTMLAnchorElementImpl; |
47 | class HTMLInputElementImpl; |
48 | class NodeImpl; |
49 | class CSSProperty; |
50 | } |
51 | |
52 | namespace KJS { |
53 | class WindowFunc; |
54 | class ExternalFunc; |
55 | } |
56 | |
57 | namespace khtml { |
58 | class RenderObject; |
59 | class RenderCanvas; |
60 | class RenderLineEdit; |
61 | class RenderPartObject; |
62 | class RenderWidget; |
63 | class RenderLayer; |
64 | class RenderBox; |
65 | class CSSStyleSelector; |
66 | class LineEditWidget; |
67 | class CaretBox; |
68 | class HTMLTokenizer; |
69 | class KHTMLWidgetPrivate; |
70 | class KHTMLWidget |
71 | { |
72 | public: |
73 | KHTMLWidget(); |
74 | ~KHTMLWidget(); |
75 | KHTMLWidgetPrivate* m_kwp; |
76 | }; |
77 | void applyRule(DOM::CSSProperty *prop); |
78 | } |
79 | |
80 | class KHTMLPart; |
81 | class KHTMLViewPrivate; |
82 | |
83 | namespace khtml { |
84 | |
85 | } |
86 | |
87 | /** |
88 | * Renders and displays HTML in a QScrollArea. |
89 | * |
90 | * Suitable for use as an application's main view. |
91 | **/ |
92 | class KHTML_EXPORT KHTMLView : public QScrollArea, public khtml::KHTMLWidget |
93 | { |
94 | Q_OBJECT |
95 | |
96 | friend class DOM::HTMLDocumentImpl; |
97 | friend class DOM::HTMLTitleElementImpl; |
98 | friend class DOM::HTMLGenericFormElementImpl; |
99 | friend class DOM::HTMLFormElementImpl; |
100 | friend class DOM::HTMLAnchorElementImpl; |
101 | friend class DOM::HTMLInputElementImpl; |
102 | friend class DOM::NodeImpl; |
103 | friend class DOM::ElementImpl; |
104 | friend class DOM::DocumentImpl; |
105 | friend class KHTMLPart; |
106 | friend class KHTMLFind; |
107 | friend class StorePass; |
108 | friend class khtml::RenderCanvas; |
109 | friend class khtml::RenderObject; |
110 | friend class khtml::RenderLineEdit; |
111 | friend class khtml::RenderPartObject; |
112 | friend class khtml::RenderWidget; |
113 | friend class khtml::KHTMLWidgetPrivate; |
114 | friend class khtml::RenderLayer; |
115 | friend class khtml::RenderBox; |
116 | friend class khtml::CSSStyleSelector; |
117 | friend class khtml::LineEditWidget; |
118 | friend class khtml::HTMLTokenizer; |
119 | friend class KJS::WindowFunc; |
120 | friend class KJS::ExternalFunc; |
121 | friend void khtml::applyRule(DOM::CSSProperty *prop); |
122 | |
123 | |
124 | public: |
125 | /** |
126 | * Constructs a KHTMLView. |
127 | */ |
128 | KHTMLView( KHTMLPart *part, QWidget *parent ); |
129 | virtual ~KHTMLView(); |
130 | |
131 | /** |
132 | * Returns a pointer to the KHTMLPart that is |
133 | * rendering the page. |
134 | **/ |
135 | KHTMLPart *part() const { return m_part; } |
136 | |
137 | int frameWidth() const { return _width; } |
138 | |
139 | /** |
140 | * Sets a margin in x direction. |
141 | */ |
142 | void setMarginWidth(int x); |
143 | |
144 | /** |
145 | * Returns the margin width. |
146 | * |
147 | * A return value of -1 means the default value will be used. |
148 | */ |
149 | int marginWidth() const { return _marginWidth; } |
150 | |
151 | /* |
152 | * Sets a margin in y direction. |
153 | */ |
154 | void setMarginHeight(int y); |
155 | |
156 | /** |
157 | * Returns the margin height. |
158 | * |
159 | * A return value of -1 means the default value will be used. |
160 | */ |
161 | int marginHeight() { return _marginHeight; } |
162 | |
163 | /** |
164 | * Sets vertical scrollbar mode. |
165 | * |
166 | * WARNING: do not call this method on a base class pointer unless you |
167 | * specifically want QAbstractScrollArea's variant (not recommended). |
168 | * QAbstractScrollArea::setVerticalScrollBarPolicy is *not* virtual. |
169 | */ |
170 | virtual void setVerticalScrollBarPolicy( Qt::ScrollBarPolicy policy ); |
171 | |
172 | /** |
173 | * Sets horizontal scrollbar mode. |
174 | * |
175 | * WARNING: do not call this method on a base class pointer unless you |
176 | * specifically want QAbstractScrollArea's variant (not recommended). |
177 | * QAbstractScrollArea::setHorizontalScrollBarPolicy is *not* virtual. |
178 | */ |
179 | virtual void setHorizontalScrollBarPolicy( Qt::ScrollBarPolicy policy ); |
180 | |
181 | /** |
182 | * Prints the HTML document. |
183 | * @param quick if true, fully automated printing, without print dialog |
184 | */ |
185 | void print( bool quick = false ); |
186 | |
187 | /** |
188 | * Display all accesskeys in small tooltips |
189 | */ |
190 | void displayAccessKeys(); |
191 | |
192 | /** |
193 | * Returns the contents area's width |
194 | */ |
195 | int contentsWidth() const; |
196 | |
197 | /** |
198 | * Returns the contents area's height |
199 | */ |
200 | int contentsHeight() const; |
201 | |
202 | /** |
203 | * Returns the x coordinate of the contents area point |
204 | * that is currently located at the top left in the viewport |
205 | */ |
206 | int contentsX() const; |
207 | |
208 | /** |
209 | * Returns the y coordinate of the contents area point |
210 | * that is currently located at the top left in the viewport |
211 | */ |
212 | int contentsY() const; |
213 | |
214 | /** |
215 | * Returns the width of the viewport |
216 | */ |
217 | int visibleWidth() const; |
218 | |
219 | /** |
220 | * Returns the height of the viewport |
221 | */ |
222 | int visibleHeight() const; |
223 | |
224 | /** |
225 | * Place the contents area point x/y |
226 | * at the top left of the viewport |
227 | */ |
228 | void setContentsPos(int x, int y); |
229 | |
230 | /** |
231 | * Returns a point translated to viewport coordinates |
232 | * @param p the contents area point to translate |
233 | * |
234 | */ |
235 | QPoint contentsToViewport(const QPoint& p) const; |
236 | |
237 | /** |
238 | * Returns a point translated to contents area coordinates |
239 | * @param p the viewport point to translate |
240 | * |
241 | */ |
242 | QPoint viewportToContents(const QPoint& p) const; |
243 | |
244 | /** |
245 | * Returns a point translated to contents area coordinates |
246 | * @param x x coordinate of viewport point to translate |
247 | * @param y y coordinate of viewport point to translate |
248 | * @param cx resulting x coordinate |
249 | * @param cy resulting y coordinate |
250 | * |
251 | */ |
252 | void viewportToContents(int x, int y, int& cx, int& cy) const; |
253 | |
254 | /** |
255 | * Returns a point translated to viewport coordinates |
256 | * @param x x coordinate of contents area point to translate |
257 | * @param y y coordinate of contents area point to translate |
258 | * @param cx resulting x coordinate |
259 | * @param cy resulting y coordinate |
260 | * |
261 | */ |
262 | void contentsToViewport(int x, int y, int& cx, int& cy) const; |
263 | |
264 | /** |
265 | * Scrolls the content area by a given amount |
266 | * @param x x offset |
267 | * @param y y offset |
268 | */ |
269 | void scrollBy(int x, int y); |
270 | |
271 | /** |
272 | * Requests an update of the content area |
273 | * @param r the content area rectangle to update |
274 | */ |
275 | void updateContents( const QRect& r ); |
276 | void updateContents(int x, int y, int w, int h); |
277 | |
278 | void addChild(QWidget *child, int dx, int dy); |
279 | |
280 | /** |
281 | * Requests an immediate repaint of the content area |
282 | * @param r the content area rectangle to repaint |
283 | */ |
284 | void repaintContents( const QRect& r ); |
285 | void repaintContents(int x, int y, int w, int h); |
286 | |
287 | /** |
288 | * Apply a zoom level to the content area |
289 | * @param percent a zoom level expressed as a percentage |
290 | */ |
291 | void setZoomLevel( int percent ); |
292 | |
293 | /** |
294 | * Retrieve the current zoom level |
295 | * |
296 | */ |
297 | int zoomLevel() const; |
298 | |
299 | /** |
300 | * Smooth Scrolling Mode enumeration |
301 | * @li SSMDisabled smooth scrolling is disabled |
302 | * @li SSMWhenEfficient only use smooth scrolling on pages that do not require a full repaint of the content area when scrolling |
303 | * @li SSMAlways smooth scrolling is performed unconditionally |
304 | */ |
305 | enum SmoothScrollingMode { SSMDisabled = 0, SSMWhenEfficient, SSMEnabled }; |
306 | |
307 | /** |
308 | * Set the smooth scrolling mode. |
309 | * |
310 | * Smooth scrolling mode is normally controlled by the configuration file's SmoothScrolling key. |
311 | * Using this setter will override the configuration file's settings. |
312 | * |
313 | * @since 4.1 |
314 | */ |
315 | void setSmoothScrollingMode( SmoothScrollingMode m ); |
316 | |
317 | /** |
318 | * Retrieve the current smooth scrolling mode |
319 | * |
320 | * @since 4.1 |
321 | */ |
322 | SmoothScrollingMode smoothScrollingMode() const; |
323 | |
324 | public Q_SLOTS: |
325 | /** |
326 | * Resize the contents area |
327 | * @param w the new width |
328 | * @param h the new height |
329 | */ |
330 | virtual void resizeContents(int w, int h); |
331 | |
332 | /** |
333 | * ensure the display is up to date |
334 | */ |
335 | void layout(); |
336 | |
337 | |
338 | Q_SIGNALS: |
339 | /** |
340 | * This signal is used for internal layouting. Don't use it to check if rendering finished. |
341 | * Use @ref KHTMLPart completed() signal instead. |
342 | */ |
343 | void finishedLayout(); |
344 | void cleared(); |
345 | void zoomView( int ); |
346 | void hideAccessKeys(); |
347 | void repaintAccessKeys(); |
348 | void findAheadActive( bool ); |
349 | |
350 | protected: |
351 | void clear(); |
352 | |
353 | virtual bool event ( QEvent * event ); |
354 | virtual void paintEvent( QPaintEvent * ); |
355 | virtual void resizeEvent ( QResizeEvent * event ); |
356 | virtual void showEvent ( QShowEvent * ); |
357 | virtual void hideEvent ( QHideEvent *); |
358 | virtual bool focusNextPrevChild( bool next ); |
359 | virtual void mousePressEvent( QMouseEvent * ); |
360 | virtual void focusInEvent( QFocusEvent * ); |
361 | virtual void focusOutEvent( QFocusEvent * ); |
362 | virtual void mouseDoubleClickEvent( QMouseEvent * ); |
363 | virtual void mouseMoveEvent(QMouseEvent *); |
364 | virtual void mouseReleaseEvent(QMouseEvent *); |
365 | #ifndef QT_NO_WHEELEVENT |
366 | virtual void wheelEvent(QWheelEvent*); |
367 | #endif |
368 | virtual void dragEnterEvent( QDragEnterEvent* ); |
369 | virtual void dropEvent( QDropEvent* ); |
370 | virtual void closeEvent ( QCloseEvent * ); |
371 | virtual bool widgetEvent( QEvent * ); |
372 | virtual bool viewportEvent( QEvent * e ); |
373 | virtual bool eventFilter(QObject *, QEvent *); |
374 | virtual void scrollContentsBy( int dx, int dy ); |
375 | |
376 | void keyPressEvent( QKeyEvent *_ke ); |
377 | void keyReleaseEvent ( QKeyEvent *_ke ); |
378 | void doAutoScroll(); |
379 | void timerEvent ( QTimerEvent * ); |
380 | |
381 | void setSmoothScrollingModeDefault( SmoothScrollingMode m ); |
382 | |
383 | protected Q_SLOTS: |
384 | void slotPaletteChanged(); |
385 | |
386 | private Q_SLOTS: |
387 | void tripleClickTimeout(); |
388 | void accessKeysTimeout(); |
389 | void scrollTick(); |
390 | |
391 | /** |
392 | * @internal |
393 | * used for autoscrolling with MMB |
394 | */ |
395 | void slotMouseScrollTimer(); |
396 | |
397 | private: |
398 | void resizeContentsToViewport(); |
399 | |
400 | void scheduleRelayout(khtml::RenderObject* clippedObj=0); |
401 | void unscheduleRelayout(); |
402 | |
403 | bool hasLayoutPending(); |
404 | |
405 | void scheduleRepaint(int x, int y, int w, int h, bool asap=false); |
406 | void unscheduleRepaint(); |
407 | |
408 | bool needsFullRepaint() const; |
409 | |
410 | void closeChildDialogs(); |
411 | bool dialogsAllowed(); |
412 | |
413 | void setMouseEventsTarget( QWidget* w ); |
414 | QWidget* mouseEventsTarget() const; |
415 | |
416 | QStack<QRegion>* clipHolder() const; |
417 | void setClipHolder( QStack<QRegion>* ch ); |
418 | |
419 | void setPart(KHTMLPart *part); |
420 | |
421 | /** |
422 | * Paints the HTML document to a QPainter. |
423 | * The document will be scaled to match the width of |
424 | * rc and clipped to fit in the height. |
425 | * yOff determines the vertical offset in the document to start with. |
426 | * more, if nonzero will be set to true if the documents extends |
427 | * beyond the rc or false if everything below yOff was painted. |
428 | **/ |
429 | void paint(QPainter *p, const QRect &rc, int yOff = 0, bool *more = 0); |
430 | |
431 | void render(QPainter *p, const QRect& r, const QPoint& off); |
432 | |
433 | /** |
434 | * Get/set the CSS Media Type. |
435 | * |
436 | * Media type is set to "screen" for on-screen rendering and "print" |
437 | * during printing. Other media types lack the proper support in the |
438 | * renderer and are not activated. The DOM tree and the parser itself, |
439 | * however, properly handle other media types. To make them actually work |
440 | * you only need to enable the media type in the view and if necessary |
441 | * add the media type dependent changes to the renderer. |
442 | */ |
443 | void setMediaType( const QString &medium ); |
444 | QString mediaType() const; |
445 | |
446 | bool pagedMode() const; |
447 | |
448 | bool scrollTo(const QRect &); |
449 | |
450 | bool focusNextPrevNode(bool next); |
451 | bool handleAccessKey(const QKeyEvent* ev); |
452 | bool focusNodeWithAccessKey(QChar c, KHTMLView* caller = NULL); |
453 | QMap< DOM::ElementImpl*, QChar > buildFallbackAccessKeys() const; |
454 | void displayAccessKeys( KHTMLView* caller, KHTMLView* origview, QVector< QChar >& taken, bool use_fallbacks ); |
455 | bool isScrollingFromMouseWheel() const; |
456 | void setHasStaticBackground(bool partial=false); |
457 | void setHasNormalBackground(); |
458 | void addStaticObject(bool fixed); |
459 | void removeStaticObject(bool fixed); |
460 | void applyTransforms( int& x, int& y, int& w, int& h) const; |
461 | void revertTransforms( int& x, int& y, int& w, int& h) const; |
462 | void revertTransforms( int& x, int& y ) const; |
463 | void checkExternalWidgetsPosition(); |
464 | |
465 | void setIgnoreWheelEvents(bool e); |
466 | |
467 | void init(); |
468 | |
469 | DOM::NodeImpl *nodeUnderMouse() const; |
470 | DOM::NodeImpl *nonSharedNodeUnderMouse() const; |
471 | |
472 | void restoreScrollBar(); |
473 | |
474 | QStringList formCompletionItems(const QString &name) const; |
475 | void clearCompletionHistory(const QString& name); |
476 | void addFormCompletionItem(const QString &name, const QString &value); |
477 | |
478 | void addNonPasswordStorableSite( const QString& host ); |
479 | void delNonPasswordStorableSite( const QString& host ); |
480 | bool nonPasswordStorableSite( const QString& host ) const; |
481 | |
482 | bool dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode, |
483 | DOM::NodeImpl *targetNodeNonShared, bool cancelable, |
484 | int detail,QMouseEvent *_mouse, bool setUnder, |
485 | int mouseEventType, int orientation=0); |
486 | bool dispatchKeyEvent( QKeyEvent *_ke ); |
487 | bool dispatchKeyEventHelper( QKeyEvent *_ke, bool generate_keypress ); |
488 | |
489 | void complete( bool pendingAction ); |
490 | |
491 | void updateScrollBars(); |
492 | void setupSmoothScrolling(int dx, int dy); |
493 | |
494 | /** |
495 | * Returns the current caret policy when the view is not focused. |
496 | * @return a KHTMLPart::CaretDisplay value |
497 | */ |
498 | int caretDisplayPolicyNonFocused() const; |
499 | |
500 | /** |
501 | * Sets the caret display policy when the view is not focused. |
502 | * @param policy new display policy as |
503 | * defined by KHTMLPart::CaretDisplayPolicy |
504 | */ |
505 | void setCaretDisplayPolicyNonFocused(int policy); |
506 | |
507 | // -- caret event handler |
508 | |
509 | /** |
510 | * Evaluates key presses for caret navigation on editable nodes. |
511 | * @return true if event has been handled |
512 | */ |
513 | bool caretKeyPressEvent(QKeyEvent *); |
514 | |
515 | // ------------------------------------- member variables ------------------------------------ |
516 | private: |
517 | friend class KHTMLViewPrivate; |
518 | enum LinkCursor { LINK_NORMAL, LINK_MAILTO, LINK_NEWWINDOW }; |
519 | |
520 | void setWidgetVisible(::khtml::RenderWidget*, bool visible); |
521 | |
522 | |
523 | int _width; |
524 | int _height; |
525 | |
526 | int _marginWidth; |
527 | int _marginHeight; |
528 | |
529 | KHTMLPart *m_part; |
530 | KHTMLViewPrivate* const d; |
531 | |
532 | QString m_medium; // media type |
533 | }; |
534 | |
535 | #endif |
536 | |
537 | |