1 /*
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.
7 *
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.
12 *
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.
17 *
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.
22 *
23 */
24
25 #ifndef RenderObject_h
26 #define RenderObject_h
27
28 #include "CachedResourceClient.h"
29 #include "Document.h"
30 #include "Element.h"
31 #include "FloatQuad.h"
32 #include "RenderObjectChildList.h"
33 #include "RenderStyle.h"
34 #include "TextAffinity.h"
35 #include "TransformationMatrix.h"
36 #include <wtf/UnusedParam.h>
37
38 namespace WebCore {
39
40 class AnimationController;
41 class HitTestResult;
42 class InlineBox;
43 class InlineFlowBox;
44 class OverlapTestRequestClient;
45 class Position;
46 class RenderBoxModelObject;
47 class RenderInline;
48 class RenderBlock;
49 class RenderFlow;
50 class RenderLayer;
51 class RenderTheme;
52 class TransformState;
53 class VisiblePosition;
54
55 /*
56 * The painting of a layer occurs in three distinct phases. Each phase involves
57 * a recursive descent into the layer's render objects. The first phase is the background phase.
58 * The backgrounds and borders of all blocks are painted. Inlines are not painted at all.
59 * Floats must paint above block backgrounds but entirely below inline content that can overlap them.
60 * In the foreground phase, all inlines are fully painted. Inline replaced elements will get all
61 * three phases invoked on them during this phase.
62 */
63
64 enum PaintPhase {
65 PaintPhaseBlockBackground,
66 PaintPhaseChildBlockBackground,
67 PaintPhaseChildBlockBackgrounds,
68 PaintPhaseFloat,
69 PaintPhaseForeground,
70 PaintPhaseOutline,
71 PaintPhaseChildOutlines,
72 PaintPhaseSelfOutline,
73 PaintPhaseSelection,
74 PaintPhaseCollapsedTableBorders,
75 PaintPhaseTextClip,
76 PaintPhaseMask
77 };
78
79 enum PaintRestriction {
80 PaintRestrictionNone,
81 PaintRestrictionSelectionOnly,
82 PaintRestrictionSelectionOnlyBlackText
83 };
84
85 enum HitTestFilter {
86 HitTestAll,
87 HitTestSelf,
88 HitTestDescendants
89 };
90
91 enum HitTestAction {
92 HitTestBlockBackground,
93 HitTestChildBlockBackground,
94 HitTestChildBlockBackgrounds,
95 HitTestFloat,
96 HitTestForeground
97 };
98
99 // Sides used when drawing borders and outlines. This is in RenderObject rather than RenderBoxModelObject since outlines can
100 // be drawn by SVG around bounding boxes.
101 enum BoxSide {
102 BSTop,
103 BSBottom,
104 BSLeft,
105 BSRight
106 };
107
108 const int caretWidth = 1;
109
110 #if ENABLE(DASHBOARD_SUPPORT)
111 struct DashboardRegionValue {
112 bool operator==(const DashboardRegionValue& o) const
113 {
114 return type == o.type && bounds == o.bounds && clip == o.clip && label == o.label;
115 }
116 bool operator!=(const DashboardRegionValue& o) const
117 {
118 return !(*this == o);
119 }
120
121 String label;
122 IntRect bounds;
123 IntRect clip;
124 int type;
125 };
126 #endif
127
128 // Base class for all rendering tree objects.
129 class RenderObject : public CachedResourceClient {
130 friend class RenderBlock;
131 friend class RenderBox;
132 friend class RenderLayer;
133 friend class RenderObjectChildList;
134 friend class RenderSVGContainer;
135 public:
136 // Anonymous objects should pass the document as their node, and they will then automatically be
137 // marked as anonymous in the constructor.
138 RenderObject(Node*);
139 virtual ~RenderObject();
140
141 RenderTheme* theme() const;
142
143 virtual const char* renderName() const = 0;
144
parent()145 RenderObject* parent() const { return m_parent; }
146 bool isDescendantOf(const RenderObject*) const;
147
previousSibling()148 RenderObject* previousSibling() const { return m_previous; }
nextSibling()149 RenderObject* nextSibling() const { return m_next; }
150
firstChild()151 RenderObject* firstChild() const
152 {
153 if (const RenderObjectChildList* children = virtualChildren())
154 return children->firstChild();
155 return 0;
156 }
lastChild()157 RenderObject* lastChild() const
158 {
159 if (const RenderObjectChildList* children = virtualChildren())
160 return children->lastChild();
161 return 0;
162 }
virtualChildren()163 virtual RenderObjectChildList* virtualChildren() { return 0; }
virtualChildren()164 virtual const RenderObjectChildList* virtualChildren() const { return 0; }
165
166 RenderObject* nextInPreOrder() const;
167 RenderObject* nextInPreOrder(RenderObject* stayWithin) const;
168 RenderObject* nextInPreOrderAfterChildren() const;
169 RenderObject* nextInPreOrderAfterChildren(RenderObject* stayWithin) const;
170 RenderObject* previousInPreOrder() const;
171 RenderObject* childAt(unsigned) const;
172
173 RenderObject* firstLeafChild() const;
174 RenderObject* lastLeafChild() const;
175
176 // The following six functions are used when the render tree hierarchy changes to make sure layers get
177 // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
178 // can contain a mixture of boxes and other object types, these functions need to be in the base class.
179 RenderLayer* enclosingLayer() const;
180 RenderLayer* enclosingSelfPaintingLayer() const;
181 void addLayers(RenderLayer* parentLayer, RenderObject* newObject);
182 void removeLayers(RenderLayer* parentLayer);
183 void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
184 RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
185
186 // Convenience function for getting to the nearest enclosing box of a RenderObject.
187 RenderBox* enclosingBox() const;
188
isEmpty()189 virtual bool isEmpty() const { return firstChild() == 0; }
190
191 #ifndef NDEBUG
setHasAXObject(bool flag)192 void setHasAXObject(bool flag) { m_hasAXObject = flag; }
hasAXObject()193 bool hasAXObject() const { return m_hasAXObject; }
isSetNeedsLayoutForbidden()194 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; }
setNeedsLayoutIsForbidden(bool flag)195 void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; }
196 #endif
197
198 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
199 // children.
200 virtual RenderBlock* firstLineBlock() const;
201
202 // Called when an object that was floating or positioned becomes a normal flow object
203 // again. We have to make sure the render tree updates as needed to accommodate the new
204 // normal flow object.
205 void handleDynamicFloatPositionChange();
206
207 // RenderObject tree manipulation
208 //////////////////////////////////////////
canHaveChildren()209 virtual bool canHaveChildren() const { return virtualChildren(); }
isChildAllowed(RenderObject *,RenderStyle *)210 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
211 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
212 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); }
213 virtual void removeChild(RenderObject*);
createsAnonymousWrapper()214 virtual bool createsAnonymousWrapper() const { return false; }
215 //////////////////////////////////////////
216
217 protected:
218 //////////////////////////////////////////
219 // Helper functions. Dangerous to use!
setPreviousSibling(RenderObject * previous)220 void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
setNextSibling(RenderObject * next)221 void setNextSibling(RenderObject* next) { m_next = next; }
setParent(RenderObject * parent)222 void setParent(RenderObject* parent) { m_parent = parent; }
223 //////////////////////////////////////////
224 private:
225 void addAbsoluteRectForLayer(IntRect& result);
226 void setLayerNeedsFullRepaint();
227
228 public:
229 #ifndef NDEBUG
230 void showTreeForThis() const;
231 #endif
232
233 static RenderObject* createObject(Node*, RenderStyle*);
234
235 // Overloaded new operator. Derived classes must override operator new
236 // in order to allocate out of the RenderArena.
237 void* operator new(size_t, RenderArena*) throw();
238
239 // Overridden to prevent the normal delete from being called.
240 void operator delete(void*, size_t);
241
242 private:
243 // The normal operator new is disallowed on all render objects.
244 void* operator new(size_t) throw();
245
246 public:
renderArena()247 RenderArena* renderArena() const { return document()->renderArena(); }
248
isApplet()249 virtual bool isApplet() const { return false; }
isBR()250 virtual bool isBR() const { return false; }
isBlockFlow()251 virtual bool isBlockFlow() const { return false; }
isBoxModelObject()252 virtual bool isBoxModelObject() const { return false; }
isCounter()253 virtual bool isCounter() const { return false; }
isFieldset()254 virtual bool isFieldset() const { return false; }
isFrame()255 virtual bool isFrame() const { return false; }
isFrameSet()256 virtual bool isFrameSet() const { return false; }
isImage()257 virtual bool isImage() const { return false; }
isInlineBlockOrInlineTable()258 virtual bool isInlineBlockOrInlineTable() const { return false; }
isListBox()259 virtual bool isListBox() const { return false; }
isListItem()260 virtual bool isListItem() const { return false; }
isListMarker()261 virtual bool isListMarker() const { return false; }
isMedia()262 virtual bool isMedia() const { return false; }
isMenuList()263 virtual bool isMenuList() const { return false; }
isRenderBlock()264 virtual bool isRenderBlock() const { return false; }
isRenderButton()265 virtual bool isRenderButton() const { return false; }
isRenderImage()266 virtual bool isRenderImage() const { return false; }
isRenderInline()267 virtual bool isRenderInline() const { return false; }
isRenderPart()268 virtual bool isRenderPart() const { return false; }
isRenderView()269 virtual bool isRenderView() const { return false; }
isSlider()270 virtual bool isSlider() const { return false; }
isTable()271 virtual bool isTable() const { return false; }
isTableCell()272 virtual bool isTableCell() const { return false; }
isTableCol()273 virtual bool isTableCol() const { return false; }
isTableRow()274 virtual bool isTableRow() const { return false; }
isTableSection()275 virtual bool isTableSection() const { return false; }
isTextControl()276 virtual bool isTextControl() const { return false; }
isTextArea()277 virtual bool isTextArea() const { return false; }
isTextField()278 virtual bool isTextField() const { return false; }
isVideo()279 virtual bool isVideo() const { return false; }
isWidget()280 virtual bool isWidget() const { return false; }
281
isRoot()282 bool isRoot() const { return document()->documentElement() == m_node; }
283 bool isBody() const;
284 bool isHR() const;
285
286 bool isHTMLMarquee() const;
287
childrenInline()288 bool childrenInline() const { return m_childrenInline; }
289 void setChildrenInline(bool b = true) { m_childrenInline = b; }
hasColumns()290 bool hasColumns() const { return m_hasColumns; }
291 void setHasColumns(bool b = true) { m_hasColumns = b; }
cellWidthChanged()292 bool cellWidthChanged() const { return m_cellWidthChanged; }
293 void setCellWidthChanged(bool b = true) { m_cellWidthChanged = b; }
294
295 #if ENABLE(SVG)
296 // FIXME: Until all SVG renders can be subclasses of RenderSVGModelObject we have
297 // to add SVG renderer methods to RenderObject with an ASSERT_NOT_REACHED() default implementation.
isSVGRoot()298 virtual bool isSVGRoot() const { return false; }
isSVGContainer()299 virtual bool isSVGContainer() const { return false; }
isSVGHiddenContainer()300 virtual bool isSVGHiddenContainer() const { return false; }
isRenderPath()301 virtual bool isRenderPath() const { return false; }
isSVGText()302 virtual bool isSVGText() const { return false; }
isSVGImage()303 virtual bool isSVGImage() const { return false; }
304
305 // Per SVG 1.1 objectBoundingBox ignores clipping, masking, filter effects, opacity and stroke-width.
306 // This is used for all computation of objectBoundingBox relative units and by SVGLocateable::getBBox().
307 // NOTE: Markers are not specifically ignored here by SVG 1.1 spec, but we ignore them
308 // since stroke-width is ignored (and marker size can depend on stroke-width).
309 // objectBoundingBox is returned local coordinates.
310 // The name objectBoundingBox is taken from the SVG 1.1 spec.
311 virtual FloatRect objectBoundingBox() const;
312
313 // Returns the smallest rectangle enclosing all of the painted content
314 // respecting clipping, masking, filters, opacity, stroke-width and markers
315 virtual FloatRect repaintRectInLocalCoordinates() const;
316
317 // FIXME: This accessor is deprecated and mostly around for SVGRenderTreeAsText.
318 // This only returns the transform="" value from the element
319 // most callsites want localToParentTransform() instead.
320 virtual TransformationMatrix localTransform() const;
321
322 // Returns the full transform mapping from local coordinates to local coords for the parent SVG renderer
323 // This includes any viewport transforms and x/y offsets as well as the transform="" value off the element.
324 virtual TransformationMatrix localToParentTransform() const;
325
326 // Walks up the parent chain to create a transform which maps from local to document coords
327 // NOTE: This method is deprecated! It doesn't respect scroll offsets or repaint containers.
328 // FIXME: This is only virtual so that RenderSVGHiddenContainer can override it to match old LayoutTest results.
329 virtual TransformationMatrix absoluteTransform() const;
330
331 // SVG uses FloatPoint precise hit testing, and passes the point in parent
332 // coordinates instead of in repaint container coordinates. Eventually the
333 // rest of the rendering tree will move to a similar model.
334 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
335 #endif
336
isAnonymous()337 bool isAnonymous() const { return m_isAnonymous; }
setIsAnonymous(bool b)338 void setIsAnonymous(bool b) { m_isAnonymous = b; }
isAnonymousBlock()339 bool isAnonymousBlock() const
340 {
341 return m_isAnonymous && style()->display() == BLOCK && style()->styleType() == NOPSEUDO && !isListMarker();
342 }
isInlineContinuation()343 bool isInlineContinuation() const { return (node() ? node()->renderer() != this : false) && isRenderInline(); }
isFloating()344 bool isFloating() const { return m_floating; }
isPositioned()345 bool isPositioned() const { return m_positioned; } // absolute or fixed positioning
isRelPositioned()346 bool isRelPositioned() const { return m_relPositioned; } // relative positioning
isText()347 bool isText() const { return m_isText; }
isBox()348 bool isBox() const { return m_isBox; }
isInline()349 bool isInline() const { return m_inline; } // inline object
isRunIn()350 bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object
isDragging()351 bool isDragging() const { return m_isDragging; }
isReplaced()352 bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS)
353
hasLayer()354 bool hasLayer() const { return m_hasLayer; }
355
hasBoxDecorations()356 bool hasBoxDecorations() const { return m_paintBackground; }
357 bool mustRepaintBackgroundOrBorder() const;
358
needsLayout()359 bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout || m_needsPositionedMovementLayout; }
selfNeedsLayout()360 bool selfNeedsLayout() const { return m_needsLayout; }
needsPositionedMovementLayout()361 bool needsPositionedMovementLayout() const { return m_needsPositionedMovementLayout; }
needsPositionedMovementLayoutOnly()362 bool needsPositionedMovementLayoutOnly() const { return m_needsPositionedMovementLayout && !m_needsLayout && !m_normalChildNeedsLayout && !m_posChildNeedsLayout; }
posChildNeedsLayout()363 bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
normalChildNeedsLayout()364 bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
365
prefWidthsDirty()366 bool prefWidthsDirty() const { return m_prefWidthsDirty; }
367
368 bool isSelectionBorder() const;
369
hasClip()370 bool hasClip() const { return isPositioned() && style()->hasClip(); }
hasOverflowClip()371 bool hasOverflowClip() const { return m_hasOverflowClip; }
372
hasTransform()373 bool hasTransform() const { return m_hasTransform; }
hasMask()374 bool hasMask() const { return style() && style()->hasMask(); }
375
376 void drawLineForBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2, BoxSide,
377 Color, const Color& textcolor, EBorderStyle, int adjbw1, int adjbw2);
378 void drawArcForBoxSide(GraphicsContext*, int x, int y, float thickness, IntSize radius, int angleStart,
379 int angleSpan, BoxSide, Color, const Color& textcolor, EBorderStyle, bool firstCorner);
380
381 public:
382 // The pseudo element style can be cached or uncached. Use the cached method if the pseudo element doesn't respect
383 // any pseudo classes (and therefore has no concept of changing state).
384 RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0) const;
385 PassRefPtr<RenderStyle> getUncachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0, RenderStyle* ownStyle = 0) const;
386
387 virtual void updateDragState(bool dragOn);
388
389 RenderView* view() const;
390
391 // Returns true if this renderer is rooted, and optionally returns the hosting view (the root of the hierarchy).
392 bool isRooted(RenderView** = 0);
393
node()394 Node* node() const { return m_isAnonymous ? 0 : m_node; }
document()395 Document* document() const { return m_node->document(); }
setNode(Node * node)396 void setNode(Node* node) { m_node = node; }
397
398 bool hasOutlineAnnotation() const;
hasOutline()399 bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
400
401 /**
402 * returns the object containing this one. can be different from parent for
403 * positioned elements
404 */
405 RenderObject* container() const;
hoverAncestor()406 virtual RenderObject* hoverAncestor() const { return parent(); }
407
408 // IE Extension that can be called on any RenderObject. See the implementation for the details.
409 RenderBoxModelObject* offsetParent() const;
410
411 void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
412 void setNeedsLayout(bool b, bool markParents = true);
413 void setChildNeedsLayout(bool b, bool markParents = true);
414 void setNeedsPositionedMovementLayout();
415 void setPrefWidthsDirty(bool, bool markParents = true);
416 void invalidateContainerPrefWidths();
417
setNeedsLayoutAndPrefWidthsRecalc()418 void setNeedsLayoutAndPrefWidthsRecalc()
419 {
420 setNeedsLayout(true);
421 setPrefWidthsDirty(true);
422 }
423
424 void setPositioned(bool b = true) { m_positioned = b; }
425 void setRelPositioned(bool b = true) { m_relPositioned = b; }
426 void setFloating(bool b = true) { m_floating = b; }
427 void setInline(bool b = true) { m_inline = b; }
428 void setHasBoxDecorations(bool b = true) { m_paintBackground = b; }
setIsText()429 void setIsText() { m_isText = true; }
setIsBox()430 void setIsBox() { m_isBox = true; }
431 void setReplaced(bool b = true) { m_replaced = b; }
432 void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
433 void setHasLayer(bool b = true) { m_hasLayer = b; }
434 void setHasTransform(bool b = true) { m_hasTransform = b; }
435 void setHasReflection(bool b = true) { m_hasReflection = b; }
436
437 void scheduleRelayout();
438
439 void updateFillImages(const FillLayer*, const FillLayer*);
440 void updateImage(StyleImage*, StyleImage*);
441
442 // for discussion of lineHeight see CSS2 spec
443 virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
444 // for the vertical-align property of inline elements
445 // the offset of baseline from the top of the object.
446 virtual int baselinePosition(bool firstLine, bool isRootLineBox = false) const;
447
448 typedef HashMap<OverlapTestRequestClient*, IntRect> OverlapTestRequestMap;
449
450 /*
451 * Paint the object and its children, clipped by (x|y|w|h).
452 * (tx|ty) is the calculated position of the parent
453 */
454 struct PaintInfo {
455 PaintInfo(GraphicsContext* newContext, const IntRect& newRect, PaintPhase newPhase, bool newForceBlackText,
456 RenderObject* newPaintingRoot, ListHashSet<RenderInline*>* newOutlineObjects,
457 OverlapTestRequestMap* overlapTestRequests = 0)
contextPaintInfo458 : context(newContext)
459 , rect(newRect)
460 , phase(newPhase)
461 , forceBlackText(newForceBlackText)
462 , paintingRoot(newPaintingRoot)
463 , outlineObjects(newOutlineObjects)
464 , overlapTestRequests(overlapTestRequests)
465 {
466 }
467
468 GraphicsContext* context;
469 IntRect rect;
470 PaintPhase phase;
471 bool forceBlackText;
472 RenderObject* paintingRoot; // used to draw just one element and its visual kids
473 ListHashSet<RenderInline*>* outlineObjects; // used to list outlines that should be painted by a block with inline children
474 OverlapTestRequestMap* overlapTestRequests;
475 };
476
477 virtual void paint(PaintInfo&, int tx, int ty);
478
479 // Recursive function that computes the size and position of this object and all its descendants.
480 virtual void layout();
481
482 /* This function performs a layout only if one is needed. */
layoutIfNeeded()483 void layoutIfNeeded() { if (needsLayout()) layout(); }
484
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.
tryLayoutDoingPositionedMovementOnly()487 virtual void tryLayoutDoingPositionedMovementOnly() { }
488
489 // used for element state updates that cannot be fixed with a
490 // repaint and do not need a relayout
updateFromElement()491 virtual void updateFromElement() { }
492
493 #if ENABLE(DASHBOARD_SUPPORT)
494 virtual void addDashboardRegions(Vector<DashboardRegionValue>&);
495 void collectDashboardRegions(Vector<DashboardRegionValue>&);
496 #endif
497
498 bool hitTest(const HitTestRequest&, HitTestResult&, const IntPoint&, int tx, int ty, HitTestFilter = HitTestAll);
499 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
500 virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
501
502 VisiblePosition positionForCoordinates(int x, int y);
503 virtual VisiblePosition positionForPoint(const IntPoint&);
504 VisiblePosition createVisiblePosition(int offset, EAffinity);
505 VisiblePosition createVisiblePosition(const Position&);
506
507 virtual void dirtyLinesFromChangedChild(RenderObject*);
508
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>);
513
514 // Set the style of the object and update the state of the object accordingly.
515 virtual void setStyle(PassRefPtr<RenderStyle>);
516
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>);
520
521 // returns the containing block level element for this element.
522 RenderBlock* containingBlock() const;
523
524 // Convert the given local point to absolute coordinates
525 // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
526 FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
527 FloatPoint absoluteToLocal(FloatPoint, bool fixed = false, bool useTransforms = false) const;
528
529 // Convert a local quad to absolute coordinates, taking transforms into account.
530 FloatQuad localToAbsoluteQuad(const FloatQuad& quad, bool fixed = false) const
531 {
532 return localToContainerQuad(quad, 0, fixed);
533 }
534 // Convert a local quad into the coordinate system of container, taking transforms into account.
535 FloatQuad localToContainerQuad(const FloatQuad&, RenderBoxModelObject* repaintContainer, bool fixed = false) const;
536
537 // Return the offset from the container() renderer (excluding transforms)
538 virtual IntSize offsetFromContainer(RenderObject*) const;
539
absoluteRects(Vector<IntRect> &,int,int)540 virtual void absoluteRects(Vector<IntRect>&, int, int) { }
541 // FIXME: useTransforms should go away eventually
542 IntRect absoluteBoundingBoxRect(bool useTransforms = false);
543
544 // Build an array of quads in absolute coords for line boxes
absoluteQuads(Vector<FloatQuad> &)545 virtual void absoluteQuads(Vector<FloatQuad>&) { }
546
547 // the rect that will be painted if this object is passed as the paintingRoot
548 IntRect paintingRootRect(IntRect& topLevelRect);
549
minPrefWidth()550 virtual int minPrefWidth() const { return 0; }
maxPrefWidth()551 virtual int maxPrefWidth() const { return 0; }
552
style()553 RenderStyle* style() const { return m_style.get(); }
firstLineStyle()554 RenderStyle* firstLineStyle() const { return document()->usesFirstLineRules() ? firstLineStyleSlowCase() : style(); }
style(bool firstLine)555 RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
556
557 // Used only by Element::pseudoStyleCacheIsInvalid to get a first line style based off of a
558 // given new style, without accessing the cache.
559 PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const;
560
561 // Anonymous blocks that are part of of a continuation chain will return their inline continuation's outline style instead.
562 // This is typically only relevant when repainting.
outlineStyleForRepaint()563 virtual RenderStyle* outlineStyleForRepaint() const { return style(); }
564
565 void getTextDecorationColors(int decorations, Color& underline, Color& overline,
566 Color& linethrough, bool quirksMode = false);
567
568 // Return the RenderBox in the container chain which is responsible for painting this object, or 0
569 // if painting is root-relative. This is the container that should be passed to the 'forRepaint'
570 // methods.
571 RenderBoxModelObject* containerForRepaint() const;
572 // Actually do the repaint of rect r for this object which has been computed in the coordinate space
573 // of repaintContainer. If repaintContainer is 0, repaint via the view.
574 void repaintUsingContainer(RenderBoxModelObject* repaintContainer, const IntRect& r, bool immediate = false);
575
576 // Repaint the entire object. Called when, e.g., the color of a border changes, or when a border
577 // style changes.
578 void repaint(bool immediate = false);
579
580 // Repaint a specific subrectangle within a given object. The rect |r| is in the object's coordinate space.
581 void repaintRectangle(const IntRect&, bool immediate = false);
582
583 // Repaint only if our old bounds and new bounds are different.
584 bool repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const IntRect& oldBounds, const IntRect& oldOutlineBox);
585
586 // Repaint only if the object moved.
587 virtual void repaintDuringLayoutIfMoved(const IntRect& rect);
588
589 // Called to repaint a block's floats.
590 virtual void repaintOverhangingFloats(bool paintAllDescendants = false);
591
592 bool checkForRepaintDuringLayout() const;
593
594 // Returns the rect that should be repainted whenever this object changes. The rect is in the view's
595 // coordinate space. This method deals with outlines and overflow.
absoluteClippedOverflowRect()596 IntRect absoluteClippedOverflowRect()
597 {
598 return clippedOverflowRectForRepaint(0);
599 }
600 virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer);
601 virtual IntRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth);
602
603 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
604 // that rect in view coordinates.
605 void computeAbsoluteRepaintRect(IntRect& r, bool fixed = false)
606 {
607 return computeRectForRepaint(0, r, fixed);
608 }
609 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
610 // that rect in the coordinate space of repaintContainer.
611 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false);
612
length()613 virtual unsigned int length() const { return 1; }
614
isFloatingOrPositioned()615 bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); }
616
isTransparent()617 bool isTransparent() const { return style()->opacity() < 1.0f; }
opacity()618 float opacity() const { return style()->opacity(); }
619
hasReflection()620 bool hasReflection() const { return m_hasReflection; }
621
622 // Applied as a "slop" to dirty rect checks during the outline painting phase's dirty-rect checks.
623 int maximalOutlineSize(PaintPhase) const;
624
625 void setHasMarkupTruncation(bool b = true) { m_hasMarkupTruncation = b; }
hasMarkupTruncation()626 bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
627
628 enum SelectionState {
629 SelectionNone, // The object is not selected.
630 SelectionStart, // The object either contains the start of a selection run or is the start of a run
631 SelectionInside, // The object is fully encompassed by a selection run
632 SelectionEnd, // The object either contains the end of a selection run or is the end of a run
633 SelectionBoth // The object contains an entire run or is the sole selected object in that run
634 };
635
636 // The current selection state for an object. For blocks, the state refers to the state of the leaf
637 // descendants (as described above in the SelectionState enum declaration).
selectionState()638 SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState);; }
639
640 // Sets the selection state for an object.
setSelectionState(SelectionState state)641 virtual void setSelectionState(SelectionState state) { m_selectionState = state; }
642
643 // A single rectangle that encompasses all of the selected objects within this object. Used to determine the tightest
644 // possible bounding box for the selection.
645 IntRect selectionRect(bool clipToVisibleContent = true) { return selectionRectForRepaint(0, clipToVisibleContent); }
646 virtual IntRect selectionRectForRepaint(RenderBoxModelObject* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return IntRect(); }
647
648 // Whether or not an object can be part of the leaf elements of the selection.
canBeSelectionLeaf()649 virtual bool canBeSelectionLeaf() const { return false; }
650
651 // Whether or not a block has selected children.
hasSelectedChildren()652 bool hasSelectedChildren() const { return m_selectionState != SelectionNone; }
653
654 // Obtains the selection colors that should be used when painting a selection.
655 Color selectionBackgroundColor() const;
656 Color selectionForegroundColor() const;
657
658 // Whether or not a given block needs to paint selection gaps.
shouldPaintSelectionGaps()659 virtual bool shouldPaintSelectionGaps() const { return false; }
660
661 Node* draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
662
663 /**
664 * Returns the local coordinates of the caret within this render object.
665 * @param caretOffset zero-based offset determining position within the render object.
666 * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
667 * useful for character range rect computations
668 */
669 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
670
calcVerticalMargins()671 virtual void calcVerticalMargins() { }
isTopMarginQuirk()672 bool isTopMarginQuirk() const { return m_topMarginQuirk; }
isBottomMarginQuirk()673 bool isBottomMarginQuirk() const { return m_bottomMarginQuirk; }
674 void setTopMarginQuirk(bool b = true) { m_topMarginQuirk = b; }
675 void setBottomMarginQuirk(bool b = true) { m_bottomMarginQuirk = b; }
676
677 // When performing a global document tear-down, the renderer of the document is cleared. We use this
678 // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
679 bool documentBeingDestroyed() const;
680
681 virtual void destroy();
682
683 // Virtual function helpers for CSS3 Flexible Box Layout
isFlexibleBox()684 virtual bool isFlexibleBox() const { return false; }
isFlexingChildren()685 virtual bool isFlexingChildren() const { return false; }
isStretchingChildren()686 virtual bool isStretchingChildren() const { return false; }
687
688 virtual int caretMinOffset() const;
689 virtual int caretMaxOffset() const;
690 virtual unsigned caretMaxRenderedOffset() const;
691
692 virtual int previousOffset(int current) const;
693 virtual int previousOffsetForBackwardDeletion(int current) const;
694 virtual int nextOffset(int current) const;
695
696 virtual void imageChanged(CachedImage*, const IntRect* = 0);
697 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
698 virtual bool willRenderImage(CachedImage*);
699
700 void selectionStartEnd(int& spos, int& epos) const;
701
paintingRootForChildren(PaintInfo & paintInfo)702 RenderObject* paintingRootForChildren(PaintInfo& paintInfo) const
703 {
704 // if we're the painting root, kids draw normally, and see root of 0
705 return (!paintInfo.paintingRoot || paintInfo.paintingRoot == this) ? 0 : paintInfo.paintingRoot;
706 }
707
shouldPaintWithinRoot(PaintInfo & paintInfo)708 bool shouldPaintWithinRoot(PaintInfo& paintInfo) const
709 {
710 return !paintInfo.paintingRoot || paintInfo.paintingRoot == this;
711 }
712
hasOverrideSize()713 bool hasOverrideSize() const { return m_hasOverrideSize; }
setHasOverrideSize(bool b)714 void setHasOverrideSize(bool b) { m_hasOverrideSize = b; }
715
remove()716 void remove() { if (parent()) parent()->removeChild(this); }
717
718 AnimationController* animation() const;
719
visibleToHitTesting()720 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE; }
721
722 // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
723 // localToAbsolute/absoluteToLocal methods instead.
724 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&) const;
725 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
726
727 bool shouldUseTransformFromContainer(const RenderObject* container) const;
728 void getTransformFromContainer(const RenderObject* container, const IntSize& offsetInContainer, TransformationMatrix&) const;
729
addFocusRingRects(GraphicsContext *,int,int)730 virtual void addFocusRingRects(GraphicsContext*, int /*tx*/, int /*ty*/) { };
731
absoluteOutlineBounds()732 IntRect absoluteOutlineBounds() const
733 {
734 return outlineBoundsForRepaint(0);
735 }
736
replacedHasOverflow()737 bool replacedHasOverflow() const { return m_replacedHasOverflow; }
738 void setReplacedHasOverflow(bool b = true) { m_replacedHasOverflow = b; }
739
740 protected:
741 // Overrides should call the superclass at the end
742 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
743 // Overrides should call the superclass at the start
744 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
745
746 void paintOutline(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*);
747 void addPDFURLRect(GraphicsContext*, const IntRect&);
748
749 virtual IntRect viewRect() const;
750
751 void adjustRectForOutlineAndShadow(IntRect&) const;
752
753 void arenaDelete(RenderArena*, void* objectBase);
754
outlineBoundsForRepaint(RenderBoxModelObject *)755 virtual IntRect outlineBoundsForRepaint(RenderBoxModelObject* /*repaintContainer*/) const { return IntRect(); }
756
757 class LayoutRepainter {
758 public:
759 LayoutRepainter(RenderObject& object, bool checkForRepaint, const IntRect* oldBounds = 0)
m_object(object)760 : m_object(object)
761 , m_repaintContainer(0)
762 , m_checkForRepaint(checkForRepaint)
763 {
764 if (m_checkForRepaint) {
765 m_repaintContainer = m_object.containerForRepaint();
766 m_oldBounds = oldBounds ? *oldBounds : m_object.clippedOverflowRectForRepaint(m_repaintContainer);
767 m_oldOutlineBox = m_object.outlineBoundsForRepaint(m_repaintContainer);
768 }
769 }
770
771 // Return true if it repainted.
repaintAfterLayout()772 bool repaintAfterLayout()
773 {
774 return m_checkForRepaint ? m_object.repaintAfterLayoutIfNeeded(m_repaintContainer, m_oldBounds, m_oldOutlineBox) : false;
775 }
776
checkForRepaint()777 bool checkForRepaint() const { return m_checkForRepaint; }
778
779 private:
780 RenderObject& m_object;
781 RenderBoxModelObject* m_repaintContainer;
782 IntRect m_oldBounds;
783 IntRect m_oldOutlineBox;
784 bool m_checkForRepaint;
785 };
786
787 private:
788 RenderStyle* firstLineStyleSlowCase() const;
789 StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
790
791 RefPtr<RenderStyle> m_style;
792
793 Node* m_node;
794
795 RenderObject* m_parent;
796 RenderObject* m_previous;
797 RenderObject* m_next;
798
799 #ifndef NDEBUG
800 bool m_hasAXObject;
801 bool m_setNeedsLayoutForbidden : 1;
802 #endif
803
804 // 32 bits have been used here. THERE ARE NO FREE BITS AVAILABLE.
805 bool m_needsLayout : 1;
806 bool m_needsPositionedMovementLayout :1;
807 bool m_normalChildNeedsLayout : 1;
808 bool m_posChildNeedsLayout : 1;
809 bool m_prefWidthsDirty : 1;
810 bool m_floating : 1;
811
812 bool m_positioned : 1;
813 bool m_relPositioned : 1;
814 bool m_paintBackground : 1; // if the box has something to paint in the
815 // background painting phase (background, border, etc)
816
817 bool m_isAnonymous : 1;
818 bool m_isText : 1;
819 bool m_isBox : 1;
820 bool m_inline : 1;
821 bool m_replaced : 1;
822 bool m_isDragging : 1;
823
824 bool m_hasLayer : 1;
825 bool m_hasOverflowClip : 1;
826 bool m_hasTransform : 1;
827 bool m_hasReflection : 1;
828
829 bool m_hasOverrideSize : 1;
830
831 public:
832 bool m_hasCounterNodeMap : 1;
833 bool m_everHadLayout : 1;
834
835 private:
836 // These bitfields are moved here from subclasses to pack them together
837 // from RenderBlock
838 bool m_childrenInline : 1;
839 bool m_topMarginQuirk : 1;
840 bool m_bottomMarginQuirk : 1;
841 bool m_hasMarkupTruncation : 1;
842 unsigned m_selectionState : 3; // SelectionState
843 bool m_hasColumns : 1;
844
845 // from RenderTableCell
846 bool m_cellWidthChanged : 1;
847
848 // from RenderReplaced
849 bool m_replacedHasOverflow : 1;
850
851 private:
852 // Store state between styleWillChange and styleDidChange
853 static bool s_affectsParentBlock;
854 };
855
documentBeingDestroyed()856 inline bool RenderObject::documentBeingDestroyed() const
857 {
858 return !document()->renderer();
859 }
860
setNeedsLayout(bool b,bool markParents)861 inline void RenderObject::setNeedsLayout(bool b, bool markParents)
862 {
863 bool alreadyNeededLayout = m_needsLayout;
864 m_needsLayout = b;
865 if (b) {
866 ASSERT(!isSetNeedsLayoutForbidden());
867 if (!alreadyNeededLayout) {
868 if (markParents)
869 markContainingBlocksForLayout();
870 if (hasLayer())
871 setLayerNeedsFullRepaint();
872 }
873 } else {
874 m_everHadLayout = true;
875 m_posChildNeedsLayout = false;
876 m_normalChildNeedsLayout = false;
877 m_needsPositionedMovementLayout = false;
878 }
879 }
880
setChildNeedsLayout(bool b,bool markParents)881 inline void RenderObject::setChildNeedsLayout(bool b, bool markParents)
882 {
883 bool alreadyNeededLayout = m_normalChildNeedsLayout;
884 m_normalChildNeedsLayout = b;
885 if (b) {
886 ASSERT(!isSetNeedsLayoutForbidden());
887 if (!alreadyNeededLayout && markParents)
888 markContainingBlocksForLayout();
889 } else {
890 m_posChildNeedsLayout = false;
891 m_normalChildNeedsLayout = false;
892 m_needsPositionedMovementLayout = false;
893 }
894 }
895
setNeedsPositionedMovementLayout()896 inline void RenderObject::setNeedsPositionedMovementLayout()
897 {
898 bool alreadyNeededLayout = needsLayout();
899 m_needsPositionedMovementLayout = true;
900 if (!alreadyNeededLayout) {
901 markContainingBlocksForLayout();
902 if (hasLayer())
903 setLayerNeedsFullRepaint();
904 }
905 }
906
objectIsRelayoutBoundary(const RenderObject * obj)907 inline bool objectIsRelayoutBoundary(const RenderObject *obj)
908 {
909 // FIXME: In future it may be possible to broaden this condition in order to improve performance.
910 // Table cells are excluded because even when their CSS height is fixed, their height()
911 // may depend on their contents.
912 return obj->isTextControl()
913 || (obj->hasOverflowClip() && !obj->style()->width().isIntrinsicOrAuto() && !obj->style()->height().isIntrinsicOrAuto() && !obj->style()->height().isPercent() && !obj->isTableCell())
914 #if ENABLE(SVG)
915 || obj->isSVGRoot()
916 #endif
917 ;
918 }
919
markContainingBlocksForLayout(bool scheduleRelayout,RenderObject * newRoot)920 inline void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot)
921 {
922 ASSERT(!scheduleRelayout || !newRoot);
923
924 RenderObject* o = container();
925 RenderObject* last = this;
926
927 while (o) {
928 // Don't mark the outermost object of an unrooted subtree. That object will be
929 // marked when the subtree is added to the document.
930 RenderObject* container = o->container();
931 if (!container && !o->isRenderView())
932 return;
933 if (!last->isText() && (last->style()->position() == FixedPosition || last->style()->position() == AbsolutePosition)) {
934 if ((last->style()->top().isAuto() && last->style()->bottom().isAuto()) || last->style()->top().isStatic()) {
935 RenderObject* parent = last->parent();
936 if (!parent->normalChildNeedsLayout()) {
937 parent->setChildNeedsLayout(true, false);
938 if (parent != newRoot)
939 parent->markContainingBlocksForLayout(scheduleRelayout, newRoot);
940 }
941 }
942 if (o->m_posChildNeedsLayout)
943 return;
944 o->m_posChildNeedsLayout = true;
945 ASSERT(!o->isSetNeedsLayoutForbidden());
946 } else {
947 if (o->m_normalChildNeedsLayout)
948 return;
949 o->m_normalChildNeedsLayout = true;
950 ASSERT(!o->isSetNeedsLayoutForbidden());
951 }
952
953 if (o == newRoot)
954 return;
955
956 last = o;
957 if (scheduleRelayout && objectIsRelayoutBoundary(last))
958 break;
959 o = container;
960 }
961
962 if (scheduleRelayout)
963 last->scheduleRelayout();
964 }
965
makeMatrixRenderable(TransformationMatrix & matrix,bool has3DRendering)966 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
967 {
968 #if !ENABLE(3D_RENDERING)
969 UNUSED_PARAM(has3DRendering);
970 matrix.makeAffine();
971 #else
972 if (!has3DRendering)
973 matrix.makeAffine();
974 #endif
975 }
976
977 } // namespace WebCore
978
979 #ifndef NDEBUG
980 // Outside the WebCore namespace for ease of invocation from gdb.
981 void showTree(const WebCore::RenderObject*);
982 #endif
983
984 #endif // RenderObject_h
985