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