1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org) 3 * (C) 2000 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Dirk Mueller (mueller (at) kde.org) 5 * (C) 2004 Allan Sandfeld Jensen (kde (at) carewolf.com) 6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved. 7 * Copyright (C) 2009 Google Inc. All rights reserved. 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Library General Public 11 * License as published by the Free Software Foundation; either 12 * version 2 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Library General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public License 20 * along with this library; see the file COPYING.LIB. If not, write to 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 * Boston, MA 02110-1301, USA. 23 * 24 */ 25 26 #ifndef RenderObject_h 27 #define RenderObject_h 28 29 #include "core/dom/Document.h" 30 #include "core/dom/DocumentLifecycle.h" 31 #include "core/dom/Element.h" 32 #include "core/editing/TextAffinity.h" 33 #include "core/fetch/ImageResourceClient.h" 34 #include "core/html/HTMLElement.h" 35 #include "core/inspector/InspectorTraceEvents.h" 36 #include "core/rendering/HitTestRequest.h" 37 #include "core/rendering/PaintInvalidationState.h" 38 #include "core/rendering/PaintPhase.h" 39 #include "core/rendering/RenderObjectChildList.h" 40 #include "core/rendering/ScrollAlignment.h" 41 #include "core/rendering/SubtreeLayoutScope.h" 42 #include "core/rendering/compositing/CompositingState.h" 43 #include "core/rendering/compositing/CompositingTriggers.h" 44 #include "core/rendering/style/RenderStyle.h" 45 #include "core/rendering/style/StyleInheritedData.h" 46 #include "platform/geometry/FloatQuad.h" 47 #include "platform/geometry/LayoutRect.h" 48 #include "platform/graphics/CompositingReasons.h" 49 #include "platform/transforms/TransformationMatrix.h" 50 51 namespace blink { 52 53 class AffineTransform; 54 class Cursor; 55 class Document; 56 class HitTestLocation; 57 class HitTestResult; 58 class InlineBox; 59 class InlineFlowBox; 60 class Position; 61 class PositionWithAffinity; 62 class PseudoStyleRequest; 63 class RenderBoxModelObject; 64 class RenderBlock; 65 class RenderFlowThread; 66 class RenderGeometryMap; 67 class RenderLayer; 68 class RenderLayerModelObject; 69 class RenderView; 70 class TransformState; 71 72 struct PaintInfo; 73 74 enum CursorDirective { 75 SetCursorBasedOnStyle, 76 SetCursor, 77 DoNotSetCursor 78 }; 79 80 enum HitTestFilter { 81 HitTestAll, 82 HitTestSelf, 83 HitTestDescendants 84 }; 85 86 enum HitTestAction { 87 HitTestBlockBackground, 88 HitTestChildBlockBackground, 89 HitTestChildBlockBackgrounds, 90 HitTestFloat, 91 HitTestForeground 92 }; 93 94 enum MarkingBehavior { 95 MarkOnlyThis, 96 MarkContainingBlockChain, 97 }; 98 99 enum MapCoordinatesMode { 100 IsFixed = 1 << 0, 101 UseTransforms = 1 << 1, 102 ApplyContainerFlip = 1 << 2, 103 TraverseDocumentBoundaries = 1 << 3, 104 }; 105 typedef unsigned MapCoordinatesFlags; 106 107 enum InvalidationReason { 108 InvalidationNone, 109 InvalidationIncremental, 110 InvalidationFull, 111 InvalidationBorderFitLines, 112 InvalidationBorderBoxChange, 113 InvalidationBoundsChange, 114 InvalidationLocationChange, 115 InvalidationBecameVisible, 116 InvalidationBecameInvisible, 117 InvalidationScroll, 118 InvalidationSelection, 119 InvalidationLayer, 120 InvalidationRendererRemoval, 121 InvalidationPaintRectangle 122 }; 123 124 const int caretWidth = 1; 125 126 struct AnnotatedRegionValue { 127 bool operator==(const AnnotatedRegionValue& o) const 128 { 129 return draggable == o.draggable && bounds == o.bounds; 130 } 131 132 LayoutRect bounds; 133 bool draggable; 134 }; 135 136 typedef WTF::HashMap<const RenderLayer*, Vector<LayoutRect> > LayerHitTestRects; 137 138 #ifndef NDEBUG 139 const int showTreeCharacterOffset = 39; 140 #endif 141 142 // Base class for all rendering tree objects. 143 class RenderObject : public NoBaseWillBeGarbageCollectedFinalized<RenderObject>, public ImageResourceClient { 144 friend class RenderBlock; 145 friend class RenderBlockFlow; 146 friend class RenderLayerReflectionInfo; // For setParent 147 friend class RenderLayerScrollableArea; // For setParent. 148 friend class RenderObjectChildList; 149 WTF_MAKE_NONCOPYABLE(RenderObject); 150 public: 151 // Anonymous objects should pass the document as their node, and they will then automatically be 152 // marked as anonymous in the constructor. 153 explicit RenderObject(Node*); 154 virtual ~RenderObject(); 155 virtual void trace(Visitor*); 156 157 virtual const char* renderName() const = 0; 158 159 String debugName() const; 160 161 RenderObject* parent() const { return m_parent; } 162 bool isDescendantOf(const RenderObject*) const; 163 164 RenderObject* previousSibling() const { return m_previous; } 165 RenderObject* nextSibling() const { return m_next; } 166 167 RenderObject* slowFirstChild() const 168 { 169 if (const RenderObjectChildList* children = virtualChildren()) 170 return children->firstChild(); 171 return 0; 172 } 173 RenderObject* slowLastChild() const 174 { 175 if (const RenderObjectChildList* children = virtualChildren()) 176 return children->lastChild(); 177 return 0; 178 } 179 180 virtual RenderObjectChildList* virtualChildren() { return 0; } 181 virtual const RenderObjectChildList* virtualChildren() const { return 0; } 182 183 RenderObject* nextInPreOrder() const; 184 RenderObject* nextInPreOrder(const RenderObject* stayWithin) const; 185 RenderObject* nextInPreOrderAfterChildren() const; 186 RenderObject* nextInPreOrderAfterChildren(const RenderObject* stayWithin) const; 187 RenderObject* previousInPreOrder() const; 188 RenderObject* previousInPreOrder(const RenderObject* stayWithin) const; 189 RenderObject* childAt(unsigned) const; 190 191 RenderObject* lastLeafChild() const; 192 193 // The following six functions are used when the render tree hierarchy changes to make sure layers get 194 // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy 195 // can contain a mixture of boxes and other object types, these functions need to be in the base class. 196 RenderLayer* enclosingLayer() const; 197 void addLayers(RenderLayer* parentLayer); 198 void removeLayers(RenderLayer* parentLayer); 199 void moveLayers(RenderLayer* oldParent, RenderLayer* newParent); 200 RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true); 201 202 // Scrolling is a RenderBox concept, however some code just cares about recursively scrolling our enclosing ScrollableArea(s). 203 bool scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX = ScrollAlignment::alignCenterIfNeeded, const ScrollAlignment& alignY = ScrollAlignment::alignCenterIfNeeded); 204 205 // Convenience function for getting to the nearest enclosing box of a RenderObject. 206 RenderBox* enclosingBox() const; 207 RenderBoxModelObject* enclosingBoxModelObject() const; 208 209 RenderBox* enclosingScrollableBox() const; 210 211 // Function to return our enclosing flow thread if we are contained inside one. This 212 // function follows the containing block chain. 213 RenderFlowThread* flowThreadContainingBlock() const 214 { 215 if (flowThreadState() == NotInsideFlowThread) 216 return 0; 217 return locateFlowThreadContainingBlock(); 218 } 219 220 #if ENABLE(ASSERT) 221 void setHasAXObject(bool flag) { m_hasAXObject = flag; } 222 bool hasAXObject() const { return m_hasAXObject; } 223 224 // Helper class forbidding calls to setNeedsLayout() during its lifetime. 225 class SetLayoutNeededForbiddenScope { 226 public: 227 explicit SetLayoutNeededForbiddenScope(RenderObject&); 228 ~SetLayoutNeededForbiddenScope(); 229 private: 230 RenderObject& m_renderObject; 231 bool m_preexistingForbidden; 232 }; 233 234 void assertRendererLaidOut() const 235 { 236 #ifndef NDEBUG 237 if (needsLayout()) 238 showRenderTreeForThis(); 239 #endif 240 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); 241 } 242 243 void assertSubtreeIsLaidOut() const 244 { 245 for (const RenderObject* renderer = this; renderer; renderer = renderer->nextInPreOrder()) 246 renderer->assertRendererLaidOut(); 247 } 248 249 void assertRendererClearedPaintInvalidationState() const 250 { 251 #ifndef NDEBUG 252 if (paintInvalidationStateIsDirty()) { 253 showRenderTreeForThis(); 254 ASSERT_NOT_REACHED(); 255 } 256 #endif 257 } 258 259 void assertSubtreeClearedPaintInvalidationState() const 260 { 261 for (const RenderObject* renderer = this; renderer; renderer = renderer->nextInPreOrder()) 262 renderer->assertRendererClearedPaintInvalidationState(); 263 } 264 265 #endif 266 267 bool skipInvalidationWhenLaidOutChildren() const; 268 269 // FIXME: This could be used when changing the size of a renderer without children to skip some invalidations. 270 bool rendererHasNoBoxEffect() const 271 { 272 return !style()->hasVisualOverflowingEffect() && !style()->hasBorder() && !style()->hasBackground(); 273 } 274 275 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline 276 // children. 277 virtual RenderBlock* firstLineBlock() const; 278 279 // Called when an object that was floating or positioned becomes a normal flow object 280 // again. We have to make sure the render tree updates as needed to accommodate the new 281 // normal flow object. 282 void handleDynamicFloatPositionChange(); 283 284 // RenderObject tree manipulation 285 ////////////////////////////////////////// 286 virtual bool canHaveChildren() const { return virtualChildren(); } 287 virtual bool canHaveGeneratedChildren() const; 288 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; } 289 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0); 290 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); } 291 virtual void removeChild(RenderObject*); 292 virtual bool createsAnonymousWrapper() const { return false; } 293 ////////////////////////////////////////// 294 295 protected: 296 ////////////////////////////////////////// 297 // Helper functions. Dangerous to use! 298 void setPreviousSibling(RenderObject* previous) { m_previous = previous; } 299 void setNextSibling(RenderObject* next) { m_next = next; } 300 void setParent(RenderObject* parent) 301 { 302 m_parent = parent; 303 304 // Only update if our flow thread state is different from our new parent and if we're not a RenderFlowThread. 305 // A RenderFlowThread is always considered to be inside itself, so it never has to change its state 306 // in response to parent changes. 307 FlowThreadState newState = parent ? parent->flowThreadState() : NotInsideFlowThread; 308 if (newState != flowThreadState() && !isRenderFlowThread()) 309 setFlowThreadStateIncludingDescendants(newState); 310 } 311 312 ////////////////////////////////////////// 313 private: 314 #if ENABLE(ASSERT) 315 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; } 316 void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; } 317 #endif 318 319 void addAbsoluteRectForLayer(LayoutRect& result); 320 bool requiresAnonymousTableWrappers(const RenderObject*) const; 321 322 // Gets pseudoStyle from Shadow host(in case of input elements) 323 // or from Parent element. 324 PassRefPtr<RenderStyle> getUncachedPseudoStyleFromParentOrShadowHost() const; 325 326 public: 327 #ifndef NDEBUG 328 void showTreeForThis() const; 329 void showRenderTreeForThis() const; 330 void showLineTreeForThis() const; 331 332 void showRenderObject() const; 333 // We don't make printedCharacters an optional parameter so that 334 // showRenderObject can be called from gdb easily. 335 void showRenderObject(int printedCharacters) const; 336 void showRenderTreeAndMark(const RenderObject* markedObject1 = 0, const char* markedLabel1 = 0, const RenderObject* markedObject2 = 0, const char* markedLabel2 = 0, int depth = 0) const; 337 #endif 338 339 static RenderObject* createObject(Element*, RenderStyle*); 340 static unsigned instanceCount() { return s_instanceCount; } 341 342 #if !ENABLE(OILPAN) 343 // RenderObjects are allocated out of the rendering partition. 344 void* operator new(size_t); 345 void operator delete(void*); 346 #endif 347 348 public: 349 bool isPseudoElement() const { return node() && node()->isPseudoElement(); } 350 351 virtual bool isBoxModelObject() const { return false; } 352 virtual bool isBR() const { return false; } 353 virtual bool isCanvas() const { return false; } 354 virtual bool isCounter() const { return false; } 355 virtual bool isDetailsMarker() const { return false; } 356 virtual bool isEmbeddedObject() const { return false; } 357 virtual bool isFieldset() const { return false; } 358 virtual bool isFileUploadControl() const { return false; } 359 virtual bool isFrame() const { return false; } 360 virtual bool isFrameSet() const { return false; } 361 virtual bool isImage() const { return false; } 362 virtual bool isInlineBlockOrInlineTable() const { return false; } 363 virtual bool isLayerModelObject() const { return false; } 364 virtual bool isListBox() const { return false; } 365 virtual bool isListItem() const { return false; } 366 virtual bool isListMarker() const { return false; } 367 virtual bool isMarquee() const { return false; } 368 virtual bool isMedia() const { return false; } 369 virtual bool isMenuList() const { return false; } 370 virtual bool isMeter() const { return false; } 371 virtual bool isProgress() const { return false; } 372 virtual bool isQuote() const { return false; } 373 virtual bool isRenderBlock() const { return false; } 374 virtual bool isRenderBlockFlow() const { return false; } 375 virtual bool isRenderButton() const { return false; } 376 virtual bool isRenderFlowThread() const { return false; } 377 virtual bool isRenderFullScreen() const { return false; } 378 virtual bool isRenderFullScreenPlaceholder() const { return false; } 379 virtual bool isRenderGrid() const { return false; } 380 virtual bool isRenderIFrame() const { return false; } 381 virtual bool isRenderImage() const { return false; } 382 virtual bool isRenderInline() const { return false; } 383 virtual bool isRenderMultiColumnSet() const { return false; } 384 virtual bool isRenderPart() const { return false; } 385 virtual bool isRenderRegion() const { return false; } 386 virtual bool isRenderScrollbarPart() const { return false; } 387 virtual bool isRenderTableCol() const { return false; } 388 virtual bool isRenderView() const { return false; } 389 virtual bool isReplica() const { return false; } 390 virtual bool isRuby() const { return false; } 391 virtual bool isRubyBase() const { return false; } 392 virtual bool isRubyRun() const { return false; } 393 virtual bool isRubyText() const { return false; } 394 virtual bool isSlider() const { return false; } 395 virtual bool isSliderThumb() const { return false; } 396 virtual bool isTable() const { return false; } 397 virtual bool isTableCaption() const { return false; } 398 virtual bool isTableCell() const { return false; } 399 virtual bool isTableRow() const { return false; } 400 virtual bool isTableSection() const { return false; } 401 virtual bool isTextArea() const { return false; } 402 virtual bool isTextControl() const { return false; } 403 virtual bool isTextField() const { return false; } 404 virtual bool isVideo() const { return false; } 405 virtual bool isWidget() const { return false; } 406 407 bool isDocumentElement() const { return document().documentElement() == m_node; } 408 // isBody is called from RenderBox::styleWillChange and is thus quite hot. 409 bool isBody() const { return node() && node()->hasTagName(HTMLNames::bodyTag); } 410 bool isHR() const; 411 bool isLegend() const; 412 413 bool isTablePart() const { return isTableCell() || isRenderTableCol() || isTableCaption() || isTableRow() || isTableSection(); } 414 415 inline bool isBeforeContent() const; 416 inline bool isAfterContent() const; 417 inline bool isBeforeOrAfterContent() const; 418 static inline bool isAfterContent(const RenderObject* obj) { return obj && obj->isAfterContent(); } 419 420 bool hasCounterNodeMap() const { return m_bitfields.hasCounterNodeMap(); } 421 void setHasCounterNodeMap(bool hasCounterNodeMap) { m_bitfields.setHasCounterNodeMap(hasCounterNodeMap); } 422 bool everHadLayout() const { return m_bitfields.everHadLayout(); } 423 424 bool childrenInline() const { return m_bitfields.childrenInline(); } 425 void setChildrenInline(bool b) { m_bitfields.setChildrenInline(b); } 426 bool hasColumns() const { return m_bitfields.hasColumns(); } 427 void setHasColumns(bool b = true) { m_bitfields.setHasColumns(b); } 428 429 bool alwaysCreateLineBoxesForRenderInline() const 430 { 431 ASSERT(isRenderInline()); 432 return m_bitfields.alwaysCreateLineBoxesForRenderInline(); 433 } 434 void setAlwaysCreateLineBoxesForRenderInline(bool alwaysCreateLineBoxes) 435 { 436 ASSERT(isRenderInline()); 437 m_bitfields.setAlwaysCreateLineBoxesForRenderInline(alwaysCreateLineBoxes); 438 } 439 440 bool ancestorLineBoxDirty() const { return m_bitfields.ancestorLineBoxDirty(); } 441 void setAncestorLineBoxDirty(bool value = true) 442 { 443 m_bitfields.setAncestorLineBoxDirty(value); 444 if (value) 445 setNeedsLayoutAndFullPaintInvalidation(); 446 } 447 448 enum FlowThreadState { 449 NotInsideFlowThread = 0, 450 InsideOutOfFlowThread = 1, 451 InsideInFlowThread = 2, 452 }; 453 454 void setFlowThreadStateIncludingDescendants(FlowThreadState); 455 456 FlowThreadState flowThreadState() const { return m_bitfields.flowThreadState(); } 457 void setFlowThreadState(FlowThreadState state) { m_bitfields.setFlowThreadState(state); } 458 459 // FIXME: Until all SVG renders can be subclasses of RenderSVGModelObject we have 460 // to add SVG renderer methods to RenderObject with an ASSERT_NOT_REACHED() default implementation. 461 virtual bool isSVG() const { return false; } 462 virtual bool isSVGRoot() const { return false; } 463 virtual bool isSVGContainer() const { return false; } 464 virtual bool isSVGTransformableContainer() const { return false; } 465 virtual bool isSVGViewportContainer() const { return false; } 466 virtual bool isSVGGradientStop() const { return false; } 467 virtual bool isSVGHiddenContainer() const { return false; } 468 virtual bool isSVGShape() const { return false; } 469 virtual bool isSVGText() const { return false; } 470 virtual bool isSVGTextPath() const { return false; } 471 virtual bool isSVGInline() const { return false; } 472 virtual bool isSVGInlineText() const { return false; } 473 virtual bool isSVGImage() const { return false; } 474 virtual bool isSVGForeignObject() const { return false; } 475 virtual bool isSVGResourceContainer() const { return false; } 476 virtual bool isSVGResourceFilter() const { return false; } 477 virtual bool isSVGResourceFilterPrimitive() const { return false; } 478 479 // FIXME: Those belong into a SVG specific base-class for all renderers (see above) 480 // Unfortunately we don't have such a class yet, because it's not possible for all renderers 481 // to inherit from RenderSVGObject -> RenderObject (some need RenderBlock inheritance for instance) 482 virtual void setNeedsTransformUpdate() { } 483 virtual void setNeedsBoundariesUpdate(); 484 485 // Per SVG 1.1 objectBoundingBox ignores clipping, masking, filter effects, opacity and stroke-width. 486 // This is used for all computation of objectBoundingBox relative units and by SVGLocatable::getBBox(). 487 // NOTE: Markers are not specifically ignored here by SVG 1.1 spec, but we ignore them 488 // since stroke-width is ignored (and marker size can depend on stroke-width). 489 // objectBoundingBox is returned local coordinates. 490 // The name objectBoundingBox is taken from the SVG 1.1 spec. 491 virtual FloatRect objectBoundingBox() const; 492 virtual FloatRect strokeBoundingBox() const; 493 494 // Returns the smallest rectangle enclosing all of the painted content 495 // respecting clipping, masking, filters, opacity, stroke-width and markers 496 virtual FloatRect paintInvalidationRectInLocalCoordinates() const; 497 498 // This only returns the transform="" value from the element 499 // most callsites want localToParentTransform() instead. 500 virtual AffineTransform localTransform() const; 501 502 // Returns the full transform mapping from local coordinates to local coords for the parent SVG renderer 503 // This includes any viewport transforms and x/y offsets as well as the transform="" value off the element. 504 virtual const AffineTransform& localToParentTransform() const; 505 506 // SVG uses FloatPoint precise hit testing, and passes the point in parent 507 // coordinates instead of in paint invalidaiton container coordinates. Eventually the 508 // rest of the rendering tree will move to a similar model. 509 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction); 510 511 virtual bool canHaveWhitespaceChildren() const 512 { 513 if (isTable() || isTableRow() || isTableSection() || isRenderTableCol() || isFrameSet() || isFlexibleBox() || isRenderGrid()) 514 return false; 515 return true; 516 } 517 518 bool isAnonymous() const { return m_bitfields.isAnonymous(); } 519 bool isAnonymousBlock() const 520 { 521 // This function is kept in sync with anonymous block creation conditions in 522 // RenderBlock::createAnonymousBlock(). This includes creating an anonymous 523 // RenderBlock having a BLOCK or BOX display. Other classes such as RenderTextFragment 524 // are not RenderBlocks and will return false. See https://bugs.webkit.org/show_bug.cgi?id=56709. 525 return isAnonymous() && (style()->display() == BLOCK || style()->display() == BOX) && style()->styleType() == NOPSEUDO && isRenderBlock() && !isListMarker() && !isRenderFlowThread() 526 && !isRenderFullScreen() 527 && !isRenderFullScreenPlaceholder(); 528 } 529 bool isAnonymousColumnsBlock() const { return style()->specifiesColumns() && isAnonymousBlock(); } 530 bool isAnonymousColumnSpanBlock() const { return style()->columnSpan() && isAnonymousBlock(); } 531 bool isElementContinuation() const { return node() && node()->renderer() != this; } 532 bool isInlineElementContinuation() const { return isElementContinuation() && isInline(); } 533 virtual RenderBoxModelObject* virtualContinuation() const { return 0; } 534 535 bool isFloating() const { return m_bitfields.floating(); } 536 537 bool isOutOfFlowPositioned() const { return m_bitfields.isOutOfFlowPositioned(); } // absolute or fixed positioning 538 bool isRelPositioned() const { return m_bitfields.isRelPositioned(); } // relative positioning 539 bool isPositioned() const { return m_bitfields.isPositioned(); } 540 541 bool isText() const { return m_bitfields.isText(); } 542 bool isBox() const { return m_bitfields.isBox(); } 543 bool isInline() const { return m_bitfields.isInline(); } // inline object 544 bool isDragging() const { return m_bitfields.isDragging(); } 545 bool isReplaced() const { return m_bitfields.isReplaced(); } // a "replaced" element (see CSS) 546 bool isHorizontalWritingMode() const { return m_bitfields.horizontalWritingMode(); } 547 548 bool hasLayer() const { return m_bitfields.hasLayer(); } 549 550 // "Box decoration background" includes all box decorations and backgrounds 551 // that are painted as the background of the object. It includes borders, 552 // box-shadows, background-color and background-image, etc. 553 enum BoxDecorationBackgroundState { 554 NoBoxDecorationBackground, 555 HasBoxDecorationBackgroundObscurationStatusInvalid, 556 HasBoxDecorationBackgroundKnownToBeObscured, 557 HasBoxDecorationBackgroundMayBeVisible, 558 }; 559 bool hasBoxDecorationBackground() const { return m_bitfields.boxDecorationBackgroundState() != NoBoxDecorationBackground; } 560 bool boxDecorationBackgroundIsKnownToBeObscured(); 561 bool canRenderBorderImage() const; 562 bool mustInvalidateBackgroundOrBorderPaintOnWidthChange() const; 563 bool mustInvalidateBackgroundOrBorderPaintOnHeightChange() const; 564 bool mustInvalidateFillLayersPaintOnWidthChange(const FillLayer&) const; 565 bool mustInvalidateFillLayersPaintOnHeightChange(const FillLayer&) const; 566 bool hasBackground() const { return style()->hasBackground(); } 567 bool hasEntirelyFixedBackground() const; 568 569 bool needsLayoutBecauseOfChildren() const { return needsLayout() && !selfNeedsLayout() && !needsPositionedMovementLayout() && !needsSimplifiedNormalFlowLayout(); } 570 571 bool needsLayout() const 572 { 573 return m_bitfields.selfNeedsLayout() || m_bitfields.normalChildNeedsLayout() || m_bitfields.posChildNeedsLayout() 574 || m_bitfields.needsSimplifiedNormalFlowLayout() || m_bitfields.needsPositionedMovementLayout(); 575 } 576 577 bool selfNeedsLayout() const { return m_bitfields.selfNeedsLayout(); } 578 bool needsPositionedMovementLayout() const { return m_bitfields.needsPositionedMovementLayout(); } 579 bool needsPositionedMovementLayoutOnly() const 580 { 581 return m_bitfields.needsPositionedMovementLayout() && !m_bitfields.selfNeedsLayout() && !m_bitfields.normalChildNeedsLayout() 582 && !m_bitfields.posChildNeedsLayout() && !m_bitfields.needsSimplifiedNormalFlowLayout(); 583 } 584 585 bool posChildNeedsLayout() const { return m_bitfields.posChildNeedsLayout(); } 586 bool needsSimplifiedNormalFlowLayout() const { return m_bitfields.needsSimplifiedNormalFlowLayout(); } 587 bool normalChildNeedsLayout() const { return m_bitfields.normalChildNeedsLayout(); } 588 589 bool preferredLogicalWidthsDirty() const { return m_bitfields.preferredLogicalWidthsDirty(); } 590 591 bool needsOverflowRecalcAfterStyleChange() const { return m_bitfields.selfNeedsOverflowRecalcAfterStyleChange() || m_bitfields.childNeedsOverflowRecalcAfterStyleChange(); } 592 bool selfNeedsOverflowRecalcAfterStyleChange() const { return m_bitfields.selfNeedsOverflowRecalcAfterStyleChange(); } 593 bool childNeedsOverflowRecalcAfterStyleChange() const { return m_bitfields.childNeedsOverflowRecalcAfterStyleChange(); } 594 595 bool isSelectionBorder() const; 596 597 bool hasClip() const { return isOutOfFlowPositioned() && !style()->hasAutoClip(); } 598 bool hasOverflowClip() const { return m_bitfields.hasOverflowClip(); } 599 bool hasClipOrOverflowClip() const { return hasClip() || hasOverflowClip(); } 600 601 bool hasTransform() const { return m_bitfields.hasTransform(); } 602 bool hasMask() const { return style() && style()->hasMask(); } 603 bool hasClipPath() const { return style() && style()->clipPath(); } 604 bool hasHiddenBackface() const { return style() && style()->backfaceVisibility() == BackfaceVisibilityHidden; } 605 606 bool hasFilter() const { return style() && style()->hasFilter(); } 607 608 bool hasBlendMode() const; 609 610 bool hasShapeOutside() const { return style() && style()->shapeOutside(); } 611 612 inline bool preservesNewline() const; 613 614 // The pseudo element style can be cached or uncached. Use the cached method if the pseudo element doesn't respect 615 // any pseudo classes (and therefore has no concept of changing state). 616 RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0) const; 617 PassRefPtr<RenderStyle> getUncachedPseudoStyle(const PseudoStyleRequest&, RenderStyle* parentStyle = 0, RenderStyle* ownStyle = 0) const; 618 619 virtual void updateDragState(bool dragOn); 620 621 RenderView* view() const { return document().renderView(); }; 622 FrameView* frameView() const { return document().view(); }; 623 624 bool isRooted() const; 625 626 Node* node() const 627 { 628 return isAnonymous() ? 0 : m_node.get(); 629 } 630 631 Node* nonPseudoNode() const 632 { 633 return isPseudoElement() ? 0 : node(); 634 } 635 636 // FIXME: Why does RenderWidget need this? 637 void clearNode() { m_node = nullptr; } 638 639 // Returns the styled node that caused the generation of this renderer. 640 // This is the same as node() except for renderers of :before and :after 641 // pseudo elements for which their parent node is returned. 642 Node* generatingNode() const { return isPseudoElement() ? node()->parentOrShadowHostNode() : node(); } 643 644 Document& document() const { return m_node->document(); } 645 LocalFrame* frame() const { return document().frame(); } 646 647 // Returns the object containing this one. Can be different from parent for positioned elements. 648 // If paintInvalidationContainer and paintInvalidationContainerSkipped are not null, on return *paintInvalidationContainerSkipped 649 // is true if the renderer returned is an ancestor of paintInvalidationContainer. 650 RenderObject* container(const RenderLayerModelObject* paintInvalidationContainer = 0, bool* paintInvalidationContainerSkipped = 0) const; 651 RenderBlock* containerForFixedPosition(const RenderLayerModelObject* paintInvalidationContainer = 0, bool* paintInvalidationContainerSkipped = 0) const; 652 653 virtual RenderObject* hoverAncestor() const { return parent(); } 654 655 Element* offsetParent() const; 656 657 void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0, SubtreeLayoutScope* = 0); 658 void setNeedsLayout(MarkingBehavior = MarkContainingBlockChain, SubtreeLayoutScope* = 0); 659 void setNeedsLayoutAndFullPaintInvalidation(MarkingBehavior = MarkContainingBlockChain, SubtreeLayoutScope* = 0); 660 void clearNeedsLayout(); 661 void setChildNeedsLayout(MarkingBehavior = MarkContainingBlockChain, SubtreeLayoutScope* = 0); 662 void setNeedsPositionedMovementLayout(); 663 void setPreferredLogicalWidthsDirty(MarkingBehavior = MarkContainingBlockChain); 664 void clearPreferredLogicalWidthsDirty(); 665 void invalidateContainerPreferredLogicalWidths(); 666 667 void setNeedsLayoutAndPrefWidthsRecalc() 668 { 669 setNeedsLayout(); 670 setPreferredLogicalWidthsDirty(); 671 } 672 void setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation() 673 { 674 setNeedsLayoutAndFullPaintInvalidation(); 675 setPreferredLogicalWidthsDirty(); 676 } 677 678 void setPositionState(EPosition position) 679 { 680 ASSERT((position != AbsolutePosition && position != FixedPosition) || isBox()); 681 m_bitfields.setPositionedState(position); 682 } 683 void clearPositionedState() { m_bitfields.clearPositionedState(); } 684 685 void setFloating(bool isFloating) { m_bitfields.setFloating(isFloating); } 686 void setInline(bool isInline) { m_bitfields.setIsInline(isInline); } 687 688 void setHasBoxDecorationBackground(bool); 689 void invalidateBackgroundObscurationStatus(); 690 virtual bool computeBackgroundIsKnownToBeObscured() { return false; } 691 692 void setIsText() { m_bitfields.setIsText(true); } 693 void setIsBox() { m_bitfields.setIsBox(true); } 694 void setReplaced(bool isReplaced) { m_bitfields.setIsReplaced(isReplaced); } 695 void setHorizontalWritingMode(bool hasHorizontalWritingMode) { m_bitfields.setHorizontalWritingMode(hasHorizontalWritingMode); } 696 void setHasOverflowClip(bool hasOverflowClip) { m_bitfields.setHasOverflowClip(hasOverflowClip); } 697 void setHasLayer(bool hasLayer) { m_bitfields.setHasLayer(hasLayer); } 698 void setHasTransform(bool hasTransform) { m_bitfields.setHasTransform(hasTransform); } 699 void setHasReflection(bool hasReflection) { m_bitfields.setHasReflection(hasReflection); } 700 701 void scheduleRelayout(); 702 703 void updateFillImages(const FillLayer* oldLayers, const FillLayer& newLayers); 704 void updateImage(StyleImage*, StyleImage*); 705 void updateShapeImage(const ShapeValue*, const ShapeValue*); 706 707 // paintOffset is the offset from the origin of the GraphicsContext at which to paint the current object. 708 virtual void paint(PaintInfo&, const LayoutPoint& paintOffset); 709 710 // Subclasses must reimplement this method to compute the size and position 711 // of this object and all its descendants. 712 virtual void layout() = 0; 713 virtual bool updateImageLoadingPriorities() { return false; } 714 void setHasPendingResourceUpdate(bool hasPendingResourceUpdate) { m_bitfields.setHasPendingResourceUpdate(hasPendingResourceUpdate); } 715 bool hasPendingResourceUpdate() const { return m_bitfields.hasPendingResourceUpdate(); } 716 717 /* This function performs a layout only if one is needed. */ 718 void layoutIfNeeded() { if (needsLayout()) layout(); } 719 720 void forceLayout(); 721 void forceChildLayout(); 722 723 // Used for element state updates that cannot be fixed with a 724 // paint invalidation and do not need a relayout. 725 virtual void updateFromElement() { } 726 727 virtual void addAnnotatedRegions(Vector<AnnotatedRegionValue>&); 728 void collectAnnotatedRegions(Vector<AnnotatedRegionValue>&); 729 730 CompositingState compositingState() const; 731 virtual CompositingReasons additionalCompositingReasons() const; 732 733 bool hitTest(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter = HitTestAll); 734 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&); 735 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction); 736 737 virtual PositionWithAffinity positionForPoint(const LayoutPoint&); 738 PositionWithAffinity createPositionWithAffinity(int offset, EAffinity); 739 PositionWithAffinity createPositionWithAffinity(const Position&); 740 741 virtual void dirtyLinesFromChangedChild(RenderObject*); 742 743 // Set the style of the object and update the state of the object accordingly. 744 void setStyle(PassRefPtr<RenderStyle>); 745 746 // Set the style of the object if it's generated content. 747 void setPseudoStyle(PassRefPtr<RenderStyle>); 748 749 // Updates only the local style ptr of the object. Does not update the state of the object, 750 // and so only should be called when the style is known not to have changed (or from setStyle). 751 void setStyleInternal(PassRefPtr<RenderStyle> style) { m_style = style; } 752 753 // returns the containing block level element for this element. 754 RenderBlock* containingBlock() const; 755 756 bool canContainFixedPositionObjects() const 757 { 758 return isRenderView() || (hasTransform() && isRenderBlock()) || isSVGForeignObject(); 759 } 760 761 // Convert the given local point to absolute coordinates 762 // FIXME: Temporary. If UseTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware. 763 FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(), MapCoordinatesFlags = 0) const; 764 FloatPoint absoluteToLocal(const FloatPoint&, MapCoordinatesFlags = 0) const; 765 766 // Convert a local quad to absolute coordinates, taking transforms into account. 767 FloatQuad localToAbsoluteQuad(const FloatQuad& quad, MapCoordinatesFlags mode = 0, bool* wasFixed = 0) const 768 { 769 return localToContainerQuad(quad, 0, mode, wasFixed); 770 } 771 // Convert an absolute quad to local coordinates. 772 FloatQuad absoluteToLocalQuad(const FloatQuad&, MapCoordinatesFlags mode = 0) const; 773 774 // Convert a local quad into the coordinate system of container, taking transforms into account. 775 FloatQuad localToContainerQuad(const FloatQuad&, const RenderLayerModelObject* paintInvalidatinoContainer, MapCoordinatesFlags = 0, bool* wasFixed = 0) const; 776 FloatPoint localToContainerPoint(const FloatPoint&, const RenderLayerModelObject* paintInvalidationContainer, MapCoordinatesFlags = 0, bool* wasFixed = 0, const PaintInvalidationState* = 0) const; 777 778 // Convert a local point into the coordinate system of backing coordinates. Also returns the backing layer if needed. 779 FloatPoint localToInvalidationBackingPoint(const LayoutPoint&, RenderLayer** backingLayer = nullptr); 780 781 // Return the offset from the container() renderer (excluding transforms). In multi-column layout, 782 // different offsets apply at different points, so return the offset that applies to the given point. 783 virtual LayoutSize offsetFromContainer(const RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const; 784 // Return the offset from an object up the container() chain. Asserts that none of the intermediate objects have transforms. 785 LayoutSize offsetFromAncestorContainer(const RenderObject*) const; 786 787 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint&) const { } 788 789 IntRect absoluteBoundingBoxRect() const; 790 // FIXME: This function should go away eventually 791 IntRect absoluteBoundingBoxRectIgnoringTransforms() const; 792 793 // Build an array of quads in absolute coords for line boxes 794 virtual void absoluteQuads(Vector<FloatQuad>&, bool* /*wasFixed*/ = 0) const { } 795 796 virtual IntRect absoluteFocusRingBoundingBoxRect() const; 797 798 static FloatRect absoluteBoundingBoxRectForRange(const Range*); 799 800 // the rect that will be painted if this object is passed as the paintingRoot 801 LayoutRect paintingRootRect(LayoutRect& topLevelRect); 802 803 virtual LayoutUnit minPreferredLogicalWidth() const { return 0; } 804 virtual LayoutUnit maxPreferredLogicalWidth() const { return 0; } 805 806 RenderStyle* style() const { return m_style.get(); } 807 808 /* The two following methods are inlined in RenderObjectInlines.h */ 809 RenderStyle* firstLineStyle() const; 810 RenderStyle* style(bool firstLine) const; 811 812 inline Color resolveColor(const RenderStyle* styleToUse, int colorProperty) const 813 { 814 return styleToUse->visitedDependentColor(colorProperty); 815 } 816 817 inline Color resolveColor(int colorProperty) const 818 { 819 return style()->visitedDependentColor(colorProperty); 820 } 821 822 // Used only by Element::pseudoStyleCacheIsInvalid to get a first line style based off of a 823 // given new style, without accessing the cache. 824 PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const; 825 826 virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const; 827 828 struct AppliedTextDecoration { 829 Color color; 830 TextDecorationStyle style; 831 AppliedTextDecoration() : color(Color::transparent), style(TextDecorationStyleSolid) { } 832 }; 833 834 void getTextDecorations(unsigned decorations, AppliedTextDecoration& underline, AppliedTextDecoration& overline, AppliedTextDecoration& linethrough, bool quirksMode = false, bool firstlineStyle = false); 835 836 void setHadPaintInvalidation(); 837 bool hadPaintInvalidation() const; 838 839 // Return the RenderLayerModelObject in the container chain which is responsible for painting this object, or 0 840 // if painting is root-relative. This is the container that should be passed to the 'forPaintInvalidation' 841 // methods. 842 const RenderLayerModelObject* containerForPaintInvalidation() const; 843 const RenderLayerModelObject* adjustCompositedContainerForSpecialAncestors(const RenderLayerModelObject* paintInvalidationContainer) const; 844 bool isPaintInvalidationContainer() const; 845 846 LayoutRect computePaintInvalidationRect() 847 { 848 return computePaintInvalidationRect(containerForPaintInvalidation()); 849 } 850 851 // Returns the paint invalidation rect for this RenderObject in the coordinate space of the paint backing (typically a GraphicsLayer) for |paintInvalidationContainer|. 852 LayoutRect computePaintInvalidationRect(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const; 853 854 // Returns the rect bounds needed to invalidate the paint of this object, in the coordinate space of the rendering backing of |paintInvalidationContainer| 855 LayoutRect boundsRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const; 856 857 // Actually do the paint invalidate of rect r for this object which has been computed in the coordinate space 858 // of the GraphicsLayer backing of |paintInvalidationContainer|. Note that this coordinaten space is not the same 859 // as the local coordinate space of |paintInvalidationContainer| in the presence of layer squashing. 860 // If |paintInvalidationContainer| is 0, invalidate paints via the view. 861 // FIXME: |paintInvalidationContainer| should never be 0. See crbug.com/363699. 862 void invalidatePaintUsingContainer(const RenderLayerModelObject* paintInvalidationContainer, const LayoutRect&, InvalidationReason) const; 863 864 // Invalidate the paint of a specific subrectangle within a given object. The rect |r| is in the object's coordinate space. 865 void invalidatePaintRectangle(const LayoutRect&) const; 866 867 // Walk the tree after layout issuing paint invalidations for renderers that have changed or moved, updating bounds that have changed, and clearing paint invalidation state. 868 virtual void invalidateTreeIfNeeded(const PaintInvalidationState&); 869 870 virtual void invalidatePaintForOverflow(); 871 void invalidatePaintForOverflowIfNeeded(); 872 873 void invalidatePaintIncludingNonCompositingDescendants(); 874 875 bool checkForPaintInvalidation() const; 876 877 // Returns the rect that should have paint invalidated whenever this object changes. The rect is in the view's 878 // coordinate space. This method deals with outlines and overflow. 879 LayoutRect absoluteClippedOverflowRect() const; 880 IntRect pixelSnappedAbsoluteClippedOverflowRect() const; 881 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const; 882 virtual LayoutRect rectWithOutlineForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, LayoutUnit outlineWidth, const PaintInvalidationState* = 0) const; 883 884 // Given a rect in the object's coordinate space, compute a rect suitable for invalidating paints of 885 // that rect in the coordinate space of paintInvalidationContainer. 886 virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const; 887 virtual void computeFloatRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, FloatRect& paintInvalidationRect, const PaintInvalidationState*) const; 888 889 // Return the offset to the column in which the specified point (in flow-thread coordinates) 890 // lives. This is used to convert a flow-thread point to a visual point. 891 virtual LayoutSize columnOffset(const LayoutPoint&) const { return LayoutSize(); } 892 893 virtual unsigned length() const { return 1; } 894 895 bool isFloatingOrOutOfFlowPositioned() const { return (isFloating() || isOutOfFlowPositioned()); } 896 897 bool isTransparent() const { return style()->hasOpacity(); } 898 float opacity() const { return style()->opacity(); } 899 900 bool hasReflection() const { return m_bitfields.hasReflection(); } 901 902 enum SelectionState { 903 SelectionNone, // The object is not selected. 904 SelectionStart, // The object either contains the start of a selection run or is the start of a run 905 SelectionInside, // The object is fully encompassed by a selection run 906 SelectionEnd, // The object either contains the end of a selection run or is the end of a run 907 SelectionBoth // The object contains an entire run or is the sole selected object in that run 908 }; 909 910 // The current selection state for an object. For blocks, the state refers to the state of the leaf 911 // descendants (as described above in the SelectionState enum declaration). 912 SelectionState selectionState() const { return m_bitfields.selectionState(); } 913 virtual void setSelectionState(SelectionState state) { m_bitfields.setSelectionState(state); } 914 inline void setSelectionStateIfNeeded(SelectionState); 915 bool canUpdateSelectionOnRootLineBoxes(); 916 917 // A single rectangle that encompasses all of the selected objects within this object. Used to determine the tightest 918 // possible bounding box for the selection. The rect returned is in the coordinate space of the paint invalidation container's backing. 919 virtual LayoutRect selectionRectForPaintInvalidation(const RenderLayerModelObject* /*paintInvalidationContainer*/) const { return LayoutRect(); } 920 921 virtual bool canBeSelectionLeaf() const { return false; } 922 bool hasSelectedChildren() const { return selectionState() != SelectionNone; } 923 924 bool isSelectable() const; 925 // Obtains the selection colors that should be used when painting a selection. 926 Color selectionBackgroundColor() const; 927 Color selectionForegroundColor() const; 928 Color selectionEmphasisMarkColor() const; 929 930 // Whether or not a given block needs to paint selection gaps. 931 virtual bool shouldPaintSelectionGaps() const { return false; } 932 933 /** 934 * Returns the local coordinates of the caret within this render object. 935 * @param caretOffset zero-based offset determining position within the render object. 936 * @param extraWidthToEndOfLine optional out arg to give extra width to end of line - 937 * useful for character range rect computations 938 */ 939 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0); 940 941 // When performing a global document tear-down, the renderer of the document is cleared. We use this 942 // as a hook to detect the case of document destruction and don't waste time doing unnecessary work. 943 bool documentBeingDestroyed() const; 944 945 void destroyAndCleanupAnonymousWrappers(); 946 virtual void destroy(); 947 948 // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box). 949 virtual bool isDeprecatedFlexibleBox() const { return false; } 950 951 // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flex). 952 virtual bool isFlexibleBox() const { return false; } 953 954 bool isFlexibleBoxIncludingDeprecated() const 955 { 956 return isFlexibleBox() || isDeprecatedFlexibleBox(); 957 } 958 959 virtual bool isCombineText() const { return false; } 960 961 virtual int caretMinOffset() const; 962 virtual int caretMaxOffset() const; 963 964 virtual int previousOffset(int current) const; 965 virtual int previousOffsetForBackwardDeletion(int current) const; 966 virtual int nextOffset(int current) const; 967 968 virtual void imageChanged(ImageResource*, const IntRect* = 0) OVERRIDE FINAL; 969 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { } 970 virtual bool willRenderImage(ImageResource*) OVERRIDE FINAL; 971 972 void selectionStartEnd(int& spos, int& epos) const; 973 974 void remove() { if (parent()) parent()->removeChild(this); } 975 976 bool isInert() const; 977 978 bool supportsTouchAction() const; 979 980 bool visibleToHitTestRequest(const HitTestRequest& request) const { return style()->visibility() == VISIBLE && (request.ignorePointerEventsNone() || style()->pointerEvents() != PE_NONE) && !isInert(); } 981 982 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE && !isInert(); } 983 984 // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use 985 // localToAbsolute/absoluteToLocal methods instead. 986 virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const; 987 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const; 988 989 // Pushes state onto RenderGeometryMap about how to map coordinates from this renderer to its container, or ancestorToStopAt (whichever is encountered first). 990 // Returns the renderer which was mapped to (container or ancestorToStopAt). 991 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const; 992 993 bool shouldUseTransformFromContainer(const RenderObject* container) const; 994 void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const; 995 996 bool createsGroup() const { return isTransparent() || hasMask() || hasFilter() || hasBlendMode(); } 997 998 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const { } 999 1000 // Compute a list of hit-test rectangles per layer rooted at this renderer. 1001 virtual void computeLayerHitTestRects(LayerHitTestRects&) const; 1002 1003 // Return the renderer whose background style is used to paint the root background. Should only be called on the renderer for which isDocumentElement() is true. 1004 RenderObject* rendererForRootBackground(); 1005 1006 RespectImageOrientationEnum shouldRespectImageOrientation() const; 1007 1008 bool isRelayoutBoundaryForInspector() const; 1009 1010 // The previous paint invalidation rect in the object's previous paint backing. 1011 const LayoutRect& previousPaintInvalidationRect() const { return m_previousPaintInvalidationRect; } 1012 void setPreviousPaintInvalidationRect(const LayoutRect& rect) { m_previousPaintInvalidationRect = rect; } 1013 1014 // The previous position of the top-left corner of the object in its previous paint backing. 1015 const LayoutPoint& previousPositionFromPaintInvalidationBacking() const { return m_previousPositionFromPaintInvalidationBacking; } 1016 void setPreviousPositionFromPaintInvalidationBacking(const LayoutPoint& positionFromPaintInvalidationBacking) { m_previousPositionFromPaintInvalidationBacking = positionFromPaintInvalidationBacking; } 1017 1018 bool shouldDoFullPaintInvalidation() const { return m_bitfields.shouldDoFullPaintInvalidation(); } 1019 void setShouldDoFullPaintInvalidation(bool, MarkingBehavior = MarkContainingBlockChain); 1020 1021 bool shouldInvalidateOverflowForPaint() const { return m_bitfields.shouldInvalidateOverflowForPaint(); } 1022 1023 bool shouldDoFullPaintInvalidationIfSelfPaintingLayer() const { return m_bitfields.shouldDoFullPaintInvalidationIfSelfPaintingLayer(); } 1024 void setShouldDoFullPaintInvalidationIfSelfPaintingLayer(bool b) 1025 { 1026 m_bitfields.setShouldDoFullPaintInvalidationIfSelfPaintingLayer(b); 1027 1028 if (b) 1029 markContainingBlockChainForPaintInvalidation(); 1030 } 1031 1032 bool onlyNeededPositionedMovementLayout() const { return m_bitfields.onlyNeededPositionedMovementLayout(); } 1033 void setOnlyNeededPositionedMovementLayout(bool b) { m_bitfields.setOnlyNeededPositionedMovementLayout(b); } 1034 1035 virtual void clearPaintInvalidationState(const PaintInvalidationState&); 1036 1037 // layoutDidGetCalled indicates whether this render object was re-laid-out 1038 // since the last call to setLayoutDidGetCalled(false) on this object. 1039 bool layoutDidGetCalled() const { return m_bitfields.layoutDidGetCalled(); } 1040 void setLayoutDidGetCalled(bool b) 1041 { 1042 m_bitfields.setLayoutDidGetCalled(b); 1043 1044 if (b) 1045 markContainingBlockChainForPaintInvalidation(); 1046 } 1047 1048 bool mayNeedPaintInvalidation() const { return m_bitfields.mayNeedPaintInvalidation(); } 1049 void setMayNeedPaintInvalidation(bool b) 1050 { 1051 m_bitfields.setMayNeedPaintInvalidation(b); 1052 1053 // Make sure our parent is marked as needing invalidation. 1054 if (b) 1055 markContainingBlockChainForPaintInvalidation(); 1056 } 1057 1058 bool neededLayoutBecauseOfChildren() const { return m_bitfields.neededLayoutBecauseOfChildren(); } 1059 void setNeededLayoutBecauseOfChildren(bool b) { m_bitfields.setNeededLayoutBecauseOfChildren(b); } 1060 1061 bool shouldCheckForPaintInvalidation(const PaintInvalidationState& paintInvalidationState) 1062 { 1063 return paintInvalidationState.forceCheckForPaintInvalidation() || shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState(); 1064 } 1065 1066 bool shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState() 1067 { 1068 return layoutDidGetCalled() || mayNeedPaintInvalidation() || shouldDoFullPaintInvalidation() || shouldDoFullPaintInvalidationIfSelfPaintingLayer(); 1069 } 1070 1071 bool supportsPaintInvalidationStateCachedOffsets() const { return !hasColumns() && !hasTransform() && !hasReflection() && !style()->isFlippedBlocksWritingMode(); } 1072 1073 void setNeedsOverflowRecalcAfterStyleChange(); 1074 void markContainingBlocksForOverflowRecalc(); 1075 1076 virtual LayoutRect viewRect() const; 1077 1078 protected: 1079 inline bool layerCreationAllowedForSubtree() const; 1080 1081 // Overrides should call the superclass at the end. m_style will be 0 the first time 1082 // this function will be called. 1083 virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle); 1084 // Overrides should call the superclass at the start. |oldStyle| will be 0 the first 1085 // time this function is called. 1086 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 1087 void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false); 1088 virtual void updateAnonymousChildStyle(const RenderObject* child, RenderStyle* style) const { } 1089 1090 public: 1091 void paintOutline(PaintInfo&, const LayoutRect&); 1092 protected: 1093 void addChildFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const; 1094 1095 void clearLayoutRootIfNeeded() const; 1096 virtual void willBeDestroyed(); 1097 void postDestroy(); 1098 1099 virtual void insertedIntoTree(); 1100 virtual void willBeRemovedFromTree(); 1101 1102 void setDocumentForAnonymous(Document* document) { ASSERT(isAnonymous()); m_node = document; } 1103 1104 // Add hit-test rects for the render tree rooted at this node to the provided collection on a 1105 // per-RenderLayer basis. 1106 // currentLayer must be the enclosing layer, and layerOffset is the current offset within 1107 // this layer. Subclass implementations will add any offset for this renderer within it's 1108 // container, so callers should provide only the offset of the container within it's layer. 1109 // containerRect is a rect that has already been added for the currentLayer which is likely to 1110 // be a container for child elements. Any rect wholly contained by containerRect can be 1111 // skipped. 1112 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const; 1113 1114 // Add hit-test rects for this renderer only to the provided list. layerOffset is the offset 1115 // of this renderer within the current layer that should be used for each result. 1116 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const { }; 1117 1118 virtual InvalidationReason getPaintInvalidationReason(const RenderLayerModelObject& paintInvalidationContainer, 1119 const LayoutRect& oldPaintInvalidationRect, const LayoutPoint& oldPositionFromPaintInvalidationBacking, 1120 const LayoutRect& newPaintInvalidationRect, const LayoutPoint& newPositionFromPaintInvalidationBacking); 1121 virtual void incrementallyInvalidatePaint(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect& oldBounds, const LayoutRect& newBounds, const LayoutPoint& positionFromPaintInvalidationBacking); 1122 void fullyInvalidatePaint(const RenderLayerModelObject& paintInvalidationContainer, InvalidationReason, const LayoutRect& oldBounds, const LayoutRect& newBounds); 1123 1124 #if ENABLE(ASSERT) 1125 virtual bool paintInvalidationStateIsDirty() const 1126 { 1127 return layoutDidGetCalled() || shouldDoFullPaintInvalidation() || shouldDoFullPaintInvalidationIfSelfPaintingLayer() 1128 || onlyNeededPositionedMovementLayout() || neededLayoutBecauseOfChildren() || mayNeedPaintInvalidation(); 1129 } 1130 #endif 1131 1132 virtual void invalidatePaintOfSubtreesIfNeeded(const PaintInvalidationState& childPaintInvalidationState); 1133 virtual InvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&, const RenderLayerModelObject& paintInvalidationContainer); 1134 1135 private: 1136 void invalidatePaintIncludingNonCompositingDescendantsInternal(const RenderLayerModelObject* repaintContainer); 1137 1138 const RenderLayerModelObject* enclosingCompositedContainer() const; 1139 1140 RenderFlowThread* locateFlowThreadContainingBlock() const; 1141 void removeFromRenderFlowThread(); 1142 void removeFromRenderFlowThreadRecursive(RenderFlowThread*); 1143 1144 bool hasImmediateNonWhitespaceTextChildOrPropertiesDependentOnColor() const; 1145 1146 RenderStyle* cachedFirstLineStyle() const; 1147 StyleDifference adjustStyleDifference(StyleDifference) const; 1148 1149 Color selectionColor(int colorProperty) const; 1150 1151 void removeShapeImageClient(ShapeValue*); 1152 1153 #if ENABLE(ASSERT) 1154 void checkBlockPositionedObjectsNeedLayout(); 1155 #endif 1156 const char* invalidationReasonToString(InvalidationReason) const; 1157 1158 void markContainingBlockChainForPaintInvalidation() 1159 { 1160 for (RenderObject* container = this->container(); container && !container->shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState(); container = container->container()) 1161 container->setMayNeedPaintInvalidation(true); 1162 } 1163 1164 static bool isAllowedToModifyRenderTreeStructure(Document&); 1165 1166 RefPtr<RenderStyle> m_style; 1167 1168 RawPtrWillBeMember<Node> m_node; 1169 1170 RawPtrWillBeMember<RenderObject> m_parent; 1171 RawPtrWillBeMember<RenderObject> m_previous; 1172 RawPtrWillBeMember<RenderObject> m_next; 1173 1174 #if ENABLE(ASSERT) 1175 unsigned m_hasAXObject : 1; 1176 unsigned m_setNeedsLayoutForbidden : 1; 1177 #if ENABLE(OILPAN) 1178 protected: 1179 unsigned m_didCallDestroy : 1; 1180 private: 1181 #endif 1182 #endif 1183 1184 #define ADD_BOOLEAN_BITFIELD(name, Name) \ 1185 private:\ 1186 unsigned m_##name : 1;\ 1187 public:\ 1188 bool name() const { return m_##name; }\ 1189 void set##Name(bool name) { m_##name = name; }\ 1190 1191 class RenderObjectBitfields { 1192 enum PositionedState { 1193 IsStaticallyPositioned = 0, 1194 IsRelativelyPositioned = 1, 1195 IsOutOfFlowPositioned = 2, 1196 }; 1197 1198 public: 1199 RenderObjectBitfields(Node* node) 1200 : m_selfNeedsLayout(false) 1201 , m_shouldDoFullPaintInvalidation(false) 1202 , m_shouldInvalidateOverflowForPaint(false) 1203 , m_shouldDoFullPaintInvalidationIfSelfPaintingLayer(false) 1204 // FIXME: We should remove mayNeedPaintInvalidation once we are able to 1205 // use the other layout flags to detect the same cases. crbug.com/370118 1206 , m_mayNeedPaintInvalidation(false) 1207 , m_onlyNeededPositionedMovementLayout(false) 1208 , m_neededLayoutBecauseOfChildren(false) 1209 , m_needsPositionedMovementLayout(false) 1210 , m_normalChildNeedsLayout(false) 1211 , m_posChildNeedsLayout(false) 1212 , m_needsSimplifiedNormalFlowLayout(false) 1213 , m_preferredLogicalWidthsDirty(false) 1214 , m_floating(false) 1215 , m_selfNeedsOverflowRecalcAfterStyleChange(false) 1216 , m_childNeedsOverflowRecalcAfterStyleChange(false) 1217 , m_isAnonymous(!node) 1218 , m_isText(false) 1219 , m_isBox(false) 1220 , m_isInline(true) 1221 , m_isReplaced(false) 1222 , m_horizontalWritingMode(true) 1223 , m_isDragging(false) 1224 , m_hasLayer(false) 1225 , m_hasOverflowClip(false) 1226 , m_hasTransform(false) 1227 , m_hasReflection(false) 1228 , m_hasCounterNodeMap(false) 1229 , m_everHadLayout(false) 1230 , m_ancestorLineBoxDirty(false) 1231 , m_layoutDidGetCalled(false) 1232 , m_hasPendingResourceUpdate(false) 1233 , m_childrenInline(false) 1234 , m_hasColumns(false) 1235 , m_alwaysCreateLineBoxesForRenderInline(false) 1236 , m_positionedState(IsStaticallyPositioned) 1237 , m_selectionState(SelectionNone) 1238 , m_flowThreadState(NotInsideFlowThread) 1239 , m_boxDecorationBackgroundState(NoBoxDecorationBackground) 1240 { 1241 } 1242 1243 // 32 bits have been used in the first word, and 11 in the second. 1244 ADD_BOOLEAN_BITFIELD(selfNeedsLayout, SelfNeedsLayout); 1245 ADD_BOOLEAN_BITFIELD(shouldDoFullPaintInvalidation, ShouldDoFullPaintInvalidation); 1246 ADD_BOOLEAN_BITFIELD(shouldInvalidateOverflowForPaint, ShouldInvalidateOverflowForPaint); 1247 ADD_BOOLEAN_BITFIELD(shouldDoFullPaintInvalidationIfSelfPaintingLayer, ShouldDoFullPaintInvalidationIfSelfPaintingLayer); 1248 ADD_BOOLEAN_BITFIELD(mayNeedPaintInvalidation, MayNeedPaintInvalidation); 1249 ADD_BOOLEAN_BITFIELD(onlyNeededPositionedMovementLayout, OnlyNeededPositionedMovementLayout); 1250 ADD_BOOLEAN_BITFIELD(neededLayoutBecauseOfChildren, NeededLayoutBecauseOfChildren); 1251 ADD_BOOLEAN_BITFIELD(needsPositionedMovementLayout, NeedsPositionedMovementLayout); 1252 ADD_BOOLEAN_BITFIELD(normalChildNeedsLayout, NormalChildNeedsLayout); 1253 ADD_BOOLEAN_BITFIELD(posChildNeedsLayout, PosChildNeedsLayout); 1254 ADD_BOOLEAN_BITFIELD(needsSimplifiedNormalFlowLayout, NeedsSimplifiedNormalFlowLayout); 1255 ADD_BOOLEAN_BITFIELD(preferredLogicalWidthsDirty, PreferredLogicalWidthsDirty); 1256 ADD_BOOLEAN_BITFIELD(floating, Floating); 1257 ADD_BOOLEAN_BITFIELD(selfNeedsOverflowRecalcAfterStyleChange, SelfNeedsOverflowRecalcAfterStyleChange); 1258 ADD_BOOLEAN_BITFIELD(childNeedsOverflowRecalcAfterStyleChange, ChildNeedsOverflowRecalcAfterStyleChange); 1259 1260 ADD_BOOLEAN_BITFIELD(isAnonymous, IsAnonymous); 1261 ADD_BOOLEAN_BITFIELD(isText, IsText); 1262 ADD_BOOLEAN_BITFIELD(isBox, IsBox); 1263 ADD_BOOLEAN_BITFIELD(isInline, IsInline); 1264 ADD_BOOLEAN_BITFIELD(isReplaced, IsReplaced); 1265 ADD_BOOLEAN_BITFIELD(horizontalWritingMode, HorizontalWritingMode); 1266 ADD_BOOLEAN_BITFIELD(isDragging, IsDragging); 1267 1268 ADD_BOOLEAN_BITFIELD(hasLayer, HasLayer); 1269 ADD_BOOLEAN_BITFIELD(hasOverflowClip, HasOverflowClip); // Set in the case of overflow:auto/scroll/hidden 1270 ADD_BOOLEAN_BITFIELD(hasTransform, HasTransform); 1271 ADD_BOOLEAN_BITFIELD(hasReflection, HasReflection); 1272 1273 ADD_BOOLEAN_BITFIELD(hasCounterNodeMap, HasCounterNodeMap); 1274 ADD_BOOLEAN_BITFIELD(everHadLayout, EverHadLayout); 1275 ADD_BOOLEAN_BITFIELD(ancestorLineBoxDirty, AncestorLineBoxDirty); 1276 1277 ADD_BOOLEAN_BITFIELD(layoutDidGetCalled, LayoutDidGetCalled); 1278 1279 ADD_BOOLEAN_BITFIELD(hasPendingResourceUpdate, HasPendingResourceUpdate); 1280 1281 // from RenderBlock 1282 ADD_BOOLEAN_BITFIELD(childrenInline, ChildrenInline); 1283 ADD_BOOLEAN_BITFIELD(hasColumns, HasColumns); 1284 1285 // from RenderInline 1286 ADD_BOOLEAN_BITFIELD(alwaysCreateLineBoxesForRenderInline, AlwaysCreateLineBoxesForRenderInline); 1287 1288 private: 1289 unsigned m_positionedState : 2; // PositionedState 1290 unsigned m_selectionState : 3; // SelectionState 1291 unsigned m_flowThreadState : 2; // FlowThreadState 1292 unsigned m_boxDecorationBackgroundState : 2; // BoxDecorationBackgroundState 1293 1294 public: 1295 bool isOutOfFlowPositioned() const { return m_positionedState == IsOutOfFlowPositioned; } 1296 bool isRelPositioned() const { return m_positionedState == IsRelativelyPositioned; } 1297 bool isPositioned() const { return m_positionedState != IsStaticallyPositioned; } 1298 1299 void setPositionedState(int positionState) 1300 { 1301 // This mask maps FixedPosition and AbsolutePosition to IsOutOfFlowPositioned, saving one bit. 1302 m_positionedState = static_cast<PositionedState>(positionState & 0x3); 1303 } 1304 void clearPositionedState() { m_positionedState = StaticPosition; } 1305 1306 ALWAYS_INLINE SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); } 1307 ALWAYS_INLINE void setSelectionState(SelectionState selectionState) { m_selectionState = selectionState; } 1308 1309 ALWAYS_INLINE FlowThreadState flowThreadState() const { return static_cast<FlowThreadState>(m_flowThreadState); } 1310 ALWAYS_INLINE void setFlowThreadState(FlowThreadState flowThreadState) { m_flowThreadState = flowThreadState; } 1311 1312 ALWAYS_INLINE BoxDecorationBackgroundState boxDecorationBackgroundState() const { return static_cast<BoxDecorationBackgroundState>(m_boxDecorationBackgroundState); } 1313 ALWAYS_INLINE void setBoxDecorationBackgroundState(BoxDecorationBackgroundState s) { m_boxDecorationBackgroundState = s; } 1314 }; 1315 1316 #undef ADD_BOOLEAN_BITFIELD 1317 1318 RenderObjectBitfields m_bitfields; 1319 1320 void setSelfNeedsLayout(bool b) { m_bitfields.setSelfNeedsLayout(b); } 1321 void setNeedsPositionedMovementLayout(bool b) { m_bitfields.setNeedsPositionedMovementLayout(b); } 1322 void setNormalChildNeedsLayout(bool b) { m_bitfields.setNormalChildNeedsLayout(b); } 1323 void setPosChildNeedsLayout(bool b) { m_bitfields.setPosChildNeedsLayout(b); } 1324 void setNeedsSimplifiedNormalFlowLayout(bool b) { m_bitfields.setNeedsSimplifiedNormalFlowLayout(b); } 1325 void setIsDragging(bool b) { m_bitfields.setIsDragging(b); } 1326 void setEverHadLayout(bool b) { m_bitfields.setEverHadLayout(b); } 1327 void setShouldInvalidateOverflowForPaint(bool b) { m_bitfields.setShouldInvalidateOverflowForPaint(b); } 1328 void setSelfNeedsOverflowRecalcAfterStyleChange(bool b) { m_bitfields.setSelfNeedsOverflowRecalcAfterStyleChange(b); } 1329 void setChildNeedsOverflowRecalcAfterStyleChange(bool b) { m_bitfields.setChildNeedsOverflowRecalcAfterStyleChange(b); } 1330 1331 private: 1332 // Store state between styleWillChange and styleDidChange 1333 static bool s_affectsParentBlock; 1334 1335 // This stores the paint invalidation rect from the previous layout. 1336 LayoutRect m_previousPaintInvalidationRect; 1337 1338 // This stores the position in the paint invalidation backing's coordinate. 1339 // It is used to detect renderer shifts that forces a full invalidation. 1340 LayoutPoint m_previousPositionFromPaintInvalidationBacking; 1341 1342 static unsigned s_instanceCount; 1343 }; 1344 1345 // FIXME: remove this once the render object lifecycle ASSERTS are no longer hit. 1346 class DeprecatedDisableModifyRenderTreeStructureAsserts { 1347 WTF_MAKE_NONCOPYABLE(DeprecatedDisableModifyRenderTreeStructureAsserts); 1348 public: 1349 DeprecatedDisableModifyRenderTreeStructureAsserts(); 1350 1351 static bool canModifyRenderTreeStateInAnyState(); 1352 1353 private: 1354 TemporaryChange<bool> m_disabler; 1355 }; 1356 1357 // Allow equality comparisons of RenderObjects by reference or pointer, interchangeably. 1358 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(RenderObject) 1359 1360 inline bool RenderObject::documentBeingDestroyed() const 1361 { 1362 return document().lifecycle().state() >= DocumentLifecycle::Stopping; 1363 } 1364 1365 inline bool RenderObject::isBeforeContent() const 1366 { 1367 if (style()->styleType() != BEFORE) 1368 return false; 1369 // Text nodes don't have their own styles, so ignore the style on a text node. 1370 if (isText() && !isBR()) 1371 return false; 1372 return true; 1373 } 1374 1375 inline bool RenderObject::isAfterContent() const 1376 { 1377 if (style()->styleType() != AFTER) 1378 return false; 1379 // Text nodes don't have their own styles, so ignore the style on a text node. 1380 if (isText() && !isBR()) 1381 return false; 1382 return true; 1383 } 1384 1385 inline bool RenderObject::isBeforeOrAfterContent() const 1386 { 1387 return isBeforeContent() || isAfterContent(); 1388 } 1389 1390 // setNeedsLayout() won't cause full paint invalidations as 1391 // setNeedsLayoutAndFullPaintInvalidation() does. Otherwise the two methods are identical. 1392 inline void RenderObject::setNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter) 1393 { 1394 TRACE_EVENT_INSTANT1( 1395 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking"), 1396 "LayoutInvalidationTracking", 1397 "data", 1398 InspectorLayoutInvalidationTrackingEvent::data(this)); 1399 ASSERT(!isSetNeedsLayoutForbidden()); 1400 bool alreadyNeededLayout = m_bitfields.selfNeedsLayout(); 1401 setSelfNeedsLayout(true); 1402 if (!alreadyNeededLayout) { 1403 if (markParents == MarkContainingBlockChain && (!layouter || layouter->root() != this)) 1404 markContainingBlocksForLayout(true, 0, layouter); 1405 } 1406 } 1407 1408 inline void RenderObject::setNeedsLayoutAndFullPaintInvalidation(MarkingBehavior markParents, SubtreeLayoutScope* layouter) 1409 { 1410 setNeedsLayout(markParents, layouter); 1411 setShouldDoFullPaintInvalidation(true); 1412 } 1413 1414 inline void RenderObject::clearNeedsLayout() 1415 { 1416 setOnlyNeededPositionedMovementLayout(needsPositionedMovementLayoutOnly()); 1417 setNeededLayoutBecauseOfChildren(needsLayoutBecauseOfChildren()); 1418 setLayoutDidGetCalled(true); 1419 setSelfNeedsLayout(false); 1420 setEverHadLayout(true); 1421 setPosChildNeedsLayout(false); 1422 setNeedsSimplifiedNormalFlowLayout(false); 1423 setNormalChildNeedsLayout(false); 1424 setNeedsPositionedMovementLayout(false); 1425 setAncestorLineBoxDirty(false); 1426 #if ENABLE(ASSERT) 1427 checkBlockPositionedObjectsNeedLayout(); 1428 #endif 1429 } 1430 1431 inline void RenderObject::setChildNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter) 1432 { 1433 ASSERT(!isSetNeedsLayoutForbidden()); 1434 bool alreadyNeededLayout = normalChildNeedsLayout(); 1435 setNormalChildNeedsLayout(true); 1436 // FIXME: Replace MarkOnlyThis with the SubtreeLayoutScope code path and remove the MarkingBehavior argument entirely. 1437 if (!alreadyNeededLayout && markParents == MarkContainingBlockChain && (!layouter || layouter->root() != this)) 1438 markContainingBlocksForLayout(true, 0, layouter); 1439 } 1440 1441 inline void RenderObject::setNeedsPositionedMovementLayout() 1442 { 1443 bool alreadyNeededLayout = needsPositionedMovementLayout(); 1444 setNeedsPositionedMovementLayout(true); 1445 ASSERT(!isSetNeedsLayoutForbidden()); 1446 if (!alreadyNeededLayout) 1447 markContainingBlocksForLayout(); 1448 } 1449 1450 inline bool RenderObject::preservesNewline() const 1451 { 1452 if (isSVGInlineText()) 1453 return false; 1454 1455 return style()->preserveNewline(); 1456 } 1457 1458 inline bool RenderObject::layerCreationAllowedForSubtree() const 1459 { 1460 RenderObject* parentRenderer = parent(); 1461 while (parentRenderer) { 1462 if (parentRenderer->isSVGHiddenContainer()) 1463 return false; 1464 parentRenderer = parentRenderer->parent(); 1465 } 1466 1467 return true; 1468 } 1469 1470 inline void RenderObject::setSelectionStateIfNeeded(SelectionState state) 1471 { 1472 if (selectionState() == state) 1473 return; 1474 1475 setSelectionState(state); 1476 } 1477 1478 inline void RenderObject::setHasBoxDecorationBackground(bool b) 1479 { 1480 if (!b) { 1481 m_bitfields.setBoxDecorationBackgroundState(NoBoxDecorationBackground); 1482 return; 1483 } 1484 if (hasBoxDecorationBackground()) 1485 return; 1486 m_bitfields.setBoxDecorationBackgroundState(HasBoxDecorationBackgroundObscurationStatusInvalid); 1487 } 1488 1489 inline void RenderObject::invalidateBackgroundObscurationStatus() 1490 { 1491 if (!hasBoxDecorationBackground()) 1492 return; 1493 m_bitfields.setBoxDecorationBackgroundState(HasBoxDecorationBackgroundObscurationStatusInvalid); 1494 } 1495 1496 inline bool RenderObject::boxDecorationBackgroundIsKnownToBeObscured() 1497 { 1498 if (m_bitfields.boxDecorationBackgroundState() == HasBoxDecorationBackgroundObscurationStatusInvalid) { 1499 BoxDecorationBackgroundState state = computeBackgroundIsKnownToBeObscured() ? HasBoxDecorationBackgroundKnownToBeObscured : HasBoxDecorationBackgroundMayBeVisible; 1500 m_bitfields.setBoxDecorationBackgroundState(state); 1501 } 1502 return m_bitfields.boxDecorationBackgroundState() == HasBoxDecorationBackgroundKnownToBeObscured; 1503 } 1504 1505 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering) 1506 { 1507 if (!has3DRendering) 1508 matrix.makeAffine(); 1509 } 1510 1511 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer) 1512 { 1513 return adjustForAbsoluteZoom(value, renderer->style()); 1514 } 1515 1516 inline double adjustDoubleForAbsoluteZoom(double value, RenderObject& renderer) 1517 { 1518 ASSERT(renderer.style()); 1519 return adjustDoubleForAbsoluteZoom(value, *renderer.style()); 1520 } 1521 1522 inline LayoutUnit adjustLayoutUnitForAbsoluteZoom(LayoutUnit value, RenderObject& renderer) 1523 { 1524 ASSERT(renderer.style()); 1525 return adjustLayoutUnitForAbsoluteZoom(value, *renderer.style()); 1526 } 1527 1528 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject& renderer) 1529 { 1530 float zoom = renderer.style()->effectiveZoom(); 1531 if (zoom != 1) 1532 quad.scale(1 / zoom, 1 / zoom); 1533 } 1534 1535 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject& renderer) 1536 { 1537 float zoom = renderer.style()->effectiveZoom(); 1538 if (zoom != 1) 1539 rect.scale(1 / zoom, 1 / zoom); 1540 } 1541 1542 inline double adjustScrollForAbsoluteZoom(int value, RenderObject& renderer) 1543 { 1544 ASSERT(renderer.style()); 1545 return adjustScrollForAbsoluteZoom(value, *renderer.style()); 1546 } 1547 1548 #define DEFINE_RENDER_OBJECT_TYPE_CASTS(thisType, predicate) \ 1549 DEFINE_TYPE_CASTS(thisType, RenderObject, object, object->predicate, object.predicate) 1550 1551 } // namespace blink 1552 1553 #ifndef NDEBUG 1554 // Outside the WebCore namespace for ease of invocation from gdb. 1555 void showTree(const blink::RenderObject*); 1556 void showLineTree(const blink::RenderObject*); 1557 void showRenderTree(const blink::RenderObject* object1); 1558 // We don't make object2 an optional parameter so that showRenderTree 1559 // can be called from gdb easily. 1560 void showRenderTree(const blink::RenderObject* object1, const blink::RenderObject* object2); 1561 1562 #endif 1563 1564 #endif // RenderObject_h 1565