Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderBox.h
1 /*
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.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #ifndef RenderBox_h
24 #define RenderBox_h
25
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"
30
31 namespace WebCore {
32
33 class RenderBoxRegionInfo;
34 class RenderRegion;
35 struct PaintInfo;
36
37 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
38 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
39 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
40
41 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
42
43 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
44
45 enum ScrollOffsetClamping {
46     ScrollOffsetUnclamped,
47     ScrollOffsetClamped
48 };
49
50 class RenderBox : public RenderBoxModelObject {
51 public:
52     explicit RenderBox(ContainerNode*);
53     virtual ~RenderBox();
54
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 LayerType layerTypeRequired() const OVERRIDE
58     {
59         if (isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex())
60             return NormalLayer;
61         if (hasOverflowClip())
62             return OverflowClipLayer;
63
64         return NoLayer;
65     }
66
67     virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
68
69     // Use this with caution! No type checking is done!
70     RenderBox* firstChildBox() const;
71     RenderBox* lastChildBox() const;
72
73     LayoutUnit x() const { return m_frameRect.x(); }
74     LayoutUnit y() const { return m_frameRect.y(); }
75     LayoutUnit width() const { return m_frameRect.width(); }
76     LayoutUnit height() const { return m_frameRect.height(); }
77
78     int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
79     int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
80
81     // These represent your location relative to your container as a physical offset.
82     // In layout related methods you almost always want the logical location (e.g. x() and y()).
83     LayoutUnit top() const { return topLeftLocation().y(); }
84     LayoutUnit left() const { return topLeftLocation().x(); }
85
86     void setX(LayoutUnit x) { m_frameRect.setX(x); }
87     void setY(LayoutUnit y) { m_frameRect.setY(y); }
88     void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
89     void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
90
91     LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
92     LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
93     LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
94     LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
95     LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
96     LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
97
98     LayoutUnit constrainLogicalWidthInRegionByMinMax(LayoutUnit, LayoutUnit, RenderBlock*, RenderRegion* = 0) const;
99     LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
100     LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
101
102     int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
103     int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
104
105     void setLogicalLeft(LayoutUnit left)
106     {
107         if (style()->isHorizontalWritingMode())
108             setX(left);
109         else
110             setY(left);
111     }
112     void setLogicalTop(LayoutUnit top)
113     {
114         if (style()->isHorizontalWritingMode())
115             setY(top);
116         else
117             setX(top);
118     }
119     void setLogicalLocation(const LayoutPoint& location)
120     {
121         if (style()->isHorizontalWritingMode())
122             setLocation(location);
123         else
124             setLocation(location.transposedPoint());
125     }
126     void setLogicalWidth(LayoutUnit size)
127     {
128         if (style()->isHorizontalWritingMode())
129             setWidth(size);
130         else
131             setHeight(size);
132     }
133     void setLogicalHeight(LayoutUnit size)
134     {
135         if (style()->isHorizontalWritingMode())
136             setHeight(size);
137         else
138             setWidth(size);
139     }
140     void setLogicalSize(const LayoutSize& size)
141     {
142         if (style()->isHorizontalWritingMode())
143             setSize(size);
144         else
145             setSize(size.transposedSize());
146     }
147
148     LayoutPoint location() const { return m_frameRect.location(); }
149     LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
150     LayoutSize size() const { return m_frameRect.size(); }
151     IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
152
153     void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
154
155     void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
156     void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
157
158     LayoutRect frameRect() const { return m_frameRect; }
159     IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
160     void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
161
162     LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
163     LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
164     IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
165     virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
166
167     // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
168     LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
169     // The content box in absolute coords. Ignores transforms.
170     IntRect absoluteContentBox() const;
171     // The content box converted to absolute coords (taking transforms into account).
172     FloatQuad absoluteContentQuad() const;
173
174     // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
175     // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
176     LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
177
178     // Bounds of the outline box in absolute coords. Respects transforms
179     virtual LayoutRect outlineBoundsForRepaint(const RenderLayerModelObject* /*repaintContainer*/, const RenderGeometryMap*) const OVERRIDE FINAL;
180     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
181
182     // Use this with caution! No type checking is done!
183     RenderBox* previousSiblingBox() const;
184     RenderBox* nextSiblingBox() const;
185     RenderBox* parentBox() const;
186
187     bool canResize() const;
188
189     // Visual and layout overflow are in the coordinate space of the box.  This means that they aren't purely physical directions.
190     // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
191     // respectively are flipped when compared to their physical counterparts.  For example minX is on the left in vertical-lr,
192     // but it is on the right in vertical-rl.
193     LayoutRect noOverflowRect() const;
194     LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
195     IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
196     LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
197     LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
198     LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
199
200     virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
201     LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
202     LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
203
204     LayoutRect overflowRectForPaintRejection() const;
205
206     LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
207
208     void addLayoutOverflow(const LayoutRect&);
209     void addVisualOverflow(const LayoutRect&);
210
211     // Clipped by the contents clip, if one exists.
212     void addContentsVisualOverflow(const LayoutRect&);
213
214     void addVisualEffectOverflow();
215     void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
216     void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
217     void clearLayoutOverflow();
218
219     void updateLayerTransform();
220
221     LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
222     LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
223     LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
224     LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
225
226     // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
227     // to return the remaining width on a given line (and the height of a single line).
228     virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); }
229     virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); }
230
231     virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
232     virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
233
234     bool canDetermineWidthWithoutLayout() const;
235     LayoutUnit fixedOffsetWidth() const;
236
237     // More IE extensions.  clientWidth and clientHeight represent the interior of an object
238     // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
239     LayoutUnit clientLeft() const { return borderLeft(); }
240     LayoutUnit clientTop() const { return borderTop(); }
241     LayoutUnit clientWidth() const;
242     LayoutUnit clientHeight() const;
243     LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
244     LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
245     LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
246     LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
247
248     int pixelSnappedClientWidth() const;
249     int pixelSnappedClientHeight() const;
250
251     // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
252     // object has overflow:hidden/scroll/auto specified and also has overflow.
253     // scrollLeft/Top return the current scroll position.  These methods are virtual so that objects like
254     // textareas can scroll shadow content (but pretend that they are the objects that are
255     // scrolling).
256     virtual int scrollLeft() const;
257     virtual int scrollTop() const;
258     virtual int scrollWidth() const;
259     virtual int scrollHeight() const;
260     virtual void setScrollLeft(int);
261     virtual void setScrollTop(int);
262
263     void scrollToOffset(const IntSize&);
264     void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
265     void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
266
267     virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
268     virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
269     virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
270     virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
271     void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
272     void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
273     void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
274     void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
275
276     LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
277     LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
278
279     virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
280     virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
281     virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
282     {
283         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
284         return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
285     }
286     virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
287     {
288         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
289         return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
290     }
291     void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
292     void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
293     void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
294     {
295         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
296         m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
297     }
298     void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
299     {
300         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
301         m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
302     }
303
304     // The following five functions are used to implement collapsing margins.
305     // All objects know their maximal positive and negative margins.  The
306     // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
307     // For a non-collapsing box, such as a leaf element, this formula will simply return
308     // the margin of the element.  Blocks override the maxMarginBefore and maxMarginAfter
309     // methods.
310     enum MarginSign { PositiveMargin, NegativeMargin };
311     virtual bool isSelfCollapsingBlock() const { return false; }
312     virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
313     virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
314
315     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
316     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
317
318     LayoutRect reflectionBox() const;
319     int reflectionOffset() const;
320     // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
321     LayoutRect reflectedRect(const LayoutRect&) const;
322
323     virtual void layout() OVERRIDE;
324     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
325     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
326
327     virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
328     virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
329
330     // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
331     // the border-box height/width like the regular height/width accessors on RenderBox.
332     // Right now, these are different than contentHeight/contentWidth because they still
333     // include the scrollbar height/width.
334     LayoutUnit overrideLogicalContentWidth() const;
335     LayoutUnit overrideLogicalContentHeight() const;
336     bool hasOverrideHeight() const;
337     bool hasOverrideWidth() const;
338     void setOverrideLogicalContentHeight(LayoutUnit);
339     void setOverrideLogicalContentWidth(LayoutUnit);
340     void clearOverrideSize();
341     void clearOverrideLogicalContentHeight();
342     void clearOverrideLogicalContentWidth();
343
344     LayoutUnit overrideContainingBlockContentLogicalWidth() const;
345     LayoutUnit overrideContainingBlockContentLogicalHeight() const;
346     bool hasOverrideContainingBlockLogicalWidth() const;
347     bool hasOverrideContainingBlockLogicalHeight() const;
348     void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
349     void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
350     void clearContainingBlockOverrideSize();
351     void clearOverrideContainingBlockContentLogicalHeight();
352
353     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
354
355     LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
356     LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
357     LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
358     LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
359
360     struct ComputedMarginValues {
361         ComputedMarginValues() { }
362
363         LayoutUnit m_before;
364         LayoutUnit m_after;
365         LayoutUnit m_start;
366         LayoutUnit m_end;
367     };
368     struct LogicalExtentComputedValues {
369         LogicalExtentComputedValues() { }
370
371         LayoutUnit m_extent;
372         LayoutUnit m_position;
373         ComputedMarginValues m_margins;
374     };
375     // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
376     // of the containing block.
377     void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
378
379     // Used to resolve margins in the containing block's block-flow direction.
380     void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
381     void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
382
383     enum RenderBoxRegionInfoFlags { CacheRenderBoxRegionInfo, DoNotCacheRenderBoxRegionInfo };
384     LayoutRect borderBoxRectInRegion(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
385     void clearRenderBoxRegionInfo();
386     virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
387
388     void positionLineBox(InlineBox*);
389
390     virtual InlineBox* createInlineBox();
391     void dirtyLineBoxes(bool fullLayout);
392
393     // For inline replaced elements, this function returns the inline box that owns us.  Enables
394     // the replaced RenderObject to quickly determine what line it is contained on and to easily
395     // iterate over structures on the line.
396     InlineBox* inlineBoxWrapper() const { return m_inlineBoxWrapper; }
397     void setInlineBoxWrapper(InlineBox*);
398     void deleteLineBoxWrapper();
399
400     virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
401     virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
402     void repaintDuringLayoutIfMoved(const LayoutRect&);
403     virtual void repaintOverhangingFloats(bool paintAllDescendants);
404
405     virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
406     LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
407
408     LayoutUnit containingBlockLogicalWidthForContentInRegion(RenderRegion*) const;
409     LayoutUnit containingBlockAvailableLineWidthInRegion(RenderRegion*) const;
410     LayoutUnit perpendicularContainingBlockLogicalHeight() const;
411
412     virtual void updateLogicalWidth();
413     virtual void updateLogicalHeight();
414     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
415
416     RenderBoxRegionInfo* renderBoxRegionInfo(RenderRegion*, RenderBoxRegionInfoFlags = CacheRenderBoxRegionInfo) const;
417     void computeLogicalWidthInRegion(LogicalExtentComputedValues&, RenderRegion* = 0) const;
418
419     bool stretchesToViewport() const
420     {
421         return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !isInline();
422     }
423
424     virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
425     LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
426     LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
427
428     // Whether or not the element shrinks to its intrinsic width (rather than filling the width
429     // of a containing block).  HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
430     bool sizesLogicalWidthToFitContent(SizeType) const;
431
432     LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb, RenderRegion*) const;
433
434     LayoutUnit computeLogicalWidthInRegionUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock, RenderRegion*) const;
435     LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
436     LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
437     LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
438     LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
439     LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred  = ComputeActual) const;
440     LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
441     LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
442
443     virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const;
444     virtual LayoutUnit computeReplacedLogicalHeight() const;
445
446     static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
447     LayoutUnit computePercentageLogicalHeight(const Length& height) const;
448
449     // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
450     virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
451     virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
452     LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
453
454     // There are a few cases where we need to refer specifically to the available physical width and available physical height.
455     // Relative positioning is one of those cases, since left/top offsets are physical.
456     LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
457     LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
458
459     virtual int verticalScrollbarWidth() const;
460     int horizontalScrollbarHeight() const;
461     int instrinsicScrollbarLogicalWidth() const;
462     int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
463     virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
464     bool canBeScrolledAndHasScrollableArea() const;
465     virtual bool canBeProgramaticallyScrolled() const;
466     virtual void autoscroll(const IntPoint&);
467     bool autoscrollInProgress() const;
468     bool canAutoscroll() const;
469     IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
470     static RenderBox* findAutoscrollable(RenderObject*);
471     virtual void stopAutoscroll() { }
472     virtual void panScroll(const IntPoint&);
473
474     bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
475     bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
476     bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
477
478     bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
479     bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
480     virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
481     virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
482     bool usesCompositedScrolling() const;
483
484     // Elements such as the <input> field override this to specify that they are scrollable
485     // outside the context of the CSS overflow style
486     virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
487
488     bool hasUnsplittableScrollingOverflow() const;
489     bool isUnsplittableForPagination() const;
490
491     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
492
493     virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
494     LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
495     virtual bool hasControlClip() const { return false; }
496     virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
497     bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
498     void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
499
500     virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
501     virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
502     virtual void paintMask(PaintInfo&, const LayoutPoint&);
503     virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
504     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
505
506     // Called when a positioned object moves but doesn't necessarily change size.  A simplified layout is attempted
507     // that just updates the object's position. If the size does change, the object remains dirty.
508     bool tryLayoutDoingPositionedMovementOnly()
509     {
510         LayoutUnit oldWidth = width();
511         updateLogicalWidth();
512         // If we shrink to fit our width may have changed, so we still need full layout.
513         if (oldWidth != width())
514             return false;
515         updateLogicalHeight();
516         return true;
517     }
518
519     LayoutRect maskClipRect();
520
521     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
522
523     void removeFloatingOrPositionedChildFromBlockLists();
524
525     RenderLayer* enclosingFloatPaintingLayer() const;
526
527     virtual int firstLineBoxBaseline() const { return -1; }
528     virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
529
530     bool shrinkToAvoidFloats() const;
531     virtual bool avoidsFloats() const;
532
533     virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&) { }
534
535     bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
536
537     bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
538     bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
539
540     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
541     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
542
543     virtual LayoutUnit offsetLeft() const OVERRIDE;
544     virtual LayoutUnit offsetTop() const OVERRIDE;
545
546     LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
547     LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
548     LayoutPoint flipForWritingMode(const LayoutPoint&) const;
549     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
550     LayoutSize flipForWritingMode(const LayoutSize&) const;
551     void flipForWritingMode(LayoutRect&) const;
552     FloatPoint flipForWritingMode(const FloatPoint&) const;
553     void flipForWritingMode(FloatRect&) const;
554     // These represent your location relative to your container as a physical offset.
555     // In layout related methods you almost always want the logical location (e.g. x() and y()).
556     LayoutPoint topLeftLocation() const;
557     LayoutSize topLeftLocationOffset() const;
558
559     LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
560     LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
561     LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
562     LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
563
564     bool hasRenderOverflow() const { return m_overflow; }
565     bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
566
567     virtual bool needsPreferredWidthsRecalculation() const;
568     virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
569
570     IntSize scrolledContentOffset() const;
571     LayoutSize cachedSizeForOverflowClip() const;
572     void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
573
574     virtual bool hasRelativeLogicalHeight() const;
575
576     bool hasHorizontalLayoutOverflow() const
577     {
578         if (!m_overflow)
579             return false;
580
581         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
582         LayoutRect noOverflowRect = this->noOverflowRect();
583         return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
584     }
585
586     bool hasVerticalLayoutOverflow() const
587     {
588         if (!m_overflow)
589             return false;
590
591         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
592         LayoutRect noOverflowRect = this->noOverflowRect();
593         return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
594     }
595
596     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
597     {
598         ASSERT_NOT_REACHED();
599         return 0;
600     }
601
602     bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
603
604     ShapeOutsideInfo* shapeOutsideInfo() const
605     {
606         return ShapeOutsideInfo::isEnabledFor(this) ? ShapeOutsideInfo::info(this) : 0;
607     }
608
609     void markShapeOutsideDependentsForLayout()
610     {
611         if (isFloating())
612             removeFloatingOrPositionedChildFromBlockLists();
613     }
614
615 protected:
616     virtual void willBeDestroyed() OVERRIDE;
617
618     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle) OVERRIDE;
619     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
620     virtual void updateFromStyle() OVERRIDE;
621
622     LayoutRect backgroundPaintedExtent() const;
623     virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
624     virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
625
626     void paintBackgroundWithBorderAndBoxShadow(PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance);
627     void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
628
629     void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
630     void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
631
632     void paintMaskImages(const PaintInfo&, const LayoutRect&);
633     void paintBoxDecorationsWithRect(PaintInfo&, const LayoutPoint&, const LayoutRect&);
634
635     BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
636     bool backgroundHasOpaqueTopLayer() const;
637
638     void computePositionedLogicalWidth(LogicalExtentComputedValues&, RenderRegion* = 0) const;
639
640     LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
641     LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
642
643     virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
644
645     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
646     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
647
648     void paintRootBoxFillLayers(const PaintInfo&);
649
650     RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
651
652     virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
653     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
654
655 private:
656     void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
657     void updateGridPositionAfterStyleChange(const RenderStyle*);
658
659     bool autoWidthShouldFitContent() const;
660     void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
661
662     // Returns true if we did a full repaint
663     bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
664
665     bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
666
667     LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, RenderRegion* = 0, bool checkForPerpendicularWritingMode = true) const;
668     LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
669
670     LayoutUnit viewLogicalHeightForPercentages() const;
671
672     void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
673     void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
674                                             LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
675                                             Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight,
676                                             LogicalExtentComputedValues&) const;
677     void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
678                                              LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
679                                              Length logicalTop, Length logicalBottom, Length marginLogicalTop, Length marginLogicalBottom,
680                                              LogicalExtentComputedValues&) const;
681
682     void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
683     void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
684
685     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
686     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
687
688     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
689
690     // This function calculates the minimum and maximum preferred widths for an object.
691     // These values are used in shrink-to-fit layout systems.
692     // These include tables, positioned objects, floats and flexible boxes.
693     virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
694
695     virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
696
697 private:
698     // The width/height of the contents + borders + padding.  The x/y location is relative to our container (which is not always our parent).
699     LayoutRect m_frameRect;
700
701 protected:
702     LayoutBoxExtent m_marginBox;
703
704     // The preferred logical width of the element if it were to break its lines at every possible opportunity.
705     LayoutUnit m_minPreferredLogicalWidth;
706
707     // The preferred logical width of the element if it never breaks any lines at all.
708     LayoutUnit m_maxPreferredLogicalWidth;
709
710     // Our intrinsic height, used for min-height: min-content etc. Maintained by
711     // updateLogicalHeight. This is logicalHeight() before it is clamped to
712     // min/max.
713     LayoutUnit m_intrinsicContentLogicalHeight;
714
715     // For inline replaced elements, the inline box that owns us.
716     InlineBox* m_inlineBoxWrapper;
717
718     // Our overflow information.
719     OwnPtr<RenderOverflow> m_overflow;
720 };
721
722 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
723
724 inline RenderBox* RenderBox::previousSiblingBox() const
725 {
726     return toRenderBox(previousSibling());
727 }
728
729 inline RenderBox* RenderBox::nextSiblingBox() const
730 {
731     return toRenderBox(nextSibling());
732 }
733
734 inline RenderBox* RenderBox::parentBox() const
735 {
736     return toRenderBox(parent());
737 }
738
739 inline RenderBox* RenderBox::firstChildBox() const
740 {
741     return toRenderBox(firstChild());
742 }
743
744 inline RenderBox* RenderBox::lastChildBox() const
745 {
746     return toRenderBox(lastChild());
747 }
748
749 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
750 {
751     if (boxWrapper) {
752         ASSERT(!m_inlineBoxWrapper);
753         // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
754         // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
755         // only one will be notified when the renderer is getting destroyed. The second line box wrapper
756         // will keep a stale reference.
757         if (UNLIKELY(m_inlineBoxWrapper != 0))
758             deleteLineBoxWrapper();
759     }
760
761     m_inlineBoxWrapper = boxWrapper;
762 }
763
764 } // namespace WebCore
765
766 #endif // RenderBox_h