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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 { 184 {
185 if (box->lineLayoutItem() == m_lineBreakObj) 185 if (box->lineLayoutItem() == m_lineBreakObj)
186 setLineBreakInfo(0, 0, BidiStatus()); 186 setLineBreakInfo(0, 0, BidiStatus());
187 187
188 for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == bo x->lineLayoutItem(); prev = prev->prevRootBox()) { 188 for (RootInlineBox* prev = prevRootBox(); prev && prev->lineBreakObj() == bo x->lineLayoutItem(); prev = prev->prevRootBox()) {
189 prev->setLineBreakInfo(0, 0, BidiStatus()); 189 prev->setLineBreakInfo(0, 0, BidiStatus());
190 prev->markDirty(); 190 prev->markDirty();
191 } 191 }
192 } 192 }
193 193
194 static inline void snapHeight(int& maxAscent, int& maxDescent, const ComputedSty le& style)
195 {
196 // If position is 0, add spaces to over/under equally.
197 // https://drafts.csswg.org/css-snap-size/#snap-height
198 int unit = style.snapHeightUnit();
199 ASSERT(unit);
200 int position = style.snapHeightPosition();
201 if (!position) {
202 int space = unit - ((maxAscent + maxDescent) % unit);
203 maxDescent += space / 2;
204 maxAscent += space - space / 2;
205 return;
206 }
207
208 // Match the baseline to the specified position.
209 // https://drafts.csswg.org/css-snap-size/#snap-baseline
210 ASSERT(position > 0 && position <= 100);
211 position = position * unit / 100;
212 int spaceOver = position - maxAscent % unit;
213 if (spaceOver < 0) {
214 spaceOver += unit;
215 ASSERT(spaceOver >= 0);
216 }
217 maxAscent += spaceOver;
218 maxDescent += unit - (maxAscent + maxDescent) % unit;
219 }
220
194 LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, G lyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& vertical PositionCache) 221 LayoutUnit RootInlineBox::alignBoxesInBlockDirection(LayoutUnit heightOfBlock, G lyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& vertical PositionCache)
195 { 222 {
196 // SVG will handle vertical alignment on its own. 223 // SVG will handle vertical alignment on its own.
197 if (isSVGRootInlineBox()) 224 if (isSVGRootInlineBox())
198 return LayoutUnit(); 225 return LayoutUnit();
199 226
200 LayoutUnit maxPositionTop; 227 LayoutUnit maxPositionTop;
201 LayoutUnit maxPositionBottom; 228 LayoutUnit maxPositionBottom;
202 int maxAscent = 0; 229 int maxAscent = 0;
203 int maxDescent = 0; 230 int maxDescent = 0;
204 bool setMaxAscent = false; 231 bool setMaxAscent = false;
205 bool setMaxDescent = false; 232 bool setMaxDescent = false;
206 233
207 // Figure out if we're in no-quirks mode. 234 // Figure out if we're in no-quirks mode.
208 bool noQuirksMode = lineLayoutItem().document().inNoQuirksMode(); 235 bool noQuirksMode = lineLayoutItem().document().inNoQuirksMode();
209 236
210 m_baselineType = dominantBaseline(); 237 m_baselineType = dominantBaseline();
211 238
212 computeLogicalBoxHeights(this, maxPositionTop, maxPositionBottom, maxAscent, maxDescent, setMaxAscent, setMaxDescent, noQuirksMode, textBoxDataMap, baseline Type(), verticalPositionCache); 239 computeLogicalBoxHeights(this, maxPositionTop, maxPositionBottom, maxAscent, maxDescent, setMaxAscent, setMaxDescent, noQuirksMode, textBoxDataMap, baseline Type(), verticalPositionCache);
213 240
214 if (maxAscent + maxDescent < std::max(maxPositionTop, maxPositionBottom)) 241 if (maxAscent + maxDescent < std::max(maxPositionTop, maxPositionBottom))
215 adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPosi tionBottom); 242 adjustMaxAscentAndDescent(maxAscent, maxDescent, maxPositionTop, maxPosi tionBottom);
216 243
244 if (lineLayoutItem().styleRef().snapHeightUnit())
245 snapHeight(maxAscent, maxDescent, lineLayoutItem().styleRef());
246
217 LayoutUnit maxHeight = LayoutUnit(maxAscent + maxDescent); 247 LayoutUnit maxHeight = LayoutUnit(maxAscent + maxDescent);
218 LayoutUnit lineTop = heightOfBlock; 248 LayoutUnit lineTop = heightOfBlock;
219 LayoutUnit lineBottom = heightOfBlock; 249 LayoutUnit lineBottom = heightOfBlock;
220 LayoutUnit lineTopIncludingMargins = heightOfBlock; 250 LayoutUnit lineTopIncludingMargins = heightOfBlock;
221 LayoutUnit lineBottomIncludingMargins = heightOfBlock; 251 LayoutUnit lineBottomIncludingMargins = heightOfBlock;
222 LayoutUnit selectionBottom = heightOfBlock; 252 LayoutUnit selectionBottom = heightOfBlock;
223 bool setLineTop = false; 253 bool setLineTop = false;
224 bool hasAnnotationsBefore = false; 254 bool hasAnnotationsBefore = false;
225 bool hasAnnotationsAfter = false; 255 bool hasAnnotationsAfter = false;
226 placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode , lineTop, lineBottom, selectionBottom, setLineTop, lineTopIncludingMargins, lin eBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType ()); 256 placeBoxesInBlockDirection(heightOfBlock, maxHeight, maxAscent, noQuirksMode , lineTop, lineBottom, selectionBottom, setLineTop, lineTopIncludingMargins, lin eBottomIncludingMargins, hasAnnotationsBefore, hasAnnotationsAfter, baselineType ());
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 endBox = nullptr; 736 endBox = nullptr;
707 return nullptr; 737 return nullptr;
708 } 738 }
709 739
710 const char* RootInlineBox::boxName() const 740 const char* RootInlineBox::boxName() const
711 { 741 {
712 return "RootInlineBox"; 742 return "RootInlineBox";
713 } 743 }
714 744
715 } // namespace blink 745 } // namespace blink
OLDNEW
« 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