initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderLayer.h
1 /*
2  * Copyright (C) 2003, 2009 Apple Inc. All rights reserved.
3  *
4  * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5  *
6  * Other contributors:
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>
14  *
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.
19  *
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.
24  *
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
28  *
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.
42  */
43
44 #ifndef RenderLayer_h
45 #define RenderLayer_h
46
47 #include "PaintInfo.h"
48 #include "RenderBox.h"
49 #include "ScrollBehavior.h"
50 #include "ScrollableArea.h"
51 #include <wtf/OwnPtr.h>
52
53 namespace WebCore {
54
55 class HitTestRequest;
56 class HitTestResult;
57 class HitTestingTransformState;
58 class RenderMarquee;
59 class RenderReplica;
60 class RenderScrollbarPart;
61 class RenderStyle;
62 class RenderView;
63 class Scrollbar;
64 class TransformationMatrix;
65
66 #if USE(ACCELERATED_COMPOSITING)
67 class RenderLayerBacking;
68 class RenderLayerCompositor;
69 #endif
70
71 class ClipRects {
72 public:
73     ClipRects()
74         : m_refCnt(0)
75         , m_fixed(false)
76     {
77     }
78
79     ClipRects(const LayoutRect& r)
80         : m_overflowClipRect(r)
81         , m_fixedClipRect(r)
82         , m_posClipRect(r)
83         , m_refCnt(0)
84         , m_fixed(false)
85     {
86     }
87
88     ClipRects(const ClipRects& other)
89         : m_overflowClipRect(other.overflowClipRect())
90         , m_fixedClipRect(other.fixedClipRect())
91         , m_posClipRect(other.posClipRect())
92         , m_refCnt(0)
93         , m_fixed(other.fixed())
94     {
95     }
96
97     void reset(const LayoutRect& r)
98     {
99         m_overflowClipRect = r;
100         m_fixedClipRect = r;
101         m_posClipRect = r;
102         m_fixed = false;
103     }
104     
105     const LayoutRect& overflowClipRect() const { return m_overflowClipRect; }
106     void setOverflowClipRect(const LayoutRect& r) { m_overflowClipRect = r; }
107
108     const LayoutRect& fixedClipRect() const { return m_fixedClipRect; }
109     void setFixedClipRect(const LayoutRect&r) { m_fixedClipRect = r; }
110
111     const LayoutRect& posClipRect() const { return m_posClipRect; }
112     void setPosClipRect(const LayoutRect& r) { m_posClipRect = r; }
113
114     bool fixed() const { return m_fixed; }
115     void setFixed(bool fixed) { m_fixed = fixed; }
116
117     void ref() { m_refCnt++; }
118     void deref(RenderArena* renderArena) { if (--m_refCnt == 0) destroy(renderArena); }
119
120     void destroy(RenderArena*);
121
122     // Overloaded new operator.
123     void* operator new(size_t, RenderArena*) throw();
124
125     // Overridden to prevent the normal delete from being called.
126     void operator delete(void*, size_t);
127
128     bool operator==(const ClipRects& other) const
129     {
130         return m_overflowClipRect == other.overflowClipRect() &&
131                m_fixedClipRect == other.fixedClipRect() &&
132                m_posClipRect == other.posClipRect() &&
133                m_fixed == other.fixed();
134     }
135
136     ClipRects& operator=(const ClipRects& other)
137     {
138         m_overflowClipRect = other.overflowClipRect();
139         m_fixedClipRect = other.fixedClipRect();
140         m_posClipRect = other.posClipRect();
141         m_fixed = other.fixed();
142         return *this;
143     }
144
145 private:
146     // The normal operator new is disallowed on all render objects.
147     void* operator new(size_t) throw();
148
149 private:
150     LayoutRect m_overflowClipRect;
151     LayoutRect m_fixedClipRect;
152     LayoutRect m_posClipRect;
153     unsigned m_refCnt : 31;
154     bool m_fixed : 1;
155 };
156
157 class RenderLayer : public ScrollableArea {
158 public:
159     friend class RenderReplica;
160
161     RenderLayer(RenderBoxModelObject*);
162     ~RenderLayer();
163
164     RenderBoxModelObject* renderer() const { return m_renderer; }
165     RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
166     RenderLayer* parent() const { return m_parent; }
167     RenderLayer* previousSibling() const { return m_previous; }
168     RenderLayer* nextSibling() const { return m_next; }
169     RenderLayer* firstChild() const { return m_first; }
170     RenderLayer* lastChild() const { return m_last; }
171
172     void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
173     RenderLayer* removeChild(RenderLayer*);
174
175     void removeOnlyThisLayer();
176     void insertOnlyThisLayer();
177
178     void repaintIncludingDescendants();
179
180 #if USE(ACCELERATED_COMPOSITING)
181     // Indicate that the layer contents need to be repainted. Only has an effect
182     // if layer compositing is being used,
183     void setBackingNeedsRepaint();
184     void setBackingNeedsRepaintInRect(const LayoutRect&); // r is in the coordinate space of the layer's render object
185     void repaintIncludingNonCompositingDescendants(RenderBoxModelObject* repaintContainer);
186 #endif
187
188     void styleChanged(StyleDifference, const RenderStyle* oldStyle);
189
190     RenderMarquee* marquee() const { return m_marquee; }
191
192     bool isNormalFlowOnly() const { return m_isNormalFlowOnly; }
193     bool isSelfPaintingLayer() const;
194
195     bool cannotBlitToWindow() const;
196
197     bool isTransparent() const;
198     RenderLayer* transparentPaintingAncestor();
199     void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, PaintBehavior);
200
201     bool hasReflection() const { return renderer()->hasReflection(); }
202     bool isReflection() const { return renderer()->isReplica(); }
203     RenderReplica* reflection() const { return m_reflection; }
204     RenderLayer* reflectionLayer() const;
205
206     const RenderLayer* root() const
207     {
208         const RenderLayer* curr = this;
209         while (curr->parent())
210             curr = curr->parent();
211         return curr;
212     }
213     
214     const LayoutPoint& location() const { return m_topLeft; }
215     void setLocation(LayoutUnit x, LayoutUnit y) { m_topLeft = LayoutPoint(x, y); }
216
217     const LayoutSize& size() const { return m_layerSize; }
218     void setSize(const LayoutSize& size) { m_layerSize = size; }
219
220     LayoutRect rect() const { return LayoutRect(location(), size()); }
221
222     LayoutUnit scrollWidth();
223     LayoutUnit scrollHeight();
224
225     void panScrollFromPoint(const LayoutPoint&);
226
227     enum ScrollOffsetClamping {
228         ScrollOffsetUnclamped,
229         ScrollOffsetClamped
230     };
231
232     // Scrolling methods for layers that can scroll their overflow.
233     void scrollByRecursively(LayoutUnit xDelta, LayoutUnit yDelta, ScrollOffsetClamping = ScrollOffsetUnclamped);
234
235     LayoutSize scrolledContentOffset() const { return scrollOffset() + m_scrollOverflow; }
236
237     LayoutUnit scrollXOffset() const { return m_scrollOffset.width() + m_scrollOrigin.x(); }
238     LayoutUnit scrollYOffset() const { return m_scrollOffset.height() + m_scrollOrigin.y(); }
239     LayoutSize scrollOffset() const { return LayoutSize(scrollXOffset(), scrollYOffset()); }
240
241     void scrollToOffset(LayoutUnit, LayoutUnit, ScrollOffsetClamping = ScrollOffsetUnclamped);
242     void scrollToXOffset(LayoutUnit x, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(x, scrollYOffset(), clamp); }
243     void scrollToYOffset(LayoutUnit y, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(scrollXOffset(), y, clamp); }
244
245     void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX = ScrollAlignment::alignCenterIfNeeded, const ScrollAlignment& alignY = ScrollAlignment::alignCenterIfNeeded);
246
247     LayoutRect getRectToExpose(const LayoutRect& visibleRect, const LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
248
249     bool scrollsOverflow() const;
250     bool allowsScrolling() const; // Returns true if at least one scrollbar is visible and enabled.
251     bool hasScrollbars() const { return m_hBar || m_vBar; }
252     virtual void didAddHorizontalScrollbar(Scrollbar*);
253     virtual void willRemoveHorizontalScrollbar(Scrollbar*);
254     void setHasHorizontalScrollbar(bool);
255     void setHasVerticalScrollbar(bool);
256
257     PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
258     void destroyScrollbar(ScrollbarOrientation);
259
260     // ScrollableArea overrides
261     virtual Scrollbar* horizontalScrollbar() const { return m_hBar.get(); }
262     virtual Scrollbar* verticalScrollbar() const { return m_vBar.get(); }
263     virtual ScrollableArea* enclosingScrollableArea() const;
264
265     int verticalScrollbarWidth(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
266     int horizontalScrollbarHeight(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
267
268     bool hasOverflowControls() const;
269     bool isPointInResizeControl(const LayoutPoint& absolutePoint) const;
270     bool hitTestOverflowControls(HitTestResult&, const LayoutPoint& localPoint);
271     LayoutSize offsetFromResizeCorner(const LayoutPoint& absolutePoint) const;
272
273     void paintOverflowControls(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect, bool paintingOverlayControls = false);
274     void paintScrollCorner(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect);
275     void paintResizer(GraphicsContext*, const LayoutPoint&, const LayoutRect& damageRect);
276
277     void updateScrollInfoAfterLayout();
278
279     bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
280     void autoscroll();
281
282     void resize(const PlatformMouseEvent&, const LayoutSize&);
283     bool inResizeMode() const { return m_inResizeMode; }
284     void setInResizeMode(bool b) { m_inResizeMode = b; }
285
286     bool isRootLayer() const { return renderer()->isRenderView(); }
287     
288 #if USE(ACCELERATED_COMPOSITING)
289     RenderLayerCompositor* compositor() const;
290     
291     // Notification from the renderer that its content changed (e.g. current frame of image changed).
292     // Allows updates of layer content without repainting.
293     enum ContentChangeType { ImageChanged, MaskImageChanged, CanvasChanged, VideoChanged, FullScreenChanged };
294     void contentChanged(ContentChangeType);
295 #endif
296
297     // Returns true if the accelerated compositing is enabled
298     bool hasAcceleratedCompositing() const;
299
300     bool canRender3DTransforms() const;
301
302     void updateLayerPosition();
303     
304     enum UpdateLayerPositionsFlag {
305         CheckForRepaint = 1,
306         IsCompositingUpdateRoot = 1 << 1,
307         UpdateCompositingLayers = 1 << 2,
308         UpdatePagination = 1 << 3
309     };
310     typedef unsigned UpdateLayerPositionsFlags;
311     static const UpdateLayerPositionsFlags defaultFlags = CheckForRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers;
312     // Providing |cachedOffset| prevents a outlineBoxForRepaint from walking back to the root for each layer in our subtree.
313     // This is an optimistic optimization that is not guaranteed to succeed.
314     void updateLayerPositions(LayoutPoint* offsetFromRoot, UpdateLayerPositionsFlags = defaultFlags);
315
316     void updateTransform();
317
318     void relativePositionOffset(LayoutUnit& relX, LayoutUnit& relY) const { relX += m_relativeOffset.width(); relY += m_relativeOffset.height(); }
319     const LayoutSize& relativePositionOffset() const { return m_relativeOffset; }
320
321     void clearClipRectsIncludingDescendants();
322     void clearClipRects();
323
324     void addBlockSelectionGapsBounds(const LayoutRect&);
325     void clearBlockSelectionGapsBounds();
326     void repaintBlockSelectionGaps();
327
328     // Get the enclosing stacking context for this layer.  A stacking context is a layer
329     // that has a non-auto z-index.
330     RenderLayer* stackingContext() const;
331     bool isStackingContext() const { return !hasAutoZIndex() || renderer()->isRenderView(); }
332
333     void dirtyZOrderLists();
334     void dirtyStackingContextZOrderLists();
335     void updateZOrderLists();
336     Vector<RenderLayer*>* posZOrderList() const { return m_posZOrderList; }
337     Vector<RenderLayer*>* negZOrderList() const { return m_negZOrderList; }
338
339     void dirtyNormalFlowList();
340     void updateNormalFlowList();
341     Vector<RenderLayer*>* normalFlowList() const { return m_normalFlowList; }
342
343     bool hasVisibleContent() const { return m_hasVisibleContent; }
344     bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
345     void setHasVisibleContent(bool);
346     void dirtyVisibleContentStatus();
347
348     // Gets the nearest enclosing positioned ancestor layer (also includes
349     // the <html> layer and the root layer).
350     RenderLayer* enclosingPositionedAncestor() const;
351
352     // Returns the nearest enclosing layer that is scrollable.
353     RenderLayer* enclosingScrollableLayer() const;
354
355     // The layer relative to which clipping rects for this layer are computed.
356     RenderLayer* clippingRoot() const;
357
358 #if USE(ACCELERATED_COMPOSITING)
359     // Enclosing compositing layer; if includeSelf is true, may return this.
360     RenderLayer* enclosingCompositingLayer(bool includeSelf = true) const;
361     // Ancestor compositing layer, excluding this.
362     RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(false); }
363 #endif
364
365     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const;
366     void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const;
367
368     bool hasAutoZIndex() const { return renderer()->style()->hasAutoZIndex(); }
369     int zIndex() const { return renderer()->style()->zIndex(); }
370
371     // The two main functions that use the layer system.  The paint method
372     // paints the layers that intersect the damage rect from back to
373     // front.  The hitTest method looks for mouse events by walking
374     // layers that intersect the point from front to back.
375     void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0);
376     bool hitTest(const HitTestRequest&, HitTestResult&);
377     void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* paintingRoot);
378
379     // This method figures out our layerBounds in coordinates relative to
380     // |rootLayer}.  It also computes our background and foreground clip rects
381     // for painting/event handling.
382     void calculateRects(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds,
383                         LayoutRect& backgroundRect, LayoutRect& foregroundRect, LayoutRect& outlineRect, bool temporaryClipRects = false,
384                         OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
385
386     // Compute and cache clip rects computed with the given layer as the root
387     void updateClipRects(const RenderLayer* rootLayer, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
388     // Compute and return the clip rects. If useCached is true, will used previously computed clip rects on ancestors
389     // (rather than computing them all from scratch up the parent chain).
390     void calculateClipRects(const RenderLayer* rootLayer, ClipRects&, bool useCached = false, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
391     ClipRects* clipRects() const { return m_clipRects; }
392
393     LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space.
394     LayoutRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space.
395
396     bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer) const;
397
398     // Bounding box relative to some ancestor layer.
399     LayoutRect boundingBox(const RenderLayer* rootLayer) const;
400     // Bounding box in the coordinates of this layer.
401     LayoutRect localBoundingBox() const;
402     // Bounding box relative to the root.
403     LayoutRect absoluteBoundingBox() const;
404
405     void updateHoverActiveState(const HitTestRequest&, HitTestResult&);
406
407     // WARNING: This method returns the offset for the parent as this is what updateLayerPositions expects.
408     LayoutPoint computeOffsetFromRoot(bool& hasLayerOffset) const;
409
410     // Return a cached repaint rect, computed relative to the layer renderer's containerForRepaint.
411     LayoutRect repaintRect() const { return m_repaintRect; }
412     LayoutRect repaintRectIncludingDescendants() const;
413     void updateLayerPositionsAfterScroll(bool fixed = false);
414     void setNeedsFullRepaint(bool f = true) { m_needsFullRepaint = f; }
415     
416     int staticInlinePosition() const { return m_staticInlinePosition; }
417     int staticBlockPosition() const { return m_staticBlockPosition; }
418     void setStaticInlinePosition(int position) { m_staticInlinePosition = position; }
419     void setStaticBlockPosition(int position) { m_staticBlockPosition = position; }
420
421     bool hasTransform() const { return renderer()->hasTransform(); }
422     // Note that this transform has the transform-origin baked in.
423     TransformationMatrix* transform() const { return m_transform.get(); }
424     // currentTransform computes a transform which takes accelerated animations into account. The
425     // resulting transform has transform-origin baked in. If the layer does not have a transform,
426     // returns the identity matrix.
427     TransformationMatrix currentTransform() const;
428     TransformationMatrix renderableTransform(PaintBehavior) const;
429     
430     // Get the perspective transform, which is applied to transformed sublayers.
431     // Returns true if the layer has a -webkit-perspective.
432     // Note that this transform has the perspective-origin baked in.
433     TransformationMatrix perspectiveTransform() const;
434     FloatPoint perspectiveOrigin() const;
435     bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
436     bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
437
438      // Overloaded new operator.  Derived classes must override operator new
439     // in order to allocate out of the RenderArena.
440     void* operator new(size_t, RenderArena*) throw();
441
442     // Overridden to prevent the normal delete from being called.
443     void operator delete(void*, size_t);
444
445 #if USE(ACCELERATED_COMPOSITING)
446     bool isComposited() const { return m_backing != 0; }
447     bool hasCompositedMask() const;
448     RenderLayerBacking* backing() const { return m_backing.get(); }
449     RenderLayerBacking* ensureBacking();
450     void clearBacking();
451     virtual GraphicsLayer* layerForHorizontalScrollbar() const;
452     virtual GraphicsLayer* layerForVerticalScrollbar() const;
453     virtual GraphicsLayer* layerForScrollCorner() const;
454 #else
455     bool isComposited() const { return false; }
456     bool hasCompositedMask() const { return false; }
457 #endif
458
459     bool paintsWithTransparency(PaintBehavior paintBehavior) const
460     {
461         return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited());
462     }
463
464     bool paintsWithTransform(PaintBehavior) const;
465
466     bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
467     void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
468
469 private:
470     void computeRepaintRects(IntPoint* offsetFromRoot = 0);
471     void clearRepaintRects();
472
473     // The normal operator new is disallowed on all render objects.
474     void* operator new(size_t) throw();
475
476     void setNextSibling(RenderLayer* next) { m_next = next; }
477     void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
478     void setParent(RenderLayer* parent);
479     void setFirstChild(RenderLayer* first) { m_first = first; }
480     void setLastChild(RenderLayer* last) { m_last = last; }
481
482     LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); }
483     LayoutUnit renderBoxX() const { return renderBoxLocation().x(); }
484     LayoutUnit renderBoxY() const { return renderBoxLocation().y(); }
485
486     void collectLayers(Vector<RenderLayer*>*&, Vector<RenderLayer*>*&);
487
488     void updateLayerListsIfNeeded();
489     void updateCompositingAndLayerListsIfNeeded();
490     
491     enum PaintLayerFlag {
492         PaintLayerHaveTransparency = 1,
493         PaintLayerAppliedTransform = 1 << 1,
494         PaintLayerTemporaryClipRects = 1 << 2,
495         PaintLayerPaintingReflection = 1 << 3,
496         PaintLayerPaintingOverlayScrollbars = 1 << 4
497     };
498     
499     typedef unsigned PaintLayerFlags;
500
501     void paintLayer(RenderLayer* rootLayer, GraphicsContext*, const LayoutRect& paintDirtyRect,
502                     PaintBehavior, RenderObject* paintingRoot, OverlapTestRequestMap* = 0,
503                     PaintLayerFlags = 0);
504     void paintList(Vector<RenderLayer*>*, RenderLayer* rootLayer, GraphicsContext* p,
505                    const LayoutRect& paintDirtyRect, PaintBehavior,
506                    RenderObject* paintingRoot, OverlapTestRequestMap*,
507                    PaintLayerFlags);
508     void paintPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, GraphicsContext*,
509                                   const LayoutRect& paintDirtyRect, PaintBehavior,
510                                   RenderObject* paintingRoot, OverlapTestRequestMap*,
511                                   PaintLayerFlags);
512     void paintChildLayerIntoColumns(RenderLayer* childLayer, RenderLayer* rootLayer, GraphicsContext*,
513                                     const LayoutRect& paintDirtyRect, PaintBehavior,
514                                     RenderObject* paintingRoot, OverlapTestRequestMap*,
515                                     PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
516
517     RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
518                               const LayoutRect& hitTestRect, const LayoutPoint& hitTestPoint, bool appliedTransform,
519                               const HitTestingTransformState* transformState = 0, double* zOffset = 0);
520     RenderLayer* hitTestList(Vector<RenderLayer*>*, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
521                              const LayoutRect& hitTestRect, const LayoutPoint& hitTestPoint,
522                              const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset,
523                              const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
524     RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
525                                             const LayoutRect& hitTestRect, const LayoutPoint& hitTestPoint,
526                                             const HitTestingTransformState* transformState, double* zOffset);
527     RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
528                                           const LayoutRect& hitTestRect, const LayoutPoint& hitTestPoint,
529                                           const HitTestingTransformState* transformState, double* zOffset,
530                                           const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
531                                     
532     PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
533                             const LayoutRect& hitTestRect, const LayoutPoint& hitTestPoint,
534                             const HitTestingTransformState* containerTransformState) const;
535     
536     bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const LayoutPoint& hitTestPoint, HitTestFilter) const;
537     
538     void computeScrollDimensions(bool* needHBar = 0, bool* needVBar = 0);
539
540     bool shouldBeNormalFlowOnly() const; 
541
542     LayoutUnit scrollPosition(Scrollbar*) const;
543     
544     // ScrollableArea interface
545     virtual void invalidateScrollbarRect(Scrollbar*, const LayoutRect&);
546     virtual void invalidateScrollCornerRect(const LayoutRect&);
547     virtual bool isActive() const;
548     virtual bool isScrollCornerVisible() const;
549     virtual LayoutRect scrollCornerRect() const;
550     virtual LayoutRect convertFromScrollbarToContainingView(const Scrollbar*, const LayoutRect&) const;
551     virtual LayoutRect convertFromContainingViewToScrollbar(const Scrollbar*, const LayoutRect&) const;
552     virtual LayoutPoint convertFromScrollbarToContainingView(const Scrollbar*, const LayoutPoint&) const;
553     virtual LayoutPoint convertFromContainingViewToScrollbar(const Scrollbar*, const LayoutPoint&) const;
554     virtual LayoutUnit scrollSize(ScrollbarOrientation) const;
555     virtual void setScrollOffset(const LayoutPoint&);
556     virtual LayoutPoint scrollPosition() const;
557     virtual LayoutPoint minimumScrollPosition() const;
558     virtual LayoutPoint maximumScrollPosition() const;
559     virtual LayoutRect visibleContentRect(bool includeScrollbars) const;
560     virtual LayoutUnit visibleHeight() const;
561     virtual LayoutUnit visibleWidth() const;
562     virtual LayoutSize contentsSize() const;
563     virtual LayoutSize overhangAmount() const;
564     virtual LayoutPoint currentMousePosition() const;
565     virtual void didCompleteRubberBand(const LayoutSize&) const;
566     virtual bool shouldSuspendScrollAnimations() const;
567     virtual bool isOnActivePage() const;
568
569     // Rectangle encompassing the scroll corner and resizer rect.
570     LayoutRect scrollCornerAndResizerRect() const;
571
572     virtual void disconnectFromPage() { m_scrollableAreaPage = 0; }
573
574     // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
575     void scrollTo(LayoutUnit, LayoutUnit);
576
577     LayoutSize scrollbarOffset(const Scrollbar*) const;
578     
579     void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
580
581     void childVisibilityChanged(bool newVisibility);
582     void dirtyVisibleDescendantStatus();
583     void updateVisibilityStatus();
584
585     // This flag is computed by RenderLayerCompositor, which knows more about 3d hierarchies than we do.
586     void setHas3DTransformedDescendant(bool b) { m_has3DTransformedDescendant = b; }
587     bool has3DTransformedDescendant() const { return m_has3DTransformedDescendant; }
588     
589     void dirty3DTransformedDescendantStatus();
590     // Both updates the status, and returns true if descendants of this have 3d.
591     bool update3DTransformedDescendantStatus();
592
593     Node* enclosingElement() const;
594
595     void createReflection();
596     void removeReflection();
597
598     void updateReflectionStyle();
599     bool paintingInsideReflection() const { return m_paintingInsideReflection; }
600     void setPaintingInsideReflection(bool b) { m_paintingInsideReflection = b; }
601     
602     void parentClipRects(const RenderLayer* rootLayer, ClipRects&, bool temporaryClipRects = false, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
603     LayoutRect backgroundClipRect(const RenderLayer* rootLayer, bool temporaryClipRects, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
604
605     RenderLayer* enclosingTransformedAncestor() const;
606
607     // Convert a point in absolute coords into layer coords, taking transforms into account
608     LayoutPoint absoluteToContents(const LayoutPoint&) const;
609
610     void positionOverflowControls(const LayoutSize&);
611     void updateScrollCornerStyle();
612     void updateResizerStyle();
613
614     void drawPlatformResizerImage(GraphicsContext*, LayoutRect resizerCornerRect);
615
616     void updatePagination();
617     bool isPaginated() const { return m_isPaginated; }
618
619 #if USE(ACCELERATED_COMPOSITING)    
620     bool hasCompositingDescendant() const { return m_hasCompositingDescendant; }
621     void setHasCompositingDescendant(bool b)  { m_hasCompositingDescendant = b; }
622     
623     bool mustOverlapCompositedLayers() const { return m_mustOverlapCompositedLayers; }
624     void setMustOverlapCompositedLayers(bool b) { m_mustOverlapCompositedLayers = b; }
625 #endif
626
627     friend class RenderLayerBacking;
628     friend class RenderLayerCompositor;
629     friend class RenderBoxModelObject;
630
631     // Only safe to call from RenderBoxModelObject::destroyLayer(RenderArena*)
632     void destroy(RenderArena*);
633
634     LayoutUnit overflowTop() const;
635     LayoutUnit overflowBottom() const;
636     LayoutUnit overflowLeft() const;
637     LayoutUnit overflowRight() const;
638
639     bool canUseConvertToLayerCoords() const
640     {
641         // These RenderObject have an impact on their layers' without them knowing about it.
642         return !renderer()->hasColumns() && !renderer()->hasTransform() && !isComposited()
643 #if ENABLE(SVG)
644             && !renderer()->isSVGRoot()
645 #endif
646             ;
647     }
648
649 protected:
650     RenderBoxModelObject* m_renderer;
651
652     RenderLayer* m_parent;
653     RenderLayer* m_previous;
654     RenderLayer* m_next;
655     RenderLayer* m_first;
656     RenderLayer* m_last;
657
658     LayoutRect m_repaintRect; // Cached repaint rects. Used by layout.
659     LayoutRect m_outlineBox;
660
661     // Our current relative position offset.
662     LayoutSize m_relativeOffset;
663
664     // Our (x,y) coordinates are in our parent layer's coordinate space.
665     LayoutPoint m_topLeft;
666
667     // The layer's width/height
668     LayoutSize m_layerSize;
669
670     // Our scroll offsets if the view is scrolled.
671     LayoutSize m_scrollOffset;
672
673     LayoutSize m_scrollOverflow;
674     
675     // The width/height of our scrolled area.
676     LayoutSize m_scrollSize;
677
678     // For layers with overflow, we have a pair of scrollbars.
679     RefPtr<Scrollbar> m_hBar;
680     RefPtr<Scrollbar> m_vBar;
681
682     // For layers that establish stacking contexts, m_posZOrderList holds a sorted list of all the
683     // descendant layers within the stacking context that have z-indices of 0 or greater
684     // (auto will count as 0).  m_negZOrderList holds descendants within our stacking context with negative
685     // z-indices.
686     Vector<RenderLayer*>* m_posZOrderList;
687     Vector<RenderLayer*>* m_negZOrderList;
688
689     // This list contains child layers that cannot create stacking contexts.  For now it is just
690     // overflow layers, but that may change in the future.
691     Vector<RenderLayer*>* m_normalFlowList;
692
693     ClipRects* m_clipRects;      // Cached clip rects used when painting and hit testing.
694 #ifndef NDEBUG
695     const RenderLayer* m_clipRectsRoot;   // Root layer used to compute clip rects.
696 #endif
697
698     // Keeps track of whether the layer is currently resizing, so events can cause resizing to start and stop.
699     bool m_inResizeMode : 1;
700
701     bool m_scrollDimensionsDirty : 1;
702     bool m_zOrderListsDirty : 1;
703     bool m_normalFlowListDirty: 1;
704     bool m_isNormalFlowOnly : 1;
705
706     bool m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
707                                  // we ended up painting this layer or any descendants (and therefore need to
708                                  // blend).
709     bool m_paintingInsideReflection : 1;  // A state bit tracking if we are painting inside a replica.
710     bool m_inOverflowRelayout : 1;
711     bool m_needsFullRepaint : 1;
712
713     bool m_overflowStatusDirty : 1;
714     bool m_horizontalOverflow : 1;
715     bool m_verticalOverflow : 1;
716     bool m_visibleContentStatusDirty : 1;
717     bool m_hasVisibleContent : 1;
718     bool m_visibleDescendantStatusDirty : 1;
719     bool m_hasVisibleDescendant : 1;
720
721     bool m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set.
722
723     bool m_3DTransformedDescendantStatusDirty : 1;
724     bool m_has3DTransformedDescendant : 1;  // Set on a stacking context layer that has 3D descendants anywhere
725                                             // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
726 #if USE(ACCELERATED_COMPOSITING)
727     bool m_hasCompositingDescendant : 1; // In the z-order tree.
728     bool m_mustOverlapCompositedLayers : 1;
729 #endif
730
731     bool m_containsDirtyOverlayScrollbars : 1;
732
733     LayoutPoint m_cachedOverlayScrollbarOffset;
734
735     RenderMarquee* m_marquee; // Used by layers with overflow:marquee
736     
737     // Cached normal flow values for absolute positioned elements with static left/top values.
738     int m_staticInlinePosition;
739     int m_staticBlockPosition;
740     
741     OwnPtr<TransformationMatrix> m_transform;
742     
743     // May ultimately be extended to many replicas (with their own paint order).
744     RenderReplica* m_reflection;
745     
746     // Renderers to hold our custom scroll corner and resizer.
747     RenderScrollbarPart* m_scrollCorner;
748     RenderScrollbarPart* m_resizer;
749
750 private:
751     LayoutRect m_blockSelectionGapsBounds;
752
753 #if USE(ACCELERATED_COMPOSITING)
754     OwnPtr<RenderLayerBacking> m_backing;
755 #endif
756
757     Page* m_scrollableAreaPage; // Page on which this is registered as a scrollable area.
758 };
759
760 } // namespace WebCore
761
762 #ifndef NDEBUG
763 // Outside the WebCore namespace for ease of invocation from gdb.
764 void showLayerTree(const WebCore::RenderLayer*);
765 void showLayerTree(const WebCore::RenderObject*);
766 #endif
767
768 #endif // RenderLayer_h