2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * (C) 2004 Allan Sandfeld Jensen (kde@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.
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.
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.
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.
26 #ifndef RenderObject_h
27 #define RenderObject_h
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"
53 class AffineTransform;
56 class HitTestLocation;
61 class PositionWithAffinity;
62 class PseudoStyleRequest;
63 class RenderBoxModelObject;
65 class RenderFlowThread;
66 class RenderGeometryMap;
68 class RenderLayerModelObject;
74 enum CursorDirective {
75 SetCursorBasedOnStyle,
87 HitTestBlockBackground,
88 HitTestChildBlockBackground,
89 HitTestChildBlockBackgrounds,
94 enum MarkingBehavior {
96 MarkContainingBlockChain,
99 enum MapCoordinatesMode {
101 UseTransforms = 1 << 1,
102 ApplyContainerFlip = 1 << 2,
103 TraverseDocumentBoundaries = 1 << 3,
105 typedef unsigned MapCoordinatesFlags;
107 enum InvalidationReason {
109 InvalidationIncremental,
111 InvalidationBorderFitLines,
112 InvalidationBorderBoxChange,
113 InvalidationBoundsChange,
114 InvalidationLocationChange,
115 InvalidationBecameVisible,
116 InvalidationBecameInvisible,
118 InvalidationSelection,
120 InvalidationRendererRemoval,
121 InvalidationPaintRectangle
124 const int caretWidth = 1;
126 struct AnnotatedRegionValue {
127 bool operator==(const AnnotatedRegionValue& o) const
129 return draggable == o.draggable && bounds == o.bounds;
136 typedef WTF::HashMap<const RenderLayer*, Vector<LayoutRect> > LayerHitTestRects;
139 const int showTreeCharacterOffset = 39;
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);
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*);
157 virtual const char* renderName() const = 0;
159 String debugName() const;
161 RenderObject* parent() const { return m_parent; }
162 bool isDescendantOf(const RenderObject*) const;
164 RenderObject* previousSibling() const { return m_previous; }
165 RenderObject* nextSibling() const { return m_next; }
167 RenderObject* slowFirstChild() const
169 if (const RenderObjectChildList* children = virtualChildren())
170 return children->firstChild();
173 RenderObject* slowLastChild() const
175 if (const RenderObjectChildList* children = virtualChildren())
176 return children->lastChild();
180 virtual RenderObjectChildList* virtualChildren() { return 0; }
181 virtual const RenderObjectChildList* virtualChildren() const { return 0; }
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;
191 RenderObject* lastLeafChild() const;
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);
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);
205 // Convenience function for getting to the nearest enclosing box of a RenderObject.
206 RenderBox* enclosingBox() const;
207 RenderBoxModelObject* enclosingBoxModelObject() const;
209 RenderBox* enclosingScrollableBox() const;
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
215 if (flowThreadState() == NotInsideFlowThread)
217 return locateFlowThreadContainingBlock();
221 void setHasAXObject(bool flag) { m_hasAXObject = flag; }
222 bool hasAXObject() const { return m_hasAXObject; }
224 // Helper class forbidding calls to setNeedsLayout() during its lifetime.
225 class SetLayoutNeededForbiddenScope {
227 explicit SetLayoutNeededForbiddenScope(RenderObject&);
228 ~SetLayoutNeededForbiddenScope();
230 RenderObject& m_renderObject;
231 bool m_preexistingForbidden;
234 void assertRendererLaidOut() const
238 showRenderTreeForThis();
240 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout());
243 void assertSubtreeIsLaidOut() const
245 for (const RenderObject* renderer = this; renderer; renderer = renderer->nextInPreOrder())
246 renderer->assertRendererLaidOut();
249 void assertRendererClearedPaintInvalidationState() const
252 if (paintInvalidationStateIsDirty()) {
253 showRenderTreeForThis();
254 ASSERT_NOT_REACHED();
259 void assertSubtreeClearedPaintInvalidationState() const
261 for (const RenderObject* renderer = this; renderer; renderer = renderer->nextInPreOrder())
262 renderer->assertRendererClearedPaintInvalidationState();
267 bool skipInvalidationWhenLaidOutChildren() const;
269 // FIXME: This could be used when changing the size of a renderer without children to skip some invalidations.
270 bool rendererHasNoBoxEffect() const
272 return !style()->hasVisualOverflowingEffect() && !style()->hasBorder() && !style()->hasBackground();
275 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
277 virtual RenderBlock* firstLineBlock() const;
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();
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 //////////////////////////////////////////
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)
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);
312 //////////////////////////////////////////
315 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; }
316 void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; }
319 void addAbsoluteRectForLayer(LayoutRect& result);
320 bool requiresAnonymousTableWrappers(const RenderObject*) const;
322 // Gets pseudoStyle from Shadow host(in case of input elements)
323 // or from Parent element.
324 PassRefPtr<RenderStyle> getUncachedPseudoStyleFromParentOrShadowHost() const;
328 void showTreeForThis() const;
329 void showRenderTreeForThis() const;
330 void showLineTreeForThis() const;
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;
339 static RenderObject* createObject(Element*, RenderStyle*);
340 static unsigned instanceCount() { return s_instanceCount; }
343 // RenderObjects are allocated out of the rendering partition.
344 void* operator new(size_t);
345 void operator delete(void*);
349 bool isPseudoElement() const { return node() && node()->isPseudoElement(); }
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; }
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); }
411 bool isLegend() const;
413 bool isTablePart() const { return isTableCell() || isRenderTableCol() || isTableCaption() || isTableRow() || isTableSection(); }
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(); }
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(); }
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); }
429 bool alwaysCreateLineBoxesForRenderInline() const
431 ASSERT(isRenderInline());
432 return m_bitfields.alwaysCreateLineBoxesForRenderInline();
434 void setAlwaysCreateLineBoxesForRenderInline(bool alwaysCreateLineBoxes)
436 ASSERT(isRenderInline());
437 m_bitfields.setAlwaysCreateLineBoxesForRenderInline(alwaysCreateLineBoxes);
440 bool ancestorLineBoxDirty() const { return m_bitfields.ancestorLineBoxDirty(); }
441 void setAncestorLineBoxDirty(bool value = true)
443 m_bitfields.setAncestorLineBoxDirty(value);
445 setNeedsLayoutAndFullPaintInvalidation();
448 enum FlowThreadState {
449 NotInsideFlowThread = 0,
450 InsideOutOfFlowThread = 1,
451 InsideInFlowThread = 2,
454 void setFlowThreadStateIncludingDescendants(FlowThreadState);
456 FlowThreadState flowThreadState() const { return m_bitfields.flowThreadState(); }
457 void setFlowThreadState(FlowThreadState state) { m_bitfields.setFlowThreadState(state); }
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; }
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();
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;
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;
498 // This only returns the transform="" value from the element
499 // most callsites want localToParentTransform() instead.
500 virtual AffineTransform localTransform() const;
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;
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);
511 virtual bool canHaveWhitespaceChildren() const
513 if (isTable() || isTableRow() || isTableSection() || isRenderTableCol() || isFrameSet() || isFlexibleBox() || isRenderGrid())
518 bool isAnonymous() const { return m_bitfields.isAnonymous(); }
519 bool isAnonymousBlock() const
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();
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; }
535 bool isFloating() const { return m_bitfields.floating(); }
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(); }
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(); }
548 bool hasLayer() const { return m_bitfields.hasLayer(); }
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,
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;
569 bool needsLayoutBecauseOfChildren() const { return needsLayout() && !selfNeedsLayout() && !needsPositionedMovementLayout() && !needsSimplifiedNormalFlowLayout(); }
571 bool needsLayout() const
573 return m_bitfields.selfNeedsLayout() || m_bitfields.normalChildNeedsLayout() || m_bitfields.posChildNeedsLayout()
574 || m_bitfields.needsSimplifiedNormalFlowLayout() || m_bitfields.needsPositionedMovementLayout();
577 bool selfNeedsLayout() const { return m_bitfields.selfNeedsLayout(); }
578 bool needsPositionedMovementLayout() const { return m_bitfields.needsPositionedMovementLayout(); }
579 bool needsPositionedMovementLayoutOnly() const
581 return m_bitfields.needsPositionedMovementLayout() && !m_bitfields.selfNeedsLayout() && !m_bitfields.normalChildNeedsLayout()
582 && !m_bitfields.posChildNeedsLayout() && !m_bitfields.needsSimplifiedNormalFlowLayout();
585 bool posChildNeedsLayout() const { return m_bitfields.posChildNeedsLayout(); }
586 bool needsSimplifiedNormalFlowLayout() const { return m_bitfields.needsSimplifiedNormalFlowLayout(); }
587 bool normalChildNeedsLayout() const { return m_bitfields.normalChildNeedsLayout(); }
589 bool preferredLogicalWidthsDirty() const { return m_bitfields.preferredLogicalWidthsDirty(); }
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(); }
595 bool isSelectionBorder() const;
597 bool hasClip() const { return isOutOfFlowPositioned() && !style()->hasAutoClip(); }
598 bool hasOverflowClip() const { return m_bitfields.hasOverflowClip(); }
599 bool hasClipOrOverflowClip() const { return hasClip() || hasOverflowClip(); }
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; }
606 bool hasFilter() const { return style() && style()->hasFilter(); }
608 bool hasBlendMode() const;
610 bool hasShapeOutside() const { return style() && style()->shapeOutside(); }
612 inline bool preservesNewline() const;
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;
619 virtual void updateDragState(bool dragOn);
621 RenderView* view() const { return document().renderView(); };
622 FrameView* frameView() const { return document().view(); };
624 bool isRooted() const;
628 return isAnonymous() ? 0 : m_node.get();
631 Node* nonPseudoNode() const
633 return isPseudoElement() ? 0 : node();
636 // FIXME: Why does RenderWidget need this?
637 void clearNode() { m_node = nullptr; }
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(); }
644 Document& document() const { return m_node->document(); }
645 LocalFrame* frame() const { return document().frame(); }
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;
653 virtual RenderObject* hoverAncestor() const { return parent(); }
655 Element* offsetParent() const;
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();
667 void setNeedsLayoutAndPrefWidthsRecalc()
670 setPreferredLogicalWidthsDirty();
672 void setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation()
674 setNeedsLayoutAndFullPaintInvalidation();
675 setPreferredLogicalWidthsDirty();
678 void setPositionState(EPosition position)
680 ASSERT((position != AbsolutePosition && position != FixedPosition) || isBox());
681 m_bitfields.setPositionedState(position);
683 void clearPositionedState() { m_bitfields.clearPositionedState(); }
685 void setFloating(bool isFloating) { m_bitfields.setFloating(isFloating); }
686 void setInline(bool isInline) { m_bitfields.setIsInline(isInline); }
688 void setHasBoxDecorationBackground(bool);
689 void invalidateBackgroundObscurationStatus();
690 virtual bool computeBackgroundIsKnownToBeObscured() { return false; }
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); }
701 void scheduleRelayout();
703 void updateFillImages(const FillLayer* oldLayers, const FillLayer& newLayers);
704 void updateImage(StyleImage*, StyleImage*);
705 void updateShapeImage(const ShapeValue*, const ShapeValue*);
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);
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(); }
717 /* This function performs a layout only if one is needed. */
718 void layoutIfNeeded() { if (needsLayout()) layout(); }
721 void forceChildLayout();
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() { }
727 virtual void addAnnotatedRegions(Vector<AnnotatedRegionValue>&);
728 void collectAnnotatedRegions(Vector<AnnotatedRegionValue>&);
730 CompositingState compositingState() const;
731 virtual CompositingReasons additionalCompositingReasons() const;
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);
737 virtual PositionWithAffinity positionForPoint(const LayoutPoint&);
738 PositionWithAffinity createPositionWithAffinity(int offset, EAffinity);
739 PositionWithAffinity createPositionWithAffinity(const Position&);
741 virtual void dirtyLinesFromChangedChild(RenderObject*);
743 // Set the style of the object and update the state of the object accordingly.
744 void setStyle(PassRefPtr<RenderStyle>);
746 // Set the style of the object if it's generated content.
747 void setPseudoStyle(PassRefPtr<RenderStyle>);
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; }
753 // returns the containing block level element for this element.
754 RenderBlock* containingBlock() const;
756 bool canContainFixedPositionObjects() const
758 return isRenderView() || (hasTransform() && isRenderBlock()) || isSVGForeignObject();
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;
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
769 return localToContainerQuad(quad, 0, mode, wasFixed);
771 // Convert an absolute quad to local coordinates.
772 FloatQuad absoluteToLocalQuad(const FloatQuad&, MapCoordinatesFlags mode = 0) const;
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;
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);
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;
787 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint&) const { }
789 IntRect absoluteBoundingBoxRect() const;
790 // FIXME: This function should go away eventually
791 IntRect absoluteBoundingBoxRectIgnoringTransforms() const;
793 // Build an array of quads in absolute coords for line boxes
794 virtual void absoluteQuads(Vector<FloatQuad>&, bool* /*wasFixed*/ = 0) const { }
796 virtual void absoluteFocusRingQuads(Vector<FloatQuad>&);
798 static FloatRect absoluteBoundingBoxRectForRange(const Range*);
800 // the rect that will be painted if this object is passed as the paintingRoot
801 LayoutRect paintingRootRect(LayoutRect& topLevelRect);
803 virtual LayoutUnit minPreferredLogicalWidth() const { return 0; }
804 virtual LayoutUnit maxPreferredLogicalWidth() const { return 0; }
806 RenderStyle* style() const { return m_style.get(); }
808 /* The two following methods are inlined in RenderObjectInlines.h */
809 RenderStyle* firstLineStyle() const;
810 RenderStyle* style(bool firstLine) const;
812 inline Color resolveColor(const RenderStyle* styleToUse, int colorProperty) const
814 return styleToUse->visitedDependentColor(colorProperty);
817 inline Color resolveColor(int colorProperty) const
819 return style()->visitedDependentColor(colorProperty);
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;
826 virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
828 struct AppliedTextDecoration {
830 TextDecorationStyle style;
831 AppliedTextDecoration() : color(Color::transparent), style(TextDecorationStyleSolid) { }
834 void getTextDecorations(unsigned decorations, AppliedTextDecoration& underline, AppliedTextDecoration& overline, AppliedTextDecoration& linethrough, bool quirksMode = false, bool firstlineStyle = false);
836 void setHadPaintInvalidation();
837 bool hadPaintInvalidation() const;
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'
842 const RenderLayerModelObject* containerForPaintInvalidation() const;
843 const RenderLayerModelObject* adjustCompositedContainerForSpecialAncestors(const RenderLayerModelObject* paintInvalidationContainer) const;
844 bool isPaintInvalidationContainer() const;
846 LayoutRect computePaintInvalidationRect()
848 return computePaintInvalidationRect(containerForPaintInvalidation());
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;
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;
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;
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;
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&);
870 virtual void invalidatePaintForOverflow();
871 void invalidatePaintForOverflowIfNeeded();
873 void invalidatePaintIncludingNonCompositingDescendants();
875 bool checkForPaintInvalidation() const;
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;
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;
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(); }
893 virtual unsigned length() const { return 1; }
895 bool isFloatingOrOutOfFlowPositioned() const { return (isFloating() || isOutOfFlowPositioned()); }
897 bool isTransparent() const { return style()->hasOpacity(); }
898 float opacity() const { return style()->opacity(); }
900 bool hasReflection() const { return m_bitfields.hasReflection(); }
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
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();
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(); }
921 virtual bool canBeSelectionLeaf() const { return false; }
922 bool hasSelectedChildren() const { return selectionState() != SelectionNone; }
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;
930 // Whether or not a given block needs to paint selection gaps.
931 virtual bool shouldPaintSelectionGaps() const { return false; }
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
939 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
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;
945 void destroyAndCleanupAnonymousWrappers();
946 virtual void destroy();
948 // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).
949 virtual bool isDeprecatedFlexibleBox() const { return false; }
951 // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flex).
952 virtual bool isFlexibleBox() const { return false; }
954 bool isFlexibleBoxIncludingDeprecated() const
956 return isFlexibleBox() || isDeprecatedFlexibleBox();
959 virtual bool isCombineText() const { return false; }
961 virtual int caretMinOffset() const;
962 virtual int caretMaxOffset() const;
964 virtual int previousOffset(int current) const;
965 virtual int previousOffsetForBackwardDeletion(int current) const;
966 virtual int nextOffset(int current) const;
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;
972 void selectionStartEnd(int& spos, int& epos) const;
974 void remove() { if (parent()) parent()->removeChild(this); }
976 bool isInert() const;
978 bool supportsTouchAction() const;
980 bool visibleToHitTestRequest(const HitTestRequest& request) const { return style()->visibility() == VISIBLE && (request.ignorePointerEventsNone() || style()->pointerEvents() != PE_NONE) && !isInert(); }
982 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE && !isInert(); }
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;
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;
993 bool shouldUseTransformFromContainer(const RenderObject* container) const;
994 void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const;
996 bool createsGroup() const { return isTransparent() || hasMask() || hasFilter() || hasBlendMode(); }
998 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const { }
1000 // Compute a list of hit-test rectangles per layer rooted at this renderer.
1001 virtual void computeLayerHitTestRects(LayerHitTestRects&) const;
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();
1006 RespectImageOrientationEnum shouldRespectImageOrientation() const;
1008 bool isRelayoutBoundaryForInspector() const;
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; }
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; }
1018 bool shouldDoFullPaintInvalidation() const { return m_bitfields.shouldDoFullPaintInvalidation(); }
1019 void setShouldDoFullPaintInvalidation(bool, MarkingBehavior = MarkContainingBlockChain);
1021 bool shouldInvalidateOverflowForPaint() const { return m_bitfields.shouldInvalidateOverflowForPaint(); }
1023 bool shouldDoFullPaintInvalidationIfSelfPaintingLayer() const { return m_bitfields.shouldDoFullPaintInvalidationIfSelfPaintingLayer(); }
1024 void setShouldDoFullPaintInvalidationIfSelfPaintingLayer(bool b)
1026 m_bitfields.setShouldDoFullPaintInvalidationIfSelfPaintingLayer(b);
1029 markContainingBlockChainForPaintInvalidation();
1032 bool onlyNeededPositionedMovementLayout() const { return m_bitfields.onlyNeededPositionedMovementLayout(); }
1033 void setOnlyNeededPositionedMovementLayout(bool b) { m_bitfields.setOnlyNeededPositionedMovementLayout(b); }
1035 virtual void clearPaintInvalidationState(const PaintInvalidationState&);
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)
1042 m_bitfields.setLayoutDidGetCalled(b);
1045 markContainingBlockChainForPaintInvalidation();
1048 bool mayNeedPaintInvalidation() const { return m_bitfields.mayNeedPaintInvalidation(); }
1049 void setMayNeedPaintInvalidation(bool b)
1051 m_bitfields.setMayNeedPaintInvalidation(b);
1053 // Make sure our parent is marked as needing invalidation.
1055 markContainingBlockChainForPaintInvalidation();
1058 bool neededLayoutBecauseOfChildren() const { return m_bitfields.neededLayoutBecauseOfChildren(); }
1059 void setNeededLayoutBecauseOfChildren(bool b) { m_bitfields.setNeededLayoutBecauseOfChildren(b); }
1061 bool shouldCheckForPaintInvalidation(const PaintInvalidationState& paintInvalidationState)
1063 return paintInvalidationState.forceCheckForPaintInvalidation() || shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState();
1066 bool shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState()
1068 return layoutDidGetCalled() || mayNeedPaintInvalidation() || shouldDoFullPaintInvalidation() || shouldDoFullPaintInvalidationIfSelfPaintingLayer();
1071 bool supportsPaintInvalidationStateCachedOffsets() const { return !hasColumns() && !hasTransform() && !hasReflection() && !style()->isFlippedBlocksWritingMode(); }
1073 void setNeedsOverflowRecalcAfterStyleChange();
1074 void markContainingBlocksForOverflowRecalc();
1076 virtual LayoutRect viewRect() const;
1079 inline bool layerCreationAllowedForSubtree() const;
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 { }
1091 void paintOutline(PaintInfo&, const LayoutRect&);
1093 void addChildFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const;
1095 void clearLayoutRootIfNeeded() const;
1096 virtual void willBeDestroyed();
1099 virtual void insertedIntoTree();
1100 virtual void willBeRemovedFromTree();
1102 void setDocumentForAnonymous(Document* document) { ASSERT(isAnonymous()); m_node = document; }
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
1112 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const;
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 { };
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);
1125 virtual bool paintInvalidationStateIsDirty() const
1127 return layoutDidGetCalled() || shouldDoFullPaintInvalidation() || shouldDoFullPaintInvalidationIfSelfPaintingLayer()
1128 || onlyNeededPositionedMovementLayout() || neededLayoutBecauseOfChildren() || mayNeedPaintInvalidation();
1132 void invalidatePaintOfSubtreesIfNeeded(const PaintInvalidationState&);
1133 virtual InvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&, const RenderLayerModelObject& paintInvalidationContainer);
1136 void invalidatePaintIncludingNonCompositingDescendantsInternal(const RenderLayerModelObject* repaintContainer);
1138 const RenderLayerModelObject* enclosingCompositedContainer() const;
1140 RenderFlowThread* locateFlowThreadContainingBlock() const;
1141 void removeFromRenderFlowThread();
1142 void removeFromRenderFlowThreadRecursive(RenderFlowThread*);
1144 bool hasImmediateNonWhitespaceTextChildOrPropertiesDependentOnColor() const;
1146 RenderStyle* cachedFirstLineStyle() const;
1147 StyleDifference adjustStyleDifference(StyleDifference) const;
1149 Color selectionColor(int colorProperty) const;
1151 void removeShapeImageClient(ShapeValue*);
1154 void checkBlockPositionedObjectsNeedLayout();
1156 const char* invalidationReasonToString(InvalidationReason) const;
1158 void markContainingBlockChainForPaintInvalidation()
1160 for (RenderObject* container = this->container(); container && !container->shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState(); container = container->container())
1161 container->setMayNeedPaintInvalidation(true);
1164 static bool isAllowedToModifyRenderTreeStructure(Document&);
1166 RefPtr<RenderStyle> m_style;
1168 RawPtrWillBeMember<Node> m_node;
1170 RawPtrWillBeMember<RenderObject> m_parent;
1171 RawPtrWillBeMember<RenderObject> m_previous;
1172 RawPtrWillBeMember<RenderObject> m_next;
1175 unsigned m_hasAXObject : 1;
1176 unsigned m_setNeedsLayoutForbidden : 1;
1179 unsigned m_didCallDestroy : 1;
1184 #define ADD_BOOLEAN_BITFIELD(name, Name) \
1186 unsigned m_##name : 1;\
1188 bool name() const { return m_##name; }\
1189 void set##Name(bool name) { m_##name = name; }\
1191 class RenderObjectBitfields {
1192 enum PositionedState {
1193 IsStaticallyPositioned = 0,
1194 IsRelativelyPositioned = 1,
1195 IsOutOfFlowPositioned = 2,
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)
1215 , m_selfNeedsOverflowRecalcAfterStyleChange(false)
1216 , m_childNeedsOverflowRecalcAfterStyleChange(false)
1217 , m_isAnonymous(!node)
1221 , m_isReplaced(false)
1222 , m_horizontalWritingMode(true)
1223 , m_isDragging(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)
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);
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);
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);
1273 ADD_BOOLEAN_BITFIELD(hasCounterNodeMap, HasCounterNodeMap);
1274 ADD_BOOLEAN_BITFIELD(everHadLayout, EverHadLayout);
1275 ADD_BOOLEAN_BITFIELD(ancestorLineBoxDirty, AncestorLineBoxDirty);
1277 ADD_BOOLEAN_BITFIELD(layoutDidGetCalled, LayoutDidGetCalled);
1279 ADD_BOOLEAN_BITFIELD(hasPendingResourceUpdate, HasPendingResourceUpdate);
1282 ADD_BOOLEAN_BITFIELD(childrenInline, ChildrenInline);
1283 ADD_BOOLEAN_BITFIELD(hasColumns, HasColumns);
1285 // from RenderInline
1286 ADD_BOOLEAN_BITFIELD(alwaysCreateLineBoxesForRenderInline, AlwaysCreateLineBoxesForRenderInline);
1289 unsigned m_positionedState : 2; // PositionedState
1290 unsigned m_selectionState : 3; // SelectionState
1291 unsigned m_flowThreadState : 2; // FlowThreadState
1292 unsigned m_boxDecorationBackgroundState : 2; // BoxDecorationBackgroundState
1295 bool isOutOfFlowPositioned() const { return m_positionedState == IsOutOfFlowPositioned; }
1296 bool isRelPositioned() const { return m_positionedState == IsRelativelyPositioned; }
1297 bool isPositioned() const { return m_positionedState != IsStaticallyPositioned; }
1299 void setPositionedState(int positionState)
1301 // This mask maps FixedPosition and AbsolutePosition to IsOutOfFlowPositioned, saving one bit.
1302 m_positionedState = static_cast<PositionedState>(positionState & 0x3);
1304 void clearPositionedState() { m_positionedState = StaticPosition; }
1306 ALWAYS_INLINE SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
1307 ALWAYS_INLINE void setSelectionState(SelectionState selectionState) { m_selectionState = selectionState; }
1309 ALWAYS_INLINE FlowThreadState flowThreadState() const { return static_cast<FlowThreadState>(m_flowThreadState); }
1310 ALWAYS_INLINE void setFlowThreadState(FlowThreadState flowThreadState) { m_flowThreadState = flowThreadState; }
1312 ALWAYS_INLINE BoxDecorationBackgroundState boxDecorationBackgroundState() const { return static_cast<BoxDecorationBackgroundState>(m_boxDecorationBackgroundState); }
1313 ALWAYS_INLINE void setBoxDecorationBackgroundState(BoxDecorationBackgroundState s) { m_boxDecorationBackgroundState = s; }
1316 #undef ADD_BOOLEAN_BITFIELD
1318 RenderObjectBitfields m_bitfields;
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); }
1332 // Store state between styleWillChange and styleDidChange
1333 static bool s_affectsParentBlock;
1335 // This stores the paint invalidation rect from the previous layout.
1336 LayoutRect m_previousPaintInvalidationRect;
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;
1342 static unsigned s_instanceCount;
1345 // FIXME: remove this once the render object lifecycle ASSERTS are no longer hit.
1346 class DeprecatedDisableModifyRenderTreeStructureAsserts {
1347 WTF_MAKE_NONCOPYABLE(DeprecatedDisableModifyRenderTreeStructureAsserts);
1349 DeprecatedDisableModifyRenderTreeStructureAsserts();
1351 static bool canModifyRenderTreeStateInAnyState();
1354 TemporaryChange<bool> m_disabler;
1357 // Allow equality comparisons of RenderObjects by reference or pointer, interchangeably.
1358 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(RenderObject)
1360 inline bool RenderObject::documentBeingDestroyed() const
1362 return document().lifecycle().state() >= DocumentLifecycle::Stopping;
1365 inline bool RenderObject::isBeforeContent() const
1367 if (style()->styleType() != BEFORE)
1369 // Text nodes don't have their own styles, so ignore the style on a text node.
1370 if (isText() && !isBR())
1375 inline bool RenderObject::isAfterContent() const
1377 if (style()->styleType() != AFTER)
1379 // Text nodes don't have their own styles, so ignore the style on a text node.
1380 if (isText() && !isBR())
1385 inline bool RenderObject::isBeforeOrAfterContent() const
1387 return isBeforeContent() || isAfterContent();
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)
1394 TRACE_EVENT_INSTANT1(
1395 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking"),
1396 "LayoutInvalidationTracking",
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);
1408 inline void RenderObject::setNeedsLayoutAndFullPaintInvalidation(MarkingBehavior markParents, SubtreeLayoutScope* layouter)
1410 setNeedsLayout(markParents, layouter);
1411 setShouldDoFullPaintInvalidation(true);
1414 inline void RenderObject::clearNeedsLayout()
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);
1427 checkBlockPositionedObjectsNeedLayout();
1431 inline void RenderObject::setChildNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter)
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);
1441 inline void RenderObject::setNeedsPositionedMovementLayout()
1443 bool alreadyNeededLayout = needsPositionedMovementLayout();
1444 setNeedsPositionedMovementLayout(true);
1445 ASSERT(!isSetNeedsLayoutForbidden());
1446 if (!alreadyNeededLayout)
1447 markContainingBlocksForLayout();
1450 inline bool RenderObject::preservesNewline() const
1452 if (isSVGInlineText())
1455 return style()->preserveNewline();
1458 inline bool RenderObject::layerCreationAllowedForSubtree() const
1460 RenderObject* parentRenderer = parent();
1461 while (parentRenderer) {
1462 if (parentRenderer->isSVGHiddenContainer())
1464 parentRenderer = parentRenderer->parent();
1470 inline void RenderObject::setSelectionStateIfNeeded(SelectionState state)
1472 if (selectionState() == state)
1475 setSelectionState(state);
1478 inline void RenderObject::setHasBoxDecorationBackground(bool b)
1481 m_bitfields.setBoxDecorationBackgroundState(NoBoxDecorationBackground);
1484 if (hasBoxDecorationBackground())
1486 m_bitfields.setBoxDecorationBackgroundState(HasBoxDecorationBackgroundObscurationStatusInvalid);
1489 inline void RenderObject::invalidateBackgroundObscurationStatus()
1491 if (!hasBoxDecorationBackground())
1493 m_bitfields.setBoxDecorationBackgroundState(HasBoxDecorationBackgroundObscurationStatusInvalid);
1496 inline bool RenderObject::boxDecorationBackgroundIsKnownToBeObscured()
1498 if (m_bitfields.boxDecorationBackgroundState() == HasBoxDecorationBackgroundObscurationStatusInvalid) {
1499 BoxDecorationBackgroundState state = computeBackgroundIsKnownToBeObscured() ? HasBoxDecorationBackgroundKnownToBeObscured : HasBoxDecorationBackgroundMayBeVisible;
1500 m_bitfields.setBoxDecorationBackgroundState(state);
1502 return m_bitfields.boxDecorationBackgroundState() == HasBoxDecorationBackgroundKnownToBeObscured;
1505 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
1507 if (!has3DRendering)
1508 matrix.makeAffine();
1511 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
1513 return adjustForAbsoluteZoom(value, renderer->style());
1516 inline double adjustDoubleForAbsoluteZoom(double value, RenderObject& renderer)
1518 ASSERT(renderer.style());
1519 return adjustDoubleForAbsoluteZoom(value, *renderer.style());
1522 inline LayoutUnit adjustLayoutUnitForAbsoluteZoom(LayoutUnit value, RenderObject& renderer)
1524 ASSERT(renderer.style());
1525 return adjustLayoutUnitForAbsoluteZoom(value, *renderer.style());
1528 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject& renderer)
1530 float zoom = renderer.style()->effectiveZoom();
1532 quad.scale(1 / zoom, 1 / zoom);
1535 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject& renderer)
1537 float zoom = renderer.style()->effectiveZoom();
1539 rect.scale(1 / zoom, 1 / zoom);
1542 inline double adjustScrollForAbsoluteZoom(int value, RenderObject& renderer)
1544 ASSERT(renderer.style());
1545 return adjustScrollForAbsoluteZoom(value, *renderer.style());
1548 #define DEFINE_RENDER_OBJECT_TYPE_CASTS(thisType, predicate) \
1549 DEFINE_TYPE_CASTS(thisType, RenderObject, object, object->predicate, object.predicate)
1551 } // namespace blink
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);
1564 #endif // RenderObject_h