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 "CachedImage.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;
53 class OverlapTestRequestClient;
56 class RenderBoxModelObject;
59 class RenderFlowThread;
63 class VisiblePosition;
65 class RenderSVGResourceContainer;
70 enum CursorDirective {
71 SetCursorBasedOnStyle,
83 HitTestBlockBackground,
84 HitTestChildBlockBackground,
85 HitTestChildBlockBackgrounds,
90 // Sides used when drawing borders and outlines. The values should run clockwise from top.
98 const int caretWidth = 1;
100 #if ENABLE(DASHBOARD_SUPPORT)
101 struct DashboardRegionValue {
102 bool operator==(const DashboardRegionValue& o) const
104 return type == o.type && bounds == o.bounds && clip == o.clip && label == o.label;
106 bool operator!=(const DashboardRegionValue& o) const
108 return !(*this == o);
119 const int showTreeCharacterOffset = 39;
122 // Base class for all rendering tree objects.
123 class RenderObject : public CachedImageClient {
124 friend class LayoutRepainter;
125 friend class RenderBlock;
126 friend class RenderBox;
127 friend class RenderLayer;
128 friend class RenderObjectChildList;
129 friend class RenderSVGContainer;
131 // Anonymous objects should pass the document as their node, and they will then automatically be
132 // marked as anonymous in the constructor.
134 virtual ~RenderObject();
136 RenderTheme* theme() const;
138 virtual const char* renderName() const = 0;
140 RenderObject* parent() const { return m_parent; }
141 bool isDescendantOf(const RenderObject*) const;
143 RenderObject* previousSibling() const { return m_previous; }
144 RenderObject* nextSibling() const { return m_next; }
146 RenderObject* firstChild() const
148 if (const RenderObjectChildList* children = virtualChildren())
149 return children->firstChild();
152 RenderObject* lastChild() const
154 if (const RenderObjectChildList* children = virtualChildren())
155 return children->lastChild();
158 RenderObject* beforePseudoElementRenderer() const
160 if (const RenderObjectChildList* children = virtualChildren())
161 return children->beforePseudoElementRenderer(this);
165 // This function only returns the renderer of the "after" pseudoElement if it is a child of
166 // this renderer. If "continuations" exist, the function returns 0 even if the element that
167 // generated this renderer has an "after" pseudo-element.
168 RenderObject* afterPseudoElementRenderer() const
170 if (const RenderObjectChildList* children = virtualChildren())
171 return children->afterPseudoElementRenderer(this);
175 virtual RenderObjectChildList* virtualChildren() { return 0; }
176 virtual const RenderObjectChildList* virtualChildren() const { return 0; }
178 RenderObject* nextInPreOrder() const;
179 RenderObject* nextInPreOrder(const RenderObject* stayWithin) const;
180 RenderObject* nextInPreOrderAfterChildren() const;
181 RenderObject* nextInPreOrderAfterChildren(const RenderObject* stayWithin) const;
182 RenderObject* previousInPreOrder() const;
183 RenderObject* childAt(unsigned) const;
185 RenderObject* firstLeafChild() const;
186 RenderObject* lastLeafChild() const;
188 // The following six functions are used when the render tree hierarchy changes to make sure layers get
189 // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
190 // can contain a mixture of boxes and other object types, these functions need to be in the base class.
191 RenderLayer* enclosingLayer() const;
192 void addLayers(RenderLayer* parentLayer);
193 void removeLayers(RenderLayer* parentLayer);
194 void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
195 RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
197 // Convenience function for getting to the nearest enclosing box of a RenderObject.
198 RenderBox* enclosingBox() const;
199 RenderBoxModelObject* enclosingBoxModelObject() const;
201 // Function to return our enclosing flow thread if we are contained inside one.
202 RenderFlowThread* enclosingRenderFlowThread() const;
204 virtual bool isEmpty() const { return firstChild() == 0; }
207 void setHasAXObject(bool flag) { m_hasAXObject = flag; }
208 bool hasAXObject() const { return m_hasAXObject; }
209 bool isSetNeedsLayoutForbidden() const { return m_setNeedsLayoutForbidden; }
210 void setNeedsLayoutIsForbidden(bool flag) { m_setNeedsLayoutForbidden = flag; }
213 // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
215 virtual RenderBlock* firstLineBlock() const;
217 // Called when an object that was floating or positioned becomes a normal flow object
218 // again. We have to make sure the render tree updates as needed to accommodate the new
219 // normal flow object.
220 void handleDynamicFloatPositionChange();
222 // RenderObject tree manipulation
223 //////////////////////////////////////////
224 virtual bool canHaveChildren() const { return virtualChildren(); }
225 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
226 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
227 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0) { return addChild(newChild, beforeChild); }
228 virtual void removeChild(RenderObject*);
229 virtual bool createsAnonymousWrapper() const { return false; }
230 //////////////////////////////////////////
233 //////////////////////////////////////////
234 // Helper functions. Dangerous to use!
235 void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
236 void setNextSibling(RenderObject* next) { m_next = next; }
237 void setParent(RenderObject* parent)
240 if (parent && parent->inRenderFlowThread())
241 setInRenderFlowThread(true);
242 else if (!parent && inRenderFlowThread())
243 setInRenderFlowThread(false);
245 //////////////////////////////////////////
247 void addAbsoluteRectForLayer(LayoutRect& result);
248 void setLayerNeedsFullRepaint();
252 void showTreeForThis() const;
253 void showRenderTreeForThis() const;
254 void showLineTreeForThis() const;
256 void showRenderObject() const;
257 // We don't make printedCharacters an optional parameter so that
258 // showRenderObject can be called from gdb easily.
259 void showRenderObject(int printedCharacters) const;
260 void showRenderTreeAndMark(const RenderObject* markedObject1 = 0, const char* markedLabel1 = 0, const RenderObject* markedObject2 = 0, const char* markedLabel2 = 0, int depth = 0) const;
263 static RenderObject* createObject(Node*, RenderStyle*);
265 // Overloaded new operator. Derived classes must override operator new
266 // in order to allocate out of the RenderArena.
267 void* operator new(size_t, RenderArena*) throw();
269 // Overridden to prevent the normal delete from being called.
270 void operator delete(void*, size_t);
273 // The normal operator new is disallowed on all render objects.
274 void* operator new(size_t) throw();
277 RenderArena* renderArena() const { return document()->renderArena(); }
279 virtual bool isApplet() const { return false; }
280 virtual bool isBR() const { return false; }
281 virtual bool isBlockFlow() const { return false; }
282 virtual bool isBoxModelObject() const { return false; }
283 virtual bool isCounter() const { return false; }
284 virtual bool isQuote() const { return false; }
286 virtual bool isDetails() const { return false; }
287 virtual bool isDetailsMarker() const { return false; }
289 virtual bool isEmbeddedObject() const { return false; }
290 virtual bool isFieldset() const { return false; }
291 virtual bool isFileUploadControl() const { return false; }
292 virtual bool isFrame() const { return false; }
293 virtual bool isFrameSet() const { return false; }
294 virtual bool isImage() const { return false; }
295 virtual bool isInlineBlockOrInlineTable() const { return false; }
296 virtual bool isListBox() const { return false; }
297 virtual bool isListItem() const { return false; }
298 virtual bool isListMarker() const { return false; }
299 virtual bool isMedia() const { return false; }
300 virtual bool isMenuList() const { return false; }
301 #if ENABLE(METER_TAG)
302 virtual bool isMeter() const { return false; }
304 #if ENABLE(PROGRESS_TAG)
305 virtual bool isProgress() const { return false; }
307 virtual bool isRenderBlock() const { return false; }
308 virtual bool isRenderButton() const { return false; }
309 virtual bool isRenderIFrame() const { return false; }
310 virtual bool isRenderImage() const { return false; }
311 virtual bool isRenderInline() const { return false; }
312 virtual bool isRenderPart() const { return false; }
313 virtual bool isRenderRegion() const { return false; }
314 virtual bool isRenderView() const { return false; }
315 virtual bool isReplica() const { return false; }
317 virtual bool isRuby() const { return false; }
318 virtual bool isRubyBase() const { return false; }
319 virtual bool isRubyRun() const { return false; }
320 virtual bool isRubyText() const { return false; }
322 virtual bool isSlider() const { return false; }
323 virtual bool isSliderThumb() const { return false; }
325 virtual bool isSummary() const { return false; }
327 virtual bool isTable() const { return false; }
328 virtual bool isTableCell() const { return false; }
329 virtual bool isTableCol() const { return false; }
330 virtual bool isTableRow() const { return false; }
331 virtual bool isTableSection() const { return false; }
332 virtual bool isTextControl() const { return false; }
333 virtual bool isTextArea() const { return false; }
334 virtual bool isTextField() const { return false; }
335 virtual bool isVideo() const { return false; }
336 virtual bool isWidget() const { return false; }
337 virtual bool isCanvas() const { return false; }
338 #if ENABLE(FULLSCREEN_API)
339 virtual bool isRenderFullScreen() const { return false; }
340 virtual bool isRenderFullScreenPlaceholder() const { return false; }
343 virtual bool isRenderFlowThread() const { return false; }
345 bool isRoot() const { return document()->documentElement() == m_node; }
348 bool isLegend() const;
350 bool isHTMLMarquee() const;
352 inline bool isBeforeContent() const;
353 inline bool isAfterContent() const;
354 inline bool isBeforeOrAfterContent() const;
355 static inline bool isBeforeContent(const RenderObject* obj) { return obj && obj->isBeforeContent(); }
356 static inline bool isAfterContent(const RenderObject* obj) { return obj && obj->isAfterContent(); }
357 static inline bool isBeforeOrAfterContent(const RenderObject* obj) { return obj && obj->isBeforeOrAfterContent(); }
359 inline RenderObject* anonymousContainer(RenderObject* child)
361 RenderObject* container = child;
362 while (container->parent() != this)
363 container = container->parent();
365 ASSERT(container->isAnonymous());
369 bool childrenInline() const { return m_childrenInline; }
370 void setChildrenInline(bool b) { m_childrenInline = b; }
371 bool hasColumns() const { return m_hasColumns; }
372 void setHasColumns(bool b = true) { m_hasColumns = b; }
374 bool inRenderFlowThread() const { return m_inRenderFlowThread; }
375 void setInRenderFlowThread(bool b = true) { m_inRenderFlowThread = b; }
377 virtual bool requiresForcedStyleRecalcPropagation() const { return false; }
380 virtual bool isRenderMathMLBlock() const { return false; }
381 #endif // ENABLE(MATHML)
384 // FIXME: Until all SVG renders can be subclasses of RenderSVGModelObject we have
385 // to add SVG renderer methods to RenderObject with an ASSERT_NOT_REACHED() default implementation.
386 virtual bool isSVGRoot() const { return false; }
387 virtual bool isSVGContainer() const { return false; }
388 virtual bool isSVGViewportContainer() const { return false; }
389 virtual bool isSVGGradientStop() const { return false; }
390 virtual bool isSVGHiddenContainer() const { return false; }
391 virtual bool isSVGPath() const { return false; }
392 virtual bool isSVGRect() const { return false; }
393 virtual bool isSVGShape() const { return false; }
394 virtual bool isSVGText() const { return false; }
395 virtual bool isSVGTextPath() const { return false; }
396 virtual bool isSVGInline() const { return false; }
397 virtual bool isSVGInlineText() const { return false; }
398 virtual bool isSVGImage() const { return false; }
399 virtual bool isSVGForeignObject() const { return false; }
400 virtual bool isSVGResourceContainer() const { return false; }
401 virtual bool isSVGResourceFilter() const { return false; }
402 virtual bool isSVGResourceFilterPrimitive() const { return false; }
403 virtual bool isSVGShadowTreeRootContainer() const { return false; }
405 virtual RenderSVGResourceContainer* toRenderSVGResourceContainer();
407 // FIXME: Those belong into a SVG specific base-class for all renderers (see above)
408 // Unfortunately we don't have such a class yet, because it's not possible for all renderers
409 // to inherit from RenderSVGObject -> RenderObject (some need RenderBlock inheritance for instance)
410 virtual void setNeedsTransformUpdate() { }
411 virtual void setNeedsBoundariesUpdate();
413 // Per SVG 1.1 objectBoundingBox ignores clipping, masking, filter effects, opacity and stroke-width.
414 // This is used for all computation of objectBoundingBox relative units and by SVGLocatable::getBBox().
415 // NOTE: Markers are not specifically ignored here by SVG 1.1 spec, but we ignore them
416 // since stroke-width is ignored (and marker size can depend on stroke-width).
417 // objectBoundingBox is returned local coordinates.
418 // The name objectBoundingBox is taken from the SVG 1.1 spec.
419 virtual FloatRect objectBoundingBox() const;
420 virtual FloatRect strokeBoundingBox() const;
422 // Returns the smallest rectangle enclosing all of the painted content
423 // respecting clipping, masking, filters, opacity, stroke-width and markers
424 virtual FloatRect repaintRectInLocalCoordinates() const;
426 // This only returns the transform="" value from the element
427 // most callsites want localToParentTransform() instead.
428 virtual AffineTransform localTransform() const;
430 // Returns the full transform mapping from local coordinates to local coords for the parent SVG renderer
431 // This includes any viewport transforms and x/y offsets as well as the transform="" value off the element.
432 virtual const AffineTransform& localToParentTransform() const;
434 // SVG uses FloatPoint precise hit testing, and passes the point in parent
435 // coordinates instead of in repaint container coordinates. Eventually the
436 // rest of the rendering tree will move to a similar model.
437 virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction);
440 bool isAnonymous() const { return m_isAnonymous; }
441 void setIsAnonymous(bool b) { m_isAnonymous = b; }
442 bool isAnonymousBlock() const
444 // This function is kept in sync with anonymous block creation conditions in
445 // RenderBlock::createAnonymousBlock(). This includes creating an anonymous
446 // RenderBlock having a BLOCK or BOX display. Other classes such as RenderTextFragment
447 // are not RenderBlocks and will return false. See https://bugs.webkit.org/show_bug.cgi?id=56709.
448 return m_isAnonymous && (style()->display() == BLOCK || style()->display() == BOX) && style()->styleType() == NOPSEUDO && isRenderBlock() && !isListMarker()
449 #if ENABLE(FULLSCREEN_API)
450 && !isRenderFullScreen()
451 && !isRenderFullScreenPlaceholder()
455 bool isAnonymousColumnsBlock() const { return style()->specifiesColumns() && isAnonymousBlock(); }
456 bool isAnonymousColumnSpanBlock() const { return style()->columnSpan() && isAnonymousBlock(); }
457 bool isElementContinuation() const { return node() && node()->renderer() != this; }
458 bool isInlineElementContinuation() const { return isElementContinuation() && isInline(); }
459 bool isBlockElementContinuation() const { return isElementContinuation() && !isInline(); }
460 virtual RenderBoxModelObject* virtualContinuation() const { return 0; }
462 bool isFloating() const { return m_floating; }
463 bool isPositioned() const { return m_positioned; } // absolute or fixed positioning
464 bool isRelPositioned() const { return m_relPositioned; } // relative positioning
465 bool isText() const { return m_isText; }
466 bool isBox() const { return m_isBox; }
467 bool isInline() const { return m_inline; } // inline object
468 bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object
469 bool isDragging() const { return m_isDragging; }
470 bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS)
471 bool isHorizontalWritingMode() const { return m_horizontalWritingMode; }
473 bool hasLayer() const { return m_hasLayer; }
475 bool hasBoxDecorations() const { return m_paintBackground; }
476 bool borderImageIsLoadedAndCanBeRendered() const;
477 bool mustRepaintBackgroundOrBorder() const;
478 bool hasBackground() const { return style()->hasBackground(); }
479 bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout || m_needsSimplifiedNormalFlowLayout || m_needsPositionedMovementLayout; }
480 bool selfNeedsLayout() const { return m_needsLayout; }
481 bool needsPositionedMovementLayout() const { return m_needsPositionedMovementLayout; }
482 bool needsPositionedMovementLayoutOnly() const { return m_needsPositionedMovementLayout && !m_needsLayout && !m_normalChildNeedsLayout && !m_posChildNeedsLayout && !m_needsSimplifiedNormalFlowLayout; }
483 bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
484 bool needsSimplifiedNormalFlowLayout() const { return m_needsSimplifiedNormalFlowLayout; }
485 bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
487 bool preferredLogicalWidthsDirty() const { return m_preferredLogicalWidthsDirty; }
489 bool isSelectionBorder() const;
491 bool hasClip() const { return isPositioned() && style()->hasClip(); }
492 bool hasOverflowClip() const { return m_hasOverflowClip; }
494 bool hasTransform() const { return m_hasTransform; }
495 bool hasMask() const { return style() && style()->hasMask(); }
497 #if ENABLE(CSS_FILTERS)
498 bool hasFilter() const { return style() && style()->hasFilter(); }
500 bool hasFilter() const { return false; }
503 inline bool preservesNewline() const;
505 #if !HAVE(PATH_BASED_BORDER_RADIUS_DRAWING)
506 // FIXME: This function should be removed when all ports implement GraphicsContext::clipConvexPolygon()!!
507 // At that time, everyone can use RenderObject::drawBoxSideFromPath() instead. This should happen soon.
508 void drawArcForBoxSide(GraphicsContext*, int x, int y, float thickness, const IntSize& radius, int angleStart,
509 int angleSpan, BoxSide, Color, EBorderStyle, bool firstCorner);
512 // The pseudo element style can be cached or uncached. Use the cached method if the pseudo element doesn't respect
513 // any pseudo classes (and therefore has no concept of changing state).
514 RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0) const;
515 PassRefPtr<RenderStyle> getUncachedPseudoStyle(PseudoId, RenderStyle* parentStyle = 0, RenderStyle* ownStyle = 0) const;
517 virtual void updateDragState(bool dragOn);
519 RenderView* view() const;
521 // Returns true if this renderer is rooted, and optionally returns the hosting view (the root of the hierarchy).
522 bool isRooted(RenderView** = 0);
524 Node* node() const { return m_isAnonymous ? 0 : m_node; }
526 // Returns the styled node that caused the generation of this renderer.
527 // This is the same as node() except for renderers of :before and :after
528 // pseudo elements for which their parent node is returned.
529 Node* generatingNode() const { return m_node == document() ? 0 : m_node; }
530 void setNode(Node* node) { m_node = node; }
532 Document* document() const { return m_node->document(); }
533 Frame* frame() const { return document()->frame(); }
535 bool hasOutlineAnnotation() const;
536 bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
538 // Returns the object containing this one. Can be different from parent for positioned elements.
539 // If repaintContainer and repaintContainerSkipped are not null, on return *repaintContainerSkipped
540 // is true if the renderer returned is an ancestor of repaintContainer.
541 RenderObject* container(RenderBoxModelObject* repaintContainer = 0, bool* repaintContainerSkipped = 0) const;
543 virtual RenderObject* hoverAncestor() const { return parent(); }
545 // IE Extension that can be called on any RenderObject. See the implementation for the details.
546 RenderBoxModelObject* offsetParent() const;
548 void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
549 void setNeedsLayout(bool b, bool markParents = true);
550 void setChildNeedsLayout(bool b, bool markParents = true);
551 void setNeedsPositionedMovementLayout();
552 void setNeedsSimplifiedNormalFlowLayout();
553 void setPreferredLogicalWidthsDirty(bool, bool markParents = true);
554 void invalidateContainerPreferredLogicalWidths();
556 void setNeedsLayoutAndPrefWidthsRecalc()
558 setNeedsLayout(true);
559 setPreferredLogicalWidthsDirty(true);
562 void setPositioned(bool b = true) { m_positioned = b; }
563 void setRelPositioned(bool b = true) { m_relPositioned = b; }
564 void setFloating(bool b = true) { m_floating = b; }
565 void setInline(bool b = true) { m_inline = b; }
566 void setHasBoxDecorations(bool b = true) { m_paintBackground = b; }
567 void setIsText() { m_isText = true; }
568 void setIsBox() { m_isBox = true; }
569 void setReplaced(bool b = true) { m_replaced = b; }
570 void setHorizontalWritingMode(bool b = true) { m_horizontalWritingMode = b; }
571 void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
572 void setHasLayer(bool b = true) { m_hasLayer = b; }
573 void setHasTransform(bool b = true) { m_hasTransform = b; }
574 void setHasReflection(bool b = true) { m_hasReflection = b; }
576 void scheduleRelayout();
578 void updateFillImages(const FillLayer*, const FillLayer*);
579 void updateImage(StyleImage*, StyleImage*);
581 virtual void paint(PaintInfo&, const LayoutPoint&);
583 // Recursive function that computes the size and position of this object and all its descendants.
584 virtual void layout();
586 /* This function performs a layout only if one is needed. */
587 void layoutIfNeeded() { if (needsLayout()) layout(); }
589 // used for element state updates that cannot be fixed with a
590 // repaint and do not need a relayout
591 virtual void updateFromElement() { }
593 #if ENABLE(DASHBOARD_SUPPORT)
594 virtual void addDashboardRegions(Vector<DashboardRegionValue>&);
595 void collectDashboardRegions(Vector<DashboardRegionValue>&);
598 bool hitTest(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestFilter = HitTestAll);
599 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
600 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
602 virtual VisiblePosition positionForPoint(const LayoutPoint&);
603 VisiblePosition createVisiblePosition(int offset, EAffinity);
604 VisiblePosition createVisiblePosition(const Position&);
606 virtual void dirtyLinesFromChangedChild(RenderObject*);
608 // Called to update a style that is allowed to trigger animations.
609 // FIXME: Right now this will typically be called only when updating happens from the DOM on explicit elements.
610 // We don't yet handle generated content animation such as first-letter or before/after (we'll worry about this later).
611 void setAnimatableStyle(PassRefPtr<RenderStyle>);
613 // Set the style of the object and update the state of the object accordingly.
614 virtual void setStyle(PassRefPtr<RenderStyle>);
616 // Updates only the local style ptr of the object. Does not update the state of the object,
617 // and so only should be called when the style is known not to have changed (or from setStyle).
618 void setStyleInternal(PassRefPtr<RenderStyle>);
620 // returns the containing block level element for this element.
621 RenderBlock* containingBlock() const;
623 // Convert the given local point to absolute coordinates
624 // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware.
625 FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const;
626 FloatPoint absoluteToLocal(const FloatPoint&, bool fixed = false, bool useTransforms = false) const;
628 // Convert a local quad to absolute coordinates, taking transforms into account.
629 FloatQuad localToAbsoluteQuad(const FloatQuad& quad, bool fixed = false, bool* wasFixed = 0) const
631 return localToContainerQuad(quad, 0, fixed, wasFixed);
633 // Convert a local quad into the coordinate system of container, taking transforms into account.
634 FloatQuad localToContainerQuad(const FloatQuad&, RenderBoxModelObject* repaintContainer, bool fixed = false, bool* wasFixed = 0) const;
636 // Return the offset from the container() renderer (excluding transforms). In multi-column layout,
637 // different offsets apply at different points, so return the offset that applies to the given point.
638 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&) const;
639 // Return the offset from an object up the container() chain. Asserts that none of the intermediate objects have transforms.
640 LayoutSize offsetFromAncestorContainer(RenderObject*) const;
642 virtual void absoluteRects(Vector<LayoutRect>&, const LayoutPoint&) const { }
644 // FIXME: useTransforms should go away eventually
645 LayoutRect absoluteBoundingBoxRect(bool useTransform = true) const;
646 LayoutRect absoluteBoundingBoxRectIgnoringTransforms() const { return absoluteBoundingBoxRect(false); }
648 // Build an array of quads in absolute coords for line boxes
649 virtual void absoluteQuads(Vector<FloatQuad>&, bool* /*wasFixed*/ = 0) const { }
651 void absoluteFocusRingQuads(Vector<FloatQuad>&);
653 // the rect that will be painted if this object is passed as the paintingRoot
654 LayoutRect paintingRootRect(LayoutRect& topLevelRect);
656 virtual LayoutUnit minPreferredLogicalWidth() const { return 0; }
657 virtual LayoutUnit maxPreferredLogicalWidth() const { return 0; }
659 RenderStyle* style() const { return m_style.get(); }
660 RenderStyle* firstLineStyle() const { return document()->usesFirstLineRules() ? firstLineStyleSlowCase() : style(); }
661 RenderStyle* style(bool firstLine) const { return firstLine ? firstLineStyle() : style(); }
663 // Used only by Element::pseudoStyleCacheIsInvalid to get a first line style based off of a
664 // given new style, without accessing the cache.
665 PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const;
667 // Anonymous blocks that are part of of a continuation chain will return their inline continuation's outline style instead.
668 // This is typically only relevant when repainting.
669 virtual RenderStyle* outlineStyleForRepaint() const { return style(); }
671 virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
673 void getTextDecorationColors(int decorations, Color& underline, Color& overline, Color& linethrough, bool quirksMode = false);
675 // Return the RenderBox in the container chain which is responsible for painting this object, or 0
676 // if painting is root-relative. This is the container that should be passed to the 'forRepaint'
678 RenderBoxModelObject* containerForRepaint() const;
679 // Actually do the repaint of rect r for this object which has been computed in the coordinate space
680 // of repaintContainer. If repaintContainer is 0, repaint via the view.
681 void repaintUsingContainer(RenderBoxModelObject* repaintContainer, const LayoutRect&, bool immediate = false);
683 // Repaint the entire object. Called when, e.g., the color of a border changes, or when a border
685 void repaint(bool immediate = false);
687 // Repaint a specific subrectangle within a given object. The rect |r| is in the object's coordinate space.
688 void repaintRectangle(const LayoutRect&, bool immediate = false);
690 // Repaint only if our old bounds and new bounds are different. The caller may pass in newBounds and newOutlineBox if they are known.
691 bool repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr = 0, const LayoutRect* newOutlineBoxPtr = 0);
693 // Repaint only if the object moved.
694 virtual void repaintDuringLayoutIfMoved(const LayoutRect&);
696 // Called to repaint a block's floats.
697 virtual void repaintOverhangingFloats(bool paintAllDescendants = false);
699 bool checkForRepaintDuringLayout() const;
701 // Returns the rect that should be repainted whenever this object changes. The rect is in the view's
702 // coordinate space. This method deals with outlines and overflow.
703 LayoutRect absoluteClippedOverflowRect() const
705 return clippedOverflowRectForRepaint(0);
707 virtual LayoutRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const;
708 virtual LayoutRect rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, LayoutUnit outlineWidth) const;
710 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
711 // that rect in view coordinates.
712 void computeAbsoluteRepaintRect(LayoutRect& r, bool fixed = false) const
714 return computeRectForRepaint(0, r, fixed);
716 // Given a rect in the object's coordinate space, compute a rect suitable for repainting
717 // that rect in the coordinate space of repaintContainer.
718 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
719 virtual void computeFloatRectForRepaint(RenderBoxModelObject* repaintContainer, FloatRect& repaintRect, bool fixed = false) const;
721 // If multiple-column layout results in applying an offset to the given point, add the same
722 // offset to the given size.
723 virtual void adjustForColumns(LayoutSize&, const LayoutPoint&) const { }
725 virtual unsigned int length() const { return 1; }
727 bool isFloatingOrPositioned() const { return (isFloating() || isPositioned()); }
729 bool isTransparent() const { return style()->opacity() < 1.0f; }
730 float opacity() const { return style()->opacity(); }
732 bool hasReflection() const { return m_hasReflection; }
734 // Applied as a "slop" to dirty rect checks during the outline painting phase's dirty-rect checks.
735 LayoutUnit maximalOutlineSize(PaintPhase) const;
737 void setHasMarkupTruncation(bool b = true) { m_hasMarkupTruncation = b; }
738 bool hasMarkupTruncation() const { return m_hasMarkupTruncation; }
740 enum SelectionState {
741 SelectionNone, // The object is not selected.
742 SelectionStart, // The object either contains the start of a selection run or is the start of a run
743 SelectionInside, // The object is fully encompassed by a selection run
744 SelectionEnd, // The object either contains the end of a selection run or is the end of a run
745 SelectionBoth // The object contains an entire run or is the sole selected object in that run
748 // The current selection state for an object. For blocks, the state refers to the state of the leaf
749 // descendants (as described above in the SelectionState enum declaration).
750 SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState);; }
752 // Sets the selection state for an object.
753 virtual void setSelectionState(SelectionState state) { m_selectionState = state; }
755 // A single rectangle that encompasses all of the selected objects within this object. Used to determine the tightest
756 // possible bounding box for the selection.
757 LayoutRect selectionRect(bool clipToVisibleContent = true) { return selectionRectForRepaint(0, clipToVisibleContent); }
758 virtual LayoutRect selectionRectForRepaint(RenderBoxModelObject* /*repaintContainer*/, bool /*clipToVisibleContent*/ = true) { return LayoutRect(); }
760 // Whether or not an object can be part of the leaf elements of the selection.
761 virtual bool canBeSelectionLeaf() const { return false; }
763 // Whether or not a block has selected children.
764 bool hasSelectedChildren() const { return m_selectionState != SelectionNone; }
766 // Obtains the selection colors that should be used when painting a selection.
767 Color selectionBackgroundColor() const;
768 Color selectionForegroundColor() const;
769 Color selectionEmphasisMarkColor() const;
771 // Whether or not a given block needs to paint selection gaps.
772 virtual bool shouldPaintSelectionGaps() const { return false; }
775 * Returns the local coordinates of the caret within this render object.
776 * @param caretOffset zero-based offset determining position within the render object.
777 * @param extraWidthToEndOfLine optional out arg to give extra width to end of line -
778 * useful for character range rect computations
780 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
782 bool isMarginBeforeQuirk() const { return m_marginBeforeQuirk; }
783 bool isMarginAfterQuirk() const { return m_marginAfterQuirk; }
784 void setMarginBeforeQuirk(bool b = true) { m_marginBeforeQuirk = b; }
785 void setMarginAfterQuirk(bool b = true) { m_marginAfterQuirk = b; }
787 // When performing a global document tear-down, the renderer of the document is cleared. We use this
788 // as a hook to detect the case of document destruction and don't waste time doing unnecessary work.
789 bool documentBeingDestroyed() const;
791 virtual void destroy();
793 // Virtual function helpers for the deprecated Flexible Box Layout (display: -webkit-box).
794 virtual bool isDeprecatedFlexibleBox() const { return false; }
795 virtual bool isFlexingChildren() const { return false; }
796 virtual bool isStretchingChildren() const { return false; }
798 // Virtual function helper for the new FlexibleBox Layout (display: -webkit-flexbox).
799 virtual bool isFlexibleBox() const { return false; }
801 bool isFlexibleBoxIncludingDeprecated() const
803 return isFlexibleBox() || isDeprecatedFlexibleBox();
806 virtual bool isCombineText() const { return false; }
808 virtual int caretMinOffset() const;
809 virtual int caretMaxOffset() const;
811 virtual int previousOffset(int current) const;
812 virtual int previousOffsetForBackwardDeletion(int current) const;
813 virtual int nextOffset(int current) const;
815 virtual void imageChanged(CachedImage*, const IntRect* = 0);
816 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
817 virtual bool willRenderImage(CachedImage*);
819 void selectionStartEnd(int& spos, int& epos) const;
821 void remove() { if (parent()) parent()->removeChild(this); }
823 AnimationController* animation() const;
825 bool visibleToHitTesting() const { return style()->visibility() == VISIBLE && style()->pointerEvents() != PE_NONE; }
827 // Map points and quads through elements, potentially via 3d transforms. You should never need to call these directly; use
828 // localToAbsolute/absoluteToLocal methods instead.
829 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool useTransforms, bool fixed, TransformState&, bool* wasFixed = 0) const;
830 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
832 bool shouldUseTransformFromContainer(const RenderObject* container) const;
833 void getTransformFromContainer(const RenderObject* container, const LayoutSize& offsetInContainer, TransformationMatrix&) const;
835 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint&) { };
837 LayoutRect absoluteOutlineBounds() const
839 return outlineBoundsForRepaint(0);
843 // Overrides should call the superclass at the end
844 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
845 // Overrides should call the superclass at the start
846 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
847 void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
849 void drawLineForBoxSide(GraphicsContext*, LayoutUnit x1, LayoutUnit y1, LayoutUnit x2, LayoutUnit y2, BoxSide,
850 Color, EBorderStyle, int adjbw1, int adjbw2, bool antialias = false);
852 void paintFocusRing(GraphicsContext*, const LayoutPoint&, RenderStyle*);
853 void paintOutline(GraphicsContext*, const LayoutRect&);
854 void addPDFURLRect(GraphicsContext*, const LayoutRect&);
856 virtual LayoutRect viewRect() const;
858 void adjustRectForOutlineAndShadow(LayoutRect&) const;
860 virtual void willBeDestroyed();
861 void arenaDelete(RenderArena*, void* objectBase);
863 virtual LayoutRect outlineBoundsForRepaint(RenderBoxModelObject* /*repaintContainer*/, LayoutPoint* /*cachedOffsetToRepaintContainer*/ = 0) const { return LayoutRect(); }
866 RenderStyle* firstLineStyleSlowCase() const;
867 StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
869 Color selectionColor(int colorProperty) const;
871 RefPtr<RenderStyle> m_style;
875 RenderObject* m_parent;
876 RenderObject* m_previous;
877 RenderObject* m_next;
881 bool m_setNeedsLayoutForbidden : 1;
884 // 32 bits have been used here. THERE ARE NO FREE BITS AVAILABLE.
885 bool m_needsLayout : 1;
886 bool m_needsPositionedMovementLayout :1;
887 bool m_normalChildNeedsLayout : 1;
888 bool m_posChildNeedsLayout : 1;
889 bool m_needsSimplifiedNormalFlowLayout : 1;
890 bool m_preferredLogicalWidthsDirty : 1;
893 bool m_positioned : 1;
894 bool m_relPositioned : 1;
895 bool m_paintBackground : 1; // if the box has something to paint in the
896 // background painting phase (background, border, etc)
898 bool m_isAnonymous : 1;
903 bool m_horizontalWritingMode : 1;
904 bool m_isDragging : 1;
907 bool m_hasOverflowClip : 1; // Set in the case of overflow:auto/scroll/hidden
908 bool m_hasTransform : 1;
909 bool m_hasReflection : 1;
912 bool m_hasCounterNodeMap : 1;
913 bool m_everHadLayout : 1;
916 // These bitfields are moved here from subclasses to pack them together
918 bool m_childrenInline : 1;
919 bool m_marginBeforeQuirk : 1;
920 bool m_marginAfterQuirk : 1;
921 bool m_hasMarkupTruncation : 1;
922 unsigned m_selectionState : 3; // SelectionState
923 bool m_hasColumns : 1;
924 bool m_inRenderFlowThread : 1;
927 // Store state between styleWillChange and styleDidChange
928 static bool s_affectsParentBlock;
931 inline bool RenderObject::documentBeingDestroyed() const
933 return !document()->renderer();
936 inline bool RenderObject::isBeforeContent() const
938 if (style()->styleType() != BEFORE)
940 // Text nodes don't have their own styles, so ignore the style on a text node.
941 if (isText() && !isBR())
946 inline bool RenderObject::isAfterContent() const
948 if (style()->styleType() != AFTER)
950 // Text nodes don't have their own styles, so ignore the style on a text node.
951 if (isText() && !isBR())
956 inline bool RenderObject::isBeforeOrAfterContent() const
958 return isBeforeContent() || isAfterContent();
961 inline void RenderObject::setNeedsLayout(bool b, bool markParents)
963 bool alreadyNeededLayout = m_needsLayout;
966 ASSERT(!isSetNeedsLayoutForbidden());
967 if (!alreadyNeededLayout) {
969 markContainingBlocksForLayout();
971 setLayerNeedsFullRepaint();
974 m_everHadLayout = true;
975 m_posChildNeedsLayout = false;
976 m_needsSimplifiedNormalFlowLayout = false;
977 m_normalChildNeedsLayout = false;
978 m_needsPositionedMovementLayout = false;
982 inline void RenderObject::setChildNeedsLayout(bool b, bool markParents)
984 bool alreadyNeededLayout = m_normalChildNeedsLayout;
985 m_normalChildNeedsLayout = b;
987 ASSERT(!isSetNeedsLayoutForbidden());
988 if (!alreadyNeededLayout && markParents)
989 markContainingBlocksForLayout();
991 m_posChildNeedsLayout = false;
992 m_needsSimplifiedNormalFlowLayout = false;
993 m_normalChildNeedsLayout = false;
994 m_needsPositionedMovementLayout = false;
998 inline void RenderObject::setNeedsPositionedMovementLayout()
1000 bool alreadyNeededLayout = m_needsPositionedMovementLayout;
1001 m_needsPositionedMovementLayout = true;
1002 ASSERT(!isSetNeedsLayoutForbidden());
1003 if (!alreadyNeededLayout) {
1004 markContainingBlocksForLayout();
1006 setLayerNeedsFullRepaint();
1010 inline void RenderObject::setNeedsSimplifiedNormalFlowLayout()
1012 bool alreadyNeededLayout = m_needsSimplifiedNormalFlowLayout;
1013 m_needsSimplifiedNormalFlowLayout = true;
1014 ASSERT(!isSetNeedsLayoutForbidden());
1015 if (!alreadyNeededLayout) {
1016 markContainingBlocksForLayout();
1018 setLayerNeedsFullRepaint();
1022 inline bool RenderObject::preservesNewline() const
1025 if (isSVGInlineText())
1029 return style()->preserveNewline();
1032 inline void makeMatrixRenderable(TransformationMatrix& matrix, bool has3DRendering)
1034 #if !ENABLE(3D_RENDERING)
1035 UNUSED_PARAM(has3DRendering);
1036 matrix.makeAffine();
1038 if (!has3DRendering)
1039 matrix.makeAffine();
1043 inline int adjustForAbsoluteZoom(int value, RenderObject* renderer)
1045 return adjustForAbsoluteZoom(value, renderer->style());
1048 inline void adjustFloatQuadForAbsoluteZoom(FloatQuad& quad, RenderObject* renderer)
1050 float zoom = renderer->style()->effectiveZoom();
1052 quad.scale(1 / zoom, 1 / zoom);
1055 inline void adjustFloatRectForAbsoluteZoom(FloatRect& rect, RenderObject* renderer)
1057 float zoom = renderer->style()->effectiveZoom();
1059 rect.scale(1 / zoom, 1 / zoom);
1062 inline void adjustFloatQuadForPageScale(FloatQuad& quad, float pageScale)
1065 quad.scale(1 / pageScale, 1 / pageScale);
1068 inline void adjustFloatRectForPageScale(FloatRect& rect, float pageScale)
1071 rect.scale(1 / pageScale, 1 / pageScale);
1074 } // namespace WebCore
1077 // Outside the WebCore namespace for ease of invocation from gdb.
1078 void showTree(const WebCore::RenderObject*);
1079 void showLineTree(const WebCore::RenderObject*);
1080 void showRenderTree(const WebCore::RenderObject* object1);
1081 // We don't make object2 an optional parameter so that showRenderTree
1082 // can be called from gdb easily.
1083 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2);
1086 #endif // RenderObject_h