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/rendering/RenderBoxModelObject.h"
27 #include "core/rendering/RenderOverflow.h"
28 #include "core/rendering/shapes/ShapeOutsideInfo.h"
29 #include "platform/scroll/ScrollTypes.h"
35 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
36 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
37 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
38 enum MarginDirection { BlockDirection, InlineDirection };
40 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
42 enum ScrollOffsetClamping {
43 ScrollOffsetUnclamped,
47 struct RenderBoxRareData {
48 WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED;
51 : m_inlineBoxWrapper(0)
52 , m_overrideLogicalContentHeight(-1)
53 , m_overrideLogicalContentWidth(-1)
54 , m_previousBorderBoxSize(-1, -1)
58 // For inline replaced elements, the inline box that owns us.
59 InlineBox* m_inlineBoxWrapper;
61 LayoutUnit m_overrideLogicalContentHeight;
62 LayoutUnit m_overrideLogicalContentWidth;
64 // Set by RenderBox::updatePreviousBorderBoxSizeIfNeeded().
65 LayoutSize m_previousBorderBoxSize;
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 (isPositioned() || createsGroup() || hasClipPath() || hasTransformRelatedProperty() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->shouldCompositeForCurrentAnimations())
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 void setX(LayoutUnit x) { m_frameRect.setX(x); }
99 void setY(LayoutUnit y) { m_frameRect.setY(y); }
100 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
101 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
103 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
104 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
105 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
106 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
107 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
108 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
110 LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
111 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
112 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
114 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
115 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
117 void setLogicalLeft(LayoutUnit left)
119 if (style()->isHorizontalWritingMode())
124 void setLogicalTop(LayoutUnit top)
126 if (style()->isHorizontalWritingMode())
131 void setLogicalLocation(const LayoutPoint& location)
133 if (style()->isHorizontalWritingMode())
134 setLocation(location);
136 setLocation(location.transposedPoint());
138 void setLogicalWidth(LayoutUnit size)
140 if (style()->isHorizontalWritingMode())
145 void setLogicalHeight(LayoutUnit size)
147 if (style()->isHorizontalWritingMode())
153 LayoutPoint location() const { return m_frameRect.location(); }
154 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
155 LayoutSize size() const { return m_frameRect.size(); }
156 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
158 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
160 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
161 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
163 LayoutRect frameRect() const { return m_frameRect; }
164 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
166 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
167 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), clientWidth(), clientHeight()); }
168 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
169 virtual IntRect borderBoundingBox() const override final { return pixelSnappedBorderBoxRect(); }
171 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
172 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
173 // The content box in absolute coords. Ignores transforms.
174 IntRect absoluteContentBox() const;
175 // The content box converted to absolute coords (taking transforms into account).
176 FloatQuad absoluteContentQuad() const;
178 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
179 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
180 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
182 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const override;
184 // Use this with caution! No type checking is done!
185 RenderBox* previousSiblingBox() const;
186 RenderBox* nextSiblingBox() const;
187 RenderBox* parentBox() const;
189 bool canResize() const;
191 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
192 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
193 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
194 // but it is on the right in vertical-rl.
195 LayoutRect noOverflowRect() const;
196 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
197 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
198 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
199 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
200 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
202 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
203 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
204 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
206 LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
208 void addLayoutOverflow(const LayoutRect&);
209 void addVisualOverflow(const LayoutRect&);
211 // Clipped by the contents clip, if one exists.
212 void addContentsVisualOverflow(const LayoutRect&);
214 void addVisualEffectOverflow();
215 LayoutBoxExtent computeVisualEffectOverflowExtent() const;
216 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
217 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
218 void clearLayoutOverflow();
219 void clearAllOverflows() { m_overflow.clear(); }
221 void updateLayerTransformAfterLayout();
223 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
224 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
225 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
226 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
228 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
229 // to return the remaining width on a given line (and the height of a single line).
230 virtual LayoutUnit offsetWidth() const override { return width(); }
231 virtual LayoutUnit offsetHeight() const override { return height(); }
233 virtual int pixelSnappedOffsetWidth() const override final;
234 virtual int pixelSnappedOffsetHeight() const override final;
236 // More IE extensions. clientWidth and clientHeight represent the interior of an object
237 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
238 LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); }
239 LayoutUnit clientTop() const { return borderTop(); }
240 LayoutUnit clientWidth() const;
241 LayoutUnit clientHeight() const;
242 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
243 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
244 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
245 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
247 int pixelSnappedClientWidth() const;
248 int pixelSnappedClientHeight() const;
250 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
251 // object has overflow:hidden/scroll/auto specified and also has overflow.
252 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
253 // textareas can scroll shadow content (but pretend that they are the objects that are
255 virtual LayoutUnit scrollLeft() const;
256 virtual LayoutUnit scrollTop() const;
257 virtual LayoutUnit scrollWidth() const;
258 virtual LayoutUnit scrollHeight() const;
259 int pixelSnappedScrollWidth() const;
260 int pixelSnappedScrollHeight() const;
261 virtual void setScrollLeft(LayoutUnit);
262 virtual void setScrollTop(LayoutUnit);
264 void scrollToOffset(const DoubleSize&);
265 void scrollByRecursively(const DoubleSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
266 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
268 virtual LayoutUnit marginTop() const override { return m_marginBox.top(); }
269 virtual LayoutUnit marginBottom() const override { return m_marginBox.bottom(); }
270 virtual LayoutUnit marginLeft() const override { return m_marginBox.left(); }
271 virtual LayoutUnit marginRight() const override { return m_marginBox.right(); }
272 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
273 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
274 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
275 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
277 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
278 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
280 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const override final { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
281 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const override final { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
282 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const override final
284 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
285 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
287 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const override final
289 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
290 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
292 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
293 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
294 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
296 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
297 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
299 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
301 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
302 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
305 // The following functions are used to implement collapsing margins.
306 // All objects know their maximal positive and negative margins. The
307 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
308 // For a non-collapsing box, such as a leaf element, this formula will simply return
309 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
311 virtual bool isSelfCollapsingBlock() const { return false; }
312 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
313 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
315 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const override;
316 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const override;
318 int reflectionOffset() const;
319 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
320 LayoutRect reflectedRect(const LayoutRect&) const;
322 virtual void layout() override;
323 virtual void paint(PaintInfo&, const LayoutPoint&) override;
324 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
326 virtual LayoutUnit minPreferredLogicalWidth() const override;
327 virtual LayoutUnit maxPreferredLogicalWidth() const override;
329 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
330 // the border-box height/width like the regular height/width accessors on RenderBox.
331 // Right now, these are different than contentHeight/contentWidth because they still
332 // include the scrollbar height/width.
333 LayoutUnit overrideLogicalContentWidth() const;
334 LayoutUnit overrideLogicalContentHeight() const;
335 bool hasOverrideHeight() const;
336 bool hasOverrideWidth() const;
337 void setOverrideLogicalContentHeight(LayoutUnit);
338 void setOverrideLogicalContentWidth(LayoutUnit);
339 void clearOverrideSize();
340 void clearOverrideLogicalContentHeight();
341 void clearOverrideLogicalContentWidth();
343 LayoutUnit overrideContainingBlockContentLogicalWidth() const;
344 LayoutUnit overrideContainingBlockContentLogicalHeight() const;
345 bool hasOverrideContainingBlockLogicalWidth() const;
346 bool hasOverrideContainingBlockLogicalHeight() const;
347 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
348 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
349 void clearContainingBlockOverrideSize();
350 void clearOverrideContainingBlockContentLogicalHeight();
352 virtual LayoutSize offsetFromContainer(const RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const override;
354 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
355 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
356 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
357 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
359 struct ComputedMarginValues {
360 ComputedMarginValues() { }
367 struct LogicalExtentComputedValues {
368 LogicalExtentComputedValues() { }
371 LayoutUnit m_position;
372 ComputedMarginValues m_margins;
374 // Resolve auto margins in the chosen direction of the containing block so that objects can be pushed to the start, middle or end
375 // of the containing block.
376 void computeMarginsForDirection(MarginDirection forDirection, const RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd, Length marginStartLength, Length marginStartEnd) const;
378 // Used to resolve margins in the containing block's block-flow direction.
379 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
381 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
383 void positionLineBox(InlineBox*);
384 void moveWithEdgeOfInlineContainerIfNecessary(bool isHorizontal);
386 virtual InlineBox* createInlineBox();
387 void dirtyLineBoxes(bool fullLayout);
389 // For inline replaced elements, this function returns the inline box that owns us. Enables
390 // the replaced RenderObject to quickly determine what line it is contained on and to easily
391 // iterate over structures on the line.
392 InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; }
393 void setInlineBoxWrapper(InlineBox*);
394 void deleteLineBoxWrapper();
396 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const override;
397 virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const override;
398 virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants);
400 virtual LayoutUnit containingBlockLogicalWidthForContent() const override;
401 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
403 LayoutUnit containingBlockAvailableLineWidth() const;
404 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
406 virtual void updateLogicalWidth();
407 virtual void updateLogicalHeight();
408 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
410 void computeLogicalWidth(LogicalExtentComputedValues&) const;
412 bool stretchesToViewport() const
414 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElement() || isBody()) && !isInline();
417 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
418 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
419 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
420 virtual LayoutUnit intrinsicContentLogicalHeight() const { return m_intrinsicContentLogicalHeight; }
422 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
423 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
424 bool sizesLogicalWidthToFitContent(const Length& logicalWidth) const;
426 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
428 LayoutUnit computeLogicalWidthUsing(SizeType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const;
429 LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
430 LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
431 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
432 LayoutUnit computeReplacedLogicalWidthUsing(const Length& width) const;
433 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
434 LayoutUnit computeReplacedLogicalHeightUsing(const Length& height) const;
435 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
437 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
438 virtual LayoutUnit computeReplacedLogicalHeight() const;
440 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
441 LayoutUnit computePercentageLogicalHeight(const Length& height) const;
443 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
444 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
445 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
446 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
448 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
449 // Relative positioning is one of those cases, since left/top offsets are physical.
450 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
451 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
453 virtual int verticalScrollbarWidth() const;
454 int horizontalScrollbarHeight() const;
455 int instrinsicScrollbarLogicalWidth() const;
456 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
457 virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
458 bool canBeScrolledAndHasScrollableArea() const;
459 virtual bool canBeProgramaticallyScrolled() const;
460 virtual void autoscroll(const IntPoint&);
461 bool canAutoscroll() const;
462 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
463 static RenderBox* findAutoscrollable(RenderObject*);
464 virtual void stopAutoscroll() { }
465 virtual void panScroll(const IntPoint&);
467 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
468 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
469 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
471 bool hasScrollableOverflowX() const { return scrollsOverflowX() && pixelSnappedScrollWidth() != pixelSnappedClientWidth(); }
472 bool hasScrollableOverflowY() const { return scrollsOverflowY() && pixelSnappedScrollHeight() != pixelSnappedClientHeight(); }
473 virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
474 virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
475 bool usesCompositedScrolling() const;
477 // Elements such as the <input> field override this to specify that they are scrollable
478 // outside the context of the CSS overflow style
479 virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
481 bool hasUnsplittableScrollingOverflow() const;
482 bool isUnsplittableForPagination() const;
484 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
486 virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
487 LayoutRect clipRect(const LayoutPoint& location);
488 virtual bool hasControlClip() const { return false; }
489 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
491 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
492 virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&);
493 virtual void paintMask(PaintInfo&, const LayoutPoint&);
494 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
495 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) override;
497 LayoutRect borderBoxAfterUpdatingLogicalWidth(const LayoutUnit& logicalTop);
499 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
500 // that just updates the object's position. If the size does change, the object remains dirty.
501 bool tryLayoutDoingPositionedMovementOnly()
503 LayoutUnit oldWidth = width();
504 LayoutUnit newWidth = borderBoxAfterUpdatingLogicalWidth(logicalTop()).width();
505 // If we shrink to fit our width may have changed, so we still need full layout.
506 // FIXME: We check for potential change of width when deciding to set needsPositionedMovementLayout.
507 // So either that check or this one is unnecessary, probably the former. crbug.com/428050
508 if (oldWidth != newWidth)
510 updateLogicalHeight();
514 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) override;
516 void removeFloatingOrPositionedChildFromBlockLists();
518 RenderLayer* enclosingFloatPaintingLayer() const;
520 virtual int firstLineBoxBaseline() const { return -1; }
521 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
523 bool shrinkToAvoidFloats() const;
524 virtual bool avoidsFloats() const;
526 virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&);
528 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
530 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
531 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
533 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
534 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
536 virtual LayoutUnit offsetLeft() const override;
537 virtual LayoutUnit offsetTop() const override;
539 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
540 LayoutUnit flipForWritingMode(LayoutUnit position) const WARN_UNUSED_RETURN
542 // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
543 if (!UNLIKELY(hasFlippedBlocksWritingMode()))
545 return logicalHeight() - position;
547 LayoutPoint flipForWritingMode(const LayoutPoint& position) const WARN_UNUSED_RETURN
549 if (!UNLIKELY(hasFlippedBlocksWritingMode()))
551 return isHorizontalWritingMode() ? LayoutPoint(position.x(), height() - position.y()) : LayoutPoint(width() - position.x(), position.y());
553 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
554 LayoutSize flipForWritingMode(const LayoutSize& offset) const WARN_UNUSED_RETURN
556 if (!UNLIKELY(hasFlippedBlocksWritingMode()))
558 return isHorizontalWritingMode() ? LayoutSize(offset.width(), height() - offset.height()) : LayoutSize(width() - offset.width(), offset.height());
560 void flipForWritingMode(LayoutRect& rect) const
562 if (!UNLIKELY(hasFlippedBlocksWritingMode()))
564 if (isHorizontalWritingMode())
565 rect.setY(height() - rect.maxY());
567 rect.setX(width() - rect.maxX());
569 FloatPoint flipForWritingMode(const FloatPoint& position) const WARN_UNUSED_RETURN
571 if (!UNLIKELY(hasFlippedBlocksWritingMode()))
573 return isHorizontalWritingMode() ? FloatPoint(position.x(), height() - position.y()) : FloatPoint(width() - position.x(), position.y());
575 void flipForWritingMode(FloatRect& rect) const
577 if (!UNLIKELY(hasFlippedBlocksWritingMode()))
579 if (isHorizontalWritingMode())
580 rect.setY(height() - rect.maxY());
582 rect.setX(width() - rect.maxX());
584 // These represent your location relative to your container as a physical offset.
585 // In layout related methods you almost always want the logical location (e.g. x() and y()).
586 LayoutPoint topLeftLocation() const;
587 LayoutSize topLeftLocationOffset() const;
589 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
590 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
591 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
592 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
594 bool hasRenderOverflow() const { return m_overflow; }
595 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
597 virtual bool needsPreferredWidthsRecalculation() const;
598 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
600 IntSize scrolledContentOffset() const;
601 void applyCachedClipAndScrollOffsetForPaintInvalidation(LayoutRect& paintRect) const;
603 virtual bool hasRelativeLogicalHeight() const;
605 bool hasHorizontalLayoutOverflow() const
610 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
611 LayoutRect noOverflowRect = this->noOverflowRect();
612 return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
615 bool hasVerticalLayoutOverflow() const
620 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
621 LayoutRect noOverflowRect = this->noOverflowRect();
622 return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
625 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
627 ASSERT_NOT_REACHED();
631 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
633 ShapeOutsideInfo* shapeOutsideInfo() const
635 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
638 void markShapeOutsideDependentsForLayout()
641 removeFloatingOrPositionedChildFromBlockLists();
644 bool backgroundHasOpaqueTopLayer() const;
646 void updateIntrinsicContentLogicalHeight(LayoutUnit intrinsicContentLogicalHeight) const { m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight; }
648 virtual void willBeDestroyed() override;
651 virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle) override;
652 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
653 virtual void updateFromStyle() override;
655 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
656 // FIXME: make this a const method once the RenderBox reference in BoxPainter is const.
657 bool getBackgroundPaintedExtent(LayoutRect&);
658 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
659 virtual bool computeBackgroundIsKnownToBeObscured() override;
661 void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
663 LayoutUnit computeIntrinsicLogicalWidthUsing(const Length& logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
664 LayoutUnit computeIntrinsicLogicalContentHeightUsing(const Length& logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
666 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
668 virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const override;
669 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
671 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
673 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const override;
674 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const override;
676 virtual PaintInvalidationReason paintInvalidationReason(const RenderLayerModelObject& paintInvalidationContainer,
677 const LayoutRect& oldBounds, const LayoutPoint& oldPositionFromPaintInvalidationContainer,
678 const LayoutRect& newBounds, const LayoutPoint& newPositionFromPaintInvalidationContainer) const override;
679 virtual void incrementallyInvalidatePaint(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect& oldBounds, const LayoutRect& newBounds, const LayoutPoint& positionFromPaintInvalidationContainer) override;
681 virtual void clearPaintInvalidationState(const PaintInvalidationState&) override;
683 virtual bool paintInvalidationStateIsDirty() const override;
687 void invalidatePaintRectClippedByOldAndNewBounds(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect&, const LayoutRect& oldBounds, const LayoutRect& newBounds);
689 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
690 void updateGridPositionAfterStyleChange(const RenderStyle*);
692 bool autoWidthShouldFitContent() const;
693 void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
695 // Returns true if we queued up a paint invalidation.
696 bool paintInvalidationLayerRectsForImage(WrappedImagePtr, const FillLayer&, bool drawingBackground);
698 bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
700 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
701 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
703 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
704 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
705 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
706 const Length& logicalLeft, const Length& logicalRight, const Length& marginLogicalLeft,
707 const Length& marginLogicalRight, LogicalExtentComputedValues&) const;
708 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
709 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
710 const Length& logicalTop, const Length& logicalBottom, const Length& marginLogicalTop,
711 const Length& marginLogicalBottom, LogicalExtentComputedValues&) const;
713 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
714 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
716 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
717 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
719 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
721 // This function calculates the minimum and maximum preferred widths for an object.
722 // These values are used in shrink-to-fit layout systems.
723 // These include tables, positioned objects, floats and flexible boxes.
724 virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
726 RenderBoxRareData& ensureRareData()
729 m_rareData = adoptPtr(new RenderBoxRareData());
730 return *m_rareData.get();
733 void savePreviousBorderBoxSizeIfNeeded();
734 LayoutSize computePreviousBorderBoxSize(const LayoutSize& previousBoundsSize) const;
736 bool logicalHeightComputesAsNone(SizeType) const;
738 virtual PaintInvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&, const RenderLayerModelObject& newPaintInvalidationContainer) override final;
740 bool isBox() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
742 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
743 LayoutRect m_frameRect;
745 // Our intrinsic height, used for min-height: min-content etc. Maintained by
746 // updateLogicalHeight. This is logicalHeight() before it is clamped to
748 mutable LayoutUnit m_intrinsicContentLogicalHeight;
750 void inflatePaintInvalidationRectForReflectionAndFilter(LayoutRect&) const;
752 bool hasNonCompositedScrollbars() const;
755 LayoutBoxExtent m_marginBox;
757 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
758 LayoutUnit m_minPreferredLogicalWidth;
760 // The preferred logical width of the element if it never breaks any lines at all.
761 LayoutUnit m_maxPreferredLogicalWidth;
763 // Our overflow information.
764 OwnPtr<RenderOverflow> m_overflow;
767 OwnPtr<RenderBoxRareData> m_rareData;
770 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
772 inline RenderBox* RenderBox::previousSiblingBox() const
774 return toRenderBox(previousSibling());
777 inline RenderBox* RenderBox::nextSiblingBox() const
779 return toRenderBox(nextSibling());
782 inline RenderBox* RenderBox::parentBox() const
784 return toRenderBox(parent());
787 inline RenderBox* RenderBox::firstChildBox() const
789 return toRenderBox(slowFirstChild());
792 inline RenderBox* RenderBox::lastChildBox() const
794 return toRenderBox(slowLastChild());
797 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
800 ASSERT(!inlineBoxWrapper());
801 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
802 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
803 // only one will be notified when the renderer is getting destroyed. The second line box wrapper
804 // will keep a stale reference.
805 if (UNLIKELY(inlineBoxWrapper() != 0))
806 deleteLineBoxWrapper();
809 ensureRareData().m_inlineBoxWrapper = boxWrapper;
814 #endif // RenderBox_h