1 /* 2 * Copyright (C) 2003, 2009, 2012 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 "core/platform/ScrollableArea.h" 48 #include "core/rendering/CompositingReasons.h" 49 #include "core/rendering/PaintInfo.h" 50 #include "core/rendering/RenderBox.h" 51 52 #include "wtf/OwnPtr.h" 53 54 #include "core/rendering/RenderLayerFilterInfo.h" 55 56 namespace WebCore { 57 58 class FilterEffectRenderer; 59 class FilterOperations; 60 class HitTestRequest; 61 class HitTestResult; 62 class HitTestingTransformState; 63 class PlatformEvent; 64 class RenderFlowThread; 65 class RenderGeometryMap; 66 class RenderLayerBacking; 67 class RenderLayerCompositor; 68 class RenderReplica; 69 class RenderScrollbarPart; 70 class RenderStyle; 71 class RenderView; 72 class Scrollbar; 73 class TransformationMatrix; 74 75 enum BorderRadiusClippingRule { IncludeSelfForBorderRadius, DoNotIncludeSelfForBorderRadius }; 76 77 enum RepaintStatus { 78 NeedsNormalRepaint = 0, 79 NeedsFullRepaint = 1 << 0, 80 NeedsFullRepaintForPositionedMovementLayout = 1 << 1 81 }; 82 83 class ClipRect { 84 public: 85 ClipRect() 86 : m_hasRadius(false) 87 { } 88 89 ClipRect(const LayoutRect& rect) 90 : m_rect(rect) 91 , m_hasRadius(false) 92 { } 93 94 const LayoutRect& rect() const { return m_rect; } 95 void setRect(const LayoutRect& rect) { m_rect = rect; } 96 97 bool hasRadius() const { return m_hasRadius; } 98 void setHasRadius(bool hasRadius) { m_hasRadius = hasRadius; } 99 100 bool operator==(const ClipRect& other) const { return rect() == other.rect() && hasRadius() == other.hasRadius(); } 101 bool operator!=(const ClipRect& other) const { return rect() != other.rect() || hasRadius() != other.hasRadius(); } 102 bool operator!=(const LayoutRect& otherRect) const { return rect() != otherRect; } 103 104 void intersect(const LayoutRect& other) { m_rect.intersect(other); } 105 void intersect(const ClipRect& other) 106 { 107 m_rect.intersect(other.rect()); 108 if (other.hasRadius()) 109 m_hasRadius = true; 110 } 111 void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); } 112 void move(const LayoutSize& size) { m_rect.move(size); } 113 void moveBy(const LayoutPoint& point) { m_rect.moveBy(point); } 114 115 bool isEmpty() const { return m_rect.isEmpty(); } 116 bool intersects(const LayoutRect& rect) const { return m_rect.intersects(rect); } 117 bool intersects(const HitTestLocation&) const; 118 119 private: 120 LayoutRect m_rect; 121 bool m_hasRadius; 122 }; 123 124 inline ClipRect intersection(const ClipRect& a, const ClipRect& b) 125 { 126 ClipRect c = a; 127 c.intersect(b); 128 return c; 129 } 130 131 class ClipRects { 132 WTF_MAKE_FAST_ALLOCATED; 133 public: 134 static PassRefPtr<ClipRects> create() 135 { 136 return adoptRef(new ClipRects); 137 } 138 139 static PassRefPtr<ClipRects> create(const ClipRects& other) 140 { 141 return adoptRef(new ClipRects(other)); 142 } 143 144 ClipRects() 145 : m_refCnt(1) 146 , m_fixed(false) 147 { 148 } 149 150 void reset(const LayoutRect& r) 151 { 152 m_overflowClipRect = r; 153 m_fixedClipRect = r; 154 m_posClipRect = r; 155 m_fixed = false; 156 } 157 158 const ClipRect& overflowClipRect() const { return m_overflowClipRect; } 159 void setOverflowClipRect(const ClipRect& r) { m_overflowClipRect = r; } 160 161 const ClipRect& fixedClipRect() const { return m_fixedClipRect; } 162 void setFixedClipRect(const ClipRect&r) { m_fixedClipRect = r; } 163 164 const ClipRect& posClipRect() const { return m_posClipRect; } 165 void setPosClipRect(const ClipRect& r) { m_posClipRect = r; } 166 167 bool fixed() const { return m_fixed; } 168 void setFixed(bool fixed) { m_fixed = fixed; } 169 170 void ref() { m_refCnt++; } 171 void deref() 172 { 173 if (!--m_refCnt) 174 delete this; 175 } 176 177 bool operator==(const ClipRects& other) const 178 { 179 return m_overflowClipRect == other.overflowClipRect() && 180 m_fixedClipRect == other.fixedClipRect() && 181 m_posClipRect == other.posClipRect() && 182 m_fixed == other.fixed(); 183 } 184 185 ClipRects& operator=(const ClipRects& other) 186 { 187 m_overflowClipRect = other.overflowClipRect(); 188 m_fixedClipRect = other.fixedClipRect(); 189 m_posClipRect = other.posClipRect(); 190 m_fixed = other.fixed(); 191 return *this; 192 } 193 194 private: 195 ClipRects(const LayoutRect& r) 196 : m_overflowClipRect(r) 197 , m_fixedClipRect(r) 198 , m_posClipRect(r) 199 , m_refCnt(1) 200 , m_fixed(false) 201 { 202 } 203 204 ClipRects(const ClipRects& other) 205 : m_overflowClipRect(other.overflowClipRect()) 206 , m_fixedClipRect(other.fixedClipRect()) 207 , m_posClipRect(other.posClipRect()) 208 , m_refCnt(1) 209 , m_fixed(other.fixed()) 210 { 211 } 212 213 ClipRect m_overflowClipRect; 214 ClipRect m_fixedClipRect; 215 ClipRect m_posClipRect; 216 unsigned m_refCnt : 31; 217 bool m_fixed : 1; 218 }; 219 220 enum ClipRectsType { 221 PaintingClipRects, // Relative to painting ancestor. Used for painting. 222 RootRelativeClipRects, // Relative to the ancestor treated as the root (e.g. transformed layer). Used for hit testing. 223 AbsoluteClipRects, // Relative to the RenderView's layer. Used for compositing overlap testing. 224 NumCachedClipRectsTypes, 225 AllClipRectTypes, 226 TemporaryClipRects 227 }; 228 229 enum ShouldRespectOverflowClip { 230 IgnoreOverflowClip, 231 RespectOverflowClip 232 }; 233 234 struct ClipRectsCache { 235 WTF_MAKE_FAST_ALLOCATED; 236 public: 237 ClipRectsCache() 238 { 239 #ifndef NDEBUG 240 for (int i = 0; i < NumCachedClipRectsTypes; ++i) { 241 m_clipRectsRoot[i] = 0; 242 m_scrollbarRelevancy[i] = IgnoreOverlayScrollbarSize; 243 } 244 #endif 245 } 246 247 PassRefPtr<ClipRects> getClipRects(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow) { return m_clipRects[getIndex(clipRectsType, respectOverflow)]; } 248 void setClipRects(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow, PassRefPtr<ClipRects> clipRects) { m_clipRects[getIndex(clipRectsType, respectOverflow)] = clipRects; } 249 250 #ifndef NDEBUG 251 const RenderLayer* m_clipRectsRoot[NumCachedClipRectsTypes]; 252 OverlayScrollbarSizeRelevancy m_scrollbarRelevancy[NumCachedClipRectsTypes]; 253 #endif 254 255 private: 256 int getIndex(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow) 257 { 258 int index = static_cast<int>(clipRectsType); 259 if (respectOverflow == RespectOverflowClip) 260 index += static_cast<int>(NumCachedClipRectsTypes); 261 return index; 262 } 263 264 RefPtr<ClipRects> m_clipRects[NumCachedClipRectsTypes * 2]; 265 }; 266 267 struct LayerFragment { 268 public: 269 LayerFragment() 270 : shouldPaintContent(false) 271 { } 272 273 void setRects(const LayoutRect& bounds, const ClipRect& background, const ClipRect& foreground, const ClipRect& outline) 274 { 275 layerBounds = bounds; 276 backgroundRect = background; 277 foregroundRect = foreground; 278 outlineRect = outline; 279 } 280 281 void moveBy(const LayoutPoint& offset) 282 { 283 layerBounds.moveBy(offset); 284 backgroundRect.moveBy(offset); 285 foregroundRect.moveBy(offset); 286 outlineRect.moveBy(offset); 287 paginationClip.moveBy(offset); 288 } 289 290 void intersect(const LayoutRect& rect) 291 { 292 backgroundRect.intersect(rect); 293 foregroundRect.intersect(rect); 294 outlineRect.intersect(rect); 295 } 296 297 bool shouldPaintContent; 298 LayoutRect layerBounds; 299 ClipRect backgroundRect; 300 ClipRect foregroundRect; 301 ClipRect outlineRect; 302 303 // Unique to paginated fragments. The physical translation to apply to shift the layer when painting/hit-testing. 304 LayoutPoint paginationOffset; 305 306 // Also unique to paginated fragments. An additional clip that applies to the layer. It is in layer-local 307 // (physical) coordinates. 308 LayoutRect paginationClip; 309 }; 310 311 typedef Vector<LayerFragment, 1> LayerFragments; 312 313 class RenderLayer : public ScrollableArea { 314 public: 315 friend class RenderReplica; 316 317 RenderLayer(RenderLayerModelObject*); 318 ~RenderLayer(); 319 320 #ifndef NDEBUG 321 String debugName() const; 322 #endif 323 324 RenderLayerModelObject* renderer() const { return m_renderer; } 325 RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; } 326 RenderLayer* parent() const { return m_parent; } 327 RenderLayer* previousSibling() const { return m_previous; } 328 RenderLayer* nextSibling() const { return m_next; } 329 RenderLayer* firstChild() const { return m_first; } 330 RenderLayer* lastChild() const { return m_last; } 331 332 void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0); 333 RenderLayer* removeChild(RenderLayer*); 334 335 void removeOnlyThisLayer(); 336 void insertOnlyThisLayer(); 337 338 void repaintIncludingDescendants(); 339 340 // Indicate that the layer contents need to be repainted. Only has an effect 341 // if layer compositing is being used, 342 void setBackingNeedsRepaint(); 343 void setBackingNeedsRepaintInRect(const LayoutRect&); // r is in the coordinate space of the layer's render object 344 void repaintIncludingNonCompositingDescendants(RenderLayerModelObject* repaintContainer); 345 346 void styleChanged(StyleDifference, const RenderStyle* oldStyle); 347 348 bool isNormalFlowOnly() const { return m_isNormalFlowOnly; } 349 bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; } 350 351 bool cannotBlitToWindow() const; 352 353 bool isTransparent() const; 354 RenderLayer* transparentPaintingAncestor(); 355 void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior); 356 357 bool hasReflection() const { return renderer()->hasReflection(); } 358 bool isReflection() const { return renderer()->isReplica(); } 359 RenderReplica* reflection() const { return m_reflection; } 360 RenderLayer* reflectionLayer() const; 361 362 const RenderLayer* root() const 363 { 364 const RenderLayer* curr = this; 365 while (curr->parent()) 366 curr = curr->parent(); 367 return curr; 368 } 369 370 const LayoutPoint& location() const { return m_topLeft; } 371 void setLocation(const LayoutPoint& p) { m_topLeft = p; } 372 373 const IntSize& size() const { return m_layerSize; } 374 void setSize(const IntSize& size) { m_layerSize = size; } 375 376 LayoutRect rect() const { return LayoutRect(location(), size()); } 377 378 enum ResizerHitTestType { 379 ResizerForPointer, 380 ResizerForTouch 381 }; 382 383 // See comments on isPointInResizeControl. 384 virtual IntRect resizerCornerRect(const IntRect& bounds, ResizerHitTestType) const; 385 386 int scrollWidth() const; 387 int scrollHeight() const; 388 389 void panScrollFromPoint(const IntPoint&); 390 391 enum ScrollOffsetClamping { 392 ScrollOffsetUnclamped, 393 ScrollOffsetClamped 394 }; 395 396 // Scrolling methods for layers that can scroll their overflow. 397 void scrollByRecursively(const IntSize&, ScrollOffsetClamping = ScrollOffsetUnclamped); 398 void scrollToOffset(const IntSize&, ScrollOffsetClamping = ScrollOffsetUnclamped); 399 void scrollToXOffset(int x, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(IntSize(x, scrollYOffset()), clamp); } 400 void scrollToYOffset(int y, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(IntSize(scrollXOffset(), y), clamp); } 401 402 int scrollXOffset() const { return m_scrollOffset.width() + scrollOrigin().x(); } 403 int scrollYOffset() const { return m_scrollOffset.height() + scrollOrigin().y(); } 404 IntSize adjustedScrollOffset() const { return IntSize(scrollXOffset(), scrollYOffset()); } 405 406 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY); 407 408 LayoutRect getRectToExpose(const LayoutRect& visibleRect, const LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& alignY); 409 410 bool hasHorizontalScrollbar() const { return horizontalScrollbar(); } 411 bool hasVerticalScrollbar() const { return verticalScrollbar(); } 412 413 // ScrollableArea overrides 414 virtual Scrollbar* horizontalScrollbar() const { return m_hBar.get(); } 415 virtual Scrollbar* verticalScrollbar() const { return m_vBar.get(); } 416 virtual ScrollableArea* enclosingScrollableArea() const; 417 418 int verticalScrollbarWidth(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const; 419 int horizontalScrollbarHeight(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const; 420 421 // isPointInResizeControl() is used for testing if a pointer/touch position is in the resize control 422 // area. 423 bool isPointInResizeControl(const IntPoint& absolutePoint, ResizerHitTestType resizerHitTestType) const; 424 bool hitTestOverflowControls(HitTestResult&, const IntPoint& localPoint); 425 IntSize offsetFromResizeCorner(const IntPoint& absolutePoint) const; 426 427 void paintOverflowControls(GraphicsContext*, const IntPoint&, const IntRect& damageRect, bool paintingOverlayControls = false); 428 void paintScrollCorner(GraphicsContext*, const IntPoint&, const IntRect& damageRect); 429 void paintResizer(GraphicsContext*, const IntPoint&, const IntRect& damageRect); 430 431 void updateScrollInfoAfterLayout(); 432 433 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1); 434 void autoscroll(const IntPoint&); 435 436 bool canResize() const; 437 void resize(const PlatformEvent&, const LayoutSize&); 438 bool inResizeMode() const { return m_inResizeMode; } 439 void setInResizeMode(bool b) { m_inResizeMode = b; } 440 441 bool isRootLayer() const { return m_isRootLayer; } 442 443 RenderLayerCompositor* compositor() const; 444 445 // Notification from the renderer that its content changed (e.g. current frame of image changed). 446 // Allows updates of layer content without repainting. 447 void contentChanged(ContentChangeType); 448 449 bool canRender3DTransforms() const; 450 451 enum UpdateLayerPositionsFlag { 452 CheckForRepaint = 1 << 0, 453 NeedsFullRepaintInBacking = 1 << 1, 454 IsCompositingUpdateRoot = 1 << 2, 455 UpdateCompositingLayers = 1 << 3, 456 UpdatePagination = 1 << 4 457 }; 458 typedef unsigned UpdateLayerPositionsFlags; 459 static const UpdateLayerPositionsFlags defaultFlags = CheckForRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers; 460 461 void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags); 462 463 void updateLayerPositionsAfterOverflowScroll(); 464 void updateLayerPositionsAfterDocumentScroll(); 465 466 void positionNewlyCreatedOverflowControls(); 467 468 bool isPaginated() const { return m_isPaginated; } 469 RenderLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; } 470 471 void updateTransform(); 472 473 void updateBlendMode(); 474 475 const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; } 476 477 void clearClipRectsIncludingDescendants(ClipRectsType typeToClear = AllClipRectTypes); 478 void clearClipRects(ClipRectsType typeToClear = AllClipRectTypes); 479 480 void addBlockSelectionGapsBounds(const LayoutRect&); 481 void clearBlockSelectionGapsBounds(); 482 void repaintBlockSelectionGaps(); 483 484 // A stacking context is a layer that has a non-auto z-index. 485 bool isStackingContext() const { return isStackingContext(renderer()->style()); } 486 487 // A stacking container can have z-order lists. All stacking contexts are 488 // stacking containers, but the converse is not true. Layers that use 489 // composited scrolling are stacking containers, but they may not 490 // necessarily be stacking contexts. 491 bool isStackingContainer() const { return isStackingContext() || needsCompositedScrolling(); } 492 493 RenderLayer* ancestorStackingContainer() const; 494 RenderLayer* ancestorStackingContext() const; 495 496 // Gets the enclosing stacking container for this layer, possibly the layer 497 // itself, if it is a stacking container. 498 RenderLayer* enclosingStackingContainer() { return isStackingContainer() ? this : ancestorStackingContainer(); } 499 500 void dirtyZOrderLists(); 501 void dirtyStackingContainerZOrderLists(); 502 503 Vector<RenderLayer*>* posZOrderList() const 504 { 505 ASSERT(!m_zOrderListsDirty); 506 ASSERT(isStackingContainer() || !m_posZOrderList); 507 return m_posZOrderList.get(); 508 } 509 510 bool hasNegativeZOrderList() const { return negZOrderList() && negZOrderList()->size(); } 511 512 Vector<RenderLayer*>* negZOrderList() const 513 { 514 ASSERT(!m_zOrderListsDirty); 515 ASSERT(isStackingContainer() || !m_negZOrderList); 516 return m_negZOrderList.get(); 517 } 518 519 void dirtyNormalFlowList(); 520 Vector<RenderLayer*>* normalFlowList() const { ASSERT(!m_normalFlowListDirty); return m_normalFlowList.get(); } 521 522 // Update our normal and z-index lists. 523 void updateLayerListsIfNeeded(); 524 525 // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044 526 // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277 527 bool hasVisibleContent() const { return m_hasVisibleContent; } 528 bool hasVisibleDescendant() const { return m_hasVisibleDescendant; } 529 530 void setHasVisibleContent(); 531 void dirtyVisibleContentStatus(); 532 533 bool hasBoxDecorationsOrBackground() const; 534 bool hasVisibleBoxDecorations() const; 535 // Returns true if this layer has visible content (ignoring any child layers). 536 bool isVisuallyNonEmpty() const; 537 // True if this layer container renderers that paint. 538 bool hasNonEmptyChildRenderers() const; 539 540 // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above. 541 // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates. 542 bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; } 543 544 // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty) here. See above. 545 bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; } 546 547 void setHasOutOfFlowPositionedDescendant(bool hasDescendant) { m_hasOutOfFlowPositionedDescendant = hasDescendant; } 548 void setHasOutOfFlowPositionedDescendantDirty(bool dirty) { m_hasOutOfFlowPositionedDescendantDirty = dirty; } 549 550 bool hasUnclippedDescendant() const { return m_hasUnclippedDescendant; } 551 void setHasUnclippedDescendant(bool hasDescendant) { m_hasUnclippedDescendant = hasDescendant; } 552 void updateHasUnclippedDescendant(); 553 554 // Gets the nearest enclosing positioned ancestor layer (also includes 555 // the <html> layer and the root layer). 556 RenderLayer* enclosingPositionedAncestor() const; 557 558 // Returns the nearest enclosing layer that is scrollable. 559 RenderLayer* enclosingScrollableLayer() const; 560 561 // The layer relative to which clipping rects for this layer are computed. 562 RenderLayer* clippingRootForPainting() const; 563 564 // Enclosing compositing layer; if includeSelf is true, may return this. 565 RenderLayer* enclosingCompositingLayer(bool includeSelf = true) const; 566 RenderLayer* enclosingCompositingLayerForRepaint(bool includeSelf = true) const; 567 // Ancestor compositing layer, excluding this. 568 RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(false); } 569 570 RenderLayer* enclosingFilterLayer(bool includeSelf = true) const; 571 RenderLayer* enclosingFilterRepaintLayer() const; 572 void setFilterBackendNeedsRepaintingInRect(const LayoutRect&); 573 bool hasAncestorWithFilterOutsets() const; 574 575 bool canUseConvertToLayerCoords() const 576 { 577 // These RenderObjects have an impact on their layers without the renderers knowing about it. 578 return !renderer()->hasColumns() && !renderer()->hasTransform() && !renderer()->isSVGRoot(); 579 } 580 581 void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& location) const; 582 void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntRect&) const; 583 void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint& location) const; 584 void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&) const; 585 586 int zIndex() const { return renderer()->style()->zIndex(); } 587 588 enum PaintLayerFlag { 589 PaintLayerHaveTransparency = 1, 590 PaintLayerAppliedTransform = 1 << 1, 591 PaintLayerTemporaryClipRects = 1 << 2, 592 PaintLayerPaintingReflection = 1 << 3, 593 PaintLayerPaintingOverlayScrollbars = 1 << 4, 594 PaintLayerPaintingCompositingBackgroundPhase = 1 << 5, 595 PaintLayerPaintingCompositingForegroundPhase = 1 << 6, 596 PaintLayerPaintingCompositingMaskPhase = 1 << 7, 597 PaintLayerPaintingCompositingScrollingPhase = 1 << 8, 598 PaintLayerPaintingOverflowContents = 1 << 9, 599 PaintLayerPaintingRootBackgroundOnly = 1 << 10, 600 PaintLayerPaintingSkipRootBackground = 1 << 11, 601 PaintLayerPaintingCompositingAllPhases = (PaintLayerPaintingCompositingBackgroundPhase | PaintLayerPaintingCompositingForegroundPhase | PaintLayerPaintingCompositingMaskPhase) 602 }; 603 604 typedef unsigned PaintLayerFlags; 605 606 // The two main functions that use the layer system. The paint method 607 // paints the layers that intersect the damage rect from back to 608 // front. The hitTest method looks for mouse events by walking 609 // layers that intersect the point from front to back. 610 void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* paintingRoot = 0, 611 RenderRegion* = 0, PaintLayerFlags = 0); 612 bool hitTest(const HitTestRequest&, HitTestResult&); 613 bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&); 614 void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* paintingRoot = 0); 615 616 struct ClipRectsContext { 617 ClipRectsContext(const RenderLayer* inRootLayer, RenderRegion* inRegion, ClipRectsType inClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, ShouldRespectOverflowClip inRespectOverflowClip = RespectOverflowClip) 618 : rootLayer(inRootLayer) 619 , region(inRegion) 620 , clipRectsType(inClipRectsType) 621 , overlayScrollbarSizeRelevancy(inOverlayScrollbarSizeRelevancy) 622 , respectOverflowClip(inRespectOverflowClip) 623 { } 624 const RenderLayer* rootLayer; 625 RenderRegion* region; 626 ClipRectsType clipRectsType; 627 OverlayScrollbarSizeRelevancy overlayScrollbarSizeRelevancy; 628 ShouldRespectOverflowClip respectOverflowClip; 629 }; 630 631 // This method figures out our layerBounds in coordinates relative to 632 // |rootLayer}. It also computes our background and foreground clip rects 633 // for painting/event handling. 634 // Pass offsetFromRoot if known. 635 void calculateRects(const ClipRectsContext&, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds, 636 ClipRect& backgroundRect, ClipRect& foregroundRect, ClipRect& outlineRect, const LayoutPoint* offsetFromRoot = 0) const; 637 638 // Compute and cache clip rects computed with the given layer as the root 639 void updateClipRects(const ClipRectsContext&); 640 // Compute and return the clip rects. If useCached is true, will used previously computed clip rects on ancestors 641 // (rather than computing them all from scratch up the parent chain). 642 void calculateClipRects(const ClipRectsContext&, ClipRects&) const; 643 644 ClipRects* clipRects(const ClipRectsContext& context) const 645 { 646 ASSERT(context.clipRectsType < NumCachedClipRectsTypes); 647 return m_clipRectsCache ? m_clipRectsCache->getClipRects(context.clipRectsType, context.respectOverflowClip).get() : 0; 648 } 649 650 LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space. 651 LayoutRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space. 652 LayoutRect localClipRect() const; // Returns the background clip rect of the layer in the local coordinate space. 653 654 // Pass offsetFromRoot if known. 655 bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutPoint* offsetFromRoot = 0) const; 656 657 enum CalculateLayerBoundsFlag { 658 IncludeSelfTransform = 1 << 0, 659 UseLocalClipRectIfPossible = 1 << 1, 660 IncludeLayerFilterOutsets = 1 << 2, 661 ExcludeHiddenDescendants = 1 << 3, 662 DontConstrainForMask = 1 << 4, 663 IncludeCompositedDescendants = 1 << 5, 664 UseFragmentBoxes = 1 << 6, 665 DefaultCalculateLayerBoundsFlags = IncludeSelfTransform | UseLocalClipRectIfPossible | IncludeLayerFilterOutsets | UseFragmentBoxes 666 }; 667 typedef unsigned CalculateLayerBoundsFlags; 668 669 // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known. 670 LayoutRect boundingBox(const RenderLayer* rootLayer, CalculateLayerBoundsFlags = 0, const LayoutPoint* offsetFromRoot = 0) const; 671 // Bounding box in the coordinates of this layer. 672 LayoutRect localBoundingBox(CalculateLayerBoundsFlags = 0) const; 673 // Pixel snapped bounding box relative to the root. 674 IntRect absoluteBoundingBox() const; 675 676 // Bounds used for layer overlap testing in RenderLayerCompositor. 677 LayoutRect overlapBounds() const { return overlapBoundsIncludeChildren() ? calculateLayerBounds(this) : localBoundingBox(); } 678 679 // If true, this layer's children are included in its bounds for overlap testing. 680 // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around. 681 bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); } 682 683 // Can pass offsetFromRoot if known. 684 IntRect calculateLayerBounds(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0, CalculateLayerBoundsFlags = DefaultCalculateLayerBoundsFlags) const; 685 686 // WARNING: This method returns the offset for the parent as this is what updateLayerPositions expects. 687 LayoutPoint computeOffsetFromRoot(bool& hasLayerOffset) const; 688 689 // Return a cached repaint rect, computed relative to the layer renderer's containerForRepaint. 690 LayoutRect repaintRect() const { return m_repaintRect; } 691 LayoutRect repaintRectIncludingNonCompositingDescendants() const; 692 693 void setRepaintStatus(RepaintStatus status) { m_repaintStatus = status; } 694 695 LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; } 696 LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; } 697 698 void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; } 699 void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; } 700 701 bool hasTransform() const { return renderer()->hasTransform(); } 702 // Note that this transform has the transform-origin baked in. 703 TransformationMatrix* transform() const { return m_transform.get(); } 704 // currentTransform computes a transform which takes accelerated animations into account. The 705 // resulting transform has transform-origin baked in. If the layer does not have a transform, 706 // returns the identity matrix. 707 TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const; 708 TransformationMatrix renderableTransform(PaintBehavior) const; 709 710 // Get the perspective transform, which is applied to transformed sublayers. 711 // Returns true if the layer has a -webkit-perspective. 712 // Note that this transform has the perspective-origin baked in. 713 TransformationMatrix perspectiveTransform() const; 714 FloatPoint perspectiveOrigin() const; 715 bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; } 716 bool has3DTransform() const { return m_transform && !m_transform->isAffine(); } 717 718 virtual void filterNeedsRepaint(); 719 bool hasFilter() const { return renderer()->hasFilter(); } 720 721 bool hasBlendMode() const; 722 723 void* operator new(size_t); 724 // Only safe to call from RenderLayerModelObject::destroyLayer() 725 void operator delete(void*); 726 727 bool isComposited() const { return m_backing != 0; } 728 bool hasCompositedMask() const; 729 RenderLayerBacking* backing() const { return m_backing.get(); } 730 RenderLayerBacking* ensureBacking(); 731 void clearBacking(bool layerBeingDestroyed = false); 732 virtual GraphicsLayer* layerForScrolling() const; 733 virtual GraphicsLayer* layerForHorizontalScrollbar() const; 734 virtual GraphicsLayer* layerForVerticalScrollbar() const; 735 virtual GraphicsLayer* layerForScrollCorner() const; 736 virtual bool usesCompositedScrolling() const OVERRIDE; 737 bool needsCompositedScrolling() const; 738 bool needsCompositingLayersRebuiltForClip(const RenderStyle* oldStyle, const RenderStyle* newStyle) const; 739 bool needsCompositingLayersRebuiltForOverflow(const RenderStyle* oldStyle, const RenderStyle* newStyle) const; 740 bool needsCompositingLayersRebuiltForFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle, bool didPaintWithFilters) const; 741 742 bool paintsWithTransparency(PaintBehavior paintBehavior) const 743 { 744 return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited()); 745 } 746 747 bool paintsWithTransform(PaintBehavior) const; 748 749 // Returns true if background phase is painted opaque in the given rect. 750 // The query rect is given in local coordinates. 751 bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const; 752 753 bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; } 754 void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; } 755 756 bool isCSSCustomFilterEnabled() const; 757 758 FilterOperations computeFilterOperations(const RenderStyle*); 759 bool paintsWithFilters() const; 760 bool requiresFullLayerImageForFilters() const; 761 FilterEffectRenderer* filterRenderer() const 762 { 763 RenderLayerFilterInfo* filterInfo = this->filterInfo(); 764 return filterInfo ? filterInfo->renderer() : 0; 765 } 766 767 RenderLayerFilterInfo* filterInfo() const { return hasFilterInfo() ? RenderLayerFilterInfo::filterInfoForRenderLayer(this) : 0; } 768 RenderLayerFilterInfo* ensureFilterInfo() { return RenderLayerFilterInfo::createFilterInfoForRenderLayerIfNeeded(this); } 769 void removeFilterInfoIfNeeded() 770 { 771 if (hasFilterInfo()) 772 RenderLayerFilterInfo::removeFilterInfoForRenderLayer(this); 773 } 774 775 bool hasFilterInfo() const { return m_hasFilterInfo; } 776 void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; } 777 778 void updateFilters(const RenderStyle* oldStyle, const RenderStyle* newStyle); 779 780 #if !ASSERT_DISABLED 781 bool layerListMutationAllowed() const { return m_layerListMutationAllowed; } 782 void setLayerListMutationAllowed(bool flag) { m_layerListMutationAllowed = flag; } 783 #endif 784 785 Node* enclosingElement() const; 786 787 bool isInTopLayer() const; 788 bool isInTopLayerSubtree() const; 789 790 enum ViewportConstrainedNotCompositedReason { 791 NoNotCompositedReason, 792 NotCompositedForBoundsOutOfView, 793 NotCompositedForNonViewContainer, 794 NotCompositedForNoVisibleContent, 795 NotCompositedForUnscrollableAncestors, 796 }; 797 798 void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_compositingProperties.viewportConstrainedNotCompositedReason = reason; } 799 ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { return static_cast<ViewportConstrainedNotCompositedReason>(m_compositingProperties.viewportConstrainedNotCompositedReason); } 800 801 bool isOutOfFlowRenderFlowThread() const { return renderer()->isOutOfFlowRenderFlowThread(); } 802 803 enum PaintOrderListType {BeforePromote, AfterPromote}; 804 void computePaintOrderList(PaintOrderListType type, Vector<RefPtr<Node> >&); 805 806 enum ForceNeedsCompositedScrollingMode { 807 DoNotForceCompositedScrolling = 0, 808 CompositedScrollingAlwaysOn = 1, 809 CompositedScrollingAlwaysOff = 2 810 }; 811 812 void setForceNeedsCompositedScrolling(ForceNeedsCompositedScrollingMode); 813 814 void addLayerHitTestRects(LayerHitTestRects&) const; 815 816 private: 817 enum CollectLayersBehavior { 818 ForceLayerToStackingContainer, 819 OverflowScrollCanBeStackingContainers, 820 OnlyStackingContextsCanBeStackingContainers 821 }; 822 823 void setHasHorizontalScrollbar(bool); 824 void setHasVerticalScrollbar(bool); 825 826 PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation); 827 void destroyScrollbar(ScrollbarOrientation); 828 829 bool hasOverflowControls() const; 830 831 void updateZOrderLists(); 832 void rebuildZOrderLists(); 833 // See the comment for collectLayers for information about the layerToForceAsStackingContainer parameter. 834 void rebuildZOrderLists(OwnPtr<Vector<RenderLayer*> >&, OwnPtr<Vector<RenderLayer*> >&, const RenderLayer* layerToForceAsStackingContainer = 0, CollectLayersBehavior = OverflowScrollCanBeStackingContainers); 835 void clearZOrderLists(); 836 837 void updateNormalFlowList(); 838 839 bool isStackingContext(const RenderStyle* style) const { return !style->hasAutoZIndex() || isRootLayer(); } 840 841 bool isDirtyStackingContainer() const { return m_zOrderListsDirty && isStackingContainer(); } 842 843 void setAncestorChainHasSelfPaintingLayerDescendant(); 844 void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus(); 845 846 void setAncestorChainHasOutOfFlowPositionedDescendant(); 847 void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus(); 848 849 bool acceleratedCompositingForOverflowScrollEnabled() const; 850 // FIXME: This is a temporary flag and should be removed once accelerated 851 // overflow scroll is ready (crbug.com/254111). 852 bool compositorDrivenAcceleratedScrollingEnabled() const; 853 void updateCanBeStackingContainer(); 854 void collectBeforePromotionZOrderList(RenderLayer* ancestorStackingContext, OwnPtr<Vector<RenderLayer*> >& posZOrderListBeforePromote, OwnPtr<Vector<RenderLayer*> >& negZOrderListBeforePromote); 855 void collectAfterPromotionZOrderList(RenderLayer* ancestorStackingContext, OwnPtr<Vector<RenderLayer*> >& posZOrderListAfterPromote, OwnPtr<Vector<RenderLayer*> >& negZOrderListAfterPromote); 856 857 void dirtyNormalFlowListCanBePromotedToStackingContainer(); 858 void dirtySiblingStackingContextCanBePromotedToStackingContainer(); 859 860 void computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* = 0); 861 void computeRepaintRectsIncludingDescendants(); 862 void clearRepaintRects(); 863 864 void clipToRect(RenderLayer* rootLayer, GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&, 865 BorderRadiusClippingRule = IncludeSelfForBorderRadius); 866 void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&); 867 868 bool shouldRepaintAfterLayout() const; 869 870 void updateSelfPaintingLayer(); 871 void updateIsNormalFlowOnly(); 872 void updateVisibilityAfterStyleChange(const RenderStyle* oldStyle); 873 void updateStackingContextsAfterStyleChange(const RenderStyle* oldStyle); 874 875 void updateScrollbarsAfterStyleChange(const RenderStyle* oldStyle); 876 void updateScrollbarsAfterLayout(); 877 878 void updateOutOfFlowPositioned(const RenderStyle* oldStyle); 879 880 virtual void updateNeedsCompositedScrolling() OVERRIDE; 881 void setNeedsCompositedScrolling(bool); 882 void didUpdateNeedsCompositedScrolling(); 883 884 // Returns true if the position changed. 885 bool updateLayerPosition(); 886 887 void updateLayerPositions(RenderGeometryMap* = 0, UpdateLayerPositionsFlags = defaultFlags); 888 889 enum UpdateLayerPositionsAfterScrollFlag { 890 NoFlag = 0, 891 IsOverflowScroll = 1 << 0, 892 HasSeenViewportConstrainedAncestor = 1 << 1, 893 HasSeenAncestorWithOverflowClip = 1 << 2, 894 HasChangedAncestor = 1 << 3 895 }; 896 typedef unsigned UpdateLayerPositionsAfterScrollFlags; 897 void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag); 898 899 friend IntSize RenderBox::scrolledContentOffset() const; 900 friend void RenderObject::computeLayerHitTestRects(LayerHitTestRects& layerRects) const; 901 IntSize scrolledContentOffset() const { return m_scrollOffset; } 902 903 IntSize clampScrollOffset(const IntSize&) const; 904 905 void setNextSibling(RenderLayer* next) { m_next = next; } 906 void setPreviousSibling(RenderLayer* prev) { m_previous = prev; } 907 void setParent(RenderLayer* parent); 908 void setFirstChild(RenderLayer* first) { m_first = first; } 909 void setLastChild(RenderLayer* last) { m_last = last; } 910 911 LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); } 912 913 // layerToForceAsStackingContainer allows us to build pre-promotion and 914 // post-promotion layer lists, by allowing us to treat a layer as if it is a 915 // stacking context, without adding a new member to RenderLayer or modifying 916 // the style (which could cause extra allocations). 917 void collectLayers(bool includeHiddenLayers, OwnPtr<Vector<RenderLayer*> >&, OwnPtr<Vector<RenderLayer*> >&, const RenderLayer* layerToForceAsStackingContainer = 0, CollectLayersBehavior = OverflowScrollCanBeStackingContainers); 918 919 struct LayerPaintingInfo { 920 LayerPaintingInfo(RenderLayer* inRootLayer, const LayoutRect& inDirtyRect, PaintBehavior inPaintBehavior, const LayoutSize& inSubPixelAccumulation, RenderObject* inPaintingRoot = 0, RenderRegion*inRegion = 0, OverlapTestRequestMap* inOverlapTestRequests = 0) 921 : rootLayer(inRootLayer) 922 , paintingRoot(inPaintingRoot) 923 , paintDirtyRect(inDirtyRect) 924 , subPixelAccumulation(inSubPixelAccumulation) 925 , region(inRegion) 926 , overlapTestRequests(inOverlapTestRequests) 927 , paintBehavior(inPaintBehavior) 928 , clipToDirtyRect(true) 929 { } 930 RenderLayer* rootLayer; 931 RenderObject* paintingRoot; // only paint descendants of this object 932 LayoutRect paintDirtyRect; // relative to rootLayer; 933 LayoutSize subPixelAccumulation; 934 RenderRegion* region; // May be null. 935 OverlapTestRequestMap* overlapTestRequests; // May be null. 936 PaintBehavior paintBehavior; 937 bool clipToDirtyRect; 938 }; 939 940 void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags); 941 void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags); 942 void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& translationOffset = LayoutPoint()); 943 void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags); 944 void paintList(Vector<RenderLayer*>*, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags); 945 void paintPaginatedChildLayer(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags); 946 void paintChildLayerIntoColumns(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex); 947 948 void collectFragments(LayerFragments&, const RenderLayer* rootLayer, RenderRegion*, const LayoutRect& dirtyRect, 949 ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, 950 ShouldRespectOverflowClip = RespectOverflowClip, const LayoutPoint* offsetFromRoot = 0, const LayoutRect* layerBoundingBox = 0); 951 void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutPoint* offsetFromRoot); 952 void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext, 953 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer); 954 void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext, 955 const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer, 956 bool selectionOnly, bool forceBlackText); 957 void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer); 958 void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer); 959 void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&); 960 void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer); 961 void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags); 962 963 RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result, 964 const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform, 965 const HitTestingTransformState* transformState = 0, double* zOffset = 0); 966 RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&, 967 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0, 968 const LayoutPoint& translationOffset = LayoutPoint()); 969 RenderLayer* hitTestList(Vector<RenderLayer*>*, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result, 970 const LayoutRect& hitTestRect, const HitTestLocation&, 971 const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset, 972 const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants); 973 RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result, 974 const LayoutRect& hitTestRect, const HitTestLocation&, 975 const HitTestingTransformState* transformState, double* zOffset); 976 RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result, 977 const LayoutRect& hitTestRect, const HitTestLocation&, 978 const HitTestingTransformState* transformState, double* zOffset, 979 const Vector<RenderLayer*>& columnLayers, size_t columnIndex); 980 981 PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer, 982 const LayoutRect& hitTestRect, const HitTestLocation&, 983 const HitTestingTransformState* containerTransformState, 984 const LayoutPoint& translationOffset = LayoutPoint()) const; 985 986 bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const; 987 bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const; 988 bool hitTestResizerInFragments(const LayerFragments&, const HitTestLocation&) const; 989 RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&, 990 const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0); 991 992 bool listBackgroundIsKnownToBeOpaqueInRect(const Vector<RenderLayer*>*, const LayoutRect&) const; 993 994 void computeScrollDimensions(); 995 bool hasHorizontalOverflow() const; 996 bool hasVerticalOverflow() const; 997 bool hasScrollableHorizontalOverflow() const; 998 bool hasScrollableVerticalOverflow() const; 999 1000 bool shouldBeNormalFlowOnly() const; 1001 bool shouldBeNormalFlowOnlyIgnoringCompositedScrolling() const; 1002 1003 bool shouldBeSelfPaintingLayer() const; 1004 1005 // ScrollableArea interface 1006 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&); 1007 virtual void invalidateScrollCornerRect(const IntRect&); 1008 virtual bool isActive() const; 1009 virtual bool isScrollCornerVisible() const; 1010 virtual IntRect scrollCornerRect() const; 1011 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const; 1012 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const; 1013 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const; 1014 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const; 1015 virtual int scrollSize(ScrollbarOrientation) const; 1016 virtual void setScrollOffset(const IntPoint&); 1017 virtual IntPoint scrollPosition() const; 1018 virtual IntPoint minimumScrollPosition() const; 1019 virtual IntPoint maximumScrollPosition() const; 1020 virtual IntRect visibleContentRect(VisibleContentRectIncludesScrollbars) const; 1021 virtual int visibleHeight() const; 1022 virtual int visibleWidth() const; 1023 virtual IntSize contentsSize() const; 1024 virtual IntSize overhangAmount() const; 1025 virtual IntPoint lastKnownMousePosition() const; 1026 virtual bool shouldSuspendScrollAnimations() const; 1027 virtual bool scrollbarsCanBeActive() const; 1028 virtual IntRect scrollableAreaBoundingBox() const OVERRIDE; 1029 virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE; 1030 virtual int pageStep(ScrollbarOrientation) const OVERRIDE; 1031 1032 // Rectangle encompassing the scroll corner and resizer rect. 1033 IntRect scrollCornerAndResizerRect() const; 1034 1035 void updateCompositingLayersAfterScroll(); 1036 1037 IntSize scrollbarOffset(const Scrollbar*) const; 1038 1039 void updateResizerAreaSet(); 1040 void updateScrollableAreaSet(bool hasOverflow); 1041 1042 void dirtyAncestorChainVisibleDescendantStatus(); 1043 void setAncestorChainHasVisibleDescendant(); 1044 1045 void updateDescendantDependentFlags(); 1046 1047 // This flag is computed by RenderLayerCompositor, which knows more about 3d hierarchies than we do. 1048 void setHas3DTransformedDescendant(bool b) { m_has3DTransformedDescendant = b; } 1049 bool has3DTransformedDescendant() const { return m_has3DTransformedDescendant; } 1050 1051 void dirty3DTransformedDescendantStatus(); 1052 // Both updates the status, and returns true if descendants of this have 3d. 1053 bool update3DTransformedDescendantStatus(); 1054 1055 void createReflection(); 1056 void removeReflection(); 1057 1058 void updateReflectionStyle(); 1059 bool paintingInsideReflection() const { return m_paintingInsideReflection; } 1060 void setPaintingInsideReflection(bool b) { m_paintingInsideReflection = b; } 1061 1062 void updateOrRemoveFilterClients(); 1063 void updateOrRemoveFilterEffectRenderer(); 1064 1065 void parentClipRects(const ClipRectsContext&, ClipRects&) const; 1066 ClipRect backgroundClipRect(const ClipRectsContext&) const; 1067 1068 LayoutRect paintingExtent(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior); 1069 1070 RenderLayer* enclosingTransformedAncestor() const; 1071 1072 // Convert a point in absolute coords into layer coords, taking transforms into account 1073 LayoutPoint absoluteToContents(const LayoutPoint&) const; 1074 1075 void positionOverflowControls(const IntSize&); 1076 void updateScrollCornerStyle(); 1077 void updateResizerStyle(); 1078 1079 void drawPlatformResizerImage(GraphicsContext*, IntRect resizerCornerRect); 1080 1081 void updatePagination(); 1082 1083 // FIXME: Temporary. Remove when new columns come online. 1084 bool useRegionBasedColumns() const; 1085 1086 bool hasCompositingDescendant() const { return m_compositingProperties.hasCompositingDescendant; } 1087 void setHasCompositingDescendant(bool b) { m_compositingProperties.hasCompositingDescendant = b; } 1088 1089 void setCompositingReasons(CompositingReasons reasons) { m_compositingProperties.compositingReasons = reasons; } 1090 CompositingReasons compositingReasons() const { return m_compositingProperties.compositingReasons; } 1091 1092 // Returns true if z ordering would not change if this layer were a stacking container. 1093 bool canBeStackingContainer() const; 1094 1095 friend class RenderLayerBacking; 1096 friend class RenderLayerCompositor; 1097 friend class RenderLayerModelObject; 1098 1099 IntRect rectForHorizontalScrollbar(const IntRect& borderBoxRect) const; 1100 IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const; 1101 1102 LayoutUnit verticalScrollbarStart(int minX, int maxX) const; 1103 LayoutUnit horizontalScrollbarStart(int minX) const; 1104 1105 bool overflowControlsIntersectRect(const IntRect& localRect) const; 1106 1107 protected: 1108 // The bitfields are up here so they will fall into the padding from ScrollableArea on 64-bit. 1109 1110 // Keeps track of whether the layer is currently resizing, so events can cause resizing to start and stop. 1111 unsigned m_inResizeMode : 1; 1112 1113 unsigned m_scrollDimensionsDirty : 1; 1114 unsigned m_zOrderListsDirty : 1; 1115 unsigned m_normalFlowListDirty: 1; 1116 unsigned m_isNormalFlowOnly : 1; 1117 1118 unsigned m_isSelfPaintingLayer : 1; 1119 1120 // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to 1121 // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells). 1122 unsigned m_hasSelfPaintingLayerDescendant : 1; 1123 unsigned m_hasSelfPaintingLayerDescendantDirty : 1; 1124 1125 unsigned m_hasOutOfFlowPositionedDescendant : 1; 1126 unsigned m_hasOutOfFlowPositionedDescendantDirty : 1; 1127 1128 // This is true if we have an out-of-flow positioned descendant whose 1129 // containing block is our ancestor. If this is the case, the descendant 1130 // may fall outside of our clip preventing things like opting into 1131 // composited scrolling (which causes clipping of all descendants). 1132 unsigned m_hasUnclippedDescendant : 1; 1133 1134 unsigned m_needsCompositedScrolling : 1; 1135 1136 // If this is true, then no non-descendant appears between any of our 1137 // descendants in stacking order. This is one of the requirements of being 1138 // able to safely become a stacking context. 1139 unsigned m_canBePromotedToStackingContainer : 1; 1140 unsigned m_canBePromotedToStackingContainerDirty : 1; 1141 1142 const unsigned m_isRootLayer : 1; 1143 1144 unsigned m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether 1145 // we ended up painting this layer or any descendants (and therefore need to 1146 // blend). 1147 unsigned m_paintingInsideReflection : 1; // A state bit tracking if we are painting inside a replica. 1148 unsigned m_inOverflowRelayout : 1; 1149 unsigned m_repaintStatus : 2; // RepaintStatus 1150 1151 unsigned m_visibleContentStatusDirty : 1; 1152 unsigned m_hasVisibleContent : 1; 1153 unsigned m_visibleDescendantStatusDirty : 1; 1154 unsigned m_hasVisibleDescendant : 1; 1155 1156 unsigned m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set. 1157 1158 unsigned m_3DTransformedDescendantStatusDirty : 1; 1159 // Set on a stacking context layer that has 3D descendants anywhere 1160 // in a preserves3D hierarchy. Hint to do 3D-aware hit testing. 1161 unsigned m_has3DTransformedDescendant : 1; 1162 1163 unsigned m_containsDirtyOverlayScrollbars : 1; 1164 1165 #if !ASSERT_DISABLED 1166 unsigned m_layerListMutationAllowed : 1; 1167 #endif 1168 // This is an optimization added for <table>. 1169 // Currently cells do not need to update their repaint rectangles when scrolling. This also 1170 // saves a lot of time when scrolling on a table. 1171 const unsigned m_canSkipRepaintRectsUpdateOnScroll : 1; 1172 1173 unsigned m_hasFilterInfo : 1; 1174 1175 BlendMode m_blendMode; 1176 1177 RenderLayerModelObject* m_renderer; 1178 1179 RenderLayer* m_parent; 1180 RenderLayer* m_previous; 1181 RenderLayer* m_next; 1182 RenderLayer* m_first; 1183 RenderLayer* m_last; 1184 1185 LayoutRect m_repaintRect; // Cached repaint rects. Used by layout. 1186 LayoutRect m_outlineBox; 1187 1188 // Our current relative position offset. 1189 LayoutSize m_offsetForInFlowPosition; 1190 1191 // Our (x,y) coordinates are in our parent layer's coordinate space. 1192 LayoutPoint m_topLeft; 1193 1194 // The layer's width/height 1195 IntSize m_layerSize; 1196 1197 // This is the (scroll) offset from scrollOrigin(). 1198 IntSize m_scrollOffset; 1199 1200 // The width/height of our scrolled area. 1201 LayoutRect m_overflowRect; 1202 1203 // For layers with overflow, we have a pair of scrollbars. 1204 RefPtr<Scrollbar> m_hBar; 1205 RefPtr<Scrollbar> m_vBar; 1206 1207 // For layers that establish stacking contexts, m_posZOrderList holds a sorted list of all the 1208 // descendant layers within the stacking context that have z-indices of 0 or greater 1209 // (auto will count as 0). m_negZOrderList holds descendants within our stacking context with negative 1210 // z-indices. 1211 OwnPtr<Vector<RenderLayer*> > m_posZOrderList; 1212 OwnPtr<Vector<RenderLayer*> > m_negZOrderList; 1213 1214 // This list contains child layers that cannot create stacking contexts. For now it is just 1215 // overflow layers, but that may change in the future. 1216 OwnPtr<Vector<RenderLayer*> > m_normalFlowList; 1217 1218 OwnPtr<ClipRectsCache> m_clipRectsCache; 1219 1220 IntPoint m_cachedOverlayScrollbarOffset; 1221 1222 // Cached normal flow values for absolute positioned elements with static left/top values. 1223 LayoutUnit m_staticInlinePosition; 1224 LayoutUnit m_staticBlockPosition; 1225 1226 OwnPtr<TransformationMatrix> m_transform; 1227 1228 // May ultimately be extended to many replicas (with their own paint order). 1229 RenderReplica* m_reflection; 1230 1231 // Renderers to hold our custom scroll corner and resizer. 1232 RenderScrollbarPart* m_scrollCorner; 1233 RenderScrollbarPart* m_resizer; 1234 1235 // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated. 1236 RenderLayer* m_enclosingPaginationLayer; 1237 1238 // Properties that are computed while updating compositing layers. These values may be dirty/invalid if 1239 // compositing status is not up-to-date before using them. 1240 struct CompositingProperties { 1241 CompositingProperties() 1242 : hasCompositingDescendant(false) 1243 , viewportConstrainedNotCompositedReason(NoNotCompositedReason) 1244 , compositingReasons(CompositingReasonNone) 1245 { } 1246 1247 // Used only while determining what layers should be composited. Applies to the tree of z-order lists. 1248 bool hasCompositingDescendant : 1; 1249 1250 // The reason, if any exists, that a fixed-position layer is chosen not to be composited. 1251 unsigned viewportConstrainedNotCompositedReason : 2; 1252 1253 // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield. 1254 CompositingReasons compositingReasons; 1255 }; 1256 1257 CompositingProperties m_compositingProperties; 1258 1259 ForceNeedsCompositedScrollingMode m_forceNeedsCompositedScrolling; 1260 1261 private: 1262 IntRect m_blockSelectionGapsBounds; 1263 1264 OwnPtr<RenderLayerBacking> m_backing; 1265 }; 1266 1267 inline void RenderLayer::clearZOrderLists() 1268 { 1269 ASSERT(!isStackingContainer()); 1270 1271 m_posZOrderList.clear(); 1272 m_negZOrderList.clear(); 1273 } 1274 1275 inline void RenderLayer::updateZOrderLists() 1276 { 1277 if (!m_zOrderListsDirty) 1278 return; 1279 1280 if (!isStackingContainer()) { 1281 clearZOrderLists(); 1282 m_zOrderListsDirty = false; 1283 return; 1284 } 1285 1286 rebuildZOrderLists(); 1287 } 1288 1289 #if !ASSERT_DISABLED 1290 class LayerListMutationDetector { 1291 public: 1292 LayerListMutationDetector(RenderLayer* layer) 1293 : m_layer(layer) 1294 , m_previousMutationAllowedState(layer->layerListMutationAllowed()) 1295 { 1296 m_layer->setLayerListMutationAllowed(false); 1297 } 1298 1299 ~LayerListMutationDetector() 1300 { 1301 m_layer->setLayerListMutationAllowed(m_previousMutationAllowedState); 1302 } 1303 1304 private: 1305 RenderLayer* m_layer; 1306 bool m_previousMutationAllowedState; 1307 }; 1308 #endif 1309 1310 1311 } // namespace WebCore 1312 1313 #ifndef NDEBUG 1314 // Outside the WebCore namespace for ease of invocation from gdb. 1315 void showLayerTree(const WebCore::RenderLayer*); 1316 void showLayerTree(const WebCore::RenderObject*); 1317 #endif 1318 1319 #endif // RenderLayer_h 1320