2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "RenderBoxModelObject.h"
27 #include "RenderOverflow.h"
28 #include "ScrollTypes.h"
29 #if ENABLE(CSS_SHAPES)
30 #include "ShapeOutsideInfo.h"
35 class RenderBlockFlow;
36 class RenderBoxRegionInfo;
40 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
41 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
42 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
44 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
46 class RenderBox : public RenderBoxModelObject {
48 explicit RenderBox(Element*, unsigned baseTypeFlags);
51 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
52 // position:static elements that are not flex-items get their z-index coerced to auto.
53 virtual bool requiresLayer() const OVERRIDE
55 return isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasOverflowClip()
56 || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns()
57 || !style()->hasAutoZIndex();
60 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE FINAL;
62 // Use this with caution! No type checking is done!
63 RenderBox* firstChildBox() const;
64 RenderBox* lastChildBox() const;
66 LayoutUnit x() const { return m_frameRect.x(); }
67 LayoutUnit y() const { return m_frameRect.y(); }
68 LayoutUnit width() const { return m_frameRect.width(); }
69 LayoutUnit height() const { return m_frameRect.height(); }
71 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
72 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
74 // These represent your location relative to your container as a physical offset.
75 // In layout related methods you almost always want the logical location (e.g. x() and y()).
76 LayoutUnit top() const { return topLeftLocation().y(); }
77 LayoutUnit left() const { return topLeftLocation().x(); }
79 void setX(LayoutUnit x) { m_frameRect.setX(x); }
80 void setY(LayoutUnit y) { m_frameRect.setY(y); }
81 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
82 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
84 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
85 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
86 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
87 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
88 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
89 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
91 LayoutUnit constrainLogicalWidthInRegionByMinMax(LayoutUnit, LayoutUnit, RenderBlock*, RenderRegion* = 0) const;
92 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit) const;
93 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit) const;
95 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
96 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
98 void setLogicalLeft(LayoutUnit left)
100 if (style()->isHorizontalWritingMode())
105 void setLogicalTop(LayoutUnit top)
107 if (style()->isHorizontalWritingMode())
112 void setLogicalLocation(const LayoutPoint& location)
114 if (style()->isHorizontalWritingMode())
115 setLocation(location);
117 setLocation(location.transposedPoint());
119 void setLogicalWidth(LayoutUnit size)
121 if (style()->isHorizontalWritingMode())
126 void setLogicalHeight(LayoutUnit size)
128 if (style()->isHorizontalWritingMode())
133 void setLogicalSize(const LayoutSize& size)
135 if (style()->isHorizontalWritingMode())
138 setSize(size.transposedSize());
141 LayoutPoint location() const { return m_frameRect.location(); }
142 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
143 LayoutSize size() const { return m_frameRect.size(); }
144 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
146 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
148 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
149 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
151 LayoutRect frameRect() const { return m_frameRect; }
152 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
153 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
155 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
156 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
157 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
158 virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
160 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
161 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
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 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 virtual LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap*) const OVERRIDE FINAL;
173 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
175 // Use this with caution! No type checking is done!
176 RenderBox* previousSiblingBox() const;
177 RenderBox* nextSiblingBox() const;
178 RenderBox* parentBox() const;
180 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
181 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
182 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
183 // but it is on the right in vertical-rl.
184 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : clientBoxRect(); }
185 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
186 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
188 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
189 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
190 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
192 LayoutRect overflowRectForPaintRejection() const;
194 void addLayoutOverflow(const LayoutRect&);
195 void addVisualOverflow(const LayoutRect&);
196 void clearOverflow();
198 void addVisualEffectOverflow();
199 LayoutRect applyVisualEffectOverflow(const LayoutRect&) const;
200 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
201 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
203 void updateLayerTransform();
205 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
206 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
207 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
208 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
210 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
211 // to return the remaining width on a given line (and the height of a single line).
212 virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); }
213 virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); }
215 virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
216 virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
218 // More IE extensions. clientWidth and clientHeight represent the interior of an object
219 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
220 LayoutUnit clientLeft() const { return borderLeft(); }
221 LayoutUnit clientTop() const { return borderTop(); }
222 LayoutUnit clientWidth() const;
223 LayoutUnit clientHeight() const;
224 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
225 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
226 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
227 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
229 int pixelSnappedClientWidth() const;
230 int pixelSnappedClientHeight() const;
232 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
233 // object has overflow:hidden/scroll/auto specified and also has overflow.
234 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
235 // textareas can scroll shadow content (but pretend that they are the objects that are
237 virtual int scrollLeft() const;
238 virtual int scrollTop() const;
239 virtual int scrollWidth() const;
240 virtual int scrollHeight() const;
241 virtual void setScrollLeft(int);
242 virtual void setScrollTop(int);
244 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
245 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
246 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
247 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
248 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
249 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
250 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
251 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
253 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
254 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
256 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
257 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
258 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
260 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
261 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
263 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
265 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
266 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
268 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
269 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
270 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
272 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
273 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
275 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
277 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
278 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
281 // The following five functions are used to implement collapsing margins.
282 // All objects know their maximal positive and negative margins. The
283 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
284 // For a non-collapsing box, such as a leaf element, this formula will simply return
285 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
287 enum MarginSign { PositiveMargin, NegativeMargin };
288 virtual bool isSelfCollapsingBlock() const { return false; }
289 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
290 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
292 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
293 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
295 LayoutRect reflectionBox() const;
296 int reflectionOffset() const;
297 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
298 LayoutRect reflectedRect(const LayoutRect&) const;
300 virtual void layout() OVERRIDE;
301 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
303 virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
304 virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
306 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
307 // the border-box height/width like the regular height/width accessors on RenderBox.
308 // Right now, these are different than contentHeight/contentWidth because they still
309 // include the scrollbar height/width.
310 LayoutUnit overrideLogicalContentWidth() const;
311 LayoutUnit overrideLogicalContentHeight() const;
312 bool hasOverrideHeight() const;
313 bool hasOverrideWidth() const;
314 void setOverrideLogicalContentHeight(LayoutUnit);
315 void setOverrideLogicalContentWidth(LayoutUnit);
316 void clearOverrideSize();
317 void clearOverrideLogicalContentHeight();
318 void clearOverrideLogicalContentWidth();
320 LayoutUnit overrideContainingBlockContentLogicalWidth() const;
321 LayoutUnit overrideContainingBlockContentLogicalHeight() const;
322 bool hasOverrideContainingBlockLogicalWidth() const;
323 bool hasOverrideContainingBlockLogicalHeight() const;
324 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
325 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
326 void clearContainingBlockOverrideSize();
327 void clearOverrideContainingBlockContentLogicalHeight();
329 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
331 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
332 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
333 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
334 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
336 struct ComputedMarginValues {
337 ComputedMarginValues()
349 struct LogicalExtentComputedValues {
350 LogicalExtentComputedValues()
357 LayoutUnit m_position;
358 ComputedMarginValues m_margins;
360 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
361 // of the containing block.
362 void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
364 // Used to resolve margins in the containing block's block-flow direction.
365 void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
366 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
368 enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
369 LayoutRect borderBoxRectInRegion(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
370 LayoutRect clientBoxRectInRegion(RenderRegion*) const;
371 RenderRegion* clampToStartAndEndRegions(RenderRegion*) const;
372 void clearRenderBoxRegionInfo();
373 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
375 void positionLineBox(InlineBox*);
377 virtual InlineBox* createInlineBox();
378 void dirtyLineBoxes(bool fullLayout);
380 // For inline replaced elements, this function returns the inline box that owns us. Enables
381 // the replaced RenderObject to quickly determine what line it is contained on and to easily
382 // iterate over structures on the line.
383 InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
384 void setInlineBoxWrapper(InlineBox* boxWrapper) { m_inlineBoxWrapper = boxWrapper; }
385 void deleteLineBoxWrapper();
387 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
388 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
389 void repaintDuringLayoutIfMoved(const LayoutRect&);
390 virtual void repaintOverhangingFloats(bool paintAllDescendants);
392 virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
393 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
395 LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*) const;
396 LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*) const;
397 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
399 virtual void updateLogicalWidth();
400 virtual void updateLogicalHeight();
401 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
403 RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
404 void computeLogicalWidthInRegion(LogicalExtentComputedValues&, RenderRegion* = 0) const;
406 bool stretchesToViewport() const
408 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !document().shouldDisplaySeamlesslyWithParent() && !isInline();
411 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
412 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
413 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
415 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
416 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
417 bool sizesLogicalWidthToFitContent(SizeType) const;
419 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock* cb, RenderRegion*) const;
421 LayoutUnit computeLogicalWidthInRegionUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock, RenderRegion*) const;
422 LayoutUnit computeLogicalHeightUsing(const Length& height) const;
423 LayoutUnit computeContentLogicalHeight(const Length& height) const;
424 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height) const;
425 LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
426 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
427 LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
428 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
430 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
431 virtual LayoutUnit computeReplacedLogicalHeight() const;
433 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
434 LayoutUnit computePercentageLogicalHeight(const Length& height) const;
436 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
437 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
438 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
439 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
441 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
442 // Relative positioning is one of those cases, since left/top offsets are physical.
443 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
444 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
446 virtual int verticalScrollbarWidth() const;
447 int horizontalScrollbarHeight() const;
448 int instrinsicScrollbarLogicalWidth() const;
449 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
450 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0);
451 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0);
452 bool canBeScrolledAndHasScrollableArea() const;
453 virtual bool canBeProgramaticallyScrolled() const;
454 virtual void autoscroll(const IntPoint&);
455 bool canAutoscroll() const;
456 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
457 static RenderBox* findAutoscrollable(RenderObject*);
458 virtual void stopAutoscroll() { }
459 virtual void panScroll(const IntPoint&);
461 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
462 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
463 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
464 bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
465 bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
466 bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
467 bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
469 bool usesCompositedScrolling() const;
471 bool hasUnsplittableScrollingOverflow() const;
472 bool isUnsplittableForPagination() const;
474 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
476 virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, PaintPhase = PaintPhaseBlockBackground);
477 virtual LayoutRect overflowClipRectForChildLayers(const LayoutPoint& location, RenderRegion* region, OverlayScrollbarSizeRelevancy relevancy) { return overflowClipRect(location, region, relevancy); }
478 LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
479 virtual bool hasControlClip() const { return false; }
480 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
481 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset);
482 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
484 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
485 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
486 virtual void paintMask(PaintInfo&, const LayoutPoint&);
487 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
489 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
490 // that just updates the object's position. If the size does change, the object remains dirty.
491 bool tryLayoutDoingPositionedMovementOnly()
493 LayoutUnit oldWidth = width();
494 updateLogicalWidth();
495 // If we shrink to fit our width may have changed, so we still need full layout.
496 if (oldWidth != width())
498 updateLogicalHeight();
502 LayoutRect maskClipRect();
504 virtual VisiblePosition positionForPoint(const LayoutPoint&) OVERRIDE;
506 RenderBlockFlow* outermostBlockContainingFloatingObject();
508 void removeFloatingOrPositionedChildFromBlockLists();
510 RenderLayer* enclosingFloatPaintingLayer() const;
512 virtual int firstLineBoxBaseline() const { return -1; }
513 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
515 bool shrinkToAvoidFloats() const;
516 virtual bool avoidsFloats() const;
518 virtual void markForPaginationRelayoutIfNeeded() { }
520 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
522 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
523 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
525 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
526 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
528 virtual LayoutUnit offsetLeft() const OVERRIDE;
529 virtual LayoutUnit offsetTop() const OVERRIDE;
531 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
532 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
533 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
534 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
535 LayoutSize flipForWritingMode(const LayoutSize&) const;
536 void flipForWritingMode(LayoutRect&) const;
537 FloatPoint flipForWritingMode(const FloatPoint&) const;
538 void flipForWritingMode(FloatRect&) const;
539 // These represent your location relative to your container as a physical offset.
540 // In layout related methods you almost always want the logical location (e.g. x() and y()).
541 LayoutPoint topLeftLocation() const;
542 LayoutSize topLeftLocationOffset() const;
544 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
545 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
546 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
547 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
549 bool hasRenderOverflow() const { return m_overflow; }
550 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
552 virtual bool needsPreferredWidthsRecalculation() const;
553 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
555 IntSize scrolledContentOffset() const;
556 LayoutSize cachedSizeForOverflowClip() const;
557 void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
559 virtual bool hasRelativeDimensions() const;
560 virtual bool hasRelativeLogicalHeight() const;
561 bool hasViewportPercentageLogicalHeight() const;
563 bool hasHorizontalLayoutOverflow() const
568 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
569 flipForWritingMode(layoutOverflowRect);
570 return layoutOverflowRect.x() < x() || layoutOverflowRect.maxX() > x() + logicalWidth();
573 bool hasVerticalLayoutOverflow() const
578 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
579 flipForWritingMode(layoutOverflowRect);
580 return layoutOverflowRect.y() < y() || layoutOverflowRect.maxY() > y() + logicalHeight();
583 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
585 ASSERT_NOT_REACHED();
589 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
591 #if ENABLE(CSS_SHAPES)
592 ShapeOutsideInfo* shapeOutsideInfo() const
594 return ShapeOutsideInfo::isEnabledFor(this) ? ShapeOutsideInfo::info(this) : 0;
597 void markShapeOutsideDependentsForLayout()
600 removeFloatingOrPositionedChildFromBlockLists();
605 virtual void willBeDestroyed() OVERRIDE;
607 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle) OVERRIDE;
608 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
609 virtual void updateFromStyle() OVERRIDE;
611 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
612 bool getBackgroundPaintedExtent(LayoutRect&) const;
613 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
614 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
616 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
618 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderElement* backgroundObject);
619 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderElement* backgroundObject = nullptr);
621 void paintMaskImages(const PaintInfo&, const LayoutRect&);
623 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
624 bool backgroundHasOpaqueTopLayer() const;
627 void paintCustomHighlight(const LayoutPoint&, const AtomicString& type, bool behindText);
630 void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderRegion* = 0) const;
632 LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
634 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
636 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
637 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject*, RenderGeometryMap&) const OVERRIDE;
638 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
640 void paintRootBoxFillLayers(const PaintInfo&);
642 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
645 #if ENABLE(CSS_SHAPES)
646 void updateShapeOutsideInfoAfterStyleChange(const ShapeValue* shapeOutside, const ShapeValue* oldShapeOutside);
649 bool fixedElementLaysOutRelativeToFrame(const FrameView&) const;
651 bool includeVerticalScrollbarSize() const;
652 bool includeHorizontalScrollbarSize() const;
654 // Returns true if we did a full repaint
655 bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
657 bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
659 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* = 0, bool checkForPerpendicularWritingMode = true) const;
660 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
662 LayoutUnit viewLogicalHeightForPercentages() const;
664 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
665 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
666 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
667 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
668 LogicalExtentComputedValues&) const;
669 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
670 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
671 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
672 LogicalExtentComputedValues&) const;
674 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
675 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
677 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
678 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
680 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
682 // This function calculates the minimum and maximum preferred widths for an object.
683 // These values are used in shrink-to-fit layout systems.
684 // These include tables, positioned objects, floats and flexible boxes.
685 virtual void computePreferredLogicalWidths() { setPreferredLogicalWidthsDirty(false); }
687 virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
690 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
691 LayoutRect m_frameRect;
694 LayoutBoxExtent m_marginBox;
696 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
697 LayoutUnit m_minPreferredLogicalWidth;
699 // The preferred logical width of the element if it never breaks any lines at all.
700 LayoutUnit m_maxPreferredLogicalWidth;
702 // For inline replaced elements, the inline box that owns us.
703 InlineBox* m_inlineBoxWrapper;
705 // Our overflow information.
706 OwnPtr<RenderOverflow> m_overflow;
709 // Used to store state between styleWillChange and styleDidChange
710 static bool s_hadOverflowClip;
713 inline RenderBox& toRenderBox(RenderObject& object)
715 ASSERT_WITH_SECURITY_IMPLICATION(object.isBox());
716 return static_cast<RenderBox&>(object);
719 inline const RenderBox& toRenderBox(const RenderObject& object)
721 ASSERT_WITH_SECURITY_IMPLICATION(object.isBox());
722 return static_cast<const RenderBox&>(object);
725 inline RenderBox* toRenderBox(RenderObject* object)
727 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isBox());
728 return static_cast<RenderBox*>(object);
731 inline const RenderBox* toRenderBox(const RenderObject* object)
733 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isBox());
734 return static_cast<const RenderBox*>(object);
737 // This will catch anyone doing an unnecessary cast.
738 void toRenderBox(const RenderBox*);
739 void toRenderBox(const RenderBox&);
741 inline RenderBox* RenderBox::previousSiblingBox() const
743 return toRenderBox(previousSibling());
746 inline RenderBox* RenderBox::nextSiblingBox() const
748 return toRenderBox(nextSibling());
751 inline RenderBox* RenderBox::parentBox() const
753 return toRenderBox(parent());
756 inline RenderBox* RenderBox::firstChildBox() const
758 return toRenderBox(firstChild());
761 inline RenderBox* RenderBox::lastChildBox() const
763 return toRenderBox(lastChild());
766 } // namespace WebCore
768 #endif // RenderBox_h