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