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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
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 RenderMultiColumnSet_h | 27 #ifndef RenderMultiColumnSet_h |
28 #define RenderMultiColumnSet_h | 28 #define RenderMultiColumnSet_h |
29 | 29 |
| 30 #include "core/layout/MultiColumnFragmentainerGroup.h" |
30 #include "core/rendering/RenderMultiColumnFlowThread.h" | 31 #include "core/rendering/RenderMultiColumnFlowThread.h" |
31 #include "core/rendering/RenderRegion.h" | 32 #include "core/rendering/RenderRegion.h" |
32 #include "wtf/Vector.h" | 33 #include "wtf/Vector.h" |
33 | 34 |
34 namespace blink { | 35 namespace blink { |
35 | 36 |
36 // RenderMultiColumnSet represents a set of columns that all have the same width
and height. By | 37 // A set of columns in a multicol container. A column set is inserted as an anon
ymous child of the |
37 // combining runs of same-size columns into a single object, we significantly re
duce the number of | 38 // actual multicol container (i.e. the renderer whose style computes to non-auto
column-count and/or |
38 // unique LayoutObjects required to represent columns. | 39 // column-width), next to the flow thread. There'll be one column set for each c
ontiguous run of |
| 40 // column content. The only thing that can interrupt a contiguous run of column
content is a column |
| 41 // spanner, which means that if there are no spanners, there'll only be one colu
mn set. |
39 // | 42 // |
40 // Column sets are inserted as anonymous children of the actual multicol contain
er (i.e. the | 43 // Since a spanner interrupts an otherwise contiguous run of column content, ins
erting one may |
41 // renderer whose style computes to non-auto column-count and/or column-width). | 44 // result in the creation of additional new column sets. A placeholder for the s
panning renderer has |
| 45 // to be placed in between the column sets that come before and after the spanne
r, if there's |
| 46 // actually column content both before and after the spanner. |
42 // | 47 // |
43 // Being a "region", a column set has no children on its own, but is merely used
to slice a portion | 48 // A column set has no children on its own, but is merely used to slice a portio
n of the tall |
44 // of the tall "single-column" flow thread into actual columns visually, to conv
ert from flow thread | 49 // "single-column" flow thread into actual columns visually, to convert from flo
w thread coordinates |
45 // coordinates to visual ones. It is in charge of both positioning columns corre
ctly relatively to | 50 // to visual ones. It is in charge of both positioning columns correctly relativ
ely to the parent |
46 // the parent multicol container, and to calculate the correct translation for e
ach column's | 51 // multicol container, and to calculate the correct translation for each column'
s contents, and to |
47 // contents, and to paint any rules between them. RenderMultiColumnSet objects a
re used for | 52 // paint any rules between them. RenderMultiColumnSet objects are used for paint
ing, hit testing, |
48 // painting, hit testing, and any other type of operation that requires mapping
from flow thread | 53 // and any other type of operation that requires mapping from flow thread coordi
nates to visual |
49 // coordinates to visual coordinates. | 54 // coordinates. |
50 // | 55 // |
51 // Column spans result in the creation of new column sets, since a spanning rend
erer has to be | 56 // Columns are normally laid out in the inline progression direction, but if the
multicol container |
52 // placed in between the column sets that come before and after the span. | 57 // is inside another fragmentation context (e.g. paged media, or an another mult
icol container), we |
| 58 // may need to group the columns, so that we get one MultiColumnFragmentainerGro
up for each outer |
| 59 // fragmentainer (page / column) that the inner multicol container lives in. Eac
h fragmentainer |
| 60 // group has its own column height, but the column height is uniform within a gr
oup. |
53 class RenderMultiColumnSet : public RenderRegion { | 61 class RenderMultiColumnSet : public RenderRegion { |
54 public: | 62 public: |
55 enum BalancedHeightCalculation { GuessFromFlowThreadPortion, StretchBySpaceS
hortage }; | 63 static RenderMultiColumnSet* createAnonymous(RenderFlowThread&, const Layout
Style& parentStyle); |
56 | 64 |
57 static RenderMultiColumnSet* createAnonymous(RenderFlowThread&, const Layout
Style& parentStyle); | 65 const MultiColumnFragmentainerGroup& firstFragmentainerGroup() const { retur
n m_fragmentainerGroups.first(); } |
| 66 const MultiColumnFragmentainerGroup& lastFragmentainerGroup() const { return
m_fragmentainerGroups.last(); } |
| 67 MultiColumnFragmentainerGroup& fragmentainerGroupAtFlowThreadOffset(LayoutUn
it); |
| 68 const MultiColumnFragmentainerGroup& fragmentainerGroupAtFlowThreadOffset(La
youtUnit) const; |
58 | 69 |
59 virtual bool isOfType(LayoutObjectType type) const override { return type ==
LayoutObjectRenderMultiColumnSet || RenderRegion::isOfType(type); } | 70 virtual bool isOfType(LayoutObjectType type) const override { return type ==
LayoutObjectRenderMultiColumnSet || RenderRegion::isOfType(type); } |
60 | 71 |
61 virtual LayoutUnit pageLogicalWidth() const override final { return flowThre
ad()->logicalWidth(); } | 72 virtual LayoutUnit pageLogicalWidth() const final { return flowThread()->log
icalWidth(); } |
62 virtual LayoutUnit pageLogicalHeight() const override final { return m_colum
nHeight; } | 73 virtual LayoutUnit pageLogicalHeight() const final; |
63 | 74 |
64 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par
ent()); } | 75 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par
ent()); } |
65 RenderMultiColumnFlowThread* multiColumnFlowThread() const | 76 RenderMultiColumnFlowThread* multiColumnFlowThread() const |
66 { | 77 { |
67 ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRender
MultiColumnFlowThread()); | 78 ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRender
MultiColumnFlowThread()); |
68 return static_cast<RenderMultiColumnFlowThread*>(flowThread()); | 79 return static_cast<RenderMultiColumnFlowThread*>(flowThread()); |
69 } | 80 } |
70 | 81 |
71 RenderMultiColumnSet* nextSiblingMultiColumnSet() const; | 82 RenderMultiColumnSet* nextSiblingMultiColumnSet() const; |
72 RenderMultiColumnSet* previousSiblingMultiColumnSet() const; | 83 RenderMultiColumnSet* previousSiblingMultiColumnSet() const; |
73 | 84 |
74 void setLogicalTopInFlowThread(LayoutUnit); | 85 LayoutUnit logicalTopInFlowThread() const; |
75 LayoutUnit logicalTopInFlowThread() const { return isHorizontalWritingMode()
? flowThreadPortionRect().y() : flowThreadPortionRect().x(); } | 86 LayoutUnit logicalBottomInFlowThread() const; |
76 LayoutUnit logicalHeightInFlowThread() const { return isHorizontalWritingMod
e() ? flowThreadPortionRect().height() : flowThreadPortionRect().width(); } | 87 LayoutUnit logicalHeightInFlowThread() const { return logicalBottomInFlowThr
ead() - logicalTopInFlowThread(); } |
77 void setLogicalBottomInFlowThread(LayoutUnit); | |
78 LayoutUnit logicalBottomInFlowThread() const { return isHorizontalWritingMod
e() ? flowThreadPortionRect().maxY() : flowThreadPortionRect().maxX(); } | |
79 | 88 |
80 // The used CSS value of column-count, i.e. how many columns there are room
for without overflowing. | 89 // The used CSS value of column-count, i.e. how many columns there are room
for without overflowing. |
81 unsigned usedColumnCount() const { return multiColumnFlowThread()->columnCou
nt(); } | 90 unsigned usedColumnCount() const { return multiColumnFlowThread()->columnCou
nt(); } |
82 | 91 |
83 bool heightIsAuto() const; | 92 bool heightIsAuto() const; |
84 | 93 |
85 // Find the column that contains the given block offset, and return the tran
slation needed to | 94 // Find the column that contains the given block offset, and return the tran
slation needed to |
86 // get from flow thread coordinates to visual coordinates. | 95 // get from flow thread coordinates to visual coordinates. |
87 LayoutSize flowThreadTranslationAtOffset(LayoutUnit) const; | 96 LayoutSize flowThreadTranslationAtOffset(LayoutUnit) const; |
88 | 97 |
89 LayoutUnit heightAdjustedForSetOffset(LayoutUnit height) const; | 98 void updateMinimumColumnHeight(LayoutUnit offsetInFlowThread, LayoutUnit hei
ght); |
90 | |
91 void updateMinimumColumnHeight(LayoutUnit height) { m_minimumColumnHeight =
std::max(height, m_minimumColumnHeight); } | |
92 LayoutUnit minimumColumnHeight() const { return m_minimumColumnHeight; } | |
93 | 99 |
94 // Add a content run, specified by its end position. A content run is append
ed at every | 100 // Add a content run, specified by its end position. A content run is append
ed at every |
95 // forced/explicit break and at the end of the column set. The content runs
are used to | 101 // forced/explicit break and at the end of the column set. The content runs
are used to |
96 // determine where implicit/soft breaks will occur, in order to calculate an
initial column | 102 // determine where implicit/soft breaks will occur, in order to calculate an
initial column |
97 // height. | 103 // height. |
98 void addContentRun(LayoutUnit endOffsetFromFirstPage); | 104 void addContentRun(LayoutUnit endOffsetFromFirstPage); |
99 | 105 |
100 // (Re-)calculate the column height if it's auto. This is first and foremost
needed by sets that | 106 // (Re-)calculate the column height if it's auto. This is first and foremost
needed by sets that |
101 // are to balance the column height, but even when it isn't to be balanced,
this is necessary if | 107 // are to balance the column height, but even when it isn't to be balanced,
this is necessary if |
102 // the multicol container's height is constrained. | 108 // the multicol container's height is constrained. |
103 virtual bool recalculateColumnHeight(BalancedHeightCalculation); | 109 bool recalculateColumnHeight(BalancedColumnHeightCalculation); |
104 | 110 |
105 // Record space shortage (the amount of space that would have been enough to
prevent some | 111 // Record space shortage (the amount of space that would have been enough to
prevent some |
106 // element from being moved to the next column) at a column break. The small
est amount of space | 112 // element from being moved to the next column) at a column break. The small
est amount of space |
107 // shortage we find is the amount with which we will stretch the column heig
ht, if it turns out | 113 // shortage we find is the amount with which we will stretch the column heig
ht, if it turns out |
108 // after layout that the columns weren't tall enough. | 114 // after layout that the columns weren't tall enough. |
109 void recordSpaceShortage(LayoutUnit spaceShortage); | 115 void recordSpaceShortage(LayoutUnit offsetInFlowThread, LayoutUnit); |
110 | 116 |
111 // Reset previously calculated column height. Will mark for layout if needed
. | 117 // Reset previously calculated column height. Will mark for layout if needed
. |
112 void resetColumnHeight(); | 118 void resetColumnHeight(); |
113 | 119 |
114 // Layout of flow thread content that's to be rendered inside this column se
t begins. This | 120 // Layout of flow thread content that's to be rendered inside this column se
t begins. This |
115 // happens at the beginning of flow thread layout, and when advancing from a
previous column set | 121 // happens at the beginning of flow thread layout, and when advancing from a
previous column set |
116 // or spanner to this one. | 122 // or spanner to this one. |
117 void beginFlow(LayoutUnit offsetInFlowThread); | 123 void beginFlow(LayoutUnit offsetInFlowThread); |
| 124 |
118 // Layout of flow thread content that was to be rendered inside this column
set has | 125 // Layout of flow thread content that was to be rendered inside this column
set has |
119 // finished. This happens at end of flow thread layout, and when advancing t
o the next column | 126 // finished. This happens at end of flow thread layout, and when advancing t
o the next column |
120 // set or spanner. | 127 // set or spanner. |
121 void endFlow(LayoutUnit offsetInFlowThread); | 128 void endFlow(LayoutUnit offsetInFlowThread); |
122 | 129 |
123 // Expand this set's flow thread portion rectangle to contain all trailing f
low thread | 130 // Expand this set's flow thread portion rectangle to contain all trailing f
low thread |
124 // overflow. Only to be called on the last set. | 131 // overflow. Only to be called on the last set. |
125 void expandToEncompassFlowThreadContentsIfNeeded(); | 132 void expandToEncompassFlowThreadContentsIfNeeded(); |
126 | 133 |
127 void attachRegion(); | 134 void attachRegion(); |
(...skipping 21 matching lines...) Expand all Loading... |
149 virtual bool isSelfCollapsingBlock() const override { return false; } | 156 virtual bool isSelfCollapsingBlock() const override { return false; } |
150 | 157 |
151 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic
alTop, LogicalExtentComputedValues&) const override; | 158 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic
alTop, LogicalExtentComputedValues&) const override; |
152 | 159 |
153 virtual void paintObject(const PaintInfo&, const LayoutPoint& paintOffset) o
verride; | 160 virtual void paintObject(const PaintInfo&, const LayoutPoint& paintOffset) o
verride; |
154 | 161 |
155 virtual void addOverflowFromChildren() override; | 162 virtual void addOverflowFromChildren() override; |
156 | 163 |
157 virtual const char* renderName() const override; | 164 virtual const char* renderName() const override; |
158 | 165 |
159 LayoutUnit calculateMaxColumnHeight() const; | 166 virtual LayoutRect flowThreadPortionRect() const override; |
160 LayoutRect columnRectAt(unsigned index) const; | |
161 | 167 |
162 | 168 MultiColumnFragmentainerGroupList m_fragmentainerGroups; |
163 LayoutRect flowThreadPortionRectAt(unsigned index) const; | |
164 LayoutRect flowThreadPortionOverflowRect(const LayoutRect& flowThreadPortion
, unsigned index, unsigned colCount, LayoutUnit colGap) const; | |
165 | |
166 enum ColumnIndexCalculationMode { | |
167 ClampToExistingColumns, // Stay within the range of already existing col
umns. | |
168 AssumeNewColumns // Allow column indices outside the range of already ex
isting columns. | |
169 }; | |
170 unsigned columnIndexAtOffset(LayoutUnit, ColumnIndexCalculationMode = ClampT
oExistingColumns) const; | |
171 | |
172 void setAndConstrainColumnHeight(LayoutUnit); | |
173 | |
174 // Return the index of the content run with the currently tallest columns, t
aking all implicit | |
175 // breaks assumed so far into account. | |
176 unsigned findRunWithTallestColumns() const; | |
177 | |
178 // Given the current list of content runs, make assumptions about where we n
eed to insert | |
179 // implicit breaks (if there's room for any at all; depending on the number
of explicit breaks), | |
180 // and store the results. This is needed in order to balance the columns. | |
181 void distributeImplicitBreaks(); | |
182 | |
183 LayoutUnit calculateColumnHeight(BalancedHeightCalculation) const; | |
184 | |
185 LayoutUnit m_columnHeight; | |
186 | |
187 // The following variables are used when balancing the column set. | |
188 LayoutUnit m_maxColumnHeight; // Maximum column height allowed. | |
189 LayoutUnit m_minSpaceShortage; // The smallest amout of space shortage that
caused a column break. | |
190 LayoutUnit m_minimumColumnHeight; | |
191 | |
192 // A run of content without explicit (forced) breaks; i.e. a flow thread por
tion between two | |
193 // explicit breaks, between flow thread start and an explicit break, between
an explicit break | |
194 // and flow thread end, or, in cases when there are no explicit breaks at al
l: between flow | |
195 // thread portion start and flow thread portion end. We need to know where t
he explicit breaks | |
196 // are, in order to figure out where the implicit breaks will end up, so tha
t we get the columns | |
197 // properly balanced. A content run starts out as representing one single co
lumn, and will | |
198 // represent one additional column for each implicit break "inserted" there. | |
199 class ContentRun { | |
200 public: | |
201 ContentRun(LayoutUnit breakOffset) | |
202 : m_breakOffset(breakOffset) | |
203 , m_assumedImplicitBreaks(0) { } | |
204 | |
205 unsigned assumedImplicitBreaks() const { return m_assumedImplicitBreaks;
} | |
206 void assumeAnotherImplicitBreak() { m_assumedImplicitBreaks++; } | |
207 LayoutUnit breakOffset() const { return m_breakOffset; } | |
208 | |
209 // Return the column height that this content run would require, conside
ring the implicit | |
210 // breaks assumed so far. | |
211 LayoutUnit columnLogicalHeight(LayoutUnit startOffset) const { return ce
ilf((m_breakOffset - startOffset).toFloat() / float(m_assumedImplicitBreaks + 1)
); } | |
212 | |
213 private: | |
214 LayoutUnit m_breakOffset; // Flow thread offset where this run ends. | |
215 unsigned m_assumedImplicitBreaks; // Number of implicit breaks in this r
un assumed so far. | |
216 }; | |
217 Vector<ContentRun, 1> m_contentRuns; | |
218 }; | 169 }; |
219 | 170 |
220 inline void RenderMultiColumnSet::beginFlow(LayoutUnit offsetInFlowThread) | |
221 { | |
222 // At this point layout is exactly at the beginning of this set. Store block
offset from flow | |
223 // thread start. | |
224 setLogicalTopInFlowThread(offsetInFlowThread); | |
225 } | |
226 | |
227 inline void RenderMultiColumnSet::endFlow(LayoutUnit offsetInFlowThread) | |
228 { | |
229 // At this point layout is exactly at the end of this set. Store block offse
t from flow thread | |
230 // start. This set is now considered "flowed", although we may have to revis
it it later (with | |
231 // beginFlow()), e.g. if a subtree in the flow thread has to be laid out ove
r again because the | |
232 // initial margin collapsing estimates were wrong. | |
233 setLogicalBottomInFlowThread(offsetInFlowThread); | |
234 } | |
235 | |
236 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); | 171 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); |
237 | 172 |
238 } // namespace blink | 173 } // namespace blink |
239 | 174 |
240 #endif // RenderMultiColumnSet_h | 175 #endif // RenderMultiColumnSet_h |
241 | 176 |
OLD | NEW |