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.
26 #include "FrameView.h"
27 #include "RenderBoxModelObject.h"
28 #include "RenderOverflow.h"
29 #include "ScrollTypes.h"
30 #if ENABLE(CSS_SHAPES)
31 #include "ShapeOutsideInfo.h"
36 class InlineElementBox;
37 class RenderBlockFlow;
38 class RenderBoxRegionInfo;
42 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
43 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
44 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
46 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
48 class RenderBox : public RenderBoxModelObject {
52 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
53 // position:static elements that are not flex-items get their z-index coerced to auto.
54 bool requiresLayer() const override
56 return isDocumentElementRenderer() || isPositioned() || createsGroup() || hasClipPath() || hasOverflowClip()
57 || hasTransformRelatedProperty() || hasHiddenBackface() || hasReflection() || style().specifiesColumns()
58 || !style().hasAutoZIndex();
61 bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const final;
63 // Use this with caution! No type checking is done!
64 RenderBox* firstChildBox() const;
65 RenderBox* lastChildBox() const;
67 LayoutUnit x() const { return m_frameRect.x(); }
68 LayoutUnit y() const { return m_frameRect.y(); }
69 LayoutUnit width() const { return m_frameRect.width(); }
70 LayoutUnit height() const { return m_frameRect.height(); }
72 // These represent your location relative to your container as a physical offset.
73 // In layout related methods you almost always want the logical location (e.g. x() and y()).
74 LayoutUnit top() const { return topLeftLocation().y(); }
75 LayoutUnit left() const { return topLeftLocation().x(); }
77 void setX(LayoutUnit x) { m_frameRect.setX(x); }
78 void setY(LayoutUnit y) { m_frameRect.setY(y); }
79 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
80 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
82 LayoutUnit logicalLeft() const { return style().isHorizontalWritingMode() ? x() : y(); }
83 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
84 LayoutUnit logicalTop() const { return style().isHorizontalWritingMode() ? y() : x(); }
85 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
86 LayoutUnit logicalWidth() const { return style().isHorizontalWritingMode() ? width() : height(); }
87 LayoutUnit logicalHeight() const { return style().isHorizontalWritingMode() ? height() : width(); }
89 LayoutUnit constrainLogicalWidthInRegionByMinMax(LayoutUnit, LayoutUnit, RenderBlock&, RenderRegion* = nullptr) const;
90 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, Optional<LayoutUnit> intrinsicContentHeight) const;
91 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, Optional<LayoutUnit> intrinsicContentHeight) const;
93 void setLogicalLeft(LayoutUnit left)
95 if (style().isHorizontalWritingMode())
100 void setLogicalTop(LayoutUnit top)
102 if (style().isHorizontalWritingMode())
107 void setLogicalLocation(const LayoutPoint& location)
109 if (style().isHorizontalWritingMode())
110 setLocation(location);
112 setLocation(location.transposedPoint());
114 void setLogicalWidth(LayoutUnit size)
116 if (style().isHorizontalWritingMode())
121 void setLogicalHeight(LayoutUnit size)
123 if (style().isHorizontalWritingMode())
128 void setLogicalSize(const LayoutSize& size)
130 if (style().isHorizontalWritingMode())
133 setSize(size.transposedSize());
136 LayoutPoint location() const { return m_frameRect.location(); }
137 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
138 LayoutSize size() const { return m_frameRect.size(); }
140 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
142 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
143 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
145 LayoutRect frameRect() const { return m_frameRect; }
146 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
148 LayoutRect marginBoxRect() const
150 LayoutRect box = borderBoxRect();
151 box.expand(m_marginBox);
154 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
155 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
156 LayoutRect borderBoundingBox() const final { return borderBoxRect(); }
158 WEBCORE_EXPORT RoundedRect::Radii borderRadii() const;
160 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
161 LayoutRect contentBoxRect() const;
162 // The content box in absolute coords. Ignores transforms.
163 IntRect absoluteContentBox() const;
164 // The content box converted to absolute coords (taking transforms into account).
165 WEBCORE_EXPORT FloatQuad absoluteContentQuad() const;
167 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
168 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
169 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
171 // Bounds of the outline box in absolute coords. Respects transforms
172 LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap*) const final;
173 void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = nullptr) override;
175 FloatRect repaintRectInLocalCoordinates() const override { return borderBoxRect(); }
176 FloatRect objectBoundingBox() const override { return borderBoxRect(); }
178 // Use this with caution! No type checking is done!
179 RenderBox* previousSiblingBox() const;
180 RenderBox* nextSiblingBox() const;
181 RenderBox* parentBox() const;
183 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
184 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
185 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
186 // but it is on the right in vertical-rl.
187 WEBCORE_EXPORT LayoutRect flippedClientBoxRect() const;
188 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : flippedClientBoxRect(); }
189 LayoutUnit logicalLeftLayoutOverflow() const { return style().isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
190 LayoutUnit logicalRightLayoutOverflow() const { return style().isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
192 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
193 LayoutUnit logicalLeftVisualOverflow() const { return style().isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
194 LayoutUnit logicalRightVisualOverflow() const { return style().isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
196 LayoutRect overflowRectForPaintRejection(RenderNamedFlowFragment*) const;
198 void addLayoutOverflow(const LayoutRect&);
199 void addVisualOverflow(const LayoutRect&);
200 void clearOverflow();
202 virtual bool isTopLayoutOverflowAllowed() const { return !style().isLeftToRightDirection() && !isHorizontalWritingMode(); }
203 virtual bool isLeftLayoutOverflowAllowed() const { return !style().isLeftToRightDirection() && isHorizontalWritingMode(); }
205 void addVisualEffectOverflow();
206 LayoutRect applyVisualEffectOverflow(const LayoutRect&) const;
207 void addOverflowFromChild(const RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
208 void addOverflowFromChild(const RenderBox* child, const LayoutSize& delta);
210 void updateLayerTransform();
212 LayoutSize contentSize() const { return { contentWidth(), contentHeight() }; }
213 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
214 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
215 LayoutUnit contentLogicalWidth() const { return style().isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
216 LayoutUnit contentLogicalHeight() const { return style().isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
218 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
219 // to return the remaining width on a given line (and the height of a single line).
220 LayoutUnit offsetWidth() const override { return width(); }
221 LayoutUnit offsetHeight() const override { return height(); }
223 // More IE extensions. clientWidth and clientHeight represent the interior of an object
224 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
225 LayoutUnit clientLeft() const { return borderLeft(); }
226 LayoutUnit clientTop() const { return borderTop(); }
227 WEBCORE_EXPORT LayoutUnit clientWidth() const;
228 WEBCORE_EXPORT LayoutUnit clientHeight() const;
229 LayoutUnit clientLogicalWidth() const { return style().isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
230 LayoutUnit clientLogicalHeight() const { return style().isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
231 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
232 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
234 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
235 // object has overflow:hidden/scroll/auto specified and also has overflow.
236 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
237 // textareas can scroll shadow content (but pretend that they are the objects that are
239 virtual int scrollLeft() const;
240 virtual int scrollTop() const;
241 virtual int scrollWidth() const;
242 virtual int scrollHeight() const;
243 virtual void setScrollLeft(int);
244 virtual void setScrollTop(int);
246 LayoutUnit marginTop() const override { return m_marginBox.top(); }
247 LayoutUnit marginBottom() const override { return m_marginBox.bottom(); }
248 LayoutUnit marginLeft() const override { return m_marginBox.left(); }
249 LayoutUnit marginRight() const override { return m_marginBox.right(); }
250 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
251 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
252 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
253 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
255 LayoutUnit marginLogicalLeft() const { return m_marginBox.start(style().writingMode()); }
256 LayoutUnit marginLogicalRight() const { return m_marginBox.end(style().writingMode()); }
258 LayoutUnit marginBefore(const RenderStyle* overrideStyle = nullptr) const final { return m_marginBox.before((overrideStyle ? overrideStyle : &style())->writingMode()); }
259 LayoutUnit marginAfter(const RenderStyle* overrideStyle = nullptr) const final { return m_marginBox.after((overrideStyle ? overrideStyle : &style())->writingMode()); }
260 LayoutUnit marginStart(const RenderStyle* overrideStyle = nullptr) const final
262 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
263 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
265 LayoutUnit marginEnd(const RenderStyle* overrideStyle = nullptr) const final
267 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
268 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
270 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = nullptr) { m_marginBox.setBefore(value, (overrideStyle ? overrideStyle : &style())->writingMode()); }
271 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = nullptr) { m_marginBox.setAfter(value, (overrideStyle ? overrideStyle : &style())->writingMode()); }
272 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = nullptr)
274 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
275 m_marginBox.setStart(value, styleToUse->writingMode(), styleToUse->direction());
277 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = nullptr)
279 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : &style();
280 m_marginBox.setEnd(value, styleToUse->writingMode(), styleToUse->direction());
283 virtual bool isSelfCollapsingBlock() const { return false; }
284 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
285 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
287 void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const override;
288 void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const override;
290 int reflectionOffset() const;
291 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
292 LayoutRect reflectedRect(const LayoutRect&) const;
294 void layout() override;
295 bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
297 LayoutUnit minPreferredLogicalWidth() const override;
298 LayoutUnit maxPreferredLogicalWidth() const override;
300 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
301 // the border-box height/width like the regular height/width accessors on RenderBox.
302 // Right now, these are different than contentHeight/contentWidth because they still
303 // include the scrollbar height/width.
304 LayoutUnit overrideLogicalContentWidth() const;
305 LayoutUnit overrideLogicalContentHeight() const;
306 bool hasOverrideLogicalContentHeight() const;
307 bool hasOverrideLogicalContentWidth() const;
308 void setOverrideLogicalContentHeight(LayoutUnit);
309 void setOverrideLogicalContentWidth(LayoutUnit);
310 void clearOverrideSize();
311 void clearOverrideLogicalContentHeight();
312 void clearOverrideLogicalContentWidth();
314 #if ENABLE(CSS_GRID_LAYOUT)
315 Optional<LayoutUnit> overrideContainingBlockContentLogicalWidth() const;
316 Optional<LayoutUnit> overrideContainingBlockContentLogicalHeight() const;
317 bool hasOverrideContainingBlockLogicalWidth() const;
318 bool hasOverrideContainingBlockLogicalHeight() const;
319 void setOverrideContainingBlockContentLogicalWidth(Optional<LayoutUnit>);
320 void setOverrideContainingBlockContentLogicalHeight(Optional<LayoutUnit>);
321 void clearContainingBlockOverrideSize();
322 void clearOverrideContainingBlockContentLogicalHeight();
323 LayoutUnit extraInlineOffset() const;
324 LayoutUnit extraBlockOffset() const;
325 void setExtraInlineOffset(LayoutUnit);
326 void setExtraBlockOffset(LayoutUnit);
327 void clearExtraInlineAndBlockOffests();
330 LayoutSize offsetFromContainer(RenderElement&, const LayoutPoint&, bool* offsetDependsOnPoint = nullptr) const override;
332 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
333 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
334 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
335 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(Optional<LayoutUnit> height) const;
337 struct ComputedMarginValues {
338 ComputedMarginValues()
350 struct LogicalExtentComputedValues {
351 LogicalExtentComputedValues()
358 LayoutUnit m_position;
359 ComputedMarginValues m_margins;
361 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
362 // of the containing block.
363 void computeInlineDirectionMargins(const RenderBlock& containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
365 // Used to resolve margins in the containing block's block-flow direction.
366 void computeBlockDirectionMargins(const RenderBlock& containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
367 void computeAndSetBlockDirectionMargins(const RenderBlock& containingBlock);
369 enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
370 LayoutRect borderBoxRectInRegion(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
371 LayoutRect clientBoxRectInRegion(RenderRegion*) const;
372 RenderRegion* clampToStartAndEndRegions(RenderRegion*) const;
373 bool hasRegionRangeInFlowThread() const;
374 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
376 void positionLineBox(InlineElementBox&);
378 virtual std::unique_ptr<InlineElementBox> createInlineBox();
379 void dirtyLineBoxes(bool fullLayout);
381 // For inline replaced elements, this function returns the inline box that owns us. Enables
382 // the replaced RenderObject to quickly determine what line it is contained on and to easily
383 // iterate over structures on the line.
384 InlineElementBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
385 void setInlineBoxWrapper(InlineElementBox*);
386 void deleteLineBoxWrapper();
388 LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const override;
389 LayoutRect computeRectForRepaint(const LayoutRect&, const RenderLayerModelObject* repaintContainer, RepaintContext context = { false, false }) const override;
390 void repaintDuringLayoutIfMoved(const LayoutRect&);
391 virtual void repaintOverhangingFloats(bool paintAllDescendants);
393 LayoutUnit containingBlockLogicalWidthForContent() const override;
394 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
396 LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*) const;
397 LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*) const;
398 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
400 virtual void updateLogicalWidth();
401 virtual void updateLogicalHeight();
402 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
404 RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
405 void computeLogicalWidthInRegion(LogicalExtentComputedValues&, RenderRegion* = nullptr) const;
407 bool stretchesToViewport() const
409 return document().inQuirksMode() && style().logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElementRenderer() || isBody()) && !isInline();
412 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
413 LayoutUnit intrinsicLogicalWidth() const { return style().isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
414 LayoutUnit intrinsicLogicalHeight() const { return style().isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
416 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
417 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
418 bool sizesLogicalWidthToFitContent(SizeType) const;
420 bool hasStretchedLogicalWidth() const;
422 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock& cb, RenderRegion*) const;
424 LayoutUnit computeLogicalWidthInRegionUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock& containingBlock, RenderRegion*) const;
425 Optional<LayoutUnit> computeLogicalHeightUsing(SizeType, const Length& height, Optional<LayoutUnit> intrinsicContentHeight) const;
426 Optional<LayoutUnit> computeContentLogicalHeight(SizeType, const Length& height, Optional<LayoutUnit> intrinsicContentHeight) const;
427 Optional<LayoutUnit> computeContentAndScrollbarLogicalHeightUsing(SizeType, const Length& height, Optional<LayoutUnit> intrinsicContentHeight) const;
428 LayoutUnit computeReplacedLogicalWidthUsing(SizeType, Length width) const;
429 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
430 LayoutUnit computeReplacedLogicalHeightUsing(SizeType, Length height) const;
431 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
433 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
434 virtual LayoutUnit computeReplacedLogicalHeight() const;
436 bool hasDefiniteLogicalWidth() const;
437 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock& containingBlock, bool outOfFlowPositioned, bool scrollsOverflowY);
438 bool hasDefiniteLogicalHeight() const;
439 Optional<LayoutUnit> computePercentageLogicalHeight(const Length& height) const;
441 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
442 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
443 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
445 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
446 // Relative positioning is one of those cases, since left/top offsets are physical.
447 LayoutUnit availableWidth() const { return style().isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
448 LayoutUnit availableHeight() const { return style().isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
450 virtual int verticalScrollbarWidth() const;
451 int horizontalScrollbarHeight() const;
452 int intrinsicScrollbarLogicalWidth() const;
453 int scrollbarLogicalWidth() const { return style().isHorizontalWritingMode() ? verticalScrollbarWidth() : horizontalScrollbarHeight(); }
454 int scrollbarLogicalHeight() const { return style().isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
455 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint());
456 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr);
457 WEBCORE_EXPORT bool canBeScrolledAndHasScrollableArea() const;
458 virtual bool canBeProgramaticallyScrolled() const;
459 virtual void autoscroll(const IntPoint&);
460 bool canAutoscroll() const;
461 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
462 static RenderBox* findAutoscrollable(RenderObject*);
463 virtual void stopAutoscroll() { }
464 virtual void panScroll(const IntPoint&);
466 bool hasVerticalScrollbarWithAutoBehavior() const;
467 bool hasHorizontalScrollbarWithAutoBehavior() const;
469 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
470 bool scrollsOverflowX() const { return hasOverflowClip() && (style().overflowX() == OSCROLL || hasHorizontalScrollbarWithAutoBehavior()); }
471 bool scrollsOverflowY() const { return hasOverflowClip() && (style().overflowY() == OSCROLL || hasVerticalScrollbarWithAutoBehavior()); }
473 bool hasHorizontalOverflow() const { return scrollWidth() != roundToInt(clientWidth()); }
474 bool hasVerticalOverflow() const { return scrollHeight() != roundToInt(clientHeight()); }
476 bool hasScrollableOverflowX() const { return scrollsOverflowX() && hasHorizontalOverflow(); }
477 bool hasScrollableOverflowY() const { return scrollsOverflowY() && hasVerticalOverflow(); }
479 bool usesCompositedScrolling() const;
481 bool hasUnsplittableScrollingOverflow() const;
482 bool isUnsplittableForPagination() const;
484 LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr) override;
486 virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, PaintPhase = PaintPhaseBlockBackground);
487 virtual LayoutRect overflowClipRectForChildLayers(const LayoutPoint& location, RenderRegion* region, OverlayScrollbarSizeRelevancy relevancy) { return overflowClipRect(location, region, relevancy); }
488 LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
489 virtual bool hasControlClip() const { return false; }
490 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
491 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset);
492 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
494 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
495 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
496 virtual void paintMask(PaintInfo&, const LayoutPoint&);
497 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
498 void imageChanged(WrappedImagePtr, const IntRect* = nullptr) override;
500 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
501 // that just updates the object's position. If the size does change, the object remains dirty.
502 bool tryLayoutDoingPositionedMovementOnly()
504 LayoutUnit oldWidth = width();
505 updateLogicalWidth();
506 // If we shrink to fit our width may have changed, so we still need full layout.
507 if (oldWidth != width())
509 updateLogicalHeight();
513 LayoutRect maskClipRect(const LayoutPoint& paintOffset);
515 VisiblePosition positionForPoint(const LayoutPoint&, const RenderRegion*) override;
517 void removeFloatingOrPositionedChildFromBlockLists();
519 RenderLayer* enclosingFloatPaintingLayer() const;
521 virtual Optional<int> firstLineBaseline() const { return Optional<int>(); }
522 virtual Optional<int> inlineBlockBaseline(LineDirectionMode) const { return Optional<int>(); } // Returns empty if we should skip this box when computing the baseline of an inline-block.
524 bool shrinkToAvoidFloats() const;
525 virtual bool avoidsFloats() const;
527 virtual void markForPaginationRelayoutIfNeeded() { }
529 bool isWritingModeRoot() const { return !parent() || parent()->style().writingMode() != style().writingMode(); }
531 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
532 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
534 LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
535 int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;
537 LayoutUnit offsetLeft() const override;
538 LayoutUnit offsetTop() const override;
540 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
541 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
542 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
543 LayoutSize flipForWritingMode(const LayoutSize&) const;
544 void flipForWritingMode(LayoutRect&) const;
545 FloatPoint flipForWritingMode(const FloatPoint&) const;
546 void flipForWritingMode(FloatRect&) const;
547 // These represent your location relative to your container as a physical offset.
548 // In layout related methods you almost always want the logical location (e.g. x() and y()).
549 LayoutPoint topLeftLocation() const;
550 LayoutSize topLeftLocationOffset() const;
551 void applyTopLeftLocationOffset(LayoutPoint& point) const
553 // This is inlined for speed, since it is used by updateLayerPosition() during scrolling.
554 if (!document().view()->hasFlippedBlockRenderers())
555 point.move(m_frameRect.x(), m_frameRect.y());
557 applyTopLeftLocationOffsetWithFlipping(point);
560 LayoutRect logicalVisualOverflowRectForPropagation(const RenderStyle*) const;
561 LayoutRect visualOverflowRectForPropagation(const RenderStyle*) const;
562 LayoutRect logicalLayoutOverflowRectForPropagation(const RenderStyle*) const;
563 LayoutRect layoutOverflowRectForPropagation(const RenderStyle*) const;
565 bool hasRenderOverflow() const { return m_overflow; }
566 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
568 virtual bool needsPreferredWidthsRecalculation() const;
569 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
571 ScrollPosition scrollPosition() const;
572 LayoutSize cachedSizeForOverflowClip() const;
574 bool shouldApplyClipAndScrollPositionForRepaint(const RenderLayerModelObject* repaintContainer) const;
575 void applyCachedClipAndScrollPositionForRepaint(LayoutRect& paintRect) const;
577 virtual bool hasRelativeDimensions() const;
578 virtual bool hasRelativeLogicalHeight() const;
579 virtual bool hasRelativeLogicalWidth() const;
581 bool hasHorizontalLayoutOverflow() const
586 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
587 flipForWritingMode(layoutOverflowRect);
588 return layoutOverflowRect.x() < x() || layoutOverflowRect.maxX() > x() + logicalWidth();
591 bool hasVerticalLayoutOverflow() const
596 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
597 flipForWritingMode(layoutOverflowRect);
598 return layoutOverflowRect.y() < y() || layoutOverflowRect.maxY() > y() + logicalHeight();
601 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
603 ASSERT_NOT_REACHED();
607 bool hasSameDirectionAs(const RenderBox* object) const { return style().direction() == object->style().direction(); }
609 #if ENABLE(CSS_SHAPES)
610 ShapeOutsideInfo* shapeOutsideInfo() const
612 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : nullptr;
615 void markShapeOutsideDependentsForLayout()
618 removeFloatingOrPositionedChildFromBlockLists();
622 // True if this box can have a range in an outside fragmentation context.
623 bool canHaveOutsideRegionRange() const { return !isInFlowRenderFlowThread(); }
624 virtual bool needsLayoutAfterRegionRangeChange() const { return false; }
626 const RenderBox* findEnclosingScrollableContainer() const;
629 RenderBox(Element&, RenderStyle&&, BaseTypeFlags);
630 RenderBox(Document&, RenderStyle&&, BaseTypeFlags);
632 void styleWillChange(StyleDifference, const RenderStyle& newStyle) override;
633 void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
634 void updateFromStyle() override;
636 void willBeRemovedFromTree() override;
638 bool createsNewFormattingContext() const;
640 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
641 bool getBackgroundPaintedExtent(const LayoutPoint& paintOffset, LayoutRect&) const;
642 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
643 bool computeBackgroundIsKnownToBeObscured(const LayoutPoint& paintOffset) override;
645 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
647 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderElement* backgroundObject, BaseBackgroundColorUsage = BaseBackgroundColorUse);
648 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderElement* backgroundObject = nullptr);
650 void paintMaskImages(const PaintInfo&, const LayoutRect&);
652 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext&) const;
653 bool backgroundHasOpaqueTopLayer() const;
655 void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderRegion* = nullptr) const;
657 LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
658 virtual Optional<LayoutUnit> computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, Optional<LayoutUnit> intrinsicContentHeight, LayoutUnit borderAndPadding) const;
660 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
662 void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags, bool* wasFixed) const override;
663 const RenderObject* pushMappingToContainer(const RenderLayerModelObject*, RenderGeometryMap&) const override;
664 void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
666 void paintRootBoxFillLayers(const PaintInfo&);
668 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
671 #if ENABLE(CSS_SHAPES)
672 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
675 #if ENABLE(CSS_GRID_LAYOUT)
676 bool isGridItem() const { return parent() && parent()->isRenderGrid(); }
679 bool scrollLayer(ScrollDirection, ScrollGranularity, float multiplier, Element** stopElement);
681 bool fixedElementLaysOutRelativeToFrame(const FrameView&) const;
683 bool includeVerticalScrollbarSize() const;
684 bool includeHorizontalScrollbarSize() const;
686 bool isScrollableOrRubberbandableBox() const override;
688 // Returns true if we did a full repaint
689 bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
691 bool skipContainingBlockForPercentHeightCalculation(const RenderBox& containingBlock, bool isPerpendicularWritingMode) const;
693 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject& containingBlock, RenderRegion* = nullptr, bool checkForPerpendicularWritingMode = true) const;
694 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject& containingBlock, bool checkForPerpendicularWritingMode = true) const;
696 LayoutUnit viewLogicalHeightForPercentages() const;
698 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
699 void computePositionedLogicalWidthUsing(SizeType, Length logicalWidth, const RenderBoxModelObject& containerBlock, TextDirection containerDirection,
700 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
701 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
702 LogicalExtentComputedValues&) const;
703 void computePositionedLogicalHeightUsing(SizeType, Length logicalHeightLength, const RenderBoxModelObject& containerBlock,
704 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
705 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
706 LogicalExtentComputedValues&) const;
708 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
709 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
711 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
712 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
714 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
716 // This function calculates the minimum and maximum preferred widths for an object.
717 // These values are used in shrink-to-fit layout systems.
718 // These include tables, positioned objects, floats and flexible boxes.
719 virtual void computePreferredLogicalWidths() { setPreferredLogicalWidthsDirty(false); }
721 LayoutRect frameRectForStickyPositioning() const final { return frameRect(); }
723 void applyTopLeftLocationOffsetWithFlipping(LayoutPoint&) const;
726 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
727 LayoutRect m_frameRect;
730 LayoutBoxExtent m_marginBox;
732 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
733 LayoutUnit m_minPreferredLogicalWidth;
735 // The preferred logical width of the element if it never breaks any lines at all.
736 LayoutUnit m_maxPreferredLogicalWidth;
738 // For inline replaced elements, the inline box that owns us.
739 InlineElementBox* m_inlineBoxWrapper;
741 // Our overflow information.
742 RefPtr<RenderOverflow> m_overflow;
745 // Used to store state between styleWillChange and styleDidChange
746 static bool s_hadOverflowClip;
749 inline RenderBox* RenderBox::previousSiblingBox() const
751 return downcast<RenderBox>(previousSibling());
754 inline RenderBox* RenderBox::nextSiblingBox() const
756 return downcast<RenderBox>(nextSibling());
759 inline RenderBox* RenderBox::parentBox() const
761 return downcast<RenderBox>(parent());
764 inline RenderBox* RenderBox::firstChildBox() const
766 return downcast<RenderBox>(firstChild());
769 inline RenderBox* RenderBox::lastChildBox() const
771 return downcast<RenderBox>(lastChild());
774 inline void RenderBox::setInlineBoxWrapper(InlineElementBox* boxWrapper)
777 ASSERT(!m_inlineBoxWrapper);
778 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
779 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
780 // only one will be notified when the renderer is getting destroyed. The second line box wrapper
781 // will keep a stale reference.
782 if (UNLIKELY(m_inlineBoxWrapper != nullptr))
783 deleteLineBoxWrapper();
786 m_inlineBoxWrapper = boxWrapper;
789 } // namespace WebCore
791 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderBox, isBox())
793 #endif // RenderBox_h