FrameView.h 8.12 KB
Newer Older
kocienda's avatar
kocienda committed
1
2
3
4
5
6
7
/* This file is part of the KDE project

   Copyright (C) 1997 Martin Jones (mjones@kde.org)
             (C) 1998 Waldo Bastian (bastian@kde.org)
             (C) 1998, 1999 Torben Weis (weis@kde.org)
             (C) 1999 Lars Knoll (knoll@kde.org)
             (C) 1999 Antti Koivisto (koivisto@kde.org)
8
   Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
kocienda's avatar
kocienda committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

26
27
#ifndef FRAMEVIEW_H
#define FRAMEVIEW_H
kocienda's avatar
kocienda committed
28
29
30
31

// qt includes and classes
#include <qscrollview.h>

darin's avatar
darin committed
32
33
34
35
36
37
class QFocusEvent;
class QKeyEvent;
class QMouseEvent;
class QResizeEvent;
class QStringList;
class QWheelEvent;
kocienda's avatar
kocienda committed
38

darin's avatar
darin committed
39
namespace WebCore {
kocienda's avatar
kocienda committed
40

darin's avatar
darin committed
41
42
43
44
45
46
class CSSProperty;
class CSSStyleSelector;
class ClipboardImpl;
class DocumentImpl;
class ElementImpl;
class Frame;
47
class FrameViewPrivate;
darin's avatar
darin committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class HTMLAnchorElementImpl;
class HTMLDocumentImpl;
class HTMLElementImpl;
class HTMLFormElementImpl;
class HTMLGenericFormElementImpl;
class HTMLTitleElementImpl;
class InlineBox;
class IntRect;
class MacFrame;
class NodeImpl;
class QPainter;
class RenderBox;
class RenderCanvas;
class RenderLineEdit;
class RenderObject;
class RenderPart;
class RenderPartObject;
class RenderStyle;
class RenderWidget;

template <typename T> class Timer;

void applyRule(CSSProperty*);
kocienda's avatar
kocienda committed
71
72

/**
73
 * Renders and displays HTML in a @ref QScrollView.
kocienda's avatar
kocienda committed
74
75
76
 *
 * Suitable for use as an application's main view.
 **/
77
class FrameView : public QScrollView
kocienda's avatar
kocienda committed
78
79
80
{
    Q_OBJECT

darin's avatar
darin committed
81
82
    friend class CSSStyleSelector;
    friend class DocumentImpl;
mjs's avatar
mjs committed
83
    friend class Frame;
darin's avatar
darin committed
84
85
86
87
88
    friend class HTMLAnchorElementImpl;
    friend class HTMLDocumentImpl;
    friend class HTMLFormElementImpl;
    friend class HTMLGenericFormElementImpl;
    friend class HTMLTitleElementImpl;
mjs's avatar
mjs committed
89
    friend class MacFrame;
darin's avatar
darin committed
90
91
92
93
94
95
96
97
    friend class RenderBox;
    friend class RenderCanvas;
    friend class RenderLineEdit;
    friend class RenderObject;
    friend class RenderPart;
    friend class RenderPartObject;
    friend class RenderWidget;
    friend void applyRule(DOM::CSSProperty *prop);
kocienda's avatar
kocienda committed
98
99
100

public:
    /**
101
     * Constructs a FrameView.
kocienda's avatar
kocienda committed
102
     */
darin's avatar
darin committed
103
    FrameView(Frame *frame, QWidget *parent, const char *name=0 );
104
    virtual ~FrameView();
kocienda's avatar
kocienda committed
105
106

    /**
mjs's avatar
mjs committed
107
     * Returns a pointer to the Frame that is
kocienda's avatar
kocienda committed
108
109
     * rendering the page.
     **/
darin's avatar
darin committed
110
    Frame *frame() const { return m_frame.get(); }
kocienda's avatar
kocienda committed
111
112
113
114

    int frameWidth() const { return _width; }

    /**
115
     * Sets a margin in x direction.
kocienda's avatar
kocienda committed
116
     */
117
    void setMarginWidth(int x);
kocienda's avatar
kocienda committed
118
119

    /**
120
     * Returns the margin width.
kocienda's avatar
kocienda committed
121
122
123
124
125
126
     *
     * A return value of -1 means the default value will be used.
     */
    int marginWidth() const { return _marginWidth; }

    /*
127
     * Sets a margin in y direction.
kocienda's avatar
kocienda committed
128
     */
129
    void setMarginHeight(int y);
kocienda's avatar
kocienda committed
130

131
132
    /**
     * Returns the margin height.
kocienda's avatar
kocienda committed
133
134
135
136
137
     *
     * A return value of -1 means the default value will be used.
     */
    int marginHeight() { return _marginHeight; }

138
139
    /**
     * Sets verticals scrollbar mode. Reimplemented for internal reasons.
kocienda's avatar
kocienda committed
140
141
142
     */
    virtual void setVScrollBarMode ( ScrollBarMode mode );

143
144
    /**
     * Sets horizontal scrollbar mode. Reimplemented for internal reasons.
kocienda's avatar
kocienda committed
145
146
147
     */
    virtual void setHScrollBarMode ( ScrollBarMode mode );

148
149
150
    // Sets both horizontal and vertical modes.
    virtual void setScrollBarsMode(ScrollBarMode mode);
    
151
152
153
154
    /**
     * Prints the HTML document.
     */
    void print();
kocienda's avatar
kocienda committed
155

156
157
158
159
    /**
     * ensure the display is up to date
     */
    void layout();
kocienda's avatar
kocienda committed
160

161
    bool inLayout() const;
162
    int layoutCount() const;
163
164

    bool needsFullRepaint() const;
165
    
166
    void addRepaintInfo(khtml::RenderObject* o, const IntRect& r);
167

168
169
    void resetScrollBars();

170
171
     void clear();

172
signals:
eseidel's avatar
eseidel committed
173
174
    void cleared();

175
public:
eseidel's avatar
eseidel committed
176
    void clearPart();
kocienda's avatar
kocienda committed
177
178
    virtual void resizeEvent ( QResizeEvent * event );
    virtual void viewportMousePressEvent( QMouseEvent * );
kocienda's avatar
kocienda committed
179
    virtual void focusInEvent( QFocusEvent * );
kocienda's avatar
kocienda committed
180
181
182
183
    virtual void focusOutEvent( QFocusEvent * );
    virtual void viewportMouseDoubleClickEvent( QMouseEvent * );
    virtual void viewportMouseMoveEvent(QMouseEvent *);
    virtual void viewportMouseReleaseEvent(QMouseEvent *);
184
#ifndef QT_NO_WHEELEVENT
kocienda's avatar
kocienda committed
185
    virtual void viewportWheelEvent(QWheelEvent*);
186
#endif
kocienda's avatar
kocienda committed
187
188
189
190

    void keyPressEvent( QKeyEvent *_ke );
    void doAutoScroll();

191
192
193
    bool updateDragAndDrop(const IntPoint &, DOM::ClipboardImpl *clipboard);
    void cancelDragAndDrop(const IntPoint &, DOM::ClipboardImpl *clipboard);
    bool performDragAndDrop(const IntPoint &, DOM::ClipboardImpl *clipboard);
trey's avatar
trey committed
194

darin's avatar
darin committed
195
    void layoutTimerFired(Timer<FrameView>*);
196

197
    void repaintRectangle(const IntRect& r, bool immediate);
darin's avatar
darin committed
198
199
200

    bool isTransparent() const;
    void setTransparent(bool isTransparent);
201
    
202
203
204
205
206
    void scheduleRelayout();
    void unscheduleRelayout();
    bool haveDelayedLayoutScheduled();
    bool layoutPending();

mjs's avatar
mjs committed
207
    QWidget *topLevelWidget() const;
208
    IntPoint mapToGlobal(const IntPoint &) const;
209
    // maps "viewport" (actually Cocoa window coords) to screen coords
210
    IntPoint viewportToGlobal(const IntPoint &) const;
211
    void adjustViewSize();
212
    void initScrollBars();
213
    
214
#if __APPLE__
215
    void updateDashboardRegions();
216
#endif
mjs's avatar
mjs committed
217
218
219

    void ref() { ++_refCount; }
    void deref() { if (!--_refCount) delete this; }
mjs's avatar
mjs committed
220
    
kocienda's avatar
kocienda committed
221
222
protected slots:
    void slotPaletteChanged();
223
    void slotScrollBarMoved();
kocienda's avatar
kocienda committed
224
225

private:
226
227

    void resetCursor();
darin's avatar
darin committed
228
    void invalidateClick();
229

kocienda's avatar
kocienda committed
230
    /**
231
232
233
234
235
236
237
     * Paints the HTML document to a QPainter.
     * The document will be scaled to match the width of
     * rc and clipped to fit in the height.
     * yOff determines the vertical offset in the document to start with.
     * more, if nonzero will be set to true if the documents extends
     * beyond the rc or false if everything below yOff was painted.
     **/
darin's avatar
darin committed
238
    void paint(QPainter *p, const IntRect &rc, int yOff = 0, bool *more = 0);
kocienda's avatar
kocienda committed
239
240

    /**
241
242
243
244
245
246
247
248
     * Get/set the CSS Media Type.
     *
     * Media type is set to "screen" for on-screen rendering and "print"
     * during printing. Other media types lack the proper support in the
     * renderer and are not activated. The DOM tree and the parser itself,
     * however, properly handle other media types. To make them actually work
     * you only need to enable the media type in the view and if necessary
     * add the media type dependent changes to the renderer.
kocienda's avatar
kocienda committed
249
     */
250
251
252
    void setMediaType( const QString &medium );
    QString mediaType() const;

253
    bool scrollTo(const IntRect &);
254
255

    void focusNextPrevNode(bool next);
kocienda's avatar
kocienda committed
256
257
258

    void useSlowRepaints();

259
260
    void setIgnoreWheelEvents(bool e);

kocienda's avatar
kocienda committed
261
262
263
264
265
266
267
268
269
    void init();

    DOM::NodeImpl *nodeUnderMouse() const;

    void restoreScrollBar();

    QStringList formCompletionItems(const QString &name) const;
    void addFormCompletionItem(const QString &name, const QString &value);

darin's avatar
darin committed
270
    bool dispatchMouseEvent(const DOM::AtomicString &eventType, DOM::NodeImpl *targetNode, bool cancelable,
271
272
                            int detail,QMouseEvent *_mouse, bool setUnder,
                            int mouseEventType);
273
    bool dispatchDragEvent(const DOM::AtomicString &eventType, DOM::NodeImpl *dragTarget, const IntPoint &loc, DOM::ClipboardImpl *clipboard);
kocienda's avatar
kocienda committed
274

275
    void applyOverflowToViewport(khtml::RenderObject* o, ScrollBarMode& hMode, ScrollBarMode& vMode);
276

277
    virtual bool isFrameView() const;
darin's avatar
darin committed
278

kocienda's avatar
kocienda committed
279
280
    // ------------------------------------- member variables ------------------------------------
 private:
mjs's avatar
mjs committed
281
282
    unsigned _refCount;

kocienda's avatar
kocienda committed
283
284
285
286
287
288
    int _width;
    int _height;

    int _marginWidth;
    int _marginHeight;

darin's avatar
darin committed
289
290
    RefPtr<Frame> m_frame;
    FrameViewPrivate* d;
291
292

    QString m_medium;   // media type
kocienda's avatar
kocienda committed
293
294
};

darin's avatar
darin committed
295
296
}

kocienda's avatar
kocienda committed
297
298
#endif