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 #include "config.h" | 26 #include "config.h" |
27 #include "core/rendering/RenderMultiColumnBlock.h" | 27 #include "core/rendering/RenderMultiColumnBlock.h" |
28 | 28 |
29 #include "core/rendering/RenderMultiColumnFlowThread.h" | 29 #include "core/rendering/RenderMultiColumnFlowThread.h" |
| 30 #include "core/rendering/RenderMultiColumnSet.h" |
| 31 #include "core/rendering/RenderView.h" |
30 | 32 |
31 using namespace std; | 33 using namespace std; |
32 | 34 |
33 namespace WebCore { | 35 namespace WebCore { |
34 | 36 |
35 RenderMultiColumnBlock::RenderMultiColumnBlock(Element* element) | 37 RenderMultiColumnBlock::RenderMultiColumnBlock(Element* element) |
36 : RenderBlock(element) | 38 : RenderBlock(element) |
37 , m_flowThread(0) | 39 , m_flowThread(0) |
38 , m_columnCount(1) | 40 , m_columnCount(1) |
39 , m_columnWidth(0) | 41 , m_columnWidth(0) |
40 , m_columnHeight(0) | 42 , m_columnHeightAvailable(0) |
41 , m_requiresBalancing(false) | 43 , m_inBalancingPass(false) |
42 { | 44 { |
43 } | 45 } |
44 | 46 |
45 void RenderMultiColumnBlock::styleDidChange(StyleDifference diff, const RenderSt
yle* oldStyle) | 47 void RenderMultiColumnBlock::styleDidChange(StyleDifference diff, const RenderSt
yle* oldStyle) |
46 { | 48 { |
47 RenderBlock::styleDidChange(diff, oldStyle); | 49 RenderBlock::styleDidChange(diff, oldStyle); |
48 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) | 50 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) |
49 child->setStyle(RenderStyle::createAnonymousStyleWithDisplay(style(), BL
OCK)); | 51 child->setStyle(RenderStyle::createAnonymousStyleWithDisplay(style(), BL
OCK)); |
50 } | 52 } |
51 | 53 |
(...skipping 30 matching lines...) Expand all Loading... |
82 computeColumnCountAndWidth(); | 84 computeColumnCountAndWidth(); |
83 if (m_columnWidth != oldColumnWidth) | 85 if (m_columnWidth != oldColumnWidth) |
84 relayoutChildren = true; | 86 relayoutChildren = true; |
85 return relayoutChildren; | 87 return relayoutChildren; |
86 } | 88 } |
87 | 89 |
88 void RenderMultiColumnBlock::checkForPaginationLogicalHeightChange(LayoutUnit& /
*pageLogicalHeight*/, bool& /*pageLogicalHeightChanged*/, bool& /*hasSpecifiedPa
geLogicalHeight*/) | 90 void RenderMultiColumnBlock::checkForPaginationLogicalHeightChange(LayoutUnit& /
*pageLogicalHeight*/, bool& /*pageLogicalHeightChanged*/, bool& /*hasSpecifiedPa
geLogicalHeight*/) |
89 { | 91 { |
90 // We don't actually update any of the variables. We just subclassed to adju
st our column height. | 92 // We don't actually update any of the variables. We just subclassed to adju
st our column height. |
91 updateLogicalHeight(); | 93 updateLogicalHeight(); |
92 LayoutUnit newContentLogicalHeight = contentLogicalHeight(); | 94 m_columnHeightAvailable = max<LayoutUnit>(contentLogicalHeight(), 0); |
93 m_requiresBalancing = !newContentLogicalHeight; | |
94 if (!m_requiresBalancing) { | |
95 // The regions will be invalidated when we lay them out and they change
size to | |
96 // the new column height. | |
97 if (columnHeight() != newContentLogicalHeight) | |
98 setColumnHeight(newContentLogicalHeight); | |
99 } | |
100 setLogicalHeight(0); | 95 setLogicalHeight(0); |
101 } | 96 } |
102 | 97 |
103 bool RenderMultiColumnBlock::relayoutForPagination(bool, LayoutUnit, LayoutState
Maintainer&) | 98 bool RenderMultiColumnBlock::relayoutForPagination(bool, LayoutUnit, LayoutState
Maintainer& statePusher) |
104 { | 99 { |
105 // FIXME: Implement. | 100 if (m_inBalancingPass || !requiresBalancing()) |
106 return false; | 101 return false; |
| 102 m_inBalancingPass = true; // Prevent re-entering this method (and recursion
into layout). |
| 103 |
| 104 bool needsRelayout; |
| 105 bool neededRelayout = false; |
| 106 bool firstPass = true; |
| 107 do { |
| 108 // Column heights may change here because of balancing. We may have to d
o multiple layout |
| 109 // passes, depending on how the contents is fitted to the changed column
heights. In most |
| 110 // cases, laying out again twice or even just once will suffice. Sometim
es we need more |
| 111 // passes than that, though, but the number of retries should not exceed
the number of |
| 112 // columns, unless we have a bug. |
| 113 needsRelayout = false; |
| 114 for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBo
x->nextSiblingBox()) { |
| 115 if (childBox != m_flowThread && childBox->isRenderMultiColumnSet())
{ |
| 116 RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(child
Box); |
| 117 if (multicolSet->calculateBalancedHeight(firstPass)) { |
| 118 multicolSet->setChildNeedsLayout(true, MarkOnlyThis); |
| 119 needsRelayout = true; |
| 120 } |
| 121 } |
| 122 } |
| 123 |
| 124 if (needsRelayout) { |
| 125 // Layout again. Column balancing resulted in a new height. |
| 126 neededRelayout = true; |
| 127 m_flowThread->setChildNeedsLayout(true, MarkOnlyThis); |
| 128 setChildNeedsLayout(true, MarkOnlyThis); |
| 129 if (firstPass) |
| 130 statePusher.pop(); |
| 131 layoutBlock(false); |
| 132 } |
| 133 firstPass = false; |
| 134 } while (needsRelayout); |
| 135 m_inBalancingPass = false; |
| 136 return neededRelayout; |
107 } | 137 } |
108 | 138 |
109 void RenderMultiColumnBlock::addChild(RenderObject* newChild, RenderObject* befo
reChild) | 139 void RenderMultiColumnBlock::addChild(RenderObject* newChild, RenderObject* befo
reChild) |
110 { | 140 { |
111 if (!m_flowThread) { | 141 if (!m_flowThread) { |
112 m_flowThread = RenderMultiColumnFlowThread::createAnonymous(document()); | 142 m_flowThread = RenderMultiColumnFlowThread::createAnonymous(document()); |
113 m_flowThread->setStyle(RenderStyle::createAnonymousStyleWithDisplay(styl
e(), BLOCK)); | 143 m_flowThread->setStyle(RenderStyle::createAnonymousStyleWithDisplay(styl
e(), BLOCK)); |
114 RenderBlock::addChild(m_flowThread); | 144 RenderBlock::addChild(m_flowThread); |
115 } | 145 } |
116 m_flowThread->addChild(newChild, beforeChild); | 146 m_flowThread->addChild(newChild, beforeChild); |
117 } | 147 } |
118 | 148 |
119 RenderObject* RenderMultiColumnBlock::layoutSpecialExcludedChild(bool relayoutCh
ildren) | 149 RenderObject* RenderMultiColumnBlock::layoutSpecialExcludedChild(bool relayoutCh
ildren) |
120 { | 150 { |
121 if (!m_flowThread) | 151 if (!m_flowThread) |
122 return 0; | 152 return 0; |
123 | 153 |
124 // Update the sizes of our regions (but not the placement) before we lay out
the flow thread. | 154 // Update the dimensions of our regions before we lay out the flow thread. |
125 // FIXME: Eventually this is going to get way more complicated, and we will
be destroying regions | 155 // FIXME: Eventually this is going to get way more complicated, and we will
be destroying regions |
126 // instead of trying to keep them around. | 156 // instead of trying to keep them around. |
127 bool shouldInvalidateRegions = false; | 157 bool shouldInvalidateRegions = false; |
128 for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->n
extSiblingBox()) { | 158 for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->n
extSiblingBox()) { |
129 if (childBox == m_flowThread) | 159 if (childBox == m_flowThread) |
130 continue; | 160 continue; |
131 | 161 |
132 if (relayoutChildren || childBox->needsLayout()) { | 162 if (relayoutChildren || childBox->needsLayout()) { |
133 childBox->updateLogicalWidth(); | 163 if (!m_inBalancingPass && childBox->isRenderMultiColumnSet()) |
134 childBox->updateLogicalHeight(); | 164 toRenderMultiColumnSet(childBox)->prepareForLayout(); |
135 shouldInvalidateRegions = true; | 165 shouldInvalidateRegions = true; |
136 } | 166 } |
137 } | 167 } |
138 | 168 |
139 if (shouldInvalidateRegions) | 169 if (shouldInvalidateRegions) |
140 m_flowThread->invalidateRegions(); | 170 m_flowThread->invalidateRegions(); |
141 | 171 |
142 if (relayoutChildren) | 172 if (relayoutChildren) |
143 m_flowThread->setChildNeedsLayout(true, MarkOnlyThis); | 173 m_flowThread->setChildNeedsLayout(true, MarkOnlyThis); |
144 | 174 |
(...skipping 16 matching lines...) Expand all Loading... |
161 if (isPseudoElement()) | 191 if (isPseudoElement()) |
162 return "RenderMultiColumnBlock (generated)"; | 192 return "RenderMultiColumnBlock (generated)"; |
163 if (isAnonymous()) | 193 if (isAnonymous()) |
164 return "RenderMultiColumnBlock (generated)"; | 194 return "RenderMultiColumnBlock (generated)"; |
165 if (isRelPositioned()) | 195 if (isRelPositioned()) |
166 return "RenderMultiColumnBlock (relative positioned)"; | 196 return "RenderMultiColumnBlock (relative positioned)"; |
167 return "RenderMultiColumnBlock"; | 197 return "RenderMultiColumnBlock"; |
168 } | 198 } |
169 | 199 |
170 } | 200 } |
OLD | NEW |