tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / rendering / RenderObject.h
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  * Copyright (C) 2009 Google Inc. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  */
25
26 #ifndef RenderObject_h
27 #define RenderObject_h
28
29 #include "CachedImage.h"
30 #include "Document.h"
31 #include "Element.h"
32 #include "FloatQuad.h"
33 #include "LayoutTypes.h"
34 #include "PaintPhase.h"
35 #include "RenderObjectChildList.h"
36 #include "RenderStyle.h"
37 #include "TextAffinity.h"
38 #include "TransformationMatrix.h"
39 #include <wtf/UnusedParam.h>
40
41 #if USE(CG) || USE(CAIRO) || USE(SKIA) || PLATFORM(QT)
42 #define HAVE_PATH_BASED_BORDER_RADIUS_DRAWING 1
43 #endif
44
45 namespace WebCore {
46
47 class AffineTransform;
48 class AnimationController;
49 class Cursor;
50 class HitTestResult;
51 class InlineBox;
52 class InlineFlowBox;
53 class OverlapTestRequestClient;
54 class Path;
55 class Position;
56 class RenderBoxModelObject;
57 class RenderInline;
58 class RenderBlock;
59 class RenderFlowThread;
60 class RenderLayer;
61 class RenderTheme;
62 class TransformState;
63 class VisiblePosition;
64 #if ENABLE(SVG)
65 class RenderSVGResourceContainer;
66 #endif
67
68 struct PaintInfo;
69
70 enum CursorDirective {
71     SetCursorBasedOnStyle,
72     SetCursor,
73     DoNotSetCursor
74 };
75
76 enum HitTestFilter {
77     HitTestAll,
78     HitTestSelf,
79     HitTestDescendants
80 };
81
82 enum HitTestAction {
83     HitTestBlockBackground,
84     HitTestChildBlockBackground,
85     HitTestChildBlockBackgrounds,
86     HitTestFloat,
87     HitTestForeground
88 };
89
90 // Sides used when drawing borders and outlines. The values should run clockwise from top.
91 enum BoxSide {
92     BSTop,
93     BSRight,
94     BSBottom,
95     BSLeft
96 };
97
98 const int caretWidth = 1;
99
100 #if ENABLE(DASHBOARD_SUPPORT)
101 struct DashboardRegionValue {
102     bool operator==(const DashboardRegionValue& o) const
103     {
104         return type == o.type && bounds == o.bounds && clip == o.clip && label == o.label;
105     }
106     bool operator!=(const DashboardRegionValue& o) const
107     {
108         return !(*this == o);
109     }
110
111     String label;
112     LayoutRect bounds;
113     LayoutRect clip;
114     int type;
115 };
116 #endif
117
118 #ifndef NDEBUG
119 const int showTreeCharacterOffset = 39;
120 #endif
121
122 // Base class for all rendering tree objects.
123 class RenderObject : public CachedImageClient {
124     friend class LayoutRepainter;
125     friend class RenderBlock;
126     friend class RenderBox;
127     friend class RenderLayer;
128     friend class RenderObjectChildList;
129     friend class RenderSVGContainer;
130 public:
131     // Anonymous objects should pass the document as their node, and they will then automatically be
132     // marked as anonymous in the constructor.
133     RenderObject(Node*);
134     virtual ~RenderObject();
135
136     RenderTheme* theme() const;
137
138     virtual const char* renderName() const = 0;
139
140     RenderObject* parent() const { return m_parent; }
141     bool isDescendantOf(const RenderObject*) const;
142
143     RenderObject* previousSibling() const { return m_previous; }
144     RenderObject* nextSibling() const { return m_next; }
145
146     RenderObject* firstChild() const
147     {
148         if (const RenderObjectChildList* children = virtualChildren())
149             return children->firstChild();
150         return 0;
151     }
152     RenderObject* lastChild() const
153     {
154         if (const RenderObjectChildList* children = virtualChildren())
155             return children->lastChild();
156         return 0;
157     }
158     RenderObject* beforePseudoElementRenderer() const
159     {
160         if (const RenderObjectChildList* children = virtualChildren())
161             return children->beforePseudoElementRenderer(this);
162         return 0;
163     }
164
165     // This function only returns the renderer of the "after" pseudoElement if it is a child of
166     // this renderer. If "continuations" exist, the function returns 0 even if the element that
167     // generated this renderer has an "after" pseudo-element.
168     RenderObject* afterPseudoElementRenderer() const
169     {
170         if (const RenderObjectChildList* children = virtualChildren())
171             return children->afterPseudoElementRenderer(this);
172         return 0;
173     }
174
175     virtual RenderObjectChildList* virtualChildren() { return 0; }
176     virtual const RenderObjectChildList* virtualChildren() const { return 0; }
177
178     RenderObject* nextInPreOrder() const;
179     RenderObject* nextInPreOrder(const RenderObject* stayWithin) const;
180     RenderObject* nextInPreOrderAfterChildren() const;
181     RenderObject* nextInPreOrderAfterChildren(const RenderObject* stayWithin) const;
182     RenderObject* previousInPreOrder() const;
183     RenderObject* childAt(unsigned) const;
184
185     RenderObject* firstLeafChild() const;
186     RenderObject* lastLeafChild() const;
187
188     // The following six functions are used when the render tree hierarchy changes to make sure layers get
189     // properly added and removed.  Since containership can be implemented by any subclass, and since a hierarchy
190     // can contain a mixture of boxes and other object types, these functions need to be in the base class.
191     RenderLayer* enclosingLayer() const;
192     void addLayers(RenderLayer* parentLayer);
193     void removeLayers(RenderLayer* parentLayer);
194     void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
195     RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
196
197     // Convenience function for getting to the nearest enclosing box of a RenderObject.
198     RenderBox* enclosingBox() const;
199     RenderBoxModelObject* enclosingBoxModelObject() const;
200
201     // Function to return our enclosing flow thread if we are contained inside one.
202     RenderFlowThread* enclosingRenderFlowThread() const;
203
204     virtual bool isEmpty() const { return firstChild() == 0; }
205
206 #ifndef NDEBUG
207     void setHasAXObject(bool flag) { m_hasAXObject = flag; }
208     bool hasAXObject() const { return m_hasAXObject; }
209     bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; }
210     void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; }
211 #endif
212
213     // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
214     // children.
215     virtual RenderBlock* firstLineBlock() const;
216
217     // Called when an object that was floating or positioned becomes a normal flow object
218     // again.  We have to make sure the render tree updates as needed to accommodate the new
219     // normal flow object.
220     void handleDynamicFloatPositionChange();
221     
222     // RenderObject tree manipulation
223     //////////////////////////////////////////
224     virtual bool canHaveChildren() const { return virtualChildren(); }
225     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
226     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
227     virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); }
228     virtual void removeChild(RenderObject*);
229     virtual bool createsAnonymousWrapper() const { return false; }
230     //////////////////////////////////////////
231
232 protected:
233     //////////////////////////////////////////
234     // Helper functions. Dangerous to use!
235     void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
236     void setNextSibling(RenderObject* next) { m_next = next; }
237     void setParent(RenderObject* parent)
238     {
239         m_parent = parent;
240         if (parent && parent->inRenderFlowThread())
241             setInRenderFlowThread(true);
242         else if (!parent && inRenderFlowThread())
243             setInRenderFlowThread(false);
244     }
245     //////////////////////////////////////////
246 private:
247     void addAbsoluteRectForLayer(LayoutRect& result);
248     void setLayerNeedsFullRepaint();
249
250 public:
251 #ifndef NDEBUG
252     void showTreeForThis() const;
253     void showRenderTreeForThis() const;
254     void showLineTreeForThis() const;
255
256     void showRenderObject() const;
257     // We don't make printedCharacters an optional parameter so that
258     // showRenderObject can be called from gdb easily.
259     void showRenderObject(int printedCharacters) const;
260     void showRenderTreeAndMark(const RenderObject* markedObject1 = 0, const char* markedLabel1 = 0, const RenderObject* markedObject2 = 0, const char* markedLabel2 = 0, int depth = 0) const;
261 #endif
262
263     static RenderObject* createObject(Node*, RenderStyle*);
264
265     // Overloaded new operator.  Derived classes must override operator new
266     // in order to allocate out of the RenderArena.
267     void* operator new(size_t, RenderArena*) throw();
268
269     // Overridden to prevent the normal delete from being called.
270     void operator delete(void*, size_t);
271
272 private:
273     // The normal operator new is disallowed on all render objects.
274     void* operator new(size_t) throw();
275
276 public:
277     RenderArena* renderArena() const { return document()->renderArena(); }
278
279     virtual bool isApplet() const { return false; }
280     virtual bool isBR() const { return false; }
281     virtual bool isBlockFlow() const { return false; }
282     virtual bool isBoxModelObject() const { return false; }
283     virtual bool isCounter() const { return false; }
284     virtual bool isQuote() const { return false; }
285 #if ENABLE(DETAILS)
286     virtual bool isDetails() const { return false; }
287     virtual bool isDetailsMarker() const { return false; }
288 #endif
289     virtual bool isEmbeddedObject() const { return false; }
290     virtual bool isFieldset() const { return false; }
291     virtual bool isFileUploadControl() const { return false; }
292     virtual bool isFrame() const { return false; }
293     virtual bool isFrameSet() const { return false; }
294     virtual bool isImage() const { return false; }
295     virtual bool isInlineBlockOrInlineTable() const { return false; }
296     virtual bool isListBox() const { return false; }
297     virtual bool isListItem() const { return false; }
298     virtual bool isListMarker() const { return false; }
299     virtual bool isMedia() const { return false; }
300     virtual bool isMenuList() const { return false; }
301 #if ENABLE(METER_TAG)
302     virtual bool isMeter() const { return false; }
303 #endif
304 #if ENABLE(PROGRESS_TAG)
305     virtual bool isProgress() const { return false; }
306 #endif
307     virtual bool isRenderBlock() const { return false; }
308     virtual bool isRenderButton() const { return false; }
309     virtual bool isRenderIFrame() const { return false; }
310     virtual bool isRenderImage() const { return false; }
311     virtual bool isRenderInline() const { return false; }
312     virtual bool isRenderPart() const { return false; }
313     virtual bool isRenderRegion() const { return false; }
314     virtual bool isRenderView() const { return false; }
315     virtual bool isReplica() const { return false; }
316
317     virtual bool isRuby() const { return false; }
318     virtual bool isRubyBase() const { return false; }
319     virtual bool isRubyRun() const { return false; }
320     virtual bool isRubyText() const { return false; }
321
322     virtual bool isSlider() const { return false; }
323     virtual bool isSliderThumb() const { return false; }
324 #if ENABLE(DETAILS)
325     virtual bool isSummary() const { return false; }
326 #endif
327     virtual bool isTable() const { return false; }
328     virtual bool isTableCell() const { return false; }
329     virtual bool isTableCol() const { return false; }
330     virtual bool isTableRow() const { return false; }
331     virtual bool isTableSection() const { return false; }
332     virtual bool isTextControl() const { return false; }
333     virtual bool isTextArea() const { return false; }
334     virtual bool isTextField() const { return false; }
335     virtual bool isVideo() const { return false; }
336     virtual bool isWidget() const { return false; }
337     virtual bool isCanvas() const { return false; }
338 #if ENABLE(FULLSCREEN_API)
339     virtual bool isRenderFullScreen() const { return false; }
340     virtual bool isRenderFullScreenPlaceholder() const { return false; }
341 #endif
342
343     virtual bool isRenderFlowThread() const { return false; }
344
345     bool isRoot() const { return document()->documentElement() == m_node; }
346     bool isBody() const;
347     bool isHR() const;
348     bool isLegend() const;
349
350     bool isHTMLMarquee() const;
351
352     inline bool isBeforeContent() const;
353     inline bool isAfterContent() const;
354     inline bool isBeforeOrAfterContent() const;
355     static inline bool isBeforeContent(const RenderObject* obj) { return obj && obj->isBeforeContent(); }
356     static inline bool isAfterContent(const RenderObject* obj) { return obj && obj->isAfterContent(); }
357     static inline bool isBeforeOrAfterContent(const RenderObject* obj) { return obj && obj->isBeforeOrAfterContent(); }
358
359     inline RenderObject* anonymousContainer(RenderObject* child)
360     {
361          RenderObject* container = child;
362          while (container->parent() != this)
363              container = container->parent();
364
365          ASSERT(container->isAnonymous());
366          return container;
367     }
368
369     bool childrenInline() const { return m_childrenInline; }
370     void setChildrenInline(bool b) { m_childrenInline = b; }
371     bool hasColumns() const { return m_hasColumns; }
372     void setHasColumns(bool b = true) { m_hasColumns = b; }
373
374     bool inRenderFlowThread() const { return m_inRenderFlowThread; }
375     void setInRenderFlowThread(bool b = true) { m_inRenderFlowThread = b; }
376
377     virtual bool requiresForcedStyleRecalcPropagation() const { return false; }
378
379 #if ENABLE(MATHML)
380     virtual bool isRenderMathMLBlock() const { return false; }
381 #endif // ENABLE(MATHML)
382
383 #if ENABLE(SVG)
384     // FIXME: Until all SVG renders can be subclasses of RenderSVGModelObject we have
385     // to add SVG renderer methods to RenderObject with an ASSERT_NOT_REACHED() default implementation.
386     virtual bool isSVGRoot() const { return false; }
387     virtual bool isSVGContainer() const { return false; }
388     virtual bool isSVGViewportContainer() const { return false; } 
389     virtual bool isSVGGradientStop() const { return false; }
390     virtual bool isSVGHiddenContainer() const { return false; }
391     virtual bool isSVGPath() const { return false; }
392     virtual bool isSVGRect() const { return false; }
393     virtual bool isSVGShape() const { return false; }
394     virtual bool isSVGText() const { return false; }
395     virtual bool isSVGTextPath() const { return false; }
396     virtual bool isSVGInline() const { return false; }
397     virtual bool isSVGInlineText() const { return false; }
398     virtual bool isSVGImage() const { return false; }
399     virtual bool isSVGForeignObject() const { return false; }
400     virtual bool isSVGResourceContainer() const { return false; }
401     virtual bool isSVGResourceFilter() const { return false; }
402     virtual bool isSVGResourceFilterPrimitive() const { return false; }
403     virtual bool isSVGShadowTreeRootContainer() const { return false; }
404
405     virtual RenderSVGResourceContainer* toRenderSVGResourceContainer();
406
407     // FIXME: Those belong into a SVG specific base-class for all renderers (see above)
408     // Unfortunately we don't have such a class yet, because it's not possible for all renderers
409     // to inherit from RenderSVGObject -> RenderObject (some need RenderBlock inheritance for instance)
410     virtual void setNeedsTransformUpdate() { }
411     virtual void setNeedsBoundariesUpdate();
412
413     // Per SVG 1.1 objectBoundingBox ignores clipping, masking, filter effects, opacity and stroke-width.
414     // This is used for all computation of objectBoundingBox relative units and by SVGLocatable::getBBox().
415     // NOTE: Markers are not specifically ignored here by SVG 1.1 spec, but we ignore them
416     // since stroke-width is ignored (and marker size can depend on stroke-width).
417     // objectBoundingBox is returned local coordinates.
418     // The name objectBoundingBox is taken from the SVG 1.1 spec.
419     virtual FloatRect objectBoundingBox() const;
420     virtual FloatRect strokeBoundingBox() const;
421
422     // Returns the smallest rectangle enclosing all of the painted content
423     // respecting clipping, masking, filters, opacity, stroke-width and markers
424     virtual FloatRect repaintRectInLocalCoordinates() const;
425
426     // This only returns the transform="" value from the element
427     // most callsites want localToParentTransform() instead.
428     virtual AffineTransform localTransform() const;
429
430     // Returns the full transform mapping from local coordinates to local coords for the parent SVG renderer
431     // This includes any viewport transforms and x/y offsets as well as the transform="" value off the element.
432     virtual const AffineTransform& localToParentTransform() const;
433
434     // SVG uses FloatPoint precise hit testing, and passes the point in parent
435     // coordinates instead of in repaint container coordinates.  Eventually the
436     // rest of the rendering tree will move to a similar model.
437     virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
438 #endif
439
440     bool isAnonymous() const { return m_isAnonymous; }
441     void setIsAnonymous(bool b) { m_isAnonymous = b; }
442     bool isAnonymousBlock() const
443     {
444         // This function is kept in sync with anonymous block creation conditions in
445         // RenderBlock::createAnonymousBlock(). This includes creating an anonymous
446         // RenderBlock having a BLOCK or BOX display. Other classes such as RenderTextFragment
447         // are not RenderBlocks and will return false. See https://bugs.webkit.org/show_bug.cgi?id=56709. 
448         return m_isAnonymous && (style()->display() == BLOCK || style()->display() == BOX) && style()->styleType() == NOPSEUDO && isRenderBlock() && !isListMarker()
449 #if ENABLE(FULLSCREEN_API)
450             && !isRenderFullScreen()
451             && !isRenderFullScreenPlaceholder()
452 #endif
453             ;
454     }
455     bool isAnonymousColumnsBlock() const { return style()->specifiesColumns() && isAnonymousBlock(); }
456     bool isAnonymousColumnSpanBlock() const { return style()->columnSpan() && isAnonymousBlock(); }
457     bool isElementContinuation() const { return node() && node()->renderer() != this; }
458     bool isInlineElementContinuation() const { return isElementContinuation() && isInline(); }
459     bool isBlockElementContinuation() const { return isElementContinuation() && !isInline(); }
460     virtual RenderBoxModelObject* virtualContinuation() const { return 0; }
461
462     bool isFloating() const { return m_floating; }
463     bool isPositioned() const { return m_positioned; } // absolute or fixed positioning
464     bool isRelPositioned() const { return m_relPositioned; } // relative positioning
465     bool isText() const  { return m_isText; }
466     bool isBox() const { return m_isBox; }
467     bool isInline() const { return m_inline; }  // inline object
468     bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object
469     bool isDragging() const { return m_isDragging; }
470     bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS)
471     bool isHorizontalWritingMode() const { return m_horizontalWritingMode; }
472
473     bool hasLayer() const { return m_hasLayer; }
474     
475     bool hasBoxDecorations() const { return m_paintBackground; }
476     bool borderImageIsLoadedAndCanBeRendered() const;
477     bool mustRepaintBackgroundOrBorder() const;
478     bool hasBackground() const { return style()->hasBackground(); }
479     bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout || m_needsSimplifiedNormalFlowLayout || m_needsPositionedMovementLayout; }
480     bool selfNeedsLayout() const { return m_needsLayout; }
481     bool needsPositionedMovementLayout() const { return m_needsPositionedMovementLayout; }
482     bool needsPositionedMovementLayoutOnly() const { return m_needsPositionedMovementLayout && !m_needsLayout && !m_normalChildNeedsLayout && !m_posChildNeedsLayout && !m_needsSimplifiedNormalFlowLayout; }
483     bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
484     bool needsSimplifiedNormalFlowLayout() const { return m_needsSimplifiedNormalFlowLayout; }
485     bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
486     
487     bool preferredLogicalWidthsDirty() const { return m_preferredLogicalWidthsDirty; }
488
489     bool isSelectionBorder() const;
490
491     bool hasClip() const { return isPositioned() && style()->hasClip(); }
492     bool hasOverflowClip() const { return m_hasOverflowClip; }
493
494     bool hasTransform() const { return m_hasTransform; }
495     bool hasMask() const { return style() && style()->hasMask(); }
496
497 #if ENABLE(CSS_FILTERS)
498     bool hasFilter() const { return style() && style()->hasFilter(); }
499 #else
500     bool hasFilter() const { return false; }
501 #endif
502
503     inline bool preservesNewline() const;
504
505 #if !HAVE(PATH_BASED_BORDER_RADIUS_DRAWING)
506     // FIXME: This function should be removed when all ports implement GraphicsContext::clipConvexPolygon()!!
507     // At that time, everyone can use RenderObject::drawBoxSideFromPath() instead. This should happen soon.
508     void drawArcForBoxSide(GraphicsContext*, int x, int y, float thickness, const IntSize& radius, int angleStart,
509                            int angleSpan, BoxSide, Color, EBorderStyle, bool firstCorner);
510 #endif
511
512     // The pseudo element style can be cached or uncached.  Use the cached method if the pseudo element doesn't respect
513     // any pseudo classes (and therefore has no concept of changing state).
514     RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0) const;
515     PassRefPtr<RenderStyle> getUncachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0, RenderStyle* ownStyle = 0) const;
516     
517     virtual void updateDragState(bool dragOn);
518
519     RenderView* view() const;
520
521     // Returns true if this renderer is rooted, and optionally returns the hosting view (the root of the hierarchy).
522     bool isRooted(RenderView** = 0);
523
524     Node* node() const { return m_isAnonymous ? 0 : m_node; }
525
526     // Returns the styled node that caused the generation of this renderer.
527     // This is the same as node() except for renderers of :before and :after
528     // pseudo elements for which their parent node is returned.
529     Node* generatingNode() const { return m_node == document() ? 0 : m_node; }
530     void setNode(Node* node) { m_node = node; }
531
532     Document* document() const { return m_node->document(); }
533     Frame* frame() const { return document()->frame(); }
534
535     bool hasOutlineAnnotation() const;
536     bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
537
538     // Returns the object containing this one. Can be different from parent for positioned elements.
539     // If repaintContainer and repaintContainerSkipped are not null, on return *repaintContainerSkipped
540     // is true if the renderer returned is an ancestor of repaintContainer.
541     RenderObject* container(RenderBoxModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
542
543     virtual RenderObject* hoverAncestor() const { return parent(); }
544
545     // IE Extension that can be called on any RenderObject.  See the implementation for the details.
546     RenderBoxModelObject* offsetParent() const;
547
548     void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
549     void setNeedsLayout(bool b, bool markParents = true);
550     void setChildNeedsLayout(bool b, bool markParents = true);
551     void setNeedsPositionedMovementLayout();
552     void setNeedsSimplifiedNormalFlowLayout();
553     void setPreferredLogicalWidthsDirty(bool, bool markParents = true);
554     void invalidateContainerPreferredLogicalWidths();
555     
556     void setNeedsLayoutAndPrefWidthsRecalc()
557     {
558         setNeedsLayout(true);
559         setPreferredLogicalWidthsDirty(true);
560     }
561
562     void setPositioned(bool b = true)  { m_positioned = b;  }
563     void setRelPositioned(bool b = true) { m_relPositioned = b; }
564     void setFloating(bool b = true) { m_floating = b; }
565     void setInline(bool b = true) { m_inline = b; }
566     void setHasBoxDecorations(bool b = true) { m_paintBackground = b; }
567     void setIsText() { m_isText = true; }
568     void setIsBox() { m_isBox = true; }
569     void setReplaced(bool b = true) { m_replaced = b; }
570     void setHorizontalWritingMode(bool b = true) { m_horizontalWritingMode = b; }
571     void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
572     void setHasLayer(bool b = true) { m_hasLayer = b; }
573     void setHasTransform(bool b = true) { m_hasTransform = b; }
574     void setHasReflection(bool b = true) { m_hasReflection = b; }
575
576     void scheduleRelayout();
577
578     void updateFillImages(const FillLayer*, const FillLayer*);
579     void updateImage(StyleImage*, StyleImage*);
580
581     virtual void paint(PaintInfo&, const LayoutPoint&);
582
583     // Recursive function that computes the size and position of this object and all its descendants.
584     virtual void layout();
585
586     /* This function performs a layout only if one is needed. */
587     void layoutIfNeeded() { if (needsLayout()) layout(); }
588     
589     // used for element state updates that cannot be fixed with a
590     // repaint and do not need a relayout
591     virtual void updateFromElement() { }
592
593 #if ENABLE(DASHBOARD_SUPPORT)
594     virtual void addDashboardRegions(Vector<DashboardRegionValue>&);
595     void collectDashboardRegions(Vector<DashboardRegionValue>&);
596 #endif
597
598     bool hitTest(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter = HitTestAll);
599     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
600     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
601
602     virtual VisiblePosition positionForPoint(const LayoutPoint&);
603     VisiblePosition createVisiblePosition(int offset, EAffinity);
604     VisiblePosition createVisiblePosition(const Position&);
605
606     virtual void dirtyLinesFromChangedChild(RenderObject*);
607
608     // Called to update a style that is allowed to trigger animations.
609     // FIXME: Right now this will typically be called only when updating happens from the DOM on explicit elements.
610     // We don't yet handle generated content animation such as first-letter or before/after (we'll worry about this later).
611     void setAnimatableStyle(PassRefPtr<RenderStyle>);
612
613     // Set the style of the object and update the state of the object accordingly.
614     virtual void setStyle(PassRefPtr<RenderStyle>);
615
616     // Updates only the local style ptr of the object.  Does not update the state of the object,
617     // and so only should be called when the style is known not to have changed (or from setStyle).
618     void setStyleInternal(PassRefPtr<RenderStyle>);
619
620     // returns the containing block level element for this element.
621     RenderBlock* containingBlock() const;
622
623     // Convert the given local point to absolute coordinates
624     // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
625     FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
626     FloatPoint absoluteToLocal(const FloatPoint&, bool fixed = false, bool useTransforms = false) const;
627
628     // Convert a local quad to absolute coordinates, taking transforms into account.
629     FloatQuad localToAbsoluteQuad(const FloatQuad& quad, bool fixed = false, bool* wasFixed = 0) const
630     {
631         return localToContainerQuad(quad, 0, fixed, wasFixed);
632     }
633     // Convert a local quad into the coordinate system of container, taking transforms into account.
634     FloatQuad localToContainerQuad(const FloatQuad&, RenderBoxModelObject* repaintContainer, bool fixed = false, bool* wasFixed = 0) const;
635
636     // Return the offset from the container() renderer (excluding transforms). In multi-column layout,
637     // different offsets apply at different points, so return the offset that applies to the given point.
638     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&) const;
639     // Return the offset from an object up the container() chain. Asserts that none of the intermediate objects have transforms.
640     LayoutSize offsetFromAncestorContainer(RenderObject*) const;
641     
642     virtual void absoluteRects(Vector<LayoutRect>&, const LayoutPoint&) const { }
643
644     // FIXME: useTransforms should go away eventually
645     LayoutRect absoluteBoundingBoxRect(bool useTransform = true) const;
646     LayoutRect absoluteBoundingBoxRectIgnoringTransforms() const { return absoluteBoundingBoxRect(false); }
647
648     // Build an array of quads in absolute coords for line boxes
649     virtual void absoluteQuads(Vector<FloatQuad>&, bool* /*wasFixed*/ = 0) const { }
650
651     void absoluteFocusRingQuads(Vector<FloatQuad>&);
652
653     // the rect that will be painted if this object is passed as the paintingRoot
654     LayoutRect paintingRootRect(LayoutRect& topLevelRect);
655
656     virtual LayoutUnit minPreferredLogicalWidth() const { return 0; }
657     virtual LayoutUnit maxPreferredLogicalWidth() const { return 0; }
658
659     RenderStyle* style() const { return m_style.get(); }
660     RenderStyle* firstLineStyle() const { return document()->usesFirstLineRules() ? firstLineStyleSlowCase() : style(); }
661     RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
662
663     // Used only by Element::pseudoStyleCacheIsInvalid to get a first line style based off of a
664     // given new style, without accessing the cache.
665     PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const;
666
667     // Anonymous blocks that are part of of a continuation chain will return their inline continuation's outline style instead.
668     // This is typically only relevant when repainting.
669     virtual RenderStyle* outlineStyleForRepaint() const { return style(); }
670     
671     virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
672
673     void getTextDecorationColors(int decorations, Color& underline, Color& overline, Color& linethrough, bool quirksMode = false);
674
675     // Return the RenderBox in the container chain which is responsible for painting this object, or 0
676     // if painting is root-relative. This is the container that should be passed to the 'forRepaint'
677     // methods.
678     RenderBoxModelObject* containerForRepaint() const;
679     // Actually do the repaint of rect r for this object which has been computed in the coordinate space
680     // of repaintContainer. If repaintContainer is 0, repaint via the view.
681     void repaintUsingContainer(RenderBoxModelObject* repaintContainer, const LayoutRect&, bool immediate = false);
682     
683     // Repaint the entire object.  Called when, e.g., the color of a border changes, or when a border
684     // style changes.
685     void repaint(bool immediate = false);
686
687     // Repaint a specific subrectangle within a given object.  The rect |r| is in the object's coordinate space.
688     void repaintRectangle(const LayoutRect&, bool immediate = false);
689
690     // Repaint only if our old bounds and new bounds are different. The caller may pass in newBounds and newOutlineBox if they are known.
691     bool repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr = 0, const LayoutRect* newOutlineBoxPtr = 0);
692
693     // Repaint only if the object moved.
694     virtual void repaintDuringLayoutIfMoved(const LayoutRect&);
695
696     // Called to repaint a block's floats.
697     virtual void repaintOverhangingFloats(bool paintAllDescendants = false);
698
699     bool checkForRepaintDuringLayout() const;
700
701     // Returns the rect that should be repainted whenever this object changes.  The rect is in the view's
702     // coordinate space.  This method deals with outlines and overflow.
703     LayoutRect absoluteClippedOverflowRect() const
704     {
705         return clippedOverflowRectForRepaint(0);
706     }
707     virtual LayoutRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const;
708     virtual LayoutRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, LayoutUnit outlineWidth) const;
709
710     // Given a rect in the object's coordinate space, compute a rect suitable for repainting
711     // that rect in view coordinates.
712     void computeAbsoluteRepaintRect(LayoutRect& r, bool fixed = false) const
713     {
714         return computeRectForRepaint(0, r, fixed);
715     }
716     // Given a rect in the object's coordinate space, compute a rect suitable for repainting
717     // that rect in the coordinate space of repaintContainer.
718     virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
719     virtual void computeFloatRectForRepaint(RenderBoxModelObject* repaintContainer, FloatRect& repaintRect, bool fixed = false) const;
720
721     // If multiple-column layout results in applying an offset to the given point, add the same
722     // offset to the given size.
723     virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const { }
724
725     virtual unsigned int length() const { return 1; }
726
727     bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); }
728
729     bool isTransparent() const { return style()->opacity() < 1.0f; }
730     float opacity() const { return style()->opacity(); }
731
732     bool hasReflection() const { return m_hasReflection; }
733
734     // Applied as a "slop" to dirty rect checks during the outline painting phase's dirty-rect checks.
735     LayoutUnit maximalOutlineSize(PaintPhase) const;
736
737     void setHasMarkupTruncation(bool b = true) { m_hasMarkupTruncation = b; }
738     bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
739
740     enum SelectionState {
741         SelectionNone, // The object is not selected.
742         SelectionStart, // The object either contains the start of a selection run or is the start of a run
743         SelectionInside, // The object is fully encompassed by a selection run
744         SelectionEnd, // The object either contains the end of a selection run or is the end of a run
745         SelectionBoth // The object contains an entire run or is the sole selected object in that run
746     };
747
748     // The current selection state for an object.  For blocks, the state refers to the state of the leaf
749     // descendants (as described above in the SelectionState enum declaration).
750     SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState);; }
751
752     // Sets the selection state for an object.
753     virtual void setSelectionState(SelectionState state) { m_selectionState = state; }
754
755     // A single rectangle that encompasses all of the selected objects within this object.  Used to determine the tightest
756     // possible bounding box for the selection.
757     LayoutRect selectionRect(bool clipToVisibleContent = true) { return selectionRectForRepaint(0, clipToVisibleContent); }
758     virtual LayoutRect selectionRectForRepaint(RenderBoxModelObject* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return LayoutRect(); }
759
760     // Whether or not an object can be part of the leaf elements of the selection.
761     virtual bool canBeSelectionLeaf() const { return false; }
762
763     // Whether or not a block has selected children.
764     bool hasSelectedChildren() const { return m_selectionState != SelectionNone; }
765
766     // Obtains the selection colors that should be used when painting a selection.
767     Color selectionBackgroundColor() const;
768     Color selectionForegroundColor() const;
769     Color selectionEmphasisMarkColor() const;
770
771     // Whether or not a given block needs to paint selection gaps.
772     virtual bool shouldPaintSelectionGaps() const { return false; }
773
774     /**
775      * Returns the local coordinates of the caret within this render object.
776      * @param caretOffset zero-based offset determining position within the render object.
777      * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
778      * useful for character range rect computations
779      */
780     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
781
782     bool isMarginBeforeQuirk() const { return m_marginBeforeQuirk; }
783     bool isMarginAfterQuirk() const { return m_marginAfterQuirk; }
784     void setMarginBeforeQuirk(bool b = true) { m_marginBeforeQuirk = b; }
785     void setMarginAfterQuirk(bool b = true) { m_marginAfterQuirk = b; }
786
787     // When performing a global document tear-down, the renderer of the document is cleared.  We use this
788     // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
789     bool documentBeingDestroyed() const;
790
791     virtual void destroy();
792
793     // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).
794     virtual bool isDeprecatedFlexibleBox() const { return false; }
795     virtual bool isFlexingChildren() const { return false; }
796     virtual bool isStretchingChildren() const { return false; }
797
798     // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flexbox).
799     virtual bool isFlexibleBox() const { return false; }
800
801     bool isFlexibleBoxIncludingDeprecated() const
802     {
803         return isFlexibleBox() || isDeprecatedFlexibleBox();
804     }
805
806     virtual bool isCombineText() const { return false; }
807
808     virtual int caretMinOffset() const;
809     virtual int caretMaxOffset() const;
810
811     virtual int previousOffset(int current) const;
812     virtual int previousOffsetForBackwardDeletion(int current) const;
813     virtual int nextOffset(int current) const;
814
815     virtual void imageChanged(CachedImage*, const IntRect* = 0);
816     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
817     virtual bool willRenderImage(CachedImage*);
818
819     void selectionStartEnd(int& spos, int& epos) const;
820     
821     void remove() { if (parent()) parent()->removeChild(this); }
822
823     AnimationController* animation() const;
824
825     bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE; }
826
827     // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
828     // localToAbsolute/absoluteToLocal methods instead.
829     virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
830     virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
831
832     bool shouldUseTransformFromContainer(const RenderObject* container) const;
833     void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const;
834     
835     virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&) { };
836
837     LayoutRect absoluteOutlineBounds() const
838     {
839         return outlineBoundsForRepaint(0);
840     }
841
842 protected:
843     // Overrides should call the superclass at the end
844     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
845     // Overrides should call the superclass at the start
846     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
847     void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
848
849     void drawLineForBoxSide(GraphicsContext*, LayoutUnit x1, LayoutUnit y1, LayoutUnit x2, LayoutUnit y2, BoxSide,
850                             Color, EBorderStyle, int adjbw1, int adjbw2, bool antialias = false);
851
852     void paintFocusRing(GraphicsContext*, const LayoutPoint&, RenderStyle*);
853     void paintOutline(GraphicsContext*, const LayoutRect&);
854     void addPDFURLRect(GraphicsContext*, const LayoutRect&);
855
856     virtual LayoutRect viewRect() const;
857
858     void adjustRectForOutlineAndShadow(LayoutRect&) const;
859
860     virtual void willBeDestroyed();
861     void arenaDelete(RenderArena*, void* objectBase);
862
863     virtual LayoutRect outlineBoundsForRepaint(RenderBoxModelObject* /*repaintContainer*/, LayoutPoint* /*cachedOffsetToRepaintContainer*/ = 0) const { return LayoutRect(); }
864
865 private:
866     RenderStyle* firstLineStyleSlowCase() const;
867     StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
868
869     Color selectionColor(int colorProperty) const;
870     
871     RefPtr<RenderStyle> m_style;
872
873     Node* m_node;
874
875     RenderObject* m_parent;
876     RenderObject* m_previous;
877     RenderObject* m_next;
878
879 #ifndef NDEBUG
880     bool m_hasAXObject;
881     bool m_setNeedsLayoutForbidden : 1;
882 #endif
883
884     // 32 bits have been used here. THERE ARE NO FREE BITS AVAILABLE.
885     bool m_needsLayout               : 1;
886     bool m_needsPositionedMovementLayout :1;
887     bool m_normalChildNeedsLayout    : 1;
888     bool m_posChildNeedsLayout       : 1;
889     bool m_needsSimplifiedNormalFlowLayout  : 1;
890     bool m_preferredLogicalWidthsDirty           : 1;
891     bool m_floating                  : 1;
892
893     bool m_positioned                : 1;
894     bool m_relPositioned             : 1;
895     bool m_paintBackground           : 1; // if the box has something to paint in the
896                                           // background painting phase (background, border, etc)
897
898     bool m_isAnonymous               : 1;
899     bool m_isText                    : 1;
900     bool m_isBox                     : 1;
901     bool m_inline                    : 1;
902     bool m_replaced                  : 1;
903     bool m_horizontalWritingMode : 1;
904     bool m_isDragging                : 1;
905
906     bool m_hasLayer                  : 1;
907     bool m_hasOverflowClip           : 1; // Set in the case of overflow:auto/scroll/hidden
908     bool m_hasTransform              : 1;
909     bool m_hasReflection             : 1;
910     
911 public:
912     bool m_hasCounterNodeMap         : 1;
913     bool m_everHadLayout             : 1;
914
915 private:
916     // These bitfields are moved here from subclasses to pack them together
917     // from RenderBlock
918     bool m_childrenInline : 1;
919     bool m_marginBeforeQuirk : 1;
920     bool m_marginAfterQuirk : 1;
921     bool m_hasMarkupTruncation : 1;
922     unsigned m_selectionState : 3; // SelectionState
923     bool m_hasColumns : 1;
924     bool m_inRenderFlowThread : 1;
925
926 private:
927     // Store state between styleWillChange and styleDidChange
928     static bool s_affectsParentBlock;
929 };
930
931 inline bool RenderObject::documentBeingDestroyed() const
932 {
933     return !document()->renderer();
934 }
935
936 inline bool RenderObject::isBeforeContent() const
937 {
938     if (style()->styleType() != BEFORE)
939         return false;
940     // Text nodes don't have their own styles, so ignore the style on a text node.
941     if (isText() && !isBR())
942         return false;
943     return true;
944 }
945
946 inline bool RenderObject::isAfterContent() const
947 {
948     if (style()->styleType() != AFTER)
949         return false;
950     // Text nodes don't have their own styles, so ignore the style on a text node.
951     if (isText() && !isBR())
952         return false;
953     return true;
954 }
955
956 inline bool RenderObject::isBeforeOrAfterContent() const
957 {
958     return isBeforeContent() || isAfterContent();
959 }
960
961 inline void RenderObject::setNeedsLayout(bool b, bool markParents)
962 {
963     bool alreadyNeededLayout = m_needsLayout;
964     m_needsLayout = b;
965     if (b) {
966         ASSERT(!isSetNeedsLayoutForbidden());
967         if (!alreadyNeededLayout) {
968             if (markParents)
969                 markContainingBlocksForLayout();
970             if (hasLayer())
971                 setLayerNeedsFullRepaint();
972         }
973     } else {
974         m_everHadLayout = true;
975         m_posChildNeedsLayout = false;
976         m_needsSimplifiedNormalFlowLayout = false;
977         m_normalChildNeedsLayout = false;
978         m_needsPositionedMovementLayout = false;
979     }
980 }
981
982 inline void RenderObject::setChildNeedsLayout(bool b, bool markParents)
983 {
984     bool alreadyNeededLayout = m_normalChildNeedsLayout;
985     m_normalChildNeedsLayout = b;
986     if (b) {
987         ASSERT(!isSetNeedsLayoutForbidden());
988         if (!alreadyNeededLayout && markParents)
989             markContainingBlocksForLayout();
990     } else {
991         m_posChildNeedsLayout = false;
992         m_needsSimplifiedNormalFlowLayout = false;
993         m_normalChildNeedsLayout = false;
994         m_needsPositionedMovementLayout = false;
995     }
996 }
997
998 inline void RenderObject::setNeedsPositionedMovementLayout()
999 {
1000     bool alreadyNeededLayout = m_needsPositionedMovementLayout;
1001     m_needsPositionedMovementLayout = true;
1002     ASSERT(!isSetNeedsLayoutForbidden());
1003     if (!alreadyNeededLayout) {
1004         markContainingBlocksForLayout();
1005         if (hasLayer())
1006             setLayerNeedsFullRepaint();
1007     }
1008 }
1009
1010 inline void RenderObject::setNeedsSimplifiedNormalFlowLayout()
1011 {
1012     bool alreadyNeededLayout = m_needsSimplifiedNormalFlowLayout;
1013     m_needsSimplifiedNormalFlowLayout = true;
1014     ASSERT(!isSetNeedsLayoutForbidden());
1015     if (!alreadyNeededLayout) {
1016         markContainingBlocksForLayout();
1017         if (hasLayer())
1018             setLayerNeedsFullRepaint();
1019     }
1020 }
1021
1022 inline bool RenderObject::preservesNewline() const
1023 {
1024 #if ENABLE(SVG)
1025     if (isSVGInlineText())
1026         return false;
1027 #endif
1028         
1029     return style()->preserveNewline();
1030 }
1031
1032 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
1033 {
1034 #if !ENABLE(3D_RENDERING)
1035     UNUSED_PARAM(has3DRendering);
1036     matrix.makeAffine();
1037 #else
1038     if (!has3DRendering)
1039         matrix.makeAffine();
1040 #endif
1041 }
1042
1043 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
1044 {
1045     return adjustForAbsoluteZoom(value, renderer->style());
1046 }
1047
1048 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject* renderer)
1049 {
1050     float zoom = renderer->style()->effectiveZoom();
1051     if (zoom != 1)
1052         quad.scale(1 / zoom, 1 / zoom);
1053 }
1054
1055 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject* renderer)
1056 {
1057     float zoom = renderer->style()->effectiveZoom();
1058     if (zoom != 1)
1059         rect.scale(1 / zoom, 1 / zoom);
1060 }
1061
1062 inline void adjustFloatQuadForPageScale(FloatQuad& quad, float pageScale)
1063 {
1064     if (pageScale != 1)
1065         quad.scale(1 / pageScale, 1 / pageScale);
1066 }
1067
1068 inline void adjustFloatRectForPageScale(FloatRect& rect, float pageScale)
1069 {
1070     if (pageScale != 1)
1071         rect.scale(1 / pageScale, 1 / pageScale);
1072 }
1073
1074 } // namespace WebCore
1075
1076 #ifndef NDEBUG
1077 // Outside the WebCore namespace for ease of invocation from gdb.
1078 void showTree(const WebCore::RenderObject*);
1079 void showLineTree(const WebCore::RenderObject*);
1080 void showRenderTree(const WebCore::RenderObject* object1);
1081 // We don't make object2 an optional parameter so that showRenderTree
1082 // can be called from gdb easily.
1083 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2);
1084 #endif
1085
1086 #endif // RenderObject_h