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 "core/animation/ActiveAnimations.h"
27 #include "core/rendering/LayoutRectRecorder.h"
28 #include "core/rendering/RenderBoxModelObject.h"
29 #include "core/rendering/RenderOverflow.h"
30 #include "core/rendering/shapes/ShapeOutsideInfo.h"
31 #include "platform/scroll/ScrollTypes.h"
37 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
38 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
39 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
41 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
43 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
45 enum ScrollOffsetClamping {
46 ScrollOffsetUnclamped,
50 struct RenderBoxRareData {
51 WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED;
54 : m_inlineBoxWrapper(0)
55 , m_overrideLogicalContentHeight(-1)
56 , m_overrideLogicalContentWidth(-1)
60 // For inline replaced elements, the inline box that owns us.
61 InlineBox* m_inlineBoxWrapper;
63 LayoutUnit m_overrideLogicalContentHeight;
64 LayoutUnit m_overrideLogicalContentWidth;
68 class RenderBox : public RenderBoxModelObject {
70 explicit RenderBox(ContainerNode*);
72 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
73 // position:static elements that are not flex-items get their z-index coerced to auto.
74 virtual LayerType layerTypeRequired() const OVERRIDE
76 if (isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->hasWillChangeCompositingHint() || style()->hasWillChangeGpuRasterizationHint() || shouldCompositeForActiveAnimations(*this))
78 if (hasOverflowClip())
79 return OverflowClipLayer;
84 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
86 // Use this with caution! No type checking is done!
87 RenderBox* firstChildBox() const;
88 RenderBox* lastChildBox() const;
90 LayoutUnit x() const { return m_frameRect.x(); }
91 LayoutUnit y() const { return m_frameRect.y(); }
92 LayoutUnit width() const { return m_frameRect.width(); }
93 LayoutUnit height() const { return m_frameRect.height(); }
95 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
96 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
98 // These represent your location relative to your container as a physical offset.
99 // In layout related methods you almost always want the logical location (e.g. x() and y()).
100 LayoutUnit top() const { return topLeftLocation().y(); }
101 LayoutUnit left() const { return topLeftLocation().x(); }
103 void setX(LayoutUnit x) { m_frameRect.setX(x); }
104 void setY(LayoutUnit y) { m_frameRect.setY(y); }
105 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
106 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
108 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
109 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
110 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
111 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
112 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
113 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
115 LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
116 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
117 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
119 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
120 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
122 void setLogicalLeft(LayoutUnit left)
124 if (style()->isHorizontalWritingMode())
129 void setLogicalTop(LayoutUnit top)
131 if (style()->isHorizontalWritingMode())
136 void setLogicalLocation(const LayoutPoint& location)
138 if (style()->isHorizontalWritingMode())
139 setLocation(location);
141 setLocation(location.transposedPoint());
143 void setLogicalWidth(LayoutUnit size)
145 if (style()->isHorizontalWritingMode())
150 void setLogicalHeight(LayoutUnit size)
152 if (style()->isHorizontalWritingMode())
157 void setLogicalSize(const LayoutSize& size)
159 if (style()->isHorizontalWritingMode())
162 setSize(size.transposedSize());
165 LayoutPoint location() const { return m_frameRect.location(); }
166 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
167 LayoutSize size() const { return m_frameRect.size(); }
168 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
170 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
172 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
173 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
175 LayoutRect frameRect() const { return m_frameRect; }
176 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
177 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
179 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
180 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
181 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
182 virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
184 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
185 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
186 // The content box in absolute coords. Ignores transforms.
187 IntRect absoluteContentBox() const;
188 // The content box converted to absolute coords (taking transforms into account).
189 FloatQuad absoluteContentQuad() const;
191 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
192 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
193 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
195 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
197 // Use this with caution! No type checking is done!
198 RenderBox* previousSiblingBox() const;
199 RenderBox* nextSiblingBox() const;
200 RenderBox* parentBox() const;
202 bool canResize() const;
204 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
205 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
206 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
207 // but it is on the right in vertical-rl.
208 LayoutRect noOverflowRect() const;
209 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
210 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
211 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
212 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
213 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
215 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
216 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
217 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
219 LayoutRect overflowRectForPaintRejection() const;
221 LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
223 void addLayoutOverflow(const LayoutRect&);
224 void addVisualOverflow(const LayoutRect&);
226 // Clipped by the contents clip, if one exists.
227 void addContentsVisualOverflow(const LayoutRect&);
229 void addVisualEffectOverflow();
230 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
231 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
232 void clearLayoutOverflow();
233 void clearAllOverflows() { m_overflow.clear(); }
235 void updateLayerTransform();
237 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
238 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
239 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
240 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
242 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
243 // to return the remaining width on a given line (and the height of a single line).
244 virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); }
245 virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); }
247 virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
248 virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
250 bool canDetermineWidthWithoutLayout() const;
251 LayoutUnit fixedOffsetWidth() const;
253 // More IE extensions. clientWidth and clientHeight represent the interior of an object
254 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
255 LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); }
256 LayoutUnit clientTop() const { return borderTop(); }
257 LayoutUnit clientWidth() const;
258 LayoutUnit clientHeight() const;
259 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
260 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
261 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
262 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
264 int pixelSnappedClientWidth() const;
265 int pixelSnappedClientHeight() const;
267 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
268 // object has overflow:hidden/scroll/auto specified and also has overflow.
269 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
270 // textareas can scroll shadow content (but pretend that they are the objects that are
272 virtual int scrollLeft() const;
273 virtual int scrollTop() const;
274 virtual int scrollWidth() const;
275 virtual int scrollHeight() const;
276 virtual void setScrollLeft(int);
277 virtual void setScrollTop(int);
279 void scrollToOffset(const IntSize&);
280 void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
281 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
283 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
284 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
285 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
286 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
287 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
288 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
289 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
290 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
292 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
293 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
295 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
296 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
297 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
299 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
300 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
302 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
304 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
305 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
307 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
308 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
309 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
311 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
312 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
314 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
316 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
317 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
320 // The following five functions are used to implement collapsing margins.
321 // All objects know their maximal positive and negative margins. The
322 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
323 // For a non-collapsing box, such as a leaf element, this formula will simply return
324 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
326 enum MarginSign { PositiveMargin, NegativeMargin };
327 virtual bool isSelfCollapsingBlock() const { return false; }
328 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
329 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
331 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
332 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
334 LayoutRect reflectionBox() const;
335 int reflectionOffset() const;
336 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
337 LayoutRect reflectedRect(const LayoutRect&) const;
339 virtual void layout() OVERRIDE;
340 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
341 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
343 virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
344 virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
346 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
347 // the border-box height/width like the regular height/width accessors on RenderBox.
348 // Right now, these are different than contentHeight/contentWidth because they still
349 // include the scrollbar height/width.
350 LayoutUnit overrideLogicalContentWidth() const;
351 LayoutUnit overrideLogicalContentHeight() const;
352 bool hasOverrideHeight() const;
353 bool hasOverrideWidth() const;
354 void setOverrideLogicalContentHeight(LayoutUnit);
355 void setOverrideLogicalContentWidth(LayoutUnit);
356 void clearOverrideSize();
357 void clearOverrideLogicalContentHeight();
358 void clearOverrideLogicalContentWidth();
360 LayoutUnit overrideContainingBlockContentLogicalWidth() const;
361 LayoutUnit overrideContainingBlockContentLogicalHeight() const;
362 bool hasOverrideContainingBlockLogicalWidth() const;
363 bool hasOverrideContainingBlockLogicalHeight() const;
364 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
365 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
366 void clearContainingBlockOverrideSize();
367 void clearOverrideContainingBlockContentLogicalHeight();
369 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
371 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
372 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
373 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
374 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
376 struct ComputedMarginValues {
377 ComputedMarginValues() { }
384 struct LogicalExtentComputedValues {
385 LogicalExtentComputedValues() { }
388 LayoutUnit m_position;
389 ComputedMarginValues m_margins;
391 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
392 // of the containing block.
393 void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
395 // Used to resolve margins in the containing block's block-flow direction.
396 void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
397 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
399 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
401 void positionLineBox(InlineBox*);
403 virtual InlineBox* createInlineBox();
404 void dirtyLineBoxes(bool fullLayout);
406 // For inline replaced elements, this function returns the inline box that owns us. Enables
407 // the replaced RenderObject to quickly determine what line it is contained on and to easily
408 // iterate over structures on the line.
409 InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; }
410 void setInlineBoxWrapper(InlineBox*);
411 void deleteLineBoxWrapper();
413 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
414 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
415 void repaintDuringLayoutIfMoved(const LayoutRect&);
416 virtual void repaintOverhangingFloats(bool paintAllDescendants);
418 virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
419 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
421 LayoutUnit containingBlockAvailableLineWidth() const;
422 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
424 virtual void updateLogicalWidth();
425 virtual void updateLogicalHeight();
426 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
428 void computeLogicalWidth(LogicalExtentComputedValues&) const;
430 bool stretchesToViewport() const
432 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !isInline();
435 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
436 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
437 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
439 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
440 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
441 bool sizesLogicalWidthToFitContent(SizeType) const;
443 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
445 LayoutUnit computeLogicalWidthUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const;
446 LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
447 LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
448 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
449 LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
450 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
451 LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
452 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
454 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
455 virtual LayoutUnit computeReplacedLogicalHeight() const;
457 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
458 LayoutUnit computePercentageLogicalHeight(const Length& height) const;
460 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
461 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
462 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
463 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
465 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
466 // Relative positioning is one of those cases, since left/top offsets are physical.
467 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
468 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
470 virtual int verticalScrollbarWidth() const;
471 int horizontalScrollbarHeight() const;
472 int instrinsicScrollbarLogicalWidth() const;
473 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
474 virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
475 bool canBeScrolledAndHasScrollableArea() const;
476 virtual bool canBeProgramaticallyScrolled() const;
477 virtual void autoscroll(const IntPoint&);
478 bool autoscrollInProgress() const;
479 bool canAutoscroll() const;
480 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
481 static RenderBox* findAutoscrollable(RenderObject*);
482 virtual void stopAutoscroll() { }
483 virtual void panScroll(const IntPoint&);
485 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
486 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
487 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
489 bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
490 bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
491 virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
492 virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
493 bool usesCompositedScrolling() const;
495 // Elements such as the <input> field override this to specify that they are scrollable
496 // outside the context of the CSS overflow style
497 virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
499 bool hasUnsplittableScrollingOverflow() const;
500 bool isUnsplittableForPagination() const;
502 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
504 virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
505 LayoutRect clipRect(const LayoutPoint& location);
506 virtual bool hasControlClip() const { return false; }
507 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
508 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
509 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
511 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
512 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
513 virtual void paintMask(PaintInfo&, const LayoutPoint&);
514 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
515 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
517 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
518 // that just updates the object's position. If the size does change, the object remains dirty.
519 bool tryLayoutDoingPositionedMovementOnly()
521 LayoutRectRecorder recorder(*this);
522 LayoutUnit oldWidth = width();
523 updateLogicalWidth();
524 // If we shrink to fit our width may have changed, so we still need full layout.
525 if (oldWidth != width())
527 updateLogicalHeight();
531 LayoutRect maskClipRect();
533 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
535 void removeFloatingOrPositionedChildFromBlockLists();
537 RenderLayer* enclosingFloatPaintingLayer() const;
539 virtual int firstLineBoxBaseline() const { return -1; }
540 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
542 bool shrinkToAvoidFloats() const;
543 virtual bool avoidsFloats() const;
545 virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&);
547 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
549 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
550 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
552 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
553 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
555 virtual LayoutUnit offsetLeft() const OVERRIDE;
556 virtual LayoutUnit offsetTop() const OVERRIDE;
558 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
559 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
560 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
561 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
562 LayoutSize flipForWritingMode(const LayoutSize&) const;
563 void flipForWritingMode(LayoutRect&) const;
564 FloatPoint flipForWritingMode(const FloatPoint&) const;
565 void flipForWritingMode(FloatRect&) const;
566 // These represent your location relative to your container as a physical offset.
567 // In layout related methods you almost always want the logical location (e.g. x() and y()).
568 LayoutPoint topLeftLocation() const;
569 LayoutSize topLeftLocationOffset() const;
571 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
572 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
573 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
574 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
576 bool hasRenderOverflow() const { return m_overflow; }
577 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
579 virtual bool needsPreferredWidthsRecalculation() const;
580 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
582 IntSize scrolledContentOffset() const;
583 LayoutSize cachedSizeForOverflowClip() const;
584 void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
586 virtual bool hasRelativeLogicalHeight() const;
588 bool hasHorizontalLayoutOverflow() const
593 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
594 LayoutRect noOverflowRect = this->noOverflowRect();
595 return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
598 bool hasVerticalLayoutOverflow() const
603 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
604 LayoutRect noOverflowRect = this->noOverflowRect();
605 return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
608 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
610 ASSERT_NOT_REACHED();
614 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
616 ShapeOutsideInfo* shapeOutsideInfo() const
618 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
621 void markShapeOutsideDependentsForLayout()
624 removeFloatingOrPositionedChildFromBlockLists();
628 virtual void willBeDestroyed() OVERRIDE;
630 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle) OVERRIDE;
631 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
632 virtual void updateFromStyle() OVERRIDE;
634 LayoutRect backgroundPaintedExtent() const;
635 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
636 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
638 void paintBackgroundWithBorderAndBoxShadow(PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance);
639 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
641 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
642 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
644 void paintMaskImages(const PaintInfo&, const LayoutRect&);
645 void paintBoxDecorationsWithRect(PaintInfo&, const LayoutPoint&, const LayoutRect&);
647 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
648 bool backgroundHasOpaqueTopLayer() const;
650 void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
652 LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
653 LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
655 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
657 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
658 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
660 void paintRootBoxFillLayers(const PaintInfo&);
662 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
664 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
665 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
668 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
669 void updateGridPositionAfterStyleChange(const RenderStyle*);
671 bool autoWidthShouldFitContent() const;
672 void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
674 // Returns true if we did a full repaint
675 bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
677 bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
679 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
680 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
682 LayoutUnit viewLogicalHeightForPercentages() const;
684 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
685 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
686 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
687 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
688 LogicalExtentComputedValues&) const;
689 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
690 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
691 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
692 LogicalExtentComputedValues&) const;
694 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
695 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
697 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
698 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
700 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
702 // This function calculates the minimum and maximum preferred widths for an object.
703 // These values are used in shrink-to-fit layout systems.
704 // These include tables, positioned objects, floats and flexible boxes.
705 virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
707 virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
709 RenderBoxRareData& ensureRareData()
712 m_rareData = adoptPtr(new RenderBoxRareData());
713 return *m_rareData.get();
717 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
718 LayoutRect m_frameRect;
720 // Our intrinsic height, used for min-height: min-content etc. Maintained by
721 // updateLogicalHeight. This is logicalHeight() before it is clamped to
723 LayoutUnit m_intrinsicContentLogicalHeight;
726 LayoutBoxExtent m_marginBox;
728 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
729 LayoutUnit m_minPreferredLogicalWidth;
731 // The preferred logical width of the element if it never breaks any lines at all.
732 LayoutUnit m_maxPreferredLogicalWidth;
734 // Our overflow information.
735 OwnPtr<RenderOverflow> m_overflow;
738 OwnPtr<RenderBoxRareData> m_rareData;
741 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
743 inline RenderBox* RenderBox::previousSiblingBox() const
745 return toRenderBox(previousSibling());
748 inline RenderBox* RenderBox::nextSiblingBox() const
750 return toRenderBox(nextSibling());
753 inline RenderBox* RenderBox::parentBox() const
755 return toRenderBox(parent());
758 inline RenderBox* RenderBox::firstChildBox() const
760 return toRenderBox(firstChild());
763 inline RenderBox* RenderBox::lastChildBox() const
765 return toRenderBox(lastChild());
768 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
771 ASSERT(!inlineBoxWrapper());
772 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
773 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
774 // only one will be notified when the renderer is getting destroyed. The second line box wrapper
775 // will keep a stale reference.
776 if (UNLIKELY(inlineBoxWrapper() != 0))
777 deleteLineBoxWrapper();
780 ensureRareData().m_inlineBoxWrapper = boxWrapper;
783 } // namespace WebCore
785 #endif // RenderBox_h