Upstream version 7.35.139.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 and newOutlineBox if they are known.
811     bool repaintAfterLayoutIfNeeded(const RenderLayerModelObject* repaintContainer, bool wasSelfLayout,
812         const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr = 0, const LayoutRect* newOutlineBoxPtr = 0);
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     virtual LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap* = 0) const { return LayoutRect(); }
830
831     // Given a rect in the object's coordinate space, compute a rect suitable for repainting
832     // that rect in the coordinate space of repaintContainer.
833     virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
834     virtual void computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed = false) const;
835
836     // If multiple-column layout results in applying an offset to the given point, add the same
837     // offset to the given size.
838     virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const { }
839     LayoutSize offsetForColumns(const LayoutPoint& point) const
840     {
841         LayoutSize offset;
842         adjustForColumns(offset, point);
843         return offset;
844     }
845
846     virtual unsigned length() const { return 1; }
847
848     bool isFloatingOrOutOfFlowPositioned() const { return (isFloating() || isOutOfFlowPositioned()); }
849
850     bool isTransparent() const { return style()->opacity() < 1.0f; }
851     float opacity() const { return style()->opacity(); }
852
853     bool hasReflection() const { return m_bitfields.hasReflection(); }
854
855     enum SelectionState {
856         SelectionNone, // The object is not selected.
857         SelectionStart, // The object either contains the start of a selection run or is the start of a run
858         SelectionInside, // The object is fully encompassed by a selection run
859         SelectionEnd, // The object either contains the end of a selection run or is the end of a run
860         SelectionBoth // The object contains an entire run or is the sole selected object in that run
861     };
862
863     // The current selection state for an object.  For blocks, the state refers to the state of the leaf
864     // descendants (as described above in the SelectionState enum declaration).
865     SelectionState selectionState() const { return m_bitfields.selectionState(); }
866     virtual void setSelectionState(SelectionState state) { m_bitfields.setSelectionState(state); }
867     inline void setSelectionStateIfNeeded(SelectionState);
868     bool canUpdateSelectionOnRootLineBoxes();
869
870     // A single rectangle that encompasses all of the selected objects within this object.  Used to determine the tightest
871     // possible bounding box for the selection.
872     LayoutRect selectionRect(bool clipToVisibleContent = true) { return selectionRectForRepaint(0, clipToVisibleContent); }
873     virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return LayoutRect(); }
874
875     virtual bool canBeSelectionLeaf() const { return false; }
876     bool hasSelectedChildren() const { return selectionState() != SelectionNone; }
877
878     bool isSelectable() const;
879     // Obtains the selection colors that should be used when painting a selection.
880     Color selectionBackgroundColor() const;
881     Color selectionForegroundColor() const;
882     Color selectionEmphasisMarkColor() const;
883
884     // Whether or not a given block needs to paint selection gaps.
885     virtual bool shouldPaintSelectionGaps() const { return false; }
886
887     /**
888      * Returns the local coordinates of the caret within this render object.
889      * @param caretOffset zero-based offset determining position within the render object.
890      * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
891      * useful for character range rect computations
892      */
893     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
894
895     // When performing a global document tear-down, the renderer of the document is cleared. We use this
896     // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
897     bool documentBeingDestroyed() const;
898
899     void destroyAndCleanupAnonymousWrappers();
900     virtual void destroy();
901
902     // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).
903     virtual bool isDeprecatedFlexibleBox() const { return false; }
904
905     // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flex).
906     virtual bool isFlexibleBox() const { return false; }
907
908     bool isFlexibleBoxIncludingDeprecated() const
909     {
910         return isFlexibleBox() || isDeprecatedFlexibleBox();
911     }
912
913     virtual bool isCombineText() const { return false; }
914
915     virtual int caretMinOffset() const;
916     virtual int caretMaxOffset() const;
917
918     virtual int previousOffset(int current) const;
919     virtual int previousOffsetForBackwardDeletion(int current) const;
920     virtual int nextOffset(int current) const;
921
922     virtual void imageChanged(ImageResource*, const IntRect* = 0) OVERRIDE FINAL;
923     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
924     virtual bool willRenderImage(ImageResource*) OVERRIDE FINAL;
925
926     void selectionStartEnd(int& spos, int& epos) const;
927
928     void remove() { if (parent()) parent()->removeChild(this); }
929
930     bool isInert() const;
931     virtual bool visibleForTouchAction() const { return false; }
932     bool visibleToHitTestRequest(const HitTestRequest& request) const
933     {
934         if (request.touchAction() && !visibleForTouchAction())
935             return false;
936         return style()->visibility() == VISIBLE && (request.ignorePointerEventsNone() || style()->pointerEvents() != PE_NONE) && !isInert();
937     }
938
939     bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE && !isInert(); }
940
941     // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
942     // localToAbsolute/absoluteToLocal methods instead.
943     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const;
944     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const;
945
946     // Pushes state onto RenderGeometryMap about how to map coordinates from this renderer to its container, or ancestorToStopAt (whichever is encountered first).
947     // Returns the renderer which was mapped to (container or ancestorToStopAt).
948     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const;
949
950     bool shouldUseTransformFromContainer(const RenderObject* container) const;
951     void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const;
952
953     bool createsGroup() const { return isTransparent() || hasMask() || hasFilter() || hasBlendMode(); }
954
955     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& /* additionalOffset */, const RenderLayerModelObject* /* paintContainer */ = 0) { };
956
957     // Compute a list of hit-test rectangles per layer rooted at this renderer.
958     virtual void computeLayerHitTestRects(LayerHitTestRects&) const;
959
960     LayoutRect absoluteOutlineBounds() const
961     {
962         return outlineBoundsForRepaint(0);
963     }
964
965     // Return the renderer whose background style is used to paint the root background. Should only be called on the renderer for which isRoot() is true.
966     RenderObject* rendererForRootBackground();
967
968     RespectImageOrientationEnum shouldRespectImageOrientation() const;
969
970     bool isRelayoutBoundaryForInspector() const;
971
972     const LayoutRect& newRepaintRect() const { return m_newRepaintRect; }
973     void setNewRepaintRect(const LayoutRect& rect) { m_newRepaintRect = rect; }
974
975     const LayoutRect& oldRepaintRect() const { return m_oldRepaintRect; }
976     void setOldRepaintRect(const LayoutRect& rect) { m_oldRepaintRect = rect; }
977
978     LayoutRect newOutlineRect();
979     void setNewOutlineRect(const LayoutRect&);
980
981     LayoutRect oldOutlineRect();
982     void setOldOutlineRect(const LayoutRect&);
983
984     bool shouldDoFullRepaintAfterLayout() const { return m_bitfields.shouldDoFullRepaintAfterLayout(); }
985     void setShouldDoFullRepaintAfterLayout(bool b) { m_bitfields.setShouldDoFullRepaintAfterLayout(b); }
986     bool shouldRepaintOverflow() const { return m_bitfields.shouldRepaintOverflow(); }
987
988     bool shouldDoFullRepaintIfSelfPaintingLayer() const { return m_bitfields.shouldDoFullRepaintIfSelfPaintingLayer(); }
989     void setShouldDoFullRepaintIfSelfPaintingLayer(bool b) { m_bitfields.setShouldDoFullRepaintIfSelfPaintingLayer(b); }
990
991     bool onlyNeededPositionedMovementLayout() const { return m_bitfields.onlyNeededPositionedMovementLayout(); }
992     void setOnlyNeededPositionedMovementLayout(bool b) { m_bitfields.setOnlyNeededPositionedMovementLayout(b); }
993
994     void clearRepaintState();
995
996     // layoutDidGetCalled indicates whether this render object was re-laid-out
997     // since the last call to setLayoutDidGetCalled(false) on this object.
998     bool layoutDidGetCalled() { return m_bitfields.layoutDidGetCalled(); }
999     void setLayoutDidGetCalled(bool b) { m_bitfields.setLayoutDidGetCalled(b); }
1000
1001     bool shouldDisableLayoutState() const { return hasColumns() || hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode(); }
1002
1003 protected:
1004     inline bool layerCreationAllowedForSubtree() const;
1005
1006     // Overrides should call the superclass at the end
1007     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
1008     // Overrides should call the superclass at the start
1009     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
1010     void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
1011
1012     void drawLineForBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2, BoxSide,
1013                             Color, EBorderStyle, int adjbw1, int adjbw2, bool antialias = false);
1014     void drawDashedOrDottedBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1015         BoxSide, Color, int thickness, EBorderStyle, bool antialias);
1016     void drawDoubleBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1017         int length, BoxSide, Color, int thickness, int adjacentWidth1, int adjacentWidth2, bool antialias);
1018     void drawRidgeOrGrooveBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1019         BoxSide, Color, EBorderStyle, int adjacentWidth1, int adjacentWidth2, bool antialias);
1020     void drawSolidBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2,
1021         BoxSide, Color, int adjacentWidth1, int adjacentWidth2, bool antialias);
1022
1023     void paintFocusRing(PaintInfo&, const LayoutPoint&, RenderStyle*);
1024     void paintOutline(PaintInfo&, const LayoutRect&);
1025     void addPDFURLRect(GraphicsContext*, const LayoutRect&);
1026
1027     virtual LayoutRect viewRect() const;
1028
1029     void adjustRectForOutline(LayoutRect&) const;
1030
1031     void clearLayoutRootIfNeeded() const;
1032     virtual void willBeDestroyed();
1033     void postDestroy();
1034
1035     virtual void insertedIntoTree();
1036     virtual void willBeRemovedFromTree();
1037
1038     void setDocumentForAnonymous(Document* document) { ASSERT(isAnonymous()); m_node = document; }
1039
1040     // Add hit-test rects for the render tree rooted at this node to the provided collection on a
1041     // per-RenderLayer basis.
1042     // currentLayer must be the enclosing layer, and layerOffset is the current offset within
1043     // this layer. Subclass implementations will add any offset for this renderer within it's
1044     // container, so callers should provide only the offset of the container within it's layer.
1045     // containerRect is a rect that has already been added for the currentLayer which is likely to
1046     // be a container for child elements. Any rect wholly contained by containerRect can be
1047     // skipped.
1048     virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const;
1049
1050     // Add hit-test rects for this renderer only to the provided list. layerOffset is the offset
1051     // of this renderer within the current layer that should be used for each result.
1052     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const { };
1053
1054 private:
1055     RenderBlock* containerForFixedPosition(const RenderLayerModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
1056
1057     RenderFlowThread* locateFlowThreadContainingBlock() const;
1058     void removeFromRenderFlowThread();
1059     void removeFromRenderFlowThreadRecursive(RenderFlowThread*);
1060
1061     bool shouldRepaintForStyleDifference(StyleDifference) const;
1062     bool hasImmediateNonWhitespaceTextChildOrPropertiesDependentOnColor() const;
1063
1064     RenderStyle* cachedFirstLineStyle() const;
1065     StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
1066
1067     Color selectionColor(int colorProperty) const;
1068
1069     void removeShapeImageClient(ShapeValue*);
1070
1071 #ifndef NDEBUG
1072     void checkBlockPositionedObjectsNeedLayout();
1073 #endif
1074
1075     RefPtr<RenderStyle> m_style;
1076
1077     Node* m_node;
1078
1079     RenderObject* m_parent;
1080     RenderObject* m_previous;
1081     RenderObject* m_next;
1082
1083 #ifndef NDEBUG
1084     unsigned m_hasAXObject             : 1;
1085     unsigned m_setNeedsLayoutForbidden : 1;
1086 #endif
1087
1088 #define ADD_BOOLEAN_BITFIELD(name, Name) \
1089     private:\
1090         unsigned m_##name : 1;\
1091     public:\
1092         bool name() const { return m_##name; }\
1093         void set##Name(bool name) { m_##name = name; }\
1094
1095     class RenderObjectBitfields {
1096         enum PositionedState {
1097             IsStaticallyPositioned = 0,
1098             IsRelativelyPositioned = 1,
1099             IsOutOfFlowPositioned = 2,
1100             IsStickyPositioned = 3
1101         };
1102
1103     public:
1104         RenderObjectBitfields(Node* node)
1105             : m_selfNeedsLayout(false)
1106             // FIXME: shouldDoFullRepaintAfterLayout is needed because we reset
1107             // the layout bits before repaint when doing repaintAfterLayout.
1108             // Holding the layout bits until after repaint would remove the need
1109             // for this flag.
1110             , m_shouldDoFullRepaintAfterLayout(false)
1111             , m_shouldRepaintOverflow(false)
1112             , m_shouldDoFullRepaintIfSelfPaintingLayer(false)
1113             , m_onlyNeededPositionedMovementLayout(false)
1114             , m_needsPositionedMovementLayout(false)
1115             , m_normalChildNeedsLayout(false)
1116             , m_posChildNeedsLayout(false)
1117             , m_needsSimplifiedNormalFlowLayout(false)
1118             , m_preferredLogicalWidthsDirty(false)
1119             , m_floating(false)
1120             , m_isAnonymous(!node)
1121             , m_isText(false)
1122             , m_isBox(false)
1123             , m_isInline(true)
1124             , m_isReplaced(false)
1125             , m_horizontalWritingMode(true)
1126             , m_isDragging(false)
1127             , m_hasLayer(false)
1128             , m_hasOverflowClip(false)
1129             , m_hasTransform(false)
1130             , m_hasReflection(false)
1131             , m_hasCounterNodeMap(false)
1132             , m_everHadLayout(false)
1133             , m_ancestorLineBoxDirty(false)
1134             , m_childrenInline(false)
1135             , m_hasColumns(false)
1136             , m_layoutDidGetCalled(false)
1137             , m_positionedState(IsStaticallyPositioned)
1138             , m_selectionState(SelectionNone)
1139             , m_flowThreadState(NotInsideFlowThread)
1140             , m_boxDecorationState(NoBoxDecorations)
1141             , m_hasPendingResourceUpdate(false)
1142         {
1143         }
1144
1145         // 32 bits have been used in the first word, and 5 in the second.
1146         ADD_BOOLEAN_BITFIELD(selfNeedsLayout, SelfNeedsLayout);
1147         ADD_BOOLEAN_BITFIELD(shouldDoFullRepaintAfterLayout, ShouldDoFullRepaintAfterLayout);
1148         ADD_BOOLEAN_BITFIELD(shouldRepaintOverflow, ShouldRepaintOverflow);
1149         ADD_BOOLEAN_BITFIELD(shouldDoFullRepaintIfSelfPaintingLayer, ShouldDoFullRepaintIfSelfPaintingLayer);
1150         ADD_BOOLEAN_BITFIELD(onlyNeededPositionedMovementLayout, OnlyNeededPositionedMovementLayout);
1151         ADD_BOOLEAN_BITFIELD(needsPositionedMovementLayout, NeedsPositionedMovementLayout);
1152         ADD_BOOLEAN_BITFIELD(normalChildNeedsLayout, NormalChildNeedsLayout);
1153         ADD_BOOLEAN_BITFIELD(posChildNeedsLayout, PosChildNeedsLayout);
1154         ADD_BOOLEAN_BITFIELD(needsSimplifiedNormalFlowLayout, NeedsSimplifiedNormalFlowLayout);
1155         ADD_BOOLEAN_BITFIELD(preferredLogicalWidthsDirty, PreferredLogicalWidthsDirty);
1156         ADD_BOOLEAN_BITFIELD(floating, Floating);
1157
1158         ADD_BOOLEAN_BITFIELD(isAnonymous, IsAnonymous);
1159         ADD_BOOLEAN_BITFIELD(isText, IsText);
1160         ADD_BOOLEAN_BITFIELD(isBox, IsBox);
1161         ADD_BOOLEAN_BITFIELD(isInline, IsInline);
1162         ADD_BOOLEAN_BITFIELD(isReplaced, IsReplaced);
1163         ADD_BOOLEAN_BITFIELD(horizontalWritingMode, HorizontalWritingMode);
1164         ADD_BOOLEAN_BITFIELD(isDragging, IsDragging);
1165
1166         ADD_BOOLEAN_BITFIELD(hasLayer, HasLayer);
1167         ADD_BOOLEAN_BITFIELD(hasOverflowClip, HasOverflowClip); // Set in the case of overflow:auto/scroll/hidden
1168         ADD_BOOLEAN_BITFIELD(hasTransform, HasTransform);
1169         ADD_BOOLEAN_BITFIELD(hasReflection, HasReflection);
1170
1171         ADD_BOOLEAN_BITFIELD(hasCounterNodeMap, HasCounterNodeMap);
1172         ADD_BOOLEAN_BITFIELD(everHadLayout, EverHadLayout);
1173         ADD_BOOLEAN_BITFIELD(ancestorLineBoxDirty, AncestorLineBoxDirty);
1174
1175         // from RenderBlock
1176         ADD_BOOLEAN_BITFIELD(childrenInline, ChildrenInline);
1177         ADD_BOOLEAN_BITFIELD(hasColumns, HasColumns);
1178
1179         ADD_BOOLEAN_BITFIELD(layoutDidGetCalled, LayoutDidGetCalled);
1180
1181     private:
1182         unsigned m_positionedState : 2; // PositionedState
1183         unsigned m_selectionState : 3; // SelectionState
1184         unsigned m_flowThreadState : 2; // FlowThreadState
1185         unsigned m_boxDecorationState : 2; // BoxDecorationState
1186
1187     public:
1188
1189         ADD_BOOLEAN_BITFIELD(hasPendingResourceUpdate, HasPendingResourceUpdate);
1190
1191         bool isOutOfFlowPositioned() const { return m_positionedState == IsOutOfFlowPositioned; }
1192         bool isRelPositioned() const { return m_positionedState == IsRelativelyPositioned; }
1193         bool isStickyPositioned() const { return m_positionedState == IsStickyPositioned; }
1194         bool isPositioned() const { return m_positionedState != IsStaticallyPositioned; }
1195
1196         void setPositionedState(int positionState)
1197         {
1198             // This mask maps FixedPosition and AbsolutePosition to IsOutOfFlowPositioned, saving one bit.
1199             m_positionedState = static_cast<PositionedState>(positionState & 0x3);
1200         }
1201         void clearPositionedState() { m_positionedState = StaticPosition; }
1202
1203         ALWAYS_INLINE SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
1204         ALWAYS_INLINE void setSelectionState(SelectionState selectionState) { m_selectionState = selectionState; }
1205
1206         ALWAYS_INLINE FlowThreadState flowThreadState() const { return static_cast<FlowThreadState>(m_flowThreadState); }
1207         ALWAYS_INLINE void setFlowThreadState(FlowThreadState flowThreadState) { m_flowThreadState = flowThreadState; }
1208
1209         ALWAYS_INLINE BoxDecorationState boxDecorationState() const { return static_cast<BoxDecorationState>(m_boxDecorationState); }
1210         ALWAYS_INLINE void setBoxDecorationState(BoxDecorationState boxDecorationState) { m_boxDecorationState = boxDecorationState; }
1211     };
1212
1213 #undef ADD_BOOLEAN_BITFIELD
1214
1215     RenderObjectBitfields m_bitfields;
1216
1217     void setSelfNeedsLayout(bool b) { m_bitfields.setSelfNeedsLayout(b); }
1218     void setNeedsPositionedMovementLayout(bool b) { m_bitfields.setNeedsPositionedMovementLayout(b); }
1219     void setNormalChildNeedsLayout(bool b) { m_bitfields.setNormalChildNeedsLayout(b); }
1220     void setPosChildNeedsLayout(bool b) { m_bitfields.setPosChildNeedsLayout(b); }
1221     void setNeedsSimplifiedNormalFlowLayout(bool b) { m_bitfields.setNeedsSimplifiedNormalFlowLayout(b); }
1222     void setIsDragging(bool b) { m_bitfields.setIsDragging(b); }
1223     void setEverHadLayout(bool b) { m_bitfields.setEverHadLayout(b); }
1224     void setShouldRepaintOverflow(bool b) { m_bitfields.setShouldRepaintOverflow(b); }
1225
1226 private:
1227     // Store state between styleWillChange and styleDidChange
1228     static bool s_affectsParentBlock;
1229
1230     LayoutRect m_oldRepaintRect;
1231     LayoutRect m_newRepaintRect;
1232 };
1233
1234 // Allow equality comparisons of RenderObject's by reference or pointer, interchangeably.
1235 inline bool operator==(const RenderObject& a, const RenderObject& b) { return &a == &b; }
1236 inline bool operator==(const RenderObject& a, const RenderObject* b) { return &a == b; }
1237 inline bool operator==(const RenderObject* a, const RenderObject& b) { return a == &b; }
1238 inline bool operator!=(const RenderObject& a, const RenderObject& b) { return !(a == b); }
1239 inline bool operator!=(const RenderObject& a, const RenderObject* b) { return !(a == b); }
1240 inline bool operator!=(const RenderObject* a, const RenderObject& b) { return !(a == b); }
1241
1242 inline bool RenderObject::documentBeingDestroyed() const
1243 {
1244     return !document().renderer();
1245 }
1246
1247 inline bool RenderObject::isBeforeContent() const
1248 {
1249     if (style()->styleType() != BEFORE)
1250         return false;
1251     // Text nodes don't have their own styles, so ignore the style on a text node.
1252     if (isText() && !isBR())
1253         return false;
1254     return true;
1255 }
1256
1257 inline bool RenderObject::isAfterContent() const
1258 {
1259     if (style()->styleType() != AFTER)
1260         return false;
1261     // Text nodes don't have their own styles, so ignore the style on a text node.
1262     if (isText() && !isBR())
1263         return false;
1264     return true;
1265 }
1266
1267 inline bool RenderObject::isBeforeOrAfterContent() const
1268 {
1269     return isBeforeContent() || isAfterContent();
1270 }
1271
1272 inline void RenderObject::setNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter)
1273 {
1274     ASSERT(!isSetNeedsLayoutForbidden());
1275     bool alreadyNeededLayout = m_bitfields.selfNeedsLayout();
1276     setSelfNeedsLayout(true);
1277     if (!alreadyNeededLayout) {
1278         if (markParents == MarkContainingBlockChain && (!layouter || layouter->root() != this))
1279             markContainingBlocksForLayout(true, 0, layouter);
1280         if (hasLayer())
1281             setLayerNeedsFullRepaint();
1282     }
1283 }
1284
1285 inline void RenderObject::clearNeedsLayout()
1286 {
1287     setSelfNeedsLayout(false);
1288     setEverHadLayout(true);
1289     setPosChildNeedsLayout(false);
1290     setNeedsSimplifiedNormalFlowLayout(false);
1291     setNormalChildNeedsLayout(false);
1292     setNeedsPositionedMovementLayout(false);
1293     setAncestorLineBoxDirty(false);
1294 #ifndef NDEBUG
1295     checkBlockPositionedObjectsNeedLayout();
1296 #endif
1297 }
1298
1299 inline void RenderObject::setChildNeedsLayout(MarkingBehavior markParents, SubtreeLayoutScope* layouter)
1300 {
1301     ASSERT(!isSetNeedsLayoutForbidden());
1302     bool alreadyNeededLayout = normalChildNeedsLayout();
1303     setNormalChildNeedsLayout(true);
1304     // FIXME: Replace MarkOnlyThis with the SubtreeLayoutScope code path and remove the MarkingBehavior argument entirely.
1305     if (!alreadyNeededLayout && markParents == MarkContainingBlockChain && (!layouter || layouter->root() != this))
1306         markContainingBlocksForLayout(true, 0, layouter);
1307 }
1308
1309 inline void RenderObject::setNeedsPositionedMovementLayout()
1310 {
1311     bool alreadyNeededLayout = needsPositionedMovementLayout();
1312     setNeedsPositionedMovementLayout(true);
1313     ASSERT(!isSetNeedsLayoutForbidden());
1314     if (!alreadyNeededLayout) {
1315         markContainingBlocksForLayout();
1316         if (hasLayer())
1317             setLayerNeedsFullRepaintForPositionedMovementLayout();
1318     }
1319 }
1320
1321 inline void RenderObject::setNeedsSimplifiedNormalFlowLayout()
1322 {
1323     bool alreadyNeededLayout = needsSimplifiedNormalFlowLayout();
1324     setNeedsSimplifiedNormalFlowLayout(true);
1325     ASSERT(!isSetNeedsLayoutForbidden());
1326     if (!alreadyNeededLayout) {
1327         markContainingBlocksForLayout();
1328         if (hasLayer())
1329             setLayerNeedsFullRepaint();
1330     }
1331 }
1332
1333 inline bool RenderObject::preservesNewline() const
1334 {
1335     if (isSVGInlineText())
1336         return false;
1337
1338     return style()->preserveNewline();
1339 }
1340
1341 inline bool RenderObject::layerCreationAllowedForSubtree() const
1342 {
1343     RenderObject* parentRenderer = parent();
1344     while (parentRenderer) {
1345         if (parentRenderer->isSVGHiddenContainer())
1346             return false;
1347         parentRenderer = parentRenderer->parent();
1348     }
1349
1350     return true;
1351 }
1352
1353 inline void RenderObject::setSelectionStateIfNeeded(SelectionState state)
1354 {
1355     if (selectionState() == state)
1356         return;
1357
1358     setSelectionState(state);
1359 }
1360
1361 inline void RenderObject::setHasBoxDecorations(bool b)
1362 {
1363     if (!b) {
1364         m_bitfields.setBoxDecorationState(NoBoxDecorations);
1365         return;
1366     }
1367     if (hasBoxDecorations())
1368         return;
1369     m_bitfields.setBoxDecorationState(HasBoxDecorationsAndBackgroundObscurationStatusInvalid);
1370 }
1371
1372 inline void RenderObject::invalidateBackgroundObscurationStatus()
1373 {
1374     if (!hasBoxDecorations())
1375         return;
1376     m_bitfields.setBoxDecorationState(HasBoxDecorationsAndBackgroundObscurationStatusInvalid);
1377 }
1378
1379 inline bool RenderObject::backgroundIsKnownToBeObscured()
1380 {
1381     if (m_bitfields.boxDecorationState() == HasBoxDecorationsAndBackgroundObscurationStatusInvalid) {
1382         BoxDecorationState boxDecorationState = computeBackgroundIsKnownToBeObscured() ? HasBoxDecorationsAndBackgroundIsKnownToBeObscured : HasBoxDecorationsAndBackgroundMayBeVisible;
1383         m_bitfields.setBoxDecorationState(boxDecorationState);
1384     }
1385     return m_bitfields.boxDecorationState() == HasBoxDecorationsAndBackgroundIsKnownToBeObscured;
1386 }
1387
1388 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
1389 {
1390     if (!has3DRendering)
1391         matrix.makeAffine();
1392 }
1393
1394 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
1395 {
1396     return adjustForAbsoluteZoom(value, renderer->style());
1397 }
1398
1399 inline LayoutUnit adjustLayoutUnitForAbsoluteZoom(LayoutUnit value, RenderObject& renderer)
1400 {
1401     ASSERT(renderer.style());
1402     return adjustLayoutUnitForAbsoluteZoom(value, *renderer.style());
1403 }
1404
1405 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject& renderer)
1406 {
1407     float zoom = renderer.style()->effectiveZoom();
1408     if (zoom != 1)
1409         quad.scale(1 / zoom, 1 / zoom);
1410 }
1411
1412 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject& renderer)
1413 {
1414     float zoom = renderer.style()->effectiveZoom();
1415     if (zoom != 1)
1416         rect.scale(1 / zoom, 1 / zoom);
1417 }
1418
1419 #define DEFINE_RENDER_OBJECT_TYPE_CASTS(thisType, predicate) \
1420     DEFINE_TYPE_CASTS(thisType, RenderObject, object, object->predicate, object.predicate)
1421
1422 } // namespace WebCore
1423
1424 #ifndef NDEBUG
1425 // Outside the WebCore namespace for ease of invocation from gdb.
1426 void showTree(const WebCore::RenderObject*);
1427 void showLineTree(const WebCore::RenderObject*);
1428 void showRenderTree(const WebCore::RenderObject* object1);
1429 // We don't make object2 an optional parameter so that showRenderTree
1430 // can be called from gdb easily.
1431 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2);
1432
1433 #endif
1434
1435 #endif // RenderObject_h