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/Element.h"
30 #include "core/dom/Position.h"
31 #include "core/dom/StyleEngine.h"
32 #include "core/fetch/ImageResourceClient.h"
33 #include "core/rendering/compositing/CompositingState.h"
34 #include "core/rendering/PaintPhase.h"
35 #include "core/rendering/RenderObjectChildList.h"
36 #include "core/rendering/ScrollAlignment.h"
37 #include "core/rendering/SubtreeLayoutScope.h"
38 #include "core/rendering/compositing/CompositingTriggers.h"
39 #include "core/rendering/style/RenderStyle.h"
40 #include "core/rendering/style/StyleInheritedData.h"
41 #include "platform/geometry/FloatQuad.h"
42 #include "platform/geometry/LayoutRect.h"
43 #include "platform/graphics/CompositingReasons.h"
44 #include "platform/transforms/TransformationMatrix.h"
48 class AffineTransform;
51 class HitTestLocation;
57 class PseudoStyleRequest;
58 class RenderBoxModelObject;
61 class RenderFlowThread;
62 class RenderGeometryMap;
64 class RenderLayerModelObject;
65 class RenderSVGResourceContainer;
69 class ResourceLoadPriorityOptimizer;
74 enum CursorDirective {
75 SetCursorBasedOnStyle,
87 HitTestBlockBackground,
88 HitTestChildBlockBackground,
89 HitTestChildBlockBackgrounds,
94 // Sides used when drawing borders and outlines. The values should run clockwise from top.
102 enum MarkingBehavior {
104 MarkContainingBlockChain,
107 enum MapCoordinatesMode {
109 UseTransforms = 1 << 1,
110 ApplyContainerFlip = 1 << 2,
111 TraverseDocumentBoundaries = 1 << 3,
113 typedef unsigned MapCoordinatesFlags;
115 const int caretWidth = 1;
117 struct AnnotatedRegionValue {
118 bool operator==(const AnnotatedRegionValue& o) const
120 return draggable == o.draggable && bounds == o.bounds;
127 typedef WTF::HashMap<const RenderLayer*, Vector<LayoutRect> > LayerHitTestRects;
130 const int showTreeCharacterOffset = 39;
133 // Base class for all rendering tree objects.
134 class RenderObject : public ImageResourceClient {
135 friend class RenderBlock;
136 friend class RenderBlockFlow;
137 friend class RenderLayer; // For setParent.
138 friend class RenderLayerReflectionInfo; // For setParent
139 friend class RenderLayerScrollableArea; // For setParent.
140 friend class RenderObjectChildList;
141 WTF_MAKE_NONCOPYABLE(RenderObject);
143 // Anonymous objects should pass the document as their node, and they will then automatically be
144 // marked as anonymous in the constructor.
145 explicit RenderObject(Node*);
146 virtual ~RenderObject();
148 virtual const char* renderName() const = 0;
150 String debugName() const;
152 RenderObject* parent() const { return m_parent; }
153 bool isDescendantOf(const RenderObject*) const;
155 RenderObject* previousSibling() const { return m_previous; }
156 RenderObject* nextSibling() const { return m_next; }
158 // FIXME: These should be renamed slowFirstChild, slowLastChild, etc.
159 // to discourage their use. The virtualChildren() call inside these
160 // can be slow for hot code paths.
161 // Currently, some subclasses like RenderBlock, override these NON-virtual
162 // functions to make these fast when we already have a more specific pointer type.
163 RenderObject* firstChild() const
165 if (const RenderObjectChildList* children = virtualChildren())
166 return children->firstChild();
169 RenderObject* lastChild() const
171 if (const RenderObjectChildList* children = virtualChildren())
172 return children->lastChild();
176 virtual RenderObjectChildList* virtualChildren() { return 0; }
177 virtual const RenderObjectChildList* virtualChildren() const { return 0; }
179 RenderObject* nextInPreOrder() const;
180 RenderObject* nextInPreOrder(const RenderObject* stayWithin) const;
181 RenderObject* nextInPreOrderAfterChildren() const;
182 RenderObject* nextInPreOrderAfterChildren(const RenderObject* stayWithin) const;
183 RenderObject* previousInPreOrder() const;
184 RenderObject* previousInPreOrder(const RenderObject* stayWithin) const;
185 RenderObject* childAt(unsigned) const;
187 RenderObject* lastLeafChild() const;
189 // The following six functions are used when the render tree hierarchy changes to make sure layers get
190 // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
191 // can contain a mixture of boxes and other object types, these functions need to be in the base class.
192 RenderLayer* enclosingLayer() const;
193 void addLayers(RenderLayer* parentLayer);
194 void removeLayers(RenderLayer* parentLayer);
195 void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
196 RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
198 // Scrolling is a RenderBox concept, however some code just cares about recursively scrolling our enclosing ScrollableArea(s).
199 bool scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX = ScrollAlignment::alignCenterIfNeeded, const ScrollAlignment& alignY = ScrollAlignment::alignCenterIfNeeded);
201 // Convenience function for getting to the nearest enclosing box of a RenderObject.
202 RenderBox* enclosingBox() const;
203 RenderBoxModelObject* enclosingBoxModelObject() const;
205 RenderBox* enclosingScrollableBox() const;
207 // Function to return our enclosing flow thread if we are contained inside one. This
208 // function follows the containing block chain.
209 RenderFlowThread* flowThreadContainingBlock() const
211 if (flowThreadState() == NotInsideFlowThread)
213 return locateFlowThreadContainingBlock();
216 virtual bool isEmpty() const { return firstChild() == 0; }
219 void setHasAXObject(bool flag) { m_hasAXObject = flag; }
220 bool hasAXObject() const { return m_hasAXObject; }
222 // Helper class forbidding calls to setNeedsLayout() during its lifetime.
223 class SetLayoutNeededForbiddenScope {
225 explicit SetLayoutNeededForbiddenScope(RenderObject*);
226 ~SetLayoutNeededForbiddenScope();
228 RenderObject* m_renderObject;
229 bool m_preexistingForbidden;
232 void assertRendererLaidOut() const
235 showRenderTreeForThis();
236 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout());
239 void assertSubtreeIsLaidOut() const
241 for (const RenderObject* renderer = this; renderer; renderer = renderer->nextInPreOrder())
242 renderer->assertRendererLaidOut();
247 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
249 virtual RenderBlock* firstLineBlock() const;
251 // Called when an object that was floating or positioned becomes a normal flow object
252 // again. We have to make sure the render tree updates as needed to accommodate the new
253 // normal flow object.
254 void handleDynamicFloatPositionChange();
256 // RenderObject tree manipulation
257 //////////////////////////////////////////
258 virtual bool canHaveChildren() const { return virtualChildren(); }
259 virtual bool canHaveGeneratedChildren() const;
260 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
261 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
262 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); }
263 virtual void removeChild(RenderObject*);
264 virtual bool createsAnonymousWrapper() const { return false; }
265 //////////////////////////////////////////
268 //////////////////////////////////////////
269 // Helper functions. Dangerous to use!
270 void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
271 void setNextSibling(RenderObject* next) { m_next = next; }
272 void setParent(RenderObject* parent)
276 // Only update if our flow thread state is different from our new parent and if we're not a RenderFlowThread.
277 // A RenderFlowThread is always considered to be inside itself, so it never has to change its state
278 // in response to parent changes.
279 FlowThreadState newState = parent ? parent->flowThreadState() : NotInsideFlowThread;
280 if (newState != flowThreadState() && !isRenderFlowThread())
281 setFlowThreadStateIncludingDescendants(newState);
284 //////////////////////////////////////////
287 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; }
288 void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; }
291 void addAbsoluteRectForLayer(LayoutRect& result);
292 void setLayerNeedsFullRepaint();
293 void setLayerNeedsFullRepaintForPositionedMovementLayout();
294 bool requiresAnonymousTableWrappers(const RenderObject*) const;
298 void showTreeForThis() const;
299 void showRenderTreeForThis() const;
300 void showLineTreeForThis() const;
302 void showRenderObject() const;
303 // We don't make printedCharacters an optional parameter so that
304 // showRenderObject can be called from gdb easily.
305 void showRenderObject(int printedCharacters) const;
306 void showRenderTreeAndMark(const RenderObject* markedObject1 = 0, const char* markedLabel1 = 0, const RenderObject* markedObject2 = 0, const char* markedLabel2 = 0, int depth = 0) const;
309 static RenderObject* createObject(Element*, RenderStyle*);
311 // RenderObjects are allocated out of the rendering partition.
312 void* operator new(size_t);
313 void operator delete(void*);
316 bool isPseudoElement() const { return node() && node()->isPseudoElement(); }
318 virtual bool isBR() const { return false; }
319 virtual bool isBoxModelObject() const { return false; }
320 virtual bool isCounter() const { return false; }
321 virtual bool isQuote() const { return false; }
323 virtual bool isDetailsMarker() const { return false; }
324 virtual bool isEmbeddedObject() const { return false; }
325 virtual bool isFieldset() const { return false; }
326 virtual bool isFileUploadControl() const { return false; }
327 virtual bool isFrame() const { return false; }
328 virtual bool isFrameSet() const { return false; }
329 virtual bool isImage() const { return false; }
330 virtual bool isInlineBlockOrInlineTable() const { return false; }
331 virtual bool isLayerModelObject() const { return false; }
332 virtual bool isListBox() const { return false; }
333 virtual bool isListItem() const { return false; }
334 virtual bool isListMarker() const { return false; }
335 virtual bool isMarquee() const { return false; }
336 virtual bool isMedia() const { return false; }
337 virtual bool isMenuList() const { return false; }
338 virtual bool isMeter() const { return false; }
339 virtual bool isProgress() const { return false; }
340 virtual bool isRenderBlock() const { return false; }
341 virtual bool isRenderBlockFlow() const { return false; }
342 virtual bool isRenderButton() const { return false; }
343 virtual bool isRenderIFrame() const { return false; }
344 virtual bool isRenderImage() const { return false; }
345 virtual bool isRenderInline() const { return false; }
346 virtual bool isRenderPart() const { return false; }
347 virtual bool isRenderRegion() const { return false; }
348 virtual bool isRenderView() const { return false; }
349 virtual bool isReplica() const { return false; }
351 virtual bool isRuby() const { return false; }
352 virtual bool isRubyBase() const { return false; }
353 virtual bool isRubyRun() const { return false; }
354 virtual bool isRubyText() const { return false; }
356 virtual bool isSlider() const { return false; }
357 virtual bool isSliderThumb() const { return false; }
358 virtual bool isTable() const { return false; }
359 virtual bool isTableCell() const { return false; }
360 virtual bool isRenderTableCol() const { return false; }
361 virtual bool isTableCaption() const { return false; }
362 virtual bool isTableRow() const { return false; }
363 virtual bool isTableSection() const { return false; }
364 virtual bool isTextControl() const { return false; }
365 virtual bool isTextArea() const { return false; }
366 virtual bool isTextField() const { return false; }
367 virtual bool isVideo() const { return false; }
368 virtual bool isWidget() const { return false; }
369 virtual bool isCanvas() const { return false; }
370 virtual bool isRenderFullScreen() const { return false; }
371 virtual bool isRenderFullScreenPlaceholder() const { return false; }
373 virtual bool isRenderGrid() const { return false; }
375 virtual bool isRenderFlowThread() const { return false; }
376 bool isInFlowRenderFlowThread() const { return isRenderFlowThread() && !isOutOfFlowPositioned(); }
377 bool isOutOfFlowRenderFlowThread() const { return isRenderFlowThread() && isOutOfFlowPositioned(); }
379 virtual bool isRenderMultiColumnSet() const { return false; }
381 virtual bool isRenderScrollbarPart() const { return false; }
383 bool isRoot() const { return document().documentElement() == m_node; }
386 bool isLegend() const;
388 bool isTablePart() const { return isTableCell() || isRenderTableCol() || isTableCaption() || isTableRow() || isTableSection(); }
390 inline bool isBeforeContent() const;
391 inline bool isAfterContent() const;
392 inline bool isBeforeOrAfterContent() const;
393 static inline bool isAfterContent(const RenderObject* obj) { return obj && obj->isAfterContent(); }
395 bool hasCounterNodeMap() const { return m_bitfields.hasCounterNodeMap(); }
396 void setHasCounterNodeMap(bool hasCounterNodeMap) { m_bitfields.setHasCounterNodeMap(hasCounterNodeMap); }
397 bool everHadLayout() const { return m_bitfields.everHadLayout(); }
399 bool childrenInline() const { return m_bitfields.childrenInline(); }
400 void setChildrenInline(bool b) { m_bitfields.setChildrenInline(b); }
401 bool hasColumns() const { return m_bitfields.hasColumns(); }
402 void setHasColumns(bool b = true) { m_bitfields.setHasColumns(b); }
404 bool ancestorLineBoxDirty() const { return m_bitfields.ancestorLineBoxDirty(); }
405 void setAncestorLineBoxDirty(bool value = true)
407 m_bitfields.setAncestorLineBoxDirty(value);
412 enum FlowThreadState {
413 NotInsideFlowThread = 0,
414 InsideOutOfFlowThread = 1,
415 InsideInFlowThread = 2,
418 void setFlowThreadStateIncludingDescendants(FlowThreadState);
420 FlowThreadState flowThreadState() const { return m_bitfields.flowThreadState(); }
421 void setFlowThreadState(FlowThreadState state) { m_bitfields.setFlowThreadState(state); }
423 // FIXME: Until all SVG renders can be subclasses of RenderSVGModelObject we have
424 // to add SVG renderer methods to RenderObject with an ASSERT_NOT_REACHED() default implementation.
425 virtual bool isSVG() const { return false; }
426 virtual bool isSVGRoot() const { return false; }
427 virtual bool isSVGContainer() const { return false; }
428 virtual bool isSVGTransformableContainer() const { return false; }
429 virtual bool isSVGViewportContainer() const { return false; }
430 virtual bool isSVGGradientStop() const { return false; }
431 virtual bool isSVGHiddenContainer() const { return false; }
432 virtual bool isSVGPath() const { return false; }
433 virtual bool isSVGShape() const { return false; }
434 virtual bool isSVGText() const { return false; }
435 virtual bool isSVGTextPath() const { return false; }
436 virtual bool isSVGInline() const { return false; }
437 virtual bool isSVGInlineText() const { return false; }
438 virtual bool isSVGImage() const { return false; }
439 virtual bool isSVGForeignObject() const { return false; }
440 virtual bool isSVGResourceContainer() const { return false; }
441 virtual bool isSVGResourceFilter() const { return false; }
442 virtual bool isSVGResourceFilterPrimitive() const { return false; }
444 // FIXME: Those belong into a SVG specific base-class for all renderers (see above)
445 // Unfortunately we don't have such a class yet, because it's not possible for all renderers
446 // to inherit from RenderSVGObject -> RenderObject (some need RenderBlock inheritance for instance)
447 virtual void setNeedsTransformUpdate() { }
448 virtual void setNeedsBoundariesUpdate();
450 // Per SVG 1.1 objectBoundingBox ignores clipping, masking, filter effects, opacity and stroke-width.
451 // This is used for all computation of objectBoundingBox relative units and by SVGLocatable::getBBox().
452 // NOTE: Markers are not specifically ignored here by SVG 1.1 spec, but we ignore them
453 // since stroke-width is ignored (and marker size can depend on stroke-width).
454 // objectBoundingBox is returned local coordinates.
455 // The name objectBoundingBox is taken from the SVG 1.1 spec.
456 virtual FloatRect objectBoundingBox() const;
457 virtual FloatRect strokeBoundingBox() const;
459 // Returns the smallest rectangle enclosing all of the painted content
460 // respecting clipping, masking, filters, opacity, stroke-width and markers
461 virtual FloatRect repaintRectInLocalCoordinates() const;
463 // This only returns the transform="" value from the element
464 // most callsites want localToParentTransform() instead.
465 virtual AffineTransform localTransform() const;
467 // Returns the full transform mapping from local coordinates to local coords for the parent SVG renderer
468 // This includes any viewport transforms and x/y offsets as well as the transform="" value off the element.
469 virtual const AffineTransform& localToParentTransform() const;
471 // SVG uses FloatPoint precise hit testing, and passes the point in parent
472 // coordinates instead of in repaint container coordinates. Eventually the
473 // rest of the rendering tree will move to a similar model.
474 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
476 virtual bool canHaveWhitespaceChildren() const
478 if (isTable() || isTableRow() || isTableSection() || isRenderTableCol() || isFrameSet() || isFlexibleBox() || isRenderGrid())
483 bool isAnonymous() const { return m_bitfields.isAnonymous(); }
484 bool isAnonymousBlock() const
486 // This function is kept in sync with anonymous block creation conditions in
487 // RenderBlock::createAnonymousBlock(). This includes creating an anonymous
488 // RenderBlock having a BLOCK or BOX display. Other classes such as RenderTextFragment
489 // are not RenderBlocks and will return false. See https://bugs.webkit.org/show_bug.cgi?id=56709.
490 return isAnonymous() && (style()->display() == BLOCK || style()->display() == BOX) && style()->styleType() == NOPSEUDO && isRenderBlock() && !isListMarker() && !isRenderFlowThread()
491 && !isRenderFullScreen()
492 && !isRenderFullScreenPlaceholder();
494 bool isAnonymousColumnsBlock() const { return style()->specifiesColumns() && isAnonymousBlock(); }
495 bool isAnonymousColumnSpanBlock() const { return style()->columnSpan() && isAnonymousBlock(); }
496 bool isElementContinuation() const { return node() && node()->renderer() != this; }
497 bool isInlineElementContinuation() const { return isElementContinuation() && isInline(); }
498 virtual RenderBoxModelObject* virtualContinuation() const { return 0; }
500 bool isFloating() const { return m_bitfields.floating(); }
502 bool isOutOfFlowPositioned() const { return m_bitfields.isOutOfFlowPositioned(); } // absolute or fixed positioning
503 bool isInFlowPositioned() const { return m_bitfields.isRelPositioned() || m_bitfields.isStickyPositioned(); } // relative or sticky positioning
504 bool isRelPositioned() const { return m_bitfields.isRelPositioned(); } // relative positioning
505 bool isStickyPositioned() const { return m_bitfields.isStickyPositioned(); }
506 bool isPositioned() const { return m_bitfields.isPositioned(); }
508 bool isText() const { return m_bitfields.isText(); }
509 bool isBox() const { return m_bitfields.isBox(); }
510 bool isInline() const { return m_bitfields.isInline(); } // inline object
511 bool isDragging() const { return m_bitfields.isDragging(); }
512 bool isReplaced() const { return m_bitfields.isReplaced(); } // a "replaced" element (see CSS)
513 bool isHorizontalWritingMode() const { return m_bitfields.horizontalWritingMode(); }
515 bool hasLayer() const { return m_bitfields.hasLayer(); }
517 enum BoxDecorationState {
519 HasBoxDecorationsAndBackgroundObscurationStatusInvalid,
520 HasBoxDecorationsAndBackgroundIsKnownToBeObscured,
521 HasBoxDecorationsAndBackgroundMayBeVisible,
523 bool hasBoxDecorations() const { return m_bitfields.boxDecorationState() != NoBoxDecorations; }
524 bool backgroundIsKnownToBeObscured();
525 bool borderImageIsLoadedAndCanBeRendered() const;
526 bool mustRepaintBackgroundOrBorder() const;
527 bool hasBackground() const { return style()->hasBackground(); }
528 bool hasEntirelyFixedBackground() const;
530 bool needsLayout() const
532 return m_bitfields.selfNeedsLayout() || m_bitfields.normalChildNeedsLayout() || m_bitfields.posChildNeedsLayout()
533 || m_bitfields.needsSimplifiedNormalFlowLayout() || m_bitfields.needsPositionedMovementLayout();
536 bool selfNeedsLayout() const { return m_bitfields.selfNeedsLayout(); }
537 bool needsPositionedMovementLayout() const { return m_bitfields.needsPositionedMovementLayout(); }
538 bool needsPositionedMovementLayoutOnly() const
540 return m_bitfields.needsPositionedMovementLayout() && !m_bitfields.selfNeedsLayout() && !m_bitfields.normalChildNeedsLayout()
541 && !m_bitfields.posChildNeedsLayout() && !m_bitfields.needsSimplifiedNormalFlowLayout();
544 bool posChildNeedsLayout() const { return m_bitfields.posChildNeedsLayout(); }
545 bool needsSimplifiedNormalFlowLayout() const { return m_bitfields.needsSimplifiedNormalFlowLayout(); }
546 bool normalChildNeedsLayout() const { return m_bitfields.normalChildNeedsLayout(); }
548 bool preferredLogicalWidthsDirty() const { return m_bitfields.preferredLogicalWidthsDirty(); }
550 bool isSelectionBorder() const;
552 bool hasClip() const { return isOutOfFlowPositioned() && style()->hasClip(); }
553 bool hasOverflowClip() const { return m_bitfields.hasOverflowClip(); }
554 bool hasClipOrOverflowClip() const { return hasClip() || hasOverflowClip(); }
556 bool hasTransform() const { return m_bitfields.hasTransform(); }
557 bool hasMask() const { return style() && style()->hasMask(); }
558 bool hasClipPath() const { return style() && style()->clipPath(); }
559 bool hasHiddenBackface() const { return style() && style()->backfaceVisibility() == BackfaceVisibilityHidden; }
561 bool hasFilter() const { return style() && style()->hasFilter(); }
563 bool hasBlendMode() const;
565 inline bool preservesNewline() const;
567 // The pseudo element style can be cached or uncached. Use the cached method if the pseudo element doesn't respect
568 // any pseudo classes (and therefore has no concept of changing state).
569 RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0) const;
570 PassRefPtr<RenderStyle> getUncachedPseudoStyle(const PseudoStyleRequest&, RenderStyle* parentStyle = 0, RenderStyle* ownStyle = 0) const;
572 virtual void updateDragState(bool dragOn);
574 RenderView* view() const { return document().renderView(); };
575 FrameView* frameView() const { return document().view(); };
577 // Returns true if this renderer is rooted, and optionally returns the hosting view (the root of the hierarchy).
578 bool isRooted(RenderView** = 0) const;
582 return isAnonymous() ? 0 : m_node;
585 Node* nonPseudoNode() const
587 return isPseudoElement() ? 0 : node();
590 // FIXME: Why does RenderWidget need this?
591 void clearNode() { m_node = 0; }
593 // Returns the styled node that caused the generation of this renderer.
594 // This is the same as node() except for renderers of :before and :after
595 // pseudo elements for which their parent node is returned.
596 Node* generatingNode() const { return isPseudoElement() ? node()->parentOrShadowHostNode() : node(); }
598 Document& document() const { return m_node->document(); }
599 LocalFrame* frame() const { return document().frame(); }
601 bool hasOutlineAnnotation() const;
602 bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
604 // Returns the object containing this one. Can be different from parent for positioned elements.
605 // If repaintContainer and repaintContainerSkipped are not null, on return *repaintContainerSkipped
606 // is true if the renderer returned is an ancestor of repaintContainer.
607 RenderObject* container(const RenderLayerModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
609 virtual RenderObject* hoverAncestor() const { return parent(); }
611 Element* offsetParent() const;
613 void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0, SubtreeLayoutScope* = 0);
614 void setNeedsLayout(MarkingBehavior = MarkContainingBlockChain, SubtreeLayoutScope* = 0);
615 void clearNeedsLayout();
616 void setChildNeedsLayout(MarkingBehavior = MarkContainingBlockChain, SubtreeLayoutScope* = 0);
617 void setNeedsPositionedMovementLayout();
618 void setNeedsSimplifiedNormalFlowLayout();
619 void setPreferredLogicalWidthsDirty(MarkingBehavior = MarkContainingBlockChain);
620 void clearPreferredLogicalWidthsDirty();
621 void invalidateContainerPreferredLogicalWidths();
623 void setNeedsLayoutAndPrefWidthsRecalc()
626 setPreferredLogicalWidthsDirty();
629 void setPositionState(EPosition position)
631 ASSERT((position != AbsolutePosition && position != FixedPosition) || isBox());
632 m_bitfields.setPositionedState(position);
634 void clearPositionedState() { m_bitfields.clearPositionedState(); }
636 void setFloating(bool isFloating) { m_bitfields.setFloating(isFloating); }
637 void setInline(bool isInline) { m_bitfields.setIsInline(isInline); }
639 void setHasBoxDecorations(bool);
640 void invalidateBackgroundObscurationStatus();
641 virtual bool computeBackgroundIsKnownToBeObscured() { return false; }
643 void setIsText() { m_bitfields.setIsText(true); }
644 void setIsBox() { m_bitfields.setIsBox(true); }
645 void setReplaced(bool isReplaced) { m_bitfields.setIsReplaced(isReplaced); }
646 void setHorizontalWritingMode(bool hasHorizontalWritingMode) { m_bitfields.setHorizontalWritingMode(hasHorizontalWritingMode); }
647 void setHasOverflowClip(bool hasOverflowClip) { m_bitfields.setHasOverflowClip(hasOverflowClip); }
648 void setHasLayer(bool hasLayer) { m_bitfields.setHasLayer(hasLayer); }
649 void setHasTransform(bool hasTransform) { m_bitfields.setHasTransform(hasTransform); }
650 void setHasReflection(bool hasReflection) { m_bitfields.setHasReflection(hasReflection); }
652 void scheduleRelayout();
654 void updateFillImages(const FillLayer*, const FillLayer*);
655 void updateImage(StyleImage*, StyleImage*);
656 void updateShapeImage(const ShapeValue*, const ShapeValue*);
658 virtual void paint(PaintInfo&, const LayoutPoint&);
660 // Subclasses must reimplement this method to compute the size and position
661 // of this object and all its descendants.
662 virtual void layout() = 0;
663 virtual bool updateImageLoadingPriorities() { return false; }
664 void setHasPendingResourceUpdate(bool hasPendingResourceUpdate) { m_bitfields.setHasPendingResourceUpdate(hasPendingResourceUpdate); }
665 bool hasPendingResourceUpdate() const { return m_bitfields.hasPendingResourceUpdate(); }
667 /* This function performs a layout only if one is needed. */
668 void layoutIfNeeded() { if (needsLayout()) layout(); }
671 void forceChildLayout();
673 // used for element state updates that cannot be fixed with a
674 // repaint and do not need a relayout
675 virtual void updateFromElement() { }
677 virtual void addAnnotatedRegions(Vector<AnnotatedRegionValue>&);
678 void collectAnnotatedRegions(Vector<AnnotatedRegionValue>&);
680 CompositingState compositingState() const;
681 virtual CompositingReasons additionalCompositingReasons(CompositingTriggerFlags) const;
683 bool acceleratedCompositingForOverflowScrollEnabled() const;
684 // FIXME: This is a temporary flag and should be removed once accelerated
685 // overflow scroll is ready (crbug.com/254111).
686 bool compositorDrivenAcceleratedScrollingEnabled() const;
688 bool hitTest(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter = HitTestAll);
689 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
690 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
692 virtual PositionWithAffinity positionForPoint(const LayoutPoint&);
693 PositionWithAffinity createPositionWithAffinity(int offset, EAffinity);
694 PositionWithAffinity createPositionWithAffinity(const Position&);
696 virtual void dirtyLinesFromChangedChild(RenderObject*);
698 // Set the style of the object and update the state of the object accordingly.
699 void setStyle(PassRefPtr<RenderStyle>);
701 // Set the style of the object if it's generated content.
702 void setPseudoStyle(PassRefPtr<RenderStyle>);
704 // Updates only the local style ptr of the object. Does not update the state of the object,
705 // and so only should be called when the style is known not to have changed (or from setStyle).
706 void setStyleInternal(PassRefPtr<RenderStyle> style) { m_style = style; }
708 // returns the containing block level element for this element.
709 RenderBlock* containingBlock() const;
710 RenderObject* clippingContainer() const;
712 bool canContainFixedPositionObjects() const
714 return isRenderView() || (hasTransform() && isRenderBlock()) || isSVGForeignObject() || isOutOfFlowRenderFlowThread();
716 bool canContainAbsolutePositionObjects() const
718 return isRenderView() || (hasTransform() && isRenderBlock()) || isSVGForeignObject();
721 // Convert the given local point to absolute coordinates
722 // FIXME: Temporary. If UseTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
723 FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(), MapCoordinatesFlags = 0) const;
724 FloatPoint absoluteToLocal(const FloatPoint&, MapCoordinatesFlags = 0) const;
726 // Convert a local quad to absolute coordinates, taking transforms into account.
727 FloatQuad localToAbsoluteQuad(const FloatQuad& quad, MapCoordinatesFlags mode = 0, bool* wasFixed = 0) const
729 return localToContainerQuad(quad, 0, mode, wasFixed);
731 // Convert an absolute quad to local coordinates.
732 FloatQuad absoluteToLocalQuad(const FloatQuad&, MapCoordinatesFlags mode = 0) const;
734 // Convert a local quad into the coordinate system of container, taking transforms into account.
735 FloatQuad localToContainerQuad(const FloatQuad&, const RenderLayerModelObject* repaintContainer, MapCoordinatesFlags = 0, bool* wasFixed = 0) const;
736 FloatPoint localToContainerPoint(const FloatPoint&, const RenderLayerModelObject* repaintContainer, MapCoordinatesFlags = 0, bool* wasFixed = 0) const;
738 // Return the offset from the container() renderer (excluding transforms). In multi-column layout,
739 // different offsets apply at different points, so return the offset that applies to the given point.
740 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const;
741 // Return the offset from an object up the container() chain. Asserts that none of the intermediate objects have transforms.
742 LayoutSize offsetFromAncestorContainer(RenderObject*) const;
744 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint&) const { }
746 // FIXME: useTransforms should go away eventually
747 IntRect absoluteBoundingBoxRect(bool useTransform = true) const;
748 IntRect absoluteBoundingBoxRectIgnoringTransforms() const { return absoluteBoundingBoxRect(false); }
750 // Build an array of quads in absolute coords for line boxes
751 virtual void absoluteQuads(Vector<FloatQuad>&, bool* /*wasFixed*/ = 0) const { }
753 virtual void absoluteFocusRingQuads(Vector<FloatQuad>&);
755 static FloatRect absoluteBoundingBoxRectForRange(const Range*);
757 // the rect that will be painted if this object is passed as the paintingRoot
758 LayoutRect paintingRootRect(LayoutRect& topLevelRect);
760 virtual LayoutUnit minPreferredLogicalWidth() const { return 0; }
761 virtual LayoutUnit maxPreferredLogicalWidth() const { return 0; }
763 RenderStyle* style() const { return m_style.get(); }
764 RenderStyle* firstLineStyle() const { return document().styleEngine()->usesFirstLineRules() ? cachedFirstLineStyle() : style(); }
765 RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
767 inline Color resolveColor(const RenderStyle* styleToUse, int colorProperty) const
769 return styleToUse->visitedDependentColor(colorProperty);
772 inline Color resolveColor(int colorProperty) const
774 return style()->visitedDependentColor(colorProperty);
777 // Used only by Element::pseudoStyleCacheIsInvalid to get a first line style based off of a
778 // given new style, without accessing the cache.
779 PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const;
781 // Anonymous blocks that are part of of a continuation chain will return their inline continuation's outline style instead.
782 // This is typically only relevant when repainting.
783 virtual RenderStyle* outlineStyleForRepaint() const { return style(); }
785 virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
787 struct AppliedTextDecoration {
789 TextDecorationStyle style;
790 AppliedTextDecoration() : color(Color::transparent), style(TextDecorationStyleSolid) { }
793 void getTextDecorations(unsigned decorations, AppliedTextDecoration& underline, AppliedTextDecoration& overline, AppliedTextDecoration& linethrough, bool quirksMode = false, bool firstlineStyle = false);
795 // Return the RenderLayerModelObject in the container chain which is responsible for painting this object, or 0
796 // if painting is root-relative. This is the container that should be passed to the 'forRepaint'
798 RenderLayerModelObject* containerForRepaint() const;
799 // Actually do the repaint of rect r for this object which has been computed in the coordinate space
800 // of repaintContainer. If repaintContainer is 0, repaint via the view.
801 void repaintUsingContainer(const RenderLayerModelObject* repaintContainer, const IntRect&) const;
803 // Repaint the entire object. Called when, e.g., the color of a border changes, or when a border
805 void repaint() const;
807 // Repaint a specific subrectangle within a given object. The rect |r| is in the object's coordinate space.
808 void repaintRectangle(const LayoutRect&) const;
810 // Repaint only if our old bounds and new bounds are different. The caller may pass in newBounds and newOutlineBox if they are known.
811 bool repaintAfterLayoutIfNeeded(const RenderLayerModelObject* repaintContainer, bool wasSelfLayout,
812 const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr = 0, const LayoutRect* newOutlineBoxPtr = 0);
814 virtual void repaintOverflow();
815 void repaintOverflowIfNeeded();
817 bool checkForRepaint() const;
818 bool checkForRepaintDuringLayout() const;
820 // Returns the rect that should be repainted whenever this object changes. The rect is in the view's
821 // coordinate space. This method deals with outlines and overflow.
822 LayoutRect absoluteClippedOverflowRect() const
824 return clippedOverflowRectForRepaint(0);
826 IntRect pixelSnappedAbsoluteClippedOverflowRect() const;
827 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const;
828 virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const;
829 virtual LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap* = 0) const { return LayoutRect(); }
831 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
832 // that rect in the coordinate space of repaintContainer.
833 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
834 virtual void computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed = false) const;
836 // If multiple-column layout results in applying an offset to the given point, add the same
837 // offset to the given size.
838 virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const { }
839 LayoutSize offsetForColumns(const LayoutPoint& point) const
842 adjustForColumns(offset, point);
846 virtual unsigned length() const { return 1; }
848 bool isFloatingOrOutOfFlowPositioned() const { return (isFloating() || isOutOfFlowPositioned()); }
850 bool isTransparent() const { return style()->opacity() < 1.0f; }
851 float opacity() const { return style()->opacity(); }
853 bool hasReflection() const { return m_bitfields.hasReflection(); }
855 enum SelectionState {
856 SelectionNone, // The object is not selected.
857 SelectionStart, // The object either contains the start of a selection run or is the start of a run
858 SelectionInside, // The object is fully encompassed by a selection run
859 SelectionEnd, // The object either contains the end of a selection run or is the end of a run
860 SelectionBoth // The object contains an entire run or is the sole selected object in that run
863 // The current selection state for an object. For blocks, the state refers to the state of the leaf
864 // descendants (as described above in the SelectionState enum declaration).
865 SelectionState selectionState() const { return m_bitfields.selectionState(); }
866 virtual void setSelectionState(SelectionState state) { m_bitfields.setSelectionState(state); }
867 inline void setSelectionStateIfNeeded(SelectionState);
868 bool canUpdateSelectionOnRootLineBoxes();
870 // A single rectangle that encompasses all of the selected objects within this object. Used to determine the tightest
871 // possible bounding box for the selection.
872 LayoutRect selectionRect(bool clipToVisibleContent = true) { return selectionRectForRepaint(0, clipToVisibleContent); }
873 virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return LayoutRect(); }
875 virtual bool canBeSelectionLeaf() const { return false; }
876 bool hasSelectedChildren() const { return selectionState() != SelectionNone; }
878 bool isSelectable() const;
879 // Obtains the selection colors that should be used when painting a selection.
880 Color selectionBackgroundColor() const;
881 Color selectionForegroundColor() const;
882 Color selectionEmphasisMarkColor() const;
884 // Whether or not a given block needs to paint selection gaps.
885 virtual bool shouldPaintSelectionGaps() const { return false; }
888 * Returns the local coordinates of the caret within this render object.
889 * @param caretOffset zero-based offset determining position within the render object.
890 * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
891 * useful for character range rect computations
893 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
895 // When performing a global document tear-down, the renderer of the document is cleared. We use this
896 // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
897 bool documentBeingDestroyed() const;
899 void destroyAndCleanupAnonymousWrappers();
900 virtual void destroy();
902 // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).
903 virtual bool isDeprecatedFlexibleBox() const { return false; }
905 // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flex).
906 virtual bool isFlexibleBox() const { return false; }
908 bool isFlexibleBoxIncludingDeprecated() const
910 return isFlexibleBox() || isDeprecatedFlexibleBox();
913 virtual bool isCombineText() const { return false; }
915 virtual int caretMinOffset() const;
916 virtual int caretMaxOffset() const;
918 virtual int previousOffset(int current) const;
919 virtual int previousOffsetForBackwardDeletion(int current) const;
920 virtual int nextOffset(int current) const;
922 virtual void imageChanged(ImageResource*, const IntRect* = 0) OVERRIDE FINAL;
923 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
924 virtual bool willRenderImage(ImageResource*) OVERRIDE FINAL;
926 void selectionStartEnd(int& spos, int& epos) const;
928 void remove() { if (parent()) parent()->removeChild(this); }
930 bool isInert() const;
931 virtual bool visibleForTouchAction() const { return false; }
932 bool visibleToHitTestRequest(const HitTestRequest& request) const
934 if (request.touchAction() && !visibleForTouchAction())
936 return style()->visibility() == VISIBLE && (request.ignorePointerEventsNone() || style()->pointerEvents() != PE_NONE) && !isInert();
939 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE && !isInert(); }
941 // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
942 // localToAbsolute/absoluteToLocal methods instead.
943 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const;
944 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const;
946 // Pushes state onto RenderGeometryMap about how to map coordinates from this renderer to its container, or ancestorToStopAt (whichever is encountered first).
947 // Returns the renderer which was mapped to (container or ancestorToStopAt).
948 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const;
950 bool shouldUseTransformFromContainer(const RenderObject* container) const;
951 void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const;
953 bool createsGroup() const { return isTransparent() || hasMask() || hasFilter() || hasBlendMode(); }
955 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& /* additionalOffset */, const RenderLayerModelObject* /* paintContainer */ = 0) { };
957 // Compute a list of hit-test rectangles per layer rooted at this renderer.
958 virtual void computeLayerHitTestRects(LayerHitTestRects&) const;
960 LayoutRect absoluteOutlineBounds() const
962 return outlineBoundsForRepaint(0);
965 // Return the renderer whose background style is used to paint the root background. Should only be called on the renderer for which isRoot() is true.
966 RenderObject* rendererForRootBackground();
968 RespectImageOrientationEnum shouldRespectImageOrientation() const;
970 bool isRelayoutBoundaryForInspector() const;
972 const LayoutRect& newRepaintRect() const { return m_newRepaintRect; }
973 void setNewRepaintRect(const LayoutRect& rect) { m_newRepaintRect = rect; }
975 const LayoutRect& oldRepaintRect() const { return m_oldRepaintRect; }
976 void setOldRepaintRect(const LayoutRect& rect) { m_oldRepaintRect = rect; }
978 LayoutRect newOutlineRect();
979 void setNewOutlineRect(const LayoutRect&);
981 LayoutRect oldOutlineRect();
982 void setOldOutlineRect(const LayoutRect&);
984 bool shouldDoFullRepaintAfterLayout() const { return m_bitfields.shouldDoFullRepaintAfterLayout(); }
985 void setShouldDoFullRepaintAfterLayout(bool b) { m_bitfields.setShouldDoFullRepaintAfterLayout(b); }
986 bool shouldRepaintOverflow() const { return m_bitfields.shouldRepaintOverflow(); }
988 bool shouldDoFullRepaintIfSelfPaintingLayer() const { return m_bitfields.shouldDoFullRepaintIfSelfPaintingLayer(); }
989 void setShouldDoFullRepaintIfSelfPaintingLayer(bool b) { m_bitfields.setShouldDoFullRepaintIfSelfPaintingLayer(b); }
991 bool onlyNeededPositionedMovementLayout() const { return m_bitfields.onlyNeededPositionedMovementLayout(); }
992 void setOnlyNeededPositionedMovementLayout(bool b) { m_bitfields.setOnlyNeededPositionedMovementLayout(b); }
994 void clearRepaintState();
996 // layoutDidGetCalled indicates whether this render object was re-laid-out
997 // since the last call to setLayoutDidGetCalled(false) on this object.
998 bool layoutDidGetCalled() { return m_bitfields.layoutDidGetCalled(); }
999 void setLayoutDidGetCalled(bool b) { m_bitfields.setLayoutDidGetCalled(b); }
1001 bool shouldDisableLayoutState() const { return hasColumns() || hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode(); }
1004 inline bool layerCreationAllowedForSubtree() const;
1006 // Overrides should call the superclass at the end
1007 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
1008 // Overrides should call the superclass at the start
1009 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
1010 void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
1012 void drawLineForBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2, BoxSide,
1013 Color, EBorderStyle, int adjbw1, int adjbw2, bool antialias = false);
1014 void drawDashedOrDottedBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1015 BoxSide, Color, int thickness, EBorderStyle, bool antialias);
1016 void drawDoubleBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1017 int length, BoxSide, Color, int thickness, int adjacentWidth1, int adjacentWidth2, bool antialias);
1018 void drawRidgeOrGrooveBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1019 BoxSide, Color, EBorderStyle, int adjacentWidth1, int adjacentWidth2, bool antialias);
1020 void drawSolidBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1021 BoxSide, Color, int adjacentWidth1, int adjacentWidth2, bool antialias);
1023 void paintFocusRing(PaintInfo&, const LayoutPoint&, RenderStyle*);
1024 void paintOutline(PaintInfo&, const LayoutRect&);
1025 void addPDFURLRect(GraphicsContext*, const LayoutRect&);
1027 virtual LayoutRect viewRect() const;
1029 void adjustRectForOutline(LayoutRect&) const;
1031 void clearLayoutRootIfNeeded() const;
1032 virtual void willBeDestroyed();
1035 virtual void insertedIntoTree();
1036 virtual void willBeRemovedFromTree();
1038 void setDocumentForAnonymous(Document* document) { ASSERT(isAnonymous()); m_node = document; }
1040 // Add hit-test rects for the render tree rooted at this node to the provided collection on a
1041 // per-RenderLayer basis.
1042 // currentLayer must be the enclosing layer, and layerOffset is the current offset within
1043 // this layer. Subclass implementations will add any offset for this renderer within it's
1044 // container, so callers should provide only the offset of the container within it's layer.
1045 // containerRect is a rect that has already been added for the currentLayer which is likely to
1046 // be a container for child elements. Any rect wholly contained by containerRect can be
1048 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const;
1050 // Add hit-test rects for this renderer only to the provided list. layerOffset is the offset
1051 // of this renderer within the current layer that should be used for each result.
1052 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const { };
1055 RenderBlock* containerForFixedPosition(const RenderLayerModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
1057 RenderFlowThread* locateFlowThreadContainingBlock() const;
1058 void removeFromRenderFlowThread();
1059 void removeFromRenderFlowThreadRecursive(RenderFlowThread*);
1061 bool shouldRepaintForStyleDifference(StyleDifference) const;
1062 bool hasImmediateNonWhitespaceTextChildOrPropertiesDependentOnColor() const;
1064 RenderStyle* cachedFirstLineStyle() const;
1065 StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
1067 Color selectionColor(int colorProperty) const;
1069 void removeShapeImageClient(ShapeValue*);
1072 void checkBlockPositionedObjectsNeedLayout();
1075 RefPtr<RenderStyle> m_style;
1079 RenderObject* m_parent;
1080 RenderObject* m_previous;
1081 RenderObject* m_next;
1084 unsigned m_hasAXObject : 1;
1085 unsigned m_setNeedsLayoutForbidden : 1;
1088 #define ADD_BOOLEAN_BITFIELD(name, Name) \
1090 unsigned m_##name : 1;\
1092 bool name() const { return m_##name; }\
1093 void set##Name(bool name) { m_##name = name; }\
1095 class RenderObjectBitfields {
1096 enum PositionedState {
1097 IsStaticallyPositioned = 0,
1098 IsRelativelyPositioned = 1,
1099 IsOutOfFlowPositioned = 2,
1100 IsStickyPositioned = 3
1104 RenderObjectBitfields(Node* node)
1105 : m_selfNeedsLayout(false)
1106 // FIXME: shouldDoFullRepaintAfterLayout is needed because we reset
1107 // the layout bits before repaint when doing repaintAfterLayout.
1108 // Holding the layout bits until after repaint would remove the need
1110 , m_shouldDoFullRepaintAfterLayout(false)
1111 , m_shouldRepaintOverflow(false)
1112 , m_shouldDoFullRepaintIfSelfPaintingLayer(false)
1113 , m_onlyNeededPositionedMovementLayout(false)
1114 , m_needsPositionedMovementLayout(false)
1115 , m_normalChildNeedsLayout(false)
1116 , m_posChildNeedsLayout(false)
1117 , m_needsSimplifiedNormalFlowLayout(false)
1118 , m_preferredLogicalWidthsDirty(false)
1120 , m_isAnonymous(!node)
1124 , m_isReplaced(false)
1125 , m_horizontalWritingMode(true)
1126 , m_isDragging(false)
1128 , m_hasOverflowClip(false)
1129 , m_hasTransform(false)
1130 , m_hasReflection(false)
1131 , m_hasCounterNodeMap(false)
1132 , m_everHadLayout(false)
1133 , m_ancestorLineBoxDirty(false)
1134 , m_childrenInline(false)
1135 , m_hasColumns(false)
1136 , m_layoutDidGetCalled(false)
1137 , m_positionedState(IsStaticallyPositioned)
1138 , m_selectionState(SelectionNone)
1139 , m_flowThreadState(NotInsideFlowThread)
1140 , m_boxDecorationState(NoBoxDecorations)
1141 , m_hasPendingResourceUpdate(false)
1145 // 32 bits have been used in the first word, and 5 in the second.
1146 ADD_BOOLEAN_BITFIELD(selfNeedsLayout, SelfNeedsLayout);
1147 ADD_BOOLEAN_BITFIELD(shouldDoFullRepaintAfterLayout, ShouldDoFullRepaintAfterLayout);
1148 ADD_BOOLEAN_BITFIELD(shouldRepaintOverflow, ShouldRepaintOverflow);
1149 ADD_BOOLEAN_BITFIELD(shouldDoFullRepaintIfSelfPaintingLayer, ShouldDoFullRepaintIfSelfPaintingLayer);
1150 ADD_BOOLEAN_BITFIELD(onlyNeededPositionedMovementLayout, OnlyNeededPositionedMovementLayout);
1151 ADD_BOOLEAN_BITFIELD(needsPositionedMovementLayout, NeedsPositionedMovementLayout);
1152 ADD_BOOLEAN_BITFIELD(normalChildNeedsLayout, NormalChildNeedsLayout);
1153 ADD_BOOLEAN_BITFIELD(posChildNeedsLayout, PosChildNeedsLayout);
1154 ADD_BOOLEAN_BITFIELD(needsSimplifiedNormalFlowLayout, NeedsSimplifiedNormalFlowLayout);
1155 ADD_BOOLEAN_BITFIELD(preferredLogicalWidthsDirty, PreferredLogicalWidthsDirty);
1156 ADD_BOOLEAN_BITFIELD(floating, Floating);
1158 ADD_BOOLEAN_BITFIELD(isAnonymous, IsAnonymous);
1159 ADD_BOOLEAN_BITFIELD(isText, IsText);
1160 ADD_BOOLEAN_BITFIELD(isBox, IsBox);
1161 ADD_BOOLEAN_BITFIELD(isInline, IsInline);
1162 ADD_BOOLEAN_BITFIELD(isReplaced, IsReplaced);
1163 ADD_BOOLEAN_BITFIELD(horizontalWritingMode, HorizontalWritingMode);
1164 ADD_BOOLEAN_BITFIELD(isDragging, IsDragging);
1166 ADD_BOOLEAN_BITFIELD(hasLayer, HasLayer);
1167 ADD_BOOLEAN_BITFIELD(hasOverflowClip, HasOverflowClip); // Set in the case of overflow:auto/scroll/hidden
1168 ADD_BOOLEAN_BITFIELD(hasTransform, HasTransform);
1169 ADD_BOOLEAN_BITFIELD(hasReflection, HasReflection);
1171 ADD_BOOLEAN_BITFIELD(hasCounterNodeMap, HasCounterNodeMap);
1172 ADD_BOOLEAN_BITFIELD(everHadLayout, EverHadLayout);
1173 ADD_BOOLEAN_BITFIELD(ancestorLineBoxDirty, AncestorLineBoxDirty);
1176 ADD_BOOLEAN_BITFIELD(childrenInline, ChildrenInline);
1177 ADD_BOOLEAN_BITFIELD(hasColumns, HasColumns);
1179 ADD_BOOLEAN_BITFIELD(layoutDidGetCalled, LayoutDidGetCalled);
1182 unsigned m_positionedState : 2; // PositionedState
1183 unsigned m_selectionState : 3; // SelectionState
1184 unsigned m_flowThreadState : 2; // FlowThreadState
1185 unsigned m_boxDecorationState : 2; // BoxDecorationState
1189 ADD_BOOLEAN_BITFIELD(hasPendingResourceUpdate, HasPendingResourceUpdate);
1191 bool isOutOfFlowPositioned() const { return m_positionedState == IsOutOfFlowPositioned; }
1192 bool isRelPositioned() const { return m_positionedState == IsRelativelyPositioned; }
1193 bool isStickyPositioned() const { return m_positionedState == IsStickyPositioned; }
1194 bool isPositioned() const { return m_positionedState != IsStaticallyPositioned; }
1196 void setPositionedState(int positionState)
1198 // This mask maps FixedPosition and AbsolutePosition to IsOutOfFlowPositioned, saving one bit.
1199 m_positionedState = static_cast<PositionedState>(positionState & 0x3);
1201 void clearPositionedState() { m_positionedState = StaticPosition; }
1203 ALWAYS_INLINE SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
1204 ALWAYS_INLINE void setSelectionState(SelectionState selectionState) { m_selectionState = selectionState; }
1206 ALWAYS_INLINE FlowThreadState flowThreadState() const { return static_cast<FlowThreadState>(m_flowThreadState); }
1207 ALWAYS_INLINE void setFlowThreadState(FlowThreadState flowThreadState) { m_flowThreadState = flowThreadState; }
1209 ALWAYS_INLINE BoxDecorationState boxDecorationState() const { return static_cast<BoxDecorationState>(m_boxDecorationState); }
1210 ALWAYS_INLINE void setBoxDecorationState(BoxDecorationState boxDecorationState) { m_boxDecorationState = boxDecorationState; }
1213 #undef ADD_BOOLEAN_BITFIELD
1215 RenderObjectBitfields m_bitfields;
1217 void setSelfNeedsLayout(bool b) { m_bitfields.setSelfNeedsLayout(b); }
1218 void setNeedsPositionedMovementLayout(bool b) { m_bitfields.setNeedsPositionedMovementLayout(b); }
1219 void setNormalChildNeedsLayout(bool b) { m_bitfields.setNormalChildNeedsLayout(b); }
1220 void setPosChildNeedsLayout(bool b) { m_bitfields.setPosChildNeedsLayout(b); }
1221 void setNeedsSimplifiedNormalFlowLayout(bool b) { m_bitfields.setNeedsSimplifiedNormalFlowLayout(b); }
1222 void setIsDragging(bool b) { m_bitfields.setIsDragging(b); }
1223 void setEverHadLayout(bool b) { m_bitfields.setEverHadLayout(b); }
1224 void setShouldRepaintOverflow(bool b) { m_bitfields.setShouldRepaintOverflow(b); }
1227 // Store state between styleWillChange and styleDidChange
1228 static bool s_affectsParentBlock;
1230 LayoutRect m_oldRepaintRect;
1231 LayoutRect m_newRepaintRect;
1234 // Allow equality comparisons of RenderObject's by reference or pointer, interchangeably.
1235 inline bool operator==(const RenderObject& a, const RenderObject& b) { return &a == &b; }
1236 inline bool operator==(const RenderObject& a, const RenderObject* b) { return &a == b; }
1237 inline bool operator==(const RenderObject* a, const RenderObject& b) { return a == &b; }
1238 inline bool operator!=(const RenderObject& a, const RenderObject& b) { return !(a == b); }
1239 inline bool operator!=(const RenderObject& a, const RenderObject* b) { return !(a == b); }
1240 inline bool operator!=(const RenderObject* a, const RenderObject& b) { return !(a == b); }
1242 inline bool RenderObject::documentBeingDestroyed() const
1244 return !document().renderer();
1247 inline bool RenderObject::isBeforeContent() const
1249 if (style()->styleType() != BEFORE)
1251 // Text nodes don't have their own styles, so ignore the style on a text node.
1252 if (isText() && !isBR())
1257 inline bool RenderObject::isAfterContent() const
1259 if (style()->styleType() != AFTER)
1261 // Text nodes don't have their own styles, so ignore the style on a text node.
1262 if (isText() && !isBR())
1267 inline bool RenderObject::isBeforeOrAfterContent() const
1269 return isBeforeContent() || isAfterContent();
1272 inline void RenderObject::setNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter)
1274 ASSERT(!isSetNeedsLayoutForbidden());
1275 bool alreadyNeededLayout = m_bitfields.selfNeedsLayout();
1276 setSelfNeedsLayout(true);
1277 if (!alreadyNeededLayout) {
1278 if (markParents == MarkContainingBlockChain && (!layouter || layouter->root() != this))
1279 markContainingBlocksForLayout(true, 0, layouter);
1281 setLayerNeedsFullRepaint();
1285 inline void RenderObject::clearNeedsLayout()
1287 setSelfNeedsLayout(false);
1288 setEverHadLayout(true);
1289 setPosChildNeedsLayout(false);
1290 setNeedsSimplifiedNormalFlowLayout(false);
1291 setNormalChildNeedsLayout(false);
1292 setNeedsPositionedMovementLayout(false);
1293 setAncestorLineBoxDirty(false);
1295 checkBlockPositionedObjectsNeedLayout();
1299 inline void RenderObject::setChildNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter)
1301 ASSERT(!isSetNeedsLayoutForbidden());
1302 bool alreadyNeededLayout = normalChildNeedsLayout();
1303 setNormalChildNeedsLayout(true);
1304 // FIXME: Replace MarkOnlyThis with the SubtreeLayoutScope code path and remove the MarkingBehavior argument entirely.
1305 if (!alreadyNeededLayout && markParents == MarkContainingBlockChain && (!layouter || layouter->root() != this))
1306 markContainingBlocksForLayout(true, 0, layouter);
1309 inline void RenderObject::setNeedsPositionedMovementLayout()
1311 bool alreadyNeededLayout = needsPositionedMovementLayout();
1312 setNeedsPositionedMovementLayout(true);
1313 ASSERT(!isSetNeedsLayoutForbidden());
1314 if (!alreadyNeededLayout) {
1315 markContainingBlocksForLayout();
1317 setLayerNeedsFullRepaintForPositionedMovementLayout();
1321 inline void RenderObject::setNeedsSimplifiedNormalFlowLayout()
1323 bool alreadyNeededLayout = needsSimplifiedNormalFlowLayout();
1324 setNeedsSimplifiedNormalFlowLayout(true);
1325 ASSERT(!isSetNeedsLayoutForbidden());
1326 if (!alreadyNeededLayout) {
1327 markContainingBlocksForLayout();
1329 setLayerNeedsFullRepaint();
1333 inline bool RenderObject::preservesNewline() const
1335 if (isSVGInlineText())
1338 return style()->preserveNewline();
1341 inline bool RenderObject::layerCreationAllowedForSubtree() const
1343 RenderObject* parentRenderer = parent();
1344 while (parentRenderer) {
1345 if (parentRenderer->isSVGHiddenContainer())
1347 parentRenderer = parentRenderer->parent();
1353 inline void RenderObject::setSelectionStateIfNeeded(SelectionState state)
1355 if (selectionState() == state)
1358 setSelectionState(state);
1361 inline void RenderObject::setHasBoxDecorations(bool b)
1364 m_bitfields.setBoxDecorationState(NoBoxDecorations);
1367 if (hasBoxDecorations())
1369 m_bitfields.setBoxDecorationState(HasBoxDecorationsAndBackgroundObscurationStatusInvalid);
1372 inline void RenderObject::invalidateBackgroundObscurationStatus()
1374 if (!hasBoxDecorations())
1376 m_bitfields.setBoxDecorationState(HasBoxDecorationsAndBackgroundObscurationStatusInvalid);
1379 inline bool RenderObject::backgroundIsKnownToBeObscured()
1381 if (m_bitfields.boxDecorationState() == HasBoxDecorationsAndBackgroundObscurationStatusInvalid) {
1382 BoxDecorationState boxDecorationState = computeBackgroundIsKnownToBeObscured() ? HasBoxDecorationsAndBackgroundIsKnownToBeObscured : HasBoxDecorationsAndBackgroundMayBeVisible;
1383 m_bitfields.setBoxDecorationState(boxDecorationState);
1385 return m_bitfields.boxDecorationState() == HasBoxDecorationsAndBackgroundIsKnownToBeObscured;
1388 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
1390 if (!has3DRendering)
1391 matrix.makeAffine();
1394 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
1396 return adjustForAbsoluteZoom(value, renderer->style());
1399 inline LayoutUnit adjustLayoutUnitForAbsoluteZoom(LayoutUnit value, RenderObject& renderer)
1401 ASSERT(renderer.style());
1402 return adjustLayoutUnitForAbsoluteZoom(value, *renderer.style());
1405 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject& renderer)
1407 float zoom = renderer.style()->effectiveZoom();
1409 quad.scale(1 / zoom, 1 / zoom);
1412 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject& renderer)
1414 float zoom = renderer.style()->effectiveZoom();
1416 rect.scale(1 / zoom, 1 / zoom);
1419 #define DEFINE_RENDER_OBJECT_TYPE_CASTS(thisType, predicate) \
1420 DEFINE_TYPE_CASTS(thisType, RenderObject, object, object->predicate, object.predicate)
1422 } // namespace WebCore
1425 // Outside the WebCore namespace for ease of invocation from gdb.
1426 void showTree(const WebCore::RenderObject*);
1427 void showLineTree(const WebCore::RenderObject*);
1428 void showRenderTree(const WebCore::RenderObject* object1);
1429 // We don't make object2 an optional parameter so that showRenderTree
1430 // can be called from gdb easily.
1431 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2);
1435 #endif // RenderObject_h