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