webengine/osswebengine/WebCore/rendering/RenderObject.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 Apple Inc. All rights reserved.
       
     7  *
       
     8  * This library is free software; you can redistribute it and/or
       
     9  * modify it under the terms of the GNU Library General Public
       
    10  * License as published by the Free Software Foundation; either
       
    11  * version 2 of the License, or (at your option) any later version.
       
    12  *
       
    13  * This library is distributed in the hope that it will be useful,
       
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16  * Library General Public License for more details.
       
    17  *
       
    18  * You should have received a copy of the GNU Library General Public License
       
    19  * along with this library; see the file COPYING.LIB.  If not, write to
       
    20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    21  * Boston, MA 02110-1301, USA.
       
    22  *
       
    23  */
       
    24 
       
    25 #ifndef RenderObject_h
       
    26 #define RenderObject_h
       
    27 
       
    28 #include "CachedResourceClient.h"
       
    29 #include "Document.h"
       
    30 #include "RenderStyle.h"
       
    31 #include "ScrollTypes.h"
       
    32 #include "VisiblePosition.h"
       
    33 #include <wtf/HashMap.h>
       
    34 
       
    35 namespace WebCore {
       
    36 
       
    37 class AffineTransform;
       
    38 class Color;
       
    39 class Document;
       
    40 class Element;
       
    41 class Event;
       
    42 class FloatRect;
       
    43 class FrameView;
       
    44 class HTMLAreaElement;
       
    45 class HitTestResult;
       
    46 class InlineBox;
       
    47 class InlineFlowBox;
       
    48 class PlatformScrollbar;
       
    49 class Position;
       
    50 class RenderArena;
       
    51 class RenderBlock;
       
    52 class RenderFlow;
       
    53 class RenderFrameSet;
       
    54 class RenderLayer;
       
    55 class RenderTable;
       
    56 class RenderText;
       
    57 class RenderView;
       
    58 class String;
       
    59 class TextStream;
       
    60 struct HitTestRequest;
       
    61 
       
    62 /*
       
    63  *  The painting of a layer occurs in three distinct phases.  Each phase involves
       
    64  *  a recursive descent into the layer's render objects. The first phase is the background phase.
       
    65  *  The backgrounds and borders of all blocks are painted.  Inlines are not painted at all.
       
    66  *  Floats must paint above block backgrounds but entirely below inline content that can overlap them.
       
    67  *  In the foreground phase, all inlines are fully painted.  Inline replaced elements will get all
       
    68  *  three phases invoked on them during this phase.
       
    69  */
       
    70 
       
    71 enum PaintPhase {
       
    72     PaintPhaseBlockBackground,
       
    73     PaintPhaseChildBlockBackground,
       
    74     PaintPhaseChildBlockBackgrounds,
       
    75     PaintPhaseFloat,
       
    76     PaintPhaseForeground,
       
    77     PaintPhaseOutline,
       
    78     PaintPhaseChildOutlines,
       
    79     PaintPhaseSelfOutline,
       
    80     PaintPhaseSelection,
       
    81     PaintPhaseCollapsedTableBorders
       
    82 };
       
    83 
       
    84 enum PaintRestriction {
       
    85     PaintRestrictionNone,
       
    86     PaintRestrictionSelectionOnly,
       
    87     PaintRestrictionSelectionOnlyBlackText
       
    88 };
       
    89 
       
    90 enum HitTestFilter {
       
    91     HitTestAll,
       
    92     HitTestSelf,
       
    93     HitTestDescendants
       
    94 };
       
    95 
       
    96 enum HitTestAction {
       
    97     HitTestBlockBackground,
       
    98     HitTestChildBlockBackground,
       
    99     HitTestChildBlockBackgrounds,
       
   100     HitTestFloat,
       
   101     HitTestForeground
       
   102 };
       
   103 
       
   104 enum VerticalPositionHint {
       
   105     PositionTop = -0x2000,
       
   106     PositionBottom = 0x2000,
       
   107     PositionUndefined = 0x1fff
       
   108 };
       
   109 
       
   110 struct DashboardRegionValue {
       
   111     bool operator==(const DashboardRegionValue& o) const
       
   112     {
       
   113         return type == o.type && bounds == o.bounds && label == o.label;
       
   114     }
       
   115 
       
   116     String label;
       
   117     IntRect bounds;
       
   118     IntRect clip;
       
   119     int type;
       
   120 };
       
   121 
       
   122 // FIXME: This should be a HashSequencedSet, but we don't have that data structure yet.
       
   123 // This means the paint order of outlines will be wrong, although this is a minor issue.
       
   124 typedef HashSet<RenderFlow*> RenderFlowSequencedSet;
       
   125 
       
   126 // Base class for all rendering tree objects.
       
   127 class RenderObject : public CachedResourceClient {
       
   128     friend class RenderContainer;
       
   129 public:
       
   130     // Anonymous objects should pass the document as their node, and they will then automatically be
       
   131     // marked as anonymous in the constructor.
       
   132     RenderObject(Node*);
       
   133     virtual ~RenderObject();
       
   134 
       
   135     virtual const char* renderName() const { return "RenderObject"; }
       
   136 
       
   137     RenderObject* parent() const { return m_parent; }
       
   138     bool isDescendantOf(const RenderObject*) const;
       
   139 
       
   140     RenderObject* previousSibling() const { return m_previous; }
       
   141     RenderObject* nextSibling() const { return m_next; }
       
   142 
       
   143     virtual RenderObject* firstChild() const { return 0; }
       
   144     virtual RenderObject* lastChild() const { return 0; }
       
   145 
       
   146     RenderObject* nextInPreOrder() const;
       
   147     RenderObject* nextInPreOrder(RenderObject* stayWithin) const;
       
   148     RenderObject* nextInPreOrderAfterChildren() const;
       
   149     RenderObject* nextInPreOrderAfterChildren(RenderObject* stayWithin) const;
       
   150     RenderObject* previousInPreOrder() const;
       
   151     RenderObject* childAt(unsigned) const;
       
   152 
       
   153     RenderObject* firstLeafChild() const;
       
   154     RenderObject* lastLeafChild() const;
       
   155 
       
   156     virtual RenderLayer* layer() const { return 0; }
       
   157     RenderLayer* enclosingLayer() const;
       
   158     void addLayers(RenderLayer* parentLayer, RenderObject* newObject);
       
   159     void removeLayers(RenderLayer* parentLayer);
       
   160     void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
       
   161     RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
       
   162     virtual void positionChildLayers() { }
       
   163     virtual bool requiresLayer();
       
   164 
       
   165     virtual IntRect getOverflowClipRect(int /*tx*/, int /*ty*/) { return IntRect(0, 0, 0, 0); }
       
   166     virtual IntRect getClipRect(int /*tx*/, int /*ty*/) { return IntRect(0, 0, 0, 0); }
       
   167     bool hasClip() { return isPositioned() && style()->hasClip(); }
       
   168 
       
   169     virtual int getBaselineOfFirstLineBox() const { return -1; }
       
   170     virtual int getBaselineOfLastLineBox() const { return -1; }
       
   171 
       
   172     virtual bool isEmpty() const { return firstChild() == 0; }
       
   173 
       
   174     virtual bool isEdited() const { return false; }
       
   175     virtual void setEdited(bool) { }
       
   176 
       
   177     // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
       
   178     // children.
       
   179     virtual RenderBlock* firstLineBlock() const;
       
   180 
       
   181     // Called when an object that was floating or positioned becomes a normal flow object
       
   182     // again.  We have to make sure the render tree updates as needed to accommodate the new
       
   183     // normal flow object.
       
   184     void handleDynamicFloatPositionChange();
       
   185 
       
   186     // This function is a convenience helper for creating an anonymous block that inherits its
       
   187     // style from this RenderObject.
       
   188     RenderBlock* createAnonymousBlock();
       
   189 
       
   190     // Whether or not a positioned element requires normal flow x/y to be computed
       
   191     // to determine its position.
       
   192     bool hasStaticX() const;
       
   193     bool hasStaticY() const;
       
   194     virtual void setStaticX(int /*staticX*/) { }
       
   195     virtual void setStaticY(int /*staticY*/) { }
       
   196     virtual int staticX() const { return 0; }
       
   197     virtual int staticY() const { return 0; }
       
   198 
       
   199     // RenderObject tree manipulation
       
   200     //////////////////////////////////////////
       
   201     virtual bool canHaveChildren() const;
       
   202     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
       
   203     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
       
   204     virtual void removeChild(RenderObject*);
       
   205     virtual bool createsAnonymousWrapper() const { return false; }
       
   206 
       
   207     // raw tree manipulation
       
   208     virtual RenderObject* removeChildNode(RenderObject*, bool fullRemove = true);
       
   209     virtual void appendChildNode(RenderObject*, bool fullAppend = true);
       
   210     virtual void insertChildNode(RenderObject* child, RenderObject* before, bool fullInsert = true);
       
   211     // Designed for speed.  Don't waste time doing a bunch of work like layer updating and repainting when we know that our
       
   212     // change in parentage is not going to affect anything.
       
   213     virtual void moveChildNode(RenderObject*);
       
   214     //////////////////////////////////////////
       
   215 
       
   216 protected:
       
   217     //////////////////////////////////////////
       
   218     // Helper functions. Dangerous to use!
       
   219     void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
       
   220     void setNextSibling(RenderObject* next) { m_next = next; }
       
   221     void setParent(RenderObject* parent) { m_parent = parent; }
       
   222     //////////////////////////////////////////
       
   223 private:
       
   224     void addAbsoluteRectForLayer(IntRect& result);
       
   225 
       
   226 public:
       
   227 #ifndef NDEBUG
       
   228     DeprecatedString information() const;
       
   229     virtual void dump(TextStream*, DeprecatedString ind = "") const;
       
   230     void showTreeForThis() const;
       
   231 #endif
       
   232 
       
   233     static RenderObject* createObject(Node*, RenderStyle*);
       
   234 
       
   235     // Overloaded new operator.  Derived classes must override operator new
       
   236     // in order to allocate out of the RenderArena.
       
   237     void* operator new(size_t, RenderArena*) throw();
       
   238 
       
   239     // Overridden to prevent the normal delete from being called.
       
   240     void operator delete(void*, size_t);
       
   241 
       
   242 private:
       
   243     // The normal operator new is disallowed on all render objects.
       
   244     void* operator new(size_t) throw();
       
   245 
       
   246 public:
       
   247     RenderArena* renderArena() const { return document()->renderArena(); }
       
   248 
       
   249     virtual bool isRenderBlock() const { return false; }
       
   250     virtual bool isRenderInline() const { return false; }
       
   251     virtual bool isInlineFlow() const { return false; }
       
   252     virtual bool isBlockFlow() const { return false; }
       
   253     virtual bool isInlineBlockOrInlineTable() const { return false; }
       
   254     virtual bool isInlineContinuation() const;
       
   255     virtual bool isListItem() const { return false; }
       
   256     virtual bool isListMarker() const { return false; }
       
   257     virtual bool isCounter() const { return false; }
       
   258     virtual bool isRenderView() const { return false; }
       
   259     virtual bool isBR() const { return false; }
       
   260     virtual bool isTableCell() const { return false; }
       
   261     virtual bool isTableRow() const { return false; }
       
   262     virtual bool isTableSection() const { return false; }
       
   263     virtual bool isTableCol() const { return false; }
       
   264     virtual bool isTable() const { return false; }
       
   265     virtual bool isWidget() const { return false; }
       
   266     virtual bool isImage() const { return false; }
       
   267     virtual bool isTextArea() const { return false; }
       
   268     virtual bool isTextField() const { return false; }
       
   269     virtual bool isFrame() const { return false; }
       
   270     virtual bool isFrameSet() const { return false; }
       
   271     virtual bool isApplet() const { return false; }
       
   272     virtual bool isMenuList() const { return false; }
       
   273     virtual bool isListBox() const { return false; }
       
   274     virtual bool isSlider() const { return false; }
       
   275 
       
   276     bool isRoot() const { return document()->documentElement() == node(); }
       
   277     bool isBody() const;
       
   278     bool isHR() const;
       
   279 
       
   280     bool isHTMLMarquee() const;
       
   281 
       
   282     virtual bool childrenInline() const { return false; }
       
   283     virtual void setChildrenInline(bool) { }
       
   284 
       
   285     virtual RenderFlow* continuation() const;
       
   286 
       
   287 #if ENABLE(SVG)
       
   288     virtual bool isSVGContainer() const { return false; }
       
   289     virtual bool isRenderPath() const { return false; }
       
   290     virtual bool isSVGText() const { return false; }
       
   291 
       
   292     virtual FloatRect relativeBBox(bool includeStroke = true) const;
       
   293 
       
   294     virtual AffineTransform localTransform() const;
       
   295     virtual void setLocalTransform(const AffineTransform&);
       
   296     virtual AffineTransform absoluteTransform() const;
       
   297 #endif
       
   298 
       
   299     virtual bool isEditable() const;
       
   300 
       
   301     bool isAnonymous() const { return m_isAnonymous; }
       
   302     void setIsAnonymous(bool b) { m_isAnonymous = b; }
       
   303     bool isAnonymousBlock() const
       
   304     {
       
   305         return m_isAnonymous && style()->display() == BLOCK && style()->styleType() == RenderStyle::NOPSEUDO && !isListMarker();
       
   306     }
       
   307 
       
   308     bool isFloating() const { return m_floating; }
       
   309     bool isPositioned() const { return m_positioned; } // absolute or fixed positioning
       
   310     bool isRelPositioned() const { return m_relPositioned; } // relative positioning
       
   311     bool isText() const  { return m_isText; }
       
   312     bool isInline() const { return m_inline; }  // inline object
       
   313     bool isCompact() const { return style()->display() == COMPACT; } // compact object
       
   314     bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object
       
   315     bool isDragging() const { return m_isDragging; }
       
   316     bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS)
       
   317     
       
   318     bool hasLayer() const { return m_hasLayer; }
       
   319     
       
   320     bool hasBoxDecorations() const { return m_paintBackground; }
       
   321     bool mustRepaintBackgroundOrBorder() const;
       
   322 
       
   323     bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout; }
       
   324     bool selfNeedsLayout() const { return m_needsLayout; }
       
   325     bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
       
   326     bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
       
   327 
       
   328     bool prefWidthsDirty() const { return m_prefWidthsDirty; }
       
   329 
       
   330     bool isSelectionBorder() const;
       
   331 
       
   332     bool hasOverflowClip() const { return m_hasOverflowClip; }
       
   333     virtual bool hasControlClip() const { return false; }
       
   334     virtual IntRect controlClipRect(int /*tx*/, int /*ty*/) const { return IntRect(); }
       
   335 
       
   336     bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
       
   337     bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
       
   338 
       
   339     bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
       
   340     bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
       
   341     bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
       
   342 
       
   343     virtual int verticalScrollbarWidth() const;
       
   344     virtual int horizontalScrollbarHeight() const;
       
   345 private:
       
   346     bool includeVerticalScrollbarSize() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || style()->overflowY() == OAUTO); }
       
   347     bool includeHorizontalScrollbarSize() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || style()->overflowX() == OAUTO); }
       
   348 
       
   349 public:
       
   350     RenderStyle* getPseudoStyle(RenderStyle::PseudoId, RenderStyle* parentStyle = 0) const;
       
   351 
       
   352     void updateDragState(bool dragOn);
       
   353 
       
   354     RenderView* view() const;
       
   355 
       
   356     // don't even think about making this method virtual!
       
   357     Node* element() const { return m_isAnonymous ? 0 : m_node; }
       
   358     Document* document() const { return m_node->document(); }
       
   359     void setNode(Node* node) { m_node = node; }
       
   360     Node* node() const { return m_node; }
       
   361 
       
   362     bool hasOutlineAnnotation() const;
       
   363     bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
       
   364 
       
   365    /**
       
   366      * returns the object containing this one. can be different from parent for
       
   367      * positioned elements
       
   368      */
       
   369     RenderObject* container() const;
       
   370     RenderObject* hoverAncestor() const;
       
   371 
       
   372     virtual void markAllDescendantsWithFloatsForLayout(RenderObject* floatToRemove = 0);
       
   373     void markContainingBlocksForLayout(bool scheduleRelayout = true);
       
   374     void setNeedsLayout(bool b, bool markParents = true);
       
   375     void setChildNeedsLayout(bool b, bool markParents = true);
       
   376 
       
   377     void setPrefWidthsDirty(bool, bool markParents = true);
       
   378     void invalidateContainerPrefWidths();
       
   379     
       
   380     void setNeedsLayoutAndPrefWidthsRecalc()
       
   381     {
       
   382         setNeedsLayout(true);
       
   383         setPrefWidthsDirty(true);
       
   384     }
       
   385 
       
   386     void setPositioned(bool b = true)  { m_positioned = b;  }
       
   387     void setRelPositioned(bool b = true) { m_relPositioned = b; }
       
   388     void setFloating(bool b = true) { m_floating = b; }
       
   389     void setInline(bool b = true) { m_inline = b; }
       
   390     void setHasBoxDecorations(bool b = true) { m_paintBackground = b; }
       
   391     void setRenderText() { m_isText = true; }
       
   392     void setReplaced(bool b = true) { m_replaced = b; }
       
   393     void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
       
   394     void setHasLayer(bool b = true) { m_hasLayer = b; }
       
   395 
       
   396     void scheduleRelayout();
       
   397 
       
   398     void updateBackgroundImages(RenderStyle* oldStyle);
       
   399 
       
   400     virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false);
       
   401     virtual void dirtyLineBoxes(bool fullLayout, bool isRootLineBox = false);
       
   402 
       
   403     // For inline replaced elements, this function returns the inline box that owns us.  Enables
       
   404     // the replaced RenderObject to quickly determine what line it is contained on and to easily
       
   405     // iterate over structures on the line.
       
   406     virtual InlineBox* inlineBoxWrapper() const;
       
   407     virtual void setInlineBoxWrapper(InlineBox*);
       
   408     virtual void deleteLineBoxWrapper();
       
   409 
       
   410     virtual InlineBox* inlineBox(int offset = 0, EAffinity = UPSTREAM);
       
   411 
       
   412     // for discussion of lineHeight see CSS2 spec
       
   413     virtual short lineHeight(bool firstLine, bool isRootLineBox = false) const;
       
   414     // for the vertical-align property of inline elements
       
   415     // the difference between this objects baseline position and the lines baseline position.
       
   416     virtual short verticalPositionHint(bool firstLine) const;
       
   417     // the offset of baseline from the top of the object.
       
   418     virtual short baselinePosition(bool firstLine, bool isRootLineBox = false) const;
       
   419 
       
   420     /*
       
   421      * Paint the object and its children, clipped by (x|y|w|h).
       
   422      * (tx|ty) is the calculated position of the parent
       
   423      */
       
   424     struct PaintInfo {
       
   425         PaintInfo(GraphicsContext* newContext, const IntRect& newRect, PaintPhase newPhase, bool newForceBlackText,
       
   426                   RenderObject* newPaintingRoot, RenderFlowSequencedSet* newOutlineObjects)
       
   427             : context(newContext)
       
   428             , rect(newRect)
       
   429             , phase(newPhase)
       
   430             , forceBlackText(newForceBlackText)
       
   431             , paintingRoot(newPaintingRoot)
       
   432             , outlineObjects(newOutlineObjects)
       
   433         {
       
   434         }
       
   435 
       
   436         GraphicsContext* context;
       
   437         IntRect rect;
       
   438         PaintPhase phase;
       
   439         bool forceBlackText;
       
   440         RenderObject* paintingRoot; // used to draw just one element and its visual kids
       
   441         RenderFlowSequencedSet* outlineObjects; // used to list outlines that should be painted by a block with inline children
       
   442     };
       
   443 
       
   444     virtual void paint(PaintInfo&, int tx, int ty);
       
   445     void paintBorder(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, bool begin = true, bool end = true);
       
   446     bool paintBorderImage(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*);
       
   447     void paintOutline(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*);
       
   448     void paintBoxShadow(GraphicsContext*, int tx, int ty, int w, int h, const RenderStyle*, bool begin = true, bool end = true);
       
   449 
       
   450     // RenderBox implements this.
       
   451     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty) { }
       
   452 
       
   453     virtual void paintBackgroundExtended(GraphicsContext*, const Color&, const BackgroundLayer*,
       
   454                                          int clipy, int cliph, int tx, int ty, int width, int height,
       
   455                                          bool includeLeftEdge = true, bool includeRightEdge = true) { }
       
   456 
       
   457     
       
   458     /*
       
   459      * Calculates the actual width of the object (only for non inline
       
   460      * objects)
       
   461      */
       
   462     virtual void calcWidth() { }
       
   463 
       
   464     /*
       
   465      * This function should cause the Element to calculate its
       
   466      * width and height and the layout of its content
       
   467      *
       
   468      * when the Element calls setNeedsLayout(false), layout() is no
       
   469      * longer called during relayouts, as long as there is no
       
   470      * style sheet change. When that occurs, m_needsLayout will be
       
   471      * set to true and the Element receives layout() calls
       
   472      * again.
       
   473      */
       
   474     virtual void layout() = 0;
       
   475 
       
   476     /* This function performs a layout only if one is needed. */
       
   477     void layoutIfNeeded() { if (needsLayout()) layout(); }
       
   478 
       
   479     // used for element state updates that can not be fixed with a
       
   480     // repaint and do not need a relayout
       
   481     virtual void updateFromElement() { }
       
   482 
       
   483     // Block flows subclass availableWidth to handle multi column layout (shrinking the width available to children when laying out.)
       
   484     virtual int availableWidth() const { return contentWidth(); }
       
   485     
       
   486     virtual int availableHeight() const { return 0; }
       
   487 
       
   488     virtual void updateWidgetPosition();
       
   489 
       
   490     void addDashboardRegions(Vector<DashboardRegionValue>&);
       
   491     void collectDashboardRegions(Vector<DashboardRegionValue>&);
       
   492 
       
   493     // Used to signal a specific subrect within an object that must be repainted after
       
   494     // layout is complete.
       
   495     struct RepaintInfo {
       
   496         RepaintInfo(RenderObject* object = 0, const IntRect& repaintRect = IntRect())
       
   497             : m_object(object)
       
   498             , m_repaintRect(repaintRect)
       
   499         {
       
   500         }
       
   501 
       
   502         RenderObject* m_object;
       
   503         IntRect m_repaintRect;
       
   504     };
       
   505 
       
   506     bool hitTest(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestFilter = HitTestAll);
       
   507     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
       
   508     void updateHitTestResult(HitTestResult&, const IntPoint&);
       
   509 
       
   510     virtual VisiblePosition positionForCoordinates(int x, int y);
       
   511     VisiblePosition positionForPoint(const IntPoint& point) { return positionForCoordinates(point.x(), point.y()); }
       
   512 
       
   513     virtual void dirtyLinesFromChangedChild(RenderObject*);
       
   514 
       
   515     // Set the style of the object and update the state of the object accordingly.
       
   516     virtual void setStyle(RenderStyle*);
       
   517 
       
   518     // Updates only the local style ptr of the object.  Does not update the state of the object,
       
   519     // and so only should be called when the style is known not to have changed (or from setStyle).
       
   520     void setStyleInternal(RenderStyle*);
       
   521 
       
   522     // returns the containing block level element for this element.
       
   523     RenderBlock* containingBlock() const;
       
   524 
       
   525     // return just the width of the containing block
       
   526     virtual int containingBlockWidth() const;
       
   527     // return just the height of the containing block
       
   528     virtual int containingBlockHeight() const;
       
   529 
       
   530     // content area (box minus padding/border)
       
   531     IntRect contentBox() const;
       
   532     IntRect absoluteContentBox() const;
       
   533     int contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
       
   534     int contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
       
   535 
       
   536     // used by flexible boxes to impose a flexed width/height override
       
   537     virtual int overrideSize() const { return 0; }
       
   538     virtual int overrideWidth() const { return 0; }
       
   539     virtual int overrideHeight() const { return 0; }
       
   540     virtual void setOverrideSize(int /*overrideSize*/) { }
       
   541 
       
   542     // relative to parent node
       
   543     virtual void setPos(int /*xPos*/, int /*yPos*/) { }
       
   544     virtual void setWidth(int /*width*/) { }
       
   545     virtual void setHeight(int /*height*/) { }
       
   546 
       
   547     virtual int xPos() const { return 0; }
       
   548     virtual int yPos() const { return 0; }
       
   549 
       
   550     // calculate client position of box
       
   551     virtual bool absolutePosition(int& x, int& y, bool fixed = false) const;
       
   552 
       
   553     // This function is used to deal with the extra top space that can occur in table cells (called borderTopExtra).
       
   554     // The children of the cell do not factor this space in, so we have to add it in.  Any code that wants to
       
   555     // accurately deal with the contents of a cell must call this function instad of absolutePosition.
       
   556     void absolutePositionForContent(int& xPos, int& yPos, bool fixed = false) const
       
   557     {
       
   558         absolutePosition(xPos, yPos, fixed);
       
   559         yPos += borderTopExtra();
       
   560     }
       
   561 
       
   562     // width and height are without margins but include paddings and borders
       
   563     virtual int width() const { return 0; }
       
   564     virtual int height() const { return 0; }
       
   565 
       
   566     virtual IntRect borderBox() const { return IntRect(0, 0, width(), height()); }
       
   567     IntRect absoluteOutlineBox() const;
       
   568 
       
   569     // The height of a block when you include normal flow overflow spillage out of the bottom
       
   570     // of the block (e.g., a <div style="height:25px"> that has a 100px tall image inside
       
   571     // it would have an overflow height of borderTop() + paddingTop() + 100px.
       
   572     virtual int overflowHeight(bool /*includeInterior*/ = true) const { return height(); }
       
   573     virtual int overflowWidth(bool /*includeInterior*/ = true) const { return width(); }
       
   574     virtual void setOverflowHeight(int) { }
       
   575     virtual void setOverflowWidth(int) { }
       
   576     virtual int overflowLeft(bool /*includeInterior*/ = true) const { return 0; }
       
   577     virtual int overflowTop(bool /*includeInterior*/ = true) const { return 0; }
       
   578     virtual IntRect overflowRect(bool /*includeInterior*/ = true) const { return borderBox(); }
       
   579 
       
   580     // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
       
   581     // to return the remaining width on a given line (and the height of a single line). -dwh
       
   582     virtual int offsetWidth() const { return width(); }
       
   583     virtual int offsetHeight() const { return height() + borderTopExtra() + borderBottomExtra(); }
       
   584 
       
   585     // IE extensions.  Also supported by Gecko.  We override in render flow to get the
       
   586     // left and top correct. -dwh
       
   587     virtual int offsetLeft() const;
       
   588     virtual int offsetTop() const;
       
   589     virtual RenderObject* offsetParent() const;
       
   590 
       
   591     // More IE extensions.  clientWidth and clientHeight represent the interior of an object
       
   592     // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
       
   593     int clientLeft() const { return borderLeft(); }
       
   594     int clientTop() const { return borderTop(); }
       
   595     int clientWidth() const;
       
   596     int clientHeight() const;
       
   597 
       
   598     // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
       
   599     // object has overflow:hidden/scroll/auto specified and also has overflow.
       
   600     // scrollLeft/Top return the current scroll position.  These methods are virtual so that objects like
       
   601     // textareas can scroll shadow content (but pretend that they are the objects that are
       
   602     // scrolling).
       
   603     virtual int scrollLeft() const;
       
   604     virtual int scrollTop() const;
       
   605     virtual int scrollWidth() const;
       
   606     virtual int scrollHeight() const;
       
   607     virtual void setScrollLeft(int);
       
   608     virtual void setScrollTop(int);
       
   609 
       
   610     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f);
       
   611     virtual bool shouldAutoscroll() const;
       
   612     virtual void autoscroll();
       
   613     virtual void stopAutoscroll() { }
       
   614     virtual bool isScrollable() const;
       
   615 
       
   616     // The following seven functions are used to implement collapsing margins.
       
   617     // All objects know their maximal positive and negative margins.  The
       
   618     // formula for computing a collapsed margin is |maxPosMargin|-|maxNegmargin|.
       
   619     // For a non-collapsing, e.g., a leaf element, this formula will simply return
       
   620     // the margin of the element.  Blocks override the maxTopMargin and maxBottomMargin
       
   621     // methods.
       
   622     virtual bool isSelfCollapsingBlock() const { return false; }
       
   623     virtual int collapsedMarginTop() const { return maxTopMargin(true) - maxTopMargin(false); }
       
   624     virtual int collapsedMarginBottom() const { return maxBottomMargin(true) - maxBottomMargin(false); }
       
   625     virtual bool isTopMarginQuirk() const { return false; }
       
   626     virtual bool isBottomMarginQuirk() const { return false; }
       
   627 
       
   628     virtual int maxTopMargin(bool positive) const;
       
   629     virtual int maxBottomMargin(bool positive) const;
       
   630 
       
   631     virtual int marginTop() const { return 0; }
       
   632     virtual int marginBottom() const { return 0; }
       
   633     virtual int marginLeft() const { return 0; }
       
   634     virtual int marginRight() const { return 0; }
       
   635 
       
   636     // Virtual since table cells override
       
   637     virtual int paddingTop() const;
       
   638     virtual int paddingBottom() const;
       
   639     virtual int paddingLeft() const;
       
   640     virtual int paddingRight() const;
       
   641 
       
   642     virtual int borderTop() const { return style()->borderTopWidth(); }
       
   643     virtual int borderBottom() const { return style()->borderBottomWidth(); }
       
   644     virtual int borderTopExtra() const { return 0; }
       
   645     virtual int borderBottomExtra() const { return 0; }
       
   646     virtual int borderLeft() const { return style()->borderLeftWidth(); }
       
   647     virtual int borderRight() const { return style()->borderRightWidth(); }
       
   648 
       
   649     virtual void addLineBoxRects(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
       
   650 
       
   651     virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
       
   652     IntRect absoluteBoundingBoxRect();
       
   653 
       
   654     // the rect that will be painted if this object is passed as the paintingRoot
       
   655     IntRect paintingRootRect(IntRect& topLevelRect);
       
   656 
       
   657     void addPDFURLRect(GraphicsContext*, IntRect);
       
   658 
       
   659     virtual void addFocusRingRects(GraphicsContext*, int tx, int ty);
       
   660 
       
   661     virtual int minPrefWidth() const { return 0; }
       
   662     virtual int maxPrefWidth() const { return 0; }
       
   663 
       
   664     RenderStyle* style() const { return m_style; }
       
   665     RenderStyle* firstLineStyle() const;
       
   666     RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
       
   667 
       
   668     void getTextDecorationColors(int decorations, Color& underline, Color& overline,
       
   669                                  Color& linethrough, bool quirksMode = false);
       
   670 
       
   671     enum BorderSide {
       
   672         BSTop,
       
   673         BSBottom,
       
   674         BSLeft,
       
   675         BSRight
       
   676     };
       
   677 
       
   678     void drawBorderArc(GraphicsContext*, int x, int y, float thickness, IntSize radius, int angleStart,
       
   679                        int angleSpan, BorderSide, Color, const Color& textcolor, EBorderStyle, bool firstCorner);
       
   680     void drawBorder(GraphicsContext*, int x1, int y1, int x2, int y2, BorderSide,
       
   681                     Color, const Color& textcolor, EBorderStyle, int adjbw1, int adjbw2);
       
   682 
       
   683     // Repaint the entire object.  Called when, e.g., the color of a border changes, or when a border
       
   684     // style changes.
       
   685     void repaint(bool immediate = false);
       
   686 
       
   687     // Repaint a specific subrectangle within a given object.  The rect |r| is in the object's coordinate space.
       
   688     void repaintRectangle(const IntRect&, bool immediate = false);
       
   689 
       
   690     // Repaint only if our old bounds and new bounds are different.
       
   691     bool repaintAfterLayoutIfNeeded(const IntRect& oldBounds, const IntRect& oldOutlineBox);
       
   692 
       
   693     // Repaint only if the object moved.
       
   694     virtual void repaintDuringLayoutIfMoved(const IntRect& rect);
       
   695 
       
   696     // Called to repaint a block's floats.
       
   697     virtual void repaintOverhangingFloats(bool paintAllDescendants = false);
       
   698 
       
   699     bool checkForRepaintDuringLayout() const;
       
   700 
       
   701     // Returns the rect that should be repainted whenever this object changes.  The rect is in the view's
       
   702     // coordinate space.  This method deals with outlines and overflow.
       
   703     virtual IntRect absoluteClippedOverflowRect();
       
   704 
       
   705     IntRect getAbsoluteRepaintRectWithOutline(int ow);
       
   706 
       
   707     // Given a rect in the object's coordinate space, this method converts the rectangle to the view's
       
   708     // coordinate space.
       
   709     virtual void computeAbsoluteRepaintRect(IntRect&, bool fixed = false);
       
   710 
       
   711     virtual unsigned int length() const { return 1; }
       
   712 
       
   713     bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); }
       
   714     virtual bool containsFloats() { return false; }
       
   715     virtual bool containsFloat(RenderObject*) { return false; }
       
   716     virtual bool hasOverhangingFloats() { return false; }
       
   717     virtual bool expandsToEncloseOverhangingFloats() const { return isFloating() && style()->height().isAuto(); }
       
   718 
       
   719     virtual void removePositionedObjects(RenderBlock*) { }
       
   720 
       
   721     virtual bool avoidsFloats() const;
       
   722     bool shrinkToAvoidFloats() const;
       
   723 
       
   724     // positioning of inline children (bidi)
       
   725     virtual void position(InlineBox*) { }
       
   726 
       
   727     bool isTransparent() const { return style()->opacity() < 1.0f; }
       
   728     float opacity() const { return style()->opacity(); }
       
   729 
       
   730     // Applied as a "slop" to dirty rect checks during the outline painting phase's dirty-rect checks.
       
   731     int maximalOutlineSize(PaintPhase) const;
       
   732 
       
   733     enum SelectionState {
       
   734         SelectionNone, // The object is not selected.
       
   735         SelectionStart, // The object either contains the start of a selection run or is the start of a run
       
   736         SelectionInside, // The object is fully encompassed by a selection run
       
   737         SelectionEnd, // The object either contains the end of a selection run or is the end of a run
       
   738         SelectionBoth // The object contains an entire run or is the sole selected object in that run
       
   739     };
       
   740 
       
   741     // The current selection state for an object.  For blocks, the state refers to the state of the leaf
       
   742     // descendants (as described above in the SelectionState enum declaration).
       
   743     virtual SelectionState selectionState() const { return SelectionNone; }
       
   744 
       
   745     // Sets the selection state for an object.
       
   746     virtual void setSelectionState(SelectionState state) { if (parent()) parent()->setSelectionState(state); }
       
   747 
       
   748     // A single rectangle that encompasses all of the selected objects within this object.  Used to determine the tightest
       
   749     // possible bounding box for the selection.
       
   750     virtual IntRect selectionRect(bool) { return IntRect(); }
       
   751 
       
   752     // Whether or not an object can be part of the leaf elements of the selection.
       
   753     virtual bool canBeSelectionLeaf() const { return false; }
       
   754 
       
   755     // Whether or not a block has selected children.
       
   756     virtual bool hasSelectedChildren() const { return false; }
       
   757 
       
   758     // Obtains the selection colors that should be used when painting a selection.
       
   759     Color selectionBackgroundColor() const;
       
   760     Color selectionForegroundColor() const;
       
   761 
       
   762     // Whether or not a given block needs to paint selection gaps.
       
   763     virtual bool shouldPaintSelectionGaps() const { return false; }
       
   764 
       
   765     // This struct is used when the selection changes to cache the old and new state of the selection for each RenderObject.
       
   766     struct SelectionInfo {
       
   767         SelectionInfo()
       
   768             : m_object(0)
       
   769             , m_state(SelectionNone)
       
   770         {
       
   771         }
       
   772 
       
   773         SelectionInfo(RenderObject* o, bool clipToVisibleContent)
       
   774             : m_object(o)
       
   775             , m_rect(o->needsLayout() ? IntRect() : o->selectionRect(clipToVisibleContent))
       
   776             , m_state(o->selectionState())
       
   777         {
       
   778         }
       
   779 
       
   780         RenderObject* object() const { return m_object; }
       
   781         IntRect rect() const { return m_rect; }
       
   782         SelectionState state() const { return m_state; }
       
   783 
       
   784         RenderObject* m_object;
       
   785         IntRect m_rect;
       
   786         SelectionState m_state;
       
   787     };
       
   788 
       
   789     Node* draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const;
       
   790 
       
   791     /**
       
   792      * Returns the content coordinates of the caret within this render object.
       
   793      * @param offset zero-based offset determining position within the render object.
       
   794      * @param override @p true if input overrides existing characters,
       
   795      * @p false if it inserts them. The width of the caret depends on this one.
       
   796      * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
       
   797      * useful for character range rect computations
       
   798      */
       
   799     virtual IntRect caretRect(int offset, EAffinity = UPSTREAM, int* extraWidthToEndOfLine = 0);
       
   800 
       
   801     virtual int lowestPosition(bool /*includeOverflowInterior*/ = true, bool /*includeSelf*/ = true) const { return 0; }
       
   802     virtual int rightmostPosition(bool /*includeOverflowInterior*/ = true, bool /*includeSelf*/ = true) const { return 0; }
       
   803     virtual int leftmostPosition(bool /*includeOverflowInterior*/ = true, bool /*includeSelf*/ = true) const { return 0; }
       
   804 
       
   805     virtual void calcVerticalMargins() { }
       
   806     void removeFromObjectLists();
       
   807 
       
   808     // When performing a global document tear-down, the renderer of the document is cleared.  We use this
       
   809     // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
       
   810     bool documentBeingDestroyed() const;
       
   811 
       
   812     virtual void destroy();
       
   813 
       
   814     // Virtual function helpers for CSS3 Flexible Box Layout
       
   815     virtual bool isFlexibleBox() const { return false; }
       
   816     virtual bool isFlexingChildren() const { return false; }
       
   817     virtual bool isStretchingChildren() const { return false; }
       
   818 
       
   819     // Convenience, to avoid repeating the code to dig down to get this.
       
   820     UChar backslashAsCurrencySymbol() const;
       
   821 
       
   822     virtual int caretMinOffset() const;
       
   823     virtual int caretMaxOffset() const;
       
   824     virtual unsigned caretMaxRenderedOffset() const;
       
   825 
       
   826     virtual int previousOffset(int current) const;
       
   827     virtual int nextOffset(int current) const;
       
   828 
       
   829     virtual void imageChanged(CachedImage*) { }
       
   830     virtual bool willRenderImage(CachedImage*);
       
   831 
       
   832     virtual void selectionStartEnd(int& spos, int& epos) const;
       
   833 
       
   834     RenderObject* paintingRootForChildren(PaintInfo& paintInfo) const
       
   835     {
       
   836         // if we're the painting root, kids draw normally, and see root of 0
       
   837         return (!paintInfo.paintingRoot || paintInfo.paintingRoot == this) ? 0 : paintInfo.paintingRoot;
       
   838     }
       
   839 
       
   840     bool shouldPaintWithinRoot(PaintInfo& paintInfo) const
       
   841     {
       
   842         return !paintInfo.paintingRoot || paintInfo.paintingRoot == this;
       
   843     }
       
   844 
       
   845     bool hasOverrideSize() const { return m_hasOverrideSize; }
       
   846     void setHasOverrideSize(bool b) { m_hasOverrideSize = b; }
       
   847     
       
   848     void remove() { if (parent()) parent()->removeChild(this); }
       
   849 
       
   850     void invalidateVerticalPosition() { m_verticalPosition = PositionUndefined; }
       
   851     
       
   852     virtual void removeLeftoverAnonymousBlock(RenderBlock* child);
       
   853 
       
   854 protected:
       
   855     virtual void printBoxDecorations(GraphicsContext*, int /*x*/, int /*y*/, int /*w*/, int /*h*/, int /*tx*/, int /*ty*/) { }
       
   856 
       
   857     virtual IntRect viewRect() const;
       
   858 
       
   859     short getVerticalPosition(bool firstLine) const;
       
   860 
       
   861     void adjustRectForOutlineAndShadow(IntRect&) const;
       
   862 
       
   863     void arenaDelete(RenderArena*, void* objectBase);
       
   864 
       
   865 private:
       
   866     RenderStyle* m_style;
       
   867 
       
   868     Node* m_node;
       
   869 
       
   870     RenderObject* m_parent;
       
   871     RenderObject* m_previous;
       
   872     RenderObject* m_next;
       
   873 
       
   874 #if PLATFORM(SYMBIAN)
       
   875     mutable short m_verticalPosition;
       
   876 #else
       
   877     mutable short m_verticalPosition : 15;
       
   878 #endif    
       
   879 
       
   880     bool m_needsLayout               : 1;
       
   881     bool m_normalChildNeedsLayout    : 1;
       
   882     bool m_posChildNeedsLayout       : 1;
       
   883     bool m_prefWidthsDirty           : 1;
       
   884     bool m_floating                  : 1;
       
   885 
       
   886     bool m_positioned                : 1;
       
   887     bool m_relPositioned             : 1;
       
   888     bool m_paintBackground           : 1; // if the box has something to paint in the
       
   889                                           // background painting phase (background, border, etc)
       
   890 
       
   891     bool m_isAnonymous               : 1;
       
   892     bool m_isText                    : 1;
       
   893     bool m_inline                    : 1;
       
   894     bool m_replaced                  : 1;
       
   895     bool m_isDragging                : 1;
       
   896 
       
   897     bool m_hasLayer                  : 1;
       
   898     bool m_hasOverflowClip           : 1;
       
   899 
       
   900     bool m_hasOverrideSize           : 1;
       
   901     
       
   902 public:
       
   903     bool m_hasCounterNodeMap         : 1;
       
   904 };
       
   905 
       
   906 } // namespace WebCore
       
   907 
       
   908 #ifndef NDEBUG
       
   909 // Outside the WebCore namespace for ease of invocation from gdb.
       
   910 void showTree(const WebCore::RenderObject*);
       
   911 #endif
       
   912 
       
   913 #endif // RenderObject_h