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 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef RenderObject_h
26 #define RenderObject_h
28 #include "CachedResourceClient.h"
29 #include "FloatQuad.h"
31 #include "RenderStyle.h"
32 #include "TransformationMatrix.h"
33 #include <wtf/UnusedParam.h>
35 #include "SelectionRect.h"
39 class AnimationController
;
47 class VisiblePosition
;
50 * The painting of a layer occurs in three distinct phases. Each phase involves
51 * a recursive descent into the layer's render objects. The first phase is the background phase.
52 * The backgrounds and borders of all blocks are painted. Inlines are not painted at all.
53 * Floats must paint above block backgrounds but entirely below inline content that can overlap them.
54 * In the foreground phase, all inlines are fully painted. Inline replaced elements will get all
55 * three phases invoked on them during this phase.
59 PaintPhaseBlockBackground
,
60 PaintPhaseChildBlockBackground
,
61 PaintPhaseChildBlockBackgrounds
,
65 PaintPhaseChildOutlines
,
66 PaintPhaseSelfOutline
,
68 PaintPhaseCollapsedTableBorders
,
73 enum PaintRestriction
{
75 PaintRestrictionSelectionOnly
,
76 PaintRestrictionSelectionOnlyBlackText
86 HitTestBlockBackground
,
87 HitTestChildBlockBackground
,
88 HitTestChildBlockBackgrounds
,
93 // Values for verticalPosition.
94 const int PositionTop
= -0x7fffffff;
95 const int PositionBottom
= 0x7fffffff;
96 const int PositionUndefined
= 0x80000000;
98 const int caretWidth
= 3;
100 #if ENABLE(DASHBOARD_SUPPORT)
101 struct DashboardRegionValue
{
102 bool operator==(const DashboardRegionValue
& o
) const
104 return type
== o
.type
&& bounds
== o
.bounds
&& clip
== o
.clip
&& label
== o
.label
;
106 bool operator!=(const DashboardRegionValue
& o
) const
108 return !(*this == o
);
118 // Base class for all rendering tree objects.
119 class RenderObject
: public CachedResourceClient
{
120 friend class RenderContainer
;
121 friend class RenderLayer
;
122 friend class RenderSVGContainer
;
124 // Anonymous objects should pass the document as their node, and they will then automatically be
125 // marked as anonymous in the constructor.
127 virtual ~RenderObject();
129 virtual const char* renderName() const { return "RenderObject"; }
131 RenderObject
* parent() const { return m_parent
; }
132 bool isDescendantOf(const RenderObject
*) const;
134 RenderObject
* previousSibling() const { return m_previous
; }
135 RenderObject
* nextSibling() const { return m_next
; }
137 virtual RenderObject
* firstChild() const { return 0; }
138 virtual RenderObject
* lastChild() const { return 0; }
140 RenderObject
* nextInPreOrder() const;
141 RenderObject
* nextInPreOrder(RenderObject
* stayWithin
) const;
142 RenderObject
* nextInPreOrderAfterChildren() const;
143 RenderObject
* nextInPreOrderAfterChildren(RenderObject
* stayWithin
) const;
144 RenderObject
* previousInPreOrder() const;
145 RenderObject
* childAt(unsigned) const;
147 RenderObject
* firstLeafChild() const;
148 RenderObject
* lastLeafChild() const;
150 RenderObject
*traverseNext(const RenderObject
*stayWithin
) const;
151 typedef bool (*TraverseNextInclusionFunction
)(const RenderObject
*);
152 RenderObject
*traverseNext(const RenderObject
*stayWithin
, TraverseNextInclusionFunction inclusionFunction
) const;
153 void adjustComputedFontSizesOnBlocks(float size
, float visibleWidth
);
154 void resetTextAutosizing();
156 // The following five functions are used when the render tree hierarchy changes to make sure layers get
157 // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
158 // can contain a mixture of boxes and other object types, these functions need to be in the base class.
159 RenderLayer
* enclosingLayer() const;
161 void addLayers(RenderLayer
* parentLayer
, RenderObject
* newObject
);
162 void removeLayers(RenderLayer
* parentLayer
);
163 void moveLayers(RenderLayer
* oldParent
, RenderLayer
* newParent
);
164 RenderLayer
* findNextLayer(RenderLayer
* parentLayer
, RenderObject
* startPoint
, bool checkParent
= true);
166 // Convenience function for getting to the nearest enclosing box of a RenderObject.
167 RenderBox
* enclosingBox() const;
169 virtual IntRect
getOverflowClipRect(int /*tx*/, int /*ty*/) { return IntRect(0, 0, 0, 0); }
170 virtual IntRect
getClipRect(int /*tx*/, int /*ty*/) { return IntRect(0, 0, 0, 0); }
171 bool hasClip() { return isPositioned() && style()->hasClip(); }
173 virtual int getBaselineOfFirstLineBox() const { return -1; }
174 virtual int getBaselineOfLastLineBox() const { return -1; }
176 virtual bool isEmpty() const { return firstChild() == 0; }
178 virtual bool isEdited() const { return false; }
179 virtual void setEdited(bool) { }
182 void setHasAXObject(bool flag
) { m_hasAXObject
= flag
; }
183 bool hasAXObject() const { return m_hasAXObject
; }
184 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden
; }
185 void setNeedsLayoutIsForbidden(bool flag
) { m_setNeedsLayoutForbidden
= flag
; }
188 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
190 virtual RenderBlock
* firstLineBlock() const;
192 // Called when an object that was floating or positioned becomes a normal flow object
193 // again. We have to make sure the render tree updates as needed to accommodate the new
194 // normal flow object.
195 void handleDynamicFloatPositionChange();
197 // This function is a convenience helper for creating an anonymous block that inherits its
198 // style from this RenderObject.
199 RenderBlock
* createAnonymousBlock();
201 // Whether or not a positioned element requires normal flow x/y to be computed
202 // to determine its position.
203 bool hasStaticX() const;
204 bool hasStaticY() const;
205 virtual void setStaticX(int /*staticX*/) { }
206 virtual void setStaticY(int /*staticY*/) { }
207 virtual int staticX() const { return 0; }
208 virtual int staticY() const { return 0; }
210 // RenderObject tree manipulation
211 //////////////////////////////////////////
212 virtual bool canHaveChildren() const;
213 virtual bool isChildAllowed(RenderObject
*, RenderStyle
*) const { return true; }
214 virtual void addChild(RenderObject
* newChild
, RenderObject
* beforeChild
= 0);
215 virtual void removeChild(RenderObject
*);
216 virtual bool createsAnonymousWrapper() const { return false; }
218 // raw tree manipulation
219 virtual RenderObject
* removeChildNode(RenderObject
*, bool fullRemove
= true);
220 virtual void appendChildNode(RenderObject
*, bool fullAppend
= true);
221 virtual void insertChildNode(RenderObject
* child
, RenderObject
* before
, bool fullInsert
= true);
222 // Designed for speed. Don't waste time doing a bunch of work like layer updating and repainting when we know that our
223 // change in parentage is not going to affect anything.
224 virtual void moveChildNode(RenderObject
*);
225 //////////////////////////////////////////
228 //////////////////////////////////////////
229 // Helper functions. Dangerous to use!
230 void setPreviousSibling(RenderObject
* previous
) { m_previous
= previous
; }
231 void setNextSibling(RenderObject
* next
) { m_next
= next
; }
232 void setParent(RenderObject
* parent
) { m_parent
= parent
; }
233 //////////////////////////////////////////
235 void addAbsoluteRectForLayer(IntRect
& result
);
239 void showTreeForThis() const;
242 static RenderObject
* createObject(Node
*, RenderStyle
*);
244 // Overloaded new operator. Derived classes must override operator new
245 // in order to allocate out of the RenderArena.
246 void* operator new(size_t, RenderArena
*) throw();
248 // Overridden to prevent the normal delete from being called.
249 void operator delete(void*, size_t);
252 // The normal operator new is disallowed on all render objects.
253 void* operator new(size_t) throw();
256 RenderArena
* renderArena() const { return document()->renderArena(); }
258 virtual bool isApplet() const { return false; }
259 virtual bool isBR() const { return false; }
260 virtual bool isBlockFlow() const { return false; }
261 virtual bool isBoxModelObject() const { return false; }
262 virtual bool isCounter() const { return false; }
263 virtual bool isFieldset() const { return false; }
264 virtual bool isFrame() const { return false; }
265 virtual bool isFrameSet() const { return false; }
266 virtual bool isImage() const { return false; }
267 virtual bool isInlineBlockOrInlineTable() const { return false; }
268 virtual bool isInlineContinuation() const;
269 virtual bool isListBox() const { return false; }
270 virtual bool isListItem() const { return false; }
271 virtual bool isListMarker() const { return false; }
272 virtual bool isMedia() const { return false; }
273 virtual bool isMenuList() const { return false; }
274 virtual bool isRenderBlock() const { return false; }
275 virtual bool isRenderImage() const { return false; }
276 virtual bool isRenderInline() const { return false; }
277 virtual bool isRenderPart() const { return false; }
278 virtual bool isRenderView() const { return false; }
279 virtual bool isSlider() const { return false; }
280 virtual bool isTable() const { return false; }
281 virtual bool isTableCell() const { return false; }
282 virtual bool isTableCol() const { return false; }
283 virtual bool isTableRow() const { return false; }
284 virtual bool isTableSection() const { return false; }
285 virtual bool isTextArea() const { return false; }
286 virtual bool isTextField() const { return false; }
287 virtual bool isWidget() const { return false; }
289 bool isRoot() const { return document()->documentElement() == node(); }
293 bool isHTMLMarquee() const;
295 virtual bool childrenInline() const { return false; }
296 virtual void setChildrenInline(bool) { }
298 virtual RenderFlow
* virtualContinuation() const { return 0; }
301 virtual bool isSVGRoot() const { return false; }
302 virtual bool isSVGContainer() const { return false; }
303 virtual bool isSVGHiddenContainer() const { return false; }
304 virtual bool isRenderPath() const { return false; }
305 virtual bool isSVGText() const { return false; }
307 virtual FloatRect
relativeBBox(bool includeStroke
= true) const;
309 virtual TransformationMatrix
localTransform() const;
310 virtual TransformationMatrix
absoluteTransform() const;
313 virtual bool isEditable() const;
315 bool isAnonymous() const { return m_isAnonymous
; }
316 void setIsAnonymous(bool b
) { m_isAnonymous
= b
; }
317 bool isAnonymousBlock() const
319 return m_isAnonymous
&& style()->display() == BLOCK
&& style()->styleType() == RenderStyle::NOPSEUDO
&& !isListMarker();
322 bool isFloating() const { return m_floating
; }
323 bool isPositioned() const { return m_positioned
; } // absolute or fixed positioning
324 bool isRelPositioned() const { return m_relPositioned
; } // relative positioning
325 bool isText() const { return m_isText
; }
326 bool isBox() const { return m_isBox
; }
327 bool isInline() const { return m_inline
; } // inline object
328 bool isRunIn() const { return style()->display() == RUN_IN
; } // run-in object
329 bool isDragging() const { return m_isDragging
; }
330 bool isReplaced() const { return m_replaced
; } // a "replaced" element (see CSS)
332 bool hasLayer() const { return m_hasLayer
; }
334 bool hasBoxDecorations() const { return m_paintBackground
; }
335 bool mustRepaintBackgroundOrBorder() const;
337 bool needsLayout() const { return m_needsLayout
|| m_normalChildNeedsLayout
|| m_posChildNeedsLayout
|| m_needsPositionedMovementLayout
; }
338 bool selfNeedsLayout() const { return m_needsLayout
; }
339 bool needsPositionedMovementLayout() const { return m_needsPositionedMovementLayout
; }
340 bool needsPositionedMovementLayoutOnly() const { return m_needsPositionedMovementLayout
&& !m_needsLayout
&& !m_normalChildNeedsLayout
&& !m_posChildNeedsLayout
; }
341 bool posChildNeedsLayout() const { return m_posChildNeedsLayout
; }
342 bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout
; }
344 bool prefWidthsDirty() const { return m_prefWidthsDirty
; }
346 bool isSelectionBorder() const;
348 bool hasOverflowClip() const { return m_hasOverflowClip
; }
349 virtual bool hasControlClip() const { return false; }
350 virtual IntRect
controlClipRect(int /*tx*/, int /*ty*/) const { return IntRect(); }
352 bool hasTransform() const { return m_hasTransform
; }
353 bool hasMask() const { return style() && style()->hasMask(); }
356 // The pseudo element style can be cached or uncached. Use the cached method if the pseudo element doesn't respect
357 // any pseudo classes (and therefore has no concept of changing state).
358 RenderStyle
* getCachedPseudoStyle(RenderStyle::PseudoId
, RenderStyle
* parentStyle
= 0) const;
359 PassRefPtr
<RenderStyle
> getUncachedPseudoStyle(RenderStyle::PseudoId
, RenderStyle
* parentStyle
= 0) const;
361 void updateDragState(bool dragOn
);
363 RenderView
* view() const;
365 // don't even think about making this method virtual!
366 Node
* element() const { return m_isAnonymous
? 0 : m_node
; }
367 Document
* document() const { return m_node
->document(); }
368 void setNode(Node
* node
) { m_node
= node
; }
369 Node
* node() const { return m_node
; }
371 bool hasOutlineAnnotation() const;
372 bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
375 * returns the object containing this one. can be different from parent for
376 * positioned elements
378 RenderObject
* container() const;
379 RenderObject
* hoverAncestor() const;
381 void markContainingBlocksForLayout(bool scheduleRelayout
= true, RenderObject
* newRoot
= 0);
382 void setNeedsLayout(bool b
, bool markParents
= true);
383 void setChildNeedsLayout(bool b
, bool markParents
= true);
384 void setNeedsPositionedMovementLayout();
385 void setPrefWidthsDirty(bool, bool markParents
= true);
386 void invalidateContainerPrefWidths();
387 virtual void invalidateCounters() { }
389 void setNeedsLayoutAndPrefWidthsRecalc()
391 setNeedsLayout(true);
392 setPrefWidthsDirty(true);
395 void setPositioned(bool b
= true) { m_positioned
= b
; }
396 void setRelPositioned(bool b
= true) { m_relPositioned
= b
; }
397 void setFloating(bool b
= true) { m_floating
= b
; }
398 void setInline(bool b
= true) { m_inline
= b
; }
399 void setHasBoxDecorations(bool b
= true) { m_paintBackground
= b
; }
400 void setIsText() { m_isText
= true; }
401 void setIsBox() { m_isBox
= true; }
402 void setReplaced(bool b
= true) { m_replaced
= b
; }
403 void setHasOverflowClip(bool b
= true) { m_hasOverflowClip
= b
; }
404 void setHasLayer(bool b
= true) { m_hasLayer
= b
; }
405 void setHasTransform(bool b
= true) { m_hasTransform
= b
; }
406 void setHasReflection(bool b
= true) { m_hasReflection
= b
; }
408 void scheduleRelayout();
410 void updateFillImages(const FillLayer
*, const FillLayer
*);
411 void updateImage(StyleImage
*, StyleImage
*);
413 virtual InlineBox
* createInlineBox(bool makePlaceHolderBox
, bool isRootLineBox
, bool isOnlyRun
= false);
414 virtual void dirtyLineBoxes(bool fullLayout
, bool isRootLineBox
= false);
416 // for discussion of lineHeight see CSS2 spec
417 virtual int lineHeight(bool firstLine
, bool isRootLineBox
= false) const;
418 // for the vertical-align property of inline elements
419 // the difference between this objects baseline position and the lines baseline position.
420 virtual int verticalPositionHint(bool firstLine
) const;
421 // the offset of baseline from the top of the object.
422 virtual int baselinePosition(bool firstLine
, bool isRootLineBox
= false) const;
424 // Hook so that RenderTextControl can return the line height of its inner renderer.
425 // For other renderers, the value is the same as lineHeight(false).
426 virtual int innerLineHeight() const;
429 * Paint the object and its children, clipped by (x|y|w|h).
430 * (tx|ty) is the calculated position of the parent
433 PaintInfo(GraphicsContext
* newContext
, const IntRect
& newRect
, PaintPhase newPhase
, bool newForceBlackText
,
434 RenderObject
* newPaintingRoot
, ListHashSet
<RenderFlow
*>* newOutlineObjects
)
435 : context(newContext
)
438 , forceBlackText(newForceBlackText
)
439 , paintingRoot(newPaintingRoot
)
440 , outlineObjects(newOutlineObjects
)
444 GraphicsContext
* context
;
448 RenderObject
* paintingRoot
; // used to draw just one element and its visual kids
449 ListHashSet
<RenderFlow
*>* outlineObjects
; // used to list outlines that should be painted by a block with inline children
452 virtual void paint(PaintInfo
&, int tx
, int ty
);
453 void paintBorder(GraphicsContext
*, int tx
, int ty
, int w
, int h
, const RenderStyle
*, bool begin
= true, bool end
= true);
454 bool paintNinePieceImage(GraphicsContext
*, int tx
, int ty
, int w
, int h
, const RenderStyle
*, const NinePieceImage
&, CompositeOperator
= CompositeSourceOver
);
455 void paintBoxShadow(GraphicsContext
*, int tx
, int ty
, int w
, int h
, const RenderStyle
*, bool begin
= true, bool end
= true);
457 // RenderBox implements this.
458 virtual void paintBoxDecorations(PaintInfo
&, int /*tx*/, int /*ty*/) { }
459 virtual void paintMask(PaintInfo
&, int /*tx*/, int /*ty*/) { }
460 virtual void paintFillLayerExtended(const PaintInfo
&, const Color
&, const FillLayer
*,
461 int /*clipY*/, int /*clipH*/, int /*tx*/, int /*ty*/, int /*width*/, int /*height*/,
462 InlineFlowBox
* = 0, CompositeOperator
= CompositeSourceOver
) { }
465 * Calculates the actual width of the object (only for non inline
468 virtual void calcWidth() { }
471 * This function should cause the Element to calculate its
472 * width and height and the layout of its content
474 * when the Element calls setNeedsLayout(false), layout() is no
475 * longer called during relayouts, as long as there is no
476 * style sheet change. When that occurs, m_needsLayout will be
477 * set to true and the Element receives layout() calls
480 virtual void layout() = 0;
482 /* This function performs a layout only if one is needed. */
483 void layoutIfNeeded() { if (needsLayout()) layout(); }
485 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
486 // that just updates the object's position. If the size does change, the object remains dirty.
487 virtual void tryLayoutDoingPositionedMovementOnly() { }
489 // used for element state updates that cannot be fixed with a
490 // repaint and do not need a relayout
491 virtual void updateFromElement() { }
493 virtual void updateWidgetPosition();
495 #if ENABLE(DASHBOARD_SUPPORT)
496 void addDashboardRegions(Vector
<DashboardRegionValue
>&);
497 void collectDashboardRegions(Vector
<DashboardRegionValue
>&);
500 bool hitTest(const HitTestRequest
&, HitTestResult
&, const IntPoint
&, int tx
, int ty
, HitTestFilter
= HitTestAll
);
501 virtual bool nodeAtPoint(const HitTestRequest
&, HitTestResult
&, int x
, int y
, int tx
, int ty
, HitTestAction
);
502 void updateHitTestResult(HitTestResult
&, const IntPoint
&);
504 virtual VisiblePosition
positionForCoordinates(int x
, int y
);
505 VisiblePosition
positionForPoint(const IntPoint
&);
507 virtual void dirtyLinesFromChangedChild(RenderObject
*);
509 // Called to update a style that is allowed to trigger animations.
510 // FIXME: Right now this will typically be called only when updating happens from the DOM on explicit elements.
511 // We don't yet handle generated content animation such as first-letter or before/after (we'll worry about this later).
512 void setAnimatableStyle(PassRefPtr
<RenderStyle
>);
514 // Set the style of the object and update the state of the object accordingly.
515 virtual void setStyle(PassRefPtr
<RenderStyle
>);
517 // Updates only the local style ptr of the object. Does not update the state of the object,
518 // and so only should be called when the style is known not to have changed (or from setStyle).
519 void setStyleInternal(PassRefPtr
<RenderStyle
>);
521 // returns the containing block level element for this element.
522 RenderBlock
* containingBlock() const;
524 // return just the width of the containing block
525 virtual int containingBlockWidth() const;
526 // return just the height of the containing block
527 virtual int containingBlockHeight() const;
529 // used by flexible boxes to impose a flexed width/height override
530 virtual int overrideSize() const { return 0; }
531 virtual int overrideWidth() const { return 0; }
532 virtual int overrideHeight() const { return 0; }
533 virtual void setOverrideSize(int /*overrideSize*/) { }
535 // Convert the given local point to absolute coordinates
536 // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
537 FloatPoint
localToAbsolute(FloatPoint localPoint
= FloatPoint(), bool fixed
= false, bool useTransforms
= false) const;
538 FloatPoint
absoluteToLocal(FloatPoint
, bool fixed
= false, bool useTransforms
= false) const;
540 // Convert a local quad to absolute coordinates, taking transforms into account.
541 FloatQuad
localToAbsoluteQuad(const FloatQuad
& quad
, bool fixed
= false) const
543 return localToContainerQuad(quad
, 0, fixed
);
545 // Convert a local quad into the coordinate system of container, taking transforms into account.
546 FloatQuad
localToContainerQuad(const FloatQuad
&, RenderBox
* repaintContainer
, bool fixed
= false) const;
548 // Return the offset from the container() renderer (excluding transforms)
549 virtual IntSize
offsetFromContainer(RenderObject
*) const;
551 virtual void addLineBoxRects(Vector
<IntRect
>&, unsigned startOffset
= 0, unsigned endOffset
= UINT_MAX
, bool useSelectionHeight
= false);
552 virtual void collectSelectionRects(Vector
<SelectionRect
>&, unsigned startOffset
= 0, unsigned endOffset
= UINT_MAX
);
554 virtual void absoluteRects(Vector
<IntRect
>&, int, int, bool = true) { }
555 // FIXME: useTransforms should go away eventually
556 IntRect
absoluteBoundingBoxRect(bool useTransforms
= false);
558 // Build an array of quads in absolute coords for line boxes
559 virtual void collectAbsoluteLineBoxQuads(Vector
<FloatQuad
>&, unsigned /*startOffset*/ = 0, unsigned /*endOffset*/ = UINT_MAX
, bool /*useSelectionHeight*/ = false) { }
560 virtual void absoluteQuads(Vector
<FloatQuad
>&, bool /*topLevel*/ = true) { }
562 // the rect that will be painted if this object is passed as the paintingRoot
563 IntRect
paintingRootRect(IntRect
& topLevelRect
);
565 virtual int minPrefWidth() const { return 0; }
566 virtual int maxPrefWidth() const { return 0; }
568 RenderStyle
* style() const { return m_style
.get(); }
569 RenderStyle
* firstLineStyle() const;
570 RenderStyle
* style(bool firstLine
) const { return firstLine
? firstLineStyle() : style(); }
572 void getTextDecorationColors(int decorations
, Color
& underline
, Color
& overline
,
573 Color
& linethrough
, bool quirksMode
= false);
582 void drawBorderArc(GraphicsContext
*, int x
, int y
, float thickness
, IntSize radius
, int angleStart
,
583 int angleSpan
, BorderSide
, Color
, const Color
& textcolor
, EBorderStyle
, bool firstCorner
);
584 void drawBorder(GraphicsContext
*, int x1
, int y1
, int x2
, int y2
, BorderSide
,
585 Color
, const Color
& textcolor
, EBorderStyle
, int adjbw1
, int adjbw2
);
587 // Return the RenderBox in the container chain which is responsible for painting this object, or 0
588 // if painting is root-relative. This is the container that should be passed to the 'forRepaint'
590 RenderBox
* containerForRepaint() const;
591 // Actually do the repaint of rect r for this object which has been computed in the coordinate space
592 // of repaintContainer. If repaintContainer is 0, repaint via the view.
593 void repaintUsingContainer(RenderBox
* repaintContainer
, const IntRect
& r
, bool immediate
= false);
595 // Repaint the entire object. Called when, e.g., the color of a border changes, or when a border
597 void repaint(bool immediate
= false);
599 // Repaint a specific subrectangle within a given object. The rect |r| is in the object's coordinate space.
600 void repaintRectangle(const IntRect
&, bool immediate
= false);
602 // Repaint only if our old bounds and new bounds are different.
603 bool repaintAfterLayoutIfNeeded(RenderBox
* repaintContainer
, const IntRect
& oldBounds
, const IntRect
& oldOutlineBox
);
605 // Repaint only if the object moved.
606 virtual void repaintDuringLayoutIfMoved(const IntRect
& rect
);
608 // Called to repaint a block's floats.
609 virtual void repaintOverhangingFloats(bool paintAllDescendants
= false);
611 bool checkForRepaintDuringLayout() const;
613 // Returns the rect that should be repainted whenever this object changes. The rect is in the view's
614 // coordinate space. This method deals with outlines and overflow.
615 IntRect
absoluteClippedOverflowRect()
617 return clippedOverflowRectForRepaint(0);
619 virtual IntRect
clippedOverflowRectForRepaint(RenderBox
* repaintContainer
);
621 IntRect
rectWithOutlineForRepaint(RenderBox
* repaintContainer
, int outlineWidth
);
623 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
624 // that rect in view coordinates.
625 void computeAbsoluteRepaintRect(IntRect
& r
, bool fixed
= false)
627 return computeRectForRepaint(0, r
, fixed
);
629 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
630 // that rect in the coordinate space of repaintContainer.
631 virtual void computeRectForRepaint(RenderBox
* repaintContainer
, IntRect
&, bool fixed
= false);
633 virtual unsigned int length() const { return 1; }
635 bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); }
636 virtual bool containsFloats() { return false; }
637 virtual bool containsFloat(RenderObject
*) { return false; }
638 virtual bool hasOverhangingFloats() { return false; }
640 virtual bool avoidsFloats() const;
641 bool shrinkToAvoidFloats() const;
643 // positioning of inline children (bidi)
644 virtual void position(InlineBox
*) { }
646 bool isTransparent() const { return style()->opacity() < 1.0f
; }
647 float opacity() const { return style()->opacity(); }
649 bool hasReflection() const { return m_hasReflection
; }
651 // Applied as a "slop" to dirty rect checks during the outline painting phase's dirty-rect checks.
652 int maximalOutlineSize(PaintPhase
) const;
654 enum SelectionState
{
655 SelectionNone
, // The object is not selected.
656 SelectionStart
, // The object either contains the start of a selection run or is the start of a run
657 SelectionInside
, // The object is fully encompassed by a selection run
658 SelectionEnd
, // The object either contains the end of a selection run or is the end of a run
659 SelectionBoth
// The object contains an entire run or is the sole selected object in that run
662 // The current selection state for an object. For blocks, the state refers to the state of the leaf
663 // descendants (as described above in the SelectionState enum declaration).
664 virtual SelectionState
selectionState() const { return SelectionNone
; }
666 // Sets the selection state for an object.
667 virtual void setSelectionState(SelectionState state
) { if (parent()) parent()->setSelectionState(state
); }
669 // A single rectangle that encompasses all of the selected objects within this object. Used to determine the tightest
670 // possible bounding box for the selection.
671 IntRect
selectionRect(bool clipToVisibleContent
= true) { return selectionRectForRepaint(0, clipToVisibleContent
); }
672 virtual IntRect
selectionRectForRepaint(RenderBox
* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return IntRect(); }
674 // Whether or not an object can be part of the leaf elements of the selection.
675 virtual bool canBeSelectionLeaf() const { return false; }
677 // Whether or not a block has selected children.
678 virtual bool hasSelectedChildren() const { return false; }
680 // Obtains the selection colors that should be used when painting a selection.
681 Color
selectionBackgroundColor() const;
682 Color
selectionForegroundColor() const;
684 // Whether or not a given block needs to paint selection gaps.
685 virtual bool shouldPaintSelectionGaps() const { return false; }
687 Node
* draggableNode(bool dhtmlOK
, bool uaOK
, int x
, int y
, bool& dhtmlWillDrag
) const;
690 * Returns the local coordinates of the caret within this render object.
691 * @param caretOffset zero-based offset determining position within the render object.
692 * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
693 * useful for character range rect computations
695 virtual IntRect
localCaretRect(InlineBox
*, int caretOffset
, int* extraWidthToEndOfLine
= 0);
697 virtual int lowestPosition(bool /*includeOverflowInterior*/ = true, bool /*includeSelf*/ = true) const { return 0; }
698 virtual int rightmostPosition(bool /*includeOverflowInterior*/ = true, bool /*includeSelf*/ = true) const { return 0; }
699 virtual int leftmostPosition(bool /*includeOverflowInterior*/ = true, bool /*includeSelf*/ = true) const { return 0; }
701 virtual void calcVerticalMargins() { }
702 void removeFromObjectLists();
704 // When performing a global document tear-down, the renderer of the document is cleared. We use this
705 // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
706 bool documentBeingDestroyed() const;
708 virtual void destroy();
710 // Virtual function helpers for CSS3 Flexible Box Layout
711 virtual bool isFlexibleBox() const { return false; }
712 virtual bool isFlexingChildren() const { return false; }
713 virtual bool isStretchingChildren() const { return false; }
715 virtual int caretMinOffset() const;
716 virtual int caretMaxOffset() const;
717 virtual unsigned caretMaxRenderedOffset() const;
719 virtual int previousOffset(int current
) const;
720 virtual int nextOffset(int current
) const;
722 virtual void imageChanged(CachedImage
*, const IntRect
* = 0);
723 virtual void imageChanged(WrappedImagePtr
, const IntRect
* = 0) { }
724 virtual bool willRenderImage(CachedImage
*);
726 virtual void selectionStartEnd(int& spos
, int& epos
) const;
728 RenderObject
* paintingRootForChildren(PaintInfo
& paintInfo
) const
730 // if we're the painting root, kids draw normally, and see root of 0
731 return (!paintInfo
.paintingRoot
|| paintInfo
.paintingRoot
== this) ? 0 : paintInfo
.paintingRoot
;
734 bool shouldPaintWithinRoot(PaintInfo
& paintInfo
) const
736 return !paintInfo
.paintingRoot
|| paintInfo
.paintingRoot
== this;
739 bool hasOverrideSize() const { return m_hasOverrideSize
; }
740 void setHasOverrideSize(bool b
) { m_hasOverrideSize
= b
; }
742 void remove() { if (parent()) parent()->removeChild(this); }
744 void invalidateVerticalPosition() { m_verticalPosition
= PositionUndefined
; }
746 virtual void removeLeftoverAnonymousBlock(RenderBlock
* child
);
748 virtual void capsLockStateMayHaveChanged() { }
750 AnimationController
* animation() const;
752 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE
&& style()->pointerEvents() != PE_NONE
; }
754 // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
755 // localToAbsolute/absoluteToLocal methods instead.
756 virtual void mapLocalToContainer(RenderBox
* repaintContainer
, bool useTransforms
, bool fixed
, TransformState
&) const;
757 virtual void mapAbsoluteToLocalPoint(bool fixed
, bool useTransforms
, TransformState
&) const;
759 bool shouldUseTransformFromContainer(const RenderObject
* container
) const;
760 void getTransformFromContainer(const RenderObject
* container
, const IntSize
& offsetInContainer
, TransformationMatrix
&) const;
762 virtual void addFocusRingRects(GraphicsContext
*, int /*tx*/, int /*ty*/) { };
764 IntRect
absoluteOutlineBounds() const
766 return outlineBoundsForRepaint(0);
770 // Overrides should call the superclass at the end
771 virtual void styleWillChange(StyleDifference
, const RenderStyle
* newStyle
);
772 // Overrides should call the superclass at the start
773 virtual void styleDidChange(StyleDifference
, const RenderStyle
* oldStyle
);
775 virtual void printBoxDecorations(GraphicsContext
*, int /*x*/, int /*y*/, int /*w*/, int /*h*/, int /*tx*/, int /*ty*/) { }
777 void paintOutline(GraphicsContext
*, int tx
, int ty
, int w
, int h
, const RenderStyle
*);
778 void addPDFURLRect(GraphicsContext
*, const IntRect
&);
780 virtual IntRect
viewRect() const;
782 int getVerticalPosition(bool firstLine
) const;
784 void adjustRectForOutlineAndShadow(IntRect
&) const;
786 void arenaDelete(RenderArena
*, void* objectBase
);
788 virtual IntRect
outlineBoundsForRepaint(RenderBox
* /*repaintContainer*/) const { return IntRect(); }
790 class LayoutRepainter
{
792 LayoutRepainter(RenderObject
& object
, bool checkForRepaint
, const IntRect
* oldBounds
= 0)
794 , m_repaintContainer(0)
795 , m_checkForRepaint(checkForRepaint
)
797 if (m_checkForRepaint
) {
798 m_repaintContainer
= m_object
.containerForRepaint();
799 m_oldBounds
= oldBounds
? *oldBounds
: m_object
.clippedOverflowRectForRepaint(m_repaintContainer
);
800 m_oldOutlineBox
= m_object
.outlineBoundsForRepaint(m_repaintContainer
);
804 // Return true if it repainted.
805 bool repaintAfterLayout()
807 return m_checkForRepaint
? m_object
.repaintAfterLayoutIfNeeded(m_repaintContainer
, m_oldBounds
, m_oldOutlineBox
) : false;
810 bool checkForRepaint() const { return m_checkForRepaint
; }
813 RenderObject
& m_object
;
814 RenderBox
* m_repaintContainer
;
816 IntRect m_oldOutlineBox
;
817 bool m_checkForRepaint
;
821 StyleDifference
adjustStyleDifference(StyleDifference
, unsigned contextSensitiveProperties
) const;
823 RefPtr
<RenderStyle
> m_style
;
827 RenderObject
* m_parent
;
828 RenderObject
* m_previous
;
829 RenderObject
* m_next
;
833 bool m_setNeedsLayoutForbidden
: 1;
835 mutable int m_verticalPosition
;
837 bool m_needsLayout
: 1;
838 bool m_needsPositionedMovementLayout
:1;
839 bool m_normalChildNeedsLayout
: 1;
840 bool m_posChildNeedsLayout
: 1;
841 bool m_prefWidthsDirty
: 1;
844 bool m_positioned
: 1;
845 bool m_relPositioned
: 1;
846 bool m_paintBackground
: 1; // if the box has something to paint in the
847 // background painting phase (background, border, etc)
849 bool m_isAnonymous
: 1;
854 bool m_isDragging
: 1;
857 bool m_hasOverflowClip
: 1;
858 bool m_hasTransform
: 1;
859 bool m_hasReflection
: 1;
861 bool m_hasOverrideSize
: 1;
864 bool m_hasCounterNodeMap
: 1;
865 bool m_everHadLayout
: 1;
868 // Store state between styleWillChange and styleDidChange
869 static bool s_affectsParentBlock
;
872 inline void makeMatrixRenderable(TransformationMatrix
& matrix
)
874 #if !ENABLE(3D_RENDERING)
877 UNUSED_PARAM(matrix
);
881 } // namespace WebCore
884 // Outside the WebCore namespace for ease of invocation from gdb.
885 void showTree(const WebCore::RenderObject
*);
888 #endif // RenderObject_h