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