2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "core/rendering/RenderBoxModelObject.h"
27 #include "core/rendering/RenderOverflow.h"
28 #include "core/rendering/shapes/ShapeOutsideInfo.h"
29 #include "platform/scroll/ScrollTypes.h"
33 class RenderBoxRegionInfo;
37 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
38 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
39 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
41 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
43 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
45 enum ScrollOffsetClamping {
46 ScrollOffsetUnclamped,
50 class RenderBox : public RenderBoxModelObject {
52 explicit RenderBox(ContainerNode*);
55 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
56 // position:static elements that are not flex-items get their z-index coerced to auto.
57 virtual bool requiresLayer() const OVERRIDE { return isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasOverflowClip() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex(); }
59 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
61 // Use this with caution! No type checking is done!
62 RenderBox* firstChildBox() const;
63 RenderBox* lastChildBox() const;
65 LayoutUnit x() const { return m_frameRect.x(); }
66 LayoutUnit y() const { return m_frameRect.y(); }
67 LayoutUnit width() const { return m_frameRect.width(); }
68 LayoutUnit height() const { return m_frameRect.height(); }
70 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
71 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
73 // These represent your location relative to your container as a physical offset.
74 // In layout related methods you almost always want the logical location (e.g. x() and y()).
75 LayoutUnit top() const { return topLeftLocation().y(); }
76 LayoutUnit left() const { return topLeftLocation().x(); }
78 void setX(LayoutUnit x) { m_frameRect.setX(x); }
79 void setY(LayoutUnit y) { m_frameRect.setY(y); }
80 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
81 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
83 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
84 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
85 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
86 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
87 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
88 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
90 LayoutUnit constrainLogicalWidthInRegionByMinMax(LayoutUnit, LayoutUnit, RenderBlock*, RenderRegion* = 0) const;
91 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
92 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
94 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
95 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
97 void setLogicalLeft(LayoutUnit left)
99 if (style()->isHorizontalWritingMode())
104 void setLogicalTop(LayoutUnit top)
106 if (style()->isHorizontalWritingMode())
111 void setLogicalLocation(const LayoutPoint& location)
113 if (style()->isHorizontalWritingMode())
114 setLocation(location);
116 setLocation(location.transposedPoint());
118 void setLogicalWidth(LayoutUnit size)
120 if (style()->isHorizontalWritingMode())
125 void setLogicalHeight(LayoutUnit size)
127 if (style()->isHorizontalWritingMode())
132 void setLogicalSize(const LayoutSize& size)
134 if (style()->isHorizontalWritingMode())
137 setSize(size.transposedSize());
140 LayoutPoint location() const { return m_frameRect.location(); }
141 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
142 LayoutSize size() const { return m_frameRect.size(); }
143 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
145 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
147 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
148 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
150 LayoutRect frameRect() const { return m_frameRect; }
151 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
152 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
154 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
155 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
156 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
157 virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
159 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
160 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
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 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 virtual LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap*) const OVERRIDE FINAL;
172 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
174 // Use this with caution! No type checking is done!
175 RenderBox* previousSiblingBox() const;
176 RenderBox* nextSiblingBox() const;
177 RenderBox* parentBox() const;
179 bool canResize() const;
181 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
182 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
183 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
184 // but it is on the right in vertical-rl.
185 LayoutRect noOverflowRect() const;
186 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
187 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
188 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
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() const;
198 LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
200 void addLayoutOverflow(const LayoutRect&);
201 void addVisualOverflow(const LayoutRect&);
203 // Clipped by the contents clip, if one exists.
204 void addContentsVisualOverflow(const LayoutRect&);
206 void addVisualEffectOverflow();
207 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
208 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
209 void clearLayoutOverflow();
211 void updateLayerTransform();
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 virtual LayoutUnit offsetWidth() const { return width(); }
221 virtual LayoutUnit offsetHeight() const { return height(); }
223 virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
224 virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
226 bool canDetermineWidthWithoutLayout() const;
227 LayoutUnit fixedOffsetWidth() const;
229 // More IE extensions. clientWidth and clientHeight represent the interior of an object
230 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
231 LayoutUnit clientLeft() const { return borderLeft(); }
232 LayoutUnit clientTop() const { return borderTop(); }
233 LayoutUnit clientWidth() const;
234 LayoutUnit clientHeight() const;
235 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
236 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
237 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
238 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
240 int pixelSnappedClientWidth() const;
241 int pixelSnappedClientHeight() const;
243 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
244 // object has overflow:hidden/scroll/auto specified and also has overflow.
245 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
246 // textareas can scroll shadow content (but pretend that they are the objects that are
248 virtual int scrollLeft() const;
249 virtual int scrollTop() const;
250 virtual int scrollWidth() const;
251 virtual int scrollHeight() const;
252 virtual void setScrollLeft(int);
253 virtual void setScrollTop(int);
255 void scrollToOffset(const IntSize&);
256 void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
257 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
259 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
260 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
261 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
262 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
263 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
264 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
265 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
266 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
268 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
269 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
271 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
272 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
273 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
275 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
276 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
278 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
280 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
281 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
283 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
284 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
285 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
287 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
288 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
290 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
292 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
293 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
296 // The following five functions are used to implement collapsing margins.
297 // All objects know their maximal positive and negative margins. The
298 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
299 // For a non-collapsing box, such as a leaf element, this formula will simply return
300 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
302 enum MarginSign { PositiveMargin, NegativeMargin };
303 virtual bool isSelfCollapsingBlock() const { return false; }
304 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
305 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
307 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
308 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
310 LayoutRect reflectionBox() const;
311 int reflectionOffset() const;
312 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
313 LayoutRect reflectedRect(const LayoutRect&) const;
315 virtual void layout();
316 virtual void paint(PaintInfo&, const LayoutPoint&);
317 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
319 virtual LayoutUnit minPreferredLogicalWidth() const;
320 virtual LayoutUnit maxPreferredLogicalWidth() const;
322 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
323 // the border-box height/width like the regular height/width accessors on RenderBox.
324 // Right now, these are different than contentHeight/contentWidth because they still
325 // include the scrollbar height/width.
326 LayoutUnit overrideLogicalContentWidth() const;
327 LayoutUnit overrideLogicalContentHeight() const;
328 bool hasOverrideHeight() const;
329 bool hasOverrideWidth() const;
330 void setOverrideLogicalContentHeight(LayoutUnit);
331 void setOverrideLogicalContentWidth(LayoutUnit);
332 void clearOverrideSize();
333 void clearOverrideLogicalContentHeight();
334 void clearOverrideLogicalContentWidth();
336 LayoutUnit overrideContainingBlockContentLogicalWidth() const;
337 LayoutUnit overrideContainingBlockContentLogicalHeight() const;
338 bool hasOverrideContainingBlockLogicalWidth() const;
339 bool hasOverrideContainingBlockLogicalHeight() const;
340 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
341 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
342 void clearContainingBlockOverrideSize();
343 void clearOverrideContainingBlockContentLogicalHeight();
345 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const;
347 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
348 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
349 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
350 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
352 struct ComputedMarginValues {
353 ComputedMarginValues() { }
360 struct LogicalExtentComputedValues {
361 LogicalExtentComputedValues() { }
364 LayoutUnit m_position;
365 ComputedMarginValues m_margins;
367 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
368 // of the containing block.
369 void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
371 // Used to resolve margins in the containing block's block-flow direction.
372 void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
373 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
375 enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
376 LayoutRect borderBoxRectInRegion(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
377 void clearRenderBoxRegionInfo();
378 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
380 void positionLineBox(InlineBox*);
382 virtual InlineBox* createInlineBox();
383 void dirtyLineBoxes(bool fullLayout);
385 // For inline replaced elements, this function returns the inline box that owns us. Enables
386 // the replaced RenderObject to quickly determine what line it is contained on and to easily
387 // iterate over structures on the line.
388 InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
389 void setInlineBoxWrapper(InlineBox*);
390 void deleteLineBoxWrapper();
392 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
393 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
394 void repaintDuringLayoutIfMoved(const LayoutRect&);
395 virtual void repaintOverhangingFloats(bool paintAllDescendants);
397 virtual LayoutUnit containingBlockLogicalWidthForContent() const;
398 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
400 LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*) const;
401 LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*) const;
402 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
404 virtual void updateLogicalWidth();
405 virtual void updateLogicalHeight();
406 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
408 RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
409 void computeLogicalWidthInRegion(LogicalExtentComputedValues&, RenderRegion* = 0) const;
411 bool stretchesToViewport() const
413 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !document().shouldDisplaySeamlesslyWithParent() && !isInline();
416 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
417 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
418 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
420 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
421 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
422 bool sizesLogicalWidthToFitContent(SizeType) const;
424 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlock* cb, RenderRegion*) const;
426 LayoutUnit computeLogicalWidthInRegionUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock, RenderRegion*) const;
427 LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
428 LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
429 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
430 LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
431 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
432 LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
433 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
435 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
436 virtual LayoutUnit computeReplacedLogicalHeight() const;
438 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
439 LayoutUnit computePercentageLogicalHeight(const Length& height) const;
441 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
442 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
443 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
444 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
446 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
447 // Relative positioning is one of those cases, since left/top offsets are physical.
448 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
449 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
451 virtual int verticalScrollbarWidth() const;
452 int horizontalScrollbarHeight() const;
453 int instrinsicScrollbarLogicalWidth() const;
454 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
455 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
456 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
457 bool canBeScrolledAndHasScrollableArea() const;
458 virtual bool canBeProgramaticallyScrolled() const;
459 virtual void autoscroll(const IntPoint&);
460 bool autoscrollInProgress() const;
461 bool canAutoscroll() const;
462 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
463 static RenderBox* findAutoscrollable(RenderObject*);
464 virtual void stopAutoscroll() { }
465 virtual void panScroll(const IntPoint&);
467 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
468 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
469 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
471 bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
472 bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
473 virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
474 virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
475 bool usesCompositedScrolling() const;
477 // Elements such as the <input> field override this to specify that they are scrollable
478 // outside the context of the CSS overflow style
479 virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
481 bool hasUnsplittableScrollingOverflow() const;
482 bool isUnsplittableForPagination() const;
484 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0);
486 virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
487 LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
488 virtual bool hasControlClip() const { return false; }
489 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
490 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
491 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
493 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
494 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
495 virtual void paintMask(PaintInfo&, const LayoutPoint&);
496 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
497 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
499 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
500 // that just updates the object's position. If the size does change, the object remains dirty.
501 bool tryLayoutDoingPositionedMovementOnly()
503 LayoutUnit oldWidth = width();
504 updateLogicalWidth();
505 // If we shrink to fit our width may have changed, so we still need full layout.
506 if (oldWidth != width())
508 updateLogicalHeight();
512 LayoutRect maskClipRect();
514 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
516 void removeFloatingOrPositionedChildFromBlockLists();
518 RenderLayer* enclosingFloatPaintingLayer() const;
520 virtual int firstLineBoxBaseline() const { return -1; }
521 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
523 bool shrinkToAvoidFloats() const;
524 virtual bool avoidsFloats() const;
526 virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&) { }
528 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
530 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
531 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
533 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
534 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
536 virtual LayoutUnit offsetLeft() const OVERRIDE;
537 virtual LayoutUnit offsetTop() const OVERRIDE;
539 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
540 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
541 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
542 LayoutPoint flipForWritingModeIncludingColumns(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;
552 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
553 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
554 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
555 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
557 bool hasRenderOverflow() const { return m_overflow; }
558 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
560 virtual bool needsPreferredWidthsRecalculation() const;
561 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
563 IntSize scrolledContentOffset() const;
564 LayoutSize cachedSizeForOverflowClip() const;
565 void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
567 virtual bool hasRelativeDimensions() const;
568 virtual bool hasRelativeLogicalHeight() const;
570 bool hasHorizontalLayoutOverflow() const
575 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
576 LayoutRect noOverflowRect = this->noOverflowRect();
577 return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
580 bool hasVerticalLayoutOverflow() const
585 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
586 LayoutRect noOverflowRect = this->noOverflowRect();
587 return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
590 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
592 ASSERT_NOT_REACHED();
596 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
598 ShapeOutsideInfo* shapeOutsideInfo() const
600 return ShapeOutsideInfo::isEnabledFor(this) ? ShapeOutsideInfo::info(this) : 0;
603 void markShapeOutsideDependentsForLayout()
606 removeFloatingOrPositionedChildFromBlockLists();
610 virtual void willBeDestroyed();
612 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
613 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
614 virtual void updateFromStyle() OVERRIDE;
616 LayoutRect backgroundPaintedExtent() const;
617 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
618 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
620 virtual void paintBackgroundWithBorderAndBoxShadow(PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance);
621 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
623 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
624 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
626 void paintMaskImages(const PaintInfo&, const LayoutRect&);
627 void paintBoxDecorationsWithRect(PaintInfo&, const LayoutPoint&, const LayoutRect&);
629 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
630 bool backgroundHasOpaqueTopLayer() const;
632 void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderRegion* = 0) const;
634 LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
635 LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
637 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
639 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
640 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const;
642 void paintRootBoxFillLayers(const PaintInfo&);
644 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
646 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
647 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
650 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
651 void updateGridPositionAfterStyleChange(const RenderStyle*);
653 bool autoWidthShouldFitContent() const;
654 void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
656 // Returns true if we did a full repaint
657 bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
659 bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
661 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* = 0, bool checkForPerpendicularWritingMode = true) const;
662 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
664 LayoutUnit viewLogicalHeightForPercentages() const;
666 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
667 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
668 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
669 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
670 LogicalExtentComputedValues&) const;
671 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
672 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
673 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
674 LogicalExtentComputedValues&) const;
676 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
677 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
679 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
680 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
682 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
684 // This function calculates the minimum and maximum preferred widths for an object.
685 // These values are used in shrink-to-fit layout systems.
686 // These include tables, positioned objects, floats and flexible boxes.
687 virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
689 virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
691 // This method performs the actual scroll. Override if scrolling without a RenderLayer. The scroll() and logicalScroll()
692 // are responsible for scroll propagation/bubbling and call this method to do the actual scrolling
693 virtual bool scrollImpl(ScrollDirection, ScrollGranularity, float);
696 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
697 LayoutRect m_frameRect;
700 LayoutBoxExtent m_marginBox;
702 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
703 LayoutUnit m_minPreferredLogicalWidth;
705 // The preferred logical width of the element if it never breaks any lines at all.
706 LayoutUnit m_maxPreferredLogicalWidth;
708 // Our intrinsic height, used for min-height: min-content etc. Maintained by
709 // updateLogicalHeight. This is logicalHeight() before it is clamped to
711 LayoutUnit m_intrinsicContentLogicalHeight;
713 // For inline replaced elements, the inline box that owns us.
714 InlineBox* m_inlineBoxWrapper;
716 // Our overflow information.
717 OwnPtr<RenderOverflow> m_overflow;
720 // Used to store state between styleWillChange and styleDidChange
721 static bool s_hadOverflowClip;
724 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
726 inline RenderBox* RenderBox::previousSiblingBox() const
728 return toRenderBox(previousSibling());
731 inline RenderBox* RenderBox::nextSiblingBox() const
733 return toRenderBox(nextSibling());
736 inline RenderBox* RenderBox::parentBox() const
738 return toRenderBox(parent());
741 inline RenderBox* RenderBox::firstChildBox() const
743 return toRenderBox(firstChild());
746 inline RenderBox* RenderBox::lastChildBox() const
748 return toRenderBox(lastChild());
751 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
754 ASSERT(!m_inlineBoxWrapper);
755 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
756 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
757 // only one will be notified when the renderer is getting destroyed. The second line box wrapper
758 // will keep a stale reference.
759 if (UNLIKELY(m_inlineBoxWrapper != 0))
760 deleteLineBoxWrapper();
763 m_inlineBoxWrapper = boxWrapper;
766 } // namespace WebCore
768 #endif // RenderBox_h