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