Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / RenderBox.h
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22
23 #ifndef RenderBox_h
24 #define RenderBox_h
25
26 #include "core/rendering/RenderBoxModelObject.h"
27 #include "core/rendering/RenderOverflow.h"
28 #include "core/rendering/shapes/ShapeOutsideInfo.h"
29 #include "platform/scroll/ScrollTypes.h"
30
31 namespace blink {
32
33 struct PaintInfo;
34
35 enum SizeType { MainOrPreferredSize, MinSize, MaxSize };
36 enum AvailableLogicalHeightType { ExcludeMarginBorderPadding, IncludeMarginBorderPadding };
37 enum OverlayScrollbarSizeRelevancy { IgnoreOverlayScrollbarSize, IncludeOverlayScrollbarSize };
38 enum MarginDirection { BlockDirection, InlineDirection };
39
40 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
41
42 enum ScrollOffsetClamping {
43     ScrollOffsetUnclamped,
44     ScrollOffsetClamped
45 };
46
47 struct RenderBoxRareData {
48     WTF_MAKE_NONCOPYABLE(RenderBoxRareData); WTF_MAKE_FAST_ALLOCATED;
49 public:
50     RenderBoxRareData()
51         : m_inlineBoxWrapper(0)
52         , m_overrideLogicalContentHeight(-1)
53         , m_overrideLogicalContentWidth(-1)
54         , m_previousBorderBoxSize(-1, -1)
55     {
56     }
57
58     // For inline replaced elements, the inline box that owns us.
59     InlineBox* m_inlineBoxWrapper;
60
61     LayoutUnit m_overrideLogicalContentHeight;
62     LayoutUnit m_overrideLogicalContentWidth;
63
64     // Set by RenderBox::updatePreviousBorderBoxSizeIfNeeded().
65     LayoutSize m_previousBorderBoxSize;
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 (isPositioned() || createsGroup() || hasClipPath() || hasTransformRelatedProperty() || hasHiddenBackface() || hasReflection() || style()->specifiesColumns() || !style()->hasAutoZIndex() || style()->shouldCompositeForCurrentAnimations())
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     void setX(LayoutUnit x) { m_frameRect.setX(x); }
99     void setY(LayoutUnit y) { m_frameRect.setY(y); }
100     void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
101     void setHeight(LayoutUnit height) { m_frameRect.setHeight(height); }
102
103     LayoutUnit logicalLeft() const { return style()->isHorizontalWritingMode() ? x() : y(); }
104     LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
105     LayoutUnit logicalTop() const { return style()->isHorizontalWritingMode() ? y() : x(); }
106     LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
107     LayoutUnit logicalWidth() const { return style()->isHorizontalWritingMode() ? width() : height(); }
108     LayoutUnit logicalHeight() const { return style()->isHorizontalWritingMode() ? height() : width(); }
109
110     LayoutUnit constrainLogicalWidthByMinMax(LayoutUnit, LayoutUnit, RenderBlock*) const;
111     LayoutUnit constrainLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
112     LayoutUnit constrainContentBoxLogicalHeightByMinMax(LayoutUnit logicalHeight, LayoutUnit intrinsicContentHeight) const;
113
114     int pixelSnappedLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedHeight() : pixelSnappedWidth(); }
115     int pixelSnappedLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedWidth() : pixelSnappedHeight(); }
116
117     void setLogicalLeft(LayoutUnit left)
118     {
119         if (style()->isHorizontalWritingMode())
120             setX(left);
121         else
122             setY(left);
123     }
124     void setLogicalTop(LayoutUnit top)
125     {
126         if (style()->isHorizontalWritingMode())
127             setY(top);
128         else
129             setX(top);
130     }
131     void setLogicalLocation(const LayoutPoint& location)
132     {
133         if (style()->isHorizontalWritingMode())
134             setLocation(location);
135         else
136             setLocation(location.transposedPoint());
137     }
138     void setLogicalWidth(LayoutUnit size)
139     {
140         if (style()->isHorizontalWritingMode())
141             setWidth(size);
142         else
143             setHeight(size);
144     }
145     void setLogicalHeight(LayoutUnit size)
146     {
147         if (style()->isHorizontalWritingMode())
148             setHeight(size);
149         else
150             setWidth(size);
151     }
152
153     LayoutPoint location() const { return m_frameRect.location(); }
154     LayoutSize locationOffset() const { return LayoutSize(x(), y()); }
155     LayoutSize size() const { return m_frameRect.size(); }
156     IntSize pixelSnappedSize() const { return m_frameRect.pixelSnappedSize(); }
157
158     void setLocation(const LayoutPoint& location) { m_frameRect.setLocation(location); }
159
160     void setSize(const LayoutSize& size) { m_frameRect.setSize(size); }
161     void move(LayoutUnit dx, LayoutUnit dy) { m_frameRect.move(dx, dy); }
162
163     LayoutRect frameRect() const { return m_frameRect; }
164     void setFrameRect(const LayoutRect& rect) { m_frameRect = rect; }
165
166     LayoutRect borderBoxRect() const { return LayoutRect(LayoutPoint(), size()); }
167     LayoutRect paddingBoxRect() const { return LayoutRect(borderLeft(), borderTop(), clientWidth(), clientHeight()); }
168     IntRect pixelSnappedBorderBoxRect() const { return IntRect(IntPoint(), m_frameRect.pixelSnappedSize()); }
169     virtual IntRect borderBoundingBox() const override final { return pixelSnappedBorderBoxRect(); }
170
171     // The content area of the box (excludes padding - and intrinsic padding for table cells, etc... - and border).
172     LayoutRect contentBoxRect() const { return LayoutRect(borderLeft() + paddingLeft(), borderTop() + paddingTop(), contentWidth(), contentHeight()); }
173     // The content box in absolute coords. Ignores transforms.
174     IntRect absoluteContentBox() const;
175     // The content box converted to absolute coords (taking transforms into account).
176     FloatQuad absoluteContentQuad() const;
177
178     // This returns the content area of the box (excluding padding and border). The only difference with contentBoxRect is that computedCSSContentBoxRect
179     // does include the intrinsic padding in the content box as this is what some callers expect (like getComputedStyle).
180     LayoutRect computedCSSContentBoxRect() const { return LayoutRect(borderLeft() + computedCSSPaddingLeft(), borderTop() + computedCSSPaddingTop(), clientWidth() - computedCSSPaddingLeft() - computedCSSPaddingRight(), clientHeight() - computedCSSPaddingTop() - computedCSSPaddingBottom()); }
181
182     virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const override;
183
184     // Use this with caution! No type checking is done!
185     RenderBox* previousSiblingBox() const;
186     RenderBox* nextSiblingBox() const;
187     RenderBox* parentBox() const;
188
189     bool canResize() const;
190
191     // Visual and layout overflow are in the coordinate space of the box.  This means that they aren't purely physical directions.
192     // For horizontal-tb and vertical-lr they will match physical directions, but for horizontal-bt and vertical-rl, the top/bottom and left/right
193     // respectively are flipped when compared to their physical counterparts.  For example minX is on the left in vertical-lr,
194     // but it is on the right in vertical-rl.
195     LayoutRect noOverflowRect() const;
196     LayoutRect layoutOverflowRect() const { return m_overflow ? m_overflow->layoutOverflowRect() : noOverflowRect(); }
197     IntRect pixelSnappedLayoutOverflowRect() const { return pixelSnappedIntRect(layoutOverflowRect()); }
198     LayoutSize maxLayoutOverflow() const { return LayoutSize(layoutOverflowRect().maxX(), layoutOverflowRect().maxY()); }
199     LayoutUnit logicalLeftLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().x() : layoutOverflowRect().y(); }
200     LayoutUnit logicalRightLayoutOverflow() const { return style()->isHorizontalWritingMode() ? layoutOverflowRect().maxX() : layoutOverflowRect().maxY(); }
201
202     virtual LayoutRect visualOverflowRect() const { return m_overflow ? m_overflow->visualOverflowRect() : borderBoxRect(); }
203     LayoutUnit logicalLeftVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().x() : visualOverflowRect().y(); }
204     LayoutUnit logicalRightVisualOverflow() const { return style()->isHorizontalWritingMode() ? visualOverflowRect().maxX() : visualOverflowRect().maxY(); }
205
206     LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
207
208     void addLayoutOverflow(const LayoutRect&);
209     void addVisualOverflow(const LayoutRect&);
210
211     // Clipped by the contents clip, if one exists.
212     void addContentsVisualOverflow(const LayoutRect&);
213
214     void addVisualEffectOverflow();
215     LayoutBoxExtent computeVisualEffectOverflowExtent() const;
216     void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
217     void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
218     void clearLayoutOverflow();
219     void clearAllOverflows() { m_overflow.clear(); }
220
221     void updateLayerTransformAfterLayout();
222
223     LayoutUnit contentWidth() const { return clientWidth() - paddingLeft() - paddingRight(); }
224     LayoutUnit contentHeight() const { return clientHeight() - paddingTop() - paddingBottom(); }
225     LayoutUnit contentLogicalWidth() const { return style()->isHorizontalWritingMode() ? contentWidth() : contentHeight(); }
226     LayoutUnit contentLogicalHeight() const { return style()->isHorizontalWritingMode() ? contentHeight() : contentWidth(); }
227
228     // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
229     // to return the remaining width on a given line (and the height of a single line).
230     virtual LayoutUnit offsetWidth() const override { return width(); }
231     virtual LayoutUnit offsetHeight() const override { return height(); }
232
233     virtual int pixelSnappedOffsetWidth() const override final;
234     virtual int pixelSnappedOffsetHeight() const override final;
235
236     // More IE extensions.  clientWidth and clientHeight represent the interior of an object
237     // excluding border and scrollbar.  clientLeft/Top are just the borderLeftWidth and borderTopWidth.
238     LayoutUnit clientLeft() const { return borderLeft() + (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? verticalScrollbarWidth() : 0); }
239     LayoutUnit clientTop() const { return borderTop(); }
240     LayoutUnit clientWidth() const;
241     LayoutUnit clientHeight() const;
242     LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }
243     LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }
244     LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); }
245     LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); }
246
247     int pixelSnappedClientWidth() const;
248     int pixelSnappedClientHeight() const;
249
250     // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the
251     // object has overflow:hidden/scroll/auto specified and also has overflow.
252     // scrollLeft/Top return the current scroll position.  These methods are virtual so that objects like
253     // textareas can scroll shadow content (but pretend that they are the objects that are
254     // scrolling).
255     virtual LayoutUnit scrollLeft() const;
256     virtual LayoutUnit scrollTop() const;
257     virtual LayoutUnit scrollWidth() const;
258     virtual LayoutUnit scrollHeight() const;
259     int pixelSnappedScrollWidth() const;
260     int pixelSnappedScrollHeight() const;
261     virtual void setScrollLeft(LayoutUnit);
262     virtual void setScrollTop(LayoutUnit);
263
264     void scrollToOffset(const DoubleSize&);
265     void scrollByRecursively(const DoubleSize& delta, ScrollOffsetClamping = ScrollOffsetUnclamped);
266     void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
267
268     virtual LayoutUnit marginTop() const override { return m_marginBox.top(); }
269     virtual LayoutUnit marginBottom() const override { return m_marginBox.bottom(); }
270     virtual LayoutUnit marginLeft() const override { return m_marginBox.left(); }
271     virtual LayoutUnit marginRight() const override { return m_marginBox.right(); }
272     void setMarginTop(LayoutUnit margin) { m_marginBox.setTop(margin); }
273     void setMarginBottom(LayoutUnit margin) { m_marginBox.setBottom(margin); }
274     void setMarginLeft(LayoutUnit margin) { m_marginBox.setLeft(margin); }
275     void setMarginRight(LayoutUnit margin) { m_marginBox.setRight(margin); }
276
277     LayoutUnit marginLogicalLeft() const { return m_marginBox.logicalLeft(style()->writingMode()); }
278     LayoutUnit marginLogicalRight() const { return m_marginBox.logicalRight(style()->writingMode()); }
279
280     virtual LayoutUnit marginBefore(const RenderStyle* overrideStyle = 0) const override final { return m_marginBox.before((overrideStyle ? overrideStyle : style())->writingMode()); }
281     virtual LayoutUnit marginAfter(const RenderStyle* overrideStyle = 0) const override final { return m_marginBox.after((overrideStyle ? overrideStyle : style())->writingMode()); }
282     virtual LayoutUnit marginStart(const RenderStyle* overrideStyle = 0) const override final
283     {
284         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
285         return m_marginBox.start(styleToUse->writingMode(), styleToUse->direction());
286     }
287     virtual LayoutUnit marginEnd(const RenderStyle* overrideStyle = 0) const override final
288     {
289         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
290         return m_marginBox.end(styleToUse->writingMode(), styleToUse->direction());
291     }
292     void setMarginBefore(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setBefore((overrideStyle ? overrideStyle : style())->writingMode(), value); }
293     void setMarginAfter(LayoutUnit value, const RenderStyle* overrideStyle = 0) { m_marginBox.setAfter((overrideStyle ? overrideStyle : style())->writingMode(), value); }
294     void setMarginStart(LayoutUnit value, const RenderStyle* overrideStyle = 0)
295     {
296         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
297         m_marginBox.setStart(styleToUse->writingMode(), styleToUse->direction(), value);
298     }
299     void setMarginEnd(LayoutUnit value, const RenderStyle* overrideStyle = 0)
300     {
301         const RenderStyle* styleToUse = overrideStyle ? overrideStyle : style();
302         m_marginBox.setEnd(styleToUse->writingMode(), styleToUse->direction(), value);
303     }
304
305     // The following functions are used to implement collapsing margins.
306     // All objects know their maximal positive and negative margins.  The
307     // formula for computing a collapsed margin is |maxPosMargin| - |maxNegmargin|.
308     // For a non-collapsing box, such as a leaf element, this formula will simply return
309     // the margin of the element.  Blocks override the maxMarginBefore and maxMarginAfter
310     // methods.
311     virtual bool isSelfCollapsingBlock() const { return false; }
312     virtual LayoutUnit collapsedMarginBefore() const { return marginBefore(); }
313     virtual LayoutUnit collapsedMarginAfter() const { return marginAfter(); }
314
315     virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const override;
316     virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const override;
317
318     int reflectionOffset() const;
319     // Given a rect in the object's coordinate space, returns the corresponding rect in the reflection.
320     LayoutRect reflectedRect(const LayoutRect&) const;
321
322     virtual void layout() override;
323     virtual void paint(PaintInfo&, const LayoutPoint&) override;
324     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
325
326     virtual LayoutUnit minPreferredLogicalWidth() const override;
327     virtual LayoutUnit maxPreferredLogicalWidth() const override;
328
329     // FIXME: We should rename these back to overrideLogicalHeight/Width and have them store
330     // the border-box height/width like the regular height/width accessors on RenderBox.
331     // Right now, these are different than contentHeight/contentWidth because they still
332     // include the scrollbar height/width.
333     LayoutUnit overrideLogicalContentWidth() const;
334     LayoutUnit overrideLogicalContentHeight() const;
335     bool hasOverrideHeight() const;
336     bool hasOverrideWidth() const;
337     void setOverrideLogicalContentHeight(LayoutUnit);
338     void setOverrideLogicalContentWidth(LayoutUnit);
339     void clearOverrideSize();
340     void clearOverrideLogicalContentHeight();
341     void clearOverrideLogicalContentWidth();
342
343     LayoutUnit overrideContainingBlockContentLogicalWidth() const;
344     LayoutUnit overrideContainingBlockContentLogicalHeight() const;
345     bool hasOverrideContainingBlockLogicalWidth() const;
346     bool hasOverrideContainingBlockLogicalHeight() const;
347     void setOverrideContainingBlockContentLogicalWidth(LayoutUnit);
348     void setOverrideContainingBlockContentLogicalHeight(LayoutUnit);
349     void clearContainingBlockOverrideSize();
350     void clearOverrideContainingBlockContentLogicalHeight();
351
352     virtual LayoutSize offsetFromContainer(const RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const override;
353
354     LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
355     LayoutUnit adjustBorderBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
356     LayoutUnit adjustContentBoxLogicalWidthForBoxSizing(LayoutUnit width) const;
357     LayoutUnit adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit height) const;
358
359     struct ComputedMarginValues {
360         ComputedMarginValues() { }
361
362         LayoutUnit m_before;
363         LayoutUnit m_after;
364         LayoutUnit m_start;
365         LayoutUnit m_end;
366     };
367     struct LogicalExtentComputedValues {
368         LogicalExtentComputedValues() { }
369
370         LayoutUnit m_extent;
371         LayoutUnit m_position;
372         ComputedMarginValues m_margins;
373     };
374     // Resolve auto margins in the chosen direction of the containing block so that objects can be pushed to the start, middle or end
375     // of the containing block.
376     void computeMarginsForDirection(MarginDirection forDirection, const RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd, Length marginStartLength, Length marginStartEnd) const;
377
378     // Used to resolve margins in the containing block's block-flow direction.
379     void computeAndSetBlockDirectionMargins(const RenderBlock* containingBlock);
380
381     virtual LayoutUnit offsetFromLogicalTopOfFirstPage() const;
382
383     void positionLineBox(InlineBox*);
384     void moveWithEdgeOfInlineContainerIfNecessary(bool isHorizontal);
385
386     virtual InlineBox* createInlineBox();
387     void dirtyLineBoxes(bool fullLayout);
388
389     // For inline replaced elements, this function returns the inline box that owns us.  Enables
390     // the replaced RenderObject to quickly determine what line it is contained on and to easily
391     // iterate over structures on the line.
392     InlineBox* inlineBoxWrapper() const { return m_rareData ? m_rareData->m_inlineBoxWrapper : 0; }
393     void setInlineBoxWrapper(InlineBox*);
394     void deleteLineBoxWrapper();
395
396     virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const override;
397     virtual void mapRectToPaintInvalidationBacking(const RenderLayerModelObject* paintInvalidationContainer, LayoutRect&, const PaintInvalidationState*) const override;
398     virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants);
399
400     virtual LayoutUnit containingBlockLogicalWidthForContent() const override;
401     LayoutUnit containingBlockLogicalHeightForContent(AvailableLogicalHeightType) const;
402
403     LayoutUnit containingBlockAvailableLineWidth() const;
404     LayoutUnit perpendicularContainingBlockLogicalHeight() const;
405
406     virtual void updateLogicalWidth();
407     virtual void updateLogicalHeight();
408     virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const;
409
410     void computeLogicalWidth(LogicalExtentComputedValues&) const;
411
412     bool stretchesToViewport() const
413     {
414         return document().inQuirksMode() && style()->logicalHeight().isAuto() && !isFloatingOrOutOfFlowPositioned() && (isDocumentElement() || isBody()) && !isInline();
415     }
416
417     virtual LayoutSize intrinsicSize() const { return LayoutSize(); }
418     LayoutUnit intrinsicLogicalWidth() const { return style()->isHorizontalWritingMode() ? intrinsicSize().width() : intrinsicSize().height(); }
419     LayoutUnit intrinsicLogicalHeight() const { return style()->isHorizontalWritingMode() ? intrinsicSize().height() : intrinsicSize().width(); }
420     virtual LayoutUnit intrinsicContentLogicalHeight() const { return m_intrinsicContentLogicalHeight; }
421
422     // Whether or not the element shrinks to its intrinsic width (rather than filling the width
423     // of a containing block).  HTML4 buttons, <select>s, <input>s, legends, and floating/compact elements do this.
424     bool sizesLogicalWidthToFitContent(const Length& logicalWidth) const;
425
426     LayoutUnit shrinkLogicalWidthToAvoidFloats(LayoutUnit childMarginStart, LayoutUnit childMarginEnd, const RenderBlockFlow* cb) const;
427
428     LayoutUnit computeLogicalWidthUsing(SizeType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* containingBlock) const;
429     LayoutUnit computeLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
430     LayoutUnit computeContentLogicalHeight(const Length& height, LayoutUnit intrinsicContentHeight) const;
431     LayoutUnit computeContentAndScrollbarLogicalHeightUsing(const Length& height, LayoutUnit intrinsicContentHeight) const;
432     LayoutUnit computeReplacedLogicalWidthUsing(const Length& width) const;
433     LayoutUnit computeReplacedLogicalWidthRespectingMinMaxWidth(LayoutUnit logicalWidth, ShouldComputePreferred  = ComputeActual) const;
434     LayoutUnit computeReplacedLogicalHeightUsing(const Length& height) const;
435     LayoutUnit computeReplacedLogicalHeightRespectingMinMaxHeight(LayoutUnit logicalHeight) const;
436
437     virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const;
438     virtual LayoutUnit computeReplacedLogicalHeight() const;
439
440     static bool percentageLogicalHeightIsResolvableFromBlock(const RenderBlock* containingBlock, bool outOfFlowPositioned);
441     LayoutUnit computePercentageLogicalHeight(const Length& height) const;
442
443     // Block flows subclass availableWidth/Height to handle multi column layout (shrinking the width/height available to children when laying out.)
444     virtual LayoutUnit availableLogicalWidth() const { return contentLogicalWidth(); }
445     virtual LayoutUnit availableLogicalHeight(AvailableLogicalHeightType) const;
446     LayoutUnit availableLogicalHeightUsing(const Length&, AvailableLogicalHeightType) const;
447
448     // There are a few cases where we need to refer specifically to the available physical width and available physical height.
449     // Relative positioning is one of those cases, since left/top offsets are physical.
450     LayoutUnit availableWidth() const { return style()->isHorizontalWritingMode() ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding); }
451     LayoutUnit availableHeight() const { return style()->isHorizontalWritingMode() ? availableLogicalHeight(IncludeMarginBorderPadding) : availableLogicalWidth(); }
452
453     virtual int verticalScrollbarWidth() const;
454     int horizontalScrollbarHeight() const;
455     int instrinsicScrollbarLogicalWidth() const;
456     int scrollbarLogicalHeight() const { return style()->isHorizontalWritingMode() ? horizontalScrollbarHeight() : verticalScrollbarWidth(); }
457     virtual bool scroll(ScrollDirection, ScrollGranularity, float delta = 1);
458     bool canBeScrolledAndHasScrollableArea() const;
459     virtual bool canBeProgramaticallyScrolled() const;
460     virtual void autoscroll(const IntPoint&);
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() && pixelSnappedScrollWidth() != pixelSnappedClientWidth(); }
472     bool hasScrollableOverflowY() const { return scrollsOverflowY() && pixelSnappedScrollHeight() != pixelSnappedClientHeight(); }
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) override;
485
486     virtual LayoutRect overflowClipRect(const LayoutPoint& location, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize);
487     LayoutRect clipRect(const LayoutPoint& location);
488     virtual bool hasControlClip() const { return false; }
489     virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
490
491     virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
492     virtual void paintBoxDecorationBackground(PaintInfo&, const LayoutPoint&);
493     virtual void paintMask(PaintInfo&, const LayoutPoint&);
494     virtual void paintClippingMask(PaintInfo&, const LayoutPoint&);
495     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) override;
496
497     LayoutRect borderBoxAfterUpdatingLogicalWidth(const LayoutUnit& logicalTop);
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         LayoutUnit newWidth = borderBoxAfterUpdatingLogicalWidth(logicalTop()).width();
505         // If we shrink to fit our width may have changed, so we still need full layout.
506         // FIXME: We check for potential change of width when deciding to set needsPositionedMovementLayout.
507         // So either that check or this one is unnecessary, probably the former. crbug.com/428050
508         if (oldWidth != newWidth)
509             return false;
510         updateLogicalHeight();
511         return true;
512     }
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 override;
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 WARN_UNUSED_RETURN
541     {
542         // The offset is in the block direction (y for horizontal writing modes, x for vertical writing modes).
543         if (!UNLIKELY(hasFlippedBlocksWritingMode()))
544             return position;
545         return logicalHeight() - position;
546     }
547     LayoutPoint flipForWritingMode(const LayoutPoint& position) const WARN_UNUSED_RETURN
548     {
549         if (!UNLIKELY(hasFlippedBlocksWritingMode()))
550             return position;
551         return isHorizontalWritingMode() ? LayoutPoint(position.x(), height() - position.y()) : LayoutPoint(width() - position.x(), position.y());
552     }
553     LayoutPoint flipForWritingModeIncludingColumns(const LayoutPoint&) const;
554     LayoutSize flipForWritingMode(const LayoutSize& offset) const WARN_UNUSED_RETURN
555     {
556         if (!UNLIKELY(hasFlippedBlocksWritingMode()))
557             return offset;
558         return isHorizontalWritingMode() ? LayoutSize(offset.width(), height() - offset.height()) : LayoutSize(width() - offset.width(), offset.height());
559     }
560     void flipForWritingMode(LayoutRect& rect) const
561     {
562         if (!UNLIKELY(hasFlippedBlocksWritingMode()))
563             return;
564         if (isHorizontalWritingMode())
565             rect.setY(height() - rect.maxY());
566         else
567             rect.setX(width() - rect.maxX());
568     }
569     FloatPoint flipForWritingMode(const FloatPoint& position) const WARN_UNUSED_RETURN
570     {
571         if (!UNLIKELY(hasFlippedBlocksWritingMode()))
572             return position;
573         return isHorizontalWritingMode() ? FloatPoint(position.x(), height() - position.y()) : FloatPoint(width() - position.x(), position.y());
574     }
575     void flipForWritingMode(FloatRect& rect) const
576     {
577         if (!UNLIKELY(hasFlippedBlocksWritingMode()))
578             return;
579         if (isHorizontalWritingMode())
580             rect.setY(height() - rect.maxY());
581         else
582             rect.setX(width() - rect.maxX());
583     }
584     // These represent your location relative to your container as a physical offset.
585     // In layout related methods you almost always want the logical location (e.g. x() and y()).
586     LayoutPoint topLeftLocation() const;
587     LayoutSize topLeftLocationOffset() const;
588
589     LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
590     LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;
591     LayoutRect logicalLayoutOverflowRectForPropagation(RenderStyle*) const;
592     LayoutRect layoutOverflowRectForPropagation(RenderStyle*) const;
593
594     bool hasRenderOverflow() const { return m_overflow; }
595     bool hasVisualOverflow() const { return m_overflow && !borderBoxRect().contains(m_overflow->visualOverflowRect()); }
596
597     virtual bool needsPreferredWidthsRecalculation() const;
598     virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */) const { }
599
600     IntSize scrolledContentOffset() const;
601     void applyCachedClipAndScrollOffsetForPaintInvalidation(LayoutRect& paintRect) const;
602
603     virtual bool hasRelativeLogicalHeight() const;
604
605     bool hasHorizontalLayoutOverflow() const
606     {
607         if (!m_overflow)
608             return false;
609
610         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
611         LayoutRect noOverflowRect = this->noOverflowRect();
612         return layoutOverflowRect.x() < noOverflowRect.x() || layoutOverflowRect.maxX() > noOverflowRect.maxX();
613     }
614
615     bool hasVerticalLayoutOverflow() const
616     {
617         if (!m_overflow)
618             return false;
619
620         LayoutRect layoutOverflowRect = m_overflow->layoutOverflowRect();
621         LayoutRect noOverflowRect = this->noOverflowRect();
622         return layoutOverflowRect.y() < noOverflowRect.y() || layoutOverflowRect.maxY() > noOverflowRect.maxY();
623     }
624
625     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject*) const
626     {
627         ASSERT_NOT_REACHED();
628         return 0;
629     }
630
631     bool hasSameDirectionAs(const RenderBox* object) const { return style()->direction() == object->style()->direction(); }
632
633     ShapeOutsideInfo* shapeOutsideInfo() const
634     {
635         return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : 0;
636     }
637
638     void markShapeOutsideDependentsForLayout()
639     {
640         if (isFloating())
641             removeFloatingOrPositionedChildFromBlockLists();
642     }
643
644     bool backgroundHasOpaqueTopLayer() const;
645
646     void updateIntrinsicContentLogicalHeight(LayoutUnit intrinsicContentLogicalHeight) const { m_intrinsicContentLogicalHeight = intrinsicContentLogicalHeight; }
647 protected:
648     virtual void willBeDestroyed() override;
649
650
651     virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle) override;
652     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
653     virtual void updateFromStyle() override;
654
655     // Returns false if it could not cheaply compute the extent (e.g. fixed background), in which case the returned rect may be incorrect.
656     // FIXME: make this a const method once the RenderBox reference in BoxPainter is const.
657     bool getBackgroundPaintedExtent(LayoutRect&);
658     virtual bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const;
659     virtual bool computeBackgroundIsKnownToBeObscured() override;
660
661     void computePositionedLogicalWidth(LogicalExtentComputedValues&) const;
662
663     LayoutUnit computeIntrinsicLogicalWidthUsing(const Length& logicalWidthLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const;
664     LayoutUnit computeIntrinsicLogicalContentHeightUsing(const Length& logicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPadding) const;
665
666     virtual bool shouldComputeSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); }
667
668     virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const override;
669     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
670
671     RenderObject* splitAnonymousBoxesAroundChild(RenderObject* beforeChild);
672
673     virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentCompositedLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const override;
674     virtual void computeSelfHitTestRects(Vector<LayoutRect>&, const LayoutPoint& layerOffset) const override;
675
676     virtual PaintInvalidationReason paintInvalidationReason(const RenderLayerModelObject& paintInvalidationContainer,
677         const LayoutRect& oldBounds, const LayoutPoint& oldPositionFromPaintInvalidationContainer,
678         const LayoutRect& newBounds, const LayoutPoint& newPositionFromPaintInvalidationContainer) const override;
679     virtual void incrementallyInvalidatePaint(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect& oldBounds, const LayoutRect& newBounds, const LayoutPoint& positionFromPaintInvalidationContainer) override;
680
681     virtual void clearPaintInvalidationState(const PaintInvalidationState&) override;
682 #if ENABLE(ASSERT)
683     virtual bool paintInvalidationStateIsDirty() const override;
684 #endif
685
686 private:
687     void invalidatePaintRectClippedByOldAndNewBounds(const RenderLayerModelObject& paintInvalidationContainer, const LayoutRect&, const LayoutRect& oldBounds, const LayoutRect& newBounds);
688
689     void updateShapeOutsideInfoAfterStyleChange(const RenderStyle&, const RenderStyle* oldStyle);
690     void updateGridPositionAfterStyleChange(const RenderStyle*);
691
692     bool autoWidthShouldFitContent() const;
693     void shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues&) const;
694
695     // Returns true if we queued up a paint invalidation.
696     bool paintInvalidationLayerRectsForImage(WrappedImagePtr, const FillLayer&, bool drawingBackground);
697
698     bool skipContainingBlockForPercentHeightCalculation(const RenderBox* containingBlock) const;
699
700     LayoutUnit containingBlockLogicalWidthForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
701     LayoutUnit containingBlockLogicalHeightForPositioned(const RenderBoxModelObject* containingBlock, bool checkForPerpendicularWritingMode = true) const;
702
703     void computePositionedLogicalHeight(LogicalExtentComputedValues&) const;
704     void computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection,
705                                             LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
706                                             const Length& logicalLeft, const Length& logicalRight, const Length& marginLogicalLeft,
707                                             const Length& marginLogicalRight, LogicalExtentComputedValues&) const;
708     void computePositionedLogicalHeightUsing(Length logicalHeightLength, const RenderBoxModelObject* containerBlock,
709                                              LayoutUnit containerLogicalHeight, LayoutUnit bordersPlusPadding, LayoutUnit logicalHeight,
710                                              const Length& logicalTop, const Length& logicalBottom, const Length& marginLogicalTop,
711                                              const Length& marginLogicalBottom, LogicalExtentComputedValues&) const;
712
713     void computePositionedLogicalHeightReplaced(LogicalExtentComputedValues&) const;
714     void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
715
716     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth) const;
717     LayoutUnit fillAvailableMeasure(LayoutUnit availableLogicalWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const;
718
719     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
720
721     // This function calculates the minimum and maximum preferred widths for an object.
722     // These values are used in shrink-to-fit layout systems.
723     // These include tables, positioned objects, floats and flexible boxes.
724     virtual void computePreferredLogicalWidths() { clearPreferredLogicalWidthsDirty(); }
725
726     RenderBoxRareData& ensureRareData()
727     {
728         if (!m_rareData)
729             m_rareData = adoptPtr(new RenderBoxRareData());
730         return *m_rareData.get();
731     }
732
733     void savePreviousBorderBoxSizeIfNeeded();
734     LayoutSize computePreviousBorderBoxSize(const LayoutSize& previousBoundsSize) const;
735
736     bool logicalHeightComputesAsNone(SizeType) const;
737
738     virtual PaintInvalidationReason invalidatePaintIfNeeded(const PaintInvalidationState&, const RenderLayerModelObject& newPaintInvalidationContainer) override final;
739
740     bool isBox() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
741
742     // The width/height of the contents + borders + padding.  The x/y location is relative to our container (which is not always our parent).
743     LayoutRect m_frameRect;
744
745     // Our intrinsic height, used for min-height: min-content etc. Maintained by
746     // updateLogicalHeight. This is logicalHeight() before it is clamped to
747     // min/max.
748     mutable LayoutUnit m_intrinsicContentLogicalHeight;
749
750     void inflatePaintInvalidationRectForReflectionAndFilter(LayoutRect&) const;
751
752     bool hasNonCompositedScrollbars() const;
753
754 protected:
755     LayoutBoxExtent m_marginBox;
756
757     // The preferred logical width of the element if it were to break its lines at every possible opportunity.
758     LayoutUnit m_minPreferredLogicalWidth;
759
760     // The preferred logical width of the element if it never breaks any lines at all.
761     LayoutUnit m_maxPreferredLogicalWidth;
762
763     // Our overflow information.
764     OwnPtr<RenderOverflow> m_overflow;
765
766 private:
767     OwnPtr<RenderBoxRareData> m_rareData;
768 };
769
770 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBox, isBox());
771
772 inline RenderBox* RenderBox::previousSiblingBox() const
773 {
774     return toRenderBox(previousSibling());
775 }
776
777 inline RenderBox* RenderBox::nextSiblingBox() const
778 {
779     return toRenderBox(nextSibling());
780 }
781
782 inline RenderBox* RenderBox::parentBox() const
783 {
784     return toRenderBox(parent());
785 }
786
787 inline RenderBox* RenderBox::firstChildBox() const
788 {
789     return toRenderBox(slowFirstChild());
790 }
791
792 inline RenderBox* RenderBox::lastChildBox() const
793 {
794     return toRenderBox(slowLastChild());
795 }
796
797 inline void RenderBox::setInlineBoxWrapper(InlineBox* boxWrapper)
798 {
799     if (boxWrapper) {
800         ASSERT(!inlineBoxWrapper());
801         // m_inlineBoxWrapper should already be 0. Deleting it is a safeguard against security issues.
802         // Otherwise, there will two line box wrappers keeping the reference to this renderer, and
803         // only one will be notified when the renderer is getting destroyed. The second line box wrapper
804         // will keep a stale reference.
805         if (UNLIKELY(inlineBoxWrapper() != 0))
806             deleteLineBoxWrapper();
807     }
808
809     ensureRareData().m_inlineBoxWrapper = boxWrapper;
810 }
811
812 } // namespace blink
813
814 #endif // RenderBox_h