2 * Copyright (C) 2003 Apple Computer, Inc.
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com>
11 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
12 * Josh Soref <timeless@mac.com>
13 * Boris Zbarsky <bzbarsky@mit.edu>
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * Alternatively, the contents of this file may be used under the terms
30 * of either the Mozilla Public License Version 1.1, found at
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are
34 * applicable instead of those above. If you wish to allow use of your
35 * version of this file only under the terms of one of those two
36 * licenses (the MPL or the GPL) and not to allow others to use your
37 * version of this file under the LGPL, indicate your decision by
38 * deletingthe provisions above and replace them with the notice and
39 * other provisions required by the MPL or the GPL, as the case may be.
40 * If you do not delete the provisions above, a recipient may use your
41 * version of this file under any of the LGPL, the MPL or the GPL.
44 #ifndef render_layer_h
45 #define render_layer_h
47 #include <QtGui/QColor>
48 #include <QtCore/QRect>
51 #include "render_object.h"
53 //template <class T*> class QVector;
57 class RenderScrollMediator
;
58 class ScrollBarWidget
;
60 class RenderScrollMediator
: public QObject
64 RenderScrollMediator(RenderLayer
* layer
)
68 void slotValueChanged();
74 // This class handles the auto-scrolling of layers with overflow: marquee.
75 class Marquee
: public QObject
80 Marquee(RenderLayer
* l
);
82 void timerEvent(QTimerEvent
*);
84 int speed() const { return m_speed
; }
85 int marqueeSpeed() const;
86 EMarqueeDirection
direction() const;
87 EMarqueeDirection
reverseDirection() const { return static_cast<EMarqueeDirection
>(-direction()); }
88 bool isHorizontal() const;
89 bool isUnfurlMarquee() const;
90 int unfurlPos() const { return m_unfurlPos
; }
92 EWhiteSpace
whiteSpace() { return KDE_CAST_BF_ENUM(EWhiteSpace
, m_whiteSpace
); }
94 int computePosition(EMarqueeDirection dir
, bool stopAtClientEdge
);
96 void setEnd(int end
) { m_end
= end
; }
102 void updateMarqueeStyle();
103 void updateMarqueePosition();
106 RenderLayer
* m_layer
;
117 KDE_BF_ENUM(EWhiteSpace
) m_whiteSpace
: 3;
118 KDE_BF_ENUM(EMarqueeDirection
) m_direction
: 4;
124 static ScrollBarWidget
* gScrollBar
;
126 RenderLayer(RenderObject
* object
);
129 RenderObject
* renderer() const { return m_object
; }
130 RenderLayer
*parent() const { return m_parent
; }
131 RenderLayer
*previousSibling() const { return m_previous
; }
132 RenderLayer
*nextSibling() const { return m_next
; }
134 RenderLayer
*firstChild() const { return m_first
; }
135 RenderLayer
*lastChild() const { return m_last
; }
137 void addChild(RenderLayer
*newChild
, RenderLayer
* beforeChild
= 0);
138 RenderLayer
* removeChild(RenderLayer
*oldChild
);
140 void removeOnlyThisLayer();
141 void insertOnlyThisLayer();
145 Marquee
* marquee() const { return m_marquee
; }
146 void suspendMarquees();
148 bool isOverflowOnly() const { return m_isOverflowOnly
; }
150 bool isTransparent() const;
151 RenderLayer
* transparentAncestor() const;
153 RenderLayer
* root() {
154 RenderLayer
* curr
= this;
155 while (curr
->parent()) curr
= curr
->parent();
159 int xPos() const { return m_x
; }
160 int yPos() const { return m_y
; }
165 short scrollWidth() const { return m_scrollWidth
; }
166 int scrollHeight() const { return m_scrollHeight
; }
168 void resize( int w
, int h
) {
169 m_scrollWidth
= w
; m_scrollHeight
= h
;
172 void setPos( int xPos
, int yPos
) {
177 // Scrolling methods for layers that can scroll their overflow.
178 void scrollOffset(int& x
, int& y
);
179 void subtractScrollOffset(int& x
, int& y
);
180 void checkInlineRelOffset(const RenderObject
* o
, int& x
, int& y
);
181 short scrollXOffset() { return m_scrollX
; }
182 int scrollYOffset() { return m_scrollY
; }
183 void scrollToOffset(int x
, int y
, bool updateScrollbars
= true, bool repaint
= true);
184 void scrollToXOffset(int x
) { scrollToOffset(x
, m_scrollY
); }
185 void scrollToYOffset(int y
) { scrollToOffset(m_scrollX
, y
); }
186 void showScrollbar(Qt::Orientation
, bool);
187 ScrollBarWidget
* horizontalScrollbar() { return m_hBar
; }
188 ScrollBarWidget
* verticalScrollbar() { return m_vBar
; }
189 int verticalScrollbarWidth();
190 int horizontalScrollbarHeight();
191 void positionScrollbars(const QRect
&damageRect
);
192 void paintScrollbars(RenderObject::PaintInfo
& pI
);
193 void checkScrollbarsAfterLayout();
194 void slotValueChanged(int);
195 void repaint(Priority p
=NormalPriority
, bool markForRepaint
= false);
196 void updateScrollPositionFromScrollbars();
198 void updateLayerPosition();
199 void updateLayerPositions( RenderLayer
* rootLayer
, bool doFullRepaint
= false, bool checkForRepaint
= false);
201 // Get the enclosing stacking context for this layer. A stacking context is a layer
202 // that has a non-auto z-index.
203 RenderLayer
* stackingContext() const;
204 bool isStackingContext() const { return !hasAutoZIndex() || renderer()->isCanvas(); }
206 void dirtyZOrderLists();
207 void updateZOrderLists();
208 QVector
<RenderLayer
*>* posZOrderList() const { return m_posZOrderList
; }
209 QVector
<RenderLayer
*>* negZOrderList() const { return m_negZOrderList
; }
211 void dirtyOverflowList();
212 void updateOverflowList();
213 QVector
<RenderLayer
*>* overflowList() const { return m_overflowList
; }
215 bool hasVisibleContent() const { return m_hasVisibleContent
; }
216 void setHasVisibleContent(bool b
);
217 void dirtyVisibleContentStatus();
220 void setHasOverlaidWidgets(bool b
=true) { m_hasOverlaidWidgets
= b
; }
221 bool hasOverlaidWidgets() const { return m_hasOverlaidWidgets
; }
222 QRegion
getMask() const { return m_region
; }
223 QRegion
paintedRegion(RenderLayer
* rootLayer
);
224 void updateWidgetMasks(RenderLayer
* rootLayer
);
226 // Gets the nearest enclosing positioned ancestor layer (also includes
227 // the <html> layer and the root layer).
228 RenderLayer
* enclosingPositionedAncestor() const;
230 void convertToLayerCoords(const RenderLayer
* ancestorLayer
, int& x
, int& y
) const;
232 bool hasAutoZIndex() const { return renderer()->style()->hasAutoZIndex(); }
233 int zIndex() const { return renderer()->style()->zIndex(); }
235 // The two main functions that use the layer system. The paint method
236 // paints the layers that intersect the damage rect from back to
237 // front. The nodeAtPoint method looks for mouse events by walking
238 // layers that intersect the point from front to back.
239 KHTML_EXPORT
void paint(QPainter
*p
, const QRect
& damageRect
, bool selectionOnly
=false);
240 bool nodeAtPoint(RenderObject::NodeInfo
& info
, int x
, int y
);
242 // This method figures out our layerBounds in coordinates relative to
243 // |rootLayer}. It also computes our background and foreground clip rects
244 // for painting/event handling.
245 void calculateRects(const RenderLayer
* rootLayer
, const QRect
& paintDirtyRect
, QRect
& layerBounds
,
246 QRect
& backgroundRect
, QRect
& foregroundRect
);
247 void calculateClipRects(const RenderLayer
* rootLayer
, QRect
& overflowClipRect
,
248 QRect
& posClipRect
, QRect
& fixedClipRect
);
250 bool intersectsDamageRect(const QRect
& layerBounds
, const QRect
& damageRect
) const;
251 bool containsPoint(int x
, int y
, const QRect
& damageRect
) const;
253 void updateHoverActiveState(RenderObject::NodeInfo
& info
);
255 void detach(RenderArena
* renderArena
);
258 KHTML_EXPORT
void dump(QTextStream
&stream
, const QString
&ind
= QString());
261 // Overloaded new operator. Derived classes must override operator new
262 // in order to allocate out of the RenderArena.
263 void* operator new(size_t sz
, RenderArena
* renderArena
) throw();
265 // Overridden to prevent the normal delete from being called.
266 void operator delete(void* ptr
, size_t sz
);
269 // The normal operator new is disallowed on all render objects.
270 void* operator new(size_t sz
) throw();
273 void setNextSibling(RenderLayer
* next
) { m_next
= next
; }
274 void setPreviousSibling(RenderLayer
* prev
) { m_previous
= prev
; }
275 void setParent(RenderLayer
* parent
) { m_parent
= parent
; }
276 void setFirstChild(RenderLayer
* first
) { m_first
= first
; }
277 void setLastChild(RenderLayer
* last
) { m_last
= last
; }
279 void collectLayers(QVector
<RenderLayer
*>*&, QVector
<RenderLayer
*>*&);
281 KHTML_EXPORT
void paintLayer(RenderLayer
* rootLayer
, QPainter
*p
, const QRect
& paintDirtyRect
, bool selectionOnly
=false);
282 RenderLayer
* nodeAtPointForLayer(RenderLayer
* rootLayer
, RenderObject::NodeInfo
& info
,
283 int x
, int y
, const QRect
& hitTestRect
);
284 bool shouldBeOverflowOnly() const;
286 void childVisibilityChanged(bool newVisibility
);
287 void dirtyVisibleDescendantStatus();
288 void updateVisibilityStatus();
291 void setClip(QPainter
* p
, const QRect
& paintDirtyRect
, const QRect
& clipRect
, bool setup
= false);
292 void restoreClip(QPainter
* p
, const QRect
& paintDirtyRect
, const QRect
& clipRect
, bool cleanup
= false);
294 RenderObject
* m_object
;
296 RenderLayer
* m_parent
;
297 RenderLayer
* m_previous
;
300 RenderLayer
* m_first
;
303 // Our (x,y) coordinates are in our parent layer's coordinate space.
307 // Our scroll offsets if the view is scrolled.
311 // The width/height of our scrolled area.
315 // For layers with overflow, we have a pair of scrollbars.
316 ScrollBarWidget
* m_hBar
;
317 ScrollBarWidget
* m_vBar
;
318 QPixmap
* m_buffer
[2];
320 RenderScrollMediator
* m_scrollMediator
;
322 // For layers that establish stacking contexts, m_posZOrderList holds a sorted list of all the
323 // descendant layers within the stacking context that have z-indices of 0 or greater
324 // (auto will count as 0). m_negZOrderList holds descendants within our stacking context with negative
326 QVector
<RenderLayer
*>* m_posZOrderList
;
327 QVector
<RenderLayer
*>* m_negZOrderList
;
329 // This list contains our overflow child layers.
330 QVector
<RenderLayer
*>* m_overflowList
;
332 bool m_zOrderListsDirty
: 1;
333 bool m_overflowListDirty
: 1;
334 bool m_isOverflowOnly
: 1;
335 bool m_markedForRepaint
: 1;
336 bool m_hasOverlaidWidgets
: 1;
337 bool m_visibleContentStatusDirty
: 1;
338 bool m_hasVisibleContent
: 1;
339 bool m_visibleDescendantStatusDirty
: 1;
340 bool m_hasVisibleDescendant
: 1;
344 QRegion m_region
; // used by overlaid (non z-order aware) widgets
346 Marquee
* m_marquee
; // Used by layers with overflow:marquee