OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "core/layout/LayoutGrid.h" | 26 #include "core/layout/LayoutGrid.h" |
27 | 27 |
28 #include "core/frame/UseCounter.h" | 28 #include "core/frame/UseCounter.h" |
29 #include "core/layout/LayoutState.h" | 29 #include "core/layout/LayoutState.h" |
30 #include "core/layout/TextAutosizer.h" | 30 #include "core/layout/TextAutosizer.h" |
31 #include "core/paint/GridPainter.h" | 31 #include "core/paint/GridPainter.h" |
32 #include "core/paint/PaintLayer.h" | 32 #include "core/paint/PaintLayer.h" |
33 #include "core/style/ComputedStyle.h" | 33 #include "core/style/ComputedStyle.h" |
34 #include "core/style/GridArea.h" | 34 #include "core/style/GridArea.h" |
35 #include "platform/LengthFunctions.h" | 35 #include "platform/LengthFunctions.h" |
36 #include "platform/text/WritingMode.h" | |
36 #include "wtf/PtrUtil.h" | 37 #include "wtf/PtrUtil.h" |
37 #include <algorithm> | 38 #include <algorithm> |
38 #include <memory> | 39 #include <memory> |
39 | 40 |
40 namespace blink { | 41 namespace blink { |
41 | 42 |
42 static const int infinity = -1; | 43 static const int infinity = -1; |
43 | 44 |
44 class GridItemWithSpan; | 45 class GridItemWithSpan; |
45 | 46 |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 updateLogicalWidth(); | 639 updateLogicalWidth(); |
639 m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight(); | 640 m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight(); |
640 | 641 |
641 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); | 642 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); |
642 | 643 |
643 placeItemsOnGrid(m_grid, TrackSizing); | 644 placeItemsOnGrid(m_grid, TrackSizing); |
644 | 645 |
645 GridSizingData sizingData(numTracks(ForColumns, m_grid), | 646 GridSizingData sizingData(numTracks(ForColumns, m_grid), |
646 numTracks(ForRows, m_grid), m_grid); | 647 numTracks(ForRows, m_grid), m_grid); |
647 | 648 |
649 computeBaselineAlignmentContext(sizingData); | |
650 if (baselineMayAffectIntrinsicWidth()) { | |
651 setPreferredLogicalWidthsDirty(MarkOnlyThis); | |
652 updateLogicalWidth(); | |
svillar
2017/01/23 10:41:58
It does not seem correct to do this twice. Why can
jfernandez
2017/02/02 15:49:22
As agreed, this is correct and the best approach,
| |
653 } | |
654 | |
648 // 1- First, the track sizing algorithm is used to resolve the sizes of the | 655 // 1- First, the track sizing algorithm is used to resolve the sizes of the |
649 // grid columns. | 656 // grid columns. |
650 // At this point the logical width is always definite as the above call to | 657 // At this point the logical width is always definite as the above call to |
651 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the | 658 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the |
652 // same for heights though because many code paths inside | 659 // same for heights though because many code paths inside |
653 // updateLogicalHeight() require a previous call to setLogicalHeight() to | 660 // updateLogicalHeight() require a previous call to setLogicalHeight() to |
654 // resolve heights properly (like for positioned items for example). | 661 // resolve heights properly (like for positioned items for example). |
655 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 662 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
656 computeTrackSizesForDefiniteSize(ForColumns, sizingData, | 663 computeTrackSizesForDefiniteSize(ForColumns, sizingData, |
657 availableSpaceForColumns); | 664 availableSpaceForColumns); |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1317 LayoutUnit(-1)); | 1324 LayoutUnit(-1)); |
1318 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1325 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
1319 } | 1326 } |
1320 | 1327 |
1321 // We need to clear the stretched height to properly compute logical height | 1328 // We need to clear the stretched height to properly compute logical height |
1322 // during layout. | 1329 // during layout. |
1323 if (child.needsLayout()) | 1330 if (child.needsLayout()) |
1324 child.clearOverrideLogicalContentHeight(); | 1331 child.clearOverrideLogicalContentHeight(); |
1325 | 1332 |
1326 child.layoutIfNeeded(); | 1333 child.layoutIfNeeded(); |
1334 GridAxis baselineAxis = | |
1335 isOrthogonalChild(child) ? GridRowAxis : GridColumnAxis; | |
1336 if (isBaselineAlignmentForChild(child, baselineAxis)) { | |
1337 auto& group = getBaselineGroupForChild(child, sizingData, baselineAxis); | |
1338 return group.maxAscent() + group.maxDescent(); | |
1339 } | |
1327 return child.logicalHeight() + child.marginLogicalHeight(); | 1340 return child.logicalHeight() + child.marginLogicalHeight(); |
1328 } | 1341 } |
1329 | 1342 |
1330 GridTrackSizingDirection LayoutGrid::flowAwareDirectionForChild( | 1343 GridTrackSizingDirection LayoutGrid::flowAwareDirectionForChild( |
1331 const LayoutBox& child, | 1344 const LayoutBox& child, |
1332 GridTrackSizingDirection direction) const { | 1345 GridTrackSizingDirection direction) const { |
1333 return !isOrthogonalChild(child) | 1346 return !isOrthogonalChild(child) |
1334 ? direction | 1347 ? direction |
1335 : (direction == ForColumns ? ForRows : ForColumns); | 1348 : (direction == ForColumns ? ForRows : ForColumns); |
1336 } | 1349 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 | 1433 |
1421 // All orthogonal flow boxes were already laid out during an early layout | 1434 // All orthogonal flow boxes were already laid out during an early layout |
1422 // phase performed in FrameView::performLayout. | 1435 // phase performed in FrameView::performLayout. |
1423 // It's true that grid track sizing was not completed at that time and it may | 1436 // It's true that grid track sizing was not completed at that time and it may |
1424 // afffect the final height of a grid item, but since it's forbidden to | 1437 // afffect the final height of a grid item, but since it's forbidden to |
1425 // perform a layout during intrinsic width computation, we have to use that | 1438 // perform a layout during intrinsic width computation, we have to use that |
1426 // computed height for now. | 1439 // computed height for now. |
1427 if (direction == ForColumns && | 1440 if (direction == ForColumns && |
1428 sizingData.sizingOperation == IntrinsicSizeComputation) { | 1441 sizingData.sizingOperation == IntrinsicSizeComputation) { |
1429 DCHECK(isOrthogonalChild(child)); | 1442 DCHECK(isOrthogonalChild(child)); |
1443 if (isBaselineAlignmentForChild(child, GridRowAxis) && | |
1444 isBaselineContextComputed(GridRowAxis)) { | |
1445 auto& group = getBaselineGroupForChild(child, sizingData, GridRowAxis); | |
1446 return group.maxAscent() + group.maxDescent(); | |
1447 } | |
1430 return child.logicalHeight() + child.marginLogicalHeight(); | 1448 return child.logicalHeight() + child.marginLogicalHeight(); |
1431 } | 1449 } |
1432 | 1450 |
1433 if (updateOverrideContainingBlockContentSizeForChild( | 1451 if (updateOverrideContainingBlockContentSizeForChild( |
1434 child, childInlineDirection, sizingData)) | 1452 child, childInlineDirection, sizingData)) |
1435 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1453 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
1436 return logicalHeightForChild(child, sizingData); | 1454 return logicalHeightForChild(child, sizingData); |
1437 } | 1455 } |
1438 | 1456 |
1439 DISABLE_CFI_PERF | 1457 DISABLE_CFI_PERF |
(...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3081 .toInt(); | 3099 .toInt(); |
3082 } | 3100 } |
3083 | 3101 |
3084 static int synthesizedBaselineFromBorderBox(const LayoutBox& box, | 3102 static int synthesizedBaselineFromBorderBox(const LayoutBox& box, |
3085 LineDirectionMode direction) { | 3103 LineDirectionMode direction) { |
3086 return (direction == HorizontalLine ? box.size().height() | 3104 return (direction == HorizontalLine ? box.size().height() |
3087 : box.size().width()) | 3105 : box.size().width()) |
3088 .toInt(); | 3106 .toInt(); |
3089 } | 3107 } |
3090 | 3108 |
3091 // TODO(lajava): This logic is shared by LayoutFlexibleBox, so it might be | |
3092 // refactored somehow. | |
3093 int LayoutGrid::baselinePosition(FontBaseline, | 3109 int LayoutGrid::baselinePosition(FontBaseline, |
3094 bool, | 3110 bool, |
3095 LineDirectionMode direction, | 3111 LineDirectionMode direction, |
3096 LinePositionMode mode) const { | 3112 LinePositionMode mode) const { |
3097 DCHECK_EQ(mode, PositionOnContainingLine); | 3113 DCHECK_EQ(mode, PositionOnContainingLine); |
3098 int baseline = firstLineBoxBaseline(); | 3114 int baseline = firstLineBoxBaseline(); |
3099 // We take content-box's bottom if no valid baseline. | 3115 // We take content-box's bottom if no valid baseline. |
3100 if (baseline == -1) | 3116 if (baseline == -1) |
3101 baseline = synthesizedBaselineFromContentBox(*this, direction); | 3117 baseline = synthesizedBaselineFromContentBox(*this, direction); |
3102 | 3118 |
3103 return baseline + beforeMarginInLineDirection(direction); | 3119 return baseline + beforeMarginInLineDirection(direction); |
3104 } | 3120 } |
3105 | 3121 |
3106 bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const { | |
3107 return alignSelfForChild(*child).position() == ItemPositionBaseline && | |
3108 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); | |
3109 } | |
3110 | |
3111 int LayoutGrid::firstLineBoxBaseline() const { | 3122 int LayoutGrid::firstLineBoxBaseline() const { |
3112 if (isWritingModeRoot() || !m_grid.hasGridItems()) | 3123 if (isWritingModeRoot() || !m_grid.hasGridItems()) |
3113 return -1; | 3124 return -1; |
3114 const LayoutBox* baselineChild = nullptr; | 3125 const LayoutBox* baselineChild = nullptr; |
3115 const LayoutBox* firstChild = nullptr; | 3126 const LayoutBox* firstChild = nullptr; |
3116 bool isBaselineAligned = false; | 3127 bool isBaselineAligned = false; |
3117 // Finding the first grid item in grid order. | 3128 // Finding the first grid item in grid order. |
3118 for (size_t column = 0; | 3129 for (size_t column = 0; |
3119 !isBaselineAligned && column < m_grid.numTracks(ForColumns); column++) { | 3130 !isBaselineAligned && column < m_grid.numTracks(ForColumns); column++) { |
3120 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { | 3131 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { |
3121 const LayoutBox* child = m_grid.cell(0, column)[index]; | 3132 const LayoutBox* child = m_grid.cell(0, column)[index]; |
3122 DCHECK(!child->isOutOfFlowPositioned()); | 3133 DCHECK(!child->isOutOfFlowPositioned()); |
3123 // If an item participates in baseline alignmen, we select such item. | 3134 // If an item participates in baseline alignment, we select such item. |
3124 if (isInlineBaselineAlignedChild(child)) { | 3135 if (isBaselineAlignmentForChild(*child)) { |
3125 // TODO (lajava): self-baseline and content-baseline alignment | 3136 // TODO (lajava): self-baseline and content-baseline alignment |
3126 // still not implemented. | 3137 // still not implemented. |
3127 baselineChild = child; | 3138 baselineChild = child; |
3128 isBaselineAligned = true; | 3139 isBaselineAligned = true; |
3129 break; | 3140 break; |
3130 } | 3141 } |
3131 if (!baselineChild) { | 3142 if (!baselineChild) { |
3132 // Use dom order for items in the same cell. | 3143 // Use dom order for items in the same cell. |
3133 if (!firstChild || (m_grid.gridItemPaintOrder(*child) < | 3144 if (!firstChild || (m_grid.gridItemPaintOrder(*child) < |
3134 m_grid.gridItemPaintOrder(*firstChild))) | 3145 m_grid.gridItemPaintOrder(*firstChild))) |
(...skipping 29 matching lines...) Expand all Loading... | |
3164 int LayoutGrid::inlineBlockBaseline(LineDirectionMode direction) const { | 3175 int LayoutGrid::inlineBlockBaseline(LineDirectionMode direction) const { |
3165 int baseline = firstLineBoxBaseline(); | 3176 int baseline = firstLineBoxBaseline(); |
3166 if (baseline != -1) | 3177 if (baseline != -1) |
3167 return baseline; | 3178 return baseline; |
3168 | 3179 |
3169 int marginHeight = | 3180 int marginHeight = |
3170 (direction == HorizontalLine ? marginTop() : marginRight()).toInt(); | 3181 (direction == HorizontalLine ? marginTop() : marginRight()).toInt(); |
3171 return synthesizedBaselineFromContentBox(*this, direction) + marginHeight; | 3182 return synthesizedBaselineFromContentBox(*this, direction) + marginHeight; |
3172 } | 3183 } |
3173 | 3184 |
3185 bool LayoutGrid::isHorizontalGridAxis(GridAxis axis) const { | |
3186 return axis == GridRowAxis ? isHorizontalWritingMode() | |
3187 : !isHorizontalWritingMode(); | |
3188 } | |
3189 | |
3190 bool LayoutGrid::isParallelToBlockAxisForChild(const LayoutBox& child, | |
3191 GridAxis axis) const { | |
3192 return axis == GridColumnAxis ? !isOrthogonalChild(child) | |
3193 : isOrthogonalChild(child); | |
3194 } | |
3195 | |
3196 bool LayoutGrid::isDescentBaselineForChild(const LayoutBox& child, | |
3197 GridAxis baselineAxis) const { | |
3198 return isHorizontalGridAxis(baselineAxis) && | |
3199 !styleRef().isFlippedBlocksWritingMode(); | |
3200 } | |
3201 | |
3202 bool LayoutGrid::isBaselineAlignmentForChild(const LayoutBox& child, | |
3203 GridAxis baselineAxis) const { | |
3204 bool isColumnAxisBaseline = baselineAxis == GridColumnAxis; | |
3205 ItemPosition align = isColumnAxisBaseline | |
3206 ? alignSelfForChild(child).position() | |
3207 : justifySelfForChild(child).position(); | |
3208 bool hasAutoMargins = isColumnAxisBaseline ? hasAutoMarginsInColumnAxis(child) | |
3209 : hasAutoMarginsInRowAxis(child); | |
3210 return isBaselinePosition(align) && !hasAutoMargins; | |
3211 } | |
3212 | |
3213 const BaselineGroup& LayoutGrid::getBaselineGroupForChild( | |
3214 const LayoutBox& child, | |
3215 const GridSizingData& sizingData, | |
3216 GridAxis baselineAxis) const { | |
3217 DCHECK(isBaselineAlignmentForChild(child, baselineAxis)); | |
3218 auto& grid = sizingData.grid(); | |
3219 bool isColumnAxisBaseline = baselineAxis == GridColumnAxis; | |
3220 bool isRowAxisContext = isColumnAxisBaseline; | |
3221 const auto& span = isRowAxisContext ? grid.gridItemSpan(child, ForRows) | |
3222 : grid.gridItemSpan(child, ForColumns); | |
3223 auto& contextsMap = | |
3224 isRowAxisContext ? m_rowAxisAlignmentContext : m_colAxisAlignmentContext; | |
3225 auto* context = contextsMap.get(span.startLine()); | |
3226 DCHECK(context); | |
3227 ItemPosition align = isColumnAxisBaseline | |
3228 ? alignSelfForChild(child).position() | |
3229 : justifySelfForChild(child).position(); | |
3230 return context->getSharedGroup(child, align); | |
3231 } | |
3232 | |
3233 LayoutUnit LayoutGrid::marginOverForChild(const LayoutBox& child, | |
3234 GridAxis axis) const { | |
3235 return isHorizontalGridAxis(axis) ? child.marginRight() : child.marginTop(); | |
3236 } | |
3237 | |
3238 LayoutUnit LayoutGrid::logicalAscentForChild(const LayoutBox& child, | |
3239 GridAxis baselineAxis) const { | |
3240 LayoutUnit ascent = ascentForChild(child, baselineAxis); | |
3241 return isDescentBaselineForChild(child, baselineAxis) | |
3242 ? descentForChild(child, ascent, baselineAxis) | |
3243 : ascent; | |
3244 } | |
3245 | |
3246 LayoutUnit LayoutGrid::ascentForChild(const LayoutBox& child, | |
3247 GridAxis baselineAxis) const { | |
3248 int baseline = isParallelToBlockAxisForChild(child, baselineAxis) | |
3249 ? child.firstLineBoxBaseline() | |
3250 : -1; | |
3251 // We take border-box's bottom if no valid baseline. | |
3252 if (baseline == -1) { | |
3253 baseline = isHorizontalGridAxis(baselineAxis) | |
3254 ? child.size().width().toInt() | |
3255 : child.size().height().toInt(); | |
3256 } | |
3257 return LayoutUnit(baseline) + marginOverForChild(child, baselineAxis); | |
3258 } | |
3259 | |
3260 LayoutUnit LayoutGrid::descentForChild(const LayoutBox& child, | |
3261 LayoutUnit ascent, | |
3262 GridAxis baselineAxis) const { | |
3263 if (isParallelToBlockAxisForChild(child, baselineAxis)) | |
3264 return child.marginLogicalHeight() + child.logicalHeight() - ascent; | |
3265 return child.marginLogicalWidth() + child.logicalWidth() - ascent; | |
3266 } | |
3267 | |
3268 bool LayoutGrid::isBaselineContextComputed(GridAxis baselineAxis) const { | |
3269 return baselineAxis == GridColumnAxis ? !m_rowAxisAlignmentContext.isEmpty() | |
3270 : !m_colAxisAlignmentContext.isEmpty(); | |
3271 } | |
3272 | |
3273 bool LayoutGrid::baselineMayAffectIntrinsicWidth() const { | |
3274 for (const auto& context : m_colAxisAlignmentContext) { | |
3275 for (const auto& group : context.value->sharedGroups()) { | |
3276 if (group.size() > 1) | |
3277 return true; | |
3278 } | |
3279 } | |
3280 return false; | |
3281 } | |
3282 | |
3283 void LayoutGrid::computeBaselineAlignmentContext(GridSizingData& sizingData) { | |
3284 for (auto* child = firstInFlowChildBox(); child; | |
3285 child = child->nextInFlowSiblingBox()) { | |
3286 updateBaselineAlignmentContextIfNeeded(*child, sizingData, GridRowAxis); | |
3287 updateBaselineAlignmentContextIfNeeded(*child, sizingData, GridColumnAxis); | |
3288 } | |
3289 } | |
3290 | |
3291 void LayoutGrid::updateBaselineAlignmentContextIfNeeded( | |
3292 LayoutBox& child, | |
3293 GridSizingData& sizingData, | |
3294 GridAxis baselineAxis) { | |
3295 DCHECK_EQ(sizingData.sizingOperation, TrackSizing); | |
3296 if (!isBaselineAlignmentForChild(child, baselineAxis)) | |
3297 return; | |
3298 | |
3299 child.layoutIfNeeded(); | |
3300 | |
3301 // Determine Ascent and Descent values of this child with respect to | |
3302 // its grid container. | |
3303 LayoutUnit ascent = ascentForChild(child, baselineAxis); | |
3304 LayoutUnit descent = descentForChild(child, ascent, baselineAxis); | |
3305 if (isDescentBaselineForChild(child, baselineAxis)) { | |
3306 LayoutUnit temp(ascent); | |
3307 ascent = descent; | |
3308 descent = temp; | |
svillar
2017/01/23 10:41:58
std::swap
jfernandez
2017/02/02 15:49:22
Done.
| |
3309 } | |
3310 | |
3311 // Looking up for a shared alignment context perpendicular to the | |
3312 // baseline axis. | |
3313 auto& grid = sizingData.grid(); | |
3314 bool isColumnAxisBaseline = baselineAxis == GridColumnAxis; | |
3315 bool isRowAxisContext = isColumnAxisBaseline; | |
3316 const auto& span = isRowAxisContext ? grid.gridItemSpan(child, ForRows) | |
3317 : grid.gridItemSpan(child, ForColumns); | |
3318 auto& contextsMap = | |
3319 isRowAxisContext ? m_rowAxisAlignmentContext : m_colAxisAlignmentContext; | |
3320 auto addResult = contextsMap.add(span.startLine(), nullptr); | |
3321 | |
3322 // Looking for a compatible baseline-sharing group. | |
3323 ItemPosition align = isColumnAxisBaseline | |
3324 ? alignSelfForChild(child).position() | |
3325 : justifySelfForChild(child).position(); | |
3326 if (addResult.isNewEntry) { | |
3327 addResult.storedValue->value = | |
3328 WTF::makeUnique<BaselineContext>(child, align, ascent, descent); | |
3329 } else { | |
3330 auto* context = addResult.storedValue->value.get(); | |
3331 context->updateSharedGroup(child, align, ascent, descent); | |
3332 } | |
3333 } | |
3334 | |
3335 LayoutUnit LayoutGrid::columnAxisBaselineOffsetForChild( | |
3336 const LayoutBox& child, | |
3337 const GridSizingData& sizingData) const { | |
3338 if (!isBaselineAlignmentForChild(child, GridColumnAxis)) | |
3339 return LayoutUnit(); | |
3340 auto& group = getBaselineGroupForChild(child, sizingData, GridColumnAxis); | |
3341 if (group.size() > 1) | |
3342 return group.maxAscent() - logicalAscentForChild(child, GridColumnAxis); | |
3343 return LayoutUnit(); | |
3344 } | |
3345 | |
3346 LayoutUnit LayoutGrid::rowAxisBaselineOffsetForChild( | |
3347 const LayoutBox& child, | |
3348 const GridSizingData& sizingData) const { | |
3349 if (!isBaselineAlignmentForChild(child, GridRowAxis)) | |
3350 return LayoutUnit(); | |
3351 auto& group = getBaselineGroupForChild(child, sizingData, GridRowAxis); | |
3352 if (group.size() > 1) | |
3353 return group.maxAscent() - logicalAscentForChild(child, GridRowAxis); | |
3354 return LayoutUnit(); | |
3355 } | |
3356 | |
3174 GridAxisPosition LayoutGrid::columnAxisPositionForChild( | 3357 GridAxisPosition LayoutGrid::columnAxisPositionForChild( |
3175 const LayoutBox& child) const { | 3358 const LayoutBox& child) const { |
3176 bool hasSameWritingMode = | 3359 bool hasSameWritingMode = |
3177 child.styleRef().getWritingMode() == styleRef().getWritingMode(); | 3360 child.styleRef().getWritingMode() == styleRef().getWritingMode(); |
3178 bool childIsLTR = child.styleRef().isLeftToRightDirection(); | 3361 bool childIsLTR = child.styleRef().isLeftToRightDirection(); |
3179 | 3362 |
3180 switch (alignSelfForChild(child).position()) { | 3363 switch (alignSelfForChild(child).position()) { |
3181 case ItemPositionSelfStart: | 3364 case ItemPositionSelfStart: |
3182 // TODO (lajava): Should we implement this logic in a generic utility | 3365 // TODO (lajava): Should we implement this logic in a generic utility |
3183 // function? | 3366 // function? |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3233 // Only used in flex layout, otherwise equivalent to 'end'. | 3416 // Only used in flex layout, otherwise equivalent to 'end'. |
3234 case ItemPositionFlexEnd: | 3417 case ItemPositionFlexEnd: |
3235 // Aligns the alignment subject to be flush with the alignment container's | 3418 // Aligns the alignment subject to be flush with the alignment container's |
3236 // 'end' edge (block-end) in the column axis. | 3419 // 'end' edge (block-end) in the column axis. |
3237 case ItemPositionEnd: | 3420 case ItemPositionEnd: |
3238 return GridAxisEnd; | 3421 return GridAxisEnd; |
3239 case ItemPositionStretch: | 3422 case ItemPositionStretch: |
3240 return GridAxisStart; | 3423 return GridAxisStart; |
3241 case ItemPositionBaseline: | 3424 case ItemPositionBaseline: |
3242 case ItemPositionLastBaseline: | 3425 case ItemPositionLastBaseline: |
3243 // FIXME: These two require implementing Baseline Alignment. For now, we | |
3244 // always 'start' align the child. crbug.com/234191 | |
3245 return GridAxisStart; | 3426 return GridAxisStart; |
3246 case ItemPositionAuto: | 3427 case ItemPositionAuto: |
3247 case ItemPositionNormal: | 3428 case ItemPositionNormal: |
3248 break; | 3429 break; |
3249 } | 3430 } |
3250 | 3431 |
3251 ASSERT_NOT_REACHED(); | 3432 ASSERT_NOT_REACHED(); |
3252 return GridAxisStart; | 3433 return GridAxisStart; |
3253 } | 3434 } |
3254 | 3435 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3312 // Only used in flex layout, otherwise equivalent to 'end'. | 3493 // Only used in flex layout, otherwise equivalent to 'end'. |
3313 case ItemPositionFlexEnd: | 3494 case ItemPositionFlexEnd: |
3314 // Aligns the alignment subject to be flush with the alignment container's | 3495 // Aligns the alignment subject to be flush with the alignment container's |
3315 // 'end' edge (inline-end) in the row axis. | 3496 // 'end' edge (inline-end) in the row axis. |
3316 case ItemPositionEnd: | 3497 case ItemPositionEnd: |
3317 return GridAxisEnd; | 3498 return GridAxisEnd; |
3318 case ItemPositionStretch: | 3499 case ItemPositionStretch: |
3319 return GridAxisStart; | 3500 return GridAxisStart; |
3320 case ItemPositionBaseline: | 3501 case ItemPositionBaseline: |
3321 case ItemPositionLastBaseline: | 3502 case ItemPositionLastBaseline: |
3322 // FIXME: These two require implementing Baseline Alignment. For now, we | |
3323 // always 'start' align the child. crbug.com/234191 | |
3324 return GridAxisStart; | 3503 return GridAxisStart; |
3325 case ItemPositionAuto: | 3504 case ItemPositionAuto: |
3326 case ItemPositionNormal: | 3505 case ItemPositionNormal: |
3327 break; | 3506 break; |
3328 } | 3507 } |
3329 | 3508 |
3330 ASSERT_NOT_REACHED(); | 3509 ASSERT_NOT_REACHED(); |
3331 return GridAxisStart; | 3510 return GridAxisStart; |
3332 } | 3511 } |
3333 | 3512 |
3334 LayoutUnit LayoutGrid::columnAxisOffsetForChild( | 3513 LayoutUnit LayoutGrid::columnAxisOffsetForChild( |
3335 const LayoutBox& child, | 3514 const LayoutBox& child, |
3336 GridSizingData& sizingData) const { | 3515 GridSizingData& sizingData) const { |
3337 const GridSpan& rowsSpan = sizingData.grid().gridItemSpan(child, ForRows); | 3516 const GridSpan& rowsSpan = sizingData.grid().gridItemSpan(child, ForRows); |
3338 size_t childStartLine = rowsSpan.startLine(); | 3517 size_t childStartLine = rowsSpan.startLine(); |
3339 LayoutUnit startOfRow = m_rowPositions[childStartLine]; | 3518 LayoutUnit startOfRow = m_rowPositions[childStartLine]; |
3340 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); | 3519 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); |
3341 if (hasAutoMarginsInColumnAxis(child)) | 3520 if (hasAutoMarginsInColumnAxis(child)) |
3342 return startPosition; | 3521 return startPosition; |
3343 GridAxisPosition axisPosition = columnAxisPositionForChild(child); | 3522 GridAxisPosition axisPosition = columnAxisPositionForChild(child); |
3344 switch (axisPosition) { | 3523 switch (axisPosition) { |
3345 case GridAxisStart: | 3524 case GridAxisStart: |
3346 return startPosition; | 3525 return startPosition + |
3526 columnAxisBaselineOffsetForChild(child, sizingData); | |
3347 case GridAxisEnd: | 3527 case GridAxisEnd: |
3348 case GridAxisCenter: { | 3528 case GridAxisCenter: { |
3349 size_t childEndLine = rowsSpan.endLine(); | 3529 size_t childEndLine = rowsSpan.endLine(); |
3350 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 3530 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
3351 // m_rowPositions include distribution offset (because of content | 3531 // m_rowPositions include distribution offset (because of content |
3352 // alignment) and gutters so we need to subtract them to get the actual | 3532 // alignment) and gutters so we need to subtract them to get the actual |
3353 // end position for a given row (this does not have to be done for the | 3533 // end position for a given row (this does not have to be done for the |
3354 // last track as there are no more m_columnPositions after it). | 3534 // last track as there are no more m_columnPositions after it). |
3355 LayoutUnit trackGap = | 3535 LayoutUnit trackGap = |
3356 gridGapForDirection(ForRows, sizingData.sizingOperation); | 3536 gridGapForDirection(ForRows, sizingData.sizingOperation); |
(...skipping 23 matching lines...) Expand all Loading... | |
3380 const GridSpan& columnsSpan = | 3560 const GridSpan& columnsSpan = |
3381 sizingData.grid().gridItemSpan(child, ForColumns); | 3561 sizingData.grid().gridItemSpan(child, ForColumns); |
3382 size_t childStartLine = columnsSpan.startLine(); | 3562 size_t childStartLine = columnsSpan.startLine(); |
3383 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; | 3563 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; |
3384 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); | 3564 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); |
3385 if (hasAutoMarginsInRowAxis(child)) | 3565 if (hasAutoMarginsInRowAxis(child)) |
3386 return startPosition; | 3566 return startPosition; |
3387 GridAxisPosition axisPosition = rowAxisPositionForChild(child); | 3567 GridAxisPosition axisPosition = rowAxisPositionForChild(child); |
3388 switch (axisPosition) { | 3568 switch (axisPosition) { |
3389 case GridAxisStart: | 3569 case GridAxisStart: |
3390 return startPosition; | 3570 return startPosition + rowAxisBaselineOffsetForChild(child, sizingData); |
3391 case GridAxisEnd: | 3571 case GridAxisEnd: |
3392 case GridAxisCenter: { | 3572 case GridAxisCenter: { |
3393 size_t childEndLine = columnsSpan.endLine(); | 3573 size_t childEndLine = columnsSpan.endLine(); |
3394 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 3574 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
3395 // m_columnPositions include distribution offset (because of content | 3575 // m_columnPositions include distribution offset (because of content |
3396 // alignment) and gutters so we need to subtract them to get the actual | 3576 // alignment) and gutters so we need to subtract them to get the actual |
3397 // end position for a given column (this does not have to be done for the | 3577 // end position for a given column (this does not have to be done for the |
3398 // last track as there are no more m_columnPositions after it). | 3578 // last track as there are no more m_columnPositions after it). |
3399 LayoutUnit trackGap = | 3579 LayoutUnit trackGap = |
3400 gridGapForDirection(ForColumns, sizingData.sizingOperation); | 3580 gridGapForDirection(ForColumns, sizingData.sizingOperation); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3617 if (direction == ForRows) | 3797 if (direction == ForRows) |
3618 return grid.numTracks(ForRows); | 3798 return grid.numTracks(ForRows); |
3619 | 3799 |
3620 return grid.numTracks(ForRows) | 3800 return grid.numTracks(ForRows) |
3621 ? grid.numTracks(ForColumns) | 3801 ? grid.numTracks(ForColumns) |
3622 : GridPositionsResolver::explicitGridColumnCount( | 3802 : GridPositionsResolver::explicitGridColumnCount( |
3623 styleRef(), grid.autoRepeatTracks(ForColumns)); | 3803 styleRef(), grid.autoRepeatTracks(ForColumns)); |
3624 } | 3804 } |
3625 | 3805 |
3626 } // namespace blink | 3806 } // namespace blink |
OLD | NEW |