#ifndef RenderLayer_h
#define RenderLayer_h
#include "RenderBox.h"
#include "ScrollBehavior.h"
#include "ScrollbarClient.h"
#include "Timer.h"
#include <wtf/OwnPtr.h>
namespace WebCore {
class CachedResource;
class HitTestRequest;
class HitTestResult;
class HitTestingTransformState;
class RenderFrameSet;
class RenderMarquee;
class RenderReplica;
class RenderScrollbarPart;
class RenderStyle;
class RenderTable;
class RenderText;
class RenderView;
class Scrollbar;
class TransformationMatrix;
#if USE(ACCELERATED_COMPOSITING)
class RenderLayerBacking;
class RenderLayerCompositor;
#endif
class ClipRects {
public:
ClipRects()
: m_refCnt(0)
, m_fixed(false)
{
}
ClipRects(const IntRect& r)
: m_overflowClipRect(r)
, m_fixedClipRect(r)
, m_posClipRect(r)
, m_refCnt(0)
, m_fixed(false)
{
}
ClipRects(const ClipRects& other)
: m_overflowClipRect(other.overflowClipRect())
, m_fixedClipRect(other.fixedClipRect())
, m_posClipRect(other.posClipRect())
, m_refCnt(0)
, m_fixed(other.fixed())
{
}
void reset(const IntRect& r)
{
m_overflowClipRect = r;
m_fixedClipRect = r;
m_posClipRect = r;
m_fixed = false;
}
const IntRect& overflowClipRect() const { return m_overflowClipRect; }
void setOverflowClipRect(const IntRect& r) { m_overflowClipRect = r; }
const IntRect& fixedClipRect() const { return m_fixedClipRect; }
void setFixedClipRect(const IntRect&r) { m_fixedClipRect = r; }
const IntRect& posClipRect() const { return m_posClipRect; }
void setPosClipRect(const IntRect& r) { m_posClipRect = r; }
bool fixed() const { return m_fixed; }
void setFixed(bool fixed) { m_fixed = fixed; }
void ref() { m_refCnt++; }
void deref(RenderArena* renderArena) { if (--m_refCnt == 0) destroy(renderArena); }
void destroy(RenderArena*);
void* operator new(size_t, RenderArena*) throw();
void operator delete(void*, size_t);
bool operator==(const ClipRects& other) const
{
return m_overflowClipRect == other.overflowClipRect() &&
m_fixedClipRect == other.fixedClipRect() &&
m_posClipRect == other.posClipRect() &&
m_fixed == other.fixed();
}
ClipRects& operator=(const ClipRects& other)
{
m_overflowClipRect = other.overflowClipRect();
m_fixedClipRect = other.fixedClipRect();
m_posClipRect = other.posClipRect();
m_fixed = other.fixed();
return *this;
}
static IntRect infiniteRect() { return IntRect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX); }
private:
void* operator new(size_t) throw();
private:
IntRect m_overflowClipRect;
IntRect m_fixedClipRect;
IntRect m_posClipRect;
unsigned m_refCnt : 31;
bool m_fixed : 1;
};
class RenderLayer : public ScrollbarClient {
public:
friend class RenderReplica;
RenderLayer(RenderBoxModelObject*);
~RenderLayer();
RenderBoxModelObject* renderer() const { return m_renderer; }
RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
RenderLayer* parent() const { return m_parent; }
RenderLayer* previousSibling() const { return m_previous; }
RenderLayer* nextSibling() const { return m_next; }
RenderLayer* firstChild() const { return m_first; }
RenderLayer* lastChild() const { return m_last; }
void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
RenderLayer* removeChild(RenderLayer*);
void removeOnlyThisLayer();
void insertOnlyThisLayer();
void repaintIncludingDescendants();
#if USE(ACCELERATED_COMPOSITING)
void setBackingNeedsRepaint();
void setBackingNeedsRepaintInRect(const IntRect& r); void repaintIncludingNonCompositingDescendants(RenderBoxModelObject* repaintContainer);
#endif
void styleChanged(StyleDifference, const RenderStyle*);
RenderMarquee* marquee() const { return m_marquee; }
bool isNormalFlowOnly() const { return m_isNormalFlowOnly; }
bool isSelfPaintingLayer() const;
bool requiresSlowRepaints() const;
bool isTransparent() const;
RenderLayer* transparentPaintingAncestor();
void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, PaintBehavior);
bool hasReflection() const { return renderer()->hasReflection(); }
bool isReflection() const { return renderer()->isReplica(); }
RenderReplica* reflection() const { return m_reflection; }
RenderLayer* reflectionLayer() const;
const RenderLayer* root() const
{
const RenderLayer* curr = this;
while (curr->parent())
curr = curr->parent();
return curr;
}
int x() const { return m_x; }
int y() const { return m_y; }
void setLocation(int x, int y)
{
m_x = x;
m_y = y;
}
int width() const { return m_width; }
int height() const { return m_height; }
IntSize size() const { return IntSize(m_width, m_height); }
void setWidth(int w) { m_width = w; }
void setHeight(int h) { m_height = h; }
int scrollWidth();
int scrollHeight();
void panScrollFromPoint(const IntPoint&);
void scrollByRecursively(int xDelta, int yDelta);
IntSize scrolledContentOffset() const { return IntSize(scrollXOffset() + m_scrollLeftOverflow, scrollYOffset()); }
int scrollXOffset() const { return m_scrollX + m_scrollOriginX; }
int scrollYOffset() const { return m_scrollY; }
void scrollToOffset(int x, int y, bool updateScrollbars = true, bool repaint = true);
void scrollToXOffset(int x) { scrollToOffset(x, m_scrollY); }
void scrollToYOffset(int y) { scrollToOffset(m_scrollX + m_scrollOriginX, y); }
void scrollRectToVisible(const IntRect&, bool scrollToAnchor = false, const ScrollAlignment& alignX = ScrollAlignment::alignCenterIfNeeded, const ScrollAlignment& alignY = ScrollAlignment::alignCenterIfNeeded);
IntRect getRectToExpose(const IntRect& visibleRect, const IntRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
void setHasHorizontalScrollbar(bool);
void setHasVerticalScrollbar(bool);
PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
void destroyScrollbar(ScrollbarOrientation);
Scrollbar* horizontalScrollbar() const { return m_hBar.get(); }
Scrollbar* verticalScrollbar() const { return m_vBar.get(); }
int verticalScrollbarWidth() const;
int horizontalScrollbarHeight() const;
bool hasOverflowControls() const;
void positionOverflowControls(int tx, int ty);
bool isPointInResizeControl(const IntPoint& absolutePoint) const;
bool hitTestOverflowControls(HitTestResult&, const IntPoint& localPoint);
IntSize offsetFromResizeCorner(const IntPoint& absolutePoint) const;
void paintOverflowControls(GraphicsContext*, int tx, int ty, const IntRect& damageRect);
void paintScrollCorner(GraphicsContext*, int tx, int ty, const IntRect& damageRect);
void paintResizer(GraphicsContext*, int tx, int ty, const IntRect& damageRect);
void updateScrollInfoAfterLayout();
bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f);
void autoscroll();
void resize(const PlatformMouseEvent&, const IntSize&);
bool inResizeMode() const { return m_inResizeMode; }
void setInResizeMode(bool b) { m_inResizeMode = b; }
bool isRootLayer() const { return renderer()->isRenderView(); }
#if USE(ACCELERATED_COMPOSITING)
RenderLayerCompositor* compositor() const;
void rendererContentChanged();
#endif
bool hasAcceleratedCompositing() const;
void updateLayerPosition();
enum UpdateLayerPositionsFlag {
DoFullRepaint = 1,
CheckForRepaint = 1 << 1,
IsCompositingUpdateRoot = 1 << 2,
UpdateCompositingLayers = 1 << 3,
};
typedef unsigned UpdateLayerPositionsFlags;
void updateLayerPositions(UpdateLayerPositionsFlags = DoFullRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers, IntPoint* cachedOffset = 0);
void updateTransform();
void relativePositionOffset(int& relX, int& relY) const { relX += m_relX; relY += m_relY; }
IntSize relativePositionOffset() const { return IntSize(m_relX, m_relY); }
void clearClipRectsIncludingDescendants();
void clearClipRects();
void addBlockSelectionGapsBounds(const IntRect&);
void clearBlockSelectionGapsBounds();
void repaintBlockSelectionGaps();
RenderLayer* stackingContext() const;
bool isStackingContext() const { return !hasAutoZIndex() || renderer()->isRenderView(); }
void dirtyZOrderLists();
void dirtyStackingContextZOrderLists();
void updateZOrderLists();
Vector<RenderLayer*>* posZOrderList() const { return m_posZOrderList; }
Vector<RenderLayer*>* negZOrderList() const { return m_negZOrderList; }
void dirtyNormalFlowList();
void updateNormalFlowList();
Vector<RenderLayer*>* normalFlowList() const { return m_normalFlowList; }
bool hasVisibleContent() const { return m_hasVisibleContent; }
bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
void setHasVisibleContent(bool);
void dirtyVisibleContentStatus();
RenderLayer* enclosingPositionedAncestor() const;
RenderLayer* clippingRoot() const;
#if USE(ACCELERATED_COMPOSITING)
RenderLayer* enclosingCompositingLayer(bool includeSelf = true) const;
RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(false); }
#endif
void convertToLayerCoords(const RenderLayer* ancestorLayer, int& x, int& y) const;
bool hasAutoZIndex() const { return renderer()->style()->hasAutoZIndex(); }
int zIndex() const { return renderer()->style()->zIndex(); }
void paint(GraphicsContext*, const IntRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0);
bool hitTest(const HitTestRequest&, HitTestResult&);
void calculateRects(const RenderLayer* rootLayer, const IntRect& paintDirtyRect, IntRect& layerBounds,
IntRect& backgroundRect, IntRect& foregroundRect, IntRect& outlineRect, bool temporaryClipRects = false) const;
void updateClipRects(const RenderLayer* rootLayer);
void calculateClipRects(const RenderLayer* rootLayer, ClipRects&, bool useCached = false) const;
ClipRects* clipRects() const { return m_clipRects; }
IntRect childrenClipRect() const; IntRect selfClipRect() const;
bool intersectsDamageRect(const IntRect& layerBounds, const IntRect& damageRect, const RenderLayer* rootLayer) const;
IntRect boundingBox(const RenderLayer* rootLayer) const;
IntRect localBoundingBox() const;
IntRect absoluteBoundingBox() const;
void updateHoverActiveState(const HitTestRequest&, HitTestResult&);
IntRect repaintRect() const { return m_repaintRect; }
void computeRepaintRects();
void updateRepaintRectsAfterScroll(bool fixed = false);
void setNeedsFullRepaint(bool f = true) { m_needsFullRepaint = f; }
int staticX() const { return m_staticX; }
int staticY() const { return m_staticY; }
void setStaticX(int staticX) { m_staticX = staticX; }
void setStaticY(int staticY) { m_staticY = staticY; }
bool adjustForPurpleCaretWhenScrolling() const { return m_adjustForPurpleCaretWhenScrolling; }
void setAdjustForPurpleCaretWhenScrolling(bool b) { m_adjustForPurpleCaretWhenScrolling = b; }
bool hasTransform() const { return renderer()->hasTransform(); }
TransformationMatrix* transform() const { return m_transform.get(); }
TransformationMatrix currentTransform() const;
TransformationMatrix renderableTransform(PaintBehavior) const;
TransformationMatrix perspectiveTransform() const;
FloatPoint perspectiveOrigin() const;
bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
void* operator new(size_t, RenderArena*) throw();
void operator delete(void*, size_t);
#if USE(ACCELERATED_COMPOSITING)
bool isComposited() const { return m_backing != 0; }
bool hasCompositedMask() const;
RenderLayerBacking* backing() const { return m_backing.get(); }
RenderLayerBacking* ensureBacking();
void clearBacking();
#else
bool isComposited() const { return false; }
bool hasCompositedMask() const { return false; }
#endif
bool paintsWithTransparency(PaintBehavior paintBehavior) const
{
return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited());
}
bool paintsWithTransform(PaintBehavior paintBehavior) const
{
return transform() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited());
}
private:
void* operator new(size_t) throw();
private:
void setNextSibling(RenderLayer* next) { m_next = next; }
void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
void setParent(RenderLayer* parent);
void setFirstChild(RenderLayer* first) { m_first = first; }
void setLastChild(RenderLayer* last) { m_last = last; }
int renderBoxX() const { return renderer()->isBox() ? toRenderBox(renderer())->x() : 0; }
int renderBoxY() const { return renderer()->isBox() ? toRenderBox(renderer())->y() : 0; }
void collectLayers(Vector<RenderLayer*>*&, Vector<RenderLayer*>*&);
void updateLayerListsIfNeeded();
void updateCompositingAndLayerListsIfNeeded();
enum PaintLayerFlag {
PaintLayerHaveTransparency = 1,
PaintLayerAppliedTransform = 1 << 1,
PaintLayerTemporaryClipRects = 1 << 2,
PaintLayerPaintingReflection = 1 << 3
};
typedef unsigned PaintLayerFlags;
void paintLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect,
PaintBehavior, RenderObject* paintingRoot, RenderObject::OverlapTestRequestMap* = 0,
PaintLayerFlags paintFlags = 0);
RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
const IntRect& hitTestRect, const IntPoint& hitTestPoint, bool appliedTransform,
const HitTestingTransformState* transformState = 0, double* zOffset = 0);
PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
const IntRect& hitTestRect, const IntPoint& hitTestPoint,
const HitTestingTransformState* containerTransformState) const;
bool hitTestContents(const HitTestRequest&, HitTestResult&, const IntRect& layerBounds, const IntPoint& hitTestPoint, HitTestFilter) const;
void computeScrollDimensions(bool* needHBar = 0, bool* needVBar = 0);
bool shouldBeNormalFlowOnly() const;
virtual void valueChanged(Scrollbar*);
virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
virtual bool isActive() const;
virtual bool scrollbarCornerPresent() const;
virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const;
virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const;
virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const;
virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const;
IntSize scrollbarOffset(const Scrollbar*) const;
void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
void childVisibilityChanged(bool newVisibility);
void dirtyVisibleDescendantStatus();
void updateVisibilityStatus();
void setHas3DTransformedDescendant(bool b) { m_has3DTransformedDescendant = b; }
bool has3DTransformedDescendant() const { return m_has3DTransformedDescendant; }
void dirty3DTransformedDescendantStatus();
bool update3DTransformedDescendantStatus();
Node* enclosingElement() const;
void createReflection();
void removeReflection();
void updateReflectionStyle();
bool paintingInsideReflection() const { return m_paintingInsideReflection; }
void setPaintingInsideReflection(bool b) { m_paintingInsideReflection = b; }
void parentClipRects(const RenderLayer* rootLayer, ClipRects&, bool temporaryClipRects = false) const;
IntRect backgroundClipRect(const RenderLayer* rootLayer, bool temporaryClipRects) const;
RenderLayer* enclosingTransformedAncestor() const;
IntPoint absoluteToContents(const IntPoint&) const;
void updateScrollCornerStyle();
void updateResizerStyle();
#if USE(ACCELERATED_COMPOSITING)
bool hasCompositingDescendant() const { return m_hasCompositingDescendant; }
void setHasCompositingDescendant(bool b) { m_hasCompositingDescendant = b; }
bool mustOverlapCompositedLayers() const { return m_mustOverlapCompositedLayers; }
void setMustOverlapCompositedLayers(bool b) { m_mustOverlapCompositedLayers = b; }
#endif
#if USE(ACCELERATED_COMPOSITING)
void updateContentsScale(float);
#endif
private:
friend class RenderLayerBacking;
friend class RenderLayerCompositor;
friend class RenderBoxModelObject;
void destroy(RenderArena*);
protected:
RenderBoxModelObject* m_renderer;
RenderLayer* m_parent;
RenderLayer* m_previous;
RenderLayer* m_next;
RenderLayer* m_first;
RenderLayer* m_last;
IntRect m_repaintRect; IntRect m_outlineBox;
int m_relX;
int m_relY;
int m_x;
int m_y;
int m_width;
int m_height;
int m_scrollX;
int m_scrollY;
int m_scrollOriginX; int m_scrollLeftOverflow;
int m_scrollWidth;
int m_scrollHeight;
RefPtr<Scrollbar> m_hBar;
RefPtr<Scrollbar> m_vBar;
bool m_inResizeMode;
Vector<RenderLayer*>* m_posZOrderList;
Vector<RenderLayer*>* m_negZOrderList;
Vector<RenderLayer*>* m_normalFlowList;
ClipRects* m_clipRects; #ifndef NDEBUG
const RenderLayer* m_clipRectsRoot; #endif
bool m_scrollDimensionsDirty : 1;
bool m_zOrderListsDirty : 1;
bool m_normalFlowListDirty: 1;
bool m_isNormalFlowOnly : 1;
bool m_usedTransparency : 1; bool m_paintingInsideReflection : 1; bool m_inOverflowRelayout : 1;
bool m_needsFullRepaint : 1;
bool m_overflowStatusDirty : 1;
bool m_horizontalOverflow : 1;
bool m_verticalOverflow : 1;
bool m_visibleContentStatusDirty : 1;
bool m_hasVisibleContent : 1;
bool m_visibleDescendantStatusDirty : 1;
bool m_hasVisibleDescendant : 1;
bool m_3DTransformedDescendantStatusDirty : 1;
bool m_has3DTransformedDescendant : 1; #if USE(ACCELERATED_COMPOSITING)
bool m_hasCompositingDescendant : 1;
bool m_mustOverlapCompositedLayers : 1;
#endif
bool m_adjustForPurpleCaretWhenScrolling : 1;
RenderMarquee* m_marquee;
int m_staticX;
int m_staticY;
OwnPtr<TransformationMatrix> m_transform;
RenderReplica* m_reflection;
RenderScrollbarPart* m_scrollCorner;
RenderScrollbarPart* m_resizer;
private:
IntRect m_blockSelectionGapsBounds;
#if USE(ACCELERATED_COMPOSITING)
OwnPtr<RenderLayerBacking> m_backing;
#endif
};
}
#ifndef NDEBUG
void showLayerTree(const WebCore::RenderLayer* layer);
#endif
#endif // RenderLayer_h