Index: third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
index a9d80d7ebbd8775def2668b9adf41c2c2b336d45..085c913e8c4572a44b87296ecc3089dfdd497a54 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
@@ -2885,6 +2885,102 @@ void LayoutGrid::updateAutoMarginsInColumnAxisIfNeeded(LayoutBox& child) { |
} |
} |
+LayoutUnit LayoutGrid::firstLineBoxBaselineForChild( |
cbiesinger
2016/10/19 20:57:59
Are you calling this function anywhere...?
jfernandez
2016/10/20 09:07:14
Umm, you're right. This function will be used late
|
+ const LayoutBox& child) const { |
+ LayoutUnit baseline(child.firstLineBoxBaseline()); |
+ // We take content-box's bottom if no valid baseline. |
cbiesinger
2016/10/19 20:57:59
But you're actually calculating the border-box bot
jfernandez
2016/10/20 09:07:14
umm, as far as I know, LayoutBlock::logicalHeightF
cbiesinger
2016/10/20 17:42:36
No, size().height() (and logicalHeight()) all refe
jfernandez
2016/10/20 22:13:23
Oh, I was so confused about this. I'll think about
|
+ if (baseline == -1) |
+ baseline = LayoutBlock::logicalHeightForChild(child); |
+ return baseline + marginBeforeForChild(child); |
+} |
+ |
+static int synthesizedBaselineFromContentBox(const LayoutBox& box, |
+ LineDirectionMode direction) { |
+ if (direction == HorizontalLine) { |
+ return (box.size().height() - box.borderBottom() - box.paddingBottom() - |
+ box.verticalScrollbarWidth()) |
+ .toInt(); |
+ } |
+ return (box.size().width() - box.borderLeft() - box.paddingLeft() - |
+ box.horizontalScrollbarHeight()) |
+ .toInt(); |
+} |
+ |
+int LayoutGrid::baselinePosition(FontBaseline, |
+ bool, |
+ LineDirectionMode direction, |
+ LinePositionMode mode) const { |
+ DCHECK(mode == PositionOnContainingLine); |
cbiesinger
2016/10/19 20:57:59
DCHECK_EQ
jfernandez
2016/10/20 09:07:14
Done.
|
+ int baseline = firstLineBoxBaseline(); |
+ // We take content-box's bottom if no valid baseline. |
+ if (baseline == -1) |
+ baseline = synthesizedBaselineFromContentBox(*this, direction); |
+ |
+ return baseline + beforeMarginInLineDirection(direction); |
+} |
+ |
+int LayoutGrid::firstLineBoxBaseline() const { |
+ if (isWritingModeRoot()) |
+ return -1; |
+ const LayoutBox* baselineChild = nullptr; |
+ for (const LayoutBox* child = m_orderIterator.first(); child; |
+ child = m_orderIterator.next()) { |
+ if (child->isOutOfFlowPositioned()) |
+ continue; |
+ const GridSpan& rowsSpan = cachedGridSpan(*child, ForRows); |
+ // TODO (lajava): propertly identifying grid items whose areas |
+ // intersect the grid container's first row. |
+ if (rowsSpan.startLine() > 0) |
+ continue; |
+ ItemPosition align = alignSelfForChild(*child).position(); |
+ // Orthogonal children don't participate in baseline alignment. |
+ if (align == ItemPositionBaseline && !isOrthogonalChild(*child) && |
+ !hasAutoMarginsInColumnAxis(*child)) { |
+ // TODO (lajava): self-baseline and content-baseline alignment |
+ // still not implemented. |
+ baselineChild = child; |
+ break; |
+ } |
+ if (!baselineChild) |
+ baselineChild = child; |
+ } |
+ |
+ if (!baselineChild) |
+ return -1; |
+ |
+ if (isOrthogonalChild(*baselineChild)) { |
+ return ((isHorizontalWritingMode() ? baselineChild->size().height() |
+ : baselineChild->size().width()) + |
+ baselineChild->logicalTop()) |
+ .toInt(); |
+ } |
+ |
+ int baseline = baselineChild->firstLineBoxBaseline(); |
+ if (baseline == -1) { |
+ // TODO (lajava): We should pass |direction| into |
+ // firstLineBoxBaseline and stop bailing out if we're a writing |
+ // mode root. This would also fix some cases where the grid is |
+ // orthogonal to its container. |
+ LineDirectionMode direction = |
+ isHorizontalWritingMode() ? HorizontalLine : VerticalLine; |
+ return (synthesizedBaselineFromContentBox(*baselineChild, direction) + |
+ baselineChild->logicalTop()) |
+ .toInt(); |
+ } |
+ |
+ return (baseline + baselineChild->logicalTop()).toInt(); |
+} |
+ |
+int LayoutGrid::inlineBlockBaseline(LineDirectionMode direction) const { |
+ int baseline = firstLineBoxBaseline(); |
+ if (baseline != -1) |
+ return baseline; |
+ |
+ int marginHeight = |
+ (direction == HorizontalLine ? marginTop() : marginRight()).toInt(); |
+ return synthesizedBaselineFromContentBox(*this, direction) + marginHeight; |
+} |
+ |
GridAxisPosition LayoutGrid::columnAxisPositionForChild( |
const LayoutBox& child) const { |
bool hasSameWritingMode = |