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