OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 static int synthesizedBaselineFromContentBox(const RenderBox* box, LineDirection
Mode direction) | 114 static int synthesizedBaselineFromContentBox(const RenderBox* box, LineDirection
Mode direction) |
115 { | 115 { |
116 return direction == HorizontalLine ? box->borderTop() + box->paddingTop() +
box->contentHeight() : box->borderRight() + box->paddingRight() + box->contentWi
dth(); | 116 return direction == HorizontalLine ? box->borderTop() + box->paddingTop() +
box->contentHeight() : box->borderRight() + box->paddingRight() + box->contentWi
dth(); |
117 } | 117 } |
118 | 118 |
119 int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di
rection, LinePositionMode mode) const | 119 int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di
rection, LinePositionMode mode) const |
120 { | 120 { |
121 ASSERT(mode == PositionOnContainingLine); | 121 ASSERT(mode == PositionOnContainingLine); |
122 int baseline = firstLineBoxBaseline(); | 122 int baseline = firstLineBoxBaseline(FontBaselineOrAuto()); |
123 if (baseline == -1) | 123 if (baseline == -1) |
124 baseline = synthesizedBaselineFromContentBox(this, direction); | 124 baseline = synthesizedBaselineFromContentBox(this, direction); |
125 | 125 |
126 return beforeMarginInLineDirection(direction) + baseline; | 126 return beforeMarginInLineDirection(direction) + baseline; |
127 } | 127 } |
128 | 128 |
129 int RenderFlexibleBox::firstLineBoxBaseline() const | 129 int RenderFlexibleBox::firstLineBoxBaseline(FontBaselineOrAuto baselineType) con
st |
130 { | 130 { |
131 if (m_numberOfInFlowChildrenOnFirstLine <= 0) | 131 if (m_numberOfInFlowChildrenOnFirstLine <= 0) |
132 return -1; | 132 return -1; |
133 RenderBox* baselineChild = 0; | 133 RenderBox* baselineChild = 0; |
134 int childNumber = 0; | 134 int childNumber = 0; |
135 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 135 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
136 if (child->isOutOfFlowPositioned()) | 136 if (child->isOutOfFlowPositioned()) |
137 continue; | 137 continue; |
138 if (alignmentForChild(child) == ItemPositionBaseline && !hasAutoMarginsI
nCrossAxis(child)) { | 138 if (alignmentForChild(child) == ItemPositionBaseline && !hasAutoMarginsI
nCrossAxis(child)) { |
139 baselineChild = child; | 139 baselineChild = child; |
140 break; | 140 break; |
141 } | 141 } |
142 if (!baselineChild) | 142 if (!baselineChild) |
143 baselineChild = child; | 143 baselineChild = child; |
144 | 144 |
145 ++childNumber; | 145 ++childNumber; |
146 if (childNumber == m_numberOfInFlowChildrenOnFirstLine) | 146 if (childNumber == m_numberOfInFlowChildrenOnFirstLine) |
147 break; | 147 break; |
148 } | 148 } |
149 | 149 |
150 if (!baselineChild) | 150 if (!baselineChild) |
151 return -1; | 151 return -1; |
152 | 152 |
153 if (!isColumnFlow() && hasOrthogonalFlow(baselineChild)) | 153 if (!isColumnFlow() && hasOrthogonalFlow(baselineChild)) |
154 return crossAxisExtentForChild(baselineChild) + baselineChild->logicalTo
p(); | 154 return crossAxisExtentForChild(baselineChild) + baselineChild->logicalTo
p(); |
155 if (isColumnFlow() && !hasOrthogonalFlow(baselineChild)) | 155 if (isColumnFlow() && !hasOrthogonalFlow(baselineChild)) |
156 return mainAxisExtentForChild(baselineChild) + baselineChild->logicalTop
(); | 156 return mainAxisExtentForChild(baselineChild) + baselineChild->logicalTop
(); |
157 | 157 |
158 int baseline = baselineChild->firstLineBoxBaseline(); | 158 int baseline = baselineChild->firstLineBoxBaseline(baselineType); |
159 if (baseline == -1) { | 159 if (baseline == -1) { |
160 // FIXME: We should pass |direction| into firstLineBoxBaseline and stop
bailing out if we're a writing mode root. | 160 // FIXME: We should pass |direction| into firstLineBoxBaseline and stop
bailing out if we're a writing mode root. |
161 // This would also fix some cases where the flexbox is orthogonal to its
container. | 161 // This would also fix some cases where the flexbox is orthogonal to its
container. |
162 LineDirectionMode direction = HorizontalLine; | 162 LineDirectionMode direction = HorizontalLine; |
163 return synthesizedBaselineFromContentBox(baselineChild, direction) + bas
elineChild->logicalTop(); | 163 return synthesizedBaselineFromContentBox(baselineChild, direction) + bas
elineChild->logicalTop(); |
164 } | 164 } |
165 | 165 |
166 return baseline + baselineChild->logicalTop(); | 166 return baseline + baselineChild->logicalTop(); |
167 } | 167 } |
168 | 168 |
169 int RenderFlexibleBox::inlineBlockBaseline(LineDirectionMode direction) const | 169 int RenderFlexibleBox::inlineBlockBaseline(LineDirectionMode direction) const |
170 { | 170 { |
171 int baseline = firstLineBoxBaseline(); | 171 int baseline = firstLineBoxBaseline(FontBaselineOrAuto()); |
172 if (baseline != -1) | 172 if (baseline != -1) |
173 return baseline; | 173 return baseline; |
174 | 174 |
175 int marginAscent = direction == HorizontalLine ? marginTop() : marginRight()
; | 175 int marginAscent = direction == HorizontalLine ? marginTop() : marginRight()
; |
176 return synthesizedBaselineFromContentBox(this, direction) + marginAscent; | 176 return synthesizedBaselineFromContentBox(this, direction) + marginAscent; |
177 } | 177 } |
178 | 178 |
179 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende
rStyle* childStyle) | 179 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende
rStyle* childStyle) |
180 { | 180 { |
181 ItemPosition align = childStyle->alignSelf(); | 181 ItemPosition align = childStyle->alignSelf(); |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 child->setMarginBottom(availableAlignmentSpace); | 673 child->setMarginBottom(availableAlignmentSpace); |
674 else | 674 else |
675 child->setMarginRight(availableAlignmentSpace); | 675 child->setMarginRight(availableAlignmentSpace); |
676 return true; | 676 return true; |
677 } | 677 } |
678 return false; | 678 return false; |
679 } | 679 } |
680 | 680 |
681 LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(RenderBox* child) | 681 LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(RenderBox* child) |
682 { | 682 { |
683 LayoutUnit ascent = child->firstLineBoxBaseline(); | 683 LayoutUnit ascent = child->firstLineBoxBaseline(FontBaselineOrAuto()); |
684 if (ascent == -1) | 684 if (ascent == -1) |
685 ascent = crossAxisExtentForChild(child); | 685 ascent = crossAxisExtentForChild(child); |
686 return ascent + flowAwareMarginBeforeForChild(child); | 686 return ascent + flowAwareMarginBeforeForChild(child); |
687 } | 687 } |
688 | 688 |
689 LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin) | 689 LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin) |
690 { | 690 { |
691 // When resolving the margins, we use the content size for resolving percent
and calc (for percents in calc expressions) margins. | 691 // When resolving the margins, we use the content size for resolving percent
and calc (for percents in calc expressions) margins. |
692 // Fortunately, percent margins are always computed with respect to the bloc
k's width, even for margin-top and margin-bottom. | 692 // Fortunately, percent margins are always computed with respect to the bloc
k's width, even for margin-top and margin-bottom. |
693 LayoutUnit availableSize = contentLogicalWidth(); | 693 LayoutUnit availableSize = contentLogicalWidth(); |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 ASSERT(child); | 1246 ASSERT(child); |
1247 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1247 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
1248 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1248 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
1249 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1249 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
1250 adjustAlignmentForChild(child, newOffset - originalOffset); | 1250 adjustAlignmentForChild(child, newOffset - originalOffset); |
1251 } | 1251 } |
1252 } | 1252 } |
1253 } | 1253 } |
1254 | 1254 |
1255 } | 1255 } |
OLD | NEW |