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 , m_refCnt(0) 84 , m_fixed(false) 85 { 86 } 87 88 ClipRects(const ClipRects& other) 89 : m_overflowClipRect(other.overflowClipRect()) 90 , m_fixedClipRect(other.fixedClipRect()) 91 , m_posClipRect(other.posClipRect()) 92 , m_refCnt(0) 93 , m_fixed(other.fixed()) 94 { 95 } 96 97 void reset(const IntRect& r) 98 { 99 m_overflowClipRect = r; 100 m_fixedClipRect = r; 101 m_posClipRect = r; 102 m_fixed = false; 103 } 104 105 const IntRect& overflowClipRect() const { return m_overflowClipRect; } 106 void setOverflowClipRect(const IntRect& r) { m_overflowClipRect = r; } 107 108 const IntRect& fixedClipRect() const { return m_fixedClipRect; } 109 void setFixedClipRect(const IntRect&r) { m_fixedClipRect = r; } 110 111 const IntRect& posClipRect() const { return m_posClipRect; } 112 void setPosClipRect(const IntRect& r) { m_posClipRect = r; } 113 114 bool fixed() const { return m_fixed; } 115 void setFixed(bool fixed) { m_fixed = fixed; } 116 117 void ref() { m_refCnt++; } 118 void deref(RenderArena* renderArena) { if (--m_refCnt == 0) destroy(renderArena); } 119 120 void destroy(RenderArena*); 121 122 // Overloaded new operator. 123 void* operator new(size_t, RenderArena*) throw(); 124 125 // Overridden to prevent the normal delete from being called. 126 void operator delete(void*, size_t); 127 128 bool operator==(const ClipRects& other) const 129 { 130 return m_overflowClipRect == other.overflowClipRect() && 131 m_fixedClipRect == other.fixedClipRect() && 132 m_posClipRect == other.posClipRect() && 133 m_fixed == other.fixed(); 134 } 135 136 ClipRects& operator=(const ClipRects& other) 137 { 138 m_overflowClipRect = other.overflowClipRect(); 139 m_fixedClipRect = other.fixedClipRect(); 140 m_posClipRect = other.posClipRect(); 141 m_fixed = other.fixed(); 142 return *this; 143 } 144 145 private: 146 // The normal operator new is disallowed on all render objects. 147 void* operator new(size_t) throw(); 148 149 private: 150 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 164 RenderBoxModelObject* renderer() const { return m_renderer; } 165 RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; } 166 RenderLayer* parent() const { return m_parent; } 167 RenderLayer* previousSibling() const { return m_previous; } 168 RenderLayer* nextSibling() const { return m_next; } 169 RenderLayer* firstChild() const { return m_first; } 170 RenderLayer* lastChild() const { return m_last; } 171 172 void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0); 173 RenderLayer* removeChild(RenderLayer*); 174 175 void removeOnlyThisLayer(); 176 void insertOnlyThisLayer(); 177 178 void repaintIncludingDescendants(); 179 180 #if USE(ACCELERATED_COMPOSITING) 181 // Indicate that the layer contents need to be repainted. Only has an effect 182 // if layer compositing is being used, 183 void setBackingNeedsRepaint(); 184 void setBackingNeedsRepaintInRect(const 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 190 RenderMarquee* marquee() const { return m_marquee; } 191 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 201 bool hasReflection() const { return renderer()->hasReflection(); } 202 bool isReflection() const { return renderer()->isReplica(); } 203 RenderReplica* reflection() const { return m_reflection; } 204 RenderLayer* reflectionLayer() const; 205 206 const RenderLayer* root() const 207 { 208 const RenderLayer* curr = this; 209 while (curr->parent()) 210 curr = curr->parent(); 211 return curr; 212 } 213 214 int x() const { return m_x; } 215 int y() const { return m_y; } 216 void setLocation(int x, int y) 217 { 218 m_x = x; 219 m_y = y; 220 } 221 222 int width() const { return m_width; } 223 int height() const { return m_height; } 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 230 void setWidth(int w) { m_width = w; } 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 242 IntSize scrolledContentOffset() const { return IntSize(scrollXOffset() + m_scrollLeftOverflow, scrollYOffset() + m_scrollTopOverflow); } 243 244 int scrollXOffset() const { return m_scrollX + m_scrollOrigin.x(); } 245 int scrollYOffset() const { return m_scrollY + m_scrollOrigin.y(); } 246 247 void scrollToOffset(int x, int y); 248 void scrollToXOffset(int x) { scrollToOffset(x, m_scrollY + m_scrollOrigin.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 261 virtual Scrollbar* horizontalScrollbar() const { return m_hBar.get(); } 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&); 282 bool inResizeMode() const { return m_inResizeMode; } 283 void setInResizeMode(bool b) { m_inResizeMode = b; } 284 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 314 void relativePositionOffset(int& relX, int& relY) const { relX += m_relX; relY += m_relY; } 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) 328 bool isFixed() const { return renderer()->isPositioned() && renderer()->style()->position() == FixedPosition; } 329 // If fixed elements are composited, they will be containing children 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) 339 bool isStackingContext() const { return !hasAutoZIndex() || renderer()->isRenderView() || hasOverflowScroll(); } 340 #else 341 bool isStackingContext() const { return !hasAutoZIndex() || renderer()->isRenderView() ; } 342 #endif 343 #endif 344 345 void dirtyZOrderLists(); 346 void dirtyStackingContextZOrderLists(); 347 void updateZOrderLists(); 348 Vector<RenderLayer*>* posZOrderList() const { return m_posZOrderList; } 349 Vector<RenderLayer*>* negZOrderList() const { return m_negZOrderList; } 350 351 void dirtyNormalFlowList(); 352 void updateNormalFlowList(); 353 Vector<RenderLayer*>* normalFlowList() const { return m_normalFlowList; } 354 355 bool hasVisibleContent() const { return m_hasVisibleContent; } 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. 371 RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(false); } 372 #endif 373 374 void convertToLayerCoords(const RenderLayer* ancestorLayer, int& x, int& y) const; 375 376 bool hasAutoZIndex() const { return renderer()->style()->hasAutoZIndex(); } 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; 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. 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 422 int staticInlinePosition() const { return m_staticInlinePosition; } 423 int staticBlockPosition() const { return m_staticBlockPosition; } 424 void setStaticInlinePosition(int position) { m_staticInlinePosition = position; } 425 void setStaticBlockPosition(int position) { m_staticBlockPosition = position; } 426 427 bool hasTransform() const { return renderer()->hasTransform(); } 428 // Note that this transform has the transform-origin baked in. 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; 441 bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; } 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) 452 bool isComposited() const { return m_backing != 0; } 453 bool hasCompositedMask() const; 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 461 bool isComposited() const { return false; } 462 bool hasCompositedMask() const { return false; } 463 #endif 464 465 bool paintsWithTransparency(PaintBehavior paintBehavior) const 466 { 467 return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited()); 468 } 469 470 bool paintsWithTransform(PaintBehavior) const; 471 472 bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; } 473 void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; } 474 475 #if ENABLE(ANDROID_OVERFLOW_SCROLL) 476 bool hasOverflowScroll() const { return m_hasOverflowScroll; } 477 bool hasOverflowParent() const; 478 #endif 479 #if PLATFORM(ANDROID) 480 bool intrinsicallyComposited() const { return m_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 490 void setNextSibling(RenderLayer* next) { m_next = next; } 491 void setPreviousSibling(RenderLayer* prev) { m_previous = prev; } 492 void setParent(RenderLayer* parent); 493 void setFirstChild(RenderLayer* first) { m_first = first; } 494 void setLastChild(RenderLayer* last) { m_last = last; } 495 496 int renderBoxX() const { return renderer()->isBox() ? toRenderBox(renderer())->x() : 0; } 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 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. 591 void setHas3DTransformedDescendant(bool b) { m_has3DTransformedDescendant = b; } 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(); 604 bool paintingInsideReflection() const { return m_paintingInsideReflection; } 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(); 620 bool isPaginated() const { return m_isPaginated; } 621 622 #if USE(ACCELERATED_COMPOSITING) 623 bool hasCompositingDescendant() const { return m_hasCompositingDescendant; } 624 void setHasCompositingDescendant(bool b) { m_hasCompositingDescendant = b; } 625 626 bool mustOverlapCompositedLayers() const { return m_mustOverlapCompositedLayers; } 627 void setMustOverlapCompositedLayers(bool b) { m_mustOverlapCompositedLayers = b; } 628 #if ENABLE(COMPOSITED_FIXED_ELEMENTS) 629 bool shouldComposite() { return m_shouldComposite; } 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