1/*
2 * Copyright (C) 2007 Apple Inc.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef LayoutState_h
27#define LayoutState_h
28
29#include "ColumnInfo.h"
30#include "LayoutRect.h"
31#include <wtf/HashMap.h>
32#include <wtf/Noncopyable.h>
33
34namespace WebCore {
35
36class RenderArena;
37class RenderBlock;
38class RenderBox;
39class RenderObject;
40class RenderFlowThread;
41#if ENABLE(CSS_SHAPES)
42class ShapeInsideInfo;
43#endif
44
45class LayoutState {
46    WTF_MAKE_NONCOPYABLE(LayoutState);
47public:
48    LayoutState()
49        : m_clipped(false)
50        , m_isPaginated(false)
51        , m_pageLogicalHeightChanged(false)
52#if !ASSERT_DISABLED && ENABLE(SATURATED_LAYOUT_ARITHMETIC)
53        , m_layoutDeltaXSaturated(false)
54        , m_layoutDeltaYSaturated(false)
55#endif
56        , m_columnInfo(0)
57        , m_lineGrid(0)
58        , m_next(0)
59#if ENABLE(CSS_SHAPES)
60        , m_shapeInsideInfo(0)
61#endif
62        , m_pageLogicalHeight(0)
63#ifndef NDEBUG
64        , m_renderer(0)
65#endif
66    {
67    }
68
69    LayoutState(LayoutState*, RenderBox*, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged, ColumnInfo*);
70    LayoutState(RenderObject*);
71
72    void destroy(RenderArena*);
73
74    // Overloaded new operator.
75    void* operator new(size_t, RenderArena*);
76
77    // Overridden to prevent the normal delete from being called.
78    void operator delete(void*, size_t);
79
80    void clearPaginationInformation();
81    bool isPaginatingColumns() const { return m_columnInfo && m_columnInfo->paginationUnit() == ColumnInfo::Column; }
82    bool isPaginated() const { return m_isPaginated; }
83
84    // The page logical offset is the object's offset from the top of the page in the page progression
85    // direction (so an x-offset in vertical text and a y-offset for horizontal text).
86    LayoutUnit pageLogicalOffset(RenderBox*, LayoutUnit childLogicalOffset) const;
87
88    void addForcedColumnBreak(RenderBox*, LayoutUnit childLogicalOffset);
89
90    LayoutUnit pageLogicalHeight() const { return m_pageLogicalHeight; }
91    bool pageLogicalHeightChanged() const { return m_pageLogicalHeightChanged; }
92
93    RenderBlock* lineGrid() const { return m_lineGrid; }
94    LayoutSize lineGridOffset() const { return m_lineGridOffset; }
95    LayoutSize lineGridPaginationOrigin() const { return m_lineGridPaginationOrigin; }
96
97    LayoutSize layoutOffset() const { return m_layoutOffset; }
98
99    bool needsBlockDirectionLocationSetBeforeLayout() const { return m_lineGrid || (m_isPaginated && m_pageLogicalHeight); }
100
101#if ENABLE(CSS_SHAPES)
102    ShapeInsideInfo* shapeInsideInfo() const { return m_shapeInsideInfo; }
103#endif
104private:
105    // The normal operator new is disallowed.
106    void* operator new(size_t) throw();
107
108    void propagateLineGridInfo(RenderBox*);
109    void establishLineGrid(RenderBlock*);
110
111    void computeLineGridPaginationOrigin(RenderBox*);
112
113public:
114    // Do not add anything apart from bitfields until after m_columnInfo. See https://bugs.webkit.org/show_bug.cgi?id=100173
115    bool m_clipped:1;
116    bool m_isPaginated:1;
117    // If our page height has changed, this will force all blocks to relayout.
118    bool m_pageLogicalHeightChanged:1;
119#if !ASSERT_DISABLED && ENABLE(SATURATED_LAYOUT_ARITHMETIC)
120    bool m_layoutDeltaXSaturated:1;
121    bool m_layoutDeltaYSaturated:1;
122#endif
123    // If the enclosing pagination model is a column model, then this will store column information for easy retrieval/manipulation.
124    ColumnInfo* m_columnInfo;
125    // The current line grid that we're snapping to and the offset of the start of the grid.
126    RenderBlock* m_lineGrid;
127    LayoutState* m_next;
128#if ENABLE(CSS_SHAPES)
129    ShapeInsideInfo* m_shapeInsideInfo;
130#endif
131
132    // FIXME: Distinguish between the layout clip rect and the paint clip rect which may be larger,
133    // e.g., because of composited scrolling.
134    LayoutRect m_clipRect;
135
136    // x/y offset from container. Includes relative positioning and scroll offsets.
137    LayoutSize m_paintOffset;
138    // x/y offset from container. Does not include relative positioning or scroll offsets.
139    LayoutSize m_layoutOffset;
140    // Transient offset from the final position of the object
141    // used to ensure that repaints happen in the correct place.
142    // This is a total delta accumulated from the root.
143    LayoutSize m_layoutDelta;
144
145    // The current page height for the pagination model that encloses us.
146    LayoutUnit m_pageLogicalHeight;
147    // The offset of the start of the first page in the nearest enclosing pagination model.
148    LayoutSize m_pageOffset;
149    LayoutSize m_lineGridOffset;
150    LayoutSize m_lineGridPaginationOrigin;
151
152#ifndef NDEBUG
153    RenderObject* m_renderer;
154#endif
155};
156
157} // namespace WebCore
158
159#endif // LayoutState_h
160