OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 | 26 |
27 #ifndef RenderMultiColumnFlowThread_h | 27 #ifndef RenderMultiColumnFlowThread_h |
28 #define RenderMultiColumnFlowThread_h | 28 #define RenderMultiColumnFlowThread_h |
29 | 29 |
30 #include "core/rendering/RenderFlowThread.h" | 30 #include "core/rendering/RenderFlowThread.h" |
| 31 #include "wtf/HashMap.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 class RenderMultiColumnSet; | 35 class RenderMultiColumnSet; |
| 36 class RenderMultiColumnSpannerSet; |
35 | 37 |
36 // Flow thread implementation for CSS multicol. This will be inserted as an anon
ymous child block of | 38 // Flow thread implementation for CSS multicol. This will be inserted as an anon
ymous child block of |
37 // the actual multicol container (i.e. the RenderBlockFlow whose style computes
to non-auto | 39 // the actual multicol container (i.e. the RenderBlockFlow whose style computes
to non-auto |
38 // column-count and/or column-width). RenderMultiColumnFlowThread is the heart o
f the multicol | 40 // column-count and/or column-width). RenderMultiColumnFlowThread is the heart o
f the multicol |
39 // implementation, and there is only one instance per multicol container. Child
content of the | 41 // implementation, and there is only one instance per multicol container. Child
content of the |
40 // multicol container is parented into the flow thread at the time of renderer i
nsertion. | 42 // multicol container is parented into the flow thread at the time of renderer i
nsertion. |
41 // | 43 // |
42 // Apart from this flow thread child, the multicol container will also have Rend
erMultiColumnSet | 44 // Apart from this flow thread child, the multicol container will also have Rend
erMultiColumnSet |
43 // "region" children, which are used to position the columns visually. The flow
thread is in charge | 45 // "region" children, which are used to position the columns visually. The flow
thread is in charge |
44 // of layout, and, after having calculated the column width, it lays out content
as if everything | 46 // of layout, and, after having calculated the column width, it lays out content
as if everything |
45 // were in one tall single column, except that there will typically be some amou
nt of blank space | 47 // were in one tall single column, except that there will typically be some amou
nt of blank space |
46 // (also known as pagination struts) at the offsets where the actual column boun
daries are. This | 48 // (also known as pagination struts) at the offsets where the actual column boun
daries are. This |
47 // way, content that needs to be preceded by a break will appear at the top of t
he next | 49 // way, content that needs to be preceded by a break will appear at the top of t
he next |
48 // column. Content needs to be preceded by a break when there's a forced break o
r when the content | 50 // column. Content needs to be preceded by a break when there's a forced break o
r when the content |
49 // is unbreakable and cannot fully fit in the same column as the preceding piece
of | 51 // is unbreakable and cannot fully fit in the same column as the preceding piece
of |
50 // content. Although a RenderMultiColumnFlowThread is laid out, it does not take
up any space in its | 52 // content. Although a RenderMultiColumnFlowThread is laid out, it does not take
up any space in its |
51 // container. It's the RenderMultiColumnSet objects that take up the necessary a
mount of space, and | 53 // container. It's the RenderMultiColumnSet objects that take up the necessary a
mount of space, and |
52 // make sure that the columns are painted and hit-tested correctly. | 54 // make sure that the columns are painted and hit-tested correctly. |
53 // | 55 // |
| 56 // If there is any column content inside the multicol container, we create a |
| 57 // RenderMultiColumnSet. We only need to create multiple sets if there are spann
ers |
| 58 // (column-span:all) in the multicol container. When a spanner is inserted, cont
ent preceding it |
| 59 // gets its own set, and content succeeding it will get another set. The spanner
itself will also |
| 60 // get its own set (RenderMultiColumnSpannerSet). |
| 61 // |
54 // The width of the flow thread is the same as the column width. The width of a
column set is the | 62 // The width of the flow thread is the same as the column width. The width of a
column set is the |
55 // same as the content box width of the multicol container; in other words exact
ly enough to hold | 63 // same as the content box width of the multicol container; in other words exact
ly enough to hold |
56 // the number of columns to be used, stacked horizontally, plus column gaps betw
een them. | 64 // the number of columns to be used, stacked horizontally, plus column gaps betw
een them. |
57 // | 65 // |
58 // Since it's the first child of the multicol container, the flow thread is laid
out first, albeit | 66 // Since it's the first child of the multicol container, the flow thread is laid
out first, albeit |
59 // in a slightly special way, since it's not to take up any space in its ancesto
rs. Afterwards, the | 67 // in a slightly special way, since it's not to take up any space in its ancesto
rs. Afterwards, the |
60 // column sets are laid out. They get their height from the columns that they ho
ld. In single | 68 // column sets are laid out. Column sets get their height from the columns that
they hold. In single |
61 // column-row constrained height non-balancing cases this will simply be the sam
e as the content | 69 // column-row constrained height non-balancing cases without spanners this will
simply be the same |
62 // height of the multicol container itself. In most other cases we'll have to ca
lculate optimal | 70 // as the content height of the multicol container itself. In most other cases w
e'll have to |
63 // column heights ourselves, though. This process is referred to as column balan
cing, and then we | 71 // calculate optimal column heights ourselves, though. This process is referred
to as column |
64 // infer the column set height from the flow thread's height. | 72 // balancing, and then we infer the column set height from the height of the flo
w thread portion |
| 73 // occupied by each set. |
65 // | 74 // |
66 // More on column balancing: the columns' height is unknown in the first layout
pass when | 75 // More on column balancing: the columns' height is unknown in the first layout
pass when |
67 // balancing. This means that we cannot insert any implicit (soft / unforced) br
eaks (and pagination | 76 // balancing. This means that we cannot insert any implicit (soft / unforced) br
eaks (and pagination |
68 // struts) when laying out the contents of the flow thread. We'll just lay out e
verything in tall | 77 // struts) when laying out the contents of the flow thread. We'll just lay out e
verything in tall |
69 // single strip. After the initial flow thread layout pass we can determine a te
ntative / minimal / | 78 // single strip. After the initial flow thread layout pass we can determine a te
ntative / minimal / |
70 // initial column height. This is calculated by simply dividing the flow thread'
s height by the | 79 // initial column height. This is calculated by simply dividing the flow thread'
s height by the |
71 // number of specified columns. In the layout pass that follows, we can insert b
reaks (and | 80 // number of specified columns. In the layout pass that follows, we can insert b
reaks (and |
72 // pagination struts) at column boundaries, since we now have a column height. I
t may very easily | 81 // pagination struts) at column boundaries, since we now have a column height. I
t may very easily |
73 // turn out that the calculated height wasn't enough, though. We'll notice this
at end of layout. If | 82 // turn out that the calculated height wasn't enough, though. We'll notice this
at end of layout. If |
74 // we end up with too many columns (i.e. columns overflowing the multicol contai
ner), it wasn't | 83 // we end up with too many columns (i.e. columns overflowing the multicol contai
ner), it wasn't |
(...skipping 15 matching lines...) Expand all Loading... |
90 | 99 |
91 static RenderMultiColumnFlowThread* createAnonymous(Document&, RenderStyle*
parentStyle); | 100 static RenderMultiColumnFlowThread* createAnonymous(Document&, RenderStyle*
parentStyle); |
92 | 101 |
93 virtual bool isRenderMultiColumnFlowThread() const OVERRIDE FINAL { return t
rue; } | 102 virtual bool isRenderMultiColumnFlowThread() const OVERRIDE FINAL { return t
rue; } |
94 | 103 |
95 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par
ent()); } | 104 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par
ent()); } |
96 | 105 |
97 RenderMultiColumnSet* firstMultiColumnSet() const; | 106 RenderMultiColumnSet* firstMultiColumnSet() const; |
98 RenderMultiColumnSet* lastMultiColumnSet() const; | 107 RenderMultiColumnSet* lastMultiColumnSet() const; |
99 | 108 |
100 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0)
OVERRIDE; | 109 // Find the first set inside which the specified renderer would be rendered. |
| 110 RenderMultiColumnSet* findSetRendering(RenderObject*) const; |
| 111 |
| 112 // Return the spanner set (if any) that contains the specified renderer. Thi
s includes the |
| 113 // renderer for the element that actually establishes the spanner too. |
| 114 RenderMultiColumnSpannerSet* containingColumnSpanner(const RenderObject* des
cendant) const; |
101 | 115 |
102 // Populate the flow thread with what's currently its siblings. Called when
a regular block | 116 // Populate the flow thread with what's currently its siblings. Called when
a regular block |
103 // becomes a multicol container. | 117 // becomes a multicol container. |
104 void populate(); | 118 void populate(); |
105 | 119 |
106 // Empty the flow thread by moving everything to the parent. Remove all mult
icol specific | 120 // Empty the flow thread by moving everything to the parent. Remove all mult
icol specific |
107 // renderers. Then destroy the flow thread. Called when a multicol container
becomes a regular | 121 // renderers. Then destroy the flow thread. Called when a multicol container
becomes a regular |
108 // block. | 122 // block. |
109 void evacuateAndDestroy(); | 123 void evacuateAndDestroy(); |
110 | 124 |
111 unsigned columnCount() const { return m_columnCount; } | 125 unsigned columnCount() const { return m_columnCount; } |
112 LayoutUnit columnHeightAvailable() const { return m_columnHeightAvailable; } | 126 LayoutUnit columnHeightAvailable() const { return m_columnHeightAvailable; } |
113 void setColumnHeightAvailable(LayoutUnit available) { m_columnHeightAvailabl
e = available; } | 127 void setColumnHeightAvailable(LayoutUnit available) { m_columnHeightAvailabl
e = available; } |
114 virtual bool heightIsAuto() const { return !columnHeightAvailable() || multi
ColumnBlockFlow()->style()->columnFill() == ColumnFillBalance; } | |
115 bool progressionIsInline() const { return m_progressionIsInline; } | 128 bool progressionIsInline() const { return m_progressionIsInline; } |
116 | 129 |
117 virtual LayoutSize columnOffset(const LayoutPoint&) const OVERRIDE FINAL; | 130 virtual LayoutSize columnOffset(const LayoutPoint&) const OVERRIDE FINAL; |
118 | 131 |
119 // Do we need to set a new width and lay out? | 132 // Do we need to set a new width and lay out? |
120 virtual bool needsNewWidth() const; | 133 virtual bool needsNewWidth() const; |
121 | 134 |
122 void layoutColumns(bool relayoutChildren, SubtreeLayoutScope&); | 135 void layoutColumns(bool relayoutChildren, SubtreeLayoutScope&); |
123 | 136 |
124 bool recalculateColumnHeights(); | 137 bool recalculateColumnHeights(); |
125 | 138 |
126 protected: | 139 protected: |
127 RenderMultiColumnFlowThread(); | 140 RenderMultiColumnFlowThread(); |
128 void setProgressionIsInline(bool isInline) { m_progressionIsInline = isInlin
e; } | 141 void setProgressionIsInline(bool isInline) { m_progressionIsInline = isInlin
e; } |
129 | 142 |
130 virtual void layout() OVERRIDE; | 143 virtual void layout() OVERRIDE; |
131 | 144 |
132 private: | 145 private: |
133 void calculateColumnCountAndWidth(LayoutUnit& width, unsigned& count) const; | 146 void calculateColumnCountAndWidth(LayoutUnit& width, unsigned& count) const; |
| 147 virtual bool isDescendantValidColumnSpanner(RenderObject* descendant) const; |
134 | 148 |
135 virtual const char* renderName() const OVERRIDE; | 149 virtual const char* renderName() const OVERRIDE; |
136 virtual void addRegionToThread(RenderMultiColumnSet*) OVERRIDE; | 150 virtual void addRegionToThread(RenderMultiColumnSet*) OVERRIDE; |
137 virtual void willBeRemovedFromTree() OVERRIDE; | 151 virtual void willBeRemovedFromTree() OVERRIDE; |
| 152 virtual bool isColumnSpanner(const RenderObject*) const OVERRIDE; |
| 153 virtual bool isInsideColumnSpanner(const RenderObject*) const OVERRIDE FINAL
; |
| 154 virtual LayoutUnit enterColumnSpanner(RenderBox*, LayoutUnit logicalTop) OVE
RRIDE; |
| 155 virtual void leaveColumnSpanner(RenderBox*, LayoutUnit logicalBottom) OVERRI
DE; |
| 156 virtual void flowThreadDescendantInserted(RenderObject*) OVERRIDE; |
| 157 virtual void flowThreadDescendantWillBeRemoved(RenderObject*) OVERRIDE; |
| 158 virtual void flowThreadDescendantStyleDidChange(RenderObject*) OVERRIDE; |
138 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic
alTop, LogicalExtentComputedValues&) const OVERRIDE; | 159 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic
alTop, LogicalExtentComputedValues&) const OVERRIDE; |
139 virtual void updateLogicalWidth() OVERRIDE; | 160 virtual void updateLogicalWidth() OVERRIDE; |
140 virtual void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) OVERR
IDE; | 161 virtual void setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage) OVERR
IDE; |
141 virtual void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight
) OVERRIDE; | 162 virtual void updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight
) OVERRIDE; |
142 virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const OVERR
IDE; | 163 virtual RenderMultiColumnSet* columnSetAtBlockOffset(LayoutUnit) const OVERR
IDE; |
143 virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool
isBefore, LayoutUnit* offsetBreakAdjustment = 0) OVERRIDE; | 164 virtual bool addForcedRegionBreak(LayoutUnit, RenderObject* breakChild, bool
isBefore, LayoutUnit* offsetBreakAdjustment = 0) OVERRIDE; |
144 virtual bool isPageLogicalHeightKnown() const OVERRIDE; | 165 virtual bool isPageLogicalHeightKnown() const OVERRIDE; |
145 | 166 |
| 167 typedef HashMap<const RenderObject*, RenderMultiColumnSpannerSet*> SpannerMa
p; |
| 168 SpannerMap m_spannerMap; |
| 169 |
| 170 // The last set we worked on. It's not to be used as the "current set". The
concept of a |
| 171 // "current set" is difficult, since layout may jump back and forth in the t
ree, due to wrong |
| 172 // top location estimates (due to e.g. margin collapsing), and possibly for
other reasons. |
| 173 RenderMultiColumnSet* m_lastSetWorkedOn; |
| 174 |
146 unsigned m_columnCount; // The used value of column-count | 175 unsigned m_columnCount; // The used value of column-count |
147 LayoutUnit m_columnHeightAvailable; // Total height available to columns, or
0 if auto. | 176 LayoutUnit m_columnHeightAvailable; // Total height available to columns, or
0 if auto. |
148 bool m_inBalancingPass; // Set when relayouting for column balancing. | 177 bool m_inBalancingPass; // Set when relayouting for column balancing. |
149 bool m_needsColumnHeightsRecalculation; // Set when we need to recalculate t
he column set heights after layout. | 178 bool m_needsColumnHeightsRecalculation; // Set when we need to recalculate t
he column set heights after layout. |
150 bool m_progressionIsInline; // Always true for regular multicol. False for p
aged-y overflow. | 179 bool m_progressionIsInline; // Always true for regular multicol. False for p
aged-y overflow. |
| 180 bool m_beingEvacuated; |
151 }; | 181 }; |
152 | 182 |
153 } // namespace blink | 183 } // namespace blink |
154 | 184 |
155 #endif // RenderMultiColumnFlowThread_h | 185 #endif // RenderMultiColumnFlowThread_h |
156 | 186 |
OLD | NEW |