e2c06cf1ea8e7b4eccc7be0f1ff7914a35b5f9c8
[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/LayoutRectRecorder.h"
28 #include "core/rendering/RenderBoxModelObject.h"
29 #include "core/rendering/RenderOverflow.h"
30 #include "core/rendering/shapes/ShapeOutsideInfo.h"
31 #include "platform/scroll/ScrollTypes.h"
32
33 namespace WebCore {
34
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 struct RenderBoxRareData {
51     WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED;
52 public:
53     RenderBoxRareData()
54         : m_inlineBoxWrapper(0)
55         , m_overrideLogicalContentHeight(-1)
56         , m_overrideLogicalContentWidth(-1)
57     {
58     }
59
60     // For inline replaced elements, the inline box that owns us.
61     InlineBox* m_inlineBoxWrapper;
62
63     LayoutUnit m_overrideLogicalContentHeight;
64     LayoutUnit m_overrideLogicalContentWidth;
65 };
66
67
68 class RenderBox : public RenderBoxModelObject {
69 public:
70     explicit RenderBox(ContainerNode*);
71
72     // hasAutoZIndex only returns true if the element is positioned or a flex-item since
73     // position:static elements that are not flex-items get their z-index coerced to auto.
74     virtual LayerType layerTypeRequired() const OVERRIDE
75     {
76         if (isRoot() || isPositioned() || createsGroup() || hasClipPath() || hasTransform() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->hasWillChangeCompositingHint() || style()->hasWillChangeGpuRasterizationHint() || shouldCompositeForActiveAnimations(*this))
77             return NormalLayer;
78         if (hasOverflowClip())
79             return OverflowClipLayer;
80
81         return NoLayer;
82     }
83
84     virtual bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect) const OVERRIDE;
85
86     // Use this with caution! No type checking is done!
87     RenderBox* firstChildBox() const;
88     RenderBox* lastChildBox() const;
89
90     LayoutUnit x() const { return m_frameRect.x(); }
91     LayoutUnit y() const { return m_frameRect.y(); }
92     LayoutUnit width() const { return m_frameRect.width(); }
93     LayoutUnit height() const { return m_frameRect.height(); }
94
95     int pixelSnappedWidth() const { return m_frameRect.pixelSnappedWidth(); }
96     int pixelSnappedHeight() const { return m_frameRect.pixelSnappedHeight(); }
97
98     // These represent your location relative to your container as a physical offset.
99     // In layout related methods you almost always want the logical location (e.g. x() and y()).
100     LayoutUnit top() const { return topLeftLocation().y(); }
101     LayoutUnit left() const { return topLeftLocation().x(); }
102
103     void setX(LayoutUnit x) { m_frameRect.setX(x); }
104     void setY(LayoutUnit y) { m_frameRect.setY(y); }
105     void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
106     void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
107
108     LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
109     LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
110     LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
111     LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
112     LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
113     LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
114
115     LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
116     LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
117     LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
118
119     int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
120     int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
121
122     void setLogicalLeft(LayoutUnit left)
123     {
124         if (style()->isHorizontalWritingMode())
125             setX(left);
126         else
127             setY(left);
128     }
129     void setLogicalTop(LayoutUnit top)
130     {
131         if (style()->isHorizontalWritingMode())
132             setY(top);
133         else
134             setX(top);
135     }
136     void setLogicalLocation(const LayoutPoint& location)
137     {
138         if (style()->isHorizontalWritingMode())
139             setLocation(location);
140         else
141             setLocation(location.transposedPoint());
142     }
143     void setLogicalWidth(LayoutUnit size)
144     {
145         if (style()->isHorizontalWritingMode())
146             setWidth(size);
147         else
148             setHeight(size);
149     }
150     void setLogicalHeight(LayoutUnit size)
151     {
152         if (style()->isHorizontalWritingMode())
153             setHeight(size);
154         else
155             setWidth(size);
156     }
157     void setLogicalSize(const LayoutSize& size)
158     {
159         if (style()->isHorizontalWritingMode())
160             setSize(size);
161         else
162             setSize(size.transposedSize());
163     }
164
165     LayoutPoint location() const { return m_frameRect.location(); }
166     LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
167     LayoutSize size() const { return m_frameRect.size(); }
168     IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
169
170     void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
171
172     void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
173     void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
174
175     LayoutRect frameRect() const { return m_frameRect; }
176     IntRect pixelSnappedFrameRect() const { return pixelSnappedIntRect(m_frameRect); }
177     void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
178
179     LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
180     LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), contentWidth() + paddingLeft() + paddingRight(), contentHeight() + paddingTop() + paddingBottom()); }
181     IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
182     virtual IntRect borderBoundingBox() const OVERRIDE FINAL { return pixelSnappedBorderBoxRect(); }
183
184     // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
185     LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
186     // The content box in absolute coords. Ignores transforms.
187     IntRect absoluteContentBox() const;
188     // The content box converted to absolute coords (taking transforms into account).
189     FloatQuad absoluteContentQuad() const;
190
191     // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
192     // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
193     LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
194
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     void clearAllOverflows() { m_overflow.clear(); }
234
235     void updateLayerTransform();
236
237     LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
238     LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
239     LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
240     LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
241
242     // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
243     // to return the remaining width on a given line (and the height of a single line).
244     virtual LayoutUnit offsetWidth() const OVERRIDE { return width(); }
245     virtual LayoutUnit offsetHeight() const OVERRIDE { return height(); }
246
247     virtual int pixelSnappedOffsetWidth() const OVERRIDE FINAL;
248     virtual int pixelSnappedOffsetHeight() const OVERRIDE FINAL;
249
250     bool canDetermineWidthWithoutLayout() const;
251     LayoutUnit fixedOffsetWidth() const;
252
253     // More IE extensions.  clientWidth and clientHeight represent the interior of an object
254     // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
255     LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); }
256     LayoutUnit clientTop() const { return borderTop(); }
257     LayoutUnit clientWidth() const;
258     LayoutUnit clientHeight() const;
259     LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
260     LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
261     LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
262     LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
263
264     int pixelSnappedClientWidth() const;
265     int pixelSnappedClientHeight() const;
266
267     // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
268     // object has overflow:hidden/scroll/auto specified and also has overflow.
269     // scrollLeft/Top return the current scroll position.  These methods are virtual so that objects like
270     // textareas can scroll shadow content (but pretend that they are the objects that are
271     // scrolling).
272     virtual int scrollLeft() const;
273     virtual int scrollTop() const;
274     virtual int scrollWidth() const;
275     virtual int scrollHeight() const;
276     virtual void setScrollLeft(int);
277     virtual void setScrollTop(int);
278
279     void scrollToOffset(const IntSize&);
280     void scrollByRecursively(const IntSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
281     void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
282
283     virtual LayoutUnit marginTop() const OVERRIDE { return m_marginBox.top(); }
284     virtual LayoutUnit marginBottom() const OVERRIDE { return m_marginBox.bottom(); }
285     virtual LayoutUnit marginLeft() const OVERRIDE { return m_marginBox.left(); }
286     virtual LayoutUnit marginRight() const OVERRIDE { return m_marginBox.right(); }
287     void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
288     void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
289     void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
290     void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
291
292     LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
293     LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
294
295     virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
296     virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
297     virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
298     {
299         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
300         return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
301     }
302     virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const OVERRIDE FINAL
303     {
304         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
305         return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
306     }
307     void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
308     void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
309     void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
310     {
311         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
312         m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
313     }
314     void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
315     {
316         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
317         m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
318     }
319
320     // The following five functions are used to implement collapsing margins.
321     // All objects know their maximal positive and negative margins.  The
322     // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
323     // For a non-collapsing box, such as a leaf element, this formula will simply return
324     // the margin of the element.  Blocks override the maxMarginBefore and maxMarginAfter
325     // methods.
326     enum MarginSign { PositiveMargin, NegativeMargin };
327     virtual bool isSelfCollapsingBlock() const { return false; }
328     virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
329     virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
330
331     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE;
332     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE;
333
334     LayoutRect reflectionBox() const;
335     int reflectionOffset() const;
336     // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
337     LayoutRect reflectedRect(const LayoutRect&) const;
338
339     virtual void layout() OVERRIDE;
340     virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
341     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
342
343     virtual LayoutUnit minPreferredLogicalWidth() const OVERRIDE;
344     virtual LayoutUnit maxPreferredLogicalWidth() const OVERRIDE;
345
346     // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
347     // the border-box height/width like the regular height/width accessors on RenderBox.
348     // Right now, these are different than contentHeight/contentWidth because they still
349     // include the scrollbar height/width.
350     LayoutUnit overrideLogicalContentWidth() const;
351     LayoutUnit overrideLogicalContentHeight() const;
352     bool hasOverrideHeight() const;
353     bool hasOverrideWidth() const;
354     void setOverrideLogicalContentHeight(LayoutUnit);
355     void setOverrideLogicalContentWidth(LayoutUnit);
356     void clearOverrideSize();
357     void clearOverrideLogicalContentHeight();
358     void clearOverrideLogicalContentWidth();
359
360     LayoutUnit overrideContainingBlockContentLogicalWidth() const;
361     LayoutUnit overrideContainingBlockContentLogicalHeight() const;
362     bool hasOverrideContainingBlockLogicalWidth() const;
363     bool hasOverrideContainingBlockLogicalHeight() const;
364     void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
365     void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
366     void clearContainingBlockOverrideSize();
367     void clearOverrideContainingBlockContentLogicalHeight();
368
369     virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const OVERRIDE;
370
371     LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
372     LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
373     LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
374     LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
375
376     struct ComputedMarginValues {
377         ComputedMarginValues() { }
378
379         LayoutUnit m_before;
380         LayoutUnit m_after;
381         LayoutUnit m_start;
382         LayoutUnit m_end;
383     };
384     struct LogicalExtentComputedValues {
385         LogicalExtentComputedValues() { }
386
387         LayoutUnit m_extent;
388         LayoutUnit m_position;
389         ComputedMarginValues m_margins;
390     };
391     // Resolve auto margins in the inline direction of the containing block so that objects can be pushed to the start, middle or end
392     // of the containing block.
393     void computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
394
395     // Used to resolve margins in the containing block's block-flow direction.
396     void computeBlockDirectionMargins(const RenderBlock* containingBlock, LayoutUnit& marginBefore, LayoutUnit& marginAfter) const;
397     void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
398
399     virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
400
401     void positionLineBox(InlineBox*);
402
403     virtual InlineBox* createInlineBox();
404     void dirtyLineBoxes(bool fullLayout);
405
406     // For inline replaced elements, this function returns the inline box that owns us.  Enables
407     // the replaced RenderObject to quickly determine what line it is contained on and to easily
408     // iterate over structures on the line.
409     InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; }
410     void setInlineBoxWrapper(InlineBox*);
411     void deleteLineBoxWrapper();
412
413     virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
414     virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed = false) const OVERRIDE;
415     void repaintDuringLayoutIfMoved(const LayoutRect&);
416     virtual void repaintOverhangingFloats(bool paintAllDescendants);
417
418     virtual LayoutUnit containingBlockLogicalWidthForContent() const OVERRIDE;
419     LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
420
421     LayoutUnit containingBlockAvailableLineWidth() const;
422     LayoutUnit perpendicularContainingBlockLogicalHeight() const;
423
424     virtual void updateLogicalWidth();
425     virtual void updateLogicalHeight();
426     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
427
428     void computeLogicalWidth(LogicalExtentComputedValues&) const;
429
430     bool stretchesToViewport() const
431     {
432         return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isRoot() || isBody()) && !isInline();
433     }
434
435     virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
436     LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
437     LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
438
439     // Whether or not the element shrinks to its intrinsic width (rather than filling the width
440     // of a containing block).  HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
441     bool sizesLogicalWidthToFitContent(SizeType) const;
442
443     LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
444
445     LayoutUnit computeLogicalWidthUsing(SizeType, Length logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const;
446     LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
447     LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
448     LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
449     LayoutUnit computeReplacedLogicalWidthUsing(Length width) const;
450     LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred  = ComputeActual) const;
451     LayoutUnit computeReplacedLogicalHeightUsing(Length height) const;
452     LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
453
454     virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const;
455     virtual LayoutUnit computeReplacedLogicalHeight() const;
456
457     static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
458     LayoutUnit computePercentageLogicalHeight(const Length& height) const;
459
460     // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
461     virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
462     virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
463     LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
464
465     // There are a few cases where we need to refer specifically to the available physical width and available physical height.
466     // Relative positioning is one of those cases, since left/top offsets are physical.
467     LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
468     LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
469
470     virtual int verticalScrollbarWidth() const;
471     int horizontalScrollbarHeight() const;
472     int instrinsicScrollbarLogicalWidth() const;
473     int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
474     virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
475     bool canBeScrolledAndHasScrollableArea() const;
476     virtual bool canBeProgramaticallyScrolled() const;
477     virtual void autoscroll(const IntPoint&);
478     bool autoscrollInProgress() const;
479     bool canAutoscroll() const;
480     IntSize calculateAutoscrollDirection(const IntPoint& windowPoint) const;
481     static RenderBox* findAutoscrollable(RenderObject*);
482     virtual void stopAutoscroll() { }
483     virtual void panScroll(const IntPoint&);
484
485     bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
486     bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
487     bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
488
489     bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
490     bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
491     virtual bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
492     virtual bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
493     bool usesCompositedScrolling() const;
494
495     // Elements such as the <input> field override this to specify that they are scrollable
496     // outside the context of the CSS overflow style
497     virtual bool isIntristicallyScrollable(ScrollbarOrientation orientation) const { return false; }
498
499     bool hasUnsplittableScrollingOverflow() const;
500     bool isUnsplittableForPagination() const;
501
502     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
503
504     virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
505     LayoutRect clipRect(const LayoutPoint& location);
506     virtual bool hasControlClip() const { return false; }
507     virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
508     bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
509     void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
510
511     virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
512     virtual void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
513     virtual void paintMask(PaintInfo&, const LayoutPoint&);
514     virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
515     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) OVERRIDE;
516
517     // Called when a positioned object moves but doesn't necessarily change size.  A simplified layout is attempted
518     // that just updates the object's position. If the size does change, the object remains dirty.
519     bool tryLayoutDoingPositionedMovementOnly()
520     {
521         LayoutRectRecorder recorder(*this);
522         LayoutUnit oldWidth = width();
523         updateLogicalWidth();
524         // If we shrink to fit our width may have changed, so we still need full layout.
525         if (oldWidth != width())
526             return false;
527         updateLogicalHeight();
528         return true;
529     }
530
531     LayoutRect maskClipRect();
532
533     virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
534
535     void removeFloatingOrPositionedChildFromBlockLists();
536
537     RenderLayer* enclosingFloatPaintingLayer() const;
538
539     virtual int firstLineBoxBaseline() const { return -1; }
540     virtual int inlineBlockBaseline(LineDirectionMode) const { return -1; } // Returns -1 if we should skip this box when computing the baseline of an inline-block.
541
542     bool shrinkToAvoidFloats() const;
543     virtual bool avoidsFloats() const;
544
545     virtual void markForPaginationRelayoutIfNeeded(SubtreeLayoutScope&);
546
547     bool isWritingModeRoot() const { return !parent() || parent()->style()->writingMode() != style()->writingMode(); }
548
549     bool isDeprecatedFlexItem() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isDeprecatedFlexibleBox(); }
550     bool isFlexItemIncludingDeprecated() const { return !isInline() && !isFloatingOrOutOfFlowPositioned() && parent() && parent()->isFlexibleBoxIncludingDeprecated(); }
551
552     virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
553     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const OVERRIDE;
554
555     virtual LayoutUnit offsetLeft() const OVERRIDE;
556     virtual LayoutUnit offsetTop() const OVERRIDE;
557
558     LayoutPoint flipForWritingModeForChild(const RenderBox* child, const LayoutPoint&) const;
559     LayoutUnit flipForWritingMode(LayoutUnit position) const; // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
560     LayoutPoint flipForWritingMode(const LayoutPoint&) const;
561     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
562     LayoutSize flipForWritingMode(const LayoutSize&) const;
563     void flipForWritingMode(LayoutRect&) const;
564     FloatPoint flipForWritingMode(const FloatPoint&) const;
565     void flipForWritingMode(FloatRect&) const;
566     // These represent your location relative to your container as a physical offset.
567     // In layout related methods you almost always want the logical location (e.g. x() and y()).
568     LayoutPoint topLeftLocation() const;
569     LayoutSize topLeftLocationOffset() const;
570
571     LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
572     LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
573     LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
574     LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
575
576     bool hasRenderOverflow() const { return m_overflow; }
577     bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
578
579     virtual bool needsPreferredWidthsRecalculation() const;
580     virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { }
581
582     IntSize scrolledContentOffset() const;
583     LayoutSize cachedSizeForOverflowClip() const;
584     void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
585
586     virtual bool hasRelativeLogicalHeight() const;
587
588     bool hasHorizontalLayoutOverflow() const
589     {
590         if (!m_overflow)
591             return false;
592
593         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
594         LayoutRect noOverflowRect = this->noOverflowRect();
595         return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
596     }
597
598     bool hasVerticalLayoutOverflow() const
599     {
600         if (!m_overflow)
601             return false;
602
603         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
604         LayoutRect noOverflowRect = this->noOverflowRect();
605         return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
606     }
607
608     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
609     {
610         ASSERT_NOT_REACHED();
611         return 0;
612     }
613
614     bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
615
616     ShapeOutsideInfo* shapeOutsideInfo() const
617     {
618         return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
619     }
620
621     void markShapeOutsideDependentsForLayout()
622     {
623         if (isFloating())
624             removeFloatingOrPositionedChildFromBlockLists();
625     }
626
627 protected:
628     virtual void willBeDestroyed() OVERRIDE;
629
630     virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle) OVERRIDE;
631     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
632     virtual void updateFromStyle() OVERRIDE;
633
634     LayoutRect backgroundPaintedExtent() const;
635     virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
636     virtual bool computeBackgroundIsKnownToBeObscured() OVERRIDE;
637
638     void paintBackgroundWithBorderAndBoxShadow(PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance);
639     void paintBackground(const PaintInfo&, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone);
640
641     void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance, CompositeOperator, RenderObject* backgroundObject);
642     void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, BackgroundBleedAvoidance = BackgroundBleedNone, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0);
643
644     void paintMaskImages(const PaintInfo&, const LayoutRect&);
645     void paintBoxDecorationsWithRect(PaintInfo&, const LayoutPoint&, const LayoutRect&);
646
647     BackgroundBleedAvoidance determineBackgroundBleedAvoidance(GraphicsContext*) const;
648     bool backgroundHasOpaqueTopLayer() const;
649
650     void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
651
652     LayoutUnit computeIntrinsicLogicalWidthUsing(Length logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
653     LayoutUnit computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
654
655     virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
656
657     virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
658     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const OVERRIDE;
659
660     void paintRootBoxFillLayers(const PaintInfo&);
661
662     RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
663
664     virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
665     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const OVERRIDE;
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     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