root/trunk/WebCore/rendering/RenderObject.h

Revision 50851, 43.4 KB (checked in by eric@webkit.org, 10 days ago)

2009-11-11 Kent Tamura < tkent@chromium.org>

Reviewed by Darin Adler.

Print the file text of a file upload control in DumpRenderTree for ease of tests.
 https://bugs.webkit.org/show_bug.cgi?id=31195

  • platform/mac-leopard/fast/forms/file-input-disabled-expected.txt:
  • platform/mac/fast/forms/box-shadow-override-expected.txt:
  • platform/mac/fast/forms/file-input-direction-expected.txt:
  • platform/mac/fast/forms/file-input-disabled-expected.txt:
  • platform/mac/fast/forms/form-element-geometry-expected.txt:
  • platform/mac/fast/forms/hidden-input-file-expected.txt:
  • platform/mac/fast/forms/input-appearance-height-expected.txt:
  • platform/mac/fast/forms/input-value-expected.txt:
  • platform/win/fast/forms/box-shadow-override-expected.txt:
  • platform/win/fast/forms/file-input-disabled-expected.txt:
  • platform/win/fast/forms/input-appearance-height-expected.txt:
  • platform/win/fast/forms/input-value-expected.txt:

2009-11-11 Kent Tamura < tkent@chromium.org>

Reviewed by Darin Adler.

Print the file text of a file upload control in DumpRenderTree for ease of tests.
 https://bugs.webkit.org/show_bug.cgi?id=31195

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