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/rendering/MultiColumnRow.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 // RenderMultiColumnSet represents a set of columns that all have the same width and height. By |
37 // combining runs of same-size columns into a single object, we significantly re duce the number of | 38 // combining runs of same-size columns into a single object, we significantly re duce the number of |
38 // unique RenderObjects required to represent columns. | 39 // unique RenderObjects required to represent columns. |
39 // | 40 // |
40 // Column sets are inserted as anonymous children of the actual multicol contain er (i.e. the | 41 // Column sets are inserted as anonymous children of the actual multicol contain er (i.e. the |
41 // renderer whose style computes to non-auto column-count and/or column-width). | 42 // renderer whose style computes to non-auto column-count and/or column-width). |
42 // | 43 // |
43 // Being a "region", a column set has no children on its own, but is merely used to slice a portion | 44 // Being a "region", a column set has no children on its own, but is merely used to slice a portion |
44 // of the tall "single-column" flow thread into actual columns visually, to conv ert from flow thread | 45 // of the tall "single-column" flow thread into actual columns visually, to conv ert from flow thread |
45 // coordinates to visual ones. It is in charge of both positioning columns corre ctly relatively to | 46 // coordinates to visual ones. It is in charge of both positioning columns corre ctly relatively to |
46 // the parent multicol container, and to calculate the correct translation for e ach column's | 47 // the parent multicol container, and to calculate the correct translation for e ach column's |
47 // contents, and to paint any rules between them. RenderMultiColumnSet objects a re used for | 48 // contents, and to paint any rules between them. RenderMultiColumnSet objects a re used for |
48 // painting, hit testing, and any other type of operation that requires mapping from flow thread | 49 // painting, hit testing, and any other type of operation that requires mapping from flow thread |
49 // coordinates to visual coordinates. | 50 // coordinates to visual coordinates. |
50 // | 51 // |
51 // Column spans result in the creation of new column sets, since a spanning rend erer has to be | 52 // Column spans result in the creation of new column sets, since a spanning rend erer has to be |
52 // placed in between the column sets that come before and after the span. | 53 // placed in between the column sets that come before and after the span. |
54 // | |
55 // A multi column set has one or more column rows (MultiColumnRow objects). If w e're inside another | |
56 // fragmentation context, there will be one row established for each outer fragm entainer (page, | |
57 // column, etc.) that this set lives in. If we're not inside another fragmentati on context, on the | |
58 // other hand, there will only be one row. | |
53 class RenderMultiColumnSet : public RenderRegion { | 59 class RenderMultiColumnSet : public RenderRegion { |
Julien - ping for review
2015/01/29 17:37:47
It would be nice to know how much is left of Rende
mstensho (USE GERRIT)
2015/02/02 17:57:24
Yeah, those are interesting thoughts. I think Rend
| |
54 public: | 60 public: |
55 enum BalancedHeightCalculation { GuessFromFlowThreadPortion, StretchBySpaceS hortage }; | |
56 | |
57 static RenderMultiColumnSet* createAnonymous(RenderFlowThread*, RenderStyle* parentStyle); | 61 static RenderMultiColumnSet* createAnonymous(RenderFlowThread*, RenderStyle* parentStyle); |
58 | 62 |
59 virtual bool isOfType(RenderObjectType type) const override { return type == RenderObjectRenderMultiColumnSet || RenderRegion::isOfType(type); } | 63 virtual bool isOfType(RenderObjectType type) const override { return type == RenderObjectRenderMultiColumnSet || RenderRegion::isOfType(type); } |
60 | 64 |
61 virtual LayoutUnit pageLogicalWidth() const override final { return flowThre ad()->logicalWidth(); } | 65 virtual LayoutUnit pageLogicalWidth() const final { return flowThread()->log icalWidth(); } |
62 virtual LayoutUnit pageLogicalHeight() const override final { return m_colum nHeight; } | 66 virtual LayoutUnit pageLogicalHeight() const final; |
63 | 67 |
64 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par ent()); } | 68 RenderBlockFlow* multiColumnBlockFlow() const { return toRenderBlockFlow(par ent()); } |
65 RenderMultiColumnFlowThread* multiColumnFlowThread() const | 69 RenderMultiColumnFlowThread* multiColumnFlowThread() const |
66 { | 70 { |
67 ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRender MultiColumnFlowThread()); | 71 ASSERT_WITH_SECURITY_IMPLICATION(!flowThread() || flowThread()->isRender MultiColumnFlowThread()); |
68 return static_cast<RenderMultiColumnFlowThread*>(flowThread()); | 72 return static_cast<RenderMultiColumnFlowThread*>(flowThread()); |
69 } | 73 } |
70 | 74 |
71 RenderMultiColumnSet* nextSiblingMultiColumnSet() const; | 75 RenderMultiColumnSet* nextSiblingMultiColumnSet() const; |
72 RenderMultiColumnSet* previousSiblingMultiColumnSet() const; | 76 RenderMultiColumnSet* previousSiblingMultiColumnSet() const; |
73 | 77 |
74 void setLogicalTopInFlowThread(LayoutUnit); | 78 LayoutUnit logicalTopInFlowThread() const; |
75 LayoutUnit logicalTopInFlowThread() const { return isHorizontalWritingMode() ? flowThreadPortionRect().y() : flowThreadPortionRect().x(); } | 79 LayoutUnit logicalBottomInFlowThread() const; |
76 LayoutUnit logicalHeightInFlowThread() const { return isHorizontalWritingMod e() ? flowThreadPortionRect().height() : flowThreadPortionRect().width(); } | 80 LayoutUnit logicalHeightInFlowThread() const { return logicalBottomInFlowThr ead() - logicalTopInFlowThread(); } |
77 void setLogicalBottomInFlowThread(LayoutUnit); | |
78 LayoutUnit logicalBottomInFlowThread() const { return isHorizontalWritingMod e() ? flowThreadPortionRect().maxY() : flowThreadPortionRect().maxX(); } | |
79 | 81 |
80 // The used CSS value of column-count, i.e. how many columns there are room for without overflowing. | 82 // 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(); } | 83 unsigned usedColumnCount() const { return multiColumnFlowThread()->columnCou nt(); } |
82 | 84 |
83 bool heightIsAuto() const; | 85 bool heightIsAuto() const; |
84 | 86 |
85 // Find the column that contains the given block offset, and return the tran slation needed to | 87 // 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. | 88 // get from flow thread coordinates to visual coordinates. |
87 LayoutSize flowThreadTranslationAtOffset(LayoutUnit) const; | 89 LayoutSize flowThreadTranslationAtOffset(LayoutUnit) const; |
88 | 90 |
89 LayoutUnit heightAdjustedForSetOffset(LayoutUnit height) const; | 91 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 | 92 |
94 // Add a content run, specified by its end position. A content run is append ed at every | 93 // 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 | 94 // 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 | 95 // determine where implicit/soft breaks will occur, in order to calculate an initial column |
97 // height. | 96 // height. |
98 void addContentRun(LayoutUnit endOffsetFromFirstPage); | 97 void addContentRun(LayoutUnit endOffsetFromFirstPage); |
99 | 98 |
100 // (Re-)calculate the column height if it's auto. This is first and foremost needed by sets that | 99 // (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 | 100 // 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. | 101 // the multicol container's height is constrained. |
103 virtual bool recalculateColumnHeight(BalancedHeightCalculation); | 102 bool recalculateColumnHeight(BalancedColumnHeightCalculation); |
104 | 103 |
105 // Record space shortage (the amount of space that would have been enough to prevent some | 104 // 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 | 105 // 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 | 106 // 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. | 107 // after layout that the columns weren't tall enough. |
109 void recordSpaceShortage(LayoutUnit spaceShortage); | 108 void recordSpaceShortage(LayoutUnit offsetInFlowThread, LayoutUnit); |
110 | 109 |
111 // Reset previously calculated column height. Will mark for layout if needed . | 110 // Reset previously calculated column height. Will mark for layout if needed . |
112 void resetColumnHeight(); | 111 void resetColumnHeight(); |
113 | 112 |
114 // Layout of flow thread content that's to be rendered inside this column se t begins. This | 113 // 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 | 114 // happens at the beginning of flow thread layout, and when advancing from a previous column set |
116 // or spanner to this one. | 115 // or spanner to this one. |
117 void beginFlow(LayoutUnit offsetInFlowThread); | 116 void beginFlow(LayoutUnit offsetInFlowThread); |
117 | |
118 // Layout of flow thread content that was to be rendered inside this column set has | 118 // 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 | 119 // finished. This happens at end of flow thread layout, and when advancing t o the next column |
120 // set or spanner. | 120 // set or spanner. |
121 void endFlow(LayoutUnit offsetInFlowThread); | 121 void endFlow(LayoutUnit offsetInFlowThread); |
122 | 122 |
123 // Expand this set's flow thread portion rectangle to contain all trailing f low thread | 123 // 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. | 124 // overflow. Only to be called on the last set. |
125 void expandToEncompassFlowThreadContentsIfNeeded(); | 125 void expandToEncompassFlowThreadContentsIfNeeded(); |
126 | 126 |
127 void attachRegion(); | 127 void attachRegion(); |
128 void detachRegion(); | 128 void detachRegion(); |
129 | 129 |
130 // The top of the nearest page inside the region. For RenderRegions, this is just the logical top of the | 130 // The top of the nearest page inside the region. For RenderRegions, this is just the logical top of the |
131 // flow thread portion we contain. For sets, we have to figure out the top o f the nearest column or | 131 // flow thread portion we contain. For sets, we have to figure out the top o f the nearest column or |
132 // page. | 132 // page. |
133 LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const; | 133 LayoutUnit pageLogicalTopForOffset(LayoutUnit offset) const; |
134 | 134 |
135 void collectLayerFragments(LayerFragments&, const LayoutRect& layerBoundingB ox, const LayoutRect& dirtyRect); | 135 void collectLayerFragments(LayerFragments&, const LayoutRect& layerBoundingB ox, const LayoutRect& dirtyRect); |
136 | 136 |
137 LayoutUnit columnGap() const; | 137 LayoutUnit columnGap() const; |
138 | 138 |
139 // The "CSS actual" value of column-count. This includes overflowing columns , if any. | 139 // The "CSS actual" value of column-count. This includes overflowing columns , if any. |
140 unsigned actualColumnCount() const; | 140 unsigned actualColumnCount() const; |
141 | 141 |
142 protected: | 142 protected: |
143 RenderMultiColumnSet(RenderFlowThread*); | 143 RenderMultiColumnSet(RenderFlowThread*); |
144 | 144 |
145 private: | 145 private: |
146 MultiColumnRow* firstColumnRow() | |
147 { | |
148 // FIXME: support multiple rows. | |
149 return &m_columnRow; | |
150 } | |
151 MultiColumnRow* lastColumnRow() | |
Julien - ping for review
2015/01/29 17:37:47
Do we really want first / last? How about just som
mstensho (USE GERRIT)
2015/02/02 17:57:24
The first and the last groups are of special signi
| |
152 { | |
153 // FIXME: support multiple rows. | |
154 return &m_columnRow; | |
155 } | |
156 MultiColumnRow* columnRowAtFlowThreadOffset(LayoutUnit); | |
157 const MultiColumnRow* firstColumnRow() const | |
158 { | |
159 // FIXME: support multiple rows. | |
160 return &m_columnRow; | |
161 } | |
162 const MultiColumnRow* lastColumnRow() const | |
163 { | |
164 // FIXME: support multiple rows. | |
165 return &m_columnRow; | |
166 } | |
167 const MultiColumnRow* columnRowAtFlowThreadOffset(LayoutUnit) const; | |
168 | |
146 virtual void insertedIntoTree() override final; | 169 virtual void insertedIntoTree() override final; |
147 virtual void willBeRemovedFromTree() override final; | 170 virtual void willBeRemovedFromTree() override final; |
148 | 171 |
149 virtual bool isSelfCollapsingBlock() const override { return false; } | 172 virtual bool isSelfCollapsingBlock() const override { return false; } |
150 | 173 |
151 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic alTop, LogicalExtentComputedValues&) const override; | 174 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logic alTop, LogicalExtentComputedValues&) const override; |
152 | 175 |
153 virtual void paintObject(const PaintInfo&, const LayoutPoint& paintOffset) o verride; | 176 virtual void paintObject(const PaintInfo&, const LayoutPoint& paintOffset) o verride; |
154 | 177 |
155 virtual void addOverflowFromChildren() override; | 178 virtual void addOverflowFromChildren() override; |
156 | 179 |
157 virtual const char* renderName() const override; | 180 virtual const char* renderName() const override; |
158 | 181 |
159 LayoutUnit calculateMaxColumnHeight() const; | 182 virtual LayoutRect flowThreadPortionRect() const override; |
160 LayoutRect columnRectAt(unsigned index) const; | |
161 | 183 |
162 | 184 MultiColumnRow m_columnRow; // FIXME: Need to support multiple rows. |
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 }; | 185 }; |
219 | 186 |
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_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); | 187 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderMultiColumnSet, isRenderMultiColumnSet()); |
237 | 188 |
238 } // namespace blink | 189 } // namespace blink |
239 | 190 |
240 #endif // RenderMultiColumnSet_h | 191 #endif // RenderMultiColumnSet_h |
241 | 192 |
OLD | NEW |