2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "RenderBoxModelObject.h"
27 #include "RenderOverflow.h"
28 #include "ScrollTypes.h"
32 class RenderBoxRegionInfo;
36 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
38 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
40 class RenderBox : public RenderBoxModelObject {
45 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
46 // position:static elements that are not flex-items get their z-index coerced to auto.
47 virtual bool requiresLayer() const OVERRIDE { return isRoot() || isOutOfFlowPositioned() || isRelPositioned() || isTransparent() || hasClipPath() || hasOverflowClip() || hasTransform() || hasHiddenBackface() || hasMask() || hasReflection() || hasFilter() || style()->specifiesColumns(); }
49 // Use this with caution! No type checking is done!
50 RenderBox* firstChildBox() const;
51 RenderBox* lastChildBox() const;
53 LayoutUnit x() const { return m_frameRect.x(); }
54 LayoutUnit y() const { return m_frameRect.y(); }
55 LayoutUnit width() const { return m_frameRect.width(); }
56 LayoutUnit height() const { return m_frameRect.height(); }
58 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
59 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
61 // These represent your location relative to your container as a physical offset.
62 // In layout related methods you almost always want the logical location (e.g. x() and y()).
63 LayoutUnit top() const { return topLeftLocation().y(); }
64 LayoutUnit left() const { return topLeftLocation().x(); }
66 void setX(LayoutUnit x) { m_frameRect.setX(x); }
67 void setY(LayoutUnit y) { m_frameRect.setY(y); }
68 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
69 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
71 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
72 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
73 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
74 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
75 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
76 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
78 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
79 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
81 void setLogicalLeft(LayoutUnit left)
83 if (style()->isHorizontalWritingMode())
88 void setLogicalTop(LayoutUnit top)
90 if (style()->isHorizontalWritingMode())
95 void setLogicalLocation(const LayoutPoint& location)
97 if (style()->isHorizontalWritingMode())
98 setLocation(location);
100 setLocation(location.transposedPoint());
102 void setLogicalWidth(LayoutUnit size)
104 if (style()->isHorizontalWritingMode())
109 void setLogicalHeight(LayoutUnit size)
111 if (style()->isHorizontalWritingMode())
116 void setLogicalSize(const LayoutSize& size)
118 if (style()->isHorizontalWritingMode())
121 setSize(size.transposedSize());
124 LayoutPoint location() const { return m_frameRect.location(); }
125 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
126 LayoutSize size() const { return m_frameRect.size(); }
127 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
129 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
131 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
132 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
134 LayoutRect frameRect() const { return m_frameRect; }
135 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
136 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
138 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
139 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
140 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
141 virtual IntRect borderBoundingBox() const { return pixelSnappedBorderBoxRect(); }
143 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
144 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
145 // The content box in absolute coords. Ignores transforms.
146 IntRect absoluteContentBox() const;
147 // The content box converted to absolute coords (taking transforms into account).
148 FloatQuad absoluteContentQuad() const;
150 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
151 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
152 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
154 // Bounds of the outline box in absolute coords. Respects transforms
155 virtual LayoutRect outlineBoundsForRepaint(RenderBoxModelObject* /*repaintContainer*/, LayoutPoint* cachedOffsetToRepaintContainer) const;
156 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
158 // Use this with caution! No type checking is done!
159 RenderBox* previousSiblingBox() const;
160 RenderBox* nextSiblingBox() const;
161 RenderBox* parentBox() const;
163 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
164 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
165 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
166 // but it is on the right in vertical-rl.
167 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : clientBoxRect(); }
168 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
169 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
170 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
171 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
173 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
174 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
175 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
177 void addLayoutOverflow(const LayoutRect&);
178 void addVisualOverflow(const LayoutRect&);
180 void addVisualEffectOverflow();
181 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
182 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
183 void clearLayoutOverflow();
185 void updateLayerTransform();
187 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
188 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
189 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
190 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
192 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
193 // to return the remaining width on a given line (and the height of a single line).
194 virtual LayoutUnit offsetWidth() const { return width(); }
195 virtual LayoutUnit offsetHeight() const { return height(); }
197 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318.
198 virtual int pixelSnappedOffsetWidth() const { return pixelSnappedWidth(); }
199 virtual int pixelSnappedOffsetHeight() const { return pixelSnappedHeight(); }
201 // More IE extensions. clientWidth and clientHeight represent the interior of an object
202 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
203 LayoutUnit clientLeft() const { return borderLeft(); }
204 LayoutUnit clientTop() const { return borderTop(); }
205 LayoutUnit clientWidth() const;
206 LayoutUnit clientHeight() const;
207 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
208 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
209 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
210 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
212 int pixelSnappedClientWidth() const;
213 int pixelSnappedClientHeight() const;
215 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
216 // object has overflow:hidden/scroll/auto specified and also has overflow.
217 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
218 // textareas can scroll shadow content (but pretend that they are the objects that are
220 virtual int scrollLeft() const;
221 virtual int scrollTop() const;
222 virtual int scrollWidth() const;
223 virtual int scrollHeight() const;
224 virtual void setScrollLeft(int);
225 virtual void setScrollTop(int);
227 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
228 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
229 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
230 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
231 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
232 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
233 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
234 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
236 virtual LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
237 virtual LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
239 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
240 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
241 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE
243 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
244 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
246 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE
248 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
249 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
251 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
252 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
253 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
255 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
256 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
258 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
260 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
261 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
264 // The following five functions are used to implement collapsing margins.
265 // All objects know their maximal positive and negative margins. The
266 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
267 // For a non-collapsing box, such as a leaf element, this formula will simply return
268 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
270 enum MarginSign { PositiveMargin, NegativeMargin };
271 virtual bool isSelfCollapsingBlock() const { return false; }
272 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
273 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
275 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
276 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
278 LayoutRect reflectionBox() const;
279 int reflectionOffset() const;
280 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
281 LayoutRect reflectedRect(const LayoutRect&) const;
283 virtual void layout();
284 virtual void paint(PaintInfo&, const LayoutPoint&);
285 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
287 virtual LayoutUnit minPreferredLogicalWidth() const;
288 virtual LayoutUnit maxPreferredLogicalWidth() const;
290 LayoutUnit overrideLogicalContentWidth() const;
291 LayoutUnit overrideLogicalContentHeight() const;
292 bool hasOverrideHeight() const;
293 bool hasOverrideWidth() const;
294 void setOverrideLogicalContentHeight(LayoutUnit);
295 void setOverrideLogicalContentWidth(LayoutUnit);
296 void clearOverrideSize();
298 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const;
300 LayoutUnit computeBorderBoxLogicalWidth(LayoutUnit width) const;
301 LayoutUnit computeBorderBoxLogicalHeight(LayoutUnit height) const;
302 LayoutUnit computeContentBoxLogicalWidth(LayoutUnit width) const;
303 LayoutUnit computeContentBoxLogicalHeight(LayoutUnit height) const;
305 virtual void borderFitAdjust(LayoutRect&) const { } // Shrink the box in which the border paints if border-fit is set.
307 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
308 // of the containing block.
309 void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth);
311 // Used to resolve margins in the containing block's block-flow direction.
312 void computeBlockDirectionMargins(const RenderBlock* containingBlock);
314 enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
315 LayoutRect borderBoxRectInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage = 0, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
316 void clearRenderBoxRegionInfo();
318 void positionLineBox(InlineBox*);
320 virtual InlineBox* createInlineBox();
321 void dirtyLineBoxes(bool fullLayout);
323 // For inline replaced elements, this function returns the inline box that owns us. Enables
324 // the replaced RenderObject to quickly determine what line it is contained on and to easily
325 // iterate over structures on the line.
326 InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
327 void setInlineBoxWrapper(InlineBox* boxWrapper) { m_inlineBoxWrapper = boxWrapper; }
328 void deleteLineBoxWrapper();
330 virtual LayoutRect clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const;
331 virtual void computeRectForRepaint(RenderBoxModelObject* repaintContainer, LayoutRect&, bool fixed = false) const;
333 virtual void repaintDuringLayoutIfMoved(const LayoutRect&);
335 virtual LayoutUnit containingBlockLogicalWidthForContent() const;
336 LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage) const;
337 LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage) const;
338 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
340 virtual void computeLogicalWidth();
341 virtual void computeLogicalHeight();
343 RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
344 void computeLogicalWidthInRegion(RenderRegion* = 0, LayoutUnit offsetFromLogicalTopOfFirstPage = ZERO_LAYOUT_UNIT);
346 bool stretchesToViewport() const
348 return document()->inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !document()->shouldDisplaySeamlesslyWithParent();
351 virtual IntSize intrinsicSize() const { return IntSize(); }
352 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
353 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
355 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
356 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
357 bool sizesLogicalWidthToFitContent(SizeType) const;
358 virtual bool stretchesToMinIntrinsicLogicalWidth() const { return false; }
360 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock* cb, RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage);
362 LayoutUnit computeLogicalWidthInRegionUsing(SizeType, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock, RenderRegion*, LayoutUnit offsetFromLogicalTopOfFirstPage);
363 LayoutUnit computeLogicalHeightUsing(SizeType, const Length& height);
364 LayoutUnit computeContentLogicalHeightUsing(SizeType, const Length& height);
365 LayoutUnit computeReplacedLogicalWidthUsing(SizeType, Length width) const;
366 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, bool includeMaxWidth = true) const;
367 LayoutUnit computeReplacedLogicalHeightUsing(SizeType, Length height) const;
368 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
370 virtual LayoutUnit computeReplacedLogicalWidth(bool includeMaxWidth = true) const;
371 virtual LayoutUnit computeReplacedLogicalHeight() const;
373 LayoutUnit computePercentageLogicalHeight(const Length& height);
375 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
376 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
377 virtual LayoutUnit availableLogicalHeight() const;
378 LayoutUnit availableLogicalHeightUsing(const Length&) const;
380 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
381 // Relative positioning is one of those cases, since left/top offsets are physical.
382 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(); }
383 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight() : availableLogicalWidth(); }
385 virtual int verticalScrollbarWidth() const;
386 int horizontalScrollbarHeight() const;
387 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
388 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
389 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
390 bool canBeScrolledAndHasScrollableArea() const;
391 virtual bool canBeProgramaticallyScrolled() const;
392 virtual void autoscroll();
393 virtual void stopAutoscroll() { }
394 virtual void panScroll(const IntPoint&);
395 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
396 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
397 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
398 bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
399 bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
401 bool hasUnsplittableScrollingOverflow() const;
402 bool isUnsplittableForPagination() const;
404 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
406 virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
407 LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
408 virtual bool hasControlClip() const { return false; }
409 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
410 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset);
411 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
413 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
414 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
415 virtual void paintMask(PaintInfo&, const LayoutPoint&);
416 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
418 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
419 // that just updates the object's position. If the size does change, the object remains dirty.
420 bool tryLayoutDoingPositionedMovementOnly()
422 LayoutUnit oldWidth = width();
423 computeLogicalWidth();
424 // If we shrink to fit our width may have changed, so we still need full layout.
425 if (oldWidth != width())
427 computeLogicalHeight();
431 LayoutRect maskClipRect();
433 virtual VisiblePosition positionForPoint(const LayoutPoint&);
435 void removeFloatingOrPositionedChildFromBlockLists();
437 RenderLayer* enclosingFloatPaintingLayer() const;
439 virtual LayoutUnit firstLineBoxBaseline() const { return -1; }
440 virtual LayoutUnit lastLineBoxBaseline() const { return -1; }
442 bool shrinkToAvoidFloats() const;
443 virtual bool avoidsFloats() const;
445 virtual void markForPaginationRelayoutIfNeeded() { }
447 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
449 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
451 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
452 virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
454 virtual LayoutUnit offsetLeft() const OVERRIDE;
455 virtual LayoutUnit offsetTop() const OVERRIDE;
457 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
458 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
459 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
460 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
461 LayoutSize flipForWritingMode(const LayoutSize&) const;
462 void flipForWritingMode(LayoutRect&) const;
463 FloatPoint flipForWritingMode(const FloatPoint&) const;
464 void flipForWritingMode(FloatRect&) const;
465 // These represent your location relative to your container as a physical offset.
466 // In layout related methods you almost always want the logical location (e.g. x() and y()).
467 LayoutPoint topLeftLocation() const;
468 LayoutSize topLeftLocationOffset() const;
470 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
471 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
472 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
473 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
475 RenderOverflow* hasRenderOverflow() const { return m_overflow.get(); }
476 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
478 virtual bool needsPreferredWidthsRecalculation() const;
479 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
481 IntSize scrolledContentOffset() const;
482 LayoutSize cachedSizeForOverflowClip() const;
484 virtual bool hasRelativeDimensions() const;
485 virtual bool hasRelativeLogicalHeight() const;
487 bool hasHorizontalLayoutOverflow() const
489 if (RenderOverflow* overflow = hasRenderOverflow()) {
490 LayoutRect layoutOverflowRect = overflow->layoutOverflowRect();
491 flipForWritingMode(layoutOverflowRect);
492 return layoutOverflowRect.x() < x() || layoutOverflowRect.maxX() > x() + logicalWidth();
498 bool hasVerticalLayoutOverflow() const
500 if (RenderOverflow* overflow = hasRenderOverflow()) {
501 LayoutRect layoutOverflowRect = overflow->layoutOverflowRect();
502 flipForWritingMode(layoutOverflowRect);
503 return layoutOverflowRect.y() < y() || layoutOverflowRect.maxY() > y() + logicalHeight();
509 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
511 ASSERT_NOT_REACHED();
516 virtual void willBeDestroyed();
518 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
519 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
520 virtual void updateBoxModelInfoFromStyle();
522 virtual bool backgroundIsObscured() const { return false; }
523 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
525 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
526 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
528 void paintMaskImages(const PaintInfo&, const LayoutRect&);
530 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
533 void paintCustomHighlight(const LayoutPoint&, const AtomicString& type, bool behindText);
536 void computePositionedLogicalWidth(RenderRegion* = 0, LayoutUnit offsetFromLogicalTopOfFirstPage = 0);
538 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
540 virtual void mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState&, ApplyContainerFlipOrNot = ApplyContainerFlip, bool* wasFixed = 0) const;
541 virtual const RenderObject* pushMappingToContainer(const RenderBoxModelObject*, RenderGeometryMap&) const;
542 virtual void mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState&) const;
544 void paintRootBoxFillLayers(const PaintInfo&);
546 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
549 bool fixedElementLaysOutRelativeToFrame(Frame*, FrameView*) const;
551 bool includeVerticalScrollbarSize() const;
552 bool includeHorizontalScrollbarSize() const;
554 // Returns true if we did a full repaint
555 bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
557 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* = 0,
558 LayoutUnit offsetFromLogicalTopOfFirstPage = 0, bool checkForPerpendicularWritingMode = true) const;
559 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
561 void computePositionedLogicalHeight();
562 void computePositionedLogicalWidthUsing(SizeType, Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
563 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
564 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
565 LayoutUnit& logicalWidthValue, LayoutUnit& marginLogicalLeftValue, LayoutUnit& marginLogicalRightValue, LayoutUnit& logicalLeftPos);
566 void computePositionedLogicalHeightUsing(SizeType, Length logicalHeight, const RenderBoxModelObject* containerBlock,
567 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding,
568 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
569 LayoutUnit& logicalHeightValue, LayoutUnit& marginLogicalTopValue, LayoutUnit& marginLogicalBottomValue, LayoutUnit& logicalTopPos);
571 void computePositionedLogicalHeightReplaced();
572 void computePositionedLogicalWidthReplaced();
574 // This function calculates the minimum and maximum preferred widths for an object.
575 // These values are used in shrink-to-fit layout systems.
576 // These include tables, positioned objects, floats and flexible boxes.
577 virtual void computePreferredLogicalWidths() { setPreferredLogicalWidthsDirty(false); }
580 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
581 LayoutRect m_frameRect;
584 LayoutBoxExtent m_marginBox;
586 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
587 LayoutUnit m_minPreferredLogicalWidth;
589 // The preferred logical width of the element if it never breaks any lines at all.
590 LayoutUnit m_maxPreferredLogicalWidth;
592 // For inline replaced elements, the inline box that owns us.
593 InlineBox* m_inlineBoxWrapper;
595 // Our overflow information.
596 OwnPtr<RenderOverflow> m_overflow;
599 // Used to store state between styleWillChange and styleDidChange
600 static bool s_hadOverflowClip;
603 inline RenderBox* toRenderBox(RenderObject* object)
605 ASSERT(!object || object->isBox());
606 return static_cast<RenderBox*>(object);
609 inline const RenderBox* toRenderBox(const RenderObject* object)
611 ASSERT(!object || object->isBox());
612 return static_cast<const RenderBox*>(object);
615 // This will catch anyone doing an unnecessary cast.
616 void toRenderBox(const RenderBox*);
618 inline RenderBox* RenderBox::previousSiblingBox() const
620 return toRenderBox(previousSibling());
623 inline RenderBox* RenderBox::nextSiblingBox() const
625 return toRenderBox(nextSibling());
628 inline RenderBox* RenderBox::parentBox() const
630 return toRenderBox(parent());
633 inline RenderBox* RenderBox::firstChildBox() const
635 return toRenderBox(firstChild());
638 inline RenderBox* RenderBox::lastChildBox() const
640 return toRenderBox(lastChild());
643 } // namespace WebCore
645 #endif // RenderBox_h