2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2006, 2007, 2015 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.
25 #include "FrameView.h"
26 #include "RenderBoxModelObject.h"
27 #include "RenderOverflow.h"
28 #include "ScrollTypes.h"
29 #include "ShapeOutsideInfo.h"
33 class InlineElementBox;
34 class RenderBlockFlow;
35 class RenderBoxFragmentInfo;
36 class RenderFragmentContainer;
39 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
40 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
41 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
43 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
45 class RenderBox : public RenderBoxModelObject {
46 WTF_MAKE_ISO_ALLOCATED(RenderBox);
50 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
51 // position:static elements that are not flex-items get their z-index coerced to auto.
52 bool requiresLayer() const override
54 return isDocumentElementRenderer() || isPositioned() || createsGroup() || hasClipPath() || hasOverflowClip()
55 || hasTransformRelatedProperty() || hasHiddenBackface() || hasReflection() || style().specifiesColumns()
56 || !style().hasAutoZIndex();
59 bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const final;
61 // Returns false for the body renderer if its background is propagated to the root.
62 bool paintsOwnBackground() const;
64 LayoutUnit x() const { return m_frameRect.x(); }
65 LayoutUnit y() const { return m_frameRect.y(); }
66 LayoutUnit width() const { return m_frameRect.width(); }
67 LayoutUnit height() const { return m_frameRect.height(); }
69 // These represent your location relative to your container as a physical offset.
70 // In layout related methods you almost always want the logical location (e.g. x() and y()).
71 LayoutUnit top() const { return topLeftLocation().y(); }
72 LayoutUnit left() const { return topLeftLocation().x(); }
74 void setX(LayoutUnit x) { m_frameRect.setX(x); }
75 void setY(LayoutUnit y) { m_frameRect.setY(y); }
76 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
77 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
79 LayoutUnit logicalLeft() const { return style().isHorizontalWritingMode() ? x() : y(); }
80 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
81 LayoutUnit logicalTop() const { return style().isHorizontalWritingMode() ? y() : x(); }
82 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
83 LayoutUnit logicalWidth() const { return style().isHorizontalWritingMode() ? width() : height(); }
84 LayoutUnit logicalHeight() const { return style().isHorizontalWritingMode() ? height() : width(); }
86 LayoutUnit constrainLogicalWidthInFragmentByMinMax(LayoutUnit, LayoutUnit, RenderBlock&, RenderFragmentContainer* = nullptr) const;
87 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, std::optional<LayoutUnit> intrinsicContentHeight) const;
88 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, std::optional<LayoutUnit> intrinsicContentHeight) const;
90 void setLogicalLeft(LayoutUnit left)
92 if (style().isHorizontalWritingMode())
97 void setLogicalTop(LayoutUnit top)
99 if (style().isHorizontalWritingMode())
104 void setLogicalLocation(const LayoutPoint& location)
106 if (style().isHorizontalWritingMode())
107 setLocation(location);
109 setLocation(location.transposedPoint());
111 void setLogicalWidth(LayoutUnit size)
113 if (style().isHorizontalWritingMode())
118 void setLogicalHeight(LayoutUnit size)
120 if (style().isHorizontalWritingMode())
125 void setLogicalSize(const LayoutSize& size)
127 if (style().isHorizontalWritingMode())
130 setSize(size.transposedSize());
133 LayoutPoint location() const { return m_frameRect.location(); }
134 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
135 LayoutSize size() const { return m_frameRect.size(); }
137 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
139 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
140 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
142 LayoutRect frameRect() const { return m_frameRect; }
143 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
145 LayoutRect marginBoxRect() const
147 LayoutRect box = borderBoxRect();
148 box.expand(m_marginBox);
151 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
152 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
153 LayoutRect borderBoundingBox() const final { return borderBoxRect(); }
155 WEBCORE_EXPORT RoundedRect::Radii borderRadii() const;
157 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
158 LayoutRect contentBoxRect() const;
159 LayoutPoint contentBoxLocation() const;
161 // The content box in absolute coords. Ignores transforms.
162 IntRect absoluteContentBox() const;
163 // The content box converted to absolute coords (taking transforms into account).
164 WEBCORE_EXPORT FloatQuad absoluteContentQuad() const;
166 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
167 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
168 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
170 // Bounds of the outline box in absolute coords. Respects transforms
171 LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap*) const final;
172 void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = nullptr) override;
174 FloatRect repaintRectInLocalCoordinates() const override { return borderBoxRect(); }
175 FloatRect objectBoundingBox() const override { return borderBoxRect(); }
177 // Note these functions are not equivalent of childrenOfType<RenderBox>
178 RenderBox* parentBox() const;
179 RenderBox* firstChildBox() const;
180 RenderBox* lastChildBox() const;
181 RenderBox* previousSiblingBox() const;
182 RenderBox* nextSiblingBox() const;
184 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
185 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
186 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
187 // but it is on the right in vertical-rl.
188 WEBCORE_EXPORT LayoutRect flippedClientBoxRect() const;
189 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : flippedClientBoxRect(); }
190 LayoutUnit logicalLeftLayoutOverflow() const { return style().isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
191 LayoutUnit logicalRightLayoutOverflow() const { return style().isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
193 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
194 LayoutUnit logicalLeftVisualOverflow() const { return style().isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
195 LayoutUnit logicalRightVisualOverflow() const { return style().isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
197 LayoutRect overflowRectForPaintRejection() const;
199 void addLayoutOverflow(const LayoutRect&);
200 void addVisualOverflow(const LayoutRect&);
201 void clearOverflow();
203 virtual bool isTopLayoutOverflowAllowed() const { return !style().isLeftToRightDirection() && !isHorizontalWritingMode(); }
204 virtual bool isLeftLayoutOverflowAllowed() const { return !style().isLeftToRightDirection() && isHorizontalWritingMode(); }
206 void addVisualEffectOverflow();
207 LayoutRect applyVisualEffectOverflow(const LayoutRect&) const;
208 void addOverflowFromChild(const RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
209 void addOverflowFromChild(const RenderBox* child, const LayoutSize& delta);
211 void updateLayerTransform();
213 LayoutSize contentSize() const { return { contentWidth(), contentHeight() }; }
214 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
215 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
216 LayoutUnit contentLogicalWidth() const { return style().isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
217 LayoutUnit contentLogicalHeight() const { return style().isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
219 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
220 // to return the remaining width on a given line (and the height of a single line).
221 LayoutUnit offsetWidth() const override { return width(); }
222 LayoutUnit offsetHeight() const override { return height(); }
224 // More IE extensions. clientWidth and clientHeight represent the interior of an object
225 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
226 LayoutUnit clientLeft() const { return borderLeft(); }
227 LayoutUnit clientTop() const { return borderTop(); }
228 WEBCORE_EXPORT LayoutUnit clientWidth() const;
229 WEBCORE_EXPORT LayoutUnit clientHeight() const;
230 LayoutUnit clientLogicalWidth() const { return style().isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
231 LayoutUnit clientLogicalHeight() const { return style().isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
232 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
233 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
235 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
236 // object has overflow:hidden/scroll/auto specified and also has overflow.
237 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
238 // textareas can scroll shadow content (but pretend that they are the objects that are
240 virtual int scrollLeft() const;
241 virtual int scrollTop() const;
242 virtual int scrollWidth() const;
243 virtual int scrollHeight() const;
244 virtual void setScrollLeft(int, ScrollClamping = ScrollClamping::Clamped);
245 virtual void setScrollTop(int, ScrollClamping = ScrollClamping::Clamped);
247 LayoutUnit marginTop() const override { return m_marginBox.top(); }
248 LayoutUnit marginBottom() const override { return m_marginBox.bottom(); }
249 LayoutUnit marginLeft() const override { return m_marginBox.left(); }
250 LayoutUnit marginRight() const override { return m_marginBox.right(); }
251 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
252 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
253 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
254 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
256 LayoutUnit marginLogicalLeft() const { return m_marginBox.start(style().writingMode()); }
257 LayoutUnit marginLogicalRight() const { return m_marginBox.end(style().writingMode()); }
259 LayoutUnit marginBefore(const RenderStyle* overrideStyle = nullptr) const final { return m_marginBox.before((overrideStyle ? overrideStyle : &style())->writingMode()); }
260 LayoutUnit marginAfter(const RenderStyle* overrideStyle = nullptr) const final { return m_marginBox.after((overrideStyle ? overrideStyle : &style())->writingMode()); }
261 LayoutUnit marginStart(const RenderStyle* overrideStyle = nullptr) const final
263 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
264 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
266 LayoutUnit marginEnd(const RenderStyle* overrideStyle = nullptr) const final
268 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
269 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
271 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = nullptr) { m_marginBox.setBefore(value, (overrideStyle ? overrideStyle : &style())->writingMode()); }
272 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = nullptr) { m_marginBox.setAfter(value, (overrideStyle ? overrideStyle : &style())->writingMode()); }
273 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = nullptr)
275 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
276 m_marginBox.setStart(value, styleToUse->writingMode(), styleToUse->direction());
278 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = nullptr)
280 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
281 m_marginBox.setEnd(value, styleToUse->writingMode(), styleToUse->direction());
284 virtual bool isSelfCollapsingBlock() const { return false; }
285 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
286 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
288 void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const override;
289 void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const override;
291 int reflectionOffset() const;
292 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
293 LayoutRect reflectedRect(const LayoutRect&) const;
295 void layout() override;
296 bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
298 LayoutUnit minPreferredLogicalWidth() const override;
299 LayoutUnit maxPreferredLogicalWidth() const override;
301 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
302 // the border-box height/width like the regular height/width accessors on RenderBox.
303 // Right now, these are different than contentHeight/contentWidth because they still
304 // include the scrollbar height/width.
305 LayoutUnit overrideLogicalContentWidth() const;
306 LayoutUnit overrideLogicalContentHeight() const;
307 bool hasOverrideLogicalContentHeight() const;
308 bool hasOverrideLogicalContentWidth() const;
309 void setOverrideLogicalContentHeight(LayoutUnit);
310 void setOverrideLogicalContentWidth(LayoutUnit);
311 void clearOverrideSize();
312 void clearOverrideLogicalContentHeight();
313 void clearOverrideLogicalContentWidth();
315 std::optional<LayoutUnit> overrideContainingBlockContentLogicalWidth() const;
316 std::optional<LayoutUnit> overrideContainingBlockContentLogicalHeight() const;
317 bool hasOverrideContainingBlockLogicalWidth() const;
318 bool hasOverrideContainingBlockLogicalHeight() const;
319 void setOverrideContainingBlockContentLogicalWidth(std::optional<LayoutUnit>);
320 void setOverrideContainingBlockContentLogicalHeight(std::optional<LayoutUnit>);
321 void clearContainingBlockOverrideSize();
322 void clearOverrideContainingBlockContentLogicalHeight();
324 LayoutSize offsetFromContainer(RenderElement&, const LayoutPoint&, bool* offsetDependsOnPoint = nullptr) const override;
326 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
327 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
329 // Overridden by fieldsets to subtract out the intrinsic border.
330 virtual LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
331 virtual LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(std::optional<LayoutUnit> height) const;
333 struct ComputedMarginValues {
339 struct LogicalExtentComputedValues {
341 LayoutUnit m_position;
342 ComputedMarginValues m_margins;
344 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
345 // of the containing block.
346 void computeInlineDirectionMargins(const RenderBlock& containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
348 // Used to resolve margins in the containing block's block-flow direction.
349 void computeBlockDirectionMargins(const RenderBlock& containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
350 void computeAndSetBlockDirectionMargins(const RenderBlock& containingBlock);
352 enum RenderBoxFragmentInfoFlags { CacheRenderBoxFragmentInfo, DoNotCacheRenderBoxFragmentInfo };
353 LayoutRect borderBoxRectInFragment(RenderFragmentContainer*, RenderBoxFragmentInfoFlags = CacheRenderBoxFragmentInfo) const;
354 LayoutRect clientBoxRectInFragment(RenderFragmentContainer*) const;
355 RenderFragmentContainer* clampToStartAndEndFragments(RenderFragmentContainer*) const;
356 bool hasFragmentRangeInFragmentedFlow() const;
357 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
359 void positionLineBox(InlineElementBox&);
361 virtual std::unique_ptr<InlineElementBox> createInlineBox();
362 void dirtyLineBoxes(bool fullLayout);
364 // For inline replaced elements, this function returns the inline box that owns us. Enables
365 // the replaced RenderObject to quickly determine what line it is contained on and to easily
366 // iterate over structures on the line.
367 InlineElementBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
368 void setInlineBoxWrapper(InlineElementBox*);
369 void deleteLineBoxWrapper();
371 LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const override;
372 LayoutRect computeRectForRepaint(const LayoutRect&, const RenderLayerModelObject* repaintContainer, RepaintContext context = { false, false }) const override;
373 void repaintDuringLayoutIfMoved(const LayoutRect&);
374 virtual void repaintOverhangingFloats(bool paintAllDescendants);
376 LayoutUnit containingBlockLogicalWidthForContent() const override;
377 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
379 LayoutUnit containingBlockLogicalWidthForContentInFragment(RenderFragmentContainer*) const;
380 LayoutUnit containingBlockAvailableLineWidthInFragment(RenderFragmentContainer*) const;
381 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
383 virtual void updateLogicalWidth();
384 virtual void updateLogicalHeight();
385 virtual LogicalExtentComputedValues computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const;
387 void cacheIntrinsicContentLogicalHeightForFlexItem(LayoutUnit) const;
389 // This function will compute the logical border-box height, without laying
390 // out the box. This means that the result is only "correct" when the height
391 // is explicitly specified. This function exists so that intrinsic width
392 // calculations have a way to deal with children that have orthogonal writing modes.
393 // When there is no explicit height, this function assumes a content height of
394 // zero (and returns just border + padding).
395 LayoutUnit computeLogicalHeightWithoutLayout() const;
397 RenderBoxFragmentInfo* renderBoxFragmentInfo(RenderFragmentContainer*, RenderBoxFragmentInfoFlags = CacheRenderBoxFragmentInfo) const;
398 void computeLogicalWidthInFragment(LogicalExtentComputedValues&, RenderFragmentContainer* = nullptr) const;
400 bool stretchesToViewport() const
402 return document().inQuirksMode() && style().logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElementRenderer() || isBody()) && !isInline();
405 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
406 LayoutUnit intrinsicLogicalWidth() const { return style().isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
407 LayoutUnit intrinsicLogicalHeight() const { return style().isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
409 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
410 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
411 bool sizesLogicalWidthToFitContent(SizeType) const;
413 bool hasStretchedLogicalWidth() const;
414 bool isStretchingColumnFlexItem() const;
415 bool columnFlexItemHasStretchAlignment() const;
417 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock& cb, RenderFragmentContainer*) const;
419 LayoutUnit computeLogicalWidthInFragmentUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock& containingBlock, RenderFragmentContainer*) const;
420 std::optional<LayoutUnit> computeLogicalHeightUsing(SizeType, const Length& height, std::optional<LayoutUnit> intrinsicContentHeight) const;
421 std::optional<LayoutUnit> computeContentLogicalHeight(SizeType, const Length& height, std::optional<LayoutUnit> intrinsicContentHeight) const;
422 std::optional<LayoutUnit> computeContentAndScrollbarLogicalHeightUsing(SizeType, const Length& height, std::optional<LayoutUnit> intrinsicContentHeight) const;
423 LayoutUnit computeReplacedLogicalWidthUsing(SizeType, Length width) const;
424 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
425 LayoutUnit computeReplacedLogicalHeightUsing(SizeType, Length height) const;
426 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
428 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
429 virtual LayoutUnit computeReplacedLogicalHeight(std::optional<LayoutUnit> estimatedUsedWidth = std::nullopt) const;
431 std::optional<LayoutUnit> computePercentageLogicalHeight(const Length& height) const;
433 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
434 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
435 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
437 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
438 // Relative positioning is one of those cases, since left/top offsets are physical.
439 LayoutUnit availableWidth() const { return style().isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
440 LayoutUnit availableHeight() const { return style().isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
442 virtual int verticalScrollbarWidth() const;
443 int horizontalScrollbarHeight() const;
444 int intrinsicScrollbarLogicalWidth() const;
445 int scrollbarLogicalWidth() const { return style().isHorizontalWritingMode() ? verticalScrollbarWidth() : horizontalScrollbarHeight(); }
446 int scrollbarLogicalHeight() const { return style().isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
447 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint());
448 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr);
449 WEBCORE_EXPORT bool canBeScrolledAndHasScrollableArea() const;
450 virtual bool canBeProgramaticallyScrolled() const;
451 virtual void autoscroll(const IntPoint&);
452 bool canAutoscroll() const;
453 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
454 static RenderBox* findAutoscrollable(RenderObject*);
455 virtual void stopAutoscroll() { }
456 virtual void panScroll(const IntPoint&);
458 bool hasVerticalScrollbarWithAutoBehavior() const;
459 bool hasHorizontalScrollbarWithAutoBehavior() const;
461 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
462 bool scrollsOverflowX() const { return hasOverflowClip() && (style().overflowX() == OSCROLL || hasHorizontalScrollbarWithAutoBehavior()); }
463 bool scrollsOverflowY() const { return hasOverflowClip() && (style().overflowY() == OSCROLL || hasVerticalScrollbarWithAutoBehavior()); }
465 bool hasHorizontalOverflow() const { return scrollWidth() != roundToInt(clientWidth()); }
466 bool hasVerticalOverflow() const { return scrollHeight() != roundToInt(clientHeight()); }
468 bool hasScrollableOverflowX() const { return scrollsOverflowX() && hasHorizontalOverflow(); }
469 bool hasScrollableOverflowY() const { return scrollsOverflowY() && hasVerticalOverflow(); }
471 bool usesCompositedScrolling() const;
473 bool percentageLogicalHeightIsResolvable() const;
474 bool hasUnsplittableScrollingOverflow() const;
475 bool isUnsplittableForPagination() const;
477 bool shouldTreatChildAsReplacedInTableCells() const;
479 LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr) override;
481 virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderFragmentContainer* = nullptr, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, PaintPhase = PaintPhaseBlockBackground);
482 virtual LayoutRect overflowClipRectForChildLayers(const LayoutPoint& location, RenderFragmentContainer* fragment, OverlayScrollbarSizeRelevancy relevancy) { return overflowClipRect(location, fragment, relevancy); }
483 LayoutRect clipRect(const LayoutPoint& location, RenderFragmentContainer*);
484 virtual bool hasControlClip() const { return false; }
485 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
486 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset);
487 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
489 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
490 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
491 virtual void paintMask(PaintInfo&, const LayoutPoint&);
492 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
493 void imageChanged(WrappedImagePtr, const IntRect* = nullptr) override;
495 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
496 // that just updates the object's position. If the size does change, the object remains dirty.
497 bool tryLayoutDoingPositionedMovementOnly()
499 LayoutUnit oldWidth = width();
500 updateLogicalWidth();
501 // If we shrink to fit our width may have changed, so we still need full layout.
502 if (oldWidth != width())
504 updateLogicalHeight();
508 LayoutRect maskClipRect(const LayoutPoint& paintOffset);
510 VisiblePosition positionForPoint(const LayoutPoint&, const RenderFragmentContainer*) override;
512 void removeFloatingOrPositionedChildFromBlockLists();
514 RenderLayer* enclosingFloatPaintingLayer() const;
516 virtual std::optional<int> firstLineBaseline() const { return std::optional<int>(); }
517 virtual std::optional<int> inlineBlockBaseline(LineDirectionMode) const { return std::optional<int>(); } // Returns empty if we should skip this box when computing the baseline of an inline-block.
519 bool shrinkToAvoidFloats() const;
520 virtual bool avoidsFloats() const;
522 virtual void markForPaginationRelayoutIfNeeded() { }
524 bool isWritingModeRoot() const { return !parent() || parent()->style().writingMode() != style().writingMode(); }
526 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
527 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
529 LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
530 int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
532 LayoutUnit offsetLeft() const override;
533 LayoutUnit offsetTop() const override;
535 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
536 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
537 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
538 LayoutSize flipForWritingMode(const LayoutSize&) const;
539 void flipForWritingMode(LayoutRect&) const;
540 FloatPoint flipForWritingMode(const FloatPoint&) const;
541 void flipForWritingMode(FloatRect&) const;
542 // These represent your location relative to your container as a physical offset.
543 // In layout related methods you almost always want the logical location (e.g. x() and y()).
544 LayoutPoint topLeftLocation() const;
545 LayoutSize topLeftLocationOffset() const;
546 void applyTopLeftLocationOffset(LayoutPoint& point) const
548 // This is inlined for speed, since it is used by updateLayerPosition() during scrolling.
549 if (!document().view()->hasFlippedBlockRenderers())
550 point.move(m_frameRect.x(), m_frameRect.y());
552 applyTopLeftLocationOffsetWithFlipping(point);
555 LayoutRect logicalVisualOverflowRectForPropagation(const RenderStyle*) const;
556 LayoutRect visualOverflowRectForPropagation(const RenderStyle*) const;
557 LayoutRect logicalLayoutOverflowRectForPropagation(const RenderStyle*) const;
558 LayoutRect layoutOverflowRectForPropagation(const RenderStyle*) const;
560 bool hasRenderOverflow() const { return m_overflow; }
561 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
563 virtual bool needsPreferredWidthsRecalculation() const;
564 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
566 ScrollPosition scrollPosition() const;
567 LayoutSize cachedSizeForOverflowClip() const;
569 bool shouldApplyClipAndScrollPositionForRepaint(const RenderLayerModelObject* repaintContainer) const;
570 void applyCachedClipAndScrollPositionForRepaint(LayoutRect& paintRect) const;
572 virtual bool hasRelativeDimensions() const;
573 virtual bool hasRelativeLogicalHeight() const;
574 virtual bool hasRelativeLogicalWidth() const;
576 bool hasHorizontalLayoutOverflow() const
581 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
582 flipForWritingMode(layoutOverflowRect);
583 return layoutOverflowRect.x() < x() || layoutOverflowRect.maxX() > x() + logicalWidth();
586 bool hasVerticalLayoutOverflow() const
591 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
592 flipForWritingMode(layoutOverflowRect);
593 return layoutOverflowRect.y() < y() || layoutOverflowRect.maxY() > y() + logicalHeight();
596 virtual RenderPtr<RenderBox> createAnonymousBoxWithSameTypeAs(const RenderBox&) const
598 ASSERT_NOT_REACHED();
602 ShapeOutsideInfo* shapeOutsideInfo() const
604 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : nullptr;
607 void markShapeOutsideDependentsForLayout()
610 removeFloatingOrPositionedChildFromBlockLists();
613 // True if this box can have a range in an outside fragmentation context.
614 bool canHaveOutsideFragmentRange() const { return !isInFlowRenderFragmentedFlow(); }
615 virtual bool needsLayoutAfterFragmentRangeChange() const { return false; }
617 const RenderBox* findEnclosingScrollableContainer() const;
619 bool isGridItem() const { return parent() && parent()->isRenderGrid() && !isExcludedFromNormalLayout(); }
620 bool isFlexItem() const { return parent() && parent()->isFlexibleBox() && !isExcludedFromNormalLayout(); }
622 virtual void adjustBorderBoxRectForPainting(LayoutRect&) { };
625 RenderBox(Element&, RenderStyle&&, BaseTypeFlags);
626 RenderBox(Document&, RenderStyle&&, BaseTypeFlags);
628 void styleWillChange(StyleDifference, const RenderStyle& newStyle) override;
629 void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
630 void updateFromStyle() override;
632 void willBeDestroyed() override;
634 bool createsNewFormattingContext() const;
636 virtual ItemPosition selfAlignmentNormalBehavior(const RenderBox* = nullptr) const { return ItemPositionStretch; }
638 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
639 bool getBackgroundPaintedExtent(const LayoutPoint& paintOffset, LayoutRect&) const;
640 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
641 bool computeBackgroundIsKnownToBeObscured(const LayoutPoint& paintOffset) override;
643 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
645 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer&, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderElement* backgroundObject, BaseBackgroundColorUsage = BaseBackgroundColorUse);
646 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderElement* backgroundObject = nullptr);
648 void paintMaskImages(const PaintInfo&, const LayoutRect&);
650 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext&) const;
651 bool backgroundHasOpaqueTopLayer() const;
653 void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderFragmentContainer* = nullptr) const;
655 LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
656 virtual std::optional<LayoutUnit> computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional<LayoutUnit> intrinsicContentHeight, LayoutUnit borderAndPadding) const;
658 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
660 void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags, bool* wasFixed) const override;
661 const RenderObject* pushMappingToContainer(const RenderLayerModelObject*, RenderGeometryMap&) const override;
662 void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
664 void paintRootBoxFillLayers(const PaintInfo&);
666 bool skipContainingBlockForPercentHeightCalculation(const RenderBox& containingBlock, bool isPerpendicularWritingMode) const;
669 bool replacedMinMaxLogicalHeightComputesAsNone(SizeType) const;
671 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
673 void updateGridPositionAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
675 bool scrollLayer(ScrollDirection, ScrollGranularity, float multiplier, Element** stopElement);
677 bool fixedElementLaysOutRelativeToFrame(const FrameView&) const;
679 bool includeVerticalScrollbarSize() const;
680 bool includeHorizontalScrollbarSize() const;
682 bool isScrollableOrRubberbandableBox() const override;
684 // Returns true if we did a full repaint.
685 bool repaintLayerRectsForImage(WrappedImagePtr, const FillLayer& layers, bool drawingBackground);
687 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject& containingBlock, RenderFragmentContainer* = nullptr, bool checkForPerpendicularWritingMode = true) const;
688 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject& containingBlock, bool checkForPerpendicularWritingMode = true) const;
690 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
691 void computePositionedLogicalWidthUsing(SizeType, Length logicalWidth, const RenderBoxModelObject& containerBlock, TextDirection containerDirection,
692 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
693 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
694 LogicalExtentComputedValues&) const;
695 void computePositionedLogicalHeightUsing(SizeType, Length logicalHeightLength, const RenderBoxModelObject& containerBlock,
696 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
697 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
698 LogicalExtentComputedValues&) const;
700 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
701 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
703 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
704 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
706 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
708 // This function calculates the minimum and maximum preferred widths for an object.
709 // These values are used in shrink-to-fit layout systems.
710 // These include tables, positioned objects, floats and flexible boxes.
711 virtual void computePreferredLogicalWidths() { setPreferredLogicalWidthsDirty(false); }
713 LayoutRect frameRectForStickyPositioning() const final { return frameRect(); }
715 void applyTopLeftLocationOffsetWithFlipping(LayoutPoint&) const;
718 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
719 LayoutRect m_frameRect;
722 LayoutBoxExtent m_marginBox;
724 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
725 LayoutUnit m_minPreferredLogicalWidth;
727 // The preferred logical width of the element if it never breaks any lines at all.
728 LayoutUnit m_maxPreferredLogicalWidth;
730 // For inline replaced elements, the inline box that owns us.
731 InlineElementBox* m_inlineBoxWrapper { nullptr };
733 // Our overflow information.
734 RefPtr<RenderOverflow> m_overflow;
737 // Used to store state between styleWillChange and styleDidChange
738 static bool s_hadOverflowClip;
741 inline RenderBox* RenderBox::parentBox() const
743 if (is<RenderBox>(parent()))
744 return downcast<RenderBox>(parent());
750 inline RenderBox* RenderBox::firstChildBox() const
752 if (is<RenderBox>(firstChild()))
753 return downcast<RenderBox>(firstChild());
755 ASSERT(!firstChild());
759 inline RenderBox* RenderBox::lastChildBox() const
761 if (is<RenderBox>(lastChild()))
762 return downcast<RenderBox>(lastChild());
764 ASSERT(!lastChild());
768 inline RenderBox* RenderBox::previousSiblingBox() const
770 if (is<RenderBox>(previousSibling()))
771 return downcast<RenderBox>(previousSibling());
773 ASSERT(!previousSibling());
777 inline RenderBox* RenderBox::nextSiblingBox() const
779 if (is<RenderBox>(nextSibling()))
780 return downcast<RenderBox>(nextSibling());
782 ASSERT(!nextSibling());
786 inline void RenderBox::setInlineBoxWrapper(InlineElementBox* boxWrapper)
789 ASSERT(!m_inlineBoxWrapper);
790 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
791 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
792 // only one will be notified when the renderer is getting destroyed. The second line box wrapper
793 // will keep a stale reference.
794 if (UNLIKELY(m_inlineBoxWrapper != nullptr))
795 deleteLineBoxWrapper();
798 m_inlineBoxWrapper = boxWrapper;
801 } // namespace WebCore
803 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderBox, isBox())