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