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

Unified Diff: third_party/WebKit/Source/core/layout/line/RootInlineBox.cpp

Issue 1699213002: Add layout support for the snap-height property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snap-height
Patch Set: eae review Created 4 years, 10 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
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('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/line/RootInlineBox.cpp
diff --git a/third_party/WebKit/Source/core/layout/line/RootInlineBox.cpp b/third_party/WebKit/Source/core/layout/line/RootInlineBox.cpp
index 4f369da0b2bfd09bbb7fbfc5755952052fd331b3..42205c212358611ebc29997dc8cd8c3429b3c837 100644
--- a/third_party/WebKit/Source/core/layout/line/RootInlineBox.cpp
+++ b/third_party/WebKit/Source/core/layout/line/RootInlineBox.cpp
@@ -191,6 +191,33 @@ void RootInlineBox::childRemoved(InlineBox* box)
}
}
+static inline void snapHeight(int& maxAscent, int& maxDescent, const ComputedStyle& style)
+{
+ // If position is 0, add spaces to over/under equally.
+ // https://drafts.csswg.org/css-snap-size/#snap-height
+ int unit = style.snapHeightUnit();
+ ASSERT(unit);
+ int position = style.snapHeightPosition();
+ if (!position) {
+ int space = unit - ((maxAscent + maxDescent) % unit);
+ maxDescent += space / 2;
+ maxAscent += space - space / 2;
+ return;
+ }
+
+ // Match the baseline to the specified position.
+ // https://drafts.csswg.org/css-snap-size/#snap-baseline
+ ASSERT(position > 0 && position <= 100);
+ position = position * unit / 100;
+ int spaceOver = position - maxAscent % unit;
+ if (spaceOver < 0) {
+ spaceOver += unit;
+ ASSERT(spaceOver >= 0);
+ }
+ maxAscent += spaceOver;
+ maxDescent += unit - (maxAscent + maxDescent) % unit;
+}
+
LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache)
{
// SVG will handle vertical alignment on its own.
@@ -214,6 +241,9 @@ LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, G
if (maxAscent + maxDescent < std::max(maxPositionTop, maxPositionBottom))
adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPositionBottom);
+ if (lineLayoutItem().styleRef().snapHeightUnit())
+ snapHeight(maxAscent, maxDescent, lineLayoutItem().styleRef());
+
LayoutUnit maxHeight = LayoutUnit(maxAscent + maxDescent);
LayoutUnit lineTop = heightOfBlock;
LayoutUnit lineBottom = heightOfBlock;
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698