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