Upstream version 7.36.149.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/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"
31
32 namespace WebCore {
33
34 struct PaintInfo;
35
36 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
37 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
38 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
39
40 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
41
42 enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
43
44 enum ScrollOffsetClamping {
45     ScrollOffsetUnclamped,
46     ScrollOffsetClamped
47 };
48
49 struct RenderBoxRareData {
50     WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED;
51 public:
52     RenderBoxRareData()
53         : m_inlineBoxWrapper(0)
54         , m_overrideLogicalContentHeight(-1)
55         , m_overrideLogicalContentWidth(-1)
56     {
57     }
58
59     // For inline replaced elements, the inline box that owns us.
60     InlineBox* m_inlineBoxWrapper;
61
62     LayoutUnit m_overrideLogicalContentHeight;
63     LayoutUnit m_overrideLogicalContentWidth;
64 };
65
66
67 class RenderBox : public RenderBoxModelObject {
68 public:
69     explicit RenderBox(ContainerNode*);
70
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
74     {
75         if (isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->shouldCompositeForCurrentAnimations())
76             return NormalLayer;
77         if (hasOverflowClip())
78             return OverflowClipLayer;
79
80         return NoLayer;
81     }
82
83     virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
84
85     // Use this with caution! No type checking is done!
86     RenderBox* firstChildBox() const;
87     RenderBox* lastChildBox() const;
88
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(); }
93
94     int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
95     int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
96
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(); }
101
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); }
106
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(); }
113
114     LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
115     LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
116     LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
117
118     int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
119     int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
120
121     void setLogicalLeft(LayoutUnit left)
122     {
123         if (style()->isHorizontalWritingMode())
124             setX(left);
125         else
126             setY(left);
127     }
128     void setLogicalTop(LayoutUnit top)
129     {
130         if (style()->isHorizontalWritingMode())
131             setY(top);
132         else
133             setX(top);
134     }
135     void setLogicalLocation(const LayoutPoint& location)
136     {
137         if (style()->isHorizontalWritingMode())
138             setLocation(location);
139         else
140             setLocation(location.transposedPoint());
141     }
142     void setLogicalWidth(LayoutUnit size)
143     {
144         if (style()->isHorizontalWritingMode())
145             setWidth(size);
146         else
147             setHeight(size);
148     }
149     void setLogicalHeight(LayoutUnit size)
150     {
151         if (style()->isHorizontalWritingMode())
152             setHeight(size);
153         else
154             setWidth(size);
155     }
156     void setLogicalSize(const LayoutSize& size)
157     {
158         if (style()->isHorizontalWritingMode())
159             setSize(size);
160         else
161             setSize(size.transposedSize());
162     }
163
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(); }
168
169     void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
170
171     void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
172     void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
173
174     LayoutRect frameRect() const { return m_frameRect; }
175     IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
176     void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
177
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(); }
182
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;
189
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()); }
193
194     virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE;
195
196     // Use this with caution! No type checking is done!
197     RenderBox* previousSiblingBox() const;
198     RenderBox* nextSiblingBox() const;
199     RenderBox* parentBox() const;
200
201     bool canResize() const;
202
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(); }
213
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(); }
217
218     LayoutRect overflowRectForPaintRejection() const;
219
220     LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
221
222     void addLayoutOverflow(const LayoutRect&);
223     void addVisualOverflow(const LayoutRect&);
224
225     // Clipped by the contents clip, if one exists.
226     void addContentsVisualOverflow(const LayoutRect&);
227
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(); }
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     // 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()); }
259
260     int pixelSnappedClientWidth() const;
261     int pixelSnappedClientHeight() const;
262
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
267     // scrolling).
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);
274
275     void scrollToOffset(const IntSize&);
276     void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
277     void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
278
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); }
287
288     LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
289     LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
290
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
294     {
295         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
296         return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
297     }
298     virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
299     {
300         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
301         return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
302     }
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)
306     {
307         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
308         m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
309     }
310     void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
311     {
312         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
313         m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
314     }
315
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
321     // methods.
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(); }
326
327     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
328     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
329
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;
333
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;
337
338     virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
339     virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
340
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();
354
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();
363
364     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
365
366     LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
367     LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
368     LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
369     LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
370
371     struct ComputedMarginValues {
372         ComputedMarginValues() { }
373
374         LayoutUnit m_before;
375         LayoutUnit m_after;
376         LayoutUnit m_start;
377         LayoutUnit m_end;
378     };
379     struct LogicalExtentComputedValues {
380         LogicalExtentComputedValues() { }
381
382         LayoutUnit m_extent;
383         LayoutUnit m_position;
384         ComputedMarginValues m_margins;
385     };
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;
389
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);
393
394     virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
395
396     void positionLineBox(InlineBox*);
397
398     virtual InlineBox* createInlineBox();
399     void dirtyLineBoxes(bool fullLayout);
400
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();
407
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);
412
413     virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
414     LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
415
416     LayoutUnit containingBlockAvailableLineWidth() const;
417     LayoutUnit perpendicularContainingBlockLogicalHeight() const;
418
419     virtual void updateLogicalWidth();
420     virtual void updateLogicalHeight();
421     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
422
423     void computeLogicalWidth(LogicalExtentComputedValues&) const;
424
425     bool stretchesToViewport() const
426     {
427         return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElement() || isBody()) && !isInline();
428     }
429
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; }
434
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;
438
439     LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
440
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;
449
450     virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const;
451     virtual LayoutUnit computeReplacedLogicalHeight() const;
452
453     static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
454     LayoutUnit computePercentageLogicalHeight(const Length& height) const;
455
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;
460
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(); }
465
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&);
480
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(); }
484
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;
490
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; }
494
495     bool hasUnsplittableScrollingOverflow() const;
496     bool isUnsplittableForPagination() const;
497
498     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
499
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);
506
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;
512
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()
516     {
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())
521             return false;
522         updateLogicalHeight();
523         return true;
524     }
525
526     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
527
528     void removeFloatingOrPositionedChildFromBlockLists();
529
530     RenderLayer* enclosingFloatPaintingLayer() const;
531
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.
534
535     bool shrinkToAvoidFloats() const;
536     virtual bool avoidsFloats() const;
537
538     virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&);
539
540     bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
541
542     bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
543     bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
544
545     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
546     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
547
548     virtual LayoutUnit offsetLeft() const OVERRIDE;
549     virtual LayoutUnit offsetTop() const OVERRIDE;
550
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;
563
564     LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
565     LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
566     LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
567     LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
568
569     bool hasRenderOverflow() const { return m_overflow; }
570     bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
571
572     virtual bool needsPreferredWidthsRecalculation() const;
573     virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
574
575     IntSize scrolledContentOffset() const;
576     LayoutSize cachedSizeForOverflowClip() const;
577     void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
578
579     virtual bool hasRelativeLogicalHeight() const;
580
581     bool hasHorizontalLayoutOverflow() const
582     {
583         if (!m_overflow)
584             return false;
585
586         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
587         LayoutRect noOverflowRect = this->noOverflowRect();
588         return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
589     }
590
591     bool hasVerticalLayoutOverflow() const
592     {
593         if (!m_overflow)
594             return false;
595
596         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
597         LayoutRect noOverflowRect = this->noOverflowRect();
598         return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
599     }
600
601     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
602     {
603         ASSERT_NOT_REACHED();
604         return 0;
605     }
606
607     bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
608
609     ShapeOutsideInfo* shapeOutsideInfo() const
610     {
611         return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
612     }
613
614     void markShapeOutsideDependentsForLayout()
615     {
616         if (isFloating())
617             removeFloatingOrPositionedChildFromBlockLists();
618     }
619
620     virtual void repaintTreeAfterLayout() OVERRIDE;
621
622 protected:
623     virtual void willBeDestroyed() OVERRIDE;
624
625     virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle) OVERRIDE;
626     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
627     virtual void updateFromStyle() OVERRIDE;
628
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;
633
634     void paintBackgroundWithBorderAndBoxShadow(PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance);
635     void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
636
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);
639
640     void paintMaskImages(const PaintInfo&, const LayoutRect&);
641     void paintBoxDecorationsWithRect(PaintInfo&, const LayoutPoint&, const LayoutRect&);
642
643     BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
644     bool backgroundHasOpaqueTopLayer() const;
645
646     void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
647
648     LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
649     LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
650
651     virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
652
653     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
654     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
655
656     void paintRootBoxFillLayers(const PaintInfo&);
657
658     RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
659
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;
662
663     void updateIntrinsicContentLogicalHeight(LayoutUnit intrinsicContentLogicalHeight) const { m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight; }
664
665     bool createsBlockFormattingContext() const;
666
667 private:
668     void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
669     void updateGridPositionAfterStyleChange(const RenderStyle*);
670
671     bool autoWidthShouldFitContent() const;
672     void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
673
674     // Returns true if we did a full repaint
675     bool repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground);
676
677     bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
678
679     LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
680     LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
681
682     LayoutUnit viewLogicalHeightForPercentages() const;
683
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;
693
694     void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
695     void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
696
697     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
698     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
699
700     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
701
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(); }
706
707     virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE FINAL { return frameRect(); }
708
709     RenderBoxRareData& ensureRareData()
710     {
711         if (!m_rareData)
712             m_rareData = adoptPtr(new RenderBoxRareData());
713         return *m_rareData.get();
714     }
715
716 private:
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;
719
720     // Our intrinsic height, used for min-height: min-content etc. Maintained by
721     // updateLogicalHeight. This is logicalHeight() before it is clamped to
722     // min/max.
723     mutable LayoutUnit m_intrinsicContentLogicalHeight;
724
725 protected:
726     LayoutBoxExtent m_marginBox;
727
728     // The preferred logical width of the element if it were to break its lines at every possible opportunity.
729     LayoutUnit m_minPreferredLogicalWidth;
730
731     // The preferred logical width of the element if it never breaks any lines at all.
732     LayoutUnit m_maxPreferredLogicalWidth;
733
734     // Our overflow information.
735     OwnPtr<RenderOverflow> m_overflow;
736
737 private:
738     OwnPtr<RenderBoxRareData> m_rareData;
739 };
740
741 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
742
743 inline RenderBox* RenderBox::previousSiblingBox() const
744 {
745     return toRenderBox(previousSibling());
746 }
747
748 inline RenderBox* RenderBox::nextSiblingBox() const
749 {
750     return toRenderBox(nextSibling());
751 }
752
753 inline RenderBox* RenderBox::parentBox() const
754 {
755     return toRenderBox(parent());
756 }
757
758 inline RenderBox* RenderBox::firstChildBox() const
759 {
760     return toRenderBox(firstChild());
761 }
762
763 inline RenderBox* RenderBox::lastChildBox() const
764 {
765     return toRenderBox(lastChild());
766 }
767
768 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
769 {
770     if (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();
778     }
779
780     ensureRareData().m_inlineBoxWrapper = boxWrapper;
781 }
782
783 } // namespace WebCore
784
785 #endif // RenderBox_h