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

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 rebased. Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 04bb50667f5106eb8ab5012fab7d6f63c63c5dad..05a01b709fbfee65abbd54397c163e4667c2d148 100644
--- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
@@ -2906,6 +2906,110 @@ void LayoutGrid::updateAutoMarginsInColumnAxisIfNeeded(LayoutBox& child) {
}
}
+// TODO(lajava): This logic is shared by LayoutFlexibleBox, so it might be
+// refactored somehow.
+static int synthesizedBaselineFromContentBox(const LayoutBox& box,
+ LineDirectionMode direction) {
+ if (direction == HorizontalLine) {
+ return (box.size().height() - box.borderBottom() - box.paddingBottom() -
+ box.horizontalScrollbarHeight())
+ .toInt();
+ }
+ return (box.size().width() - box.borderLeft() - box.paddingLeft() -
+ box.verticalScrollbarWidth())
+ .toInt();
+}
+
+static int synthesizedBaselineFromBorderBox(const LayoutBox& box,
+ LineDirectionMode direction) {
+ return (direction == HorizontalLine ? box.size().height()
+ : box.size().width())
+ .toInt();
+}
+
+// TODO(lajava): This logic is shared by LayoutFlexibleBox, so it might be
+// refactored somehow.
+int LayoutGrid::baselinePosition(FontBaseline,
+ bool,
+ LineDirectionMode direction,
+ LinePositionMode mode) const {
+ 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);
+}
+
+bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const {
+ return alignSelfForChild(*child).position() == ItemPositionBaseline &&
+ !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child);
+}
+
+int LayoutGrid::firstLineBoxBaseline() const {
+ if (isWritingModeRoot() || m_grid.isEmpty())
+ return -1;
+ const LayoutBox* baselineChild = nullptr;
+ const LayoutBox* firstChild = nullptr;
+ bool isBaselineAligned = false;
+ // Finding the first grid item in grid order.
+ for (size_t column = 0; !isBaselineAligned && column < m_grid[0].size();
+ column++) {
+ for (size_t index = 0; index < m_grid[0][column].size(); index++) {
+ const LayoutBox* child = m_grid[0][column][index];
+ DCHECK(!child->isOutOfFlowPositioned());
+ // If an item participates in baseline alignmen, we select such item.
+ if (isInlineBaselineAlignedChild(child)) {
+ // TODO (lajava): self-baseline and content-baseline alignment
+ // still not implemented.
+ baselineChild = child;
+ isBaselineAligned = true;
+ break;
+ }
+ if (!baselineChild) {
+ // Use dom order for items in the same cell.
+ if (!firstChild || (m_gridItemsIndexesMap.get(child) <
+ m_gridItemsIndexesMap.get(firstChild)))
+ firstChild = child;
+ }
+ }
+ if (!baselineChild && firstChild)
+ baselineChild = firstChild;
+ }
+
+ if (!baselineChild)
+ return -1;
+
+ int baseline = isOrthogonalChild(*baselineChild)
+ ? -1
+ : baselineChild->firstLineBoxBaseline();
+ // We take border-box's bottom if no valid baseline.
+ 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 (synthesizedBaselineFromBorderBox(*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 =
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698