Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 2417853002: [css-grid] Implementing the grid's first line baseline. (Closed)
Patch Set: Patch for landing. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 26b4afd42c9f6a66f70e7a0e1a2aeccb0f5cc909..406a16c1a586f9bc8630e4e2c7069e46dab7746f 100644
--- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
@@ -2900,6 +2900,93 @@ void LayoutGrid::updateAutoMarginsInColumnAxisIfNeeded(LayoutBox& child) {
}
}
+static int synthesizedBaselineFromContentBox(const LayoutBox& box,
+ LineDirectionMode direction) {
+ if (direction == HorizontalLine) {
+ return (box.size().height() - box.borderBottom() - box.paddingBottom() -
+ box.verticalScrollbarWidth())
svillar 2016/10/21 12:53:06 Why aren't you directly using contentHeight() ?
jfernandez 2016/10/26 14:22:31 Well, we don't want contentHeight, but the distanc
+ .toInt();
+ }
+ return (box.size().width() - box.borderLeft() - box.paddingLeft() -
+ box.horizontalScrollbarHeight())
svillar 2016/10/21 12:53:06 Why aren't you directly using contentWidth() ?
jfernandez 2016/10/26 14:22:31 Ditto.
+ .toInt();
+}
+
+int LayoutGrid::baselinePosition(FontBaseline,
+ bool,
+ LineDirectionMode direction,
+ LinePositionMode mode) const {
Manuel Rego 2016/10/25 19:42:09 This is the same code than flexbox, probably it'd
jfernandez 2016/10/26 14:22:31 Acknowledged.
+ DCHECK_EQ(mode, PositionOnContainingLine);
+ 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;
svillar 2016/10/21 12:53:06 This is order-modified document order not grid-mod
Manuel Rego 2016/10/25 19:42:09 Yeah you should check the things in the first row
jfernandez 2016/10/26 14:22:31 Done.
+ 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 {
Manuel Rego 2016/10/25 19:42:09 Again same code than flexbox, please add a comment
jfernandez 2016/10/26 14:22:31 Acknowledged.
+ 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 =

Powered by Google App Engine
This is Rietveld 408576698