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/animation/ActiveAnimations.h"
27 #include "core/rendering/RenderBoxModelObject.h"
28 #include "core/rendering/RenderOverflow.h"
29 #include "core/rendering/shapes/ShapeOutsideInfo.h"
30 #include "platform/scroll/ScrollTypes.h"
36 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
37 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
38 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
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)
59 // For inline replaced elements, the inline box that owns us.
60 InlineBox* m_inlineBoxWrapper;
62 LayoutUnit m_overrideLogicalContentHeight;
63 LayoutUnit m_overrideLogicalContentWidth;
67 class RenderBox : public RenderBoxModelObject {
69 explicit RenderBox(ContainerNode*);
71 // hasAutoZIndex only returns true if the element is positioned or a flex-item since
72 // position:static elements that are not flex-items get their z-index coerced to auto.
73 virtual LayerType layerTypeRequired() const OVERRIDE
75 if (isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->shouldCompositeForCurrentAnimations())
77 if (hasOverflowClip())
78 return OverflowClipLayer;
83 virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
85 // Use this with caution! No type checking is done!
86 RenderBox* firstChildBox() const;
87 RenderBox* lastChildBox() const;
89 LayoutUnit x() const { return m_frameRect.x(); }
90 LayoutUnit y() const { return m_frameRect.y(); }
91 LayoutUnit width() const { return m_frameRect.width(); }
92 LayoutUnit height() const { return m_frameRect.height(); }
94 int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
95 int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
97 // These represent your location relative to your container as a physical offset.
98 // In layout related methods you almost always want the logical location (e.g. x() and y()).
99 LayoutUnit top() const { return topLeftLocation().y(); }
100 LayoutUnit left() const { return topLeftLocation().x(); }
102 void setX(LayoutUnit x) { m_frameRect.setX(x); }
103 void setY(LayoutUnit y) { m_frameRect.setY(y); }
104 void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
105 void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
107 LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
108 LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
109 LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
110 LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
111 LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
112 LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
114 LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
115 LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
116 LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
118 int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
119 int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
121 void setLogicalLeft(LayoutUnit left)
123 if (style()->isHorizontalWritingMode())
128 void setLogicalTop(LayoutUnit top)
130 if (style()->isHorizontalWritingMode())
135 void setLogicalLocation(const LayoutPoint& location)
137 if (style()->isHorizontalWritingMode())
138 setLocation(location);
140 setLocation(location.transposedPoint());
142 void setLogicalWidth(LayoutUnit size)
144 if (style()->isHorizontalWritingMode())
149 void setLogicalHeight(LayoutUnit size)
151 if (style()->isHorizontalWritingMode())
156 void setLogicalSize(const LayoutSize& size)
158 if (style()->isHorizontalWritingMode())
161 setSize(size.transposedSize());
164 LayoutPoint location() const { return m_frameRect.location(); }
165 LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
166 LayoutSize size() const { return m_frameRect.size(); }
167 IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
169 void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
171 void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
172 void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
174 LayoutRect frameRect() const { return m_frameRect; }
175 IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
176 void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
178 LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
179 LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
180 IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
181 virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
183 // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
184 LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
185 // The content box in absolute coords. Ignores transforms.
186 IntRect absoluteContentBox() const;
187 // The content box converted to absolute coords (taking transforms into account).
188 FloatQuad absoluteContentQuad() const;
190 // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
191 // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
192 LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
194 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
196 // Use this with caution! No type checking is done!
197 RenderBox* previousSiblingBox() const;
198 RenderBox* nextSiblingBox() const;
199 RenderBox* parentBox() const;
201 bool canResize() const;
203 // Visual and layout overflow are in the coordinate space of the box. This means that they aren't purely physical directions.
204 // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
205 // respectively are flipped when compared to their physical counterparts. For example minX is on the left in vertical-lr,
206 // but it is on the right in vertical-rl.
207 LayoutRect noOverflowRect() const;
208 LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
209 IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
210 LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
211 LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
212 LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
214 virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
215 LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
216 LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
218 LayoutRect overflowRectForPaintRejection() const;
220 LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
222 void addLayoutOverflow(const LayoutRect&);
223 void addVisualOverflow(const LayoutRect&);
225 // Clipped by the contents clip, if one exists.
226 void addContentsVisualOverflow(const LayoutRect&);
228 void addVisualEffectOverflow();
229 void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
230 void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
231 void clearLayoutOverflow();
232 void clearAllOverflows() { m_overflow.clear(); }
234 void updateLayerTransform();
236 LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
237 LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
238 LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
239 LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
241 // IE extensions. Used to calculate offsetWidth/Height. Overridden by inlines (RenderFlow)
242 // to return the remaining width on a given line (and the height of a single line).
243 virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); }
244 virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); }
246 virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
247 virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
249 // More IE extensions. clientWidth and clientHeight represent the interior of an object
250 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth.
251 LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); }
252 LayoutUnit clientTop() const { return borderTop(); }
253 LayoutUnit clientWidth() const;
254 LayoutUnit clientHeight() const;
255 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
256 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
257 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
258 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
260 int pixelSnappedClientWidth() const;
261 int pixelSnappedClientHeight() const;
263 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
264 // object has overflow:hidden/scroll/auto specified and also has overflow.
265 // scrollLeft/Top return the current scroll position. These methods are virtual so that objects like
266 // textareas can scroll shadow content (but pretend that they are the objects that are
268 virtual int scrollLeft() const;
269 virtual int scrollTop() const;
270 virtual int scrollWidth() const;
271 virtual int scrollHeight() const;
272 virtual void setScrollLeft(int);
273 virtual void setScrollTop(int);
275 void scrollToOffset(const IntSize&);
276 void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
277 void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
279 virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
280 virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
281 virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
282 virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
283 void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
284 void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
285 void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
286 void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
288 LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
289 LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
291 virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
292 virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
293 virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
295 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
296 return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
298 virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
300 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
301 return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
303 void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
304 void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
305 void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
307 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
308 m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
310 void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
312 const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
313 m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
316 // The following five functions are used to implement collapsing margins.
317 // All objects know their maximal positive and negative margins. The
318 // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
319 // For a non-collapsing box, such as a leaf element, this formula will simply return
320 // the margin of the element. Blocks override the maxMarginBefore and maxMarginAfter
322 enum MarginSign { PositiveMargin, NegativeMargin };
323 virtual bool isSelfCollapsingBlock() const { return false; }
324 virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
325 virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
327 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
328 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
330 int reflectionOffset() const;
331 // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
332 LayoutRect reflectedRect(const LayoutRect&) const;
334 virtual void layout() OVERRIDE;
335 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
336 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
338 virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
339 virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
341 // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
342 // the border-box height/width like the regular height/width accessors on RenderBox.
343 // Right now, these are different than contentHeight/contentWidth because they still
344 // include the scrollbar height/width.
345 LayoutUnit overrideLogicalContentWidth() const;
346 LayoutUnit overrideLogicalContentHeight() const;
347 bool hasOverrideHeight() const;
348 bool hasOverrideWidth() const;
349 void setOverrideLogicalContentHeight(LayoutUnit);
350 void setOverrideLogicalContentWidth(LayoutUnit);
351 void clearOverrideSize();
352 void clearOverrideLogicalContentHeight();
353 void clearOverrideLogicalContentWidth();
355 LayoutUnit overrideContainingBlockContentLogicalWidth() const;
356 LayoutUnit overrideContainingBlockContentLogicalHeight() const;
357 bool hasOverrideContainingBlockLogicalWidth() const;
358 bool hasOverrideContainingBlockLogicalHeight() const;
359 void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
360 void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
361 void clearContainingBlockOverrideSize();
362 void clearOverrideContainingBlockContentLogicalHeight();
364 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
366 LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
367 LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
368 LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
369 LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
371 struct ComputedMarginValues {
372 ComputedMarginValues() { }
379 struct LogicalExtentComputedValues {
380 LogicalExtentComputedValues() { }
383 LayoutUnit m_position;
384 ComputedMarginValues m_margins;
386 // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
387 // of the containing block.
388 void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
390 // Used to resolve margins in the containing block's block-flow direction.
391 void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
392 void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
394 virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
396 void positionLineBox(InlineBox*);
398 virtual InlineBox* createInlineBox();
399 void dirtyLineBoxes(bool fullLayout);
401 // For inline replaced elements, this function returns the inline box that owns us. Enables
402 // the replaced RenderObject to quickly determine what line it is contained on and to easily
403 // iterate over structures on the line.
404 InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; }
405 void setInlineBoxWrapper(InlineBox*);
406 void deleteLineBoxWrapper();
408 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
409 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
410 void repaintDuringLayoutIfMoved(const LayoutRect&);
411 virtual void repaintOverhangingFloats(bool paintAllDescendants);
413 virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
414 LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
416 LayoutUnit containingBlockAvailableLineWidth() const;
417 LayoutUnit perpendicularContainingBlockLogicalHeight() const;
419 virtual void updateLogicalWidth();
420 virtual void updateLogicalHeight();
421 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
423 void computeLogicalWidth(LogicalExtentComputedValues&) const;
425 bool stretchesToViewport() const
427 return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElement() || isBody()) && !isInline();
430 virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
431 LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
432 LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
433 virtual LayoutUnit intrinsicContentLogicalHeight() const { return m_intrinsicContentLogicalHeight; }
435 // Whether or not the element shrinks to its intrinsic width (rather than filling the width
436 // of a containing block). HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
437 bool sizesLogicalWidthToFitContent(const Length& logicalWidth) const;
439 LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
441 LayoutUnit computeLogicalWidthUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const;
442 LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
443 LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
444 LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
445 LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
446 LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred = ComputeActual) const;
447 LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
448 LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
450 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const;
451 virtual LayoutUnit computeReplacedLogicalHeight() const;
453 static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
454 LayoutUnit computePercentageLogicalHeight(const Length& height) const;
456 // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
457 virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
458 virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
459 LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
461 // There are a few cases where we need to refer specifically to the available physical width and available physical height.
462 // Relative positioning is one of those cases, since left/top offsets are physical.
463 LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
464 LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
466 virtual int verticalScrollbarWidth() const;
467 int horizontalScrollbarHeight() const;
468 int instrinsicScrollbarLogicalWidth() const;
469 int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
470 virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
471 bool canBeScrolledAndHasScrollableArea() const;
472 virtual bool canBeProgramaticallyScrolled() const;
473 virtual void autoscroll(const IntPoint&);
474 bool autoscrollInProgress() const;
475 bool canAutoscroll() const;
476 IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
477 static RenderBox* findAutoscrollable(RenderObject*);
478 virtual void stopAutoscroll() { }
479 virtual void panScroll(const IntPoint&);
481 bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
482 bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
483 bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
485 bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
486 bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
487 virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
488 virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
489 bool usesCompositedScrolling() const;
491 // Elements such as the <input> field override this to specify that they are scrollable
492 // outside the context of the CSS overflow style
493 virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
495 bool hasUnsplittableScrollingOverflow() const;
496 bool isUnsplittableForPagination() const;
498 virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
500 virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
501 LayoutRect clipRect(const LayoutPoint& location);
502 virtual bool hasControlClip() const { return false; }
503 virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
504 bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
505 void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
507 virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
508 virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
509 virtual void paintMask(PaintInfo&, const LayoutPoint&);
510 virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
511 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
513 // Called when a positioned object moves but doesn't necessarily change size. A simplified layout is attempted
514 // that just updates the object's position. If the size does change, the object remains dirty.
515 bool tryLayoutDoingPositionedMovementOnly()
517 LayoutUnit oldWidth = width();
518 updateLogicalWidth();
519 // If we shrink to fit our width may have changed, so we still need full layout.
520 if (oldWidth != width())
522 updateLogicalHeight();
526 virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
528 void removeFloatingOrPositionedChildFromBlockLists();
530 RenderLayer* enclosingFloatPaintingLayer() const;
532 virtual int firstLineBoxBaseline() const { return -1; }
533 virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
535 bool shrinkToAvoidFloats() const;
536 virtual bool avoidsFloats() const;
538 virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&);
540 bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
542 bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
543 bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
545 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
546 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
548 virtual LayoutUnit offsetLeft() const OVERRIDE;
549 virtual LayoutUnit offsetTop() const OVERRIDE;
551 LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
552 LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
553 LayoutPoint flipForWritingMode(const LayoutPoint&) const;
554 LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
555 LayoutSize flipForWritingMode(const LayoutSize&) const;
556 void flipForWritingMode(LayoutRect&) const;
557 FloatPoint flipForWritingMode(const FloatPoint&) const;
558 void flipForWritingMode(FloatRect&) const;
559 // These represent your location relative to your container as a physical offset.
560 // In layout related methods you almost always want the logical location (e.g. x() and y()).
561 LayoutPoint topLeftLocation() const;
562 LayoutSize topLeftLocationOffset() const;
564 LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
565 LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
566 LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
567 LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
569 bool hasRenderOverflow() const { return m_overflow; }
570 bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
572 virtual bool needsPreferredWidthsRecalculation() const;
573 virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
575 IntSize scrolledContentOffset() const;
576 LayoutSize cachedSizeForOverflowClip() const;
577 void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
579 virtual bool hasRelativeLogicalHeight() const;
581 bool hasHorizontalLayoutOverflow() const
586 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
587 LayoutRect noOverflowRect = this->noOverflowRect();
588 return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
591 bool hasVerticalLayoutOverflow() const
596 LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
597 LayoutRect noOverflowRect = this->noOverflowRect();
598 return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
601 virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
603 ASSERT_NOT_REACHED();
607 bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
609 ShapeOutsideInfo* shapeOutsideInfo() const
611 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
614 void markShapeOutsideDependentsForLayout()
617 removeFloatingOrPositionedChildFromBlockLists();
620 virtual void repaintTreeAfterLayout() OVERRIDE;
623 virtual void willBeDestroyed() OVERRIDE;
625 virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle) OVERRIDE;
626 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
627 virtual void updateFromStyle() OVERRIDE;
629 // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
630 bool getBackgroundPaintedExtent(LayoutRect&) const;
631 virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
632 virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
634 void paintBackgroundWithBorderAndBoxShadow(PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance);
635 void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
637 void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
638 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
640 void paintMaskImages(const PaintInfo&, const LayoutRect&);
641 void paintBoxDecorationsWithRect(PaintInfo&, const LayoutPoint&, const LayoutRect&);
643 BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
644 bool backgroundHasOpaqueTopLayer() const;
646 void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
648 LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
649 LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
651 virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
653 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
654 virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
656 void paintRootBoxFillLayers(const PaintInfo&);
658 RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
660 virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
661 virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
663 void updateIntrinsicContentLogicalHeight(LayoutUnit intrinsicContentLogicalHeight) const { m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight; }
665 bool createsBlockFormattingContext() const;
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 did a full repaint
675 bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, 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 LayoutUnit viewLogicalHeightForPercentages() const;
684 void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
685 void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
686 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
687 Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
688 LogicalExtentComputedValues&) const;
689 void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
690 LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
691 Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
692 LogicalExtentComputedValues&) const;
694 void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
695 void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
697 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
698 LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
700 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
702 // This function calculates the minimum and maximum preferred widths for an object.
703 // These values are used in shrink-to-fit layout systems.
704 // These include tables, positioned objects, floats and flexible boxes.
705 virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
707 virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
709 RenderBoxRareData& ensureRareData()
712 m_rareData = adoptPtr(new RenderBoxRareData());
713 return *m_rareData.get();
717 // The width/height of the contents + borders + padding. The x/y location is relative to our container (which is not always our parent).
718 LayoutRect m_frameRect;
720 // Our intrinsic height, used for min-height: min-content etc. Maintained by
721 // updateLogicalHeight. This is logicalHeight() before it is clamped to
723 mutable LayoutUnit m_intrinsicContentLogicalHeight;
726 LayoutBoxExtent m_marginBox;
728 // The preferred logical width of the element if it were to break its lines at every possible opportunity.
729 LayoutUnit m_minPreferredLogicalWidth;
731 // The preferred logical width of the element if it never breaks any lines at all.
732 LayoutUnit m_maxPreferredLogicalWidth;
734 // Our overflow information.
735 OwnPtr<RenderOverflow> m_overflow;
738 OwnPtr<RenderBoxRareData> m_rareData;
741 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
743 inline RenderBox* RenderBox::previousSiblingBox() const
745 return toRenderBox(previousSibling());
748 inline RenderBox* RenderBox::nextSiblingBox() const
750 return toRenderBox(nextSibling());
753 inline RenderBox* RenderBox::parentBox() const
755 return toRenderBox(parent());
758 inline RenderBox* RenderBox::firstChildBox() const
760 return toRenderBox(firstChild());
763 inline RenderBox* RenderBox::lastChildBox() const
765 return toRenderBox(lastChild());
768 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
771 ASSERT(!inlineBoxWrapper());
772 // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
773 // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
774 // only one will be notified when the renderer is getting destroyed. The second line box wrapper
775 // will keep a stale reference.
776 if (UNLIKELY(inlineBoxWrapper() != 0))
777 deleteLineBoxWrapper();
780 ensureRareData().m_inlineBoxWrapper = boxWrapper;
783 } // namespace WebCore
785 #endif // RenderBox_h