2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "core/rendering/RenderBoxModelObject.h"
27 #include "core/rendering/RenderOverflow.h"
28 #include "core/rendering/shapes/ShapeOutsideInfo.h"
29 #include "platform/scroll/ScrollTypes.h"
35 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
36 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
37 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
38 enum MarginDirection { BlockDirection, InlineDirection };
40 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
42 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
44 enum ScrollOffsetClamping {
45 ScrollOffsetUnclamped,
49 struct RenderBoxRareData {
50 WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED;
53 : m_inlineBoxWrapper(0)
54 , m_overrideLogicalContentHeight(-1)
55 , m_overrideLogicalContentWidth(-1)
56 , m_previousBorderBoxSize(-1, -1)
60 // For inline replaced elements, the inline box that owns us.
61 InlineBox* m_inlineBoxWrapper;
63 LayoutUnit m_overrideLogicalContentHeight;
64 LayoutUnit m_overrideLogicalContentWidth;
66 // Set by RenderBox::updatePreviousBorderBoxSizeIfNeeded().
67 LayoutSize m_previousBorderBoxSize;
70 class RenderBox : public RenderBoxModelObject {
72 explicit RenderBox(ContainerNode*);
74 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
75 // position:static elements that are not flex-items get their z-index coerced to auto.
76 virtual LayerType layerTypeRequired() const OVERRIDE
78 if (isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->shouldCompositeForCurrentAnimations())
80 if (hasOverflowClip())
81 return OverflowClipLayer;
86 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
88 // Use this with caution! No type checking is done!
89 RenderBox* firstChildBox() const;
90 RenderBox* lastChildBox() const;
92 LayoutUnit x() const { return m_frameRect.x(); }
93 LayoutUnit y() const { return m_frameRect.y(); }
94 LayoutUnit width() const { return m_frameRect.width(); }
95 LayoutUnit height() const { return m_frameRect.height(); }
97 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
98 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
100 // These represent your location relative to your container as a physical offset.
101 // In layout related methods you almost always want the logical location (e.g. x() and y()).
102 LayoutUnit top() const { return topLeftLocation().y(); }
103 LayoutUnit left() const { return topLeftLocation().x(); }
105 void setX(LayoutUnit x) { m_frameRect.setX(x); }
106 void setY(LayoutUnit y) { m_frameRect.setY(y); }
107 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
108 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
110 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
111 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
112 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
113 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
114 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
115 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
117 LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
118 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
119 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
121 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
122 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
124 void setLogicalLeft(LayoutUnit left)
126 if (style()->isHorizontalWritingMode())
131 void setLogicalTop(LayoutUnit top)
133 if (style()->isHorizontalWritingMode())
138 void setLogicalLocation(const LayoutPoint& location)
140 if (style()->isHorizontalWritingMode())
141 setLocation(location);
143 setLocation(location.transposedPoint());
145 void setLogicalWidth(LayoutUnit size)
147 if (style()->isHorizontalWritingMode())
152 void setLogicalHeight(LayoutUnit size)
154 if (style()->isHorizontalWritingMode())
159 void setLogicalSize(const LayoutSize& size)
161 if (style()->isHorizontalWritingMode())
164 setSize(size.transposedSize());
167 LayoutPoint location() const { return m_frameRect.location(); }
168 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
169 LayoutSize size() const { return m_frameRect.size(); }
170 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
172 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
174 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
175 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
177 LayoutRect frameRect() const { return m_frameRect; }
178 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
179 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
181 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
182 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
183 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
184 virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
186 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
187 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
188 // The content box in absolute coords. Ignores transforms.
189 IntRect absoluteContentBox() const;
190 // The content box converted to absolute coords (taking transforms into account).
191 FloatQuad absoluteContentQuad() const;
193 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
194 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
195 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
197 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const OVERRIDE;
199 // Use this with caution! No type checking is done!
200 RenderBox* previousSiblingBox() const;
201 RenderBox* nextSiblingBox() const;
202 RenderBox* parentBox() const;
204 bool canResize() const;
206 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
207 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
208 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
209 // but it is on the right in vertical-rl.
210 LayoutRect noOverflowRect() const;
211 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
212 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
213 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
214 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
215 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
217 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
218 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
219 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
221 LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
223 void addLayoutOverflow(const LayoutRect&);
224 void addVisualOverflow(const LayoutRect&);
226 // Clipped by the contents clip, if one exists.
227 void addContentsVisualOverflow(const LayoutRect&);
229 void addVisualEffectOverflow();
230 LayoutBoxExtent computeVisualEffectOverflowExtent() const;
231 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
232 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
233 void clearLayoutOverflow();
234 void clearAllOverflows() { m_overflow.clear(); }
236 void updateLayerTransformAfterLayout();
238 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
239 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
240 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
241 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
243 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
244 // to return the remaining width on a given line (and the height of a single line).
245 virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); }
246 virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); }
248 virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
249 virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
251 // More IE extensions. clientWidth and clientHeight represent the interior of an object
252 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
253 LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); }
254 LayoutUnit clientTop() const { return borderTop(); }
255 LayoutUnit clientWidth() const;
256 LayoutUnit clientHeight() const;
257 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
258 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
259 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
260 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
262 int pixelSnappedClientWidth() const;
263 int pixelSnappedClientHeight() const;
265 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
266 // object has overflow:hidden/scroll/auto specified and also has overflow.
267 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
268 // textareas can scroll shadow content (but pretend that they are the objects that are
270 virtual LayoutUnit scrollLeft() const;
271 virtual LayoutUnit scrollTop() const;
272 virtual LayoutUnit scrollWidth() const;
273 virtual LayoutUnit scrollHeight() const;
274 int pixelSnappedScrollWidth() const;
275 int pixelSnappedScrollHeight() const;
276 virtual void setScrollLeft(LayoutUnit);
277 virtual void setScrollTop(LayoutUnit);
279 void scrollToOffset(const IntSize&);
280 void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
281 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
283 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
284 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
285 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
286 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
287 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
288 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
289 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
290 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
292 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
293 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
295 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
296 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
297 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
299 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
300 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
302 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
304 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
305 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
307 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
308 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
309 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
311 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
312 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
314 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
316 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
317 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
320 // The following functions are used to implement collapsing margins.
321 // All objects know their maximal positive and negative margins. The
322 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
323 // For a non-collapsing box, such as a leaf element, this formula will simply return
324 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
326 virtual bool isSelfCollapsingBlock() const { return false; }
327 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
328 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
330 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
331 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
333 int reflectionOffset() const;
334 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
335 LayoutRect reflectedRect(const LayoutRect&) const;
337 virtual void layout() OVERRIDE;
338 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
339 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
341 virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
342 virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
344 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
345 // the border-box height/width like the regular height/width accessors on RenderBox.
346 // Right now, these are different than contentHeight/contentWidth because they still
347 // include the scrollbar height/width.
348 LayoutUnit overrideLogicalContentWidth() const;
349 LayoutUnit overrideLogicalContentHeight() const;
350 bool hasOverrideHeight() const;
351 bool hasOverrideWidth() const;
352 void setOverrideLogicalContentHeight(LayoutUnit);
353 void setOverrideLogicalContentWidth(LayoutUnit);
354 void clearOverrideSize();
355 void clearOverrideLogicalContentHeight();
356 void clearOverrideLogicalContentWidth();
358 LayoutUnit overrideContainingBlockContentLogicalWidth() const;
359 LayoutUnit overrideContainingBlockContentLogicalHeight() const;
360 bool hasOverrideContainingBlockLogicalWidth() const;
361 bool hasOverrideContainingBlockLogicalHeight() const;
362 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
363 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
364 void clearContainingBlockOverrideSize();
365 void clearOverrideContainingBlockContentLogicalHeight();
367 virtual LayoutSize offsetFromContainer(const RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
369 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
370 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
371 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
372 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
374 struct ComputedMarginValues {
375 ComputedMarginValues() { }
382 struct LogicalExtentComputedValues {
383 LogicalExtentComputedValues() { }
386 LayoutUnit m_position;
387 ComputedMarginValues m_margins;
389 // Resolve auto margins in the chosen direction of the containing block so that objects can be pushed to the start, middle or end
390 // of the containing block.
391 void computeMarginsForDirection(MarginDirection forDirection, const RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd, Length marginStartLength, Length marginStartEnd) const;
393 // Used to resolve margins in the containing block's block-flow direction.
394 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
396 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
398 void positionLineBox(InlineBox*);
399 void moveWithEdgeOfInlineContainerIfNecessary(bool isHorizontal);
401 virtual InlineBox* createInlineBox();
402 void dirtyLineBoxes(bool fullLayout);
404 // For inline replaced elements, this function returns the inline box that owns us. Enables
405 // the replaced RenderObject to quickly determine what line it is contained on and to easily
406 // iterate over structures on the line.
407 InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; }
408 void setInlineBoxWrapper(InlineBox*);
409 void deleteLineBoxWrapper();
411 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const OVERRIDE;
412 virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const OVERRIDE;
413 virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants);
415 virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
416 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
418 LayoutUnit containingBlockAvailableLineWidth() const;
419 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
421 virtual void updateLogicalWidth();
422 virtual void updateLogicalHeight();
423 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
425 void computeLogicalWidth(LogicalExtentComputedValues&) const;
427 bool stretchesToViewport() const
429 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElement() || isBody()) && !isInline();
432 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
433 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
434 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
435 virtual LayoutUnit intrinsicContentLogicalHeight() const { return m_intrinsicContentLogicalHeight; }
437 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
438 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
439 bool sizesLogicalWidthToFitContent(const Length& logicalWidth) const;
441 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
443 LayoutUnit computeLogicalWidthUsing(SizeType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const;
444 LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
445 LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
446 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
447 LayoutUnit computeReplacedLogicalWidthUsing(const Length& width) const;
448 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
449 LayoutUnit computeReplacedLogicalHeightUsing(const Length& height) const;
450 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
452 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
453 virtual LayoutUnit computeReplacedLogicalHeight() const;
455 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
456 LayoutUnit computePercentageLogicalHeight(const Length& height) const;
458 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
459 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
460 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
461 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
463 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
464 // Relative positioning is one of those cases, since left/top offsets are physical.
465 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
466 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
468 virtual int verticalScrollbarWidth() const;
469 int horizontalScrollbarHeight() const;
470 int instrinsicScrollbarLogicalWidth() const;
471 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
472 virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
473 bool canBeScrolledAndHasScrollableArea() const;
474 virtual bool canBeProgramaticallyScrolled() const;
475 virtual void autoscroll(const IntPoint&);
476 bool autoscrollInProgress() const;
477 bool canAutoscroll() const;
478 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
479 static RenderBox* findAutoscrollable(RenderObject*);
480 virtual void stopAutoscroll() { }
481 virtual void panScroll(const IntPoint&);
483 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
484 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
485 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
487 bool hasScrollableOverflowX() const { return scrollsOverflowX() && pixelSnappedScrollWidth() != pixelSnappedClientWidth(); }
488 bool hasScrollableOverflowY() const { return scrollsOverflowY() && pixelSnappedScrollHeight() != pixelSnappedClientHeight(); }
489 virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
490 virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
491 bool usesCompositedScrolling() const;
493 // Elements such as the <input> field override this to specify that they are scrollable
494 // outside the context of the CSS overflow style
495 virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
497 bool hasUnsplittableScrollingOverflow() const;
498 bool isUnsplittableForPagination() const;
500 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
502 virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
503 LayoutRect clipRect(const LayoutPoint& location);
504 virtual bool hasControlClip() const { return false; }
505 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
506 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
507 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
509 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
510 virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&);
511 virtual void paintMask(PaintInfo&, const LayoutPoint&);
512 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
513 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
515 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
516 // that just updates the object's position. If the size does change, the object remains dirty.
517 bool tryLayoutDoingPositionedMovementOnly()
519 LayoutUnit oldWidth = width();
520 updateLogicalWidth();
521 // If we shrink to fit our width may have changed, so we still need full layout.
522 if (oldWidth != width())
524 updateLogicalHeight();
528 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
530 void removeFloatingOrPositionedChildFromBlockLists();
532 RenderLayer* enclosingFloatPaintingLayer() const;
534 virtual int firstLineBoxBaseline() const { return -1; }
535 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
537 bool shrinkToAvoidFloats() const;
538 virtual bool avoidsFloats() const;
540 virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&);
542 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
544 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
545 bool isFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBox(); }
546 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
548 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
549 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
551 virtual LayoutUnit offsetLeft() const OVERRIDE;
552 virtual LayoutUnit offsetTop() const OVERRIDE;
554 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
555 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
556 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
557 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
558 LayoutSize flipForWritingMode(const LayoutSize&) const;
559 void flipForWritingMode(LayoutRect&) const;
560 FloatPoint flipForWritingMode(const FloatPoint&) const;
561 void flipForWritingMode(FloatRect&) const;
562 // These represent your location relative to your container as a physical offset.
563 // In layout related methods you almost always want the logical location (e.g. x() and y()).
564 LayoutPoint topLeftLocation() const;
565 LayoutSize topLeftLocationOffset() const;
567 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
568 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
569 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
570 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
572 bool hasRenderOverflow() const { return m_overflow; }
573 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
575 virtual bool needsPreferredWidthsRecalculation() const;
576 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
578 IntSize scrolledContentOffset() const;
579 void applyCachedClipAndScrollOffsetForPaintInvalidation(LayoutRect& paintRect) const;
581 virtual bool hasRelativeLogicalHeight() const;
583 bool hasHorizontalLayoutOverflow() const
588 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
589 LayoutRect noOverflowRect = this->noOverflowRect();
590 return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
593 bool hasVerticalLayoutOverflow() const
598 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
599 LayoutRect noOverflowRect = this->noOverflowRect();
600 return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
603 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
605 ASSERT_NOT_REACHED();
609 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
611 ShapeOutsideInfo* shapeOutsideInfo() const
613 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
616 void markShapeOutsideDependentsForLayout()
619 removeFloatingOrPositionedChildFromBlockLists();
622 bool backgroundHasOpaqueTopLayer() const;
625 virtual void willBeDestroyed() OVERRIDE;
628 virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle) OVERRIDE;
629 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
630 virtual void updateFromStyle() OVERRIDE;
632 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
633 // FIXME: make this a const method once the RenderBox reference in BoxPainter is const.
634 bool getBackgroundPaintedExtent(LayoutRect&);
635 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
636 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
638 void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
640 LayoutUnit computeIntrinsicLogicalWidthUsing(const Length& logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
641 LayoutUnit computeIntrinsicLogicalContentHeightUsing(const Length& logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
643 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
645 virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const OVERRIDE;
646 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
648 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
650 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
651 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
653 void updateIntrinsicContentLogicalHeight(LayoutUnit intrinsicContentLogicalHeight) const { m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight; }
655 virtual InvalidationReason getPaintInvalidationReason(const RenderLayerModelObject& paintInvalidationContainer,
656 const LayoutRect& oldBounds, const LayoutPoint& oldPositionFromPaintInvalidationContainer,
657 const LayoutRect& newBounds, const LayoutPoint& newPositionFromPaintInvalidationContainer) OVERRIDE;
658 virtual void incrementallyInvalidatePaint(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect& oldBounds, const LayoutRect& newBounds, const LayoutPoint& positionFromPaintInvalidationContainer) OVERRIDE;
660 virtual void clearPaintInvalidationState(const PaintInvalidationState&) OVERRIDE;
662 virtual bool paintInvalidationStateIsDirty() const OVERRIDE;
666 void invalidatePaintRectClippedByOldAndNewBounds(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect&, const LayoutRect& oldBounds, const LayoutRect& newBounds);
668 void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
669 void updateGridPositionAfterStyleChange(const RenderStyle*);
671 bool autoWidthShouldFitContent() const;
672 void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
674 // Returns true if we queued up a paint invalidation.
675 bool paintInvalidationLayerRectsForImage(WrappedImagePtr, const FillLayer&, bool drawingBackground);
677 bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
679 LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
680 LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
682 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
683 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
684 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
685 const Length& logicalLeft, const Length& logicalRight, const Length& marginLogicalLeft,
686 const Length& marginLogicalRight, LogicalExtentComputedValues&) const;
687 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
688 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
689 const Length& logicalTop, const Length& logicalBottom, const Length& marginLogicalTop,
690 const Length& marginLogicalBottom, LogicalExtentComputedValues&) const;
692 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
693 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
695 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
696 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
698 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
700 // This function calculates the minimum and maximum preferred widths for an object.
701 // These values are used in shrink-to-fit layout systems.
702 // These include tables, positioned objects, floats and flexible boxes.
703 virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
705 RenderBoxRareData& ensureRareData()
708 m_rareData = adoptPtr(new RenderBoxRareData());
709 return *m_rareData.get();
712 void savePreviousBorderBoxSizeIfNeeded();
713 LayoutSize computePreviousBorderBoxSize(const LayoutSize& previousBoundsSize) const;
715 bool logicalHeightComputesAsNone(SizeType) const;
717 virtual InvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&, const RenderLayerModelObject& newPaintInvalidationContainer) OVERRIDE FINAL;
719 bool isBox() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
721 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
722 LayoutRect m_frameRect;
724 // Our intrinsic height, used for min-height: min-content etc. Maintained by
725 // updateLogicalHeight. This is logicalHeight() before it is clamped to
727 mutable LayoutUnit m_intrinsicContentLogicalHeight;
729 void inflatePaintInvalidationRectForReflectionAndFilter(LayoutRect&) const;
732 LayoutBoxExtent m_marginBox;
734 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
735 LayoutUnit m_minPreferredLogicalWidth;
737 // The preferred logical width of the element if it never breaks any lines at all.
738 LayoutUnit m_maxPreferredLogicalWidth;
740 // Our overflow information.
741 OwnPtr<RenderOverflow> m_overflow;
744 OwnPtr<RenderBoxRareData> m_rareData;
747 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
749 inline RenderBox* RenderBox::previousSiblingBox() const
751 return toRenderBox(previousSibling());
754 inline RenderBox* RenderBox::nextSiblingBox() const
756 return toRenderBox(nextSibling());
759 inline RenderBox* RenderBox::parentBox() const
761 return toRenderBox(parent());
764 inline RenderBox* RenderBox::firstChildBox() const
766 return toRenderBox(slowFirstChild());
769 inline RenderBox* RenderBox::lastChildBox() const
771 return toRenderBox(slowLastChild());
774 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
777 ASSERT(!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(inlineBoxWrapper() != 0))
783 deleteLineBoxWrapper();
786 ensureRareData().m_inlineBoxWrapper = boxWrapper;
791 #endif // RenderBox_h