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.
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.
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.
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.
26 #ifndef RenderObject_h
27 #define RenderObject_h
29 #include "CachedResourceClient.h"
32 #include "FloatQuad.h"
33 #include "LayoutTypes.h"
34 #include "PaintPhase.h"
35 #include "RenderObjectChildList.h"
36 #include "RenderStyle.h"
37 #include "TextAffinity.h"
38 #include "TransformationMatrix.h"
39 #include <wtf/UnusedParam.h>
41 #if USE(CG) || USE(CAIRO) || USE(SKIA) || PLATFORM(QT)
42 #define HAVE_PATH_BASED_BORDER_RADIUS_DRAWING 1
47 class AffineTransform;
48 class AnimationController;
52 class OverlapTestRequestClient;
55 class RenderBoxModelObject;
58 class RenderFlowThread;
62 class VisiblePosition;
64 class RenderSVGResourceContainer;
76 HitTestBlockBackground,
77 HitTestChildBlockBackground,
78 HitTestChildBlockBackgrounds,
83 // Sides used when drawing borders and outlines. The values should run clockwise from top.
91 const int caretWidth = 1;
93 #if ENABLE(DASHBOARD_SUPPORT)
94 struct DashboardRegionValue {
95 bool operator==(const DashboardRegionValue& o) const
97 return type == o.type && bounds == o.bounds && clip == o.clip && label == o.label;
99 bool operator!=(const DashboardRegionValue& o) const
101 return !(*this == o);
112 const int showTreeCharacterOffset = 39;
115 // Base class for all rendering tree objects.
116 class RenderObject : public CachedResourceClient {
117 friend class LayoutRepainter;
118 friend class RenderBlock;
119 friend class RenderBox;
120 friend class RenderLayer;
121 friend class RenderObjectChildList;
122 friend class RenderSVGContainer;
124 // Anonymous objects should pass the document as their node, and they will then automatically be
125 // marked as anonymous in the constructor.
127 virtual ~RenderObject();
129 RenderTheme* theme() const;
131 virtual const char* renderName() const = 0;
133 RenderObject* parent() const { return m_parent; }
134 bool isDescendantOf(const RenderObject*) const;
136 RenderObject* previousSibling() const { return m_previous; }
137 RenderObject* nextSibling() const { return m_next; }
139 RenderObject* firstChild() const
141 if (const RenderObjectChildList* children = virtualChildren())
142 return children->firstChild();
145 RenderObject* lastChild() const
147 if (const RenderObjectChildList* children = virtualChildren())
148 return children->lastChild();
151 RenderObject* beforePseudoElementRenderer() const
153 if (const RenderObjectChildList* children = virtualChildren())
154 return children->beforePseudoElementRenderer(this);
157 RenderObject* afterPseudoElementRenderer() const
159 if (const RenderObjectChildList* children = virtualChildren())
160 return children->afterPseudoElementRenderer(this);
163 virtual RenderObjectChildList* virtualChildren() { return 0; }
164 virtual const RenderObjectChildList* virtualChildren() const { return 0; }
166 RenderObject* nextInPreOrder() const;
167 RenderObject* nextInPreOrder(RenderObject* stayWithin) const;
168 RenderObject* nextInPreOrderAfterChildren() const;
169 RenderObject* nextInPreOrderAfterChildren(RenderObject* stayWithin) const;
170 RenderObject* previousInPreOrder() const;
171 RenderObject* childAt(unsigned) const;
173 RenderObject* firstLeafChild() const;
174 RenderObject* lastLeafChild() const;
176 // The following six functions are used when the render tree hierarchy changes to make sure layers get
177 // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
178 // can contain a mixture of boxes and other object types, these functions need to be in the base class.
179 RenderLayer* enclosingLayer() const;
180 void addLayers(RenderLayer* parentLayer);
181 void removeLayers(RenderLayer* parentLayer);
182 void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
183 RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
185 // Convenience function for getting to the nearest enclosing box of a RenderObject.
186 RenderBox* enclosingBox() const;
187 RenderBoxModelObject* enclosingBoxModelObject() const;
189 // Function to return our enclosing flow thread if we are contained inside one.
190 RenderFlowThread* enclosingRenderFlowThread() const;
192 virtual bool isEmpty() const { return firstChild() == 0; }
195 void setHasAXObject(bool flag) { m_hasAXObject = flag; }
196 bool hasAXObject() const { return m_hasAXObject; }
197 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; }
198 void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; }
201 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
203 virtual RenderBlock* firstLineBlock() const;
205 // Called when an object that was floating or positioned becomes a normal flow object
206 // again. We have to make sure the render tree updates as needed to accommodate the new
207 // normal flow object.
208 void handleDynamicFloatPositionChange();
210 // RenderObject tree manipulation
211 //////////////////////////////////////////
212 virtual bool canHaveChildren() const { return virtualChildren(); }
213 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
214 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
215 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); }
216 virtual void removeChild(RenderObject*);
217 virtual bool createsAnonymousWrapper() const { return false; }
218 //////////////////////////////////////////
221 //////////////////////////////////////////
222 // Helper functions. Dangerous to use!
223 void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
224 void setNextSibling(RenderObject* next) { m_next = next; }
225 void setParent(RenderObject* parent) { m_parent = parent; }
226 //////////////////////////////////////////
228 void addAbsoluteRectForLayer(IntRect& result);
229 void setLayerNeedsFullRepaint();
233 void showTreeForThis() const;
234 void showRenderTreeForThis() const;
235 void showLineTreeForThis() const;
237 void showRenderObject() const;
238 // We don't make printedCharacters an optional parameter so that
239 // showRenderObject can be called from gdb easily.
240 void showRenderObject(int printedCharacters) const;
241 void showRenderTreeAndMark(const RenderObject* markedObject1 = 0, const char* markedLabel1 = 0, const RenderObject* markedObject2 = 0, const char* markedLabel2 = 0, int depth = 0) const;
244 static RenderObject* createObject(Node*, RenderStyle*);
246 // Overloaded new operator. Derived classes must override operator new
247 // in order to allocate out of the RenderArena.
248 void* operator new(size_t, RenderArena*) throw();
250 // Overridden to prevent the normal delete from being called.
251 void operator delete(void*, size_t);
254 // The normal operator new is disallowed on all render objects.
255 void* operator new(size_t) throw();
258 RenderArena* renderArena() const { return document()->renderArena(); }
260 virtual bool isApplet() const { return false; }
261 virtual bool isBR() const { return false; }
262 virtual bool isBlockFlow() const { return false; }
263 virtual bool isBoxModelObject() const { return false; }
264 virtual bool isCounter() const { return false; }
265 virtual bool isQuote() const { return false; }
267 virtual bool isDetails() const { return false; }
268 virtual bool isDetailsMarker() const { return false; }
270 virtual bool isEmbeddedObject() const { return false; }
271 virtual bool isFieldset() const { return false; }
272 virtual bool isFileUploadControl() const { return false; }
273 virtual bool isFrame() const { return false; }
274 virtual bool isFrameSet() const { return false; }
275 virtual bool isImage() const { return false; }
276 virtual bool isInlineBlockOrInlineTable() const { return false; }
277 virtual bool isListBox() const { return false; }
278 virtual bool isListItem() const { return false; }
279 virtual bool isListMarker() const { return false; }
280 virtual bool isMedia() const { return false; }
281 virtual bool isMenuList() const { return false; }
282 #if ENABLE(METER_TAG)
283 virtual bool isMeter() const { return false; }
285 #if ENABLE(PROGRESS_TAG)
286 virtual bool isProgress() const { return false; }
288 virtual bool isRenderBlock() const { return false; }
289 virtual bool isRenderButton() const { return false; }
290 virtual bool isRenderIFrame() const { return false; }
291 virtual bool isRenderImage() const { return false; }
292 virtual bool isRenderInline() const { return false; }
293 virtual bool isRenderPart() const { return false; }
294 virtual bool isRenderRegion() const { return false; }
295 virtual bool isRenderView() const { return false; }
296 virtual bool isReplica() const { return false; }
298 virtual bool isRuby() const { return false; }
299 virtual bool isRubyBase() const { return false; }
300 virtual bool isRubyRun() const { return false; }
301 virtual bool isRubyText() const { return false; }
303 virtual bool isSlider() const { return false; }
304 virtual bool isSliderThumb() const { return false; }
306 virtual bool isSummary() const { return false; }
308 virtual bool isTable() const { return false; }
309 virtual bool isTableCell() const { return false; }
310 virtual bool isTableCol() const { return false; }
311 virtual bool isTableRow() const { return false; }
312 virtual bool isTableSection() const { return false; }
313 virtual bool isTextControl() const { return false; }
314 virtual bool isTextArea() const { return false; }
315 virtual bool isTextField() const { return false; }
316 virtual bool isVideo() const { return false; }
317 virtual bool isWidget() const { return false; }
318 virtual bool isCanvas() const { return false; }
319 #if ENABLE(FULLSCREEN_API)
320 virtual bool isRenderFullScreen() const { return false; }
321 virtual bool isRenderFullScreenPlaceholder() const { return false; }
324 virtual bool isRenderFlowThread() const { return false; }
326 bool isRoot() const { return document()->documentElement() == m_node; }
329 bool isLegend() const;
331 bool isHTMLMarquee() const;
333 inline bool isBeforeContent() const;
334 inline bool isAfterContent() const;
335 inline bool isBeforeOrAfterContent() const;
336 static inline bool isBeforeContent(const RenderObject* obj) { return obj && obj->isBeforeContent(); }
337 static inline bool isAfterContent(const RenderObject* obj) { return obj && obj->isAfterContent(); }
338 static inline bool isBeforeOrAfterContent(const RenderObject* obj) { return obj && obj->isBeforeOrAfterContent(); }
340 bool childrenInline() const { return m_childrenInline; }
341 void setChildrenInline(bool b = true) { m_childrenInline = b; }
342 bool hasColumns() const { return m_hasColumns; }
343 void setHasColumns(bool b = true) { m_hasColumns = b; }
345 virtual bool requiresForcedStyleRecalcPropagation() const { return false; }
348 virtual bool isRenderMathMLBlock() const { return false; }
349 #endif // ENABLE(MATHML)
352 // FIXME: Until all SVG renders can be subclasses of RenderSVGModelObject we have
353 // to add SVG renderer methods to RenderObject with an ASSERT_NOT_REACHED() default implementation.
354 virtual bool isSVGRoot() const { return false; }
355 virtual bool isSVGContainer() const { return false; }
356 virtual bool isSVGViewportContainer() const { return false; }
357 virtual bool isSVGGradientStop() const { return false; }
358 virtual bool isSVGHiddenContainer() const { return false; }
359 virtual bool isSVGPath() const { return false; }
360 virtual bool isSVGText() const { return false; }
361 virtual bool isSVGTextPath() const { return false; }
362 virtual bool isSVGInline() const { return false; }
363 virtual bool isSVGInlineText() const { return false; }
364 virtual bool isSVGImage() const { return false; }
365 virtual bool isSVGForeignObject() const { return false; }
366 virtual bool isSVGResourceContainer() const { return false; }
367 virtual bool isSVGResourceFilter() const { return false; }
368 virtual bool isSVGResourceFilterPrimitive() const { return false; }
369 virtual bool isSVGShadowTreeRootContainer() const { return false; }
371 virtual RenderSVGResourceContainer* toRenderSVGResourceContainer();
373 // FIXME: Those belong into a SVG specific base-class for all renderers (see above)
374 // Unfortunately we don't have such a class yet, because it's not possible for all renderers
375 // to inherit from RenderSVGObject -> RenderObject (some need RenderBlock inheritance for instance)
376 virtual void setNeedsTransformUpdate() { }
377 virtual void setNeedsBoundariesUpdate();
379 // Per SVG 1.1 objectBoundingBox ignores clipping, masking, filter effects, opacity and stroke-width.
380 // This is used for all computation of objectBoundingBox relative units and by SVGLocateable::getBBox().
381 // NOTE: Markers are not specifically ignored here by SVG 1.1 spec, but we ignore them
382 // since stroke-width is ignored (and marker size can depend on stroke-width).
383 // objectBoundingBox is returned local coordinates.
384 // The name objectBoundingBox is taken from the SVG 1.1 spec.
385 virtual FloatRect objectBoundingBox() const;
386 virtual FloatRect strokeBoundingBox() const;
388 // Returns the smallest rectangle enclosing all of the painted content
389 // respecting clipping, masking, filters, opacity, stroke-width and markers
390 virtual FloatRect repaintRectInLocalCoordinates() const;
392 // This only returns the transform="" value from the element
393 // most callsites want localToParentTransform() instead.
394 virtual AffineTransform localTransform() const;
396 // Returns the full transform mapping from local coordinates to local coords for the parent SVG renderer
397 // This includes any viewport transforms and x/y offsets as well as the transform="" value off the element.
398 virtual const AffineTransform& localToParentTransform() const;
400 // SVG uses FloatPoint precise hit testing, and passes the point in parent
401 // coordinates instead of in repaint container coordinates. Eventually the
402 // rest of the rendering tree will move to a similar model.
403 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
406 bool isAnonymous() const { return m_isAnonymous; }
407 void setIsAnonymous(bool b) { m_isAnonymous = b; }
408 bool isAnonymousBlock() const
410 // This function is kept in sync with anonymous block creation conditions in
411 // RenderBlock::createAnonymousBlock(). This includes creating an anonymous
412 // RenderBlock having a BLOCK or BOX display. Other classes such as RenderTextFragment
413 // are not RenderBlocks and will return false. See https://bugs.webkit.org/show_bug.cgi?id=56709.
414 return m_isAnonymous && (style()->display() == BLOCK || style()->display() == BOX) && style()->styleType() == NOPSEUDO && isRenderBlock() && !isListMarker()
415 #if ENABLE(FULLSCREEN_API)
416 && !isRenderFullScreen()
417 && !isRenderFullScreenPlaceholder()
421 bool isAnonymousColumnsBlock() const { return style()->specifiesColumns() && isAnonymousBlock(); }
422 bool isAnonymousColumnSpanBlock() const { return style()->columnSpan() && isAnonymousBlock(); }
423 bool isElementContinuation() const { return node() && node()->renderer() != this; }
424 bool isInlineElementContinuation() const { return isElementContinuation() && isInline(); }
425 bool isBlockElementContinuation() const { return isElementContinuation() && !isInline(); }
426 virtual RenderBoxModelObject* virtualContinuation() const { return 0; }
428 bool isFloating() const { return m_floating; }
429 bool isPositioned() const { return m_positioned; } // absolute or fixed positioning
430 bool isRelPositioned() const { return m_relPositioned; } // relative positioning
431 bool isText() const { return m_isText; }
432 bool isBox() const { return m_isBox; }
433 bool isInline() const { return m_inline; } // inline object
434 bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object
435 bool isDragging() const { return m_isDragging; }
436 bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS)
437 bool isHorizontalWritingMode() const { return m_horizontalWritingMode; }
439 bool hasLayer() const { return m_hasLayer; }
441 bool hasBoxDecorations() const { return m_paintBackground; }
442 bool borderImageIsLoadedAndCanBeRendered() const;
443 bool mustRepaintBackgroundOrBorder() const;
444 bool hasBackground() const { return style()->hasBackground(); }
445 bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout || m_needsSimplifiedNormalFlowLayout || m_needsPositionedMovementLayout; }
446 bool selfNeedsLayout() const { return m_needsLayout; }
447 bool needsPositionedMovementLayout() const { return m_needsPositionedMovementLayout; }
448 bool needsPositionedMovementLayoutOnly() const { return m_needsPositionedMovementLayout && !m_needsLayout && !m_normalChildNeedsLayout && !m_posChildNeedsLayout && !m_needsSimplifiedNormalFlowLayout; }
449 bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
450 bool needsSimplifiedNormalFlowLayout() const { return m_needsSimplifiedNormalFlowLayout; }
451 bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
453 bool preferredLogicalWidthsDirty() const { return m_preferredLogicalWidthsDirty; }
455 bool isSelectionBorder() const;
457 bool hasClip() const { return isPositioned() && style()->hasClip(); }
458 bool hasOverflowClip() const { return m_hasOverflowClip; }
460 bool hasTransform() const { return m_hasTransform; }
461 bool hasMask() const { return style() && style()->hasMask(); }
463 inline bool preservesNewline() const;
465 #if !HAVE(PATH_BASED_BORDER_RADIUS_DRAWING)
466 // FIXME: This function should be removed when all ports implement GraphicsContext::clipConvexPolygon()!!
467 // At that time, everyone can use RenderObject::drawBoxSideFromPath() instead. This should happen soon.
468 void drawArcForBoxSide(GraphicsContext*, int x, int y, float thickness, const IntSize& radius, int angleStart,
469 int angleSpan, BoxSide, Color, EBorderStyle, bool firstCorner);
472 // The pseudo element style can be cached or uncached. Use the cached method if the pseudo element doesn't respect
473 // any pseudo classes (and therefore has no concept of changing state).
474 RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0) const;
475 PassRefPtr<RenderStyle> getUncachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0, RenderStyle* ownStyle = 0) const;
477 virtual void updateDragState(bool dragOn);
479 RenderView* view() const;
481 // Returns true if this renderer is rooted, and optionally returns the hosting view (the root of the hierarchy).
482 bool isRooted(RenderView** = 0);
484 Node* node() const { return m_isAnonymous ? 0 : m_node; }
486 // Returns the styled node that caused the generation of this renderer.
487 // This is the same as node() except for renderers of :before and :after
488 // pseudo elements for which their parent node is returned.
489 Node* generatingNode() const { return m_node == document() ? 0 : m_node; }
490 void setNode(Node* node) { m_node = node; }
492 Document* document() const { return m_node->document(); }
493 Frame* frame() const { return document()->frame(); }
495 bool hasOutlineAnnotation() const;
496 bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
498 // Returns the object containing this one. Can be different from parent for positioned elements.
499 // If repaintContainer and repaintContainerSkipped are not null, on return *repaintContainerSkipped
500 // is true if the renderer returned is an ancestor of repaintContainer.
501 RenderObject* container(RenderBoxModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
503 virtual RenderObject* hoverAncestor() const { return parent(); }
505 // IE Extension that can be called on any RenderObject. See the implementation for the details.
506 RenderBoxModelObject* offsetParent() const;
508 void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
509 void setNeedsLayout(bool b, bool markParents = true);
510 void setChildNeedsLayout(bool b, bool markParents = true);
511 void setNeedsPositionedMovementLayout();
512 void setNeedsSimplifiedNormalFlowLayout();
513 void setPreferredLogicalWidthsDirty(bool, bool markParents = true);
514 void invalidateContainerPreferredLogicalWidths();
516 void setNeedsLayoutAndPrefWidthsRecalc()
518 setNeedsLayout(true);
519 setPreferredLogicalWidthsDirty(true);
522 void setPositioned(bool b = true) { m_positioned = b; }
523 void setRelPositioned(bool b = true) { m_relPositioned = b; }
524 void setFloating(bool b = true) { m_floating = b; }
525 void setInline(bool b = true) { m_inline = b; }
526 void setHasBoxDecorations(bool b = true) { m_paintBackground = b; }
527 void setIsText() { m_isText = true; }
528 void setIsBox() { m_isBox = true; }
529 void setReplaced(bool b = true) { m_replaced = b; }
530 void setHorizontalWritingMode(bool b = true) { m_horizontalWritingMode = b; }
531 void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
532 void setHasLayer(bool b = true) { m_hasLayer = b; }
533 void setHasTransform(bool b = true) { m_hasTransform = b; }
534 void setHasReflection(bool b = true) { m_hasReflection = b; }
536 void scheduleRelayout();
538 void updateFillImages(const FillLayer*, const FillLayer*);
539 void updateImage(StyleImage*, StyleImage*);
541 virtual void paint(PaintInfo&, const LayoutPoint&);
543 // Recursive function that computes the size and position of this object and all its descendants.
544 virtual void layout();
546 /* This function performs a layout only if one is needed. */
547 void layoutIfNeeded() { if (needsLayout()) layout(); }
549 // used for element state updates that cannot be fixed with a
550 // repaint and do not need a relayout
551 virtual void updateFromElement() { }
553 #if ENABLE(DASHBOARD_SUPPORT)
554 virtual void addDashboardRegions(Vector<DashboardRegionValue>&);
555 void collectDashboardRegions(Vector<DashboardRegionValue>&);
558 bool hitTest(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter = HitTestAll);
559 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
560 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
562 virtual VisiblePosition positionForPoint(const LayoutPoint&);
563 VisiblePosition createVisiblePosition(int offset, EAffinity);
564 VisiblePosition createVisiblePosition(const Position&);
566 virtual void dirtyLinesFromChangedChild(RenderObject*);
568 // Called to update a style that is allowed to trigger animations.
569 // FIXME: Right now this will typically be called only when updating happens from the DOM on explicit elements.
570 // We don't yet handle generated content animation such as first-letter or before/after (we'll worry about this later).
571 void setAnimatableStyle(PassRefPtr<RenderStyle>);
573 // Set the style of the object and update the state of the object accordingly.
574 virtual void setStyle(PassRefPtr<RenderStyle>);
576 // Updates only the local style ptr of the object. Does not update the state of the object,
577 // and so only should be called when the style is known not to have changed (or from setStyle).
578 void setStyleInternal(PassRefPtr<RenderStyle>);
580 // returns the containing block level element for this element.
581 virtual RenderBlock* containingBlock() const;
583 // Convert the given local point to absolute coordinates
584 // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
585 FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
586 FloatPoint absoluteToLocal(const FloatPoint&, bool fixed = false, bool useTransforms = false) const;
588 // Convert a local quad to absolute coordinates, taking transforms into account.
589 FloatQuad localToAbsoluteQuad(const FloatQuad& quad, bool fixed = false, bool* wasFixed = 0) const
591 return localToContainerQuad(quad, 0, fixed, wasFixed);
593 // Convert a local quad into the coordinate system of container, taking transforms into account.
594 FloatQuad localToContainerQuad(const FloatQuad&, RenderBoxModelObject* repaintContainer, bool fixed = false, bool* wasFixed = 0) const;
596 // Return the offset from the container() renderer (excluding transforms). In multi-column layout,
597 // different offsets apply at different points, so return the offset that applies to the given point.
598 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&) const;
599 // Return the offset from an object up the container() chain. Asserts that none of the intermediate objects have transforms.
600 LayoutSize offsetFromAncestorContainer(RenderObject*) const;
602 virtual void absoluteRects(Vector<LayoutRect>&, const LayoutPoint&) { }
603 // FIXME: useTransforms should go away eventually
604 IntRect absoluteBoundingBoxRect(bool useTransforms = false);
606 // Build an array of quads in absolute coords for line boxes
607 virtual void absoluteQuads(Vector<FloatQuad>&, bool* /*wasFixed*/ = 0) { }
609 void absoluteFocusRingQuads(Vector<FloatQuad>&);
611 // the rect that will be painted if this object is passed as the paintingRoot
612 LayoutRect paintingRootRect(LayoutRect& topLevelRect);
614 virtual LayoutUnit minPreferredLogicalWidth() const { return 0; }
615 virtual LayoutUnit maxPreferredLogicalWidth() const { return 0; }
617 RenderStyle* style() const { return m_style.get(); }
618 RenderStyle* firstLineStyle() const { return document()->usesFirstLineRules() ? firstLineStyleSlowCase() : style(); }
619 RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
621 // Used only by Element::pseudoStyleCacheIsInvalid to get a first line style based off of a
622 // given new style, without accessing the cache.
623 PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const;
625 // Anonymous blocks that are part of of a continuation chain will return their inline continuation's outline style instead.
626 // This is typically only relevant when repainting.
627 virtual RenderStyle* outlineStyleForRepaint() const { return style(); }
629 void getTextDecorationColors(int decorations, Color& underline, Color& overline,
630 Color& linethrough, bool quirksMode = false);
632 // Return the RenderBox in the container chain which is responsible for painting this object, or 0
633 // if painting is root-relative. This is the container that should be passed to the 'forRepaint'
635 RenderBoxModelObject* containerForRepaint() const;
636 // Actually do the repaint of rect r for this object which has been computed in the coordinate space
637 // of repaintContainer. If repaintContainer is 0, repaint via the view.
638 void repaintUsingContainer(RenderBoxModelObject* repaintContainer, const LayoutRect&, bool immediate = false);
640 // Repaint the entire object. Called when, e.g., the color of a border changes, or when a border
642 void repaint(bool immediate = false);
644 // Repaint a specific subrectangle within a given object. The rect |r| is in the object's coordinate space.
645 void repaintRectangle(const LayoutRect&, bool immediate = false);
647 // Repaint only if our old bounds and new bounds are different. The caller may pass in newBounds and newOutlineBox if they are known.
648 bool repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr = 0, const LayoutRect* newOutlineBoxPtr = 0);
650 // Repaint only if the object moved.
651 virtual void repaintDuringLayoutIfMoved(const LayoutRect&);
653 // Called to repaint a block's floats.
654 virtual void repaintOverhangingFloats(bool paintAllDescendants = false);
656 bool checkForRepaintDuringLayout() const;
658 // Returns the rect that should be repainted whenever this object changes. The rect is in the view's
659 // coordinate space. This method deals with outlines and overflow.
660 IntRect absoluteClippedOverflowRect() const
662 return clippedOverflowRectForRepaint(0);
664 virtual IntRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const;
665 virtual IntRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth) const;
667 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
668 // that rect in view coordinates.
669 void computeAbsoluteRepaintRect(IntRect& r, bool fixed = false) const
671 return computeRectForRepaint(0, r, fixed);
673 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
674 // that rect in the coordinate space of repaintContainer.
675 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect&, bool fixed = false) const;
677 // If multiple-column layout results in applying an offset to the given point, add the same
678 // offset to the given size.
679 virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const { }
681 virtual unsigned int length() const { return 1; }
683 bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); }
685 bool isTransparent() const { return style()->opacity() < 1.0f; }
686 float opacity() const { return style()->opacity(); }
688 bool hasReflection() const { return m_hasReflection; }
690 // Applied as a "slop" to dirty rect checks during the outline painting phase's dirty-rect checks.
691 int maximalOutlineSize(PaintPhase) const;
693 void setHasMarkupTruncation(bool b = true) { m_hasMarkupTruncation = b; }
694 bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
696 enum SelectionState {
697 SelectionNone, // The object is not selected.
698 SelectionStart, // The object either contains the start of a selection run or is the start of a run
699 SelectionInside, // The object is fully encompassed by a selection run
700 SelectionEnd, // The object either contains the end of a selection run or is the end of a run
701 SelectionBoth // The object contains an entire run or is the sole selected object in that run
704 // The current selection state for an object. For blocks, the state refers to the state of the leaf
705 // descendants (as described above in the SelectionState enum declaration).
706 SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState);; }
708 // Sets the selection state for an object.
709 virtual void setSelectionState(SelectionState state) { m_selectionState = state; }
711 // A single rectangle that encompasses all of the selected objects within this object. Used to determine the tightest
712 // possible bounding box for the selection.
713 LayoutRect selectionRect(bool clipToVisibleContent = true) { return selectionRectForRepaint(0, clipToVisibleContent); }
714 virtual LayoutRect selectionRectForRepaint(RenderBoxModelObject* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return LayoutRect(); }
716 // Whether or not an object can be part of the leaf elements of the selection.
717 virtual bool canBeSelectionLeaf() const { return false; }
719 // Whether or not a block has selected children.
720 bool hasSelectedChildren() const { return m_selectionState != SelectionNone; }
722 // Obtains the selection colors that should be used when painting a selection.
723 Color selectionBackgroundColor() const;
724 Color selectionForegroundColor() const;
725 Color selectionEmphasisMarkColor() const;
727 // Whether or not a given block needs to paint selection gaps.
728 virtual bool shouldPaintSelectionGaps() const { return false; }
731 * Returns the local coordinates of the caret within this render object.
732 * @param caretOffset zero-based offset determining position within the render object.
733 * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
734 * useful for character range rect computations
736 virtual IntRect localCaretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
738 bool isMarginBeforeQuirk() const { return m_marginBeforeQuirk; }
739 bool isMarginAfterQuirk() const { return m_marginAfterQuirk; }
740 void setMarginBeforeQuirk(bool b = true) { m_marginBeforeQuirk = b; }
741 void setMarginAfterQuirk(bool b = true) { m_marginAfterQuirk = b; }
743 // When performing a global document tear-down, the renderer of the document is cleared. We use this
744 // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
745 bool documentBeingDestroyed() const;
747 virtual void destroy();
749 // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).
750 virtual bool isDeprecatedFlexibleBox() const { return false; }
751 virtual bool isFlexingChildren() const { return false; }
752 virtual bool isStretchingChildren() const { return false; }
754 #if ENABLE(CSS3_FLEXBOX)
755 // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flexbox).
756 virtual bool isFlexibleBox() const { return false; }
759 bool isFlexibleBoxIncludingDeprecated() const
761 #if ENABLE(CSS3_FLEXBOX)
762 return isFlexibleBox() || isDeprecatedFlexibleBox();
764 return isDeprecatedFlexibleBox();
768 virtual bool isCombineText() const { return false; }
770 virtual int caretMinOffset() const;
771 virtual int caretMaxOffset() const;
772 virtual unsigned caretMaxRenderedOffset() const;
774 virtual int previousOffset(int current) const;
775 virtual int previousOffsetForBackwardDeletion(int current) const;
776 virtual int nextOffset(int current) const;
778 virtual void imageChanged(CachedImage*, const IntRect* = 0);
779 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
780 virtual bool willRenderImage(CachedImage*);
782 void selectionStartEnd(int& spos, int& epos) const;
784 void remove() { if (parent()) parent()->removeChild(this); }
786 AnimationController* animation() const;
788 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE; }
790 // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
791 // localToAbsolute/absoluteToLocal methods instead.
792 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
793 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
795 bool shouldUseTransformFromContainer(const RenderObject* container) const;
796 void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const;
798 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&) { };
800 IntRect absoluteOutlineBounds() const
802 return outlineBoundsForRepaint(0);
806 // Overrides should call the superclass at the end
807 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
808 // Overrides should call the superclass at the start
809 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
810 void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
812 void drawLineForBoxSide(GraphicsContext*, int x1, int y1, int x2, int y2, BoxSide,
813 Color, EBorderStyle, int adjbw1, int adjbw2, bool antialias = false);
815 void paintFocusRing(GraphicsContext*, const LayoutPoint&, RenderStyle*);
816 void paintOutline(GraphicsContext*, const LayoutRect&);
817 void addPDFURLRect(GraphicsContext*, const IntRect&);
819 virtual IntRect viewRect() const;
821 void adjustRectForOutlineAndShadow(IntRect&) const;
823 virtual void willBeDestroyed();
824 void arenaDelete(RenderArena*, void* objectBase);
826 virtual IntRect outlineBoundsForRepaint(RenderBoxModelObject* /*repaintContainer*/, IntPoint* /*cachedOffsetToRepaintContainer*/ = 0) const { return IntRect(); }
829 RenderStyle* firstLineStyleSlowCase() const;
830 StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
832 Color selectionColor(int colorProperty) const;
834 RefPtr<RenderStyle> m_style;
838 RenderObject* m_parent;
839 RenderObject* m_previous;
840 RenderObject* m_next;
844 bool m_setNeedsLayoutForbidden : 1;
847 // 32 bits have been used here. THERE ARE NO FREE BITS AVAILABLE.
848 bool m_needsLayout : 1;
849 bool m_needsPositionedMovementLayout :1;
850 bool m_normalChildNeedsLayout : 1;
851 bool m_posChildNeedsLayout : 1;
852 bool m_needsSimplifiedNormalFlowLayout : 1;
853 bool m_preferredLogicalWidthsDirty : 1;
856 bool m_positioned : 1;
857 bool m_relPositioned : 1;
858 bool m_paintBackground : 1; // if the box has something to paint in the
859 // background painting phase (background, border, etc)
861 bool m_isAnonymous : 1;
866 bool m_horizontalWritingMode : 1;
867 bool m_isDragging : 1;
870 bool m_hasOverflowClip : 1; // Set in the case of overflow:auto/scroll/hidden
871 bool m_hasTransform : 1;
872 bool m_hasReflection : 1;
875 bool m_hasCounterNodeMap : 1;
876 bool m_everHadLayout : 1;
879 // These bitfields are moved here from subclasses to pack them together
881 bool m_childrenInline : 1;
882 bool m_marginBeforeQuirk : 1;
883 bool m_marginAfterQuirk : 1;
884 bool m_hasMarkupTruncation : 1;
885 unsigned m_selectionState : 3; // SelectionState
886 bool m_hasColumns : 1;
889 // Store state between styleWillChange and styleDidChange
890 static bool s_affectsParentBlock;
893 inline bool RenderObject::documentBeingDestroyed() const
895 return !document()->renderer();
898 inline bool RenderObject::isBeforeContent() const
900 if (style()->styleType() != BEFORE)
902 // Text nodes don't have their own styles, so ignore the style on a text node.
903 if (isText() && !isBR())
908 inline bool RenderObject::isAfterContent() const
910 if (style()->styleType() != AFTER)
912 // Text nodes don't have their own styles, so ignore the style on a text node.
913 if (isText() && !isBR())
918 inline bool RenderObject::isBeforeOrAfterContent() const
920 return isBeforeContent() || isAfterContent();
923 inline void RenderObject::setNeedsLayout(bool b, bool markParents)
925 bool alreadyNeededLayout = m_needsLayout;
928 ASSERT(!isSetNeedsLayoutForbidden());
929 if (!alreadyNeededLayout) {
931 markContainingBlocksForLayout();
933 setLayerNeedsFullRepaint();
936 m_everHadLayout = true;
937 m_posChildNeedsLayout = false;
938 m_needsSimplifiedNormalFlowLayout = false;
939 m_normalChildNeedsLayout = false;
940 m_needsPositionedMovementLayout = false;
944 inline void RenderObject::setChildNeedsLayout(bool b, bool markParents)
946 bool alreadyNeededLayout = m_normalChildNeedsLayout;
947 m_normalChildNeedsLayout = b;
949 ASSERT(!isSetNeedsLayoutForbidden());
950 if (!alreadyNeededLayout && markParents)
951 markContainingBlocksForLayout();
953 m_posChildNeedsLayout = false;
954 m_needsSimplifiedNormalFlowLayout = false;
955 m_normalChildNeedsLayout = false;
956 m_needsPositionedMovementLayout = false;
960 inline void RenderObject::setNeedsPositionedMovementLayout()
962 bool alreadyNeededLayout = m_needsPositionedMovementLayout;
963 m_needsPositionedMovementLayout = true;
964 ASSERT(!isSetNeedsLayoutForbidden());
965 if (!alreadyNeededLayout) {
966 markContainingBlocksForLayout();
968 setLayerNeedsFullRepaint();
972 inline void RenderObject::setNeedsSimplifiedNormalFlowLayout()
974 bool alreadyNeededLayout = m_needsSimplifiedNormalFlowLayout;
975 m_needsSimplifiedNormalFlowLayout = true;
976 ASSERT(!isSetNeedsLayoutForbidden());
977 if (!alreadyNeededLayout) {
978 markContainingBlocksForLayout();
980 setLayerNeedsFullRepaint();
984 inline bool objectIsRelayoutBoundary(const RenderObject *obj)
986 // FIXME: In future it may be possible to broaden this condition in order to improve performance.
987 // Table cells are excluded because even when their CSS height is fixed, their height()
988 // may depend on their contents.
989 return obj->isTextControl()
990 || (obj->hasOverflowClip() && !obj->style()->width().isIntrinsicOrAuto() && !obj->style()->height().isIntrinsicOrAuto() && !obj->style()->height().isPercent() && !obj->isTableCell())
997 inline void RenderObject::markContainingBlocksForLayout(bool scheduleRelayout, RenderObject* newRoot)
999 ASSERT(!scheduleRelayout || !newRoot);
1001 RenderObject* o = container();
1002 RenderObject* last = this;
1004 bool simplifiedNormalFlowLayout = needsSimplifiedNormalFlowLayout() && !selfNeedsLayout() && !normalChildNeedsLayout();
1007 // Don't mark the outermost object of an unrooted subtree. That object will be
1008 // marked when the subtree is added to the document.
1009 RenderObject* container = o->container();
1010 if (!container && !o->isRenderView())
1012 if (!last->isText() && (last->style()->position() == FixedPosition || last->style()->position() == AbsolutePosition)) {
1013 bool willSkipRelativelyPositionedInlines = !o->isRenderBlock();
1014 while (o && !o->isRenderBlock()) // Skip relatively positioned inlines and get to the enclosing RenderBlock.
1016 if (!o || o->m_posChildNeedsLayout)
1018 if (willSkipRelativelyPositionedInlines)
1019 container = o->container();
1020 o->m_posChildNeedsLayout = true;
1021 simplifiedNormalFlowLayout = true;
1022 ASSERT(!o->isSetNeedsLayoutForbidden());
1023 } else if (simplifiedNormalFlowLayout) {
1024 if (o->m_needsSimplifiedNormalFlowLayout)
1026 o->m_needsSimplifiedNormalFlowLayout = true;
1027 ASSERT(!o->isSetNeedsLayoutForbidden());
1029 if (o->m_normalChildNeedsLayout)
1031 o->m_normalChildNeedsLayout = true;
1032 ASSERT(!o->isSetNeedsLayoutForbidden());
1039 if (scheduleRelayout && objectIsRelayoutBoundary(last))
1044 if (scheduleRelayout)
1045 last->scheduleRelayout();
1048 inline bool RenderObject::preservesNewline() const
1051 if (isSVGInlineText())
1055 return style()->preserveNewline();
1058 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
1060 #if !ENABLE(3D_RENDERING)
1061 UNUSED_PARAM(has3DRendering);
1062 matrix.makeAffine();
1064 if (!has3DRendering)
1065 matrix.makeAffine();
1069 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
1071 return adjustForAbsoluteZoom(value, renderer->style());
1074 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject* renderer)
1076 float zoom = renderer->style()->effectiveZoom();
1078 quad.scale(1 / zoom, 1 / zoom);
1081 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject* renderer)
1083 float zoom = renderer->style()->effectiveZoom();
1085 rect.scale(1 / zoom, 1 / zoom);
1088 inline void adjustFloatQuadForPageScale(FloatQuad& quad, float pageScale)
1091 quad.scale(1 / pageScale, 1 / pageScale);
1094 inline void adjustFloatRectForPageScale(FloatRect& rect, float pageScale)
1097 rect.scale(1 / pageScale, 1 / pageScale);
1100 } // namespace WebCore
1103 // Outside the WebCore namespace for ease of invocation from gdb.
1104 void showTree(const WebCore::RenderObject*);
1105 void showLineTree(const WebCore::RenderObject*);
1106 void showRenderTree(const WebCore::RenderObject* object1);
1107 // We don't make object2 an optional parameter so that showRenderTree
1108 // can be called from gdb easily.
1109 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2);
1112 #endif // RenderObject_h